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

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

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

Powered by Google App Engine
This is Rietveld 408576698