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

Unified Diff: ui/android/view_android.cc

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: tests Created 3 years, 12 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_android.cc
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
index 96e56495886dd26d8807a5847a0d6f0e12894295..f93d0b6ff08e9dccfb0605de1be1f6a26ad8acd9 100644
--- a/ui/android/view_android.cc
+++ b/ui/android/view_android.cc
@@ -9,7 +9,6 @@
#include "base/android/jni_android.h"
#include "cc/layers/layer.h"
#include "jni/ViewAndroidDelegate_jni.h"
-#include "jni/ViewRoot_jni.h"
#include "ui/android/view_client.h"
#include "ui/android/window_android.h"
#include "ui/display/display.h"
@@ -84,11 +83,6 @@ ViewAndroid::~ViewAndroid() {
DCHECK_EQ(child->parent_, this);
child->parent_ = nullptr;
}
-
- JNIEnv* env = base::android::AttachCurrentThread();
- const ScopedJavaLocalRef<jobject> view_root = view_root_.get(env);
- if (!view_root.is_null())
- Java_ViewRoot_onDestroyNativeView(env, view_root);
}
void ViewAndroid::SetDelegate(const JavaRef<jobject>& delegate) {
@@ -110,8 +104,8 @@ void ViewAndroid::AddChild(ViewAndroid* child) {
child->RemoveFromParent();
child->parent_ = this;
if (physical_width_pix_ || physical_height_pix_) {
- child->OnPhysicalBackingSizeChanged(physical_width_pix_,
- physical_height_pix_);
+ child->OnPhysicalBackingSizeChangedInternal(physical_width_pix_,
+ physical_height_pix_);
}
}
@@ -165,13 +159,13 @@ WindowAndroid* ViewAndroid::GetWindowAndroid() const {
return parent_ ? parent_->GetWindowAndroid() : nullptr;
}
-ScopedJavaLocalRef<jobject> ViewAndroid::CreateViewRoot() {
- JNIEnv* env = base::android::AttachCurrentThread();
- return Java_ViewRoot_create(env, reinterpret_cast<intptr_t>(this));
+void ViewAndroid::SetWindowAndroid(WindowAndroid* window) {
+ DCHECK(parent_) << "The root of this view tree is not present.";
+ parent_->SetWindowAndroid(window);
}
-bool ViewAndroid::HasViewRoot() {
- return !view_root_.is_uninitialized();
+bool ViewAndroid::IsViewRoot() {
+ return GetViewRoot() == this;
}
const ScopedJavaLocalRef<jobject> ViewAndroid::GetViewAndroidDelegate()
@@ -193,21 +187,14 @@ void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) {
UpdateLayerBounds();
}
-ScopedJavaLocalRef<jobject> ViewAndroid::GetViewRoot() {
- JNIEnv* env = base::android::AttachCurrentThread();
- const ScopedJavaLocalRef<jobject> view_root = view_root_.get(env);
- if (!view_root.is_null())
- return view_root;
-
- DCHECK(!HasViewRootInTreeHierarchy());
- view_root_ = JavaObjectWeakGlobalRef(env, CreateViewRoot());
- return view_root_.get(env);
+ViewAndroid* ViewAndroid::GetViewRoot() {
+ return parent_ ? parent_->GetViewRoot() : nullptr;
}
bool ViewAndroid::HasViewRootInTreeHierarchy() {
boliu 2017/01/03 19:16:11 I think this linear time check is unnecessary now.
Jinsuk Kim 2017/01/04 10:45:02 Done.
ViewAndroid* view = parent_;
while (view) {
- if (view->HasViewRoot())
+ if (view->IsViewRoot())
return true;
view = view->parent_;
}
@@ -215,7 +202,7 @@ bool ViewAndroid::HasViewRootInTreeHierarchy() {
}
bool ViewAndroid::HasViewRootInSubtree() {
- if (HasViewRoot())
+ if (IsViewRoot())
return true;
for (auto& child : children_) {
if (child->HasViewRootInSubtree())
@@ -243,7 +230,7 @@ void ViewAndroid::UpdateLayerBounds() {
layer_->SetBounds(GetPhysicalBackingSize());
}
-void ViewAndroid::OnPhysicalBackingSizeChanged(int width, int height) {
+void ViewAndroid::OnPhysicalBackingSizeChangedInternal(int width, int height) {
if (width == physical_width_pix_ && height == physical_height_pix_)
return;
@@ -255,21 +242,6 @@ void ViewAndroid::OnPhysicalBackingSizeChanged(int width, int height) {
client_->OnPhysicalBackingSizeChanged(width, height);
for (auto& child : children_)
- child->OnPhysicalBackingSizeChanged(width, height);
+ child->OnPhysicalBackingSizeChangedInternal(width, height);
}
-
-// static
-void OnPhysicalBackingSizeChanged(JNIEnv* env,
- const JavaParamRef<jclass>& jcaller,
- jlong native_view,
- int width,
- int height) {
- ViewAndroid* view_android = reinterpret_cast<ViewAndroid*>(native_view);
- view_android->OnPhysicalBackingSizeChanged(width, height);
-}
-
-bool RegisterViewRoot(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698