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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: base::Bind (doesn't compile yet) Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "gpu/config/gpu_driver_bug_workaround_type.h" 73 #include "gpu/config/gpu_driver_bug_workaround_type.h"
74 #include "ipc/ipc_message_macros.h" 74 #include "ipc/ipc_message_macros.h"
75 #include "ipc/ipc_message_start.h" 75 #include "ipc/ipc_message_start.h"
76 #include "skia/ext/image_operations.h" 76 #include "skia/ext/image_operations.h"
77 #include "third_party/khronos/GLES2/gl2.h" 77 #include "third_party/khronos/GLES2/gl2.h"
78 #include "third_party/khronos/GLES2/gl2ext.h" 78 #include "third_party/khronos/GLES2/gl2ext.h"
79 #include "third_party/skia/include/core/SkCanvas.h" 79 #include "third_party/skia/include/core/SkCanvas.h"
80 #include "ui/android/window_android.h" 80 #include "ui/android/window_android.h"
81 #include "ui/android/window_android_compositor.h" 81 #include "ui/android/window_android_compositor.h"
82 #include "ui/base/layout.h" 82 #include "ui/base/layout.h"
83 #include "ui/display/display.h" 83 #include "ui/events/android/motion_event_android.h"
84 #include "ui/display/screen.h"
85 #include "ui/events/base_event_utils.h" 84 #include "ui/events/base_event_utils.h"
86 #include "ui/events/blink/blink_event_util.h" 85 #include "ui/events/blink/blink_event_util.h"
87 #include "ui/events/blink/did_overscroll_params.h" 86 #include "ui/events/blink/did_overscroll_params.h"
88 #include "ui/events/blink/web_input_event_traits.h" 87 #include "ui/events/blink/web_input_event_traits.h"
89 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 88 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
90 #include "ui/events/gesture_detection/motion_event.h"
91 #include "ui/gfx/android/java_bitmap.h" 89 #include "ui/gfx/android/java_bitmap.h"
92 #include "ui/gfx/android/view_configuration.h" 90 #include "ui/gfx/android/view_configuration.h"
93 #include "ui/gfx/geometry/dip_util.h" 91 #include "ui/gfx/geometry/dip_util.h"
94 #include "ui/gfx/geometry/size_conversions.h" 92 #include "ui/gfx/geometry/size_conversions.h"
95 #include "ui/touch_selection/touch_selection_controller.h" 93 #include "ui/touch_selection/touch_selection_controller.h"
96 94
97 namespace content { 95 namespace content {
98 96
99 namespace { 97 namespace {
100 98
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 390
393 gl_helper->CropScaleReadbackAndCleanMailbox( 391 gl_helper->CropScaleReadbackAndCleanMailbox(
394 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), 392 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
395 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, 393 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type,
396 base::Bind(&CopyFromCompositingSurfaceFinished, callback, 394 base::Bind(&CopyFromCompositingSurfaceFinished, callback,
397 base::Passed(&release_callback), base::Passed(&bitmap), 395 base::Passed(&release_callback), base::Passed(&bitmap),
398 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), 396 start_time, base::Passed(&bitmap_pixels_lock), readback_lock),
399 display_compositor::GLHelper::SCALER_QUALITY_GOOD); 397 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
400 } 398 }
401 399
400 void RecordToolTypeForActionDown(const ui::MotionEventAndroid& event) {
401 ui::MotionEventAndroid::Action action = event.GetAction();
402 if (action == ui::MotionEventAndroid::ACTION_DOWN ||
403 action == ui::MotionEventAndroid::ACTION_POINTER_DOWN ||
404 action == ui::MotionEventAndroid::ACTION_BUTTON_PRESS) {
405 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
406 event.GetToolType(0),
407 ui::MotionEventAndroid::TOOL_TYPE_LAST + 1);
408 }
409 }
410
402 bool FloatEquals(float a, float b) { 411 bool FloatEquals(float a, float b) {
403 return std::abs(a - b) < FLT_EPSILON; 412 return std::abs(a - b) < FLT_EPSILON;
404 } 413 }
405 414
406 } // namespace 415 } // namespace
407 416
408 void RenderWidgetHostViewAndroid::OnContextLost() { 417 void RenderWidgetHostViewAndroid::OnContextLost() {
409 std::unique_ptr<RenderWidgetHostIterator> widgets( 418 std::unique_ptr<RenderWidgetHostIterator> widgets(
410 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 419 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
411 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 420 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
(...skipping 10 matching lines...) Expand all
422 : host_(widget_host), 431 : host_(widget_host),
423 begin_frame_source_(nullptr), 432 begin_frame_source_(nullptr),
424 outstanding_begin_frame_requests_(0), 433 outstanding_begin_frame_requests_(0),
425 is_showing_(!widget_host->is_hidden()), 434 is_showing_(!widget_host->is_hidden()),
426 is_window_visible_(true), 435 is_window_visible_(true),
427 is_window_activity_started_(true), 436 is_window_activity_started_(true),
428 is_in_vr_(false), 437 is_in_vr_(false),
429 content_view_core_(nullptr), 438 content_view_core_(nullptr),
430 ime_adapter_android_(this), 439 ime_adapter_android_(this),
431 cached_background_color_(SK_ColorWHITE), 440 cached_background_color_(SK_ColorWHITE),
441 view_(this),
432 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 442 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
433 gesture_provider_(ui::GetGestureProviderConfig( 443 gesture_provider_(ui::GetGestureProviderConfig(
434 ui::GestureProviderConfigType::CURRENT_PLATFORM), 444 ui::GestureProviderConfigType::CURRENT_PLATFORM),
435 this), 445 this),
436 stylus_text_selector_(this), 446 stylus_text_selector_(this),
437 using_browser_compositor_(CompositorImpl::IsInitialized()), 447 using_browser_compositor_(CompositorImpl::IsInitialized()),
438 synchronous_compositor_client_(nullptr), 448 synchronous_compositor_client_(nullptr),
439 frame_evictor_(new DelegatedFrameEvictor(this)), 449 frame_evictor_(new DelegatedFrameEvictor(this)),
440 observing_root_window_(false), 450 observing_root_window_(false),
441 prev_top_shown_pix_(0.f), 451 prev_top_shown_pix_(0.f),
442 prev_bottom_shown_pix_(0.f), 452 prev_bottom_shown_pix_(0.f),
443 weak_ptr_factory_(this) { 453 weak_ptr_factory_(this) {
444 // Set the layer which will hold the content layer for this view. The content 454 // Set the layer which will hold the content layer for this view. The content
445 // layer is managed by the DelegatedFrameHost. 455 // layer is managed by the DelegatedFrameHost.
446 view_.SetLayer(cc::Layer::Create()); 456 view_.SetLayer(cc::Layer::Create());
457 view_.SetLayout(ui::ViewAndroid::LayoutParams::MatchParent());
458
447 if (using_browser_compositor_) { 459 if (using_browser_compositor_) {
448 cc::FrameSinkId frame_sink_id = 460 cc::FrameSinkId frame_sink_id =
449 host_->AllocateFrameSinkId(false /* is_guest_view_hack */); 461 host_->AllocateFrameSinkId(false /* is_guest_view_hack */);
450 delegated_frame_host_.reset( 462 delegated_frame_host_.reset(
451 new ui::DelegatedFrameHostAndroid(&view_, this, frame_sink_id)); 463 new ui::DelegatedFrameHostAndroid(&view_, this, frame_sink_id));
452 } 464 }
453 465
454 host_->SetView(this); 466 host_->SetView(this);
455 SetContentViewCore(content_view_core); 467 SetContentViewCore(content_view_core);
456 468
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 const ReadbackRequestCallback& result_callback) { 547 const ReadbackRequestCallback& result_callback) {
536 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { 548 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
537 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 549 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
538 return; 550 return;
539 } 551 }
540 gfx::Size bounds = current_surface_size_; 552 gfx::Size bounds = current_surface_size_;
541 if (src_subrect.IsEmpty()) 553 if (src_subrect.IsEmpty())
542 src_subrect = gfx::Rect(bounds); 554 src_subrect = gfx::Rect(bounds);
543 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); 555 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
544 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); 556 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
545 const display::Display& display = 557 float device_scale_factor = view_.GetDipScale();
546 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
547 float device_scale_factor = display.device_scale_factor();
548 DCHECK_GT(device_scale_factor, 0); 558 DCHECK_GT(device_scale_factor, 0);
549 gfx::Size dst_size( 559 gfx::Size dst_size(
550 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); 560 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
551 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); 561 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect);
552 562
553 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, 563 CopyFromCompositingSurface(src_subrect, dst_size, result_callback,
554 preferred_color_type); 564 preferred_color_type);
555 } 565 }
556 566
557 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 567 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 if (!host_ || !IsSurfaceAvailableForCopy()) { 938 if (!host_ || !IsSurfaceAvailableForCopy()) {
929 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 939 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
930 return; 940 return;
931 } 941 }
932 if (!(view_.GetWindowAndroid())) { 942 if (!(view_.GetWindowAndroid())) {
933 callback.Run(SkBitmap(), READBACK_FAILED); 943 callback.Run(SkBitmap(), READBACK_FAILED);
934 return; 944 return;
935 } 945 }
936 946
937 base::TimeTicks start_time = base::TimeTicks::Now(); 947 base::TimeTicks start_time = base::TimeTicks::Now();
938 const display::Display& display = 948 float device_scale_factor = view_.GetDipScale();
939 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
940 float device_scale_factor = display.device_scale_factor();
941 gfx::Size dst_size_in_pixel = 949 gfx::Size dst_size_in_pixel =
942 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 950 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
943 gfx::Rect src_subrect_in_pixel = 951 gfx::Rect src_subrect_in_pixel =
944 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); 952 gfx::ConvertRectToPixel(device_scale_factor, src_subrect);
945 953
946 if (!using_browser_compositor_) { 954 if (!using_browser_compositor_) {
947 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 955 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
948 preferred_color_type); 956 preferred_color_type);
949 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 957 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
950 base::TimeTicks::Now() - start_time); 958 base::TimeTicks::Now() - start_time);
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 CreateOverscrollControllerIfPossible(); 1771 CreateOverscrollControllerIfPossible();
1764 } 1772 }
1765 1773
1766 void RenderWidgetHostViewAndroid::RunAckCallbacks() { 1774 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
1767 while (!ack_callbacks_.empty()) { 1775 while (!ack_callbacks_.empty()) {
1768 ack_callbacks_.front().Run(); 1776 ack_callbacks_.front().Run();
1769 ack_callbacks_.pop(); 1777 ack_callbacks_.pop();
1770 } 1778 }
1771 } 1779 }
1772 1780
1781 bool RenderWidgetHostViewAndroid::OnTouchEvent(
1782 const ui::MotionEventAndroid& event,
1783 bool for_touch_handle) {
1784 RecordToolTypeForActionDown(event);
1785
1786 // TODO(jinsukkim): Remove this distinction.
1787 return for_touch_handle ? OnTouchHandleEvent(event) : OnTouchEvent(event);
1788 }
1789
1790 bool RenderWidgetHostViewAndroid::OnMouseEvent(
1791 const ui::MotionEventAndroid& event) {
1792 RecordToolTypeForActionDown(event);
1793 SendMouseEvent(event, event.GetActionButton());
1794 return true;
1795 }
1796
1773 void RenderWidgetHostViewAndroid::OnGestureEvent( 1797 void RenderWidgetHostViewAndroid::OnGestureEvent(
1774 const ui::GestureEventData& gesture) { 1798 const ui::GestureEventData& gesture) {
1775 blink::WebGestureEvent web_gesture = 1799 blink::WebGestureEvent web_gesture =
1776 ui::CreateWebGestureEventFromGestureEventData(gesture); 1800 ui::CreateWebGestureEventFromGestureEventData(gesture);
1777 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to 1801 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
1778 // stop providing shift meta values to synthetic MotionEvents. This prevents 1802 // stop providing shift meta values to synthetic MotionEvents. This prevents
1779 // unintended shift+click interpretation of all accessibility clicks. 1803 // unintended shift+click interpretation of all accessibility clicks.
1780 // See crbug.com/443247. 1804 // See crbug.com/443247.
1781 if (web_gesture.type() == blink::WebInputEvent::GestureTap && 1805 if (web_gesture.type() == blink::WebInputEvent::GestureTap &&
1782 web_gesture.modifiers() == blink::WebInputEvent::ShiftKey) { 1806 web_gesture.modifiers() == blink::WebInputEvent::ShiftKey) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2010 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
1987 if (!compositor) 2011 if (!compositor)
1988 return; 2012 return;
1989 2013
1990 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2014 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
1991 overscroll_refresh_handler, compositor, 2015 overscroll_refresh_handler, compositor,
1992 ui::GetScaleFactorForNativeView(GetNativeView())); 2016 ui::GetScaleFactorForNativeView(GetNativeView()));
1993 } 2017 }
1994 2018
1995 } // namespace content 2019 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698