OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
Ian Vollick
2016/02/12 15:01:17
2016
Navid Zolghadr
2016/02/12 16:30:47
Done.
| |
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 /** | |
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 | |
19 the domain of the id (i.e. in touch or pen) the corresponding pointer event | |
20 will have a unique id amongst all pointer events as per pointer events' | |
Ian Vollick
2016/02/12 15:01:17
nit: I'd use // to be consistent with the license
Navid Zolghadr
2016/02/12 16:30:47
Done.
| |
21 specification. This class intended to behave the same as existing browsers as | |
22 much as possible for compatibility reasons. Particularly it behaves very | |
23 similar to MS Edge to have pointer event ids generated by mouse always equal 1 | |
24 and those that are generated by touch and pen will have increasing ids from 2. | |
25 */ | |
26 class CORE_EXPORT PointerEventFactory { | |
27 DISALLOW_NEW(); | |
28 public: | |
29 | |
30 PointerEventFactory(); | |
31 ~PointerEventFactory(); | |
32 | |
33 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | |
34 const PlatformMouseEvent&, PassRefPtrWillBeRawPtr<Node> relatedTarget, | |
35 PassRefPtrWillBeRawPtr<AbstractView>); | |
36 | |
37 PassRefPtrWillBeRawPtr<PointerEvent> create(const AtomicString& type, | |
38 const PlatformTouchPoint&, PlatformEvent::Modifiers, | |
39 const double width, const double height, | |
40 const double clientX, const double clientY); | |
41 | |
42 PassRefPtrWillBeRawPtr<PointerEvent> createPointerCancel( | |
43 const PlatformTouchPoint&); | |
44 | |
45 PassRefPtrWillBeRawPtr<PointerEvent> create( | |
46 PassRefPtrWillBeRawPtr<PointerEvent>, | |
47 const AtomicString& type, | |
48 PassRefPtrWillBeRawPtr<EventTarget>); | |
49 | |
50 // Clear all the existing ids. | |
51 void clear(); | |
52 | |
53 /* | |
54 * When a pointerEvent with a particular id is removed that id is considered | |
55 * free even though there might have been other PointerEvents that were | |
56 * generated with the same id before. | |
57 */ | |
58 void remove(const PassRefPtrWillBeRawPtr<PointerEvent>); | |
59 | |
60 private: | |
61 typedef std::pair<int, int> IncomingId; | |
62 typedef WTF::UnsignedWithZeroKeyHashTraits<int> UnsignedHash; | |
63 | |
64 int add(const IncomingId); | |
65 bool isPrimary(const int) const; | |
66 void setIdAndType(PointerEventInit &, const WebPointerProperties &); | |
67 | |
68 static const int s_invalidId; | |
69 static const int s_mouseId; | |
70 | |
71 int m_currentId; | |
72 HashMap<IncomingId, int, WTF::PairHash<int, int>, WTF::PairHashTraits<Unsign edHash, UnsignedHash>> m_idMapping; | |
73 HashMap<int, IncomingId, WTF::IntHash<int>, UnsignedHash> m_idReverseMapping ; | |
74 int m_primaryId[static_cast<int>(WebPointerProperties::PointerType::LastEntr y) + 1]; | |
75 int m_idCount[static_cast<int>(WebPointerProperties::PointerType::LastEntry) + 1]; | |
76 }; | |
77 | |
78 } // namespace blink | |
79 | |
80 #endif // PointerEventFactory_h | |
OLD | NEW |