OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/events/PointerIdManager.h" | |
7 | |
8 namespace blink { | |
9 | |
10 namespace { | |
11 | |
12 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(
t); } | |
13 | |
14 } // namespace | |
15 | |
16 PointerIdManager::PointerIdManager() | |
17 { | |
18 clear(); | |
19 } | |
20 | |
21 PointerIdManager::~PointerIdManager() | |
22 { | |
23 clear(); | |
24 } | |
25 | |
26 void PointerIdManager::clear() | |
27 { | |
28 for (int type = 0; type <= toInt(WebPointerProperties::PointerType::LastEntr
y); type++) { | |
29 m_ids[type].clear(); | |
30 m_hasPrimaryId[type] = false; | |
31 } | |
32 } | |
33 | |
34 void PointerIdManager::add(WebPointerProperties::PointerType type, unsigned id) | |
35 { | |
36 if (m_ids[toInt(type)].isEmpty()) | |
37 m_hasPrimaryId[toInt(type)] = true; | |
38 m_ids[toInt(type)].add(id); | |
39 } | |
40 | |
41 void PointerIdManager::remove(WebPointerProperties::PointerType type, unsigned i
d) | |
42 { | |
43 if (isPrimary(type, id)) { | |
44 m_ids[toInt(type)].removeFirst(); | |
45 m_hasPrimaryId[toInt(type)] = false; | |
46 } else { | |
47 // Note that simply counting the number of ids instead of storing all of
them is not enough. | |
48 // When id is absent, remove() should be a no-op. | |
49 m_ids[toInt(type)].remove(id); | |
50 } | |
51 } | |
52 | |
53 bool PointerIdManager::isPrimary(WebPointerProperties::PointerType type, unsigne
d id) | |
54 { | |
55 return m_hasPrimaryId[toInt(type)] && m_ids[toInt(type)].first() == id; | |
56 } | |
57 | |
58 } // namespace blink | |
OLD | NEW |