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

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

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: addressed comments Created 3 years, 11 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/jni_weak_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 #include "ui/gfx/geometry/rect_f.h"
14 14
15 namespace cc { 15 namespace cc {
16 class Layer; 16 class Layer;
17 } 17 }
18 18
19 namespace ui { 19 namespace ui {
20 20
21 class ViewClient; 21 class ViewClient;
22 class WindowAndroid; 22 class WindowAndroid;
23 23
24 // A simple container for a UI layer. 24 // A simple container for a UI layer.
25 // At the root of the hierarchy is a WindowAndroid, when attached. 25 // At the root of the hierarchy is a ViewRoot, a subclass of ViewAndroid.
26 class UI_ANDROID_EXPORT ViewAndroid { 26 class UI_ANDROID_EXPORT ViewAndroid {
27 public: 27 public:
28 // Stores an anchored view to delete itself at the end of its lifetime 28 // Stores an anchored view to delete itself at the end of its lifetime
29 // automatically. This helps manage the lifecyle without the dependency 29 // automatically. This helps manage the lifecyle without the dependency
30 // on |ViewAndroid|. 30 // on |ViewAndroid|.
31 class ScopedAnchorView { 31 class ScopedAnchorView {
32 public: 32 public:
33 ScopedAnchorView(JNIEnv* env, 33 ScopedAnchorView(JNIEnv* env,
34 const base::android::JavaRef<jobject>& jview, 34 const base::android::JavaRef<jobject>& jview,
35 const base::android::JavaRef<jobject>& jdelegate); 35 const base::android::JavaRef<jobject>& jdelegate);
(...skipping 21 matching lines...) Expand all
57 57
58 explicit ViewAndroid(ViewClient* client); 58 explicit ViewAndroid(ViewClient* client);
59 59
60 ViewAndroid(); 60 ViewAndroid();
61 virtual ~ViewAndroid(); 61 virtual ~ViewAndroid();
62 62
63 // Returns the window at the root of this hierarchy, or |null| 63 // Returns the window at the root of this hierarchy, or |null|
64 // if disconnected. 64 // if disconnected.
65 virtual WindowAndroid* GetWindowAndroid() const; 65 virtual WindowAndroid* GetWindowAndroid() const;
66 66
67 // Returns |ViewRoot| associated with the current ViewAndroid. 67 // Adds this view as a child of another view.
68 // Create one if not present. 68 virtual void AddChild(ViewAndroid* child);
boliu 2017/01/04 18:58:06 hmm, why does this need to be virtual?
Jinsuk Kim 2017/01/05 11:03:12 Ah forgot to remove it after some testing. Done.
69 base::android::ScopedJavaLocalRef<jobject> GetViewRoot();
70 69
71 // Used to return and set the layer for this view. May be |null|. 70 // Used to return and set the layer for this view. May be |null|.
72 cc::Layer* GetLayer() const; 71 cc::Layer* GetLayer() const;
73 void SetLayer(scoped_refptr<cc::Layer> layer); 72 void SetLayer(scoped_refptr<cc::Layer> layer);
74 73
75 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 74 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
76 75
77 // Adds this view as a child of another view.
78 void AddChild(ViewAndroid* child);
79
80 // Detaches this view from its parent. 76 // Detaches this view from its parent.
81 void RemoveFromParent(); 77 void RemoveFromParent();
82 78
83 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 79 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
84 const base::android::JavaRef<jobject>& jimage); 80 const base::android::JavaRef<jobject>& jimage);
85 81
86 ScopedAnchorView AcquireAnchorView(); 82 ScopedAnchorView AcquireAnchorView();
87 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 83 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
88 const gfx::RectF& bounds); 84 const gfx::RectF& bounds);
89 85
90 gfx::Size GetPhysicalBackingSize(); 86 gfx::Size GetPhysicalBackingSize();
91 void UpdateLayerBounds(); 87 void UpdateLayerBounds();
92 88
89 protected:
90 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't
91 // attached to a |ViewRoot|.
92 virtual ViewAndroid* GetViewRoot();
93
94 virtual void RemoveChild(ViewAndroid* child);
boliu 2017/01/04 18:58:06 this doesn't need to be virtual or protected if Vi
Jinsuk Kim 2017/01/05 11:03:12 Removed virtual and turned to private.
95
93 // Internal implementation of ViewClient forwarding calls to the interface. 96 // Internal implementation of ViewClient forwarding calls to the interface.
94 void OnPhysicalBackingSizeChanged(int width, int height); 97 void OnPhysicalBackingSizeChangedInternal(int width, int height);
95 98
96 protected: 99 std::list<ViewAndroid*> children_;
97 ViewAndroid* parent_;
98 100
99 private: 101 private:
100 void RemoveChild(ViewAndroid* child);
101
102 // Checks if any ViewAndroid instance in the tree hierarchy (including
103 // all the parents and the children) has |ViewRoot| already.
104 bool HasViewRootInTreeHierarchy();
105
106 // Checks if any children (plus this ViewAndroid itself) has |ViewRoot|.
107 bool HasViewRootInSubtree();
108
109 // Returns the Java delegate for this view. This is used to delegate work 102 // Returns the Java delegate for this view. This is used to delegate work
110 // up to the embedding view (or the embedder that can deal with the 103 // up to the embedding view (or the embedder that can deal with the
111 // implementation details). 104 // implementation details).
112 const base::android::ScopedJavaLocalRef<jobject> 105 const base::android::ScopedJavaLocalRef<jobject>
113 GetViewAndroidDelegate() const; 106 GetViewAndroidDelegate() const;
114 107
115 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child 108 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child
116 // should have |ViewRoot| for this ViewAndroid to have one. 109 // should have |ViewRoot| for this ViewAndroid to have one.
117 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot(); 110 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot();
118 111
119 bool HasViewRoot(); 112 ViewAndroid* parent_;
120
121 std::list<ViewAndroid*> children_;
122 scoped_refptr<cc::Layer> layer_; 113 scoped_refptr<cc::Layer> layer_;
123 JavaObjectWeakGlobalRef delegate_; 114 JavaObjectWeakGlobalRef delegate_;
124 JavaObjectWeakGlobalRef view_root_;
125 ViewClient* const client_; 115 ViewClient* const client_;
126 116
127 int physical_width_pix_; 117 int physical_width_pix_;
128 int physical_height_pix_; 118 int physical_height_pix_;
129 119
130 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 120 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
131 }; 121 };
132 122
133 bool RegisterViewRoot(JNIEnv* env);
134
135 } // namespace ui 123 } // namespace ui
136 124
137 #endif // UI_ANDROID_VIEW_ANDROID_H_ 125 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698