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 /* | |
53 * When a pointerEvent with a particular id is removed that id is considered | |
54 * free even though there might have been other PointerEvents that were | |
55 * generated with the same id before. | |
56 */ | |
Ian Vollick
2016/02/12 16:41:32
nit: //.
Navid Zolghadr
2016/02/12 16:43:55
Will fix it.
| |
57 void remove(const PassRefPtrWillBeRawPtr<PointerEvent>); | |
58 | |
59 private: | |
60 typedef std::pair<int, int> IncomingId; | |
61 typedef WTF::UnsignedWithZeroKeyHashTraits<int> UnsignedHash; | |
62 | |
63 int add(const IncomingId); | |
64 bool isPrimary(const int) const; | |
65 void setIdAndType(PointerEventInit &, const WebPointerProperties &); | |
66 | |
67 static const int s_invalidId; | |
68 static const int s_mouseId; | |
69 | |
70 int m_currentId; | |
71 HashMap<IncomingId, int, WTF::PairHash<int, int>, WTF::PairHashTraits<Unsign edHash, UnsignedHash>> m_idMapping; | |
72 HashMap<int, IncomingId, WTF::IntHash<int>, UnsignedHash> m_idReverseMapping ; | |
73 int m_primaryId[static_cast<int>(WebPointerProperties::PointerType::LastEntr y) + 1]; | |
74 int m_idCount[static_cast<int>(WebPointerProperties::PointerType::LastEntry) + 1]; | |
75 }; | |
76 | |
77 } // namespace blink | |
78 | |
79 #endif // PointerEventFactory_h | |
OLD | NEW |