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/scoped_java_ref.h" | 10 #include "base/android/scoped_java_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 | 14 |
14 namespace cc { | 15 namespace cc { |
15 class Layer; | 16 class Layer; |
16 } | 17 } |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 class WindowAndroid; | 21 class WindowAndroid; |
21 | 22 |
22 // A simple container for a UI layer. | 23 // A simple container for a UI layer. |
23 // At the root of the hierarchy is a WindowAndroid. | 24 // At the root of the hierarchy is a WindowAndroid. |
24 // | 25 // |
25 class UI_ANDROID_EXPORT ViewAndroid { | 26 class UI_ANDROID_EXPORT ViewAndroid { |
26 public: | 27 public: |
27 // Used to construct a root view. | 28 // Used to construct a root view. |
28 ViewAndroid(const base::android::JavaRef<jobject>& delegate, | 29 ViewAndroid(const base::android::JavaRef<jobject>& delegate, |
29 WindowAndroid* root_window); | 30 WindowAndroid* root_window); |
30 | 31 |
32 static bool RegisterWindowAndroid(JNIEnv* env); | |
33 | |
31 // Used to construct a child view. | 34 // Used to construct a child view. |
32 ViewAndroid(); | 35 ViewAndroid(); |
33 ~ViewAndroid(); | 36 ~ViewAndroid(); |
34 | 37 |
35 // Returns the window at the root of this hierarchy, or |null| | 38 // Returns the window at the root of this hierarchy, or |null| |
36 // if disconnected. | 39 // if disconnected. |
37 WindowAndroid* GetWindowAndroid() const; | 40 WindowAndroid* GetWindowAndroid() const; |
38 | 41 |
39 // Set the root |WindowAndroid|. This is only valid for root | 42 // Set the root |WindowAndroid|. This is only valid for root |
40 // nodes and must not be called for children. | 43 // nodes and must not be called for children. |
41 void SetWindowAndroid(WindowAndroid* root_window); | 44 void SetWindowAndroid(WindowAndroid* root_window); |
42 | 45 |
43 // Returns the Java delegate for this view. This is used to delegate work | |
44 // up to the embedding view (or the embedder that can deal with the | |
45 // implementation details). | |
46 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const; | |
47 | |
48 // Used to return and set the layer for this view. May be |null|. | 46 // Used to return and set the layer for this view. May be |null|. |
49 cc::Layer* GetLayer() const; | 47 cc::Layer* GetLayer() const; |
50 void SetLayer(scoped_refptr<cc::Layer> layer); | 48 void SetLayer(scoped_refptr<cc::Layer> layer); |
51 | 49 |
52 // Add/remove this view as a child of another view. | 50 // Add/remove this view as a child of another view. |
53 void AddChild(ViewAndroid* child); | 51 void AddChild(ViewAndroid* child); |
54 void RemoveChild(ViewAndroid* child); | 52 void RemoveChild(ViewAndroid* child); |
55 | 53 |
54 // Stores an anchored view to delete itself at the end of its lifetime | |
55 // automatically. This helps manage the lifecyle without the dependency | |
56 // on |ViewAndroid|. | |
57 class ScopedAnchorView { | |
58 public: | |
59 ScopedAnchorView(const base::android::JavaRef<jobject>& jview, | |
60 const base::android::JavaRef<jobject>& jdelegate) | |
61 : view_(jview), delegate_(jdelegate) { } | |
62 | |
63 ScopedAnchorView() : ScopedAnchorView(nullptr, nullptr) { } | |
64 | |
65 // Calls JNI removeView() on the delegate for cleanup. | |
66 ~ScopedAnchorView(); | |
67 | |
68 base::android::ScopedJavaGlobalRef<jobject> ref() const { return view_; } | |
69 jobject obj() const { return view_.obj(); } | |
no sievers
2016/07/18 22:14:17
nit: Could this just have one method to return 'co
Jinsuk Kim
2016/07/19 07:08:40
Done. Also added |is_null()| to not to have to cal
| |
70 | |
71 private: | |
72 base::android::ScopedJavaGlobalRef<jobject> view_; | |
73 base::android::ScopedJavaGlobalRef<jobject> delegate_; | |
74 }; | |
75 | |
76 ScopedAnchorView* AcquireAnchorView(); | |
no sievers
2016/07/18 22:14:17
Can you make this a 'move only' type and return by
Jinsuk Kim
2016/07/19 07:08:40
Done. The way I changed it uses move assignment th
| |
77 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | |
78 const gfx::RectF& bounds); | |
79 | |
56 private: | 80 private: |
81 // Returns the Java delegate for this view. This is used to delegate work | |
82 // up to the embedding view (or the embedder that can deal with the | |
83 // implementation details). | |
84 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const; | |
85 | |
57 ViewAndroid* parent_; | 86 ViewAndroid* parent_; |
58 std::list<ViewAndroid*> children_; | 87 std::list<ViewAndroid*> children_; |
59 WindowAndroid* window_; | 88 WindowAndroid* window_; |
60 scoped_refptr<cc::Layer> layer_; | 89 scoped_refptr<cc::Layer> layer_; |
61 base::android::ScopedJavaGlobalRef<jobject> delegate_; | 90 base::android::ScopedJavaGlobalRef<jobject> delegate_; |
62 | 91 |
63 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 92 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
64 }; | 93 }; |
65 | 94 |
66 } // namespace ui | 95 } // namespace ui |
67 | 96 |
68 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 97 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |