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

Unified Diff: ui/android/view_android.cc

Issue 2103243002: Factor out ContentViewAndroidDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
« ui/android/view_android.h ('K') | « ui/android/view_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/view_android.cc
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc
index 3771c37282d3359e8febec8ebcbb99db1b53a260..8adbe2f5e9ccbaa9ce1f8bd3a81ecfd1ba224d9f 100644
--- a/ui/android/view_android.cc
+++ b/ui/android/view_android.cc
@@ -8,6 +8,9 @@
#include "base/android/jni_android.h"
#include "cc/layers/layer.h"
+#include "jni/ViewAndroid_jni.h"
+#include "ui/android/window_android.h"
+#include "ui/gfx/android/device_display_info.h"
namespace ui {
@@ -15,12 +18,22 @@ using base::android::AttachCurrentThread;
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
-ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate,
+ViewAndroid::ViewAndroid(const JavaRef<jobject>& context,
+ const JavaRef<jobject>& delegate,
WindowAndroid* root_window)
- : parent_(nullptr), window_(root_window), delegate_(delegate) {}
+ : parent_(nullptr)
+ , window_(root_window)
+ , java_ref_(Java_ViewAndroid_create(base::android::AttachCurrentThread(),
+ context.obj(),
+ delegate.obj()))
+ , delegate_(delegate) {}
ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {}
+bool ViewAndroid::RegisterWindowAndroid(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
ViewAndroid::~ViewAndroid() {
if (parent_)
parent_->RemoveChild(this);
@@ -55,6 +68,42 @@ void ViewAndroid::RemoveChild(ViewAndroid* child) {
child->parent_ = nullptr;
}
+ScopedJavaLocalRef<jobject>
+ViewAndroid::AcquireAnchorView() {
+ if (delegate_.is_null())
no sievers 2016/07/14 23:14:32 Doesn't it need to go to the parent's delegate if
Jinsuk Kim 2016/07/15 05:46:27 Makes sense. In fact other methods |SetAnchorRect|
+ return base::android::ScopedJavaLocalRef<jobject>();
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return ScopedJavaLocalRef<jobject>(
+ Java_ViewAndroid_acquireAnchorView(env,
+ java_ref_.obj()));
+}
+
+void ViewAndroid::SetAnchorRect(const jobject& anchor,
+ const gfx::RectF& bounds) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ gfx::DeviceDisplayInfo device_info;
+ float scale = device_info.GetDIPScale();
+ int left_margin = std::round(bounds.x() * scale);
+ float content_offset_y_pix = GetWindowAndroid()->content_offset().y();
no sievers 2016/07/14 23:14:32 nit: can you put a TODO? content_offset() should b
Jinsuk Kim 2016/07/15 05:46:27 Meant to do it in this CL but it involved changes
+ int top_margin = std::round(content_offset_y_pix + bounds.y() * scale);
+ Java_ViewAndroid_setAnchorViewPosition(env,
+ java_ref_.obj(),
+ anchor,
+ bounds.x(),
+ bounds.y(),
+ bounds.width(),
+ bounds.height(),
+ scale,
+ left_margin,
+ top_margin);
+}
+
+void ViewAndroid::RemoveAnchorView(const jobject& anchor) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_ViewAndroid_removeAnchorView(env, java_ref_.obj(), anchor);
+}
+
WindowAndroid* ViewAndroid::GetWindowAndroid() const {
if (window_)
return window_;
@@ -67,14 +116,6 @@ void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) {
DCHECK(parent_ == nullptr) << "Children shouldn't have a root window";
}
-const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate()
- const {
- if (!delegate_.is_null())
- return delegate_;
-
- return parent_ ? parent_->GetViewAndroidDelegate() : delegate_;
no sievers 2016/07/14 23:14:32 see above, I think you want to keep the recursion
Jinsuk Kim 2016/07/15 05:46:27 Done.
-}
-
cc::Layer* ViewAndroid::GetLayer() const {
return layer_.get();
}
« ui/android/view_android.h ('K') | « ui/android/view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698