| Index: third_party/WebKit/Source/core/events/PointerIdManager.cpp
|
| diff --git a/third_party/WebKit/Source/core/events/PointerIdManager.cpp b/third_party/WebKit/Source/core/events/PointerIdManager.cpp
|
| index a0342b72387e5550842a64cd8307099dc0d7523b..b355b764a96bd50b5d9a2e883e030a7bf2f5f4b4 100644
|
| --- a/third_party/WebKit/Source/core/events/PointerIdManager.cpp
|
| +++ b/third_party/WebKit/Source/core/events/PointerIdManager.cpp
|
| @@ -10,10 +10,15 @@ namespace blink {
|
| namespace {
|
|
|
| inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(t); }
|
| +// Mouse id is 1 to behave the same as MS Edge for compatibility reasons.
|
| +const PointerIdManager::MappedId mouseId = 1;
|
|
|
| } // namespace
|
|
|
| +const PointerIdManager::MappedId PointerIdManager::s_invalidId = 0;
|
| +
|
| PointerIdManager::PointerIdManager()
|
| +: m_currentId(2)
|
| {
|
| clear();
|
| }
|
| @@ -27,32 +32,81 @@ void PointerIdManager::clear()
|
| {
|
| for (int type = 0; type <= toInt(WebPointerProperties::PointerType::LastEntry); type++) {
|
| m_ids[type].clear();
|
| - m_hasPrimaryId[type] = false;
|
| + m_primaryId[type] = PointerIdManager::s_invalidId;
|
| }
|
| + m_reverseMapping.clear();
|
| +
|
| + // Always add mouse pointer in initialization and never remove it.
|
| + // No need to add it to m_ids as it is not going to be used with the existing APIs
|
| + m_primaryId[toInt(WebPointerProperties::PointerType::Mouse)] = mouseId;
|
| + m_reverseMapping.add(mouseId, GeneratedPointer(WebPointerProperties::PointerType::Mouse, 0));
|
| }
|
|
|
| -void PointerIdManager::add(WebPointerProperties::PointerType type, unsigned id)
|
| +PointerIdManager::MappedId PointerIdManager::add(const GeneratedPointer p)
|
| {
|
| - if (m_ids[toInt(type)].isEmpty())
|
| - m_hasPrimaryId[toInt(type)] = true;
|
| - m_ids[toInt(type)].add(id);
|
| + // Do not add extra mouse pointer as it was added in initialization
|
| + if (p.first == WebPointerProperties::PointerType::Mouse)
|
| + return mouseId;
|
| +
|
| + int type = toInt(p.first);
|
| + unsigned id = p.second;
|
| + if (m_ids[type].contains(id))
|
| + return m_ids[type].get(id);
|
| + // We do not handle the overflow of m_currentId as it should be very rare
|
| + MappedId mappedId = m_currentId++;
|
| + if (m_ids[type].isEmpty())
|
| + m_primaryId[type] = mappedId;
|
| + m_ids[type].add(id, mappedId);
|
| + m_reverseMapping.add(mappedId, p);
|
| + return static_cast<PointerIdManager::MappedId>(mappedId);
|
| }
|
|
|
| -void PointerIdManager::remove(WebPointerProperties::PointerType type, unsigned id)
|
| +void PointerIdManager::remove(const GeneratedPointer p)
|
| {
|
| - if (isPrimary(type, id)) {
|
| - m_ids[toInt(type)].removeFirst();
|
| - m_hasPrimaryId[toInt(type)] = false;
|
| - } 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[toInt(type)].remove(id);
|
| - }
|
| + int type = toInt(p.first);
|
| + unsigned id = p.second;
|
| + if (!m_ids[type].contains(id))
|
| + return;
|
| + remove(m_ids[type].get(id));
|
| }
|
|
|
| -bool PointerIdManager::isPrimary(WebPointerProperties::PointerType type, unsigned id)
|
| +void PointerIdManager::remove(const PointerIdManager::MappedId mappedId)
|
| {
|
| - return m_hasPrimaryId[toInt(type)] && m_ids[toInt(type)].first() == id;
|
| + // Do not remove mouse pointer id as it should always be there
|
| + if (mappedId == mouseId || !m_reverseMapping.contains(mappedId))
|
| + return;
|
| +
|
| + GeneratedPointer p = m_reverseMapping.get(mappedId);
|
| + int type = toInt(p.first);
|
| + unsigned id = p.second;
|
| + m_reverseMapping.remove(mappedId);
|
| + m_ids[type].remove(id);
|
| + if (m_primaryId[type] == mappedId)
|
| + m_primaryId[type] = PointerIdManager::s_invalidId;
|
| +}
|
| +
|
| +bool PointerIdManager::isPrimary(PointerIdManager::MappedId mappedId) const
|
| +{
|
| + if (!m_reverseMapping.contains(mappedId))
|
| + return false;
|
| +
|
| + GeneratedPointer p = m_reverseMapping.get(mappedId);
|
| + int type = toInt(p.first);
|
| + return m_primaryId[type] == mappedId;
|
| }
|
|
|
| +PointerIdManager::MappedId PointerIdManager::getPrimaryId(const WebPointerProperties::PointerType type) const
|
| +{
|
| + return m_primaryId[toInt(type)];
|
| +}
|
| +
|
| +WebPointerProperties::PointerType PointerIdManager::getType(const PointerIdManager::MappedId mappedId) const
|
| +{
|
| + if (!m_reverseMapping.contains(mappedId))
|
| + return WebPointerProperties::PointerType::Unknown;
|
| +
|
| + return m_reverseMapping.get(mappedId).first;
|
| +}
|
| +
|
| +
|
| } // namespace blink
|
|
|