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

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: webview issues addressed Created 4 years, 4 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/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:
26 // A ViewAndroid may have its own delegate or otherwise will 27 // A ViewAndroid may have its own delegate or otherwise will
27 // use the next available parent's delegate. 28 // use the next available parent's delegate.
28 ViewAndroid(const base::android::JavaRef<jobject>& delegate); 29 ViewAndroid(const base::android::JavaRef<jobject>& delegate);
30
29 ViewAndroid(); 31 ViewAndroid();
30 virtual ~ViewAndroid(); 32 virtual ~ViewAndroid();
31 33
34 // This method is intentionally not called anywhere, since there are
35 // no native methods that are called from Java. TODO(crbug.com/603936).
36 static bool RegisterViewAndroid(JNIEnv* env);
37
32 // Returns the window at the root of this hierarchy, or |null| 38 // Returns the window at the root of this hierarchy, or |null|
33 // if disconnected. 39 // if disconnected.
34 virtual WindowAndroid* GetWindowAndroid() const; 40 virtual WindowAndroid* GetWindowAndroid() const;
35 41
36 // Returns the Java delegate for this view. This is used to delegate work 42 // Set the root |WindowAndroid|. This is only valid for root
37 // up to the embedding view (or the embedder that can deal with the 43 // nodes and must not be called for children.
38 // implementation details). 44 void SetWindowAndroid(WindowAndroid* root_window);
39 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
40 45
41 // 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|.
42 cc::Layer* GetLayer() const; 47 cc::Layer* GetLayer() const;
43 void SetLayer(scoped_refptr<cc::Layer> layer); 48 void SetLayer(scoped_refptr<cc::Layer> layer);
44 49
45 // Adds this view as a child of another view. 50 // Adds this view as a child of another view.
46 void AddChild(ViewAndroid* child); 51 void AddChild(ViewAndroid* child);
47 52
48 // Detaches this view from its parent. 53 // Detaches this view from its parent.
49 void RemoveFromParent(); 54 void RemoveFromParent();
50 55
51 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 56 void StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
52 const base::android::JavaRef<jobject>& jimage); 57 const base::android::JavaRef<jobject>& jimage);
53 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(JNIEnv* env,
65 const base::android::JavaRef<jobject>& jview,
66 const base::android::JavaRef<jobject>& jdelegate);
67
68 ScopedAnchorView();
69 ScopedAnchorView(ScopedAnchorView&& other);
70 ScopedAnchorView& operator=(ScopedAnchorView&& other);
71
72 // Calls JNI removeView() on the delegate for cleanup.
73 ~ScopedAnchorView();
74
75 void Reset();
76
77 bool is_null() const { return view_.is_empty(); }
boliu 2016/07/27 16:20:26 this method is no longer valid, since *in theory*,
Jinsuk Kim 2016/07/29 06:09:14 Good to know this. Removed |is_null()|.
78 const base::android::ScopedJavaLocalRef<jobject> view(JNIEnv* env) const {
79 return view_.get(env);
80 }
81
82 private:
83 // TODO(jinsukkim): Following weak refs can be cast to strong refs which
84 // cannot be garbage-collected and leak memory. Rewrite not to use them.
85 // see comments in crrev.com/2103243002.
86 JavaObjectWeakGlobalRef view_;
87 JavaObjectWeakGlobalRef delegate_;
88 };
89
90 ScopedAnchorView AcquireAnchorView();
91 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
92 const gfx::RectF& bounds);
93
54 protected: 94 protected:
55 ViewAndroid* parent_; 95 ViewAndroid* parent_;
56 96
57 private: 97 private:
58 void RemoveChild(ViewAndroid* child); 98 void RemoveChild(ViewAndroid* child);
59 99
100 // Returns the Java delegate for this view. This is used to delegate work
101 // up to the embedding view (or the embedder that can deal with the
102 // implementation details).
103 const base::android::JavaRef<jobject>& GetViewAndroidDelegate() const;
104
60 std::list<ViewAndroid*> children_; 105 std::list<ViewAndroid*> children_;
61 scoped_refptr<cc::Layer> layer_; 106 scoped_refptr<cc::Layer> layer_;
62 base::android::ScopedJavaGlobalRef<jobject> delegate_; 107 base::android::ScopedJavaGlobalRef<jobject> delegate_;
63 108
64 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 109 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
65 }; 110 };
66 111
67 } // namespace ui 112 } // namespace ui
68 113
69 #endif // UI_ANDROID_VIEW_ANDROID_H_ 114 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698