Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: third_party/WebKit/Source/core/input/TouchEventManager.cpp

Issue 2669663002: Move touch slop suppression to TouchEventManager (Closed)
Patch Set: slop regesion Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/input/TouchEventManager.h" 5 #include "core/input/TouchEventManager.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/events/TouchEvent.h" 8 #include "core/events/TouchEvent.h"
9 #include "core/frame/Deprecation.h" 9 #include "core/frame/Deprecation.h"
10 #include "core/frame/EventHandlerRegistry.h" 10 #include "core/frame/EventHandlerRegistry.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 return emptyAtom; 55 return emptyAtom;
56 } 56 }
57 } 57 }
58 58
59 enum TouchEventDispatchResultType { 59 enum TouchEventDispatchResultType {
60 UnhandledTouches, // Unhandled touch events. 60 UnhandledTouches, // Unhandled touch events.
61 HandledTouches, // Handled touch events. 61 HandledTouches, // Handled touch events.
62 TouchEventDispatchResultTypeMax, 62 TouchEventDispatchResultTypeMax,
63 }; 63 };
64 64
65 bool IsTouchSequenceStart(const WebTouchEvent& event) {
66 if (!event.touchesLength)
67 return false;
68 if (event.type() != WebInputEvent::TouchStart)
69 return false;
70 for (size_t i = 0; i < event.touchesLength; ++i) {
71 if (event.touches[i].state != blink::WebTouchPoint::StatePressed)
72 return false;
73 }
74 return true;
75 }
76
65 // Defining this class type local to dispatchTouchEvents() and annotating 77 // Defining this class type local to dispatchTouchEvents() and annotating
66 // it with STACK_ALLOCATED(), runs into MSVC(VS 2013)'s C4822 warning 78 // it with STACK_ALLOCATED(), runs into MSVC(VS 2013)'s C4822 warning
67 // that the local class doesn't provide a local definition for 'operator new'. 79 // that the local class doesn't provide a local definition for 'operator new'.
68 // Which it intentionally doesn't and shouldn't. 80 // Which it intentionally doesn't and shouldn't.
69 // 81 //
70 // Work around such toolchain bugginess by lifting out the type, thereby 82 // Work around such toolchain bugginess by lifting out the type, thereby
71 // taking it out of C4822's reach. 83 // taking it out of C4822's reach.
72 class ChangedTouches final { 84 class ChangedTouches final {
73 STACK_ALLOCATED(); 85 STACK_ALLOCATED();
74 86
(...skipping 13 matching lines...) Expand all
88 100
89 TouchEventManager::TouchEventManager(LocalFrame& frame) : m_frame(frame) { 101 TouchEventManager::TouchEventManager(LocalFrame& frame) : m_frame(frame) {
90 clear(); 102 clear();
91 } 103 }
92 104
93 void TouchEventManager::clear() { 105 void TouchEventManager::clear() {
94 m_touchSequenceDocument.clear(); 106 m_touchSequenceDocument.clear();
95 m_targetForTouchID.clear(); 107 m_targetForTouchID.clear();
96 m_regionForTouchID.clear(); 108 m_regionForTouchID.clear();
97 m_touchPressed = false; 109 m_touchPressed = false;
110 m_suppressingTouchmovesWithinSlop = false;
98 m_currentTouchAction = TouchActionAuto; 111 m_currentTouchAction = TouchActionAuto;
99 } 112 }
100 113
101 DEFINE_TRACE(TouchEventManager) { 114 DEFINE_TRACE(TouchEventManager) {
102 visitor->trace(m_frame); 115 visitor->trace(m_frame);
103 visitor->trace(m_touchSequenceDocument); 116 visitor->trace(m_touchSequenceDocument);
104 visitor->trace(m_targetForTouchID); 117 visitor->trace(m_targetForTouchID);
105 } 118 }
106 119
107 WebInputEventResult TouchEventManager::dispatchTouchEvents( 120 WebInputEventResult TouchEventManager::dispatchTouchEvents(
108 const WebTouchEvent& event, 121 const WebTouchEvent& event,
109 const HeapVector<TouchInfo>& touchInfos, 122 const HeapVector<TouchInfo>& touchInfos,
110 bool allTouchesReleased) { 123 bool allTouchesReleased) {
111 // Build up the lists to use for the |touches|, |targetTouches| and 124 // Build up the lists to use for the |touches|, |targetTouches| and
112 // |changedTouches| attributes in the JS event. See 125 // |changedTouches| attributes in the JS event. See
113 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these 126 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these
114 // lists fit together. 127 // lists fit together.
115 128
129 // Suppress all the touch moves in the slop region.
130 if (IsTouchSequenceStart(event))
131 m_suppressingTouchmovesWithinSlop = true;
132
133 if (event.type() == WebInputEvent::TouchEnd ||
134 event.type() == WebInputEvent::TouchCancel || event.touchesLength > 1) {
135 m_suppressingTouchmovesWithinSlop = false;
136 }
137
138 if (m_suppressingTouchmovesWithinSlop &&
139 event.type() == WebInputEvent::TouchMove) {
140 if (!event.movedBeyondSlopRegion)
141 return WebInputEventResult::HandledSuppressed;
142 m_suppressingTouchmovesWithinSlop = false;
143 }
144
116 // Holds the complete set of touches on the screen. 145 // Holds the complete set of touches on the screen.
117 TouchList* touches = TouchList::create(); 146 TouchList* touches = TouchList::create();
118 147
119 // A different view on the 'touches' list above, filtered and grouped by 148 // A different view on the 'touches' list above, filtered and grouped by
120 // event target. Used for the |targetTouches| list in the JS event. 149 // event target. Used for the |targetTouches| list in the JS event.
121 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>; 150 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>;
122 TargetTouchesHeapMap touchesByTarget; 151 TargetTouchesHeapMap touchesByTarget;
123 152
124 // Array of touches per state, used to assemble the |changedTouches| list. 153 // Array of touches per state, used to assemble the |changedTouches| list.
125 ChangedTouches changedTouches[WebTouchPoint::StateMax + 1]; 154 ChangedTouches changedTouches[WebTouchPoint::StateMax + 1];
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 512 }
484 513
485 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); 514 return dispatchTouchEvents(event, touchInfos, allTouchesReleased);
486 } 515 }
487 516
488 bool TouchEventManager::isAnyTouchActive() const { 517 bool TouchEventManager::isAnyTouchActive() const {
489 return m_touchPressed; 518 return m_touchPressed;
490 } 519 }
491 520
492 } // namespace blink 521 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698