| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 pointerEventInit.setPointerId(pointerId); | 201 pointerEventInit.setPointerId(pointerId); |
| 202 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); | 202 pointerEventInit.setPointerType(pointerTypeNameForWebPointPointerType(pointe
rType)); |
| 203 pointerEventInit.setIsPrimary(isPrimary(pointerId)); | 203 pointerEventInit.setIsPrimary(isPrimary(pointerId)); |
| 204 pointerEventInit.setBubbles(true); | 204 pointerEventInit.setBubbles(true); |
| 205 pointerEventInit.setCancelable(false); | 205 pointerEventInit.setCancelable(false); |
| 206 | 206 |
| 207 return PointerEvent::create(EventTypeNames::pointercancel, pointerEventInit)
; | 207 return PointerEvent::create(EventTypeNames::pointercancel, pointerEventInit)
; |
| 208 } | 208 } |
| 209 | 209 |
| 210 PointerEvent* PointerEventFactory::createPointerCaptureEvent( | 210 PointerEvent* PointerEventFactory::createPointerCaptureEvent( |
| 211 const int pointerId, | 211 PointerEvent* pointerEvent, |
| 212 const AtomicString& type) | 212 const AtomicString& type) |
| 213 { | 213 { |
| 214 ASSERT(type == EventTypeNames::gotpointercapture | 214 ASSERT(type == EventTypeNames::gotpointercapture |
| 215 || type == EventTypeNames::lostpointercapture); | 215 || type == EventTypeNames::lostpointercapture); |
| 216 | 216 |
| 217 // See https://github.com/w3c/pointerevents/issues/113 as why we don't set | |
| 218 // any other attributes for got/lostpointercapture. | |
| 219 PointerEventInit pointerEventInit; | 217 PointerEventInit pointerEventInit; |
| 220 pointerEventInit.setPointerId(pointerId); | 218 pointerEventInit.setPointerId(pointerEvent->pointerId()); |
| 219 pointerEventInit.setPointerType(pointerEvent->pointerType()); |
| 220 pointerEventInit.setIsPrimary(pointerEvent->isPrimary()); |
| 221 pointerEventInit.setBubbles(true); | 221 pointerEventInit.setBubbles(true); |
| 222 pointerEventInit.setCancelable(false); | 222 pointerEventInit.setCancelable(false); |
| 223 | 223 |
| 224 return PointerEvent::create(type, pointerEventInit); | 224 return PointerEvent::create(type, pointerEventInit); |
| 225 } | 225 } |
| 226 | 226 |
| 227 PointerEvent* PointerEventFactory::createPointerBoundaryEvent( | 227 PointerEvent* PointerEventFactory::createPointerBoundaryEvent( |
| 228 PointerEvent* pointerEvent, | 228 PointerEvent* pointerEvent, |
| 229 const AtomicString& type, | 229 const AtomicString& type, |
| 230 EventTarget* relatedTarget) | 230 EventTarget* relatedTarget) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 m_pointerIdMapping.add(s_mouseId, PointerAttributes( | 287 m_pointerIdMapping.add(s_mouseId, PointerAttributes( |
| 288 IncomingId(WebPointerProperties::PointerType::Mouse, 0), 0)); | 288 IncomingId(WebPointerProperties::PointerType::Mouse, 0), 0)); |
| 289 | 289 |
| 290 m_currentId = PointerEventFactory::s_mouseId+1; | 290 m_currentId = PointerEventFactory::s_mouseId+1; |
| 291 } | 291 } |
| 292 | 292 |
| 293 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, | 293 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, |
| 294 bool isActiveButtons) | 294 bool isActiveButtons) |
| 295 { | 295 { |
| 296 // Do not add extra mouse pointer as it was added in initialization | 296 // Do not add extra mouse pointer as it was added in initialization |
| 297 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { | 297 if (p.pointerType() == toInt(WebPointerProperties::PointerType::Mouse)) { |
| 298 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons))
; | 298 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons))
; |
| 299 return s_mouseId; | 299 return s_mouseId; |
| 300 } | 300 } |
| 301 | 301 |
| 302 int type = p.pointerTypeInt(); | 302 int type = p.pointerType(); |
| 303 if (m_pointerIncomingIdMapping.contains(p)) { | 303 if (m_pointerIncomingIdMapping.contains(p)) { |
| 304 int mappedId = m_pointerIncomingIdMapping.get(p); | 304 int mappedId = m_pointerIncomingIdMapping.get(p); |
| 305 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); | 305 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); |
| 306 return mappedId; | 306 return mappedId; |
| 307 } | 307 } |
| 308 // We do not handle the overflow of m_currentId as it should be very rare | 308 // We do not handle the overflow of m_currentId as it should be very rare |
| 309 int mappedId = m_currentId++; | 309 int mappedId = m_currentId++; |
| 310 if (!m_idCount[type]) | 310 if (!m_idCount[type]) |
| 311 m_primaryId[type] = mappedId; | 311 m_primaryId[type] = mappedId; |
| 312 m_idCount[type]++; | 312 m_idCount[type]++; |
| 313 m_pointerIncomingIdMapping.add(p, mappedId); | 313 m_pointerIncomingIdMapping.add(p, mappedId); |
| 314 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); | 314 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); |
| 315 return mappedId; | 315 return mappedId; |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool PointerEventFactory::remove(const int mappedId) | 318 bool PointerEventFactory::remove(const int mappedId) |
| 319 { | 319 { |
| 320 // Do not remove mouse pointer id as it should always be there | 320 // Do not remove mouse pointer id as it should always be there |
| 321 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) | 321 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) |
| 322 return false; | 322 return false; |
| 323 | 323 |
| 324 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 324 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 325 int type = p.pointerTypeInt(); | 325 int type = p.pointerType(); |
| 326 m_pointerIdMapping.remove(mappedId); | 326 m_pointerIdMapping.remove(mappedId); |
| 327 m_pointerIncomingIdMapping.remove(p); | 327 m_pointerIncomingIdMapping.remove(p); |
| 328 if (m_primaryId[type] == mappedId) | 328 if (m_primaryId[type] == mappedId) |
| 329 m_primaryId[type] = PointerEventFactory::s_invalidId; | 329 m_primaryId[type] = PointerEventFactory::s_invalidId; |
| 330 m_idCount[type]--; | 330 m_idCount[type]--; |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 | 333 |
| 334 Vector<int> PointerEventFactory::getPointerIdsOfType( | 334 Vector<int> PointerEventFactory::getPointerIdsOfType( |
| 335 WebPointerProperties::PointerType pointerType) const | 335 WebPointerProperties::PointerType pointerType) const |
| 336 { | 336 { |
| 337 Vector<int> mappedIds; | 337 Vector<int> mappedIds; |
| 338 | 338 |
| 339 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(
); ++iter) { | 339 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end(
); ++iter) { |
| 340 int mappedId = iter->key; | 340 int mappedId = iter->key; |
| 341 if (iter->value.incomingId.pointerType() == pointerType) | 341 if (iter->value.incomingId.pointerType() == static_cast<int>(pointerType
)) |
| 342 mappedIds.append(mappedId); | 342 mappedIds.append(mappedId); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Sorting for a predictable ordering. | 345 // Sorting for a predictable ordering. |
| 346 std::sort(mappedIds.begin(), mappedIds.end()); | 346 std::sort(mappedIds.begin(), mappedIds.end()); |
| 347 return mappedIds; | 347 return mappedIds; |
| 348 } | 348 } |
| 349 | 349 |
| 350 bool PointerEventFactory::isPrimary(int mappedId) const | 350 bool PointerEventFactory::isPrimary(int mappedId) const |
| 351 { | 351 { |
| 352 if (!m_pointerIdMapping.contains(mappedId)) | 352 if (!m_pointerIdMapping.contains(mappedId)) |
| 353 return false; | 353 return false; |
| 354 | 354 |
| 355 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 355 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 356 return m_primaryId[p.pointerTypeInt()] == mappedId; | 356 return m_primaryId[p.pointerType()] == mappedId; |
| 357 } | 357 } |
| 358 | 358 |
| 359 bool PointerEventFactory::isActive(const int pointerId) const | 359 bool PointerEventFactory::isActive(const int pointerId) const |
| 360 { | 360 { |
| 361 return m_pointerIdMapping.contains(pointerId); | 361 return m_pointerIdMapping.contains(pointerId); |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const | 364 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const |
| 365 { | 365 { |
| 366 return m_pointerIdMapping.contains(pointerId) | 366 return m_pointerIdMapping.contains(pointerId) |
| 367 && m_pointerIdMapping.get(pointerId).isActiveButtons; | 367 && m_pointerIdMapping.get(pointerId).isActiveButtons; |
| 368 } | 368 } |
| 369 | 369 |
| 370 int PointerEventFactory::getPointerEventId( | 370 int PointerEventFactory::getPointerEventId( |
| 371 const WebPointerProperties& properties) const | 371 const WebPointerProperties& properties) const |
| 372 { | 372 { |
| 373 if (properties.pointerType | 373 if (properties.pointerType |
| 374 == WebPointerProperties::PointerType::Mouse) | 374 == WebPointerProperties::PointerType::Mouse) |
| 375 return PointerEventFactory::s_mouseId; | 375 return PointerEventFactory::s_mouseId; |
| 376 IncomingId id(properties.pointerType, properties.id); | 376 IncomingId id(properties.pointerType, properties.id); |
| 377 if (m_pointerIncomingIdMapping.contains(id)) | 377 if (m_pointerIncomingIdMapping.contains(id)) |
| 378 return m_pointerIncomingIdMapping.get(id); | 378 return m_pointerIncomingIdMapping.get(id); |
| 379 return PointerEventFactory::s_invalidId; | 379 return PointerEventFactory::s_invalidId; |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |