| OLD | NEW |
| 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 Loading... |
| 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 PlatformTouchEvent& event) { |
| 66 if (!event.touchPoints().size()) |
| 67 return false; |
| 68 if (event.type() != PlatformEvent::TouchStart) |
| 69 return false; |
| 70 for (const auto& point : event.touchPoints()) { |
| 71 if (point.state() != PlatformTouchPoint::TouchPressed) |
| 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 14 matching lines...) Expand all Loading... |
| 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; |
| 98 m_currentEvent = PlatformEvent::NoType; | 110 m_currentEvent = PlatformEvent::NoType; |
| 111 m_suppressingTouchmovesWithinSlop = false; |
| 99 m_currentTouchAction = TouchActionAuto; | 112 m_currentTouchAction = TouchActionAuto; |
| 100 } | 113 } |
| 101 | 114 |
| 102 DEFINE_TRACE(TouchEventManager) { | 115 DEFINE_TRACE(TouchEventManager) { |
| 103 visitor->trace(m_frame); | 116 visitor->trace(m_frame); |
| 104 visitor->trace(m_touchSequenceDocument); | 117 visitor->trace(m_touchSequenceDocument); |
| 105 visitor->trace(m_targetForTouchID); | 118 visitor->trace(m_targetForTouchID); |
| 106 } | 119 } |
| 107 | 120 |
| 108 WebInputEventResult TouchEventManager::dispatchTouchEvents( | 121 WebInputEventResult TouchEventManager::dispatchTouchEvents( |
| 109 const PlatformTouchEvent& event, | 122 const PlatformTouchEvent& event, |
| 110 const HeapVector<TouchInfo>& touchInfos, | 123 const HeapVector<TouchInfo>& touchInfos, |
| 111 bool allTouchesReleased) { | 124 bool allTouchesReleased) { |
| 112 // Build up the lists to use for the |touches|, |targetTouches| and | 125 // Build up the lists to use for the |touches|, |targetTouches| and |
| 113 // |changedTouches| attributes in the JS event. See | 126 // |changedTouches| attributes in the JS event. See |
| 114 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these | 127 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these |
| 115 // lists fit together. | 128 // lists fit together. |
| 116 | 129 |
| 130 // Suppress all the touch moves in the slop region. |
| 131 if (IsTouchSequenceStart(event)) |
| 132 m_suppressingTouchmovesWithinSlop = true; |
| 133 |
| 134 if (event.type() == PlatformEvent::TouchEnd || |
| 135 event.type() == PlatformEvent::TouchCancel || |
| 136 event.touchPoints().size() > 1) { |
| 137 m_suppressingTouchmovesWithinSlop = false; |
| 138 } |
| 139 |
| 140 if (m_suppressingTouchmovesWithinSlop && |
| 141 event.type() == PlatformEvent::TouchMove) { |
| 142 if (!event.causesScrollingIfUncanceled()) |
| 143 return WebInputEventResult::HandledSuppressed; |
| 144 m_suppressingTouchmovesWithinSlop = false; |
| 145 } |
| 146 |
| 117 // Holds the complete set of touches on the screen. | 147 // Holds the complete set of touches on the screen. |
| 118 TouchList* touches = TouchList::create(); | 148 TouchList* touches = TouchList::create(); |
| 119 | 149 |
| 120 // A different view on the 'touches' list above, filtered and grouped by | 150 // A different view on the 'touches' list above, filtered and grouped by |
| 121 // event target. Used for the |targetTouches| list in the JS event. | 151 // event target. Used for the |targetTouches| list in the JS event. |
| 122 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>; | 152 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>; |
| 123 TargetTouchesHeapMap touchesByTarget; | 153 TargetTouchesHeapMap touchesByTarget; |
| 124 | 154 |
| 125 // Array of touches per state, used to assemble the |changedTouches| list. | 155 // Array of touches per state, used to assemble the |changedTouches| list. |
| 126 ChangedTouches changedTouches[PlatformTouchPoint::TouchStateEnd]; | 156 ChangedTouches changedTouches[PlatformTouchPoint::TouchStateEnd]; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 535 } |
| 506 | 536 |
| 507 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 537 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
| 508 } | 538 } |
| 509 | 539 |
| 510 bool TouchEventManager::isAnyTouchActive() const { | 540 bool TouchEventManager::isAnyTouchActive() const { |
| 511 return m_touchPressed; | 541 return m_touchPressed; |
| 512 } | 542 } |
| 513 | 543 |
| 514 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |