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 ViewAndroid(ViewClient* client); |
boliu
2016/12/06 00:34:14
explicit
Jinsuk Kim
2016/12/06 07:35:07
Done.
| |
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 |
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 |
82 gfx::Size GetPhysicalBackingSize(); | |
83 | |
83 ScopedAnchorView AcquireAnchorView(); | 84 ScopedAnchorView AcquireAnchorView(); |
84 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 85 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
85 const gfx::RectF& bounds); | 86 const gfx::RectF& bounds); |
86 | 87 |
88 // Internal implementation of ViewClient forwarding calls to the interface. | |
89 bool OnPhysicalBackingSizeChanged(int width, int height); | |
90 | |
91 void UpdateLayerBounds(); | |
92 | |
87 protected: | 93 protected: |
88 ViewAndroid* parent_; | 94 ViewAndroid* parent_; |
89 | 95 |
90 private: | 96 private: |
91 void RemoveChild(ViewAndroid* child); | 97 void RemoveChild(ViewAndroid* child); |
92 | 98 |
93 // Returns the Java delegate for this view. This is used to delegate work | 99 // 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 | 100 // up to the embedding view (or the embedder that can deal with the |
95 // implementation details). | 101 // implementation details). |
96 const base::android::ScopedJavaLocalRef<jobject> | 102 const base::android::ScopedJavaLocalRef<jobject> |
97 GetViewAndroidDelegate() const; | 103 GetViewAndroidDelegate() const; |
98 | 104 |
105 int GetPhysicalBackingSizeWidthPix(); | |
106 int GetPhysicalBackingSizeHeightPix(); | |
107 void SetPhysicalBackingSize(int width, int height); | |
108 | |
99 std::list<ViewAndroid*> children_; | 109 std::list<ViewAndroid*> children_; |
100 scoped_refptr<cc::Layer> layer_; | 110 scoped_refptr<cc::Layer> layer_; |
101 JavaObjectWeakGlobalRef delegate_; | 111 JavaObjectWeakGlobalRef delegate_; |
112 ViewClient* client_; | |
boliu
2016/12/06 00:34:14
ViewClient* const client_;, it should be const, ri
Jinsuk Kim
2016/12/06 07:35:07
Yes. Done.
| |
113 | |
114 int physical_width_pix_; | |
115 int physical_height_pix_; | |
102 | 116 |
103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 117 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
104 }; | 118 }; |
105 | 119 |
106 } // namespace ui | 120 } // namespace ui |
107 | 121 |
108 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 122 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |