Index: ui/android/view_android.h |
diff --git a/ui/android/view_android.h b/ui/android/view_android.h |
index 9ceee0a5e437a49eec647c6931faad42838450bd..ce9424d4c4565db9483e9083389f928640ed1575 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; |
@@ -28,6 +29,8 @@ class UI_ANDROID_EXPORT ViewAndroid { |
ViewAndroid(const base::android::JavaRef<jobject>& delegate, |
WindowAndroid* root_window); |
+ static bool RegisterWindowAndroid(JNIEnv* env); |
+ |
// Used to construct a child view. |
ViewAndroid(); |
~ViewAndroid(); |
@@ -40,11 +43,6 @@ class UI_ANDROID_EXPORT ViewAndroid { |
// nodes and must not be called for children. |
void SetWindowAndroid(WindowAndroid* root_window); |
- // 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; |
- |
// Used to return and set the layer for this view. May be |null|. |
cc::Layer* GetLayer() const; |
void SetLayer(scoped_refptr<cc::Layer> layer); |
@@ -53,7 +51,38 @@ class UI_ANDROID_EXPORT ViewAndroid { |
void AddChild(ViewAndroid* child); |
void RemoveChild(ViewAndroid* child); |
+ // 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) |
+ : view_(jview), delegate_(jdelegate) { } |
+ |
+ ScopedAnchorView() : ScopedAnchorView(nullptr, nullptr) { } |
+ |
+ // Calls JNI removeView() on the delegate for cleanup. |
+ ~ScopedAnchorView(); |
+ |
+ base::android::ScopedJavaGlobalRef<jobject> ref() const { return view_; } |
+ jobject obj() const { return view_.obj(); } |
no sievers
2016/07/18 22:14:17
nit: Could this just have one method to return 'co
Jinsuk Kim
2016/07/19 07:08:40
Done. Also added |is_null()| to not to have to cal
|
+ |
+ private: |
+ base::android::ScopedJavaGlobalRef<jobject> view_; |
+ base::android::ScopedJavaGlobalRef<jobject> delegate_; |
+ }; |
+ |
+ ScopedAnchorView* AcquireAnchorView(); |
no sievers
2016/07/18 22:14:17
Can you make this a 'move only' type and return by
Jinsuk Kim
2016/07/19 07:08:40
Done. The way I changed it uses move assignment th
|
+ void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
+ const gfx::RectF& bounds); |
+ |
private: |
+ // 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; |
+ |
ViewAndroid* parent_; |
std::list<ViewAndroid*> children_; |
WindowAndroid* window_; |