| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "core/events/PointerEventFactory.h" | 5 #include "core/events/PointerEventFactory.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "platform/geometry/FloatSize.h" | 8 #include "platform/geometry/FloatSize.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 m_primaryId[type] = PointerEventFactory::s_invalidId; | 419 m_primaryId[type] = PointerEventFactory::s_invalidId; |
| 420 m_idCount[type] = 0; | 420 m_idCount[type] = 0; |
| 421 } | 421 } |
| 422 m_pointerIncomingIdMapping.clear(); | 422 m_pointerIncomingIdMapping.clear(); |
| 423 m_pointerIdMapping.clear(); | 423 m_pointerIdMapping.clear(); |
| 424 | 424 |
| 425 // Always add mouse pointer in initialization and never remove it. | 425 // Always add mouse pointer in initialization and never remove it. |
| 426 // No need to add it to m_pointerIncomingIdMapping as it is not going to be | 426 // No need to add it to m_pointerIncomingIdMapping as it is not going to be |
| 427 // used with the existing APIs | 427 // used with the existing APIs |
| 428 m_primaryId[toInt(WebPointerProperties::PointerType::Mouse)] = s_mouseId; | 428 m_primaryId[toInt(WebPointerProperties::PointerType::Mouse)] = s_mouseId; |
| 429 m_pointerIdMapping.add( | 429 m_pointerIdMapping.insert( |
| 430 s_mouseId, | 430 s_mouseId, |
| 431 PointerAttributes(IncomingId(WebPointerProperties::PointerType::Mouse, 0), | 431 PointerAttributes(IncomingId(WebPointerProperties::PointerType::Mouse, 0), |
| 432 0)); | 432 0)); |
| 433 | 433 |
| 434 m_currentId = PointerEventFactory::s_mouseId + 1; | 434 m_currentId = PointerEventFactory::s_mouseId + 1; |
| 435 } | 435 } |
| 436 | 436 |
| 437 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, | 437 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, |
| 438 bool isActiveButtons) { | 438 bool isActiveButtons) { |
| 439 // Do not add extra mouse pointer as it was added in initialization | 439 // Do not add extra mouse pointer as it was added in initialization |
| 440 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { | 440 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { |
| 441 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); | 441 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); |
| 442 return s_mouseId; | 442 return s_mouseId; |
| 443 } | 443 } |
| 444 | 444 |
| 445 if (m_pointerIncomingIdMapping.contains(p)) { | 445 if (m_pointerIncomingIdMapping.contains(p)) { |
| 446 int mappedId = m_pointerIncomingIdMapping.get(p); | 446 int mappedId = m_pointerIncomingIdMapping.get(p); |
| 447 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); | 447 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); |
| 448 return mappedId; | 448 return mappedId; |
| 449 } | 449 } |
| 450 int typeInt = p.pointerTypeInt(); | 450 int typeInt = p.pointerTypeInt(); |
| 451 // We do not handle the overflow of m_currentId as it should be very rare | 451 // We do not handle the overflow of m_currentId as it should be very rare |
| 452 int mappedId = m_currentId++; | 452 int mappedId = m_currentId++; |
| 453 if (!m_idCount[typeInt]) | 453 if (!m_idCount[typeInt]) |
| 454 m_primaryId[typeInt] = mappedId; | 454 m_primaryId[typeInt] = mappedId; |
| 455 m_idCount[typeInt]++; | 455 m_idCount[typeInt]++; |
| 456 m_pointerIncomingIdMapping.add(p, mappedId); | 456 m_pointerIncomingIdMapping.insert(p, mappedId); |
| 457 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); | 457 m_pointerIdMapping.insert(mappedId, PointerAttributes(p, isActiveButtons)); |
| 458 return mappedId; | 458 return mappedId; |
| 459 } | 459 } |
| 460 | 460 |
| 461 bool PointerEventFactory::remove(const int mappedId) { | 461 bool PointerEventFactory::remove(const int mappedId) { |
| 462 // Do not remove mouse pointer id as it should always be there | 462 // Do not remove mouse pointer id as it should always be there |
| 463 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) | 463 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) |
| 464 return false; | 464 return false; |
| 465 | 465 |
| 466 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 466 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 467 int typeInt = p.pointerTypeInt(); | 467 int typeInt = p.pointerTypeInt(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 const WebPointerProperties& properties) const { | 517 const WebPointerProperties& properties) const { |
| 518 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 518 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
| 519 return PointerEventFactory::s_mouseId; | 519 return PointerEventFactory::s_mouseId; |
| 520 IncomingId id(properties.pointerType, properties.id); | 520 IncomingId id(properties.pointerType, properties.id); |
| 521 if (m_pointerIncomingIdMapping.contains(id)) | 521 if (m_pointerIncomingIdMapping.contains(id)) |
| 522 return m_pointerIncomingIdMapping.get(id); | 522 return m_pointerIncomingIdMapping.get(id); |
| 523 return PointerEventFactory::s_invalidId; | 523 return PointerEventFactory::s_invalidId; |
| 524 } | 524 } |
| 525 | 525 |
| 526 } // namespace blink | 526 } // namespace blink |
| OLD | NEW |