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