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