| 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; | |
| 22 class WindowAndroid; | 21 class WindowAndroid; |
| 23 | 22 |
| 24 // A simple container for a UI layer. | 23 // A simple container for a UI layer. |
| 25 // At the root of the hierarchy is a WindowAndroid, when attached. | 24 // At the root of the hierarchy is a WindowAndroid, when attached. |
| 26 class UI_ANDROID_EXPORT ViewAndroid { | 25 class UI_ANDROID_EXPORT ViewAndroid { |
| 27 public: | 26 public: |
| 28 // Stores an anchored view to delete itself at the end of its lifetime | 27 // Stores an anchored view to delete itself at the end of its lifetime |
| 29 // automatically. This helps manage the lifecyle without the dependency | 28 // automatically. This helps manage the lifecyle without the dependency |
| 30 // on |ViewAndroid|. | 29 // on |ViewAndroid|. |
| 31 class ScopedAnchorView { | 30 class ScopedAnchorView { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 private: | 47 private: |
| 49 // TODO(jinsukkim): Following weak refs can be cast to strong refs which | 48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which |
| 50 // cannot be garbage-collected and leak memory. Rewrite not to use them. | 49 // cannot be garbage-collected and leak memory. Rewrite not to use them. |
| 51 // see comments in crrev.com/2103243002. | 50 // see comments in crrev.com/2103243002. |
| 52 JavaObjectWeakGlobalRef view_; | 51 JavaObjectWeakGlobalRef view_; |
| 53 JavaObjectWeakGlobalRef delegate_; | 52 JavaObjectWeakGlobalRef delegate_; |
| 54 | 53 |
| 55 // Default copy/assign disabled by move constructor. | 54 // Default copy/assign disabled by move constructor. |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 explicit ViewAndroid(ViewClient* client); | 57 // A ViewAndroid may have its own delegate or otherwise will |
| 58 // use the next available parent's delegate. |
| 59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); |
| 59 | 60 |
| 60 ViewAndroid(); | 61 ViewAndroid(); |
| 61 virtual ~ViewAndroid(); | 62 virtual ~ViewAndroid(); |
| 62 | 63 |
| 63 // The content offset is in CSS pixels, and is used to translate | 64 // The content offset is in CSS pixels, and is used to translate |
| 64 // snapshots to the correct part of the view. | 65 // snapshots to the correct part of the view. |
| 65 void set_content_offset(const gfx::Vector2dF& content_offset) { | 66 void set_content_offset(const gfx::Vector2dF& content_offset) { |
| 66 content_offset_ = content_offset; | 67 content_offset_ = content_offset; |
| 67 } | 68 } |
| 68 | 69 |
| 69 gfx::Vector2dF content_offset() const { | 70 gfx::Vector2dF content_offset() const { |
| 70 return content_offset_; | 71 return content_offset_; |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Returns the window at the root of this hierarchy, or |null| | 74 // Returns the window at the root of this hierarchy, or |null| |
| 74 // if disconnected. | 75 // if disconnected. |
| 75 virtual WindowAndroid* GetWindowAndroid() const; | 76 virtual WindowAndroid* GetWindowAndroid() const; |
| 76 | 77 |
| 77 // Returns |ViewRoot| associated with the current ViewAndroid. | |
| 78 // Create one if not present. | |
| 79 base::android::ScopedJavaLocalRef<jobject> GetViewRoot(); | |
| 80 | |
| 81 // Used to return and set the layer for this view. May be |null|. | 78 // Used to return and set the layer for this view. May be |null|. |
| 82 cc::Layer* GetLayer() const; | 79 cc::Layer* GetLayer() const; |
| 83 void SetLayer(scoped_refptr<cc::Layer> layer); | 80 void SetLayer(scoped_refptr<cc::Layer> layer); |
| 84 | 81 |
| 85 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 82 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
| 86 | 83 |
| 87 // Adds this view as a child of another view. | 84 // Adds this view as a child of another view. |
| 88 void AddChild(ViewAndroid* child); | 85 void AddChild(ViewAndroid* child); |
| 89 | 86 |
| 90 // Detaches this view from its parent. | 87 // Detaches this view from its parent. |
| 91 void RemoveFromParent(); | 88 void RemoveFromParent(); |
| 92 | 89 |
| 93 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 94 const base::android::JavaRef<jobject>& jimage); | 91 const base::android::JavaRef<jobject>& jimage); |
| 95 | 92 |
| 96 ScopedAnchorView AcquireAnchorView(); | 93 ScopedAnchorView AcquireAnchorView(); |
| 97 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
| 98 const gfx::RectF& bounds); | 95 const gfx::RectF& bounds); |
| 99 | 96 |
| 100 gfx::Size GetPhysicalBackingSize(); | |
| 101 void UpdateLayerBounds(); | |
| 102 | |
| 103 // Internal implementation of ViewClient forwarding calls to the interface. | |
| 104 void OnPhysicalBackingSizeChanged(int width, int height); | |
| 105 | |
| 106 protected: | 97 protected: |
| 107 ViewAndroid* parent_; | 98 ViewAndroid* parent_; |
| 108 | 99 |
| 109 private: | 100 private: |
| 110 void RemoveChild(ViewAndroid* child); | 101 void RemoveChild(ViewAndroid* child); |
| 111 | 102 |
| 112 // Checks if any ViewAndroid instance in the tree hierarchy (including | |
| 113 // all the parents and the children) has |ViewRoot| already. | |
| 114 bool HasViewRootInTreeHierarchy(); | |
| 115 | |
| 116 // Checks if any children (plus this ViewAndroid itself) has |ViewRoot|. | |
| 117 bool HasViewRootInSubtree(); | |
| 118 | |
| 119 // Returns the Java delegate for this view. This is used to delegate work | 103 // Returns the Java delegate for this view. This is used to delegate work |
| 120 // up to the embedding view (or the embedder that can deal with the | 104 // up to the embedding view (or the embedder that can deal with the |
| 121 // implementation details). | 105 // implementation details). |
| 122 const base::android::ScopedJavaLocalRef<jobject> | 106 const base::android::ScopedJavaLocalRef<jobject> |
| 123 GetViewAndroidDelegate() const; | 107 GetViewAndroidDelegate() const; |
| 124 | 108 |
| 125 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child | |
| 126 // should have |ViewRoot| for this ViewAndroid to have one. | |
| 127 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot(); | |
| 128 | |
| 129 bool HasViewRoot(); | |
| 130 | |
| 131 std::list<ViewAndroid*> children_; | 109 std::list<ViewAndroid*> children_; |
| 132 scoped_refptr<cc::Layer> layer_; | 110 scoped_refptr<cc::Layer> layer_; |
| 133 JavaObjectWeakGlobalRef delegate_; | 111 JavaObjectWeakGlobalRef delegate_; |
| 134 JavaObjectWeakGlobalRef view_root_; | |
| 135 ViewClient* const client_; | |
| 136 | |
| 137 int physical_width_pix_; | |
| 138 int physical_height_pix_; | |
| 139 gfx::Vector2dF content_offset_; // in CSS pixel | 112 gfx::Vector2dF content_offset_; // in CSS pixel |
| 140 | 113 |
| 141 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 114 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 142 }; | 115 }; |
| 143 | 116 |
| 144 bool RegisterViewRoot(JNIEnv* env); | |
| 145 | |
| 146 } // namespace ui | 117 } // namespace ui |
| 147 | 118 |
| 148 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 119 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |