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

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

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: unittest Created 3 years, 11 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 | « ui/android/view_root.h ('k') | ui/android/window_android.h » ('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 "ui/android/view_root.h"
6
7 #include "base/metrics/histogram_macros.h"
8 #include "jni/ViewRoot_jni.h"
9 #include "ui/display/display.h"
10 #include "ui/display/screen.h"
11
12 namespace ui {
13
14 using base::android::JavaParamRef;
15 using base::android::JavaRef;
16
17 namespace {
18
19 void RecordToolTypeForActionDown(MotionEventAndroid& event) {
20 MotionEventAndroid::Action action = event.GetAction();
21 if (action == MotionEventAndroid::ACTION_DOWN ||
22 action == MotionEventAndroid::ACTION_POINTER_DOWN ||
23 action == MotionEventAndroid::ACTION_BUTTON_PRESS) {
24 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
25 event.GetToolType(0),
26 MotionEventAndroid::TOOL_TYPE_LAST + 1);
27 }
28 }
29
30 } // namespace
31
32 ViewRoot::ViewRoot(jlong window_android_ptr) {
33 WindowAndroid* window_android =
34 reinterpret_cast<WindowAndroid*>(window_android_ptr);
35 window_ = window_android;
36
37 // ViewRoot simply accepts all events and passes them down to children.
38 SetBounds(gfx::Point(), Bounds::kMatchParent, Bounds::kMatchParent);
39 }
40
41 void ViewRoot::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
42 delete this;
43 }
44
45 ViewAndroid* ViewRoot::GetViewRoot() {
46 return this;
47 }
48
49 WindowAndroid* ViewRoot::GetWindowAndroid() const {
50 return window_;
51 }
52
53 void ViewRoot::MoveToFront(ViewAndroid* child) {
54 DCHECK(child);
55 auto it = std::find(children_.begin(), children_.end(), child);
56 DCHECK(it != children_.end());
57
58 if (it != children_.begin()) {
59 children_.erase(it);
60 children_.push_front(*it);
61 }
62 }
63
64 jboolean ViewRoot::OnTouchEvent(JNIEnv* env,
65 const JavaParamRef<jobject>& obj,
66 const JavaParamRef<jobject>& motion_event,
67 jlong time_ms,
68 jint android_action,
69 jint pointer_count,
70 jint history_size,
71 jint action_index,
72 jfloat pos_x_0,
73 jfloat pos_y_0,
74 jfloat pos_x_1,
75 jfloat pos_y_1,
76 jint pointer_id_0,
77 jint pointer_id_1,
78 jfloat touch_major_0,
79 jfloat touch_major_1,
80 jfloat touch_minor_0,
81 jfloat touch_minor_1,
82 jfloat orientation_0,
83 jfloat orientation_1,
84 jfloat tilt_0,
85 jfloat tilt_1,
86 jfloat raw_pos_x,
87 jfloat raw_pos_y,
88 jint android_tool_type_0,
89 jint android_tool_type_1,
90 jint android_button_state,
91 jint android_meta_state,
92 jboolean is_touch_handle_event) {
93 MotionEventAndroid::Pointer pointer0(pointer_id_0,
94 pos_x_0,
95 pos_y_0,
96 touch_major_0,
97 touch_minor_0,
98 orientation_0,
99 tilt_0,
100 android_tool_type_0);
101 MotionEventAndroid::Pointer pointer1(pointer_id_1,
102 pos_x_1,
103 pos_y_1,
104 touch_major_1,
105 touch_minor_1,
106 orientation_1,
107 tilt_1,
108 android_tool_type_1);
109 float dip_scale = display::Screen::GetScreen()
110 ->GetDisplayNearestWindow(this)
111 .device_scale_factor();
112 MotionEventAndroid event(1.f / dip_scale,
113 env,
114 motion_event,
115 time_ms,
116 android_action,
117 pointer_count,
118 history_size,
119 action_index,
120 android_button_state,
121 android_meta_state,
122 raw_pos_x - pos_x_0,
123 raw_pos_y - pos_y_0,
124 &pointer0,
125 &pointer1);
126
127 RecordToolTypeForActionDown(event);
128
129 return OnTouchEventInternal(event, is_touch_handle_event);
130 }
131
132 // static
133 jlong Init(JNIEnv* env,
134 const JavaParamRef<jobject>& obj,
135 jlong window_android_ptr) {
136 return reinterpret_cast<intptr_t>(new ViewRoot(window_android_ptr));
137 }
138
139 bool RegisterViewRoot(JNIEnv* env) {
140 return RegisterNativesImpl(env);
141 }
142
143 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/view_root.h ('k') | ui/android/window_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698