| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 PointerEventManager_h | 5 #ifndef PointerEventManager_h |
| 6 #define PointerEventManager_h | 6 #define PointerEventManager_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/events/PointerEvent.h" | 9 #include "core/events/PointerEvent.h" |
| 10 #include "public/platform/WebPointerProperties.h" | 10 #include "public/platform/WebPointerProperties.h" |
| 11 #include "wtf/Allocator.h" | 11 #include "wtf/Allocator.h" |
| 12 #include "wtf/HashMap.h" | 12 #include "wtf/HashMap.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 Helper class for tracking the pointer ids for each type of PointerEvents. | 17 Helper class for tracking the pointer ids for each type of PointerEvents. |
| 18 Using id re-mapping at this layer, this class makes sure that regardless of th
e | 18 Using id re-mapping at this layer, this class makes sure that regardless of th
e |
| 19 domain of the id (i.e. in touch or pen) the corresponding pointer event will h
ave | 19 domain of the id (i.e. in touch or pen) the corresponding pointer event will h
ave |
| 20 a unique id amongst all pointer events as per pointer events' specification. | 20 a unique id amongst all pointer events as per pointer events' specification. |
| 21 This class intended to behave the same as existing browsers as much as possibl
e | 21 This class intended to behave the same as existing browsers as much as possibl
e |
| 22 for compatibility reasons. Particularly it behaves very similar to MS Edge to
have | 22 for compatibility reasons. Particularly it behaves very similar to MS Edge to
have |
| 23 pointer event ids generated by mouse always equal 1 and those that are generat
ed | 23 pointer event ids generated by mouse always equal 1 and those that are generat
ed |
| 24 by touch and pen will have increasing ids from 2. | 24 by touch and pen will have increasing ids from 2. |
| 25 */ | 25 */ |
| 26 class CORE_EXPORT PointerEventManager { | 26 class CORE_EXPORT PointerEventManager { |
| 27 DISALLOW_NEW(); | 27 DISALLOW_NEW(); |
| 28 public: | 28 public: |
| 29 | 29 |
| 30 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | 30 RawPtr<PointerEvent> create(const AtomicString& type, |
| 31 const PlatformMouseEvent&, PassRefPtrWillBeRawPtr<Node> relatedTarget, | 31 const PlatformMouseEvent&, RawPtr<Node> relatedTarget, |
| 32 PassRefPtrWillBeRawPtr<AbstractView>); | 32 RawPtr<AbstractView>); |
| 33 | 33 |
| 34 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | 34 RawPtr<PointerEvent> create(const AtomicString& type, |
| 35 const PlatformTouchPoint&, PlatformEvent::Modifiers, | 35 const PlatformTouchPoint&, PlatformEvent::Modifiers, |
| 36 const double width, const double height, | 36 const double width, const double height, |
| 37 const double clientX, const double clientY); | 37 const double clientX, const double clientY); |
| 38 | 38 |
| 39 PassRefPtrWillBeRawPtr<PointerEvent> createPointerCancel(const PlatformTouch
Point&); | 39 RawPtr<PointerEvent> createPointerCancel(const PlatformTouchPoint&); |
| 40 | 40 |
| 41 PointerEventManager(); | 41 PointerEventManager(); |
| 42 ~PointerEventManager(); | 42 ~PointerEventManager(); |
| 43 | 43 |
| 44 // Clear all the existing ids. | 44 // Clear all the existing ids. |
| 45 void clear(); | 45 void clear(); |
| 46 /* | 46 /* |
| 47 * When a pointerEvent with a particular id is removed that id is considered | 47 * When a pointerEvent with a particular id is removed that id is considered |
| 48 * free even though there might have been other PointerEvents that were | 48 * free even though there might have been other PointerEvents that were |
| 49 * generated with the same id before. | 49 * generated with the same id before. |
| 50 */ | 50 */ |
| 51 void remove(const PassRefPtrWillBeRawPtr<PointerEvent>); | 51 void remove(const RawPtr<PointerEvent>); |
| 52 | 52 |
| 53 // Returns the node capturing this pointer id, and null if no node is captur
ing it. | 53 // Returns the node capturing this pointer id, and null if no node is captur
ing it. |
| 54 EventTarget* getCapturingNode(PassRefPtrWillBeRawPtr<PointerEvent>); | 54 EventTarget* getCapturingNode(RawPtr<PointerEvent>); |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 typedef long MappedId; | 57 typedef long MappedId; |
| 58 typedef std::pair<int, int> IncomingId; | 58 typedef std::pair<int, int> IncomingId; |
| 59 | 59 |
| 60 MappedId add(const IncomingId); | 60 MappedId add(const IncomingId); |
| 61 bool isPrimary(const MappedId) const; | 61 bool isPrimary(const MappedId) const; |
| 62 void setIdAndType(PointerEventInit &, const WebPointerProperties &); | 62 void setIdAndType(PointerEventInit &, const WebPointerProperties &); |
| 63 | 63 |
| 64 static const MappedId s_invalidId; | 64 static const MappedId s_invalidId; |
| 65 static const MappedId s_mouseId; | 65 static const MappedId s_mouseId; |
| 66 | 66 |
| 67 PointerEventManager::MappedId m_currentId; | 67 PointerEventManager::MappedId m_currentId; |
| 68 HashMap<IncomingId, MappedId, WTF::PairHash<int, int>, WTF::PairHashTraits<W
TF::UnsignedWithZeroKeyHashTraits<int>, WTF::UnsignedWithZeroKeyHashTraits<int>>
> m_idMapping; | 68 HashMap<IncomingId, MappedId, WTF::PairHash<int, int>, WTF::PairHashTraits<W
TF::UnsignedWithZeroKeyHashTraits<int>, WTF::UnsignedWithZeroKeyHashTraits<int>>
> m_idMapping; |
| 69 HashMap<MappedId, IncomingId, WTF::IntHash<MappedId>, WTF::UnsignedWithZeroK
eyHashTraits<MappedId>> m_idReverseMapping; | 69 HashMap<MappedId, IncomingId, WTF::IntHash<MappedId>, WTF::UnsignedWithZeroK
eyHashTraits<MappedId>> m_idReverseMapping; |
| 70 MappedId m_primaryId[static_cast<int>(WebPointerProperties::PointerType::Las
tEntry) + 1]; | 70 MappedId m_primaryId[static_cast<int>(WebPointerProperties::PointerType::Las
tEntry) + 1]; |
| 71 MappedId m_idCount[static_cast<int>(WebPointerProperties::PointerType::LastE
ntry) + 1]; | 71 MappedId m_idCount[static_cast<int>(WebPointerProperties::PointerType::LastE
ntry) + 1]; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 } // namespace blink | 74 } // namespace blink |
| 75 | 75 |
| 76 #endif // PointerEventManager_h | 76 #endif // PointerEventManager_h |
| OLD | NEW |