Chromium Code Reviews| 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 PointerEvent* pointerEvent, | 211 const int pointerId, |
| 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 PointerEventInit pointerEventInit; | 217 PointerEventInit pointerEventInit; |
| 218 pointerEventInit.setPointerId(pointerEvent->pointerId()); | 218 pointerEventInit.setPointerId(pointerId); |
|
Rick Byers
2016/07/15 17:35:31
so for now you're just matching edge's behavior fo
Navid Zolghadr
2016/07/15 20:41:01
Not quite. Edge does set the attributes for the go
| |
| 219 pointerEventInit.setPointerType(pointerEvent->pointerType()); | |
| 220 pointerEventInit.setIsPrimary(pointerEvent->isPrimary()); | |
| 221 pointerEventInit.setBubbles(true); | 219 pointerEventInit.setBubbles(true); |
| 222 pointerEventInit.setCancelable(false); | 220 pointerEventInit.setCancelable(false); |
| 223 | 221 |
| 224 return PointerEvent::create(type, pointerEventInit); | 222 return PointerEvent::create(type, pointerEventInit); |
| 225 } | 223 } |
| 226 | 224 |
| 227 PointerEvent* PointerEventFactory::createPointerBoundaryEvent( | 225 PointerEvent* PointerEventFactory::createPointerBoundaryEvent( |
| 228 PointerEvent* pointerEvent, | 226 PointerEvent* pointerEvent, |
| 229 const AtomicString& type, | 227 const AtomicString& type, |
| 230 EventTarget* relatedTarget) | 228 EventTarget* relatedTarget) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 m_pointerIdMapping.add(s_mouseId, PointerAttributes( | 285 m_pointerIdMapping.add(s_mouseId, PointerAttributes( |
| 288 IncomingId(WebPointerProperties::PointerType::Mouse, 0), 0)); | 286 IncomingId(WebPointerProperties::PointerType::Mouse, 0), 0)); |
| 289 | 287 |
| 290 m_currentId = PointerEventFactory::s_mouseId+1; | 288 m_currentId = PointerEventFactory::s_mouseId+1; |
| 291 } | 289 } |
| 292 | 290 |
| 293 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, | 291 int PointerEventFactory::addIdAndActiveButtons(const IncomingId p, |
| 294 bool isActiveButtons) | 292 bool isActiveButtons) |
| 295 { | 293 { |
| 296 // Do not add extra mouse pointer as it was added in initialization | 294 // Do not add extra mouse pointer as it was added in initialization |
| 297 if (p.pointerType() == toInt(WebPointerProperties::PointerType::Mouse)) { | 295 if (p.pointerType() == WebPointerProperties::PointerType::Mouse) { |
| 298 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)) ; | 296 m_pointerIdMapping.set(s_mouseId, PointerAttributes(p, isActiveButtons)) ; |
| 299 return s_mouseId; | 297 return s_mouseId; |
| 300 } | 298 } |
| 301 | 299 |
| 302 int type = p.pointerType(); | 300 int type = p.pointerTypeInt(); |
| 303 if (m_pointerIncomingIdMapping.contains(p)) { | 301 if (m_pointerIncomingIdMapping.contains(p)) { |
| 304 int mappedId = m_pointerIncomingIdMapping.get(p); | 302 int mappedId = m_pointerIncomingIdMapping.get(p); |
| 305 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); | 303 m_pointerIdMapping.set(mappedId, PointerAttributes(p, isActiveButtons)); |
| 306 return mappedId; | 304 return mappedId; |
| 307 } | 305 } |
| 308 // We do not handle the overflow of m_currentId as it should be very rare | 306 // We do not handle the overflow of m_currentId as it should be very rare |
| 309 int mappedId = m_currentId++; | 307 int mappedId = m_currentId++; |
| 310 if (!m_idCount[type]) | 308 if (!m_idCount[type]) |
| 311 m_primaryId[type] = mappedId; | 309 m_primaryId[type] = mappedId; |
| 312 m_idCount[type]++; | 310 m_idCount[type]++; |
| 313 m_pointerIncomingIdMapping.add(p, mappedId); | 311 m_pointerIncomingIdMapping.add(p, mappedId); |
| 314 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); | 312 m_pointerIdMapping.add(mappedId, PointerAttributes(p, isActiveButtons)); |
| 315 return mappedId; | 313 return mappedId; |
| 316 } | 314 } |
| 317 | 315 |
| 318 bool PointerEventFactory::remove(const int mappedId) | 316 bool PointerEventFactory::remove(const int mappedId) |
| 319 { | 317 { |
| 320 // Do not remove mouse pointer id as it should always be there | 318 // Do not remove mouse pointer id as it should always be there |
| 321 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) | 319 if (mappedId == s_mouseId || !m_pointerIdMapping.contains(mappedId)) |
| 322 return false; | 320 return false; |
| 323 | 321 |
| 324 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 322 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 325 int type = p.pointerType(); | 323 int type = p.pointerTypeInt(); |
| 326 m_pointerIdMapping.remove(mappedId); | 324 m_pointerIdMapping.remove(mappedId); |
| 327 m_pointerIncomingIdMapping.remove(p); | 325 m_pointerIncomingIdMapping.remove(p); |
| 328 if (m_primaryId[type] == mappedId) | 326 if (m_primaryId[type] == mappedId) |
| 329 m_primaryId[type] = PointerEventFactory::s_invalidId; | 327 m_primaryId[type] = PointerEventFactory::s_invalidId; |
| 330 m_idCount[type]--; | 328 m_idCount[type]--; |
| 331 return true; | 329 return true; |
| 332 } | 330 } |
| 333 | 331 |
| 334 Vector<int> PointerEventFactory::getPointerIdsOfType( | 332 Vector<int> PointerEventFactory::getPointerIdsOfType( |
| 335 WebPointerProperties::PointerType pointerType) const | 333 WebPointerProperties::PointerType pointerType) const |
| 336 { | 334 { |
| 337 Vector<int> mappedIds; | 335 Vector<int> mappedIds; |
| 338 | 336 |
| 339 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end( ); ++iter) { | 337 for (auto iter = m_pointerIdMapping.begin(); iter != m_pointerIdMapping.end( ); ++iter) { |
| 340 int mappedId = iter->key; | 338 int mappedId = iter->key; |
| 341 if (iter->value.incomingId.pointerType() == static_cast<int>(pointerType )) | 339 if (iter->value.incomingId.pointerType() == pointerType) |
| 342 mappedIds.append(mappedId); | 340 mappedIds.append(mappedId); |
| 343 } | 341 } |
| 344 | 342 |
| 345 // Sorting for a predictable ordering. | 343 // Sorting for a predictable ordering. |
| 346 std::sort(mappedIds.begin(), mappedIds.end()); | 344 std::sort(mappedIds.begin(), mappedIds.end()); |
| 347 return mappedIds; | 345 return mappedIds; |
| 348 } | 346 } |
| 349 | 347 |
| 350 bool PointerEventFactory::isPrimary(int mappedId) const | 348 bool PointerEventFactory::isPrimary(int mappedId) const |
| 351 { | 349 { |
| 352 if (!m_pointerIdMapping.contains(mappedId)) | 350 if (!m_pointerIdMapping.contains(mappedId)) |
| 353 return false; | 351 return false; |
| 354 | 352 |
| 355 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; | 353 IncomingId p = m_pointerIdMapping.get(mappedId).incomingId; |
| 356 return m_primaryId[p.pointerType()] == mappedId; | 354 return m_primaryId[p.pointerTypeInt()] == mappedId; |
| 357 } | 355 } |
| 358 | 356 |
| 359 bool PointerEventFactory::isActive(const int pointerId) const | 357 bool PointerEventFactory::isActive(const int pointerId) const |
| 360 { | 358 { |
| 361 return m_pointerIdMapping.contains(pointerId); | 359 return m_pointerIdMapping.contains(pointerId); |
| 362 } | 360 } |
| 363 | 361 |
| 364 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const | 362 bool PointerEventFactory::isActiveButtonsState(const int pointerId) const |
| 365 { | 363 { |
| 366 return m_pointerIdMapping.contains(pointerId) | 364 return m_pointerIdMapping.contains(pointerId) |
| 367 && m_pointerIdMapping.get(pointerId).isActiveButtons; | 365 && m_pointerIdMapping.get(pointerId).isActiveButtons; |
| 368 } | 366 } |
| 369 | 367 |
| 370 int PointerEventFactory::getPointerEventId( | 368 int PointerEventFactory::getPointerEventId( |
| 371 const WebPointerProperties& properties) const | 369 const WebPointerProperties& properties) const |
| 372 { | 370 { |
| 373 if (properties.pointerType | 371 if (properties.pointerType |
| 374 == WebPointerProperties::PointerType::Mouse) | 372 == WebPointerProperties::PointerType::Mouse) |
| 375 return PointerEventFactory::s_mouseId; | 373 return PointerEventFactory::s_mouseId; |
| 376 IncomingId id(properties.pointerType, properties.id); | 374 IncomingId id(properties.pointerType, properties.id); |
| 377 if (m_pointerIncomingIdMapping.contains(id)) | 375 if (m_pointerIncomingIdMapping.contains(id)) |
| 378 return m_pointerIncomingIdMapping.get(id); | 376 return m_pointerIncomingIdMapping.get(id); |
| 379 return PointerEventFactory::s_invalidId; | 377 return PointerEventFactory::s_invalidId; |
| 380 } | 378 } |
| 381 | 379 |
| 382 } // namespace blink | 380 } // namespace blink |
| OLD | NEW |