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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_android.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 53c758f11f2760db6d1ec2218b6fdc475ba4ecbb..aa600860b1fdf51f00058be27d21b3c7fb0827d2 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -80,14 +80,12 @@
#include "ui/android/window_android.h"
#include "ui/android/window_android_compositor.h"
#include "ui/base/layout.h"
-#include "ui/display/display.h"
-#include "ui/display/screen.h"
+#include "ui/events/android/motion_event_android.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/blink/did_overscroll_params.h"
#include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
-#include "ui/events/gesture_detection/motion_event.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/android/view_configuration.h"
#include "ui/gfx/geometry/dip_util.h"
@@ -399,6 +397,17 @@ void PrepareTextureCopyOutputResult(
display_compositor::GLHelper::SCALER_QUALITY_GOOD);
}
+void RecordToolTypeForActionDown(const ui::MotionEventAndroid& event) {
+ ui::MotionEventAndroid::Action action = event.GetAction();
+ if (action == ui::MotionEventAndroid::ACTION_DOWN ||
+ action == ui::MotionEventAndroid::ACTION_POINTER_DOWN ||
+ action == ui::MotionEventAndroid::ACTION_BUTTON_PRESS) {
+ UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
+ event.GetToolType(0),
+ ui::MotionEventAndroid::TOOL_TYPE_LAST + 1);
+ }
+}
+
bool FloatEquals(float a, float b) {
return std::abs(a - b) < FLT_EPSILON;
}
@@ -429,6 +438,7 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
content_view_core_(nullptr),
ime_adapter_android_(this),
cached_background_color_(SK_ColorWHITE),
+ view_(this),
last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
gesture_provider_(ui::GetGestureProviderConfig(
ui::GestureProviderConfigType::CURRENT_PLATFORM),
@@ -444,6 +454,8 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
// Set the layer which will hold the content layer for this view. The content
// layer is managed by the DelegatedFrameHost.
view_.SetLayer(cc::Layer::Create());
+ view_.SetLayout(0, 0, 0, 0, true);
+
if (using_browser_compositor_) {
cc::FrameSinkId frame_sink_id =
host_->AllocateFrameSinkId(false /* is_guest_view_hack */);
@@ -542,9 +554,7 @@ void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
src_subrect = gfx::Rect(bounds);
DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
- const display::Display& display =
- display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
- float device_scale_factor = display.device_scale_factor();
+ float device_scale_factor = view_.GetDipScale();
DCHECK_GT(device_scale_factor, 0);
gfx::Size dst_size(
gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
@@ -935,9 +945,7 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
}
base::TimeTicks start_time = base::TimeTicks::Now();
- const display::Display& display =
- display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
- float device_scale_factor = display.device_scale_factor();
+ float device_scale_factor = view_.GetDipScale();
gfx::Size dst_size_in_pixel =
gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
gfx::Rect src_subrect_in_pixel =
@@ -1770,6 +1778,47 @@ void RenderWidgetHostViewAndroid::RunAckCallbacks() {
}
}
+bool RenderWidgetHostViewAndroid::OnTouchEvent(const ui::MotionEventData& m) {
+ ui::MotionEventAndroid::Pointer pointer0(
+ m.pointer_id_0, m.pos_x_0, m.pos_y_0, m.touch_major_0, m.touch_minor_0,
+ m.orientation_0, m.tilt_0, m.android_tool_type_0);
+ ui::MotionEventAndroid::Pointer pointer1(
+ m.pointer_id_1, m.pos_x_1, m.pos_y_1, m.touch_major_1, m.touch_minor_1,
+ m.orientation_1, m.tilt_1, m.android_tool_type_1);
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ui::MotionEventAndroid event(
+ 1.f / m.dip_scale, env, m.jevent, m.time_ms, m.android_action,
+ m.pointer_count, m.history_size, m.action_index, m.android_button_state,
+ m.android_meta_state, m.raw_pos_x - m.pos_x_0, m.raw_pos_y - m.pos_y_0,
+ &pointer0, &pointer1);
+
+ RecordToolTypeForActionDown(event);
+
+ // TODO(jinsukkim): Remove this distinction.
+ return m.is_touch_handle_event ? OnTouchHandleEvent(event)
+ : OnTouchEvent(event);
+}
+
+bool RenderWidgetHostViewAndroid::OnMouseEvent(const ui::MotionEventData& m) {
+ // Construct a motion_event object minimally, only to convert the raw
+ // parameters to ui::MotionEvent values. Since we used only the cached values
+ // at index=0, it is okay to even pass a null event to the constructor.
+ ui::MotionEventAndroid::Pointer pointer0(
+ m.pointer_id_0, m.pos_x_0, m.pos_y_0, 0.0f /* touch_major */,
+ 0.0f /* touch_minor */, m.orientation_0, m.tilt_0, m.android_tool_type_0);
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ui::MotionEventAndroid event(
+ 1.f / m.dip_scale, env, nullptr /* event */, m.time_ms, m.android_action,
+ 1 /* pointer_count */, 0 /* history_size */, 0 /* action_index */,
+ m.android_button_state, m.android_meta_state, 0 /* raw_offset_x_pixels */,
+ 0 /* raw_offset_y_pixels */, &pointer0, nullptr);
+
+ RecordToolTypeForActionDown(event);
+ SendMouseEvent(event, m.android_action_button);
+ return true;
+}
+
void RenderWidgetHostViewAndroid::OnGestureEvent(
const ui::GestureEventData& gesture) {
blink::WebGestureEvent web_gesture =

Powered by Google App Engine
This is Rietveld 408576698