File: touch_action_filter.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (159 lines) | stat: -rw-r--r-- 5,951 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_INPUT_TOUCH_ACTION_FILTER_H_
#define COMPONENTS_INPUT_TOUCH_ACTION_FILTER_H_

#include <optional>

#include "cc/input/touch_action.h"
#include "base/component_export.h"

namespace blink {
class WebGestureEvent;
}

namespace content {
class InputRouterImplTest;
class InputRouterImplTestBase;
class MockRenderWidgetHost;
class SitePerProcessBrowserTouchActionTest;
} // namespace content

namespace input {

enum class FilterGestureEventResult { kAllowed, kFiltered, kDelayed };

// The TouchActionFilter is responsible for filtering scroll and pinch gesture
// events according to the CSS touch-action values the renderer has sent for
// each touch point.
// For details see the touch-action design doc at http://goo.gl/KcKbxQ.
class COMPONENT_EXPORT(INPUT) TouchActionFilter {
 public:
  TouchActionFilter();

  TouchActionFilter(const TouchActionFilter&) = delete;
  TouchActionFilter& operator=(const TouchActionFilter&) = delete;

  ~TouchActionFilter();

  // Returns kFiltered if the supplied gesture event should be dropped based on
  // current touch-action state. kDelayed if the |scrolling_touch_action_| has
  // no value. Returns kAllowed, and possibly modifies the event's directional
  // parameters to make the event compatible with the effective touch-action.
  FilterGestureEventResult FilterGestureEvent(
      blink::WebGestureEvent* gesture_event);

  // Called when a set-touch-action message is received from the renderer
  // for a touch start event that is currently in flight.
  void OnSetTouchAction(cc::TouchAction touch_action);

  // Called at the end of a touch action sequence in order to log when a
  // compositor allowed touch action is or is not equivalent to the allowed
  // touch action.
  void ReportAndResetTouchAction();

  // Called when a set-compositor-allowed-touch-action message is received from
  // the renderer for a touch start event that is currently in flight.
  void OnSetCompositorAllowedTouchAction(cc::TouchAction);

  std::optional<cc::TouchAction> allowed_touch_action() const {
    return allowed_touch_action_;
  }

  std::optional<cc::TouchAction> active_touch_action() const {
    return active_touch_action_;
  }

  cc::TouchAction compositor_allowed_touch_action() const {
    return compositor_allowed_touch_action_;
  }

  bool has_touch_event_handler_for_testing() const {
    return has_touch_event_handler_;
  }

  void SetForceEnableZoom(bool enabled) { force_enable_zoom_ = enabled; }

  void OnHasTouchEventHandlers(bool has_handlers);

  void IncreaseActiveTouches();
  void DecreaseActiveTouches();

  void ForceResetTouchActionForTest();

 private:
  friend class content::InputRouterImplTest;
  friend class content::InputRouterImplTestBase;
  friend class content::MockRenderWidgetHost;
  friend class TouchActionFilterTest;
  friend class TouchActionFilterPinchTest;
  friend class content::SitePerProcessBrowserTouchActionTest;

  bool ShouldSuppressScrolling(const blink::WebGestureEvent&,
                               cc::TouchAction touch_action,
                               bool is_active_touch_action);
  FilterGestureEventResult FilterScrollEventAndResetState();
  FilterGestureEventResult FilterPinchEventAndResetState();
  void ResetTouchAction();
  void SetTouchAction(cc::TouchAction touch_action);

  // Whether scroll gestures should be discarded due to touch-action.
  bool drop_scroll_events_ = false;

  // Whether pinch gestures should be discarded due to touch-action.
  bool drop_pinch_events_ = false;

  // Whether a tap ending event in this sequence should be discarded because a
  // previous GestureTapUnconfirmed event was turned into a GestureTap.
  bool drop_current_tap_ending_event_ = false;

  // True iff the touch action of the last TapUnconfirmed or Tap event was
  // TOUCH_ACTION_AUTO. The double tap event depends on the touch action of the
  // previous tap or tap unconfirmed. Only valid between a TapUnconfirmed or Tap
  // and the next DoubleTap.
  bool allow_current_double_tap_event_ = true;

  // Force enable zoom for Accessibility.
  bool force_enable_zoom_ = false;

  // Indicates whether this page has touch event handler or not. Set by
  // InputRouterImpl::OnHasTouchEventHandlers. Default to false because one
  // could not scroll anyways when there is no content, and this is consistent
  // with the default state committed after DocumentLoader::DidCommitNavigation.
  // TODO(savella): Split touch_event_handler into touch_event_handler and
  // non_auto_touch_action.
  bool has_touch_event_handler_ = false;

  // True if an active gesture sequence is in progress. i.e. after GTD and
  // before GSE.
  bool gesture_sequence_in_progress_ = false;

  bool has_deferred_events_ = false;

  // True if scroll gestures are allowed to be used for cursor control. We set
  // this to false if a long press or double press has occurred in the current
  // gesture sequence, to prevent the cursor control feature from interfering
  // with long press drag selection and double press drag selection.
  bool allow_cursor_control_ = true;

  // Increment at receiving ACK for touch start and decrement at touch end.
  int num_of_active_touches_ = 0;

  // What touch actions are currently permitted.
  std::optional<cc::TouchAction> allowed_touch_action_;

  // The touch action that is used for the current gesture sequence. At the
  // touch sequence end, the |allowed_touch_action_| is reset while this remains
  // set as the effective touch action, for the still in progress gesture
  // sequence due to fling.
  std::optional<cc::TouchAction> active_touch_action_;

  // Allowed touch action received from the compositor.
  cc::TouchAction compositor_allowed_touch_action_;
};

}  // namespace input

#endif  // COMPONENTS_INPUT_TOUCH_ACTION_FILTER_H_