Chromium Code Reviews| Index: Source/core/events/PointerEventUtils.cpp |
| diff --git a/Source/core/events/PointerEventUtils.cpp b/Source/core/events/PointerEventUtils.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b078f6f52440b1cd464df9514d8b4f00eef54fd6 |
| --- /dev/null |
| +++ b/Source/core/events/PointerEventUtils.cpp |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/events/PointerEventUtils.h" |
| + |
| +namespace blink { |
| + |
| +PointerIdManager::PointerIdManager() |
| +{ |
| + clear(); |
| +} |
| + |
| +PointerIdManager::~PointerIdManager() |
| +{ |
| + clear(); |
| +} |
| + |
| +void PointerIdManager::clear() |
| +{ |
| + for (int type = 0; type < static_cast<int>(PointerTypeLastEntry); type++) { |
| + m_ids[type].clear(); |
| + m_hasPrimaryId[type] = false; |
| + } |
| +} |
| + |
| +void PointerIdManager::add(PointerType type, unsigned id) |
| +{ |
| + if (m_ids[type].isEmpty()) |
| + m_hasPrimaryId[type] = true; |
|
Rick Byers
2015/06/16 17:25:39
ASSERT(!m_hasPrimaryId[type]) ?
mustaq
2015/06/16 20:18:42
I relied on deduping-through-set here instead of a
Rick Byers
2015/06/18 17:40:07
Oh right, clusterfuzz can definitely trigger this
mustaq
2015/06/18 18:20:53
Acknowledged.
|
| + m_ids[type].add(id); |
| +} |
| + |
| +void PointerIdManager::remove(PointerType type, unsigned id) |
| +{ |
| + if (isPrimary(type, id)) { |
| + m_ids[type].removeFirst(); |
| + m_hasPrimaryId[type] = false; |
|
Rick Byers
2015/06/16 17:25:39
ASSERT(m_hasPrimaryId[type]) ?
mustaq
2015/06/16 20:18:42
Ditto.
|
| + } else { |
| + // Note that simply counting the number of ids instead of storing all of them is not enough. |
| + // When id is absent, remove() should be a no-op. |
| + m_ids[type].remove(id); |
| + } |
| +} |
| + |
| +bool PointerIdManager::isPrimary(PointerType type, unsigned id) |
| +{ |
| + return m_hasPrimaryId[type] && m_ids[type].first() == id; |
| +} |
| + |
| +} // namespace blink |