| OLD | NEW |
| (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 <jni.h> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/android/jni_weak_ref.h" |
| 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics.h" |
| 16 #include "base/observer_list.h" |
| 17 #include "base/time/time.h" |
| 18 #include "jni/ViewRoot_jni.h" |
| 19 #include "ui/android/ui_android_export.h" |
| 20 #include "ui/android/view_android.h" |
| 21 #include "ui/display/display.h" |
| 22 #include "ui/display/screen.h" |
| 23 #include "ui/gfx/geometry/vector2d_f.h" |
| 24 |
| 25 namespace ui { |
| 26 |
| 27 using base::android::JavaParamRef; |
| 28 using base::android::JavaRef; |
| 29 using base::android::ScopedJavaLocalRef; |
| 30 |
| 31 namespace { |
| 32 |
| 33 void RecordToolTypeForActionDown(MotionEventAndroid& event) { |
| 34 MotionEventAndroid::Action action = event.GetAction(); |
| 35 if (action == MotionEventAndroid::ACTION_DOWN || |
| 36 action == MotionEventAndroid::ACTION_POINTER_DOWN || |
| 37 action == MotionEventAndroid::ACTION_BUTTON_PRESS) { |
| 38 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType", |
| 39 event.GetToolType(0), |
| 40 MotionEventAndroid::TOOL_TYPE_LAST + 1); |
| 41 } |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 ViewRoot::ViewRoot(jlong window_android_ptr) { |
| 47 WindowAndroid* window_android = |
| 48 reinterpret_cast<WindowAndroid*>(window_android_ptr); |
| 49 window_ = window_android; |
| 50 } |
| 51 |
| 52 void ViewRoot::Destroy(JNIEnv* env, |
| 53 const base::android::JavaParamRef<jobject>& obj) { |
| 54 delete this; |
| 55 } |
| 56 |
| 57 ViewAndroid* ViewRoot::GetViewRoot() { |
| 58 return this; |
| 59 } |
| 60 |
| 61 WindowAndroid* ViewRoot::GetWindowAndroid() const { |
| 62 return window_; |
| 63 } |
| 64 |
| 65 void ViewRoot::MoveToFront(ViewAndroid* child) { |
| 66 DCHECK(child); |
| 67 auto it = std::find(children_.begin(), children_.end(), child); |
| 68 DCHECK(it != children_.end()); |
| 69 |
| 70 if (it != children_.begin()) { |
| 71 children_.erase(it); |
| 72 children_.push_front(*it); |
| 73 } |
| 74 } |
| 75 |
| 76 jboolean ViewRoot::OnTouchEvent( |
| 77 JNIEnv* env, |
| 78 const JavaParamRef<jobject>& obj, |
| 79 const JavaParamRef<jobject>& motion_event, |
| 80 jlong time_ms, |
| 81 jint android_action, |
| 82 jint pointer_count, |
| 83 jint history_size, |
| 84 jint action_index, |
| 85 jfloat pos_x_0, |
| 86 jfloat pos_y_0, |
| 87 jfloat pos_x_1, |
| 88 jfloat pos_y_1, |
| 89 jint pointer_id_0, |
| 90 jint pointer_id_1, |
| 91 jfloat touch_major_0, |
| 92 jfloat touch_major_1, |
| 93 jfloat touch_minor_0, |
| 94 jfloat touch_minor_1, |
| 95 jfloat orientation_0, |
| 96 jfloat orientation_1, |
| 97 jfloat tilt_0, |
| 98 jfloat tilt_1, |
| 99 jfloat raw_pos_x, |
| 100 jfloat raw_pos_y, |
| 101 jint android_tool_type_0, |
| 102 jint android_tool_type_1, |
| 103 jint android_button_state, |
| 104 jint android_meta_state, |
| 105 jboolean is_touch_handle_event) { |
| 106 |
| 107 MotionEventAndroid::Pointer pointer0(pointer_id_0, |
| 108 pos_x_0, |
| 109 pos_y_0, |
| 110 touch_major_0, |
| 111 touch_minor_0, |
| 112 orientation_0, |
| 113 tilt_0, |
| 114 android_tool_type_0); |
| 115 MotionEventAndroid::Pointer pointer1(pointer_id_1, |
| 116 pos_x_1, |
| 117 pos_y_1, |
| 118 touch_major_1, |
| 119 touch_minor_1, |
| 120 orientation_1, |
| 121 tilt_1, |
| 122 android_tool_type_1); |
| 123 float dip_scale = display::Screen::GetScreen() |
| 124 ->GetDisplayNearestWindow(this) |
| 125 .device_scale_factor(); |
| 126 MotionEventAndroid event(1.f / dip_scale, |
| 127 env, |
| 128 motion_event, |
| 129 time_ms, |
| 130 android_action, |
| 131 pointer_count, |
| 132 history_size, |
| 133 action_index, |
| 134 android_button_state, |
| 135 android_meta_state, |
| 136 raw_pos_x - pos_x_0, |
| 137 raw_pos_y - pos_y_0, |
| 138 &pointer0, |
| 139 &pointer1); |
| 140 |
| 141 RecordToolTypeForActionDown(event); |
| 142 |
| 143 return OnTouchEventInternal(event, is_touch_handle_event); |
| 144 } |
| 145 |
| 146 // static |
| 147 jlong Init(JNIEnv* env, |
| 148 const JavaParamRef<jobject>& obj, |
| 149 jlong window_android_ptr) { |
| 150 return reinterpret_cast<intptr_t>(new ViewRoot(window_android_ptr)); |
| 151 } |
| 152 |
| 153 bool RegisterViewRoot(JNIEnv* env) { |
| 154 return RegisterNativesImpl(env); |
| 155 } |
| 156 |
| 157 } // namespace ui |
| OLD | NEW |