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

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

Issue 2645353004: ViewRoot class for event forwarding on Android (Closed)
Patch Set: comments Created 3 years, 10 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/android/view_client.h"
13 #include "ui/gfx/geometry/rect_f.h" 14 #include "ui/gfx/geometry/rect_f.h"
14 15
15 namespace cc { 16 namespace cc {
16 class Layer; 17 class Layer;
17 } 18 }
18 19
19 namespace ui { 20 namespace ui {
20 21
21 class WindowAndroid; 22 class WindowAndroid;
22 23
23 // A simple container for a UI layer. 24 // A simple container for a UI layer.
24 // At the root of the hierarchy is a WindowAndroid, when attached. 25 // At the root of the hierarchy is a WindowAndroid, when attached.
26 // TODO(jinsukkim): Replace WindowAndroid with ViewRoot for the root of the
27 // view hierarchy. See https://crbug.com/671401
25 class UI_ANDROID_EXPORT ViewAndroid { 28 class UI_ANDROID_EXPORT ViewAndroid {
26 public: 29 public:
27 // Stores an anchored view to delete itself at the end of its lifetime 30 // Stores an anchored view to delete itself at the end of its lifetime
28 // automatically. This helps manage the lifecyle without the dependency 31 // automatically. This helps manage the lifecyle without the dependency
29 // on |ViewAndroid|. 32 // on |ViewAndroid|.
30 class ScopedAnchorView { 33 class ScopedAnchorView {
31 public: 34 public:
32 ScopedAnchorView(JNIEnv* env, 35 ScopedAnchorView(JNIEnv* env,
33 const base::android::JavaRef<jobject>& jview, 36 const base::android::JavaRef<jobject>& jview,
34 const base::android::JavaRef<jobject>& jdelegate); 37 const base::android::JavaRef<jobject>& jdelegate);
(...skipping 12 matching lines...) Expand all
47 private: 50 private:
48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which 51 // TODO(jinsukkim): Following weak refs can be cast to strong refs which
49 // cannot be garbage-collected and leak memory. Rewrite not to use them. 52 // cannot be garbage-collected and leak memory. Rewrite not to use them.
50 // see comments in crrev.com/2103243002. 53 // see comments in crrev.com/2103243002.
51 JavaObjectWeakGlobalRef view_; 54 JavaObjectWeakGlobalRef view_;
52 JavaObjectWeakGlobalRef delegate_; 55 JavaObjectWeakGlobalRef delegate_;
53 56
54 // Default copy/assign disabled by move constructor. 57 // Default copy/assign disabled by move constructor.
55 }; 58 };
56 59
57 // A ViewAndroid may have its own delegate or otherwise will 60 explicit ViewAndroid(ViewClient* client);
58 // use the next available parent's delegate.
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate);
60 61
61 ViewAndroid(); 62 ViewAndroid();
62 virtual ~ViewAndroid(); 63 virtual ~ViewAndroid();
63 64
64 // The content offset is in CSS pixels, and is used to translate 65 // The content offset is in CSS pixels, and is used to translate
65 // snapshots to the correct part of the view. 66 // snapshots to the correct part of the view.
66 void set_content_offset(const gfx::Vector2dF& content_offset) { 67 void set_content_offset(const gfx::Vector2dF& content_offset) {
67 content_offset_ = content_offset; 68 content_offset_ = content_offset;
68 } 69 }
69 70
70 gfx::Vector2dF content_offset() const { 71 gfx::Vector2dF content_offset() const {
71 return content_offset_; 72 return content_offset_;
72 } 73 }
73 74
74 // Returns the window at the root of this hierarchy, or |null| 75 // Returns the window at the root of this hierarchy, or |null|
75 // if disconnected. 76 // if disconnected.
76 virtual WindowAndroid* GetWindowAndroid() const; 77 virtual WindowAndroid* GetWindowAndroid() const;
77 78
79 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't
80 // attached to a |ViewRoot|.
81 virtual ViewAndroid* GetViewRoot();
82
78 // Used to return and set the layer for this view. May be |null|. 83 // Used to return and set the layer for this view. May be |null|.
79 cc::Layer* GetLayer() const; 84 cc::Layer* GetLayer() const;
80 void SetLayer(scoped_refptr<cc::Layer> layer); 85 void SetLayer(scoped_refptr<cc::Layer> layer);
81 86
82 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 87 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
83 88
84 // Adds this view as a child of another view. 89 // Adds a child to this view.
85 void AddChild(ViewAndroid* child); 90 void AddChild(ViewAndroid* child);
86 91
92 // Move the give child ViewAndroid to the top of the list
93 // so that it can be the first responder of events.
94 void MoveToTop(ViewAndroid* child);
95
87 // Detaches this view from its parent. 96 // Detaches this view from its parent.
88 void RemoveFromParent(); 97 void RemoveFromParent();
89 98
99 // Set the layout relative to parent. Used to do hit testing against events.
100 void SetLayout(int x, int y, int width, int height, bool match_parent);
101
90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 102 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
91 const base::android::JavaRef<jobject>& jimage); 103 const base::android::JavaRef<jobject>& jimage);
92 104
93 ScopedAnchorView AcquireAnchorView(); 105 ScopedAnchorView AcquireAnchorView();
94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 106 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
95 const gfx::RectF& bounds); 107 const gfx::RectF& bounds);
96 108
97 // This may return null. 109 // This may return null.
98 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); 110 base::android::ScopedJavaLocalRef<jobject> GetContainerView();
99 111
100 protected: 112 protected:
113 // Internal implementation of ViewClient forwarding calls to the interface.
114 bool OnTouchEventInternal(const MotionEventData& event);
115
116 // Virtual for testing.
117 virtual float GetDipScale();
118
101 ViewAndroid* parent_; 119 ViewAndroid* parent_;
102 120
103 private: 121 private:
122 // Returns true only if this is of type |ViewRoot|.
123 bool IsViewRoot();
124
104 void RemoveChild(ViewAndroid* child); 125 void RemoveChild(ViewAndroid* child);
105 126
106 // Returns the Java delegate for this view. This is used to delegate work 127 // Returns the Java delegate for this view. This is used to delegate work
107 // up to the embedding view (or the embedder that can deal with the 128 // up to the embedding view (or the embedder that can deal with the
108 // implementation details). 129 // implementation details).
109 const base::android::ScopedJavaLocalRef<jobject> 130 const base::android::ScopedJavaLocalRef<jobject>
110 GetViewAndroidDelegate() const; 131 GetViewAndroidDelegate() const;
111 132
133 // The child view at the front of the list receives event first.
112 std::list<ViewAndroid*> children_; 134 std::list<ViewAndroid*> children_;
113 scoped_refptr<cc::Layer> layer_; 135 scoped_refptr<cc::Layer> layer_;
114 JavaObjectWeakGlobalRef delegate_; 136 JavaObjectWeakGlobalRef delegate_;
137 ViewClient* const client_;
138
139 // Basic view layout information. Used to do hit testing deciding whether
140 // the passed events should be processed by the view.
141 gfx::Point origin_;
boliu 2017/02/06 18:29:26 add a comment that this is in parent's coordinate
Jinsuk Kim 2017/02/06 23:51:33 Done.
142 gfx::Size size_;
143 bool match_parent_; // bounds matches that of the parent if true.
144
115 gfx::Vector2dF content_offset_; // in CSS pixel 145 gfx::Vector2dF content_offset_; // in CSS pixel
116 146
117 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 147 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
118 }; 148 };
119 149
120 } // namespace ui 150 } // namespace ui
121 151
122 #endif // UI_ANDROID_VIEW_ANDROID_H_ 152 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698