| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 return PointerEvent::create(type, pointerEventInit); | 343 return PointerEvent::create(type, pointerEventInit); |
| 344 } | 344 } |
| 345 | 345 |
| 346 PointerEvent* PointerEventFactory::createPointerCancelEvent( | 346 PointerEvent* PointerEventFactory::createPointerCancelEvent( |
| 347 const int pointerId, | 347 const int pointerId, |
| 348 const WebPointerProperties::PointerType pointerType) { | 348 const WebPointerProperties::PointerType pointerType) { |
| 349 DCHECK(m_pointerIdMapping.contains(pointerId)); | 349 DCHECK(m_pointerIdMapping.contains(pointerId)); |
| 350 m_pointerIdMapping.set( | 350 m_pointerIdMapping.set( |
| 351 pointerId, | 351 pointerId, |
| 352 PointerAttributes(m_pointerIdMapping.get(pointerId).incomingId, false)); | 352 PointerAttributes(m_pointerIdMapping.at(pointerId).incomingId, false)); |
| 353 | 353 |
| 354 PointerEventInit pointerEventInit; | 354 PointerEventInit pointerEventInit; |
| 355 | 355 |
| 356 pointerEventInit.setPointerId(pointerId); | 356 pointerEventInit.setPointerId(pointerId); |
| 357 pointerEventInit.setPointerType( | 357 pointerEventInit.setPointerType( |
| 358 pointerTypeNameForWebPointPointerType(pointerType)); | 358 pointerTypeNameForWebPointPointerType(pointerType)); |
| 359 pointerEventInit.setIsPrimary(isPrimary(pointerId)); | 359 pointerEventInit.setIsPrimary(isPrimary(pointerId)); |
| 360 | 360 |
| 361 setEventSpecificFields(pointerEventInit, EventTypeNames::pointercancel); | 361 setEventSpecificFields(pointerEventInit, EventTypeNames::pointercancel); |
| 362 | 362 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 448 |
| 449 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, | 449 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, |
| 450 bool isActiveButtons) { | 450 bool isActiveButtons) { |
| 451 // Do not add extra mouse pointer as it was added in initialization | 451 // Do not add extra mouse pointer as it was added in initialization |
| 452 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { | 452 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { |
| 453 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); | 453 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); |
| 454 return s_mouseId; | 454 return s_mouseId; |
| 455 } | 455 } |
| 456 | 456 |
| 457 if (m_pointerIncomingIdMapping.contains(p)) { | 457 if (m_pointerIncomingIdMapping.contains(p)) { |
| 458 int mappedId = m_pointerIncomingIdMapping.get(p); | 458 int mappedId = m_pointerIncomingIdMapping.at(p); |
| 459 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); | 459 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); |
| 460 return mappedId; | 460 return mappedId; |
| 461 } | 461 } |
| 462 int typeInt = p.pointerTypeInt(); | 462 int typeInt = p.pointerTypeInt(); |
| 463 // We do not handle the overflow of m_currentId as it should be very rare | 463 // We do not handle the overflow of m_currentId as it should be very rare |
| 464 int mappedId = m_currentId++; | 464 int mappedId = m_currentId++; |
| 465 if (!m_idCount[typeInt]) | 465 if (!m_idCount[typeInt]) |
| 466 m_primaryId[typeInt] = mappedId; | 466 m_primaryId[typeInt] = mappedId; |
| 467 m_idCount[typeInt]++; | 467 m_idCount[typeInt]++; |
| 468 m_pointerIncomingIdMapping.insert(p, mappedId); | 468 m_pointerIncomingIdMapping.insert(p, mappedId); |
| 469 m_pointerIdMapping.insert(mappedId, PointerAttributes(p, isActiveButtons)); | 469 m_pointerIdMapping.insert(mappedId, PointerAttributes(p, isActiveButtons)); |
| 470 return mappedId; | 470 return mappedId; |
| 471 } | 471 } |
| 472 | 472 |
| 473 bool PointerEventFactory::remove(const int mappedId) { | 473 bool PointerEventFactory::remove(const int mappedId) { |
| 474 // Do not remove mouse pointer id as it should always be there | 474 // Do not remove mouse pointer id as it should always be there |
| 475 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) | 475 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) |
| 476 return false; | 476 return false; |
| 477 | 477 |
| 478 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 478 IncomingId p = m_pointerIdMapping.at(mappedId).incomingId; |
| 479 int typeInt = p.pointerTypeInt(); | 479 int typeInt = p.pointerTypeInt(); |
| 480 m_pointerIdMapping.erase(mappedId); | 480 m_pointerIdMapping.erase(mappedId); |
| 481 m_pointerIncomingIdMapping.erase(p); | 481 m_pointerIncomingIdMapping.erase(p); |
| 482 if (m_primaryId[typeInt] == mappedId) | 482 if (m_primaryId[typeInt] == mappedId) |
| 483 m_primaryId[typeInt] = PointerEventFactory::s_invalidId; | 483 m_primaryId[typeInt] = PointerEventFactory::s_invalidId; |
| 484 m_idCount[typeInt]--; | 484 m_idCount[typeInt]--; |
| 485 return true; | 485 return true; |
| 486 } | 486 } |
| 487 | 487 |
| 488 Vector<int> PointerEventFactory::getPointerIdsOfType( | 488 Vector<int> PointerEventFactory::getPointerIdsOfType( |
| 489 WebPointerProperties::PointerType pointerType) const { | 489 WebPointerProperties::PointerType pointerType) const { |
| 490 Vector<int> mappedIds; | 490 Vector<int> mappedIds; |
| 491 | 491 |
| 492 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(); | 492 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(); |
| 493 ++iter) { | 493 ++iter) { |
| 494 int mappedId = iter->key; | 494 int mappedId = iter->key; |
| 495 if (iter->value.incomingId.pointerType() == pointerType) | 495 if (iter->value.incomingId.pointerType() == pointerType) |
| 496 mappedIds.push_back(mappedId); | 496 mappedIds.push_back(mappedId); |
| 497 } | 497 } |
| 498 | 498 |
| 499 // Sorting for a predictable ordering. | 499 // Sorting for a predictable ordering. |
| 500 std::sort(mappedIds.begin(), mappedIds.end()); | 500 std::sort(mappedIds.begin(), mappedIds.end()); |
| 501 return mappedIds; | 501 return mappedIds; |
| 502 } | 502 } |
| 503 | 503 |
| 504 bool PointerEventFactory::isPrimary(int mappedId) const { | 504 bool PointerEventFactory::isPrimary(int mappedId) const { |
| 505 if (!m_pointerIdMapping.contains(mappedId)) | 505 if (!m_pointerIdMapping.contains(mappedId)) |
| 506 return false; | 506 return false; |
| 507 | 507 |
| 508 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 508 IncomingId p = m_pointerIdMapping.at(mappedId).incomingId; |
| 509 return m_primaryId[p.pointerTypeInt()] == mappedId; | 509 return m_primaryId[p.pointerTypeInt()] == mappedId; |
| 510 } | 510 } |
| 511 | 511 |
| 512 bool PointerEventFactory::isActive(const int pointerId) const { | 512 bool PointerEventFactory::isActive(const int pointerId) const { |
| 513 return m_pointerIdMapping.contains(pointerId); | 513 return m_pointerIdMapping.contains(pointerId); |
| 514 } | 514 } |
| 515 | 515 |
| 516 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const { | 516 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const { |
| 517 return m_pointerIdMapping.contains(pointerId) && | 517 return m_pointerIdMapping.contains(pointerId) && |
| 518 m_pointerIdMapping.get(pointerId).isActiveButtons; | 518 m_pointerIdMapping.at(pointerId).isActiveButtons; |
| 519 } | 519 } |
| 520 | 520 |
| 521 WebPointerProperties::PointerType PointerEventFactory::getPointerType( | 521 WebPointerProperties::PointerType PointerEventFactory::getPointerType( |
| 522 int pointerId) const { | 522 int pointerId) const { |
| 523 if (!isActive(pointerId)) | 523 if (!isActive(pointerId)) |
| 524 return WebPointerProperties::PointerType::Unknown; | 524 return WebPointerProperties::PointerType::Unknown; |
| 525 return m_pointerIdMapping.get(pointerId).incomingId.pointerType(); | 525 return m_pointerIdMapping.at(pointerId).incomingId.pointerType(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 int PointerEventFactory::getPointerEventId( | 528 int PointerEventFactory::getPointerEventId( |
| 529 const WebPointerProperties& properties) const { | 529 const WebPointerProperties& properties) const { |
| 530 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 530 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
| 531 return PointerEventFactory::s_mouseId; | 531 return PointerEventFactory::s_mouseId; |
| 532 IncomingId id(properties.pointerType, properties.id); | 532 IncomingId id(properties.pointerType, properties.id); |
| 533 if (m_pointerIncomingIdMapping.contains(id)) | 533 if (m_pointerIncomingIdMapping.contains(id)) |
| 534 return m_pointerIncomingIdMapping.get(id); | 534 return m_pointerIncomingIdMapping.at(id); |
| 535 return PointerEventFactory::s_invalidId; | 535 return PointerEventFactory::s_invalidId; |
| 536 } | 536 } |
| 537 | 537 |
| 538 } // namespace blink | 538 } // namespace blink |
| OLD | NEW |