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

Side by Side Diff: ui/android/event_forwarder.cc

Issue 2770613002: Forward GenericMotionEvent to EventForwarder (Closed)
Patch Set: comments Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 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 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 "ui/android/event_forwarder.h" 5 #include "ui/android/event_forwarder.h"
6 6
7 #include "base/metrics/histogram_macros.h"
7 #include "jni/EventForwarder_jni.h" 8 #include "jni/EventForwarder_jni.h"
8 #include "ui/android/view_android.h" 9 #include "ui/android/view_android.h"
9 #include "ui/android/view_client.h" 10 #include "ui/android/view_client.h"
10 #include "ui/events/android/motion_event_android.h" 11 #include "ui/events/android/motion_event_android.h"
12 #include "ui/events/base_event_utils.h"
11 13
12 namespace ui { 14 namespace ui {
13 15
14 using base::android::JavaParamRef; 16 using base::android::JavaParamRef;
15 using base::android::ScopedJavaLocalRef; 17 using base::android::ScopedJavaLocalRef;
16 18
17 EventForwarder::EventForwarder(ViewAndroid* view) : view_(view) {} 19 EventForwarder::EventForwarder(ViewAndroid* view) : view_(view) {}
18 20
19 EventForwarder::~EventForwarder() { 21 EventForwarder::~EventForwarder() {
20 if (!java_obj_.is_null()) { 22 if (!java_obj_.is_null()) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 jint android_button_state, 64 jint android_button_state,
63 jint android_meta_state, 65 jint android_meta_state,
64 jboolean is_touch_handle_event) { 66 jboolean is_touch_handle_event) {
65 ui::MotionEventAndroid::Pointer pointer0( 67 ui::MotionEventAndroid::Pointer pointer0(
66 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0, 68 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0,
67 orientation_0, tilt_0, android_tool_type_0); 69 orientation_0, tilt_0, android_tool_type_0);
68 ui::MotionEventAndroid::Pointer pointer1( 70 ui::MotionEventAndroid::Pointer pointer1(
69 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1, 71 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1,
70 orientation_1, tilt_1, android_tool_type_1); 72 orientation_1, tilt_1, android_tool_type_1);
71 ui::MotionEventAndroid event( 73 ui::MotionEventAndroid event(
72 1.f / view_->GetDipScale(), env, motion_event.obj(), time_ms, 74 env, motion_event.obj(), 1.f / view_->GetDipScale(), 0.f, 0.f, 0.f,
73 android_action, pointer_count, history_size, action_index, 75 time_ms, android_action, pointer_count, history_size, action_index,
74 0 /* action_button */, android_button_state, android_meta_state, 76 0 /* action_button */, android_button_state, android_meta_state,
75 raw_pos_x - pos_x_0, raw_pos_y - pos_y_0, &pointer0, &pointer1); 77 raw_pos_x - pos_x_0, raw_pos_y - pos_y_0, &pointer0, &pointer1);
76 return view_->OnTouchEvent(event, is_touch_handle_event); 78 return view_->OnTouchEvent(event, is_touch_handle_event);
77 } 79 }
78 80
79 void EventForwarder::OnMouseEvent(JNIEnv* env, 81 void EventForwarder::OnMouseEvent(JNIEnv* env,
80 const JavaParamRef<jobject>& obj, 82 const JavaParamRef<jobject>& obj,
81 jlong time_ms, 83 jlong time_ms,
82 jint android_action, 84 jint android_action,
83 jfloat x, 85 jfloat x,
84 jfloat y, 86 jfloat y,
85 jint pointer_id, 87 jint pointer_id,
86 jfloat orientation, 88 jfloat orientation,
87 jfloat pressure, 89 jfloat pressure,
88 jfloat tilt, 90 jfloat tilt,
89 jint android_action_button, 91 jint android_action_button,
90 jint android_button_state, 92 jint android_button_state,
91 jint android_meta_state, 93 jint android_meta_state,
92 jint android_tool_type) { 94 jint android_tool_type) {
93 // Construct a motion_event object minimally, only to convert the raw 95 // Construct a motion_event object minimally, only to convert the raw
94 // parameters to ui::MotionEvent values. Since we used only the cached values 96 // parameters to ui::MotionEvent values. Since we used only the cached values
95 // at index=0, it is okay to even pass a null event to the constructor. 97 // at index=0, it is okay to even pass a null event to the constructor.
96 ui::MotionEventAndroid::Pointer pointer( 98 ui::MotionEventAndroid::Pointer pointer(
97 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, 99 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
98 orientation, tilt, android_tool_type); 100 orientation, tilt, android_tool_type);
99 ui::MotionEventAndroid event( 101 ui::MotionEventAndroid event(
100 1.f / view_->GetDipScale(), env, nullptr /* event */, time_ms, 102 env, nullptr /* event */, 1.f / view_->GetDipScale(), 0.f, 0.f, 0.f,
101 android_action, 1 /* pointer_count */, 0 /* history_size */, 103 time_ms, android_action, 1 /* pointer_count */, 0 /* history_size */,
102 0 /* action_index */, android_action_button, android_button_state, 104 0 /* action_index */, android_action_button, android_button_state,
103 android_meta_state, 0 /* raw_offset_x_pixels */, 105 android_meta_state, 0 /* raw_offset_x_pixels */,
104 0 /* raw_offset_y_pixels */, &pointer, nullptr); 106 0 /* raw_offset_y_pixels */, &pointer, nullptr);
105 view_->OnMouseEvent(event); 107 view_->OnMouseEvent(event);
106 } 108 }
107 109
110 void EventForwarder::OnMouseWheelEvent(JNIEnv* env,
111 const JavaParamRef<jobject>& obj,
112 jlong time_ms,
113 jfloat x,
114 jfloat y,
115 jfloat ticks_x,
116 jfloat ticks_y,
117 jfloat pixels_per_tick) {
118 if (!ticks_x && !ticks_y)
119 return;
120
121 // Compute Event.Latency.OS.MOUSE_WHEEL histogram.
122 base::TimeTicks current_time = ui::EventTimeForNow();
123 base::TimeTicks event_time =
124 base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms);
125 base::TimeDelta delta = current_time - event_time;
126 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.MOUSE_WHEEL",
127 delta.InMicroseconds(), 1, 1000000, 50);
128 ui::MotionEventAndroid::Pointer pointer(
129 0, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, 0.0f, 0.0f, 0);
130 ui::MotionEventAndroid event(env, nullptr, 1.f / view_->GetDipScale(),
131 ticks_x, ticks_y, pixels_per_tick, time_ms,
132 0 /* action */, 1 /* pointer_count */,
133 0 /* history_size */, 0 /* action_index */, 0, 0,
134 0, 0 /* raw_offset_x_pixels */,
135 0 /* raw_offset_y_pixels */, &pointer, nullptr);
136
137 view_->OnMouseWheelEvent(event);
138 }
139
108 bool RegisterEventForwarder(JNIEnv* env) { 140 bool RegisterEventForwarder(JNIEnv* env) {
109 return RegisterNativesImpl(env); 141 return RegisterNativesImpl(env);
110 } 142 }
111 143
112 } // namespace ui 144 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/event_forwarder.h ('k') | ui/android/java/src/org/chromium/ui/base/EventForwarder.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698