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/input/PointerEventManager.h" | 5 #include "core/input/PointerEventManager.h" |
| 6 | 6 |
| 7 #include "core/dom/ElementTraversal.h" | 7 #include "core/dom/ElementTraversal.h" |
| 8 #include "core/dom/UserGestureIndicator.h" | 8 #include "core/dom/UserGestureIndicator.h" |
| 9 #include "core/dom/shadow/FlatTreeTraversal.h" | 9 #include "core/dom/shadow/FlatTreeTraversal.h" |
| 10 #include "core/events/MouseEvent.h" | 10 #include "core/events/MouseEvent.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { | 29 size_t ToPointerTypeIndex(WebPointerProperties::PointerType t) { |
| 30 return static_cast<size_t>(t); | 30 return static_cast<size_t>(t); |
| 31 } | 31 } |
| 32 bool HasPointerEventListener(const EventHandlerRegistry& registry) { | 32 bool HasPointerEventListener(const EventHandlerRegistry& registry) { |
| 33 return registry.HasEventHandlers(EventHandlerRegistry::kPointerEvent); | 33 return registry.HasEventHandlers(EventHandlerRegistry::kPointerEvent); |
| 34 } | 34 } |
| 35 | 35 |
| 36 Vector<WebPointerEvent> GetCoalescedWebPointerEventsWithNoTransformation( | |
| 37 const Vector<WebTouchEvent>& coalesced_events, | |
| 38 int id) { | |
| 39 Vector<WebPointerEvent> related_pointer_events; | |
| 40 for (const auto& touch_event : coalesced_events) { | |
| 41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { | |
| 42 if (touch_event.touches[i].id == id && | |
| 43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { | |
| 44 related_pointer_events.push_back( | |
| 45 WebPointerEvent(touch_event, touch_event.touches[i])); | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 return related_pointer_events; | |
| 50 } | |
| 51 | |
| 36 Vector<std::pair<WebTouchPoint, TimeTicks>> GetCoalescedPoints( | 52 Vector<std::pair<WebTouchPoint, TimeTicks>> GetCoalescedPoints( |
| 37 const Vector<WebTouchEvent>& coalesced_events, | 53 const Vector<WebTouchEvent>& coalesced_events, |
| 38 int id) { | 54 int id) { |
| 39 Vector<std::pair<WebTouchPoint, TimeTicks>> related_points; | 55 Vector<std::pair<WebTouchPoint, TimeTicks>> related_points; |
| 40 for (const auto& touch_event : coalesced_events) { | 56 for (const auto& touch_event : coalesced_events) { |
| 41 for (unsigned i = 0; i < touch_event.touches_length; ++i) { | 57 for (unsigned i = 0; i < touch_event.touches_length; ++i) { |
| 42 if (touch_event.touches[i].id == id && | 58 if (touch_event.touches[i].id == id && |
| 43 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { | 59 touch_event.touches[i].state != WebTouchPoint::kStateStationary) { |
| 44 related_points.push_back(std::pair<WebTouchPoint, TimeTicks>( | 60 related_points.push_back(std::pair<WebTouchPoint, TimeTicks>( |
| 45 touch_event.TouchPointInRootFrame(i), | 61 touch_event.TouchPointInRootFrame(i), |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 // associated with so just pick the first finger. | 333 // associated with so just pick the first finger. |
| 318 RefPtr<UserGestureToken> possible_gesture_token; | 334 RefPtr<UserGestureToken> possible_gesture_token; |
| 319 if (event.GetType() == WebInputEvent::kTouchEnd && | 335 if (event.GetType() == WebInputEvent::kTouchEnd && |
| 320 !in_canceled_state_for_pointer_type_touch_ && event.touches_length && | 336 !in_canceled_state_for_pointer_type_touch_ && event.touches_length && |
| 321 first_pointer_event_target.target_frame) { | 337 first_pointer_event_target.target_frame) { |
| 322 possible_gesture_token = UserGestureToken::Create( | 338 possible_gesture_token = UserGestureToken::Create( |
| 323 first_pointer_event_target.target_frame->GetDocument()); | 339 first_pointer_event_target.target_frame->GetDocument()); |
| 324 } | 340 } |
| 325 UserGestureIndicator holder(possible_gesture_token); | 341 UserGestureIndicator holder(possible_gesture_token); |
| 326 | 342 |
| 327 HeapVector<EventHandlingUtil::PointerEventTarget> pointer_event_targets; | |
| 328 | 343 |
| 329 for (unsigned touch_point_idx = 0; touch_point_idx < event.touches_length; | 344 for (unsigned touch_point_idx = 0; touch_point_idx < event.touches_length; |
| 330 ++touch_point_idx) { | 345 ++touch_point_idx) { |
| 331 // Do any necessary hit-tests and compute the event targets for all pointers | 346 // Do any necessary hit-tests and compute the event targets for all pointers |
| 332 // in the event. | 347 // in the event. |
| 333 const auto& touch_point = event.TouchPointInRootFrame(touch_point_idx); | 348 const auto& touch_point = event.TouchPointInRootFrame(touch_point_idx); |
| 334 EventHandlingUtil::PointerEventTarget pointer_event_target = | 349 EventHandlingUtil::PointerEventTarget pointer_event_target = |
| 335 touch_point_idx ? ComputePointerEventTarget(touch_point) | 350 touch_point_idx ? ComputePointerEventTarget(touch_point) |
| 336 : first_pointer_event_target; | 351 : first_pointer_event_target; |
| 337 pointer_event_targets.push_back(pointer_event_target); | |
| 338 | 352 |
| 339 DispatchTouchPointerEvent( | 353 if (touch_point.state != blink::WebTouchPoint::kStateStationary) { |
| 340 touch_point, pointer_event_target, | 354 DispatchTouchPointerEvent( |
| 341 GetCoalescedPoints(coalesced_events, touch_point.id), | 355 touch_point, pointer_event_target, |
| 342 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), | 356 GetCoalescedPoints(coalesced_events, touch_point.id), |
| 343 event.TimeStampSeconds(), event.unique_touch_event_id); | 357 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), |
| 358 event.TimeStampSeconds(), event.unique_touch_event_id); | |
| 359 | |
| 360 touch_event_manager_->HandleTouchPoint( | |
| 361 WebPointerEvent(event, event.touches[touch_point_idx]), | |
| 362 GetCoalescedWebPointerEventsWithNoTransformation( | |
| 363 coalesced_events, event.touches[touch_point_idx].id), | |
| 364 pointer_event_target); | |
| 365 } | |
| 344 } | 366 } |
| 345 | 367 |
| 346 return touch_event_manager_->HandleTouchEvent(event, coalesced_events, | 368 return touch_event_manager_->FlushEvents(); |
|
mustaq
2017/06/13 15:15:24
Please add a TODO re main_thread_event_queue calls
Navid Zolghadr
2017/06/13 19:31:17
Done.
| |
| 347 pointer_event_targets); | |
| 348 } | 369 } |
| 349 | 370 |
| 350 EventHandlingUtil::PointerEventTarget | 371 EventHandlingUtil::PointerEventTarget |
| 351 PointerEventManager::ComputePointerEventTarget( | 372 PointerEventManager::ComputePointerEventTarget( |
| 352 const WebTouchPoint& touch_point) { | 373 const WebTouchPoint& touch_point) { |
| 353 EventHandlingUtil::PointerEventTarget pointer_event_target; | 374 EventHandlingUtil::PointerEventTarget pointer_event_target; |
| 354 | 375 |
| 355 int pointer_id = pointer_event_factory_.GetPointerEventId(touch_point); | 376 int pointer_id = pointer_event_factory_.GetPointerEventId(touch_point); |
| 356 // Do the hit test either when the touch first starts or when the touch | 377 // Do the hit test either when the touch first starts or when the touch |
| 357 // is not captured. |m_pendingPointerCaptureTarget| indicates the target | 378 // is not captured. |m_pendingPointerCaptureTarget| indicates the target |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 const WebTouchPoint& touch_point, | 424 const WebTouchPoint& touch_point, |
| 404 const EventHandlingUtil::PointerEventTarget& pointer_event_target, | 425 const EventHandlingUtil::PointerEventTarget& pointer_event_target, |
| 405 const Vector<std::pair<WebTouchPoint, TimeTicks>>& coalesced_events, | 426 const Vector<std::pair<WebTouchPoint, TimeTicks>>& coalesced_events, |
| 406 WebInputEvent::Modifiers modifiers, | 427 WebInputEvent::Modifiers modifiers, |
| 407 double timestamp, | 428 double timestamp, |
| 408 uint32_t unique_touch_event_id) { | 429 uint32_t unique_touch_event_id) { |
| 409 // Iterate through the touch points, sending PointerEvents to the targets as | 430 // Iterate through the touch points, sending PointerEvents to the targets as |
| 410 // required. | 431 // required. |
| 411 // Do not send pointer events for stationary touches or null targetFrame | 432 // Do not send pointer events for stationary touches or null targetFrame |
| 412 if (pointer_event_target.target_node && pointer_event_target.target_frame && | 433 if (pointer_event_target.target_node && pointer_event_target.target_frame && |
| 413 touch_point.state != WebTouchPoint::kStateStationary && | |
| 414 !in_canceled_state_for_pointer_type_touch_) { | 434 !in_canceled_state_for_pointer_type_touch_) { |
| 415 PointerEvent* pointer_event = pointer_event_factory_.Create( | 435 PointerEvent* pointer_event = pointer_event_factory_.Create( |
| 416 touch_point, coalesced_events, | 436 touch_point, coalesced_events, |
| 417 static_cast<WebInputEvent::Modifiers>(modifiers), | 437 static_cast<WebInputEvent::Modifiers>(modifiers), |
| 418 TimeTicks::FromSeconds(timestamp), pointer_event_target.target_frame, | 438 TimeTicks::FromSeconds(timestamp), pointer_event_target.target_frame, |
| 419 pointer_event_target.target_node | 439 pointer_event_target.target_node |
| 420 ? pointer_event_target.target_node->GetDocument().domWindow() | 440 ? pointer_event_target.target_node->GetDocument().domWindow() |
| 421 : nullptr); | 441 : nullptr); |
| 422 | 442 |
| 423 WebInputEventResult result = | 443 WebInputEventResult result = |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 if (first_id > unique_touch_event_id) | 771 if (first_id > unique_touch_event_id) |
| 752 return false; | 772 return false; |
| 753 touch_ids_for_canceled_pointerdowns_.TakeFirst(); | 773 touch_ids_for_canceled_pointerdowns_.TakeFirst(); |
| 754 if (first_id == unique_touch_event_id) | 774 if (first_id == unique_touch_event_id) |
| 755 return true; | 775 return true; |
| 756 } | 776 } |
| 757 return false; | 777 return false; |
| 758 } | 778 } |
| 759 | 779 |
| 760 } // namespace blink | 780 } // namespace blink |
| OLD | NEW |