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 PointerIdManager_h | 5 #ifndef PointerIdManager_h |
6 #define PointerIdManager_h | 6 #define PointerIdManager_h |
7 | 7 |
8 #include "core/CoreExport.h" | |
8 #include "public/platform/WebPointerProperties.h" | 9 #include "public/platform/WebPointerProperties.h" |
9 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
10 #include "wtf/ListHashSet.h" | 11 #include "wtf/HashMap.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 /** | 15 /** |
15 Helper class for tracking the primary pointer id for each type of PointerEvent s. | 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 th e | |
18 domain of the id (i.e. in touch or pen) the corresponding pointer event will h ave | |
19 a unique id amongst all pointer events as per pointer events' specification. | |
20 This class intended to behave the same as existing browsers as much as possibl e | |
21 for compatibility reasons. Particularly it behaves very similar to MS Edge to have | |
22 pointer event ids generated by mouse always equal 1 and those that are generat ed | |
23 by touch and pen will have increasing ids from 2. | |
16 */ | 24 */ |
17 class PointerIdManager { | 25 class CORE_EXPORT PointerIdManager { |
18 DISALLOW_NEW(); | 26 DISALLOW_NEW(); |
19 public: | 27 public: |
28 typedef unsigned MappedId; | |
29 typedef std::pair<WebPointerProperties::PointerType, unsigned> GeneratedPoin ter; | |
30 static const MappedId s_invalidId; | |
20 PointerIdManager(); | 31 PointerIdManager(); |
21 ~PointerIdManager(); | 32 ~PointerIdManager(); |
22 void clear(); | 33 void clear(); |
23 void add(WebPointerProperties::PointerType, unsigned); | 34 MappedId add(const GeneratedPointer); |
24 void remove(WebPointerProperties::PointerType, unsigned); | 35 void remove(const GeneratedPointer); |
mustaq
2015/11/20 20:13:53
Two remove()s is confusing. just pass a ref to Poi
| |
25 bool isPrimary(WebPointerProperties::PointerType, unsigned); | 36 void remove(const MappedId); |
37 bool isPrimary(const MappedId) const; | |
38 MappedId getPrimaryId(const WebPointerProperties::PointerType) const; | |
39 WebPointerProperties::PointerType getType(const MappedId) const; | |
26 | 40 |
27 private: | 41 private: |
28 // TODO(crbug.com/537319): Switch to /one/ set of ids to guarantee uniquenes s. | 42 PointerIdManager::MappedId m_currentId; |
29 ListHashSet<unsigned> m_ids[static_cast<int>(WebPointerProperties::PointerTy pe::LastEntry) + 1]; | 43 HashMap<unsigned, MappedId, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKey HashTraits<unsigned>> m_ids[static_cast<int>(WebPointerProperties::PointerType:: LastEntry) + 1]; |
30 bool m_hasPrimaryId[static_cast<int>(WebPointerProperties::PointerType::Last Entry) + 1]; | 44 HashMap<MappedId, GeneratedPointer, WTF::IntHash<unsigned>, WTF::UnsignedWit hZeroKeyHashTraits<unsigned>> m_reverseMapping; |
45 MappedId m_primaryId[static_cast<int>(WebPointerProperties::PointerType::Las tEntry) + 1]; | |
31 }; | 46 }; |
32 | 47 |
33 } // namespace blink | 48 } // namespace blink |
34 | 49 |
35 #endif // PointerIdManager_h | 50 #endif // PointerIdManager_h |
OLD | NEW |