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

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

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: updateViewRoot, ... 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 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't
68 // Create one if not present. 68 // attached to a |ViewRoot|.
69 base::android::ScopedJavaLocalRef<jobject> GetViewRoot(); 69 virtual ViewAndroid* GetViewRoot();
70
71 // Adds this view as a child of another view.
boliu 2017/01/05 19:09:29 just noticed this comment sounds backwards..
Jinsuk Kim 2017/01/05 22:30:15 Done.
72 void AddChild(ViewAndroid* child);
boliu 2017/01/05 19:09:29 nit: avoid rearranging method order
Jinsuk Kim 2017/01/05 22:30:15 Done.
70 73
71 // Used to return and set the layer for this view. May be |null|. 74 // Used to return and set the layer for this view. May be |null|.
72 cc::Layer* GetLayer() const; 75 cc::Layer* GetLayer() const;
73 void SetLayer(scoped_refptr<cc::Layer> layer); 76 void SetLayer(scoped_refptr<cc::Layer> layer);
74 77
75 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 78 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
76 79
77 // Adds this view as a child of another view.
78 void AddChild(ViewAndroid* child);
79
80 // Detaches this view from its parent. 80 // Detaches this view from its parent.
81 void RemoveFromParent(); 81 void RemoveFromParent();
82 82
83 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 83 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
84 const base::android::JavaRef<jobject>& jimage); 84 const base::android::JavaRef<jobject>& jimage);
85 85
86 ScopedAnchorView AcquireAnchorView(); 86 ScopedAnchorView AcquireAnchorView();
87 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 87 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
88 const gfx::RectF& bounds); 88 const gfx::RectF& bounds);
89 89
90 gfx::Size GetPhysicalBackingSize(); 90 gfx::Size GetPhysicalBackingSize();
91 void UpdateLayerBounds(); 91 void UpdateLayerBounds();
92 92
93 protected:
93 // Internal implementation of ViewClient forwarding calls to the interface. 94 // Internal implementation of ViewClient forwarding calls to the interface.
94 void OnPhysicalBackingSizeChanged(int width, int height); 95 void OnPhysicalBackingSizeChangedInternal(int width, int height);
95
96 protected:
97 ViewAndroid* parent_;
98 96
99 private: 97 private:
98 // Returns true only if this is of type |ViewRoot|.
99 bool IsViewRoot();
100
100 void RemoveChild(ViewAndroid* child); 101 void RemoveChild(ViewAndroid* child);
101 102
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 103 // 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 104 // up to the embedding view (or the embedder that can deal with the
111 // implementation details). 105 // implementation details).
112 const base::android::ScopedJavaLocalRef<jobject> 106 const base::android::ScopedJavaLocalRef<jobject>
113 GetViewAndroidDelegate() const; 107 GetViewAndroidDelegate() const;
114 108
115 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child 109 // Creates a new |ViewRoot| for this ViewAndroid. No parent or child
116 // should have |ViewRoot| for this ViewAndroid to have one. 110 // should have |ViewRoot| for this ViewAndroid to have one.
117 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot(); 111 base::android::ScopedJavaLocalRef<jobject> CreateViewRoot();
118 112
119 bool HasViewRoot(); 113 ViewAndroid* parent_;
120
121 std::list<ViewAndroid*> children_; 114 std::list<ViewAndroid*> children_;
122 scoped_refptr<cc::Layer> layer_; 115 scoped_refptr<cc::Layer> layer_;
123 JavaObjectWeakGlobalRef delegate_; 116 JavaObjectWeakGlobalRef delegate_;
124 JavaObjectWeakGlobalRef view_root_;
125 ViewClient* const client_; 117 ViewClient* const client_;
126 118
127 int physical_width_pix_; 119 int physical_width_pix_;
128 int physical_height_pix_; 120 int physical_height_pix_;
129 121
130 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 122 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
131 }; 123 };
132 124
133 bool RegisterViewRoot(JNIEnv* env);
134
135 } // namespace ui 125 } // namespace ui
136 126
137 #endif // UI_ANDROID_VIEW_ANDROID_H_ 127 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698