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

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: EventForwarder... 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #include "gpu/config/gpu_driver_bug_workaround_type.h" 77 #include "gpu/config/gpu_driver_bug_workaround_type.h"
78 #include "ipc/ipc_message_macros.h" 78 #include "ipc/ipc_message_macros.h"
79 #include "ipc/ipc_message_start.h" 79 #include "ipc/ipc_message_start.h"
80 #include "skia/ext/image_operations.h" 80 #include "skia/ext/image_operations.h"
81 #include "third_party/khronos/GLES2/gl2.h" 81 #include "third_party/khronos/GLES2/gl2.h"
82 #include "third_party/khronos/GLES2/gl2ext.h" 82 #include "third_party/khronos/GLES2/gl2ext.h"
83 #include "third_party/skia/include/core/SkCanvas.h" 83 #include "third_party/skia/include/core/SkCanvas.h"
84 #include "ui/android/window_android.h" 84 #include "ui/android/window_android.h"
85 #include "ui/android/window_android_compositor.h" 85 #include "ui/android/window_android_compositor.h"
86 #include "ui/base/layout.h" 86 #include "ui/base/layout.h"
87 #include "ui/display/display.h" 87 #include "ui/events/android/motion_event_android.h"
88 #include "ui/display/screen.h"
89 #include "ui/events/base_event_utils.h" 88 #include "ui/events/base_event_utils.h"
90 #include "ui/events/blink/blink_event_util.h" 89 #include "ui/events/blink/blink_event_util.h"
91 #include "ui/events/blink/did_overscroll_params.h" 90 #include "ui/events/blink/did_overscroll_params.h"
92 #include "ui/events/blink/web_input_event_traits.h" 91 #include "ui/events/blink/web_input_event_traits.h"
93 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 92 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
94 #include "ui/events/gesture_detection/motion_event.h"
95 #include "ui/gfx/android/java_bitmap.h" 93 #include "ui/gfx/android/java_bitmap.h"
96 #include "ui/gfx/android/view_configuration.h" 94 #include "ui/gfx/android/view_configuration.h"
97 #include "ui/gfx/geometry/dip_util.h" 95 #include "ui/gfx/geometry/dip_util.h"
98 #include "ui/gfx/geometry/size_conversions.h" 96 #include "ui/gfx/geometry/size_conversions.h"
99 #include "ui/touch_selection/touch_selection_controller.h" 97 #include "ui/touch_selection/touch_selection_controller.h"
100 98
101 namespace content { 99 namespace content {
102 100
103 namespace { 101 namespace {
104 102
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 394
397 gl_helper->CropScaleReadbackAndCleanMailbox( 395 gl_helper->CropScaleReadbackAndCleanMailbox(
398 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), 396 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
399 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, 397 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type,
400 base::Bind(&CopyFromCompositingSurfaceFinished, callback, 398 base::Bind(&CopyFromCompositingSurfaceFinished, callback,
401 base::Passed(&release_callback), base::Passed(&bitmap), 399 base::Passed(&release_callback), base::Passed(&bitmap),
402 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), 400 start_time, base::Passed(&bitmap_pixels_lock), readback_lock),
403 display_compositor::GLHelper::SCALER_QUALITY_GOOD); 401 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
404 } 402 }
405 403
404 void RecordToolTypeForActionDown(const ui::MotionEventAndroid& event) {
405 ui::MotionEventAndroid::Action action = event.GetAction();
406 if (action == ui::MotionEventAndroid::ACTION_DOWN ||
407 action == ui::MotionEventAndroid::ACTION_POINTER_DOWN ||
408 action == ui::MotionEventAndroid::ACTION_BUTTON_PRESS) {
409 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
410 event.GetToolType(0),
411 ui::MotionEventAndroid::TOOL_TYPE_LAST + 1);
412 }
413 }
414
406 bool FloatEquals(float a, float b) { 415 bool FloatEquals(float a, float b) {
407 return std::abs(a - b) < FLT_EPSILON; 416 return std::abs(a - b) < FLT_EPSILON;
408 } 417 }
409 418
410 void WakeUpGpu(GpuProcessHost* host) { 419 void WakeUpGpu(GpuProcessHost* host) {
411 DCHECK(host); 420 DCHECK(host);
412 GpuDataManagerImpl* gpu_data = GpuDataManagerImpl::GetInstance(); 421 GpuDataManagerImpl* gpu_data = GpuDataManagerImpl::GetInstance();
413 if (gpu_data && 422 if (gpu_data &&
414 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) 423 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING))
415 host->gpu_service()->WakeUpGpu(); 424 host->gpu_service()->WakeUpGpu();
(...skipping 18 matching lines...) Expand all
434 : host_(widget_host), 443 : host_(widget_host),
435 begin_frame_source_(nullptr), 444 begin_frame_source_(nullptr),
436 outstanding_begin_frame_requests_(0), 445 outstanding_begin_frame_requests_(0),
437 is_showing_(!widget_host->is_hidden()), 446 is_showing_(!widget_host->is_hidden()),
438 is_window_visible_(true), 447 is_window_visible_(true),
439 is_window_activity_started_(true), 448 is_window_activity_started_(true),
440 is_in_vr_(false), 449 is_in_vr_(false),
441 content_view_core_(nullptr), 450 content_view_core_(nullptr),
442 ime_adapter_android_(this), 451 ime_adapter_android_(this),
443 cached_background_color_(SK_ColorWHITE), 452 cached_background_color_(SK_ColorWHITE),
453 view_(this),
444 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 454 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
445 gesture_provider_(ui::GetGestureProviderConfig( 455 gesture_provider_(ui::GetGestureProviderConfig(
446 ui::GestureProviderConfigType::CURRENT_PLATFORM), 456 ui::GestureProviderConfigType::CURRENT_PLATFORM),
447 this), 457 this),
448 stylus_text_selector_(this), 458 stylus_text_selector_(this),
449 using_browser_compositor_(CompositorImpl::IsInitialized()), 459 using_browser_compositor_(CompositorImpl::IsInitialized()),
450 synchronous_compositor_client_(nullptr), 460 synchronous_compositor_client_(nullptr),
451 frame_evictor_(new DelegatedFrameEvictor(this)), 461 frame_evictor_(new DelegatedFrameEvictor(this)),
452 observing_root_window_(false), 462 observing_root_window_(false),
453 prev_top_shown_pix_(0.f), 463 prev_top_shown_pix_(0.f),
454 prev_bottom_shown_pix_(0.f), 464 prev_bottom_shown_pix_(0.f),
455 weak_ptr_factory_(this) { 465 weak_ptr_factory_(this) {
456 // Set the layer which will hold the content layer for this view. The content 466 // Set the layer which will hold the content layer for this view. The content
457 // layer is managed by the DelegatedFrameHost. 467 // layer is managed by the DelegatedFrameHost.
458 view_.SetLayer(cc::Layer::Create()); 468 view_.SetLayer(cc::Layer::Create());
469 view_.SetLayout(ui::ViewAndroid::LayoutParams::MatchParent());
470
459 if (using_browser_compositor_) { 471 if (using_browser_compositor_) {
460 cc::FrameSinkId frame_sink_id = 472 cc::FrameSinkId frame_sink_id =
461 host_->AllocateFrameSinkId(false /* is_guest_view_hack */); 473 host_->AllocateFrameSinkId(false /* is_guest_view_hack */);
462 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( 474 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
463 &view_, CompositorImpl::GetSurfaceManager(), this, frame_sink_id)); 475 &view_, CompositorImpl::GetSurfaceManager(), this, frame_sink_id));
464 476
465 // Let the page-level input event router know about our frame sink ID 477 // Let the page-level input event router know about our frame sink ID
466 // for surface-based hit testing. 478 // for surface-based hit testing.
467 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { 479 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) {
468 host_->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner( 480 host_->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner(
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 : cc::SurfaceId(); 801 : cc::SurfaceId();
790 } 802 }
791 803
792 cc::FrameSinkId RenderWidgetHostViewAndroid::FrameSinkIdAtPoint( 804 cc::FrameSinkId RenderWidgetHostViewAndroid::FrameSinkIdAtPoint(
793 cc::SurfaceHittestDelegate* delegate, 805 cc::SurfaceHittestDelegate* delegate,
794 const gfx::Point& point, 806 const gfx::Point& point,
795 gfx::Point* transformed_point) { 807 gfx::Point* transformed_point) {
796 if (!delegated_frame_host_) 808 if (!delegated_frame_host_)
797 return cc::FrameSinkId(); 809 return cc::FrameSinkId();
798 810
799 float scale_factor = 811 float scale_factor = view_.GetDipScale();
800 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
801 DCHECK_GT(scale_factor, 0); 812 DCHECK_GT(scale_factor, 0);
802 // The surface hittest happens in device pixels, so we need to convert the 813 // The surface hittest happens in device pixels, so we need to convert the
803 // |point| from DIPs to pixels before hittesting. 814 // |point| from DIPs to pixels before hittesting.
804 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); 815 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point);
805 816
806 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId(); 817 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId();
807 if (surface_id.is_valid()) { 818 if (surface_id.is_valid()) {
808 cc::SurfaceHittest hittest(delegate, GetSurfaceManager()); 819 cc::SurfaceHittest hittest(delegate, GetSurfaceManager());
809 gfx::Transform target_transform; 820 gfx::Transform target_transform;
810 surface_id = hittest.GetTargetSurfaceAtPoint(surface_id, point_in_pixels, 821 surface_id = hittest.GetTargetSurfaceAtPoint(surface_id, point_in_pixels,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 host_->ForwardGestureEventWithLatencyInfo(event, latency); 858 host_->ForwardGestureEventWithLatencyInfo(event, latency);
848 } 859 }
849 860
850 bool RenderWidgetHostViewAndroid::TransformPointToLocalCoordSpace( 861 bool RenderWidgetHostViewAndroid::TransformPointToLocalCoordSpace(
851 const gfx::Point& point, 862 const gfx::Point& point,
852 const cc::SurfaceId& original_surface, 863 const cc::SurfaceId& original_surface,
853 gfx::Point* transformed_point) { 864 gfx::Point* transformed_point) {
854 if (!delegated_frame_host_) 865 if (!delegated_frame_host_)
855 return false; 866 return false;
856 867
857 float scale_factor = 868 float scale_factor = view_.GetDipScale();
858 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
859 DCHECK_GT(scale_factor, 0); 869 DCHECK_GT(scale_factor, 0);
860 // Transformations use physical pixels rather than DIP, so conversion 870 // Transformations use physical pixels rather than DIP, so conversion
861 // is necessary. 871 // is necessary.
862 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); 872 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point);
863 873
864 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId(); 874 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId();
865 if (!surface_id.is_valid()) 875 if (!surface_id.is_valid())
866 return false; 876 return false;
867 877
868 if (original_surface == surface_id) 878 if (original_surface == surface_id)
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 if (!host_ || !IsSurfaceAvailableForCopy()) { 1046 if (!host_ || !IsSurfaceAvailableForCopy()) {
1037 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 1047 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
1038 return; 1048 return;
1039 } 1049 }
1040 if (!(view_.GetWindowAndroid())) { 1050 if (!(view_.GetWindowAndroid())) {
1041 callback.Run(SkBitmap(), READBACK_FAILED); 1051 callback.Run(SkBitmap(), READBACK_FAILED);
1042 return; 1052 return;
1043 } 1053 }
1044 1054
1045 base::TimeTicks start_time = base::TimeTicks::Now(); 1055 base::TimeTicks start_time = base::TimeTicks::Now();
1046 const display::Display& display = 1056 float device_scale_factor = view_.GetDipScale();
1047 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
1048 float device_scale_factor = display.device_scale_factor();
1049 gfx::Size dst_size_in_pixel = 1057 gfx::Size dst_size_in_pixel =
1050 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 1058 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
1051 // Note: When |src_subrect| is empty, a conversion from the view size must be 1059 // Note: When |src_subrect| is empty, a conversion from the view size must be
1052 // made instead of using |current_frame_size_|. The latter sometimes also 1060 // made instead of using |current_frame_size_|. The latter sometimes also
1053 // includes extra height for the toolbar UI, which is not intended for 1061 // includes extra height for the toolbar UI, which is not intended for
1054 // capture. 1062 // capture.
1055 gfx::Rect src_subrect_in_pixel = gfx::ConvertRectToPixel( 1063 gfx::Rect src_subrect_in_pixel = gfx::ConvertRectToPixel(
1056 device_scale_factor, src_subrect.IsEmpty() 1064 device_scale_factor, src_subrect.IsEmpty()
1057 ? gfx::Rect(GetVisibleViewportSize()) 1065 ? gfx::Rect(GetVisibleViewportSize())
1058 : src_subrect); 1066 : src_subrect);
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 CreateOverscrollControllerIfPossible(); 1893 CreateOverscrollControllerIfPossible();
1886 } 1894 }
1887 1895
1888 void RenderWidgetHostViewAndroid::RunAckCallbacks() { 1896 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
1889 while (!ack_callbacks_.empty()) { 1897 while (!ack_callbacks_.empty()) {
1890 ack_callbacks_.front().Run(); 1898 ack_callbacks_.front().Run();
1891 ack_callbacks_.pop(); 1899 ack_callbacks_.pop();
1892 } 1900 }
1893 } 1901 }
1894 1902
1903 bool RenderWidgetHostViewAndroid::OnTouchEvent(
1904 const ui::MotionEventAndroid& event,
1905 bool for_touch_handle) {
1906 RecordToolTypeForActionDown(event);
1907
1908 // TODO(jinsukkim): Remove this distinction.
1909 return for_touch_handle ? OnTouchHandleEvent(event) : OnTouchEvent(event);
1910 }
1911
1912 bool RenderWidgetHostViewAndroid::OnMouseEvent(
1913 const ui::MotionEventAndroid& event) {
1914 RecordToolTypeForActionDown(event);
1915 SendMouseEvent(event, event.GetActionButton());
1916 return true;
1917 }
1918
1895 void RenderWidgetHostViewAndroid::OnGestureEvent( 1919 void RenderWidgetHostViewAndroid::OnGestureEvent(
1896 const ui::GestureEventData& gesture) { 1920 const ui::GestureEventData& gesture) {
1897 blink::WebGestureEvent web_gesture = 1921 blink::WebGestureEvent web_gesture =
1898 ui::CreateWebGestureEventFromGestureEventData(gesture); 1922 ui::CreateWebGestureEventFromGestureEventData(gesture);
1899 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to 1923 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
1900 // stop providing shift meta values to synthetic MotionEvents. This prevents 1924 // stop providing shift meta values to synthetic MotionEvents. This prevents
1901 // unintended shift+click interpretation of all accessibility clicks. 1925 // unintended shift+click interpretation of all accessibility clicks.
1902 // See crbug.com/443247. 1926 // See crbug.com/443247.
1903 if (web_gesture.type() == blink::WebInputEvent::GestureTap && 1927 if (web_gesture.type() == blink::WebInputEvent::GestureTap &&
1904 web_gesture.modifiers() == blink::WebInputEvent::ShiftKey) { 1928 web_gesture.modifiers() == blink::WebInputEvent::ShiftKey) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2132 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2109 if (!compositor) 2133 if (!compositor)
2110 return; 2134 return;
2111 2135
2112 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2136 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2113 overscroll_refresh_handler, compositor, 2137 overscroll_refresh_handler, compositor,
2114 ui::GetScaleFactorForNativeView(GetNativeView())); 2138 ui::GetScaleFactorForNativeView(GetNativeView()));
2115 } 2139 }
2116 2140
2117 } // namespace content 2141 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | content/browser/web_contents/web_contents_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698