Chromium Code Reviews| 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 #ifndef TouchEventManager_h | 5 #ifndef TouchEventManager_h |
| 6 #define TouchEventManager_h | 6 #define TouchEventManager_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/events/PointerEventFactory.h" | 9 #include "core/events/PointerEventFactory.h" |
| 10 #include "core/input/EventHandlingUtil.h" | 10 #include "core/input/EventHandlingUtil.h" |
| 11 #include "platform/graphics/TouchAction.h" | 11 #include "platform/graphics/TouchAction.h" |
| 12 #include "platform/wtf/Allocator.h" | 12 #include "platform/wtf/Allocator.h" |
| 13 #include "platform/wtf/HashMap.h" | 13 #include "platform/wtf/HashMap.h" |
| 14 #include "platform/wtf/Vector.h" | 14 #include "platform/wtf/Vector.h" |
| 15 #include "public/platform/WebCoalescedInputEvent.h" | |
| 15 #include "public/platform/WebInputEventResult.h" | 16 #include "public/platform/WebInputEventResult.h" |
| 17 #include "public/platform/WebPointerEvent.h" | |
| 16 #include "public/platform/WebTouchPoint.h" | 18 #include "public/platform/WebTouchPoint.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 class LocalFrame; | 22 class LocalFrame; |
| 21 class Document; | 23 class Document; |
| 22 class WebTouchEvent; | |
| 23 | 24 |
| 24 // This class takes care of dispatching all touch events and | 25 // This class takes care of dispatching all touch events and |
| 25 // maintaining related states. | 26 // maintaining related states. |
| 26 class CORE_EXPORT TouchEventManager | 27 class CORE_EXPORT TouchEventManager |
| 27 : public GarbageCollectedFinalized<TouchEventManager> { | 28 : public GarbageCollectedFinalized<TouchEventManager> { |
| 28 WTF_MAKE_NONCOPYABLE(TouchEventManager); | 29 WTF_MAKE_NONCOPYABLE(TouchEventManager); |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 | 32 |
| 32 explicit TouchEventManager(LocalFrame&); | 33 explicit TouchEventManager(LocalFrame&); |
| 33 DECLARE_TRACE(); | 34 DECLARE_TRACE(); |
| 34 | 35 |
| 35 // The entries in touch point array of WebTouchEvent (i.e. first parameter) | 36 void HandleTouchPoint(const WebPointerEvent&, |
| 36 // correspond to the entries of the PointerEventTargets (i.e. last parameter). | 37 const Vector<WebPointerEvent>&, |
| 37 WebInputEventResult HandleTouchEvent( | 38 const EventHandlingUtil::PointerEventTarget&); |
| 38 const WebTouchEvent&, | 39 |
| 39 const Vector<WebTouchEvent>&, | 40 WebInputEventResult HandleVSyncSignal(); |
| 40 const HeapVector<EventHandlingUtil::PointerEventTarget>&); | |
| 41 | 41 |
| 42 // Resets the internal state of this object. | 42 // Resets the internal state of this object. |
| 43 void Clear(); | 43 void Clear(); |
| 44 | 44 |
| 45 // Returns whether there is any touch on the screen. | 45 // Returns whether there is any touch on the screen. |
| 46 bool IsAnyTouchActive() const; | 46 bool IsAnyTouchActive() const; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 Touch* CreateDomTouch(const WebTouchPoint&, bool* known_target); | 49 class TouchPointAttributes |
| 50 : public GarbageCollectedFinalized<TouchPointAttributes> { | |
| 51 public: | |
| 52 DEFINE_INLINE_TRACE() { visitor->Trace(target_); } | |
| 50 | 53 |
| 51 void UpdateTargetAndRegionMapsForTouchStart( | 54 TouchPointAttributes() {} |
| 52 const WebTouchPoint&, | 55 explicit TouchPointAttributes(WebPointerEvent event) |
| 56 : event_(event), stale_(false) {} | |
| 57 | |
| 58 // Last state of the touch point. | |
| 59 WebPointerEvent event_; | |
| 60 // The list of coalesced events if there is any. Note that at the end of | |
|
mustaq
2017/06/09 16:12:27
Please clarify if this list include all TEs, or on
Navid Zolghadr
2017/06/12 16:17:32
Done.
| |
| 61 // each frame this list gets cleared. | |
| 62 Vector<WebPointerEvent> coalesced_events_; | |
| 63 Member<Node> target_; // The target of each active touch point. | |
| 64 String region_; // // The region of each active touch point. | |
| 65 bool stale_; | |
| 66 }; | |
| 67 | |
| 68 WebCoalescedInputEvent GenerateWebCoalescedInputEvent(); | |
| 69 Touch* CreateDomTouch(const TouchPointAttributes*, bool* known_target); | |
| 70 void allTouchesReleasedCleanup(); | |
| 71 | |
| 72 // Keeps track of attributes of the touch point in the | |
| 73 // |touch_points_attributes_| map and does the hit-testing if the original hit | |
| 74 // test result was not inside capturing frame |touch_sequence_document_| for | |
| 75 // touch events. | |
| 76 void UpdateTouchAttributeMapsForPointerDown( | |
| 77 const WebPointerEvent&, | |
| 53 const EventHandlingUtil::PointerEventTarget&); | 78 const EventHandlingUtil::PointerEventTarget&); |
| 54 | 79 |
| 55 // Does the hit-testing if the original hit test result was not inside | 80 WebInputEventResult DispatchTouchEvents(); |
|
mustaq
2017/06/09 16:12:29
Rename to something like DispatchAccumulatedTouchE
Navid Zolghadr
2017/06/12 16:17:32
Done.
| |
| 56 // capturing frame for touch events. Returns true if touch events could be | |
| 57 // dispatched and otherwise returns false. | |
| 58 bool HitTestTouchPointsIfNeeded( | |
| 59 const WebTouchEvent&, | |
| 60 const HeapVector<EventHandlingUtil::PointerEventTarget>&); | |
| 61 | |
| 62 WebInputEventResult DispatchTouchEvents(const WebTouchEvent&, | |
| 63 const Vector<WebTouchEvent>&, | |
| 64 bool all_touches_released); | |
| 65 | 81 |
| 66 // NOTE: If adding a new field to this class please ensure that it is | 82 // NOTE: If adding a new field to this class please ensure that it is |
| 67 // cleared in |TouchEventManager::clear()|. | 83 // cleared in |TouchEventManager::clear()|. |
| 68 | 84 |
| 69 const Member<LocalFrame> frame_; | 85 const Member<LocalFrame> frame_; |
| 70 | 86 |
| 71 // The target of each active touch point indexed by the touch ID. | 87 using TouchAttributeMap = |
|
mustaq
2017/06/09 16:12:27
Please keep the past comment re "indexed by touch
Navid Zolghadr
2017/06/12 16:17:32
Done.
| |
| 72 using TouchTargetMap = | 88 HeapHashMap<int, |
| 73 HeapHashMap<unsigned, | 89 Member<TouchPointAttributes>, |
| 74 Member<Node>, | 90 WTF::IntHash<int>, |
| 75 DefaultHash<unsigned>::Hash, | 91 WTF::UnsignedWithZeroKeyHashTraits<int>>; |
| 76 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; | 92 TouchAttributeMap touch_points_attributes_; |
|
mustaq
2017/06/09 16:12:29
Nit: I would avoid double plural in the name. s/to
Navid Zolghadr
2017/06/12 16:17:32
Done.
| |
| 77 TouchTargetMap target_for_touch_id_; | |
| 78 using TouchRegionMap = HashMap<unsigned, | |
| 79 String, | |
| 80 DefaultHash<unsigned>::Hash, | |
| 81 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; | |
| 82 TouchRegionMap region_for_touch_id_; | |
| 83 | 93 |
| 84 // If set, the document of the active touch sequence. Unset if no touch | 94 // If set, the document of the active touch sequence. Unset if no touch |
| 85 // sequence active. | 95 // sequence active. |
| 86 Member<Document> touch_sequence_document_; | 96 Member<Document> touch_sequence_document_; |
| 87 | 97 |
| 88 bool touch_pressed_; | |
| 89 bool suppressing_touchmoves_within_slop_; | 98 bool suppressing_touchmoves_within_slop_; |
| 90 | 99 |
| 91 // The current touch action, computed on each touch start and is | 100 // The current touch action, computed on each touch start and is |
| 92 // a union of all touches. Reset when all touches are released. | 101 // a union of all touches. Reset when all touches are released. |
| 93 TouchAction current_touch_action_; | 102 TouchAction current_touch_action_; |
| 94 }; | 103 }; |
| 95 | 104 |
| 96 } // namespace blink | 105 } // namespace blink |
| 97 | 106 |
| 98 #endif // TouchEventManager_h | 107 #endif // TouchEventManager_h |
| OLD | NEW |