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

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: unittests 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(0, 0, 0, 0, true);
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(const ui::MotionEventData& m) {
1782 ui::MotionEventAndroid::Pointer pointer0(
1783 m.pointer_id_0, m.pos_x_0, m.pos_y_0, m.touch_major_0, m.touch_minor_0,
1784 m.orientation_0, m.tilt_0, m.android_tool_type_0);
1785 ui::MotionEventAndroid::Pointer pointer1(
1786 m.pointer_id_1, m.pos_x_1, m.pos_y_1, m.touch_major_1, m.touch_minor_1,
1787 m.orientation_1, m.tilt_1, m.android_tool_type_1);
1788 JNIEnv* env = base::android::AttachCurrentThread();
1789 ui::MotionEventAndroid event(
1790 1.f / m.dip_scale, env, m.jevent, m.time_ms, m.android_action,
1791 m.pointer_count, m.history_size, m.action_index, m.android_button_state,
1792 m.android_meta_state, m.raw_pos_x - m.pos_x_0, m.raw_pos_y - m.pos_y_0,
1793 &pointer0, &pointer1);
1794
1795 RecordToolTypeForActionDown(event);
1796
1797 // TODO(jinsukkim): Remove this distinction.
1798 return m.is_touch_handle_event ? OnTouchHandleEvent(event)
1799 : OnTouchEvent(event);
1800 }
1801
1802 bool RenderWidgetHostViewAndroid::OnMouseEvent(const ui::MotionEventData& m) {
1803 // Construct a motion_event object minimally, only to convert the raw
1804 // parameters to ui::MotionEvent values. Since we used only the cached values
1805 // at index=0, it is okay to even pass a null event to the constructor.
1806 ui::MotionEventAndroid::Pointer pointer0(
1807 m.pointer_id_0, m.pos_x_0, m.pos_y_0, 0.0f /* touch_major */,
1808 0.0f /* touch_minor */, m.orientation_0, m.tilt_0, m.android_tool_type_0);
1809
1810 JNIEnv* env = base::android::AttachCurrentThread();
1811 ui::MotionEventAndroid event(
1812 1.f / m.dip_scale, env, nullptr /* event */, m.time_ms, m.android_action,
1813 1 /* pointer_count */, 0 /* history_size */, 0 /* action_index */,
1814 m.android_button_state, m.android_meta_state, 0 /* raw_offset_x_pixels */,
1815 0 /* raw_offset_y_pixels */, &pointer0, nullptr);
1816
1817 RecordToolTypeForActionDown(event);
1818 SendMouseEvent(event, m.android_action_button);
1819 return true;
1820 }
1821
1773 void RenderWidgetHostViewAndroid::OnGestureEvent( 1822 void RenderWidgetHostViewAndroid::OnGestureEvent(
1774 const ui::GestureEventData& gesture) { 1823 const ui::GestureEventData& gesture) {
1775 blink::WebGestureEvent web_gesture = 1824 blink::WebGestureEvent web_gesture =
1776 ui::CreateWebGestureEventFromGestureEventData(gesture); 1825 ui::CreateWebGestureEventFromGestureEventData(gesture);
1777 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to 1826 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
1778 // stop providing shift meta values to synthetic MotionEvents. This prevents 1827 // stop providing shift meta values to synthetic MotionEvents. This prevents
1779 // unintended shift+click interpretation of all accessibility clicks. 1828 // unintended shift+click interpretation of all accessibility clicks.
1780 // See crbug.com/443247. 1829 // See crbug.com/443247.
1781 if (web_gesture.type() == blink::WebInputEvent::GestureTap && 1830 if (web_gesture.type() == blink::WebInputEvent::GestureTap &&
1782 web_gesture.modifiers() == blink::WebInputEvent::ShiftKey) { 1831 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(); 2035 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
1987 if (!compositor) 2036 if (!compositor)
1988 return; 2037 return;
1989 2038
1990 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2039 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
1991 overscroll_refresh_handler, compositor, 2040 overscroll_refresh_handler, compositor,
1992 ui::GetScaleFactorForNativeView(GetNativeView())); 2041 ui::GetScaleFactorForNativeView(GetNativeView()));
1993 } 2042 }
1994 2043
1995 } // namespace content 2044 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698