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

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 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 56 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
57 const base::android::JavaRef<jobject>& jimage); 57 const base::android::JavaRef<jobject>& jimage);
58 58
59 // Stores an anchored view to delete itself at the end of its lifetime
60 // automatically. This helps manage the lifecyle without the dependency
61 // on |ViewAndroid|.
62 class ScopedAnchorView {
63 public:
64 ScopedAnchorView(const base::android::JavaRef<jobject>& jview,
65 const base::android::JavaRef<jobject>& jdelegate);
66
67 ScopedAnchorView();
68 ScopedAnchorView(ScopedAnchorView&& other);
69 ScopedAnchorView& operator=(ScopedAnchorView&& other);
70
71 // Calls JNI removeView() on the delegate for cleanup.
72 ~ScopedAnchorView();
73
74 void Reset();
75
76 bool is_null() const { return view_.is_null(); }
77 const base::android::JavaRef<jobject>& view() const { return view_; }
78
79 private:
80 base::android::ScopedJavaGlobalRef<jobject> view_;
81 base::android::ScopedJavaGlobalRef<jobject> delegate_;
82 };
83
84 ScopedAnchorView AcquireAnchorView();
85 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
86 const gfx::RectF& bounds);
87
59 private: 88 private:
89 // Returns the Java delegate for this view. This is used to delegate work
90 // up to the embedding view (or the embedder that can deal with the
91 // implementation details).
92 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
93
60 ViewAndroid* parent_; 94 ViewAndroid* parent_;
61 std::list<ViewAndroid*> children_; 95 std::list<ViewAndroid*> children_;
62 WindowAndroid* window_; 96 WindowAndroid* window_;
63 scoped_refptr<cc::Layer> layer_; 97 scoped_refptr<cc::Layer> layer_;
64 base::android::ScopedJavaGlobalRef<jobject> delegate_; 98 base::android::ScopedJavaGlobalRef<jobject> delegate_;
65 99
66 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 100 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
67 }; 101 };
68 102
69 } // namespace ui 103 } // namespace ui
70 104
71 #endif // UI_ANDROID_VIEW_ANDROID_H_ 105 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698