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/callback.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "ui/android/ui_android_export.h" | 13 #include "ui/android/ui_android_export.h" |
13 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
14 | 15 |
| 16 typedef unsigned int SkColor; |
| 17 |
15 namespace cc { | 18 namespace cc { |
16 class Layer; | 19 class Layer; |
17 } | 20 } |
18 | 21 |
19 namespace ui { | 22 namespace ui { |
20 | 23 |
21 class WindowAndroid; | 24 class WindowAndroid; |
22 | 25 |
23 // A simple container for a UI layer. | 26 // A simple container for a UI layer. |
24 // At the root of the hierarchy is a WindowAndroid, when attached. | 27 // At the root of the hierarchy is a WindowAndroid, when attached. |
(...skipping 22 matching lines...) Expand all Loading... |
47 private: | 50 private: |
48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which | 51 // 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. | 52 // cannot be garbage-collected and leak memory. Rewrite not to use them. |
50 // see comments in crrev.com/2103243002. | 53 // see comments in crrev.com/2103243002. |
51 JavaObjectWeakGlobalRef view_; | 54 JavaObjectWeakGlobalRef view_; |
52 JavaObjectWeakGlobalRef delegate_; | 55 JavaObjectWeakGlobalRef delegate_; |
53 | 56 |
54 // Default copy/assign disabled by move constructor. | 57 // Default copy/assign disabled by move constructor. |
55 }; | 58 }; |
56 | 59 |
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); | |
60 | |
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 |
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 |
80 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 79 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
81 const base::android::JavaRef<jobject>& jimage); | 80 const base::android::JavaRef<jobject>& jimage); |
82 | 81 |
83 ScopedAnchorView AcquireAnchorView(); | 82 ScopedAnchorView AcquireAnchorView(); |
84 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 83 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
85 const gfx::RectF& bounds); | 84 const gfx::RectF& bounds); |
86 | 85 |
| 86 void reset_physical_backing_size_changed_handler( |
| 87 base::RepeatingCallback<void(int, int)> handler) { |
| 88 // Handlers are stored in the view android that has the java delegate, |
| 89 // which is unique in the implementation. |
| 90 // |
| 91 // This should be able to find the one to store the handler in before |
| 92 // reaching the top view (or window, if not attached yet). |
| 93 DCHECK(parent_); |
| 94 if (delegate_.is_uninitialized()) |
| 95 parent_->reset_physical_backing_size_changed_handler(handler); |
| 96 else |
| 97 physical_backing_size_changed_handler_ = std::move(handler); |
| 98 } |
| 99 |
| 100 void reset_physical_backing_size_changed_handler() { |
| 101 DCHECK(parent_); |
| 102 if (delegate_.is_uninitialized()) |
| 103 parent_->reset_physical_backing_size_changed_handler(); |
| 104 else |
| 105 physical_backing_size_changed_handler_.Reset(); |
| 106 } |
| 107 |
| 108 void OnPhysicalBackingSizeChanged( |
| 109 JNIEnv* env, |
| 110 const base::android::JavaParamRef<jobject>& obj, |
| 111 jint width, |
| 112 jint height); |
| 113 |
| 114 // Register the ViewAndroid's native methods through JNI. |
| 115 static bool RegisterViewAndroid(JNIEnv* env); |
| 116 |
87 protected: | 117 protected: |
88 ViewAndroid* parent_; | 118 ViewAndroid* parent_; |
89 | 119 |
90 private: | 120 private: |
91 void RemoveChild(ViewAndroid* child); | 121 void RemoveChild(ViewAndroid* child); |
92 | 122 |
93 // Returns the Java delegate for this view. This is used to delegate work | 123 // 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 | 124 // up to the embedding view (or the embedder that can deal with the |
95 // implementation details). | 125 // implementation details). |
96 const base::android::ScopedJavaLocalRef<jobject> | 126 const base::android::ScopedJavaLocalRef<jobject> |
97 GetViewAndroidDelegate() const; | 127 GetViewAndroidDelegate() const; |
98 | 128 |
99 std::list<ViewAndroid*> children_; | 129 std::list<ViewAndroid*> children_; |
100 scoped_refptr<cc::Layer> layer_; | 130 scoped_refptr<cc::Layer> layer_; |
101 JavaObjectWeakGlobalRef delegate_; | 131 JavaObjectWeakGlobalRef delegate_; |
102 | 132 |
| 133 // Handler for calls coming down from Java layer. |
| 134 base::RepeatingCallback<void(int, int)> |
| 135 physical_backing_size_changed_handler_; |
| 136 |
103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 137 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
104 }; | 138 }; |
105 | 139 |
106 } // namespace ui | 140 } // namespace ui |
107 | 141 |
108 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 142 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |