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/jni_weak_ref.h" | 10 #include "base/android/jni_weak_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 #include "ui/gfx/geometry/rect_f.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 class Layer; | 16 class Layer; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 class ViewClient; | 21 class ViewClient; |
| 22 class WindowAndroid; | 22 class WindowAndroid; |
| 23 | 23 |
| 24 // A simple container for a UI layer. | 24 // A simple container for a UI layer. |
| 25 // At the root of the hierarchy is a WindowAndroid, when attached. | 25 // At the root of the hierarchy is a ViewRoot, a subclass of ViewAndroid. |
| 26 class UI_ANDROID_EXPORT ViewAndroid { | 26 class UI_ANDROID_EXPORT ViewAndroid { |
| 27 public: | 27 public: |
| 28 // Stores an anchored view to delete itself at the end of its lifetime | 28 // Stores an anchored view to delete itself at the end of its lifetime |
| 29 // automatically. This helps manage the lifecyle without the dependency | 29 // automatically. This helps manage the lifecyle without the dependency |
| 30 // on |ViewAndroid|. | 30 // on |ViewAndroid|. |
| 31 class ScopedAnchorView { | 31 class ScopedAnchorView { |
| 32 public: | 32 public: |
| 33 ScopedAnchorView(JNIEnv* env, | 33 ScopedAnchorView(JNIEnv* env, |
| 34 const base::android::JavaRef<jobject>& jview, | 34 const base::android::JavaRef<jobject>& jview, |
| 35 const base::android::JavaRef<jobject>& jdelegate); | 35 const base::android::JavaRef<jobject>& jdelegate); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 57 | 57 |
| 58 explicit ViewAndroid(ViewClient* client); | 58 explicit ViewAndroid(ViewClient* client); |
| 59 | 59 |
| 60 ViewAndroid(); | 60 ViewAndroid(); |
| 61 virtual ~ViewAndroid(); | 61 virtual ~ViewAndroid(); |
| 62 | 62 |
| 63 // Returns the window at the root of this hierarchy, or |null| | 63 // Returns the window at the root of this hierarchy, or |null| |
| 64 // if disconnected. | 64 // if disconnected. |
| 65 virtual WindowAndroid* GetWindowAndroid() const; | 65 virtual WindowAndroid* GetWindowAndroid() const; |
| 66 | 66 |
| 67 // Returns |ViewRoot| associated with the current ViewAndroid. | 67 // Set the root |WindowAndroid|. This is simply passed up to the root |
| 68 // Create one if not present. | 68 // of the tree i.e. |ViewRoot| where the reference is held. |
| 69 base::android::ScopedJavaLocalRef<jobject> GetViewRoot(); | 69 virtual void SetWindowAndroid(WindowAndroid* window); |
|
boliu
2017/01/03 19:16:11
This should not be needed.
First this seems to be
Jinsuk Kim
2017/01/04 10:45:02
Done. Is this suggestion about the immutable pairi
boliu
2017/01/04 17:45:10
Yeah. Also to keep things simple and avoid unneces
Jinsuk Kim
2017/01/05 11:03:12
Acknowledged.
| |
| 70 | 70 |
| 71 // Used to return and set the layer for this view. May be |null|. | 71 // Used to return and set the layer for this view. May be |null|. |
| 72 cc::Layer* GetLayer() const; | 72 cc::Layer* GetLayer() const; |
| 73 void SetLayer(scoped_refptr<cc::Layer> layer); | 73 void SetLayer(scoped_refptr<cc::Layer> layer); |
| 74 | 74 |
| 75 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 75 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
| 76 | 76 |
| 77 // Adds this view as a child of another view. | 77 // Adds this view as a child of another view. |
| 78 void AddChild(ViewAndroid* child); | 78 void AddChild(ViewAndroid* child); |
| 79 | 79 |
| 80 // Detaches this view from its parent. | 80 // Detaches this view from its parent. |
| 81 void RemoveFromParent(); | 81 void RemoveFromParent(); |
| 82 | 82 |
| 83 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 83 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 84 const base::android::JavaRef<jobject>& jimage); | 84 const base::android::JavaRef<jobject>& jimage); |
| 85 | 85 |
| 86 ScopedAnchorView AcquireAnchorView(); | 86 ScopedAnchorView AcquireAnchorView(); |
| 87 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 87 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
| 88 const gfx::RectF& bounds); | 88 const gfx::RectF& bounds); |
| 89 | 89 |
| 90 gfx::Size GetPhysicalBackingSize(); | 90 gfx::Size GetPhysicalBackingSize(); |
| 91 void UpdateLayerBounds(); | 91 void UpdateLayerBounds(); |
| 92 | 92 |
| 93 // Internal implementation of ViewClient forwarding calls to the interface. | 93 // Internal implementation of ViewClient forwarding calls to the interface. |
| 94 void OnPhysicalBackingSizeChanged(int width, int height); | 94 void OnPhysicalBackingSizeChangedInternal(int width, int height); |
|
boliu
2017/01/03 19:16:11
the rename is to avoid name collision with ViewRoo
Jinsuk Kim
2017/01/04 10:45:02
Done.
| |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 // Returns the root of this hierarchy. | |
|
boliu
2017/01/03 19:16:11
not quite, returns the ViewRoot of the hierarchy,
Jinsuk Kim
2017/01/04 10:45:02
Done.
| |
| 98 virtual ViewAndroid* GetViewRoot(); | |
| 99 | |
| 97 ViewAndroid* parent_; | 100 ViewAndroid* parent_; |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 void RemoveChild(ViewAndroid* child); | 103 void RemoveChild(ViewAndroid* child); |
| 101 | 104 |
| 102 // Checks if any ViewAndroid instance in the tree hierarchy (including | 105 // Checks if any ViewAndroid instance in the tree hierarchy (including |
| 103 // all the parents and the children) has |ViewRoot| already. | 106 // all the parents and the children) has |ViewRoot| already. |
| 104 bool HasViewRootInTreeHierarchy(); | 107 bool HasViewRootInTreeHierarchy(); |
| 105 | 108 |
| 106 // Checks if any children (plus this ViewAndroid itself) has |ViewRoot|. | 109 // Checks if any children (plus this ViewAndroid itself) has |ViewRoot|. |
| 107 bool HasViewRootInSubtree(); | 110 bool HasViewRootInSubtree(); |
| 108 | 111 |
| 109 // Returns the Java delegate for this view. This is used to delegate work | 112 // Returns the Java delegate for this view. This is used to delegate work |
| 110 // up to the embedding view (or the embedder that can deal with the | 113 // up to the embedding view (or the embedder that can deal with the |
| 111 // implementation details). | 114 // implementation details). |
| 112 const base::android::ScopedJavaLocalRef<jobject> | 115 const base::android::ScopedJavaLocalRef<jobject> |
| 113 GetViewAndroidDelegate() const; | 116 GetViewAndroidDelegate() const; |
| 114 | 117 |
| 115 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child | 118 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child |
| 116 // should have |ViewRoot| for this ViewAndroid to have one. | 119 // should have |ViewRoot| for this ViewAndroid to have one. |
| 117 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot(); | 120 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot(); |
| 118 | 121 |
| 119 bool HasViewRoot(); | 122 // Checks if this is the root of the view tree. Used to avoid ending up |
| 123 // with multiple roots when modifying a tree. | |
| 124 bool IsViewRoot(); | |
| 120 | 125 |
| 121 std::list<ViewAndroid*> children_; | 126 std::list<ViewAndroid*> children_; |
| 127 | |
| 122 scoped_refptr<cc::Layer> layer_; | 128 scoped_refptr<cc::Layer> layer_; |
| 123 JavaObjectWeakGlobalRef delegate_; | 129 JavaObjectWeakGlobalRef delegate_; |
| 124 JavaObjectWeakGlobalRef view_root_; | |
| 125 ViewClient* const client_; | 130 ViewClient* const client_; |
| 126 | 131 |
| 127 int physical_width_pix_; | 132 int physical_width_pix_; |
| 128 int physical_height_pix_; | 133 int physical_height_pix_; |
| 129 | 134 |
| 130 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 135 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 131 }; | 136 }; |
| 132 | 137 |
| 133 bool RegisterViewRoot(JNIEnv* env); | |
| 134 | |
| 135 } // namespace ui | 138 } // namespace ui |
| 136 | 139 |
| 137 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 140 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |