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/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 | 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, when attached. | 24 // At the root of the hierarchy is a WindowAndroid, when attached. |
24 class UI_ANDROID_EXPORT ViewAndroid { | 25 class UI_ANDROID_EXPORT ViewAndroid { |
25 public: | 26 public: |
27 // Stores an anchored view to delete itself at the end of its lifetime | |
28 // automatically. This helps manage the lifecyle without the dependency | |
29 // on |ViewAndroid|. | |
30 class ScopedAnchorView { | |
31 public: | |
32 ScopedAnchorView(JNIEnv* env, | |
33 const base::android::JavaRef<jobject>& jview, | |
34 const base::android::JavaRef<jobject>& jdelegate); | |
35 | |
36 ScopedAnchorView(); | |
37 ScopedAnchorView(ScopedAnchorView&& other); | |
38 ScopedAnchorView& operator=(ScopedAnchorView&& other); | |
39 | |
40 // Calls JNI removeView() on the delegate for cleanup. | |
41 ~ScopedAnchorView(); | |
42 | |
43 void Reset(); | |
44 | |
45 const base::android::ScopedJavaLocalRef<jobject> view() const; | |
46 | |
47 private: | |
48 // 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 // see comments in crrev.com/2103243002. | |
51 JavaObjectWeakGlobalRef view_; | |
52 JavaObjectWeakGlobalRef delegate_; | |
53 | |
54 // Default copy/assign disabled by move constructor. | |
55 }; | |
56 | |
26 // A ViewAndroid may have its own delegate or otherwise will | 57 // A ViewAndroid may have its own delegate or otherwise will |
27 // use the next available parent's delegate. | 58 // use the next available parent's delegate. |
28 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | 59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); |
60 | |
29 ViewAndroid(); | 61 ViewAndroid(); |
30 virtual ~ViewAndroid(); | 62 virtual ~ViewAndroid(); |
31 | 63 |
32 // Returns the window at the root of this hierarchy, or |null| | 64 // Returns the window at the root of this hierarchy, or |null| |
33 // if disconnected. | 65 // if disconnected. |
34 virtual WindowAndroid* GetWindowAndroid() const; | 66 virtual WindowAndroid* GetWindowAndroid() const; |
35 | 67 |
36 // Returns the Java delegate for this view. This is used to delegate work | 68 // Set the root |WindowAndroid|. This is only valid for root |
37 // up to the embedding view (or the embedder that can deal with the | 69 // nodes and must not be called for children. |
38 // implementation details). | 70 void SetWindowAndroid(WindowAndroid* root_window); |
Ted C
2016/08/24 17:26:54
I think this was a bad rebase. This was removed b
| |
39 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const; | |
40 | 71 |
41 // Used to return and set the layer for this view. May be |null|. | 72 // Used to return and set the layer for this view. May be |null|. |
42 cc::Layer* GetLayer() const; | 73 cc::Layer* GetLayer() const; |
43 void SetLayer(scoped_refptr<cc::Layer> layer); | 74 void SetLayer(scoped_refptr<cc::Layer> layer); |
44 | 75 |
45 // Adds this view as a child of another view. | 76 // Adds this view as a child of another view. |
46 void AddChild(ViewAndroid* child); | 77 void AddChild(ViewAndroid* child); |
47 | 78 |
48 // Detaches this view from its parent. | 79 // Detaches this view from its parent. |
49 void RemoveFromParent(); | 80 void RemoveFromParent(); |
50 | 81 |
51 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 82 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
52 const base::android::JavaRef<jobject>& jimage); | 83 const base::android::JavaRef<jobject>& jimage); |
53 | 84 |
85 ScopedAnchorView AcquireAnchorView(); | |
86 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | |
87 const gfx::RectF& bounds); | |
88 | |
54 protected: | 89 protected: |
55 ViewAndroid* parent_; | 90 ViewAndroid* parent_; |
56 | 91 |
57 private: | 92 private: |
58 void RemoveChild(ViewAndroid* child); | 93 void RemoveChild(ViewAndroid* child); |
59 | 94 |
95 // Returns the Java delegate for this view. This is used to delegate work | |
96 // up to the embedding view (or the embedder that can deal with the | |
97 // implementation details). | |
98 const base::android::ScopedJavaLocalRef<jobject> | |
99 GetViewAndroidDelegate() const; | |
100 | |
60 std::list<ViewAndroid*> children_; | 101 std::list<ViewAndroid*> children_; |
61 scoped_refptr<cc::Layer> layer_; | 102 scoped_refptr<cc::Layer> layer_; |
62 base::android::ScopedJavaGlobalRef<jobject> delegate_; | 103 JavaObjectWeakGlobalRef delegate_; |
63 | 104 |
64 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 105 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
65 }; | 106 }; |
66 | 107 |
67 } // namespace ui | 108 } // namespace ui |
68 | 109 |
69 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 110 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |