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

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

Issue 2844823002: Support Coalesced Touch in ppapi (Closed)
Patch Set: Support Coalesced Touch in ppapi 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_ = TouchAction::kTouchActionAuto; 202 current_touch_action_ = TouchAction::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 std::vector<const WebInputEvent*> coalesced_touches;
209 for (size_t i = 0; i < coalesced_events.size(); ++i) {
210 coalesced_touches.push_back(&coalesced_events[i]);
211 }
212 WebCoalescedInputEvent coalesced_event(event, coalesced_touches);
204 213
205 // Now iterate through the |changedTouches| list and |m_targets| within it, 214 // Now iterate through the |changedTouches| list and |m_targets| within it,
206 // sending TouchEvents to the targets as required. 215 // sending TouchEvents to the targets as required.
207 for (unsigned state = 0; state <= WebTouchPoint::kStateMax; ++state) { 216 for (unsigned state = 0; state <= WebTouchPoint::kStateMax; ++state) {
208 if (!changed_touches[state].touches_) 217 if (!changed_touches[state].touches_)
209 continue; 218 continue;
210 219
211 const AtomicString& event_name(TouchEventNameForTouchPointState( 220 const AtomicString& event_name(TouchEventNameForTouchPointState(
212 static_cast<WebTouchPoint::State>(state))); 221 static_cast<WebTouchPoint::State>(state)));
213 for (const auto& event_target : changed_touches[state].targets_) { 222 for (const auto& event_target : changed_touches[state].targets_) {
214 EventTarget* touch_event_target = event_target; 223 EventTarget* touch_event_target = event_target;
215 TouchEvent* touch_event = TouchEvent::Create( 224 TouchEvent* touch_event = TouchEvent::Create(
216 event, touches, touches_by_target.at(touch_event_target), 225 coalesced_event, touches, touches_by_target.at(touch_event_target),
217 changed_touches[state].touches_.Get(), event_name, 226 changed_touches[state].touches_.Get(), event_name,
218 touch_event_target->ToNode()->GetDocument().domWindow(), 227 touch_event_target->ToNode()->GetDocument().domWindow(),
219 current_touch_action_); 228 current_touch_action_);
220 229
221 DispatchEventResult dom_dispatch_result = 230 DispatchEventResult dom_dispatch_result =
222 touch_event_target->DispatchEvent(touch_event); 231 touch_event_target->DispatchEvent(touch_event);
223 232
224 // Only report for top level documents with a single touch on 233 // Only report for top level documents with a single touch on
225 // touch-start or the first touch-move. 234 // touch-start or the first touch-move.
226 if (event.touch_start_or_first_touch_move && touch_infos.size() == 1 && 235 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; 507 return false;
499 } 508 }
500 509
501 SetAllPropertiesOfTouchInfos(touch_infos); 510 SetAllPropertiesOfTouchInfos(touch_infos);
502 511
503 return true; 512 return true;
504 } 513 }
505 514
506 WebInputEventResult TouchEventManager::HandleTouchEvent( 515 WebInputEventResult TouchEventManager::HandleTouchEvent(
507 const WebTouchEvent& event, 516 const WebTouchEvent& event,
517 const Vector<WebTouchEvent>& coalesced_events,
508 HeapVector<TouchInfo>& touch_infos) { 518 HeapVector<TouchInfo>& touch_infos) {
509 if (!ReHitTestTouchPointsIfNeeded(event, touch_infos)) 519 if (!ReHitTestTouchPointsIfNeeded(event, touch_infos))
510 return WebInputEventResult::kNotHandled; 520 return WebInputEventResult::kNotHandled;
511 521
512 bool all_touches_released = true; 522 bool all_touches_released = true;
513 for (unsigned i = 0; i < event.touches_length; ++i) { 523 for (unsigned i = 0; i < event.touches_length; ++i) {
514 WebTouchPoint::State state = event.touches[i].state; 524 WebTouchPoint::State state = event.touches[i].state;
515 if (state != WebTouchPoint::kStateReleased && 525 if (state != WebTouchPoint::kStateReleased &&
516 state != WebTouchPoint::kStateCancelled) 526 state != WebTouchPoint::kStateCancelled)
517 all_touches_released = false; 527 all_touches_released = false;
518 } 528 }
519 529
520 return DispatchTouchEvents(event, touch_infos, all_touches_released); 530 return DispatchTouchEvents(event, coalesced_events, touch_infos,
531 all_touches_released);
521 } 532 }
522 533
523 bool TouchEventManager::IsAnyTouchActive() const { 534 bool TouchEventManager::IsAnyTouchActive() const {
524 return touch_pressed_; 535 return touch_pressed_;
525 } 536 }
526 537
527 } // namespace blink 538 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698