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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: comment 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
(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 "ui/android/event_handler.h"
6
7 #include "jni/EventHandler_jni.h"
8 #include "ui/android/view_android.h"
9 #include "ui/android/view_client.h"
10 #include "ui/events/android/motion_event_android.h"
11
12 namespace ui {
13
14 using base::android::JavaParamRef;
15 using base::android::ScopedJavaLocalRef;
16
17 EventHandler::EventHandler(ViewAndroid* view) : view_(view) {}
18
19 EventHandler::~EventHandler() {
20 if (!java_obj_.is_null()) {
21 Java_EventHandler_destroy(base::android::AttachCurrentThread(), java_obj_);
22 java_obj_.Reset();
23 }
24 }
25
26 ScopedJavaLocalRef<jobject> EventHandler::GetJavaObject() {
27 if (java_obj_.is_null()) {
28 java_obj_.Reset(
29 Java_EventHandler_create(base::android::AttachCurrentThread(),
30 reinterpret_cast<intptr_t>(this)));
31 }
32 return ScopedJavaLocalRef<jobject>(java_obj_);
33 }
34
35 jboolean EventHandler::OnTouchEvent(JNIEnv* env,
36 const JavaParamRef<jobject>& obj,
37 const JavaParamRef<jobject>& motion_event,
38 jlong time_ms,
39 jint android_action,
40 jint pointer_count,
41 jint history_size,
42 jint action_index,
43 jfloat pos_x_0,
44 jfloat pos_y_0,
45 jfloat pos_x_1,
46 jfloat pos_y_1,
47 jint pointer_id_0,
48 jint pointer_id_1,
49 jfloat touch_major_0,
50 jfloat touch_major_1,
51 jfloat touch_minor_0,
52 jfloat touch_minor_1,
53 jfloat orientation_0,
54 jfloat orientation_1,
55 jfloat tilt_0,
56 jfloat tilt_1,
57 jfloat raw_pos_x,
58 jfloat raw_pos_y,
59 jint android_tool_type_0,
60 jint android_tool_type_1,
61 jint android_button_state,
62 jint android_meta_state,
63 jboolean is_touch_handle_event) {
64 ui::MotionEventAndroid::Pointer pointer0(
65 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0,
66 orientation_0, tilt_0, android_tool_type_0);
67 ui::MotionEventAndroid::Pointer pointer1(
68 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1,
69 orientation_1, tilt_1, android_tool_type_1);
70 ui::MotionEventAndroid event(
71 1.f / view_->GetDipScale(), env, motion_event.obj(), time_ms,
72 android_action, pointer_count, history_size, action_index,
73 0 /* action_button */, android_button_state, android_meta_state,
74 raw_pos_x - pos_x_0, raw_pos_y - pos_y_0, &pointer0, &pointer1);
75 return view_->OnTouchEvent(event, is_touch_handle_event);
76 }
77
78 void EventHandler::OnMouseEvent(JNIEnv* env,
79 const JavaParamRef<jobject>& obj,
80 jlong time_ms,
81 jint android_action,
82 jfloat x,
83 jfloat y,
84 jint pointer_id,
85 jfloat orientation,
86 jfloat pressure,
87 jfloat tilt,
88 jint android_action_button,
89 jint android_button_state,
90 jint android_meta_state,
91 jint android_tool_type) {
92 // Construct a motion_event object minimally, only to convert the raw
93 // parameters to ui::MotionEvent values. Since we used only the cached values
94 // at index=0, it is okay to even pass a null event to the constructor.
95 ui::MotionEventAndroid::Pointer pointer(
96 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
97 orientation, tilt, android_tool_type);
98 ui::MotionEventAndroid event(
99 1.f / view_->GetDipScale(), env, nullptr /* event */, time_ms,
100 android_action, 1 /* pointer_count */, 0 /* history_size */,
101 0 /* action_index */, android_action_button, android_button_state,
102 android_meta_state, 0 /* raw_offset_x_pixels */,
103 0 /* raw_offset_y_pixels */, &pointer, nullptr);
104 view_->OnMouseEvent(event);
105 }
106
107 bool RegisterEventHandler(JNIEnv* env) {
108 return RegisterNativesImpl(env);
109 }
110
111 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698