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 PointerIdManager::PointerIdManager() |
| 11 { |
| 12 clear(); |
| 13 } |
| 14 |
| 15 PointerIdManager::~PointerIdManager() |
| 16 { |
| 17 clear(); |
| 18 } |
| 19 |
| 20 void PointerIdManager::clear() |
| 21 { |
| 22 for (int type = 0; type < static_cast<int>(PointerTypeLastEntry); type++) { |
| 23 m_ids[type].clear(); |
| 24 m_hasPrimaryId[type] = false; |
| 25 } |
| 26 } |
| 27 |
| 28 void PointerIdManager::add(PointerType type, unsigned id) |
| 29 { |
| 30 if (m_ids[type].isEmpty()) |
| 31 m_hasPrimaryId[type] = true; |
| 32 m_ids[type].add(id); |
| 33 } |
| 34 |
| 35 void PointerIdManager::remove(PointerType type, unsigned id) |
| 36 { |
| 37 if (isPrimary(type, id)) { |
| 38 m_ids[type].removeFirst(); |
| 39 m_hasPrimaryId[type] = false; |
| 40 } else { |
| 41 // Note that simply counting the number of ids instead of storing all of
them is not enough. |
| 42 // When id is absent, remove() should be a no-op. |
| 43 m_ids[type].remove(id); |
| 44 } |
| 45 } |
| 46 |
| 47 bool PointerIdManager::isPrimary(PointerType type, unsigned id) |
| 48 { |
| 49 return m_hasPrimaryId[type] && m_ids[type].first() == id; |
| 50 } |
| 51 |
| 52 } // namespace blink |
OLD | NEW |