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(); |
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | |
60 | 60 |
61 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 |
68 // Used to return and set the layer for this view. May be |null|. | 67 // Used to return and set the layer for this view. May be |null|. |
69 cc::Layer* GetLayer() const; | 68 cc::Layer* GetLayer() const; |
70 void SetLayer(scoped_refptr<cc::Layer> layer); | 69 void SetLayer(scoped_refptr<cc::Layer> layer); |
71 | 70 |
72 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 71 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
73 | 72 |
74 // Adds this view as a child of another view. | 73 // Adds this view as a child of another view. |
75 void AddChild(ViewAndroid* child); | 74 void AddChild(ViewAndroid* child); |
76 | 75 |
77 // Detaches this view from its parent. | 76 // Detaches this view from its parent. |
78 void RemoveFromParent(); | 77 void RemoveFromParent(); |
79 | 78 |
79 bool has_event_handler() { return has_event_handler_; } | |
boliu
2016/12/06 23:15:46
private
Jinsuk Kim
2016/12/07 12:36:28
Removed.
| |
80 | |
81 // Called when an |EventHandler| gets associated with the current ViewAndroid. | |
82 // The |EventHandler| must be unique in the tree to which this ViewAndroid | |
boliu
2016/12/06 23:15:46
"unique in the tree" is not the phrase here, I don
Jinsuk Kim
2016/12/07 12:36:28
Done.
| |
83 // belongs - i.e. there must be no parent or child ViewAndroid instance that | |
84 // already has an |EventHandler|. | |
85 void OnSetEventHandler(); | |
86 | |
80 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 87 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
81 const base::android::JavaRef<jobject>& jimage); | 88 const base::android::JavaRef<jobject>& jimage); |
82 | 89 |
90 gfx::Size GetPhysicalBackingSize(); | |
91 | |
83 ScopedAnchorView AcquireAnchorView(); | 92 ScopedAnchorView AcquireAnchorView(); |
84 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 93 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
85 const gfx::RectF& bounds); | 94 const gfx::RectF& bounds); |
86 | 95 |
96 // Internal implementation of ViewClient forwarding calls to the interface. | |
97 void OnPhysicalBackingSizeChanged(int width, int height); | |
98 | |
99 void UpdateLayerBounds(); | |
100 | |
87 protected: | 101 protected: |
88 ViewAndroid* parent_; | 102 ViewAndroid* parent_; |
89 | 103 |
90 private: | 104 private: |
91 void RemoveChild(ViewAndroid* child); | 105 void RemoveChild(ViewAndroid* child); |
92 | 106 |
107 // Checks if any ViewAndroid instance in the tree hierarchy (including | |
108 // all the parents and the children) has |EventHandler| already. | |
109 bool HasEventHandlerInTreeHierarchy(); | |
110 | |
111 // Checks if any children (plus this ViewAndroid itself) has |EventHandler|. | |
112 bool HasEventHandlerInSubtree(); | |
113 | |
93 // Returns the Java delegate for this view. This is used to delegate work | 114 // 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 | 115 // up to the embedding view (or the embedder that can deal with the |
95 // implementation details). | 116 // implementation details). |
96 const base::android::ScopedJavaLocalRef<jobject> | 117 const base::android::ScopedJavaLocalRef<jobject> |
97 GetViewAndroidDelegate() const; | 118 GetViewAndroidDelegate() const; |
98 | 119 |
120 int GetPhysicalBackingSizeWidthPix(); | |
boliu
2016/12/06 23:15:46
remove these two
Jinsuk Kim
2016/12/07 12:36:28
Done.
| |
121 int GetPhysicalBackingSizeHeightPix(); | |
122 void SetPhysicalBackingSize(int width, int height); | |
123 | |
99 std::list<ViewAndroid*> children_; | 124 std::list<ViewAndroid*> children_; |
100 scoped_refptr<cc::Layer> layer_; | 125 scoped_refptr<cc::Layer> layer_; |
101 JavaObjectWeakGlobalRef delegate_; | 126 JavaObjectWeakGlobalRef delegate_; |
127 ViewClient* const client_; | |
128 | |
129 int physical_width_pix_; | |
130 int physical_height_pix_; | |
131 bool has_event_handler_; | |
102 | 132 |
103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 133 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
104 }; | 134 }; |
105 | 135 |
106 } // namespace ui | 136 } // namespace ui |
107 | 137 |
108 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 138 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |