Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: third_party/WebKit/Source/core/input/TouchEventManager.cpp

Issue 2844823002: Support Coalesced Touch in ppapi (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/TouchEventManager.h" 5 #include "core/input/TouchEventManager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/events/TouchEvent.h" 9 #include "core/events/TouchEvent.h"
10 #include "core/frame/Deprecation.h" 10 #include "core/frame/Deprecation.h"
11 #include "core/frame/EventHandlerRegistry.h" 11 #include "core/frame/EventHandlerRegistry.h"
12 #include "core/frame/FrameView.h" 12 #include "core/frame/FrameView.h"
13 #include "core/html/HTMLCanvasElement.h" 13 #include "core/html/HTMLCanvasElement.h"
14 #include "core/input/EventHandlingUtil.h" 14 #include "core/input/EventHandlingUtil.h"
15 #include "core/input/TouchActionUtil.h" 15 #include "core/input/TouchActionUtil.h"
16 #include "core/layout/HitTestCanvasResult.h" 16 #include "core/layout/HitTestCanvasResult.h"
17 #include "core/page/ChromeClient.h" 17 #include "core/page/ChromeClient.h"
18 #include "core/page/Page.h" 18 #include "core/page/Page.h"
19 #include "platform/Histogram.h" 19 #include "platform/Histogram.h"
20 #include "platform/wtf/CurrentTime.h" 20 #include "platform/wtf/CurrentTime.h"
21 #include "platform/wtf/PtrUtil.h" 21 #include "platform/wtf/PtrUtil.h"
22 #include "public/platform/WebCoalescedInputEvent.h"
22 #include "public/platform/WebTouchEvent.h" 23 #include "public/platform/WebTouchEvent.h"
23 24
24 namespace blink { 25 namespace blink {
25 26
26 namespace { 27 namespace {
27 28
28 bool HasTouchHandlers(const EventHandlerRegistry& registry) { 29 bool HasTouchHandlers(const EventHandlerRegistry& registry) {
29 return registry.HasEventHandlers( 30 return registry.HasEventHandlers(
30 EventHandlerRegistry::kTouchStartOrMoveEventBlocking) || 31 EventHandlerRegistry::kTouchStartOrMoveEventBlocking) ||
31 registry.HasEventHandlers( 32 registry.HasEventHandlers(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 113
113 DEFINE_TRACE(TouchEventManager) { 114 DEFINE_TRACE(TouchEventManager) {
114 visitor->Trace(frame_); 115 visitor->Trace(frame_);
115 visitor->Trace(touch_sequence_document_); 116 visitor->Trace(touch_sequence_document_);
116 visitor->Trace(target_for_touch_id_); 117 visitor->Trace(target_for_touch_id_);
117 } 118 }
118 119
119 WebInputEventResult TouchEventManager::DispatchTouchEvents( 120 WebInputEventResult TouchEventManager::DispatchTouchEvents(
120 const WebTouchEvent& event, 121 const WebTouchEvent& event,
122 const Vector<WebTouchEvent>& coalesced_events,
121 const HeapVector<TouchInfo>& touch_infos, 123 const HeapVector<TouchInfo>& touch_infos,
122 bool all_touches_released) { 124 bool all_touches_released) {
123 // Build up the lists to use for the |touches|, |targetTouches| and 125 // Build up the lists to use for the |touches|, |targetTouches| and
124 // |changedTouches| attributes in the JS event. See 126 // |changedTouches| attributes in the JS event. See
125 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these 127 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these
126 // lists fit together. 128 // lists fit together.
127 129
128 if (event.GetType() == WebInputEvent::kTouchEnd || 130 if (event.GetType() == WebInputEvent::kTouchEnd ||
129 event.GetType() == WebInputEvent::kTouchCancel || 131 event.GetType() == WebInputEvent::kTouchCancel ||
130 event.touches_length > 1) { 132 event.touches_length > 1) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 changed_touches[point_state].pointer_type_ = point.pointer_type; 196 changed_touches[point_state].pointer_type_ = point.pointer_type;
195 } 197 }
196 } 198 }
197 199
198 if (all_touches_released) { 200 if (all_touches_released) {
199 touch_sequence_document_.Clear(); 201 touch_sequence_document_.Clear();
200 current_touch_action_ = kTouchActionAuto; 202 current_touch_action_ = kTouchActionAuto;
201 } 203 }
202 204
203 WebInputEventResult event_result = WebInputEventResult::kNotHandled; 205 WebInputEventResult event_result = WebInputEventResult::kNotHandled;
206 // First we construct the webcoalescedinputevent contains all the coalesced
207 // touch event.
208 WebCoalescedInputEvent coalesced_event(event);
209 for (size_t i = 1; i < coalesced_events.size(); ++i) {
210 coalesced_event.AddCoalescedEvent(coalesced_events[i]);
211 }
204 212
205 // Now iterate through the |changedTouches| list and |m_targets| within it, 213 // Now iterate through the |changedTouches| list and |m_targets| within it,
206 // sending TouchEvents to the targets as required. 214 // sending TouchEvents to the targets as required.
207 for (unsigned state = 0; state <= WebTouchPoint::kStateMax; ++state) { 215 for (unsigned state = 0; state <= WebTouchPoint::kStateMax; ++state) {
208 if (!changed_touches[state].touches_) 216 if (!changed_touches[state].touches_)
209 continue; 217 continue;
210 218
211 const AtomicString& event_name(TouchEventNameForTouchPointState( 219 const AtomicString& event_name(TouchEventNameForTouchPointState(
212 static_cast<WebTouchPoint::State>(state))); 220 static_cast<WebTouchPoint::State>(state)));
213 for (const auto& event_target : changed_touches[state].targets_) { 221 for (const auto& event_target : changed_touches[state].targets_) {
214 EventTarget* touch_event_target = event_target; 222 EventTarget* touch_event_target = event_target;
215 TouchEvent* touch_event = TouchEvent::Create( 223 TouchEvent* touch_event = TouchEvent::Create(
216 event, touches, touches_by_target.at(touch_event_target), 224 coalesced_event, touches, touches_by_target.at(touch_event_target),
217 changed_touches[state].touches_.Get(), event_name, 225 changed_touches[state].touches_.Get(), event_name,
218 touch_event_target->ToNode()->GetDocument().domWindow(), 226 touch_event_target->ToNode()->GetDocument().domWindow(),
219 current_touch_action_); 227 current_touch_action_);
220 228
221 DispatchEventResult dom_dispatch_result = 229 DispatchEventResult dom_dispatch_result =
222 touch_event_target->DispatchEvent(touch_event); 230 touch_event_target->DispatchEvent(touch_event);
223 231
224 // Only report for top level documents with a single touch on 232 // Only report for top level documents with a single touch on
225 // touch-start or the first touch-move. 233 // touch-start or the first touch-move.
226 if (event.touch_start_or_first_touch_move && touch_infos.size() == 1 && 234 if (event.touch_start_or_first_touch_move && touch_infos.size() == 1 &&
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 return false; 506 return false;
499 } 507 }
500 508
501 SetAllPropertiesOfTouchInfos(touch_infos); 509 SetAllPropertiesOfTouchInfos(touch_infos);
502 510
503 return true; 511 return true;
504 } 512 }
505 513
506 WebInputEventResult TouchEventManager::HandleTouchEvent( 514 WebInputEventResult TouchEventManager::HandleTouchEvent(
507 const WebTouchEvent& event, 515 const WebTouchEvent& event,
516 const Vector<WebTouchEvent>& coalesced_events,
508 HeapVector<TouchInfo>& touch_infos) { 517 HeapVector<TouchInfo>& touch_infos) {
509 if (!ReHitTestTouchPointsIfNeeded(event, touch_infos)) 518 if (!ReHitTestTouchPointsIfNeeded(event, touch_infos))
510 return WebInputEventResult::kNotHandled; 519 return WebInputEventResult::kNotHandled;
511 520
512 bool all_touches_released = true; 521 bool all_touches_released = true;
513 for (unsigned i = 0; i < event.touches_length; ++i) { 522 for (unsigned i = 0; i < event.touches_length; ++i) {
514 WebTouchPoint::State state = event.touches[i].state; 523 WebTouchPoint::State state = event.touches[i].state;
515 if (state != WebTouchPoint::kStateReleased && 524 if (state != WebTouchPoint::kStateReleased &&
516 state != WebTouchPoint::kStateCancelled) 525 state != WebTouchPoint::kStateCancelled)
517 all_touches_released = false; 526 all_touches_released = false;
518 } 527 }
519 528
520 return DispatchTouchEvents(event, touch_infos, all_touches_released); 529 return DispatchTouchEvents(event, coalesced_events, touch_infos,
530 all_touches_released);
521 } 531 }
522 532
523 bool TouchEventManager::IsAnyTouchActive() const { 533 bool TouchEventManager::IsAnyTouchActive() const {
524 return touch_pressed_; 534 return touch_pressed_;
525 } 535 }
526 536
527 } // namespace blink 537 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698