OLD | NEW |
---|---|
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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "ui/android/ui_android_export.h" | 13 #include "ui/android/ui_android_export.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 class Layer; | 17 class Layer; |
18 } | 18 } |
19 | 19 |
20 namespace ui { | 20 namespace ui { |
21 class DragEventAndroid; | |
21 class EventForwarder; | 22 class EventForwarder; |
22 class MotionEventAndroid; | 23 class MotionEventAndroid; |
23 class ViewClient; | 24 class ViewClient; |
24 class WindowAndroid; | 25 class WindowAndroid; |
25 | 26 |
26 // A simple container for a UI layer. | 27 // A simple container for a UI layer. |
27 // At the root of the hierarchy is a WindowAndroid, when attached. | 28 // At the root of the hierarchy is a WindowAndroid, when attached. |
28 // Dispatches input/view events coming from Java layer. Hit testing against | 29 // Dispatches input/view events coming from Java layer. Hit testing against |
29 // those events is implemented so that the |ViewClient| will be invoked | 30 // those events is implemented so that the |ViewClient| will be invoked |
30 // when the event got hit on the area defined by |layout_params_|. | 31 // when the event got hit on the area defined by |layout_params_|. |
(...skipping 25 matching lines...) Expand all Loading... | |
56 // TODO(jinsukkim): Following weak refs can be cast to strong refs which | 57 // TODO(jinsukkim): Following weak refs can be cast to strong refs which |
57 // cannot be garbage-collected and leak memory. Rewrite not to use them. | 58 // cannot be garbage-collected and leak memory. Rewrite not to use them. |
58 // see comments in crrev.com/2103243002. | 59 // see comments in crrev.com/2103243002. |
59 JavaObjectWeakGlobalRef view_; | 60 JavaObjectWeakGlobalRef view_; |
60 JavaObjectWeakGlobalRef delegate_; | 61 JavaObjectWeakGlobalRef delegate_; |
61 | 62 |
62 // Default copy/assign disabled by move constructor. | 63 // Default copy/assign disabled by move constructor. |
63 }; | 64 }; |
64 | 65 |
65 // Layout parameters used to set the view's position and size. | 66 // Layout parameters used to set the view's position and size. |
66 // Position is in parent's coordinate space. | 67 // Position is in parent's coordinate space, and all the values |
68 // are in CSS pixel. | |
67 struct LayoutParams { | 69 struct LayoutParams { |
68 static LayoutParams MatchParent() { return {true, 0, 0, 0, 0}; } | 70 static LayoutParams MatchParent() { return {true, 0, 0, 0, 0}; } |
69 static LayoutParams Normal(int x, int y, int width, int height) { | 71 static LayoutParams Normal(int x, int y, int width, int height) { |
70 return {false, x, y, width, height}; | 72 return {false, x, y, width, height}; |
71 }; | 73 }; |
72 | 74 |
75 bool HitBy(const gfx::Point& point) { | |
boliu
2017/05/24 22:54:02
this should not be part of the public interface
p
Jinsuk Kim
2017/05/25 03:18:19
Reverted (inlined it back).
| |
76 if (match_parent) | |
77 return true; | |
78 return gfx::Rect(x, y, width, height).Contains(point); | |
79 } | |
80 | |
73 bool match_parent; // Bounds matches that of the parent if true. | 81 bool match_parent; // Bounds matches that of the parent if true. |
74 int x; | 82 int x; |
75 int y; | 83 int y; |
76 int width; | 84 int width; |
77 int height; | 85 int height; |
78 | 86 |
79 LayoutParams(const LayoutParams& p) = default; | 87 LayoutParams(const LayoutParams& p) = default; |
80 | 88 |
81 private: | 89 private: |
82 LayoutParams(bool match_parent, int x, int y, int width, int height) | 90 LayoutParams(bool match_parent, int x, int y, int width, int height) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 152 |
145 ScopedAnchorView AcquireAnchorView(); | 153 ScopedAnchorView AcquireAnchorView(); |
146 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 154 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
147 const gfx::RectF& bounds); | 155 const gfx::RectF& bounds); |
148 | 156 |
149 // This may return null. | 157 // This may return null. |
150 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); | 158 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); |
151 | 159 |
152 float GetDipScale(); | 160 float GetDipScale(); |
153 | 161 |
162 bool HitBy(const gfx::Point& point); | |
boliu
2017/05/24 22:54:02
ditto does this need to be public?
Jinsuk Kim
2017/05/25 03:18:18
Mistake. changed to private.
| |
163 | |
154 protected: | 164 protected: |
155 ViewAndroid* parent_; | 165 ViewAndroid* parent_; |
156 | 166 |
157 private: | 167 private: |
158 friend class EventForwarder; | 168 friend class EventForwarder; |
159 friend class ViewAndroidBoundsTest; | 169 friend class ViewAndroidBoundsTest; |
160 | 170 |
161 using ViewClientCallback = | 171 bool OnDragEvent(const DragEventAndroid& event); |
162 const base::Callback<bool(ViewClient*, const MotionEventAndroid&)>; | |
163 | |
164 bool OnTouchEvent(const MotionEventAndroid& event, bool for_touch_handle); | 172 bool OnTouchEvent(const MotionEventAndroid& event, bool for_touch_handle); |
165 bool OnMouseEvent(const MotionEventAndroid& event); | 173 bool OnMouseEvent(const MotionEventAndroid& event); |
166 bool OnMouseWheelEvent(const MotionEventAndroid& event); | 174 bool OnMouseWheelEvent(const MotionEventAndroid& event); |
167 | 175 |
168 void RemoveChild(ViewAndroid* child); | 176 void RemoveChild(ViewAndroid* child); |
169 | 177 |
170 bool HitTest(ViewClientCallback send_to_client, | 178 template <typename E, typename T> |
171 const MotionEventAndroid& event); | 179 bool HitTest(T send_to_client, const E& event, const gfx::Point& point); |
172 | 180 |
181 static bool SendDragEventToClient(ViewClient* client, | |
182 const DragEventAndroid& event, | |
183 const gfx::Point& point); | |
173 static bool SendTouchEventToClient(bool for_touch_handle, | 184 static bool SendTouchEventToClient(bool for_touch_handle, |
174 ViewClient* client, | 185 ViewClient* client, |
175 const MotionEventAndroid& event); | 186 const MotionEventAndroid& event, |
187 const gfx::Point& point); | |
176 static bool SendMouseEventToClient(ViewClient* client, | 188 static bool SendMouseEventToClient(ViewClient* client, |
177 const MotionEventAndroid& event); | 189 const MotionEventAndroid& event, |
190 const gfx::Point& point); | |
178 static bool SendMouseWheelEventToClient(ViewClient* client, | 191 static bool SendMouseWheelEventToClient(ViewClient* client, |
179 const MotionEventAndroid& event); | 192 const MotionEventAndroid& event, |
193 const gfx::Point& point); | |
180 | 194 |
181 bool has_event_forwarder() const { return !!event_forwarder_; } | 195 bool has_event_forwarder() const { return !!event_forwarder_; } |
182 | 196 |
183 // Checks if there is any event forwarder in any node up to root. | 197 // Checks if there is any event forwarder in any node up to root. |
184 static bool RootPathHasEventForwarder(ViewAndroid* view); | 198 static bool RootPathHasEventForwarder(ViewAndroid* view); |
185 | 199 |
186 // Checks if there is any event forwarder in the node paths down to | 200 // Checks if there is any event forwarder in the node paths down to |
187 // each leaf of subtree. | 201 // each leaf of subtree. |
188 static bool SubtreeHasEventForwarder(ViewAndroid* view); | 202 static bool SubtreeHasEventForwarder(ViewAndroid* view); |
189 | 203 |
(...skipping 17 matching lines...) Expand all Loading... | |
207 | 221 |
208 gfx::Vector2dF content_offset_; // in CSS pixel. | 222 gfx::Vector2dF content_offset_; // in CSS pixel. |
209 std::unique_ptr<EventForwarder> event_forwarder_; | 223 std::unique_ptr<EventForwarder> event_forwarder_; |
210 | 224 |
211 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 225 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
212 }; | 226 }; |
213 | 227 |
214 } // namespace ui | 228 } // namespace ui |
215 | 229 |
216 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 230 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |