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

Unified Diff: ui/android/view_android.h

Issue 2103243002: Factor out ContentViewAndroidDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed isValidView() 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
Index: ui/android/view_android.h
diff --git a/ui/android/view_android.h b/ui/android/view_android.h
index 6e7140da3e111d470da0ff73c77a7fa007108d6b..058ebb9c988082ade17163f907a0c56e6de0c4c7 100644
--- a/ui/android/view_android.h
+++ b/ui/android/view_android.h
@@ -10,6 +10,7 @@
#include "base/android/scoped_java_ref.h"
#include "base/memory/ref_counted.h"
#include "ui/android/ui_android_export.h"
+#include "ui/gfx/geometry/rect_f.h"
namespace cc {
class Layer;
@@ -26,17 +27,21 @@ class UI_ANDROID_EXPORT ViewAndroid {
// A ViewAndroid may have its own delegate or otherwise will
// use the next available parent's delegate.
ViewAndroid(const base::android::JavaRef<jobject>& delegate);
+
ViewAndroid();
virtual ~ViewAndroid();
+ // This method is intentionally not called anywhere, since there are
+ // no native methods that are called from Java. TODO(crbug.com/603936).
+ static bool RegisterViewAndroid(JNIEnv* env);
+
// Returns the window at the root of this hierarchy, or |null|
// if disconnected.
virtual WindowAndroid* GetWindowAndroid() const;
- // Returns the Java delegate for this view. This is used to delegate work
- // up to the embedding view (or the embedder that can deal with the
- // implementation details).
- const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
+ // Set the root |WindowAndroid|. This is only valid for root
+ // nodes and must not be called for children.
+ void SetWindowAndroid(WindowAndroid* root_window);
// Used to return and set the layer for this view. May be |null|.
cc::Layer* GetLayer() const;
@@ -51,12 +56,46 @@ class UI_ANDROID_EXPORT ViewAndroid {
void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
const base::android::JavaRef<jobject>& jimage);
+ // Stores an anchored view to delete itself at the end of its lifetime
+ // automatically. This helps manage the lifecyle without the dependency
+ // on |ViewAndroid|.
+ class ScopedAnchorView {
+ public:
+ ScopedAnchorView(const base::android::JavaRef<jobject>& jview,
+ const base::android::JavaRef<jobject>& jdelegate);
+
+ ScopedAnchorView();
+ ScopedAnchorView(ScopedAnchorView&& other);
+ ScopedAnchorView& operator=(ScopedAnchorView&& other);
+
+ // Calls JNI removeView() on the delegate for cleanup.
+ ~ScopedAnchorView();
+
+ void Reset();
+
+ bool is_null() const { return view_.is_null(); }
+ const base::android::JavaRef<jobject>& view() const { return view_; }
+
+ private:
+ base::android::ScopedJavaGlobalRef<jobject> view_;
boliu 2016/07/25 22:15:27 maybe will need a weak reference version of this,
no sievers 2016/07/25 22:24:41 Hmm why would the child view be a GC root? And ho
boliu 2016/07/25 22:29:24 Any strong reference from native code is a gc root
Jinsuk Kim 2016/07/27 10:02:43 Done.
+ base::android::ScopedJavaGlobalRef<jobject> delegate_;
+ };
+
+ ScopedAnchorView AcquireAnchorView();
+ void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
+ const gfx::RectF& bounds);
+
protected:
ViewAndroid* parent_;
private:
void RemoveChild(ViewAndroid* child);
+ // Returns the Java delegate for this view. This is used to delegate work
+ // up to the embedding view (or the embedder that can deal with the
+ // implementation details).
+ const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
+
std::list<ViewAndroid*> children_;
scoped_refptr<cc::Layer> layer_;
base::android::ScopedJavaGlobalRef<jobject> delegate_;

Powered by Google App Engine
This is Rietveld 408576698