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

Side by Side Diff: content/browser/renderer_host/render_widget_host_input_event_router.cc

Issue 2186983002: Re-route Touchscreen GesturePinch events to root view. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/renderer_host/render_widget_host_input_event_router.h" 5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
6 6
7 #include "base/debug/dump_without_crashing.h" 7 #include "base/debug/dump_without_crashing.h"
8 #include "cc/quads/surface_draw_quad.h" 8 #include "cc/quads/surface_draw_quad.h"
9 #include "cc/surfaces/surface_id_allocator.h" 9 #include "cc/surfaces/surface_id_allocator.h"
10 #include "cc/surfaces/surface_manager.h" 10 #include "cc/surfaces/surface_manager.h"
11 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/browser/renderer_host/render_widget_host_view_base.h" 12 #include "content/browser/renderer_host/render_widget_host_view_base.h"
12 #include "content/common/frame_messages.h" 13 #include "content/common/frame_messages.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h" 14 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 15
15 namespace { 16 namespace {
16 17
17 void TransformEventTouchPositions(blink::WebTouchEvent* event, 18 void TransformEventTouchPositions(blink::WebTouchEvent* event,
18 const gfx::Vector2d& delta) { 19 const gfx::Vector2d& delta) {
19 for (unsigned i = 0; i < event->touchesLength; ++i) { 20 for (unsigned i = 0; i < event->touchesLength; ++i) {
20 event->touches[i].position.x += delta.x(); 21 event->touches[i].position.x += delta.x();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget( 89 bool RenderWidgetHostInputEventRouter::HittestDelegate::AcceptHitTarget(
89 const cc::SurfaceDrawQuad* surface_quad, 90 const cc::SurfaceDrawQuad* surface_quad,
90 const gfx::Point& point_in_quad_space) { 91 const gfx::Point& point_in_quad_space) {
91 auto it = hittest_data_.find(surface_quad->surface_id); 92 auto it = hittest_data_.find(surface_quad->surface_id);
92 if (it != hittest_data_.end() && !it->second.ignored_for_hittest) 93 if (it != hittest_data_.end() && !it->second.ignored_for_hittest)
93 return true; 94 return true;
94 return false; 95 return false;
95 } 96 }
96 97
97 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() 98 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter()
98 : active_touches_(0) {} 99 : active_touches_(0),
100 in_touchscreen_gesture_pinch_(false),
101 gesture_pinch_did_send_scroll_begin_(false) {}
99 102
100 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { 103 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() {
101 // We may be destroyed before some of the owners in the map, so we must 104 // We may be destroyed before some of the owners in the map, so we must
102 // remove ourself from their observer lists. 105 // remove ourself from their observer lists.
103 ClearAllObserverRegistrations(); 106 ClearAllObserverRegistrations();
104 } 107 }
105 108
106 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( 109 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget(
107 RenderWidgetHostViewBase* root_view, 110 RenderWidgetHostViewBase* root_view,
108 const gfx::Point& point, 111 const gfx::Point& point,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 316
314 bubbling_gesture_scroll_target_.target = target_view; 317 bubbling_gesture_scroll_target_.target = target_view;
315 318
316 SendGestureScrollBegin(target_view, event); 319 SendGestureScrollBegin(target_view, event);
317 target_view->ProcessGestureEvent(event, ui::LatencyInfo()); 320 target_view->ProcessGestureEvent(event, ui::LatencyInfo());
318 } 321 }
319 322
320 void RenderWidgetHostInputEventRouter::SendGestureScrollBegin( 323 void RenderWidgetHostInputEventRouter::SendGestureScrollBegin(
321 RenderWidgetHostViewBase* view, 324 RenderWidgetHostViewBase* view,
322 const blink::WebGestureEvent& event) { 325 const blink::WebGestureEvent& event) {
323 DCHECK(event.type == blink::WebInputEvent::GestureScrollUpdate); 326 DCHECK(event.type == blink::WebInputEvent::GestureScrollUpdate ||
327 event.type == blink::WebInputEvent::GesturePinchBegin);
324 blink::WebGestureEvent scroll_begin(event); 328 blink::WebGestureEvent scroll_begin(event);
325 scroll_begin.type = blink::WebInputEvent::GestureScrollBegin; 329 scroll_begin.type = blink::WebInputEvent::GestureScrollBegin;
326 scroll_begin.data.scrollBegin.deltaXHint = event.data.scrollUpdate.deltaX; 330 scroll_begin.data.scrollBegin.deltaXHint = event.data.scrollUpdate.deltaX;
327 scroll_begin.data.scrollBegin.deltaYHint = event.data.scrollUpdate.deltaY; 331 scroll_begin.data.scrollBegin.deltaYHint = event.data.scrollUpdate.deltaY;
328 scroll_begin.data.scrollBegin.deltaHintUnits = 332 scroll_begin.data.scrollBegin.deltaHintUnits =
329 event.data.scrollUpdate.deltaUnits; 333 event.data.scrollUpdate.deltaUnits;
330 view->ProcessGestureEvent(scroll_begin, ui::LatencyInfo()); 334 view->ProcessGestureEvent(scroll_begin, ui::LatencyInfo());
331 } 335 }
332 336
333 void RenderWidgetHostInputEventRouter::SendGestureScrollEnd( 337 void RenderWidgetHostInputEventRouter::SendGestureScrollEnd(
334 RenderWidgetHostViewBase* view, 338 RenderWidgetHostViewBase* view,
335 const blink::WebGestureEvent& event) { 339 const blink::WebGestureEvent& event) {
336 DCHECK(event.type == blink::WebInputEvent::GestureScrollUpdate); 340 DCHECK(event.type == blink::WebInputEvent::GestureScrollUpdate ||
341 event.type == blink::WebInputEvent::GesturePinchEnd);
337 blink::WebGestureEvent scroll_end(event); 342 blink::WebGestureEvent scroll_end(event);
338 scroll_end.type = blink::WebInputEvent::GestureScrollEnd; 343 scroll_end.type = blink::WebInputEvent::GestureScrollEnd;
339 scroll_end.timeStampSeconds = 344 scroll_end.timeStampSeconds =
340 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 345 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
341 scroll_end.data.scrollEnd.inertialPhase = 346 scroll_end.data.scrollEnd.inertialPhase =
342 event.data.scrollUpdate.inertialPhase; 347 event.data.scrollUpdate.inertialPhase;
343 scroll_end.data.scrollEnd.deltaUnits = event.data.scrollUpdate.deltaUnits; 348 scroll_end.data.scrollEnd.deltaUnits = event.data.scrollUpdate.deltaUnits;
344 view->ProcessGestureEvent(scroll_end, ui::LatencyInfo()); 349 view->ProcessGestureEvent(scroll_end, ui::LatencyInfo());
345 } 350 }
346 351
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 data.ignored_for_hittest = params.ignored_for_hittest; 392 data.ignored_for_hittest = params.ignored_for_hittest;
388 hittest_data_[params.surface_id] = data; 393 hittest_data_[params.surface_id] = data;
389 } 394 }
390 395
391 void RenderWidgetHostInputEventRouter::RouteTouchscreenGestureEvent( 396 void RenderWidgetHostInputEventRouter::RouteTouchscreenGestureEvent(
392 RenderWidgetHostViewBase* root_view, 397 RenderWidgetHostViewBase* root_view,
393 blink::WebGestureEvent* event, 398 blink::WebGestureEvent* event,
394 const ui::LatencyInfo& latency) { 399 const ui::LatencyInfo& latency) {
395 DCHECK_EQ(blink::WebGestureDeviceTouchscreen, event->sourceDevice); 400 DCHECK_EQ(blink::WebGestureDeviceTouchscreen, event->sourceDevice);
396 401
402 if (event->type == blink::WebInputEvent::GesturePinchBegin) {
403 in_touchscreen_gesture_pinch_ = true;
404 // If the root view wasn't already receiving the gesture stream, then we
405 // need to wrap the diverted pinch events in a GestureScrollBegin/End.
406 // TODO(wjmaclean,kenrb,tdresser): When scroll latching lands, we can
407 // revisit how this code should work.
408 // https://crbug.com/526463
409 auto rwhi =
410 static_cast<RenderWidgetHostImpl*>(root_view->GetRenderWidgetHost());
411 // If the root view is the current gesture target, then we explicitly don't
412 // send a GestureScrollBegin, as by the time we see GesturePinchBegin there
413 // should have been one.
414 if (root_view != touchscreen_gesture_target_.target &&
415 !rwhi->is_in_touchscreen_gesture_scroll()) {
416 gesture_pinch_did_send_scroll_begin_ = true;
417 SendGestureScrollBegin(root_view, *event);
418 }
419 }
420
421 if (in_touchscreen_gesture_pinch_) {
422 root_view->ProcessGestureEvent(*event, latency);
423 if (event->type == blink::WebInputEvent::GesturePinchEnd) {
424 in_touchscreen_gesture_pinch_ = false;
425 // If the root view wasn't already receiving the gesture stream, then we
426 // need to wrap the diverted pinch events in a GestureScrollBegin/End.
427 auto rwhi =
428 static_cast<RenderWidgetHostImpl*>(root_view->GetRenderWidgetHost());
429 if (root_view != touchscreen_gesture_target_.target &&
430 gesture_pinch_did_send_scroll_begin_ &&
431 rwhi->is_in_touchscreen_gesture_scroll()) {
432 SendGestureScrollEnd(root_view, *event);
433 }
434 gesture_pinch_did_send_scroll_begin_ = false;
435 }
436 return;
437 }
438
397 // We use GestureTapDown to detect the start of a gesture sequence since there 439 // We use GestureTapDown to detect the start of a gesture sequence since there
398 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this 440 // is no WebGestureEvent equivalent for ET_GESTURE_BEGIN. Note that this
399 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and 441 // means the GestureFlingCancel that always comes between ET_GESTURE_BEGIN and
400 // GestureTapDown is sent to the previous target, in case it is still in a 442 // GestureTapDown is sent to the previous target, in case it is still in a
401 // fling. 443 // fling.
402 if (event->type == blink::WebInputEvent::GestureTapDown) { 444 if (event->type == blink::WebInputEvent::GestureTapDown) {
403 if (touchscreen_gesture_target_queue_.empty()) { 445 if (touchscreen_gesture_target_queue_.empty()) {
404 LOG(ERROR) << "Gesture sequence start detected with no target available."; 446 LOG(ERROR) << "Gesture sequence start detected with no target available.";
405 // Ignore this gesture sequence as no target is available. 447 // Ignore this gesture sequence as no target is available.
406 // TODO(wjmaclean): this only happens on Windows, and should not happen. 448 // TODO(wjmaclean): this only happens on Windows, and should not happen.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (!touchpad_gesture_target_.target) 506 if (!touchpad_gesture_target_.target)
465 return; 507 return;
466 508
467 // TODO(mohsen): Add tests to check event location. 509 // TODO(mohsen): Add tests to check event location.
468 event->x += touchpad_gesture_target_.delta.x(); 510 event->x += touchpad_gesture_target_.delta.x();
469 event->y += touchpad_gesture_target_.delta.y(); 511 event->y += touchpad_gesture_target_.delta.y();
470 touchpad_gesture_target_.target->ProcessGestureEvent(*event, latency); 512 touchpad_gesture_target_.target->ProcessGestureEvent(*event, latency);
471 } 513 }
472 514
473 } // namespace content 515 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_input_event_router.h ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698