| 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 "public/platform/WebInputEventResult.h" | 10 #include "public/platform/WebInputEventResult.h" |
| 11 #include "public/platform/WebTouchPoint.h" |
| 11 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
| 12 #include "wtf/HashMap.h" | 13 #include "wtf/HashMap.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class LocalFrame; | 17 class LocalFrame; |
| 17 class Document; | 18 class Document; |
| 18 class PlatformTouchEvent; | 19 class WebTouchEvent; |
| 19 | 20 |
| 20 // This class takes care of dispatching all touch events and | 21 // This class takes care of dispatching all touch events and |
| 21 // maintaining related states. | 22 // maintaining related states. |
| 22 class CORE_EXPORT TouchEventManager | 23 class CORE_EXPORT TouchEventManager |
| 23 : public GarbageCollectedFinalized<TouchEventManager> { | 24 : public GarbageCollectedFinalized<TouchEventManager> { |
| 24 WTF_MAKE_NONCOPYABLE(TouchEventManager); | 25 WTF_MAKE_NONCOPYABLE(TouchEventManager); |
| 25 | 26 |
| 26 public: | 27 public: |
| 27 class TouchInfo { | 28 class TouchInfo { |
| 28 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 29 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 DEFINE_INLINE_TRACE() { | 32 DEFINE_INLINE_TRACE() { |
| 32 visitor->trace(touchNode); | 33 visitor->trace(touchNode); |
| 33 visitor->trace(targetFrame); | 34 visitor->trace(targetFrame); |
| 34 } | 35 } |
| 35 | 36 |
| 36 PlatformTouchPoint point; | 37 WebTouchPoint point; |
| 37 Member<Node> touchNode; | 38 Member<Node> touchNode; |
| 38 Member<LocalFrame> targetFrame; | 39 Member<LocalFrame> targetFrame; |
| 39 FloatPoint contentPoint; | 40 FloatPoint contentPoint; |
| 40 FloatSize adjustedRadius; | 41 FloatSize adjustedRadius; |
| 41 bool knownTarget; | 42 bool knownTarget; |
| 42 String region; | 43 String region; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 explicit TouchEventManager(LocalFrame&); | 46 explicit TouchEventManager(LocalFrame&); |
| 46 DECLARE_TRACE(); | 47 DECLARE_TRACE(); |
| 47 | 48 |
| 48 // Does the hit-testing again if the original hit test result was not inside | 49 // Does the hit-testing again if the original hit test result was not inside |
| 49 // capturing frame for touch events. Returns true if touch events could be | 50 // capturing frame for touch events. Returns true if touch events could be |
| 50 // dispatched and otherwise returns false. | 51 // dispatched and otherwise returns false. |
| 51 bool reHitTestTouchPointsIfNeeded(const PlatformTouchEvent&, | 52 bool reHitTestTouchPointsIfNeeded(const WebTouchEvent&, |
| 52 HeapVector<TouchInfo>&); | 53 HeapVector<TouchInfo>&); |
| 53 | 54 |
| 54 // The TouchInfo array is reference just to prevent the copy. However, it | 55 // The TouchInfo array is reference just to prevent the copy. However, it |
| 55 // cannot be const as this function might change some of the properties in | 56 // cannot be const as this function might change some of the properties in |
| 56 // TouchInfo objects. | 57 // TouchInfo objects. |
| 57 WebInputEventResult handleTouchEvent(const PlatformTouchEvent&, | 58 WebInputEventResult handleTouchEvent(const WebTouchEvent&, |
| 58 HeapVector<TouchInfo>&); | 59 HeapVector<TouchInfo>&); |
| 59 | 60 |
| 60 // Resets the internal state of this object. | 61 // Resets the internal state of this object. |
| 61 void clear(); | 62 void clear(); |
| 62 | 63 |
| 63 // Returns whether there is any touch on the screen. | 64 // Returns whether there is any touch on the screen. |
| 64 bool isAnyTouchActive() const; | 65 bool isAnyTouchActive() const; |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 void updateTargetAndRegionMapsForTouchStarts(HeapVector<TouchInfo>&); | 68 void updateTargetAndRegionMapsForTouchStarts(HeapVector<TouchInfo>&); |
| 68 void setAllPropertiesOfTouchInfos(HeapVector<TouchInfo>&); | 69 void setAllPropertiesOfTouchInfos(HeapVector<TouchInfo>&); |
| 69 | 70 |
| 70 WebInputEventResult dispatchTouchEvents(const PlatformTouchEvent&, | 71 WebInputEventResult dispatchTouchEvents(const WebTouchEvent&, |
| 71 const HeapVector<TouchInfo>&, | 72 const HeapVector<TouchInfo>&, |
| 72 bool allTouchesReleased); | 73 bool allTouchesReleased); |
| 73 | 74 |
| 74 // NOTE: If adding a new field to this class please ensure that it is | 75 // NOTE: If adding a new field to this class please ensure that it is |
| 75 // cleared in |TouchEventManager::clear()|. | 76 // cleared in |TouchEventManager::clear()|. |
| 76 | 77 |
| 77 const Member<LocalFrame> m_frame; | 78 const Member<LocalFrame> m_frame; |
| 78 | 79 |
| 79 // The target of each active touch point indexed by the touch ID. | 80 // The target of each active touch point indexed by the touch ID. |
| 80 using TouchTargetMap = | 81 using TouchTargetMap = |
| 81 HeapHashMap<unsigned, | 82 HeapHashMap<unsigned, |
| 82 Member<Node>, | 83 Member<Node>, |
| 83 DefaultHash<unsigned>::Hash, | 84 DefaultHash<unsigned>::Hash, |
| 84 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; | 85 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; |
| 85 TouchTargetMap m_targetForTouchID; | 86 TouchTargetMap m_targetForTouchID; |
| 86 using TouchRegionMap = HashMap<unsigned, | 87 using TouchRegionMap = HashMap<unsigned, |
| 87 String, | 88 String, |
| 88 DefaultHash<unsigned>::Hash, | 89 DefaultHash<unsigned>::Hash, |
| 89 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; | 90 WTF::UnsignedWithZeroKeyHashTraits<unsigned>>; |
| 90 TouchRegionMap m_regionForTouchID; | 91 TouchRegionMap m_regionForTouchID; |
| 91 | 92 |
| 92 // If set, the document of the active touch sequence. Unset if no touch | 93 // If set, the document of the active touch sequence. Unset if no touch |
| 93 // sequence active. | 94 // sequence active. |
| 94 Member<Document> m_touchSequenceDocument; | 95 Member<Document> m_touchSequenceDocument; |
| 95 | 96 |
| 96 bool m_touchPressed; | 97 bool m_touchPressed; |
| 97 // The touch event currently being handled or NoType if none. | |
| 98 PlatformEvent::EventType m_currentEvent; | |
| 99 | 98 |
| 100 // The current touch action, computed on each touch start and is | 99 // The current touch action, computed on each touch start and is |
| 101 // a union of all touches. Reset when all touches are released. | 100 // a union of all touches. Reset when all touches are released. |
| 102 TouchAction m_currentTouchAction; | 101 TouchAction m_currentTouchAction; |
| 103 }; | 102 }; |
| 104 | 103 |
| 105 } // namespace blink | 104 } // namespace blink |
| 106 | 105 |
| 107 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TouchEventManager::TouchInfo); | 106 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TouchEventManager::TouchInfo); |
| 108 | 107 |
| 109 #endif // TouchEventManager_h | 108 #endif // TouchEventManager_h |
| OLD | NEW |