Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_ANDROID_VIEW_ANDROID_H_ | 5 #ifndef UI_ANDROID_VIEW_ANDROID_H_ |
| 6 #define UI_ANDROID_VIEW_ANDROID_H_ | 6 #define UI_ANDROID_VIEW_ANDROID_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ui/android/ui_android_export.h" | 12 #include "ui/android/ui_android_export.h" |
| 13 #include "ui/gfx/geometry/rect_f.h" | |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 class Layer; | 16 class Layer; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace ui { | 19 namespace ui { |
| 19 | 20 |
| 20 class WindowAndroid; | 21 class WindowAndroid; |
| 21 | 22 |
| 22 // A simple container for a UI layer. | 23 // A simple container for a UI layer. |
| 23 // At the root of the hierarchy is a WindowAndroid, when attached. | 24 // At the root of the hierarchy is a WindowAndroid, when attached. |
| 24 class UI_ANDROID_EXPORT ViewAndroid { | 25 class UI_ANDROID_EXPORT ViewAndroid { |
| 25 public: | 26 public: |
| 26 // A ViewAndroid may have its own delegate or otherwise will | 27 // A ViewAndroid may have its own delegate or otherwise will |
| 27 // use the next available parent's delegate. | 28 // use the next available parent's delegate. |
| 28 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | 29 ViewAndroid(const base::android::JavaRef<jobject>& delegate); |
| 30 | |
| 29 ViewAndroid(); | 31 ViewAndroid(); |
| 30 virtual ~ViewAndroid(); | 32 virtual ~ViewAndroid(); |
| 31 | 33 |
| 34 // This method is intentionally not called anywhere, since there are | |
| 35 // no native methods that are called from Java. TODO(crbug.com/603936). | |
| 36 static bool RegisterViewAndroid(JNIEnv* env); | |
| 37 | |
| 32 // Returns the window at the root of this hierarchy, or |null| | 38 // Returns the window at the root of this hierarchy, or |null| |
| 33 // if disconnected. | 39 // if disconnected. |
| 34 virtual WindowAndroid* GetWindowAndroid() const; | 40 virtual WindowAndroid* GetWindowAndroid() const; |
| 35 | 41 |
| 36 // Returns the Java delegate for this view. This is used to delegate work | 42 // Set the root |WindowAndroid|. This is only valid for root |
| 37 // up to the embedding view (or the embedder that can deal with the | 43 // nodes and must not be called for children. |
| 38 // implementation details). | 44 void SetWindowAndroid(WindowAndroid* root_window); |
| 39 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const; | |
| 40 | 45 |
| 41 // Used to return and set the layer for this view. May be |null|. | 46 // Used to return and set the layer for this view. May be |null|. |
| 42 cc::Layer* GetLayer() const; | 47 cc::Layer* GetLayer() const; |
| 43 void SetLayer(scoped_refptr<cc::Layer> layer); | 48 void SetLayer(scoped_refptr<cc::Layer> layer); |
| 44 | 49 |
| 45 // Adds this view as a child of another view. | 50 // Adds this view as a child of another view. |
| 46 void AddChild(ViewAndroid* child); | 51 void AddChild(ViewAndroid* child); |
| 47 | 52 |
| 48 // Detaches this view from its parent. | 53 // Detaches this view from its parent. |
| 49 void RemoveFromParent(); | 54 void RemoveFromParent(); |
| 50 | 55 |
| 51 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 56 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 52 const base::android::JavaRef<jobject>& jimage); | 57 const base::android::JavaRef<jobject>& jimage); |
| 53 | 58 |
| 59 // Stores an anchored view to delete itself at the end of its lifetime | |
| 60 // automatically. This helps manage the lifecyle without the dependency | |
| 61 // on |ViewAndroid|. | |
| 62 class ScopedAnchorView { | |
| 63 public: | |
| 64 ScopedAnchorView(const base::android::JavaRef<jobject>& jview, | |
| 65 const base::android::JavaRef<jobject>& jdelegate); | |
| 66 | |
| 67 ScopedAnchorView(); | |
| 68 ScopedAnchorView(ScopedAnchorView&& other); | |
| 69 ScopedAnchorView& operator=(ScopedAnchorView&& other); | |
| 70 | |
| 71 // Calls JNI removeView() on the delegate for cleanup. | |
| 72 ~ScopedAnchorView(); | |
| 73 | |
| 74 void Reset(); | |
| 75 | |
| 76 bool is_null() const { return view_.is_null(); } | |
| 77 const base::android::JavaRef<jobject>& view() const { return view_; } | |
| 78 | |
| 79 private: | |
| 80 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.
| |
| 81 base::android::ScopedJavaGlobalRef<jobject> delegate_; | |
| 82 }; | |
| 83 | |
| 84 ScopedAnchorView AcquireAnchorView(); | |
| 85 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | |
| 86 const gfx::RectF& bounds); | |
| 87 | |
| 54 protected: | 88 protected: |
| 55 ViewAndroid* parent_; | 89 ViewAndroid* parent_; |
| 56 | 90 |
| 57 private: | 91 private: |
| 58 void RemoveChild(ViewAndroid* child); | 92 void RemoveChild(ViewAndroid* child); |
| 59 | 93 |
| 94 // Returns the Java delegate for this view. This is used to delegate work | |
| 95 // up to the embedding view (or the embedder that can deal with the | |
| 96 // implementation details). | |
| 97 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const; | |
| 98 | |
| 60 std::list<ViewAndroid*> children_; | 99 std::list<ViewAndroid*> children_; |
| 61 scoped_refptr<cc::Layer> layer_; | 100 scoped_refptr<cc::Layer> layer_; |
| 62 base::android::ScopedJavaGlobalRef<jobject> delegate_; | 101 base::android::ScopedJavaGlobalRef<jobject> delegate_; |
| 63 | 102 |
| 64 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 65 }; | 104 }; |
| 66 | 105 |
| 67 } // namespace ui | 106 } // namespace ui |
| 68 | 107 |
| 69 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 108 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |