| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 s_mouseId, | 337 s_mouseId, |
| 338 PointerAttributes(IncomingId(WebPointerProperties::PointerType::Mouse, 0), | 338 PointerAttributes(IncomingId(WebPointerProperties::PointerType::Mouse, 0), |
| 339 0)); | 339 0)); |
| 340 | 340 |
| 341 m_currentId = PointerEventFactory::s_mouseId + 1; | 341 m_currentId = PointerEventFactory::s_mouseId + 1; |
| 342 } | 342 } |
| 343 | 343 |
| 344 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, | 344 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, |
| 345 bool isActiveButtons) { | 345 bool isActiveButtons) { |
| 346 // Do not add extra mouse pointer as it was added in initialization | 346 // Do not add extra mouse pointer as it was added in initialization |
| 347 if (p.pointerType() == toInt(WebPointerProperties::PointerType::Mouse)) { | 347 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { |
| 348 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); | 348 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)); |
| 349 return s_mouseId; | 349 return s_mouseId; |
| 350 } | 350 } |
| 351 | 351 |
| 352 int type = p.pointerType(); | |
| 353 if (m_pointerIncomingIdMapping.contains(p)) { | 352 if (m_pointerIncomingIdMapping.contains(p)) { |
| 354 int mappedId = m_pointerIncomingIdMapping.get(p); | 353 int mappedId = m_pointerIncomingIdMapping.get(p); |
| 355 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); | 354 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); |
| 356 return mappedId; | 355 return mappedId; |
| 357 } | 356 } |
| 357 int typeInt = p.pointerTypeInt(); |
| 358 // We do not handle the overflow of m_currentId as it should be very rare | 358 // We do not handle the overflow of m_currentId as it should be very rare |
| 359 int mappedId = m_currentId++; | 359 int mappedId = m_currentId++; |
| 360 if (!m_idCount[type]) | 360 if (!m_idCount[typeInt]) |
| 361 m_primaryId[type] = mappedId; | 361 m_primaryId[typeInt] = mappedId; |
| 362 m_idCount[type]++; | 362 m_idCount[typeInt]++; |
| 363 m_pointerIncomingIdMapping.add(p, mappedId); | 363 m_pointerIncomingIdMapping.add(p, mappedId); |
| 364 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); | 364 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); |
| 365 return mappedId; | 365 return mappedId; |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool PointerEventFactory::remove(const int mappedId) { | 368 bool PointerEventFactory::remove(const int mappedId) { |
| 369 // Do not remove mouse pointer id as it should always be there | 369 // Do not remove mouse pointer id as it should always be there |
| 370 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) | 370 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) |
| 371 return false; | 371 return false; |
| 372 | 372 |
| 373 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 373 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 374 int type = p.pointerType(); | 374 int typeInt = p.pointerTypeInt(); |
| 375 m_pointerIdMapping.remove(mappedId); | 375 m_pointerIdMapping.remove(mappedId); |
| 376 m_pointerIncomingIdMapping.remove(p); | 376 m_pointerIncomingIdMapping.remove(p); |
| 377 if (m_primaryId[type] == mappedId) | 377 if (m_primaryId[typeInt] == mappedId) |
| 378 m_primaryId[type] = PointerEventFactory::s_invalidId; | 378 m_primaryId[typeInt] = PointerEventFactory::s_invalidId; |
| 379 m_idCount[type]--; | 379 m_idCount[typeInt]--; |
| 380 return true; | 380 return true; |
| 381 } | 381 } |
| 382 | 382 |
| 383 Vector<int> PointerEventFactory::getPointerIdsOfType( | 383 Vector<int> PointerEventFactory::getPointerIdsOfType( |
| 384 WebPointerProperties::PointerType pointerType) const { | 384 WebPointerProperties::PointerType pointerType) const { |
| 385 Vector<int> mappedIds; | 385 Vector<int> mappedIds; |
| 386 | 386 |
| 387 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(); | 387 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(); |
| 388 ++iter) { | 388 ++iter) { |
| 389 int mappedId = iter->key; | 389 int mappedId = iter->key; |
| 390 if (iter->value.incomingId.pointerType() == static_cast<int>(pointerType)) | 390 if (iter->value.incomingId.pointerType() == pointerType) |
| 391 mappedIds.append(mappedId); | 391 mappedIds.append(mappedId); |
| 392 } | 392 } |
| 393 | 393 |
| 394 // Sorting for a predictable ordering. | 394 // Sorting for a predictable ordering. |
| 395 std::sort(mappedIds.begin(), mappedIds.end()); | 395 std::sort(mappedIds.begin(), mappedIds.end()); |
| 396 return mappedIds; | 396 return mappedIds; |
| 397 } | 397 } |
| 398 | 398 |
| 399 bool PointerEventFactory::isPrimary(int mappedId) const { | 399 bool PointerEventFactory::isPrimary(int mappedId) const { |
| 400 if (!m_pointerIdMapping.contains(mappedId)) | 400 if (!m_pointerIdMapping.contains(mappedId)) |
| 401 return false; | 401 return false; |
| 402 | 402 |
| 403 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 403 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 404 return m_primaryId[p.pointerType()] == mappedId; | 404 return m_primaryId[p.pointerTypeInt()] == mappedId; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool PointerEventFactory::isActive(const int pointerId) const { | 407 bool PointerEventFactory::isActive(const int pointerId) const { |
| 408 return m_pointerIdMapping.contains(pointerId); | 408 return m_pointerIdMapping.contains(pointerId); |
| 409 } | 409 } |
| 410 | 410 |
| 411 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const { | 411 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const { |
| 412 return m_pointerIdMapping.contains(pointerId) && | 412 return m_pointerIdMapping.contains(pointerId) && |
| 413 m_pointerIdMapping.get(pointerId).isActiveButtons; | 413 m_pointerIdMapping.get(pointerId).isActiveButtons; |
| 414 } | 414 } |
| 415 | 415 |
| 416 WebPointerProperties::PointerType PointerEventFactory::getPointerType( |
| 417 int pointerId) const { |
| 418 if (!isActive(pointerId)) |
| 419 return WebPointerProperties::PointerType::Unknown; |
| 420 return m_pointerIdMapping.get(pointerId).incomingId.pointerType(); |
| 421 } |
| 422 |
| 416 int PointerEventFactory::getPointerEventId( | 423 int PointerEventFactory::getPointerEventId( |
| 417 const WebPointerProperties& properties) const { | 424 const WebPointerProperties& properties) const { |
| 418 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) | 425 if (properties.pointerType == WebPointerProperties::PointerType::Mouse) |
| 419 return PointerEventFactory::s_mouseId; | 426 return PointerEventFactory::s_mouseId; |
| 420 IncomingId id(properties.pointerType, properties.id); | 427 IncomingId id(properties.pointerType, properties.id); |
| 421 if (m_pointerIncomingIdMapping.contains(id)) | 428 if (m_pointerIncomingIdMapping.contains(id)) |
| 422 return m_pointerIncomingIdMapping.get(id); | 429 return m_pointerIncomingIdMapping.get(id); |
| 423 return PointerEventFactory::s_invalidId; | 430 return PointerEventFactory::s_invalidId; |
| 424 } | 431 } |
| 425 | 432 |
| 426 } // namespace blink | 433 } // namespace blink |
| OLD | NEW |