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

Side by Side Diff: content/browser/android/event_forwarder_impl.cc

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: - 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 unified diff | Download patch
« no previous file with comments | « content/browser/android/event_forwarder_impl.h ('k') | content/public/android/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/android/event_forwarder_impl.h"
6
7 #include "base/metrics/histogram_macros.h"
8 #include "content/browser/renderer_host/render_widget_host_view_android.h"
9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/browser/web_contents/web_contents_view.h"
11 #include "content/public/browser/interstitial_page.h"
12 #include "jni/EventForwarderImpl_jni.h"
13
14 using base::android::JavaParamRef;
15 using ui::MotionEventAndroid;
16
17 namespace content {
18
19 namespace {
20
21 void RecordToolTypeForActionDown(MotionEventAndroid& event) {
22 MotionEventAndroid::Action action = event.GetAction();
23 if (action == MotionEventAndroid::ACTION_DOWN ||
24 action == MotionEventAndroid::ACTION_POINTER_DOWN ||
25 action == MotionEventAndroid::ACTION_BUTTON_PRESS) {
26 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
27 event.GetToolType(0),
28 MotionEventAndroid::TOOL_TYPE_LAST + 1);
29 }
30 }
31
32 } // namespace
33
34 EventForwarderImpl::EventForwarderImpl(WebContentsImpl* web_contents)
35 : web_contents_(web_contents) {
36 dip_scale_ = GetViewAndroid()->GetDipScale();
37 }
38
39 jboolean EventForwarderImpl::OnTouchEvent(
40 JNIEnv* env,
41 const JavaParamRef<jobject>& obj,
42 const JavaParamRef<jobject>& motion_event,
43 jlong time_ms,
44 jint android_action,
45 jint pointer_count,
46 jint history_size,
47 jint action_index,
48 jfloat pos_x_0,
49 jfloat pos_y_0,
50 jfloat pos_x_1,
51 jfloat pos_y_1,
52 jint pointer_id_0,
53 jint pointer_id_1,
54 jfloat touch_major_0,
55 jfloat touch_major_1,
56 jfloat touch_minor_0,
57 jfloat touch_minor_1,
58 jfloat orientation_0,
59 jfloat orientation_1,
60 jfloat tilt_0,
61 jfloat tilt_1,
62 jfloat raw_pos_x,
63 jfloat raw_pos_y,
64 jint android_tool_type_0,
65 jint android_tool_type_1,
66 jint android_button_state,
67 jint android_meta_state,
68 jboolean is_touch_handle_event) {
69 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
70 // Avoid synthesizing a touch event if it cannot be forwarded.
71 if (!rwhv)
72 return false;
73
74 MotionEventAndroid::Pointer pointer0(
75 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0,
76 orientation_0, tilt_0, android_tool_type_0);
77 MotionEventAndroid::Pointer pointer1(
78 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1,
79 orientation_1, tilt_1, android_tool_type_1);
80 MotionEventAndroid event(1.f / dip_scale_, env, motion_event, time_ms,
81 android_action, pointer_count, history_size,
82 action_index, android_button_state,
83 android_meta_state, raw_pos_x - pos_x_0,
84 raw_pos_y - pos_y_0, &pointer0, &pointer1);
85
86 RecordToolTypeForActionDown(event);
87 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
boliu 2017/02/21 16:23:30 this isn't actually using the viewandroid tree to
Jinsuk Kim 2017/02/26 23:18:27 Done.
88 : rwhv->OnTouchEvent(event);
89 }
90
91 ui::ViewAndroid* EventForwarderImpl::GetViewAndroid() const {
92 return web_contents_->GetView()->GetNativeView();
93 }
94
95 RenderWidgetHostViewAndroid*
96 EventForwarderImpl::GetRenderWidgetHostViewAndroid() const {
97 RenderWidgetHostView* rwhv = nullptr;
98 rwhv = web_contents_->GetRenderWidgetHostView();
99 if (web_contents_->ShowingInterstitialPage()) {
100 rwhv = web_contents_->GetInterstitialPage()
101 ->GetMainFrame()
102 ->GetRenderViewHost()
103 ->GetWidget()
104 ->GetView();
105 }
106 return static_cast<RenderWidgetHostViewAndroid*>(rwhv);
107 }
108
109 jlong Init(JNIEnv* env,
110 const JavaParamRef<jobject>& obj,
111 const JavaParamRef<jobject>& jweb_contents) {
112 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
113 WebContents::FromJavaWebContents(jweb_contents));
114 CHECK(web_contents)
115 << "An EventFowarder should be created with a valid WebContents.";
116 return reinterpret_cast<intptr_t>(new EventForwarderImpl(web_contents));
117 }
118
119 bool RegisterEventForwarderImpl(JNIEnv* env) {
120 return RegisterNativesImpl(env);
121 }
122
123 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/event_forwarder_impl.h ('k') | content/public/android/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698