| 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..870e379f7af6ee3866de2021cd088f5b5325974f
|
| --- /dev/null
|
| +++ b/ui/android/view_root.cc
|
| @@ -0,0 +1,143 @@
|
| +// 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 "base/metrics/histogram_macros.h"
|
| +#include "jni/ViewRoot_jni.h"
|
| +#include "ui/display/display.h"
|
| +#include "ui/display/screen.h"
|
| +
|
| +namespace ui {
|
| +
|
| +using base::android::JavaParamRef;
|
| +using base::android::JavaRef;
|
| +
|
| +namespace {
|
| +
|
| +void RecordToolTypeForActionDown(MotionEventAndroid& event) {
|
| + MotionEventAndroid::Action action = event.GetAction();
|
| + if (action == MotionEventAndroid::ACTION_DOWN ||
|
| + action == MotionEventAndroid::ACTION_POINTER_DOWN ||
|
| + action == MotionEventAndroid::ACTION_BUTTON_PRESS) {
|
| + UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
|
| + event.GetToolType(0),
|
| + MotionEventAndroid::TOOL_TYPE_LAST + 1);
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ViewRoot::ViewRoot(jlong window_android_ptr) {
|
| + WindowAndroid* window_android =
|
| + reinterpret_cast<WindowAndroid*>(window_android_ptr);
|
| + window_ = window_android;
|
| +
|
| + // ViewRoot simply accepts all events and passes them down to 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_.erase(it);
|
| + children_.push_front(*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) {
|
| + MotionEventAndroid::Pointer pointer0(pointer_id_0,
|
| + pos_x_0,
|
| + pos_y_0,
|
| + touch_major_0,
|
| + touch_minor_0,
|
| + orientation_0,
|
| + tilt_0,
|
| + android_tool_type_0);
|
| + MotionEventAndroid::Pointer pointer1(pointer_id_1,
|
| + pos_x_1,
|
| + pos_y_1,
|
| + touch_major_1,
|
| + touch_minor_1,
|
| + orientation_1,
|
| + tilt_1,
|
| + android_tool_type_1);
|
| + float dip_scale = display::Screen::GetScreen()
|
| + ->GetDisplayNearestWindow(this)
|
| + .device_scale_factor();
|
| + MotionEventAndroid event(1.f / dip_scale,
|
| + env,
|
| + motion_event,
|
| + time_ms,
|
| + android_action,
|
| + pointer_count,
|
| + history_size,
|
| + action_index,
|
| + android_button_state,
|
| + android_meta_state,
|
| + raw_pos_x - pos_x_0,
|
| + raw_pos_y - pos_y_0,
|
| + &pointer0,
|
| + &pointer1);
|
| +
|
| + RecordToolTypeForActionDown(event);
|
| +
|
| + return OnTouchEventInternal(event, is_touch_handle_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
|
|
|