Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: ui/android/view_android.h

Issue 2103243002: Factor out ContentViewAndroidDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // This method is intentionally not called anywhere, since there are
33 // no native methods that are called from Java. TODO(crbug.com/603936).
34 static bool RegisterViewAndroid(JNIEnv* env);
35
31 // Used to construct a child view. 36 // Used to construct a child view.
32 ViewAndroid(); 37 ViewAndroid();
33 ~ViewAndroid(); 38 ~ViewAndroid();
34 39
35 // Returns the window at the root of this hierarchy, or |null| 40 // Returns the window at the root of this hierarchy, or |null|
36 // if disconnected. 41 // if disconnected.
37 WindowAndroid* GetWindowAndroid() const; 42 WindowAndroid* GetWindowAndroid() const;
38 43
39 // Set the root |WindowAndroid|. This is only valid for root 44 // Set the root |WindowAndroid|. This is only valid for root
40 // nodes and must not be called for children. 45 // nodes and must not be called for children.
41 void SetWindowAndroid(WindowAndroid* root_window); 46 void SetWindowAndroid(WindowAndroid* root_window);
42 47
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|. 48 // Used to return and set the layer for this view. May be |null|.
49 cc::Layer* GetLayer() const; 49 cc::Layer* GetLayer() const;
50 void SetLayer(scoped_refptr<cc::Layer> layer); 50 void SetLayer(scoped_refptr<cc::Layer> layer);
51 51
52 // Add/remove this view as a child of another view. 52 // Add/remove this view as a child of another view.
53 void AddChild(ViewAndroid* child); 53 void AddChild(ViewAndroid* child);
54 void RemoveChild(ViewAndroid* child); 54 void RemoveChild(ViewAndroid* child);
55 55
56 // Stores an anchored view to delete itself at the end of its lifetime
57 // automatically. This helps manage the lifecyle without the dependency
58 // on |ViewAndroid|.
59 class ScopedAnchorView {
60 public:
61 ScopedAnchorView(const base::android::JavaRef<jobject>& jview,
62 const base::android::JavaRef<jobject>& jdelegate);
63
64 ScopedAnchorView();
65 ScopedAnchorView(ScopedAnchorView&& other);
66 ScopedAnchorView& operator=(ScopedAnchorView&& other);
67
68 // Calls JNI removeView() on the delegate for cleanup.
69 ~ScopedAnchorView();
70
71 const bool is_null() const { return view_.is_null(); }
72 const base::android::JavaRef<jobject>& view() const { return view_; }
73
74 private:
75 base::android::ScopedJavaGlobalRef<jobject> view_;
76 base::android::ScopedJavaGlobalRef<jobject> delegate_;
77 };
78
79 ScopedAnchorView AcquireAnchorView();
80 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
81 const gfx::RectF& bounds);
82
56 private: 83 private:
84 // Returns the Java delegate for this view. This is used to delegate work
85 // up to the embedding view (or the embedder that can deal with the
86 // implementation details).
87 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
88
57 ViewAndroid* parent_; 89 ViewAndroid* parent_;
58 std::list<ViewAndroid*> children_; 90 std::list<ViewAndroid*> children_;
59 WindowAndroid* window_; 91 WindowAndroid* window_;
60 scoped_refptr<cc::Layer> layer_; 92 scoped_refptr<cc::Layer> layer_;
61 base::android::ScopedJavaGlobalRef<jobject> delegate_; 93 base::android::ScopedJavaGlobalRef<jobject> delegate_;
62 94
63 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 95 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
64 }; 96 };
65 97
66 } // namespace ui 98 } // namespace ui
67 99
68 #endif // UI_ANDROID_VIEW_ANDROID_H_ 100 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698