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

Unified Diff: ui/android/view_root.cc

Issue 2645353004: ViewRoot class for event forwarding on Android (Closed)
Patch Set: fix tests 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 side-by-side diff with in-line comments
Download patch
Index: ui/android/view_root.cc
diff --git a/ui/android/view_root.cc b/ui/android/view_root.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8526944021c7dd36ef9d970c0b8166aad9adee39
--- /dev/null
+++ b/ui/android/view_root.cc
@@ -0,0 +1,115 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/android/view_root.h"
+
+#include "jni/ViewRoot_jni.h"
+
+namespace ui {
+
+using base::android::JavaParamRef;
+
+ViewRoot::ViewRoot(jlong window_android_ptr) {
+ WindowAndroid* window_android =
+ reinterpret_cast<WindowAndroid*>(window_android_ptr);
+ window_ = window_android;
+
+ // ViewRoot simply accepts all events and lets the hit testing
+ // start from its children.
+ SetBounds(gfx::Point(), Bounds::kMatchParent, Bounds::kMatchParent);
+}
+
+void ViewRoot::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
+ delete this;
+}
+
+ViewAndroid* ViewRoot::GetViewRoot() {
+ return this;
+}
+
+WindowAndroid* ViewRoot::GetWindowAndroid() const {
+ return window_;
+}
+
+void ViewRoot::MoveToFront(ViewAndroid* child) {
+ DCHECK(child);
+ auto it = std::find(children_.begin(), children_.end(), child);
+ DCHECK(it != children_.end());
+
+ if (it != children_.begin())
+ children_.splice(children_.begin(), children_, it);
+}
+
+jboolean ViewRoot::OnTouchEvent(JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ const JavaParamRef<jobject>& motion_event,
+ jlong time_ms,
+ jint android_action,
+ jint pointer_count,
+ jint history_size,
+ jint action_index,
+ jfloat pos_x_0,
+ jfloat pos_y_0,
+ jfloat pos_x_1,
+ jfloat pos_y_1,
+ jint pointer_id_0,
+ jint pointer_id_1,
+ jfloat touch_major_0,
+ jfloat touch_major_1,
+ jfloat touch_minor_0,
+ jfloat touch_minor_1,
+ jfloat orientation_0,
+ jfloat orientation_1,
+ jfloat tilt_0,
+ jfloat tilt_1,
+ jfloat raw_pos_x,
+ jfloat raw_pos_y,
+ jint android_tool_type_0,
+ jint android_tool_type_1,
+ jint android_button_state,
+ jint android_meta_state,
+ jboolean is_touch_handle_event) {
+ MotionEventData event(GetDipScale(),
+ motion_event.obj(),
+ time_ms,
+ android_action,
+ pointer_count,
+ history_size,
+ action_index,
+ pos_x_0,
+ pos_y_0,
+ pos_x_1,
+ pos_y_1,
+ pointer_id_0,
+ pointer_id_1,
+ touch_major_0,
+ touch_major_1,
+ touch_minor_0,
+ touch_minor_1,
+ orientation_0,
+ orientation_1,
+ tilt_0,
+ tilt_1,
+ raw_pos_x,
+ raw_pos_y,
+ android_tool_type_0,
+ android_tool_type_1,
+ android_button_state,
+ android_meta_state,
+ is_touch_handle_event);
+ return OnTouchEventInternal(event);
+}
+
+// static
+jlong Init(JNIEnv* env,
+ const JavaParamRef<jobject>& obj,
+ jlong window_android_ptr) {
+ return reinterpret_cast<intptr_t>(new ViewRoot(window_android_ptr));
+}
+
+bool RegisterViewRoot(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698