| 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 | |
| 77 // Defining this class type local to dispatchTouchEvents() and annotating | 65 // Defining this class type local to dispatchTouchEvents() and annotating |
| 78 // it with STACK_ALLOCATED(), runs into MSVC(VS 2013)'s C4822 warning | 66 // it with STACK_ALLOCATED(), runs into MSVC(VS 2013)'s C4822 warning |
| 79 // that the local class doesn't provide a local definition for 'operator new'. | 67 // that the local class doesn't provide a local definition for 'operator new'. |
| 80 // Which it intentionally doesn't and shouldn't. | 68 // Which it intentionally doesn't and shouldn't. |
| 81 // | 69 // |
| 82 // Work around such toolchain bugginess by lifting out the type, thereby | 70 // Work around such toolchain bugginess by lifting out the type, thereby |
| 83 // taking it out of C4822's reach. | 71 // taking it out of C4822's reach. |
| 84 class ChangedTouches final { | 72 class ChangedTouches final { |
| 85 STACK_ALLOCATED(); | 73 STACK_ALLOCATED(); |
| 86 | 74 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 TouchEventManager::TouchEventManager(LocalFrame& frame) : m_frame(frame) { | 89 TouchEventManager::TouchEventManager(LocalFrame& frame) : m_frame(frame) { |
| 102 clear(); | 90 clear(); |
| 103 } | 91 } |
| 104 | 92 |
| 105 void TouchEventManager::clear() { | 93 void TouchEventManager::clear() { |
| 106 m_touchSequenceDocument.clear(); | 94 m_touchSequenceDocument.clear(); |
| 107 m_targetForTouchID.clear(); | 95 m_targetForTouchID.clear(); |
| 108 m_regionForTouchID.clear(); | 96 m_regionForTouchID.clear(); |
| 109 m_touchPressed = false; | 97 m_touchPressed = false; |
| 110 m_currentEvent = PlatformEvent::NoType; | 98 m_currentEvent = PlatformEvent::NoType; |
| 111 m_suppressingTouchmovesWithinSlop = false; | |
| 112 m_currentTouchAction = TouchActionAuto; | 99 m_currentTouchAction = TouchActionAuto; |
| 113 } | 100 } |
| 114 | 101 |
| 115 DEFINE_TRACE(TouchEventManager) { | 102 DEFINE_TRACE(TouchEventManager) { |
| 116 visitor->trace(m_frame); | 103 visitor->trace(m_frame); |
| 117 visitor->trace(m_touchSequenceDocument); | 104 visitor->trace(m_touchSequenceDocument); |
| 118 visitor->trace(m_targetForTouchID); | 105 visitor->trace(m_targetForTouchID); |
| 119 } | 106 } |
| 120 | 107 |
| 121 WebInputEventResult TouchEventManager::dispatchTouchEvents( | 108 WebInputEventResult TouchEventManager::dispatchTouchEvents( |
| 122 const PlatformTouchEvent& event, | 109 const PlatformTouchEvent& event, |
| 123 const HeapVector<TouchInfo>& touchInfos, | 110 const HeapVector<TouchInfo>& touchInfos, |
| 124 bool allTouchesReleased) { | 111 bool allTouchesReleased) { |
| 125 // Build up the lists to use for the |touches|, |targetTouches| and | 112 // Build up the lists to use for the |touches|, |targetTouches| and |
| 126 // |changedTouches| attributes in the JS event. See | 113 // |changedTouches| attributes in the JS event. See |
| 127 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these | 114 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these |
| 128 // lists fit together. | 115 // lists fit together. |
| 129 | 116 |
| 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 | |
| 147 // Holds the complete set of touches on the screen. | 117 // Holds the complete set of touches on the screen. |
| 148 TouchList* touches = TouchList::create(); | 118 TouchList* touches = TouchList::create(); |
| 149 | 119 |
| 150 // A different view on the 'touches' list above, filtered and grouped by | 120 // A different view on the 'touches' list above, filtered and grouped by |
| 151 // event target. Used for the |targetTouches| list in the JS event. | 121 // event target. Used for the |targetTouches| list in the JS event. |
| 152 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>; | 122 using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>; |
| 153 TargetTouchesHeapMap touchesByTarget; | 123 TargetTouchesHeapMap touchesByTarget; |
| 154 | 124 |
| 155 // Array of touches per state, used to assemble the |changedTouches| list. | 125 // Array of touches per state, used to assemble the |changedTouches| list. |
| 156 ChangedTouches changedTouches[PlatformTouchPoint::TouchStateEnd]; | 126 ChangedTouches changedTouches[PlatformTouchPoint::TouchStateEnd]; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 505 } |
| 536 | 506 |
| 537 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); | 507 return dispatchTouchEvents(event, touchInfos, allTouchesReleased); |
| 538 } | 508 } |
| 539 | 509 |
| 540 bool TouchEventManager::isAnyTouchActive() const { | 510 bool TouchEventManager::isAnyTouchActive() const { |
| 541 return m_touchPressed; | 511 return m_touchPressed; |
| 542 } | 512 } |
| 543 | 513 |
| 544 } // namespace blink | 514 } // namespace blink |
| OLD | NEW |