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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: removed MotionEventData Created 3 years, 9 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 class GURL; 15 class GURL;
16 16
17 namespace cc { 17 namespace cc {
18 class Layer; 18 class Layer;
19 } 19 }
20 20
21 namespace ui { 21 namespace ui {
22 22
23 class EventHandler;
24 class EventSender;
25 class MotionEventAndroid;
26 class ViewClient;
23 class WindowAndroid; 27 class WindowAndroid;
24 28
25 // A simple container for a UI layer. 29 // A simple container for a UI layer.
26 // At the root of the hierarchy is a WindowAndroid, when attached. 30 // At the root of the hierarchy is a WindowAndroid, when attached.
27 class UI_ANDROID_EXPORT ViewAndroid { 31 class UI_ANDROID_EXPORT ViewAndroid {
28 public: 32 public:
29 // Stores an anchored view to delete itself at the end of its lifetime 33 // Stores an anchored view to delete itself at the end of its lifetime
30 // automatically. This helps manage the lifecyle without the dependency 34 // automatically. This helps manage the lifecyle without the dependency
31 // on |ViewAndroid|. 35 // on |ViewAndroid|.
32 class ScopedAnchorView { 36 class ScopedAnchorView {
(...skipping 16 matching lines...) Expand all
49 private: 53 private:
50 // TODO(jinsukkim): Following weak refs can be cast to strong refs which 54 // TODO(jinsukkim): Following weak refs can be cast to strong refs which
51 // cannot be garbage-collected and leak memory. Rewrite not to use them. 55 // cannot be garbage-collected and leak memory. Rewrite not to use them.
52 // see comments in crrev.com/2103243002. 56 // see comments in crrev.com/2103243002.
53 JavaObjectWeakGlobalRef view_; 57 JavaObjectWeakGlobalRef view_;
54 JavaObjectWeakGlobalRef delegate_; 58 JavaObjectWeakGlobalRef delegate_;
55 59
56 // Default copy/assign disabled by move constructor. 60 // Default copy/assign disabled by move constructor.
57 }; 61 };
58 62
59 // A ViewAndroid may have its own delegate or otherwise will 63 // Abstracts out the dispatcher for various types of events. Used for hit
60 // use the next available parent's delegate. 64 // testing logic.
61 ViewAndroid(const base::android::JavaRef<jobject>& delegate); 65 struct EventSender {
66 virtual bool SendToView(ViewAndroid* view,
67 const MotionEventAndroid& event) const = 0;
68 virtual bool SendToClient(ViewClient* client,
69 const MotionEventAndroid& event) const = 0;
70 };
71
72 explicit ViewAndroid(ViewClient* view_client);
62 73
63 ViewAndroid(); 74 ViewAndroid();
64 virtual ~ViewAndroid(); 75 virtual ~ViewAndroid();
65 76
66 // The content offset is in CSS pixels, and is used to translate 77 // The content offset is in CSS pixels, and is used to translate
67 // snapshots to the correct part of the view. 78 // snapshots to the correct part of the view.
68 void set_content_offset(const gfx::Vector2dF& content_offset) { 79 void set_content_offset(const gfx::Vector2dF& content_offset) {
69 content_offset_ = content_offset; 80 content_offset_ = content_offset;
70 } 81 }
71 82
72 gfx::Vector2dF content_offset() const { 83 gfx::Vector2dF content_offset() const {
73 return content_offset_; 84 return content_offset_;
74 } 85 }
75 86
76 // Returns the window at the root of this hierarchy, or |null| 87 // Returns the window at the root of this hierarchy, or |null|
77 // if disconnected. 88 // if disconnected.
78 virtual WindowAndroid* GetWindowAndroid() const; 89 virtual WindowAndroid* GetWindowAndroid() const;
79 90
80 // Used to return and set the layer for this view. May be |null|. 91 // Used to return and set the layer for this view. May be |null|.
81 cc::Layer* GetLayer() const; 92 cc::Layer* GetLayer() const;
82 void SetLayer(scoped_refptr<cc::Layer> layer); 93 void SetLayer(scoped_refptr<cc::Layer> layer);
83 94
84 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 95 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
85 96
86 // Adds this view as a child of another view. 97 // Gets (creates one if not present) Java object of the EventHandler
98 // for a view tree in the view hierarchy including this node.
99 // Only one instance per the view tree is allowed.
100 base::android::ScopedJavaLocalRef<jobject> GetEventHandler();
101
102 // Adds a child to this view.
87 void AddChild(ViewAndroid* child); 103 void AddChild(ViewAndroid* child);
88 104
105 // Moves the give child ViewAndroid to the top of the list so that it can be
106 // the first responder of events.
107 void MoveToTop(ViewAndroid* child);
108
89 // Detaches this view from its parent. 109 // Detaches this view from its parent.
90 void RemoveFromParent(); 110 void RemoveFromParent();
91 111
112 // Sets the layout relative to parent. Used to do hit testing against events.
113 void SetLayout(int x, int y, int width, int height, bool match_parent);
114
92 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 115 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
93 const base::android::JavaRef<jobject>& jimage); 116 const base::android::JavaRef<jobject>& jimage);
94 117
95 void OnBackgroundColorChanged(unsigned int color); 118 void OnBackgroundColorChanged(unsigned int color);
96 void OnTopControlsChanged(float top_controls_offset, 119 void OnTopControlsChanged(float top_controls_offset,
97 float top_content_offset); 120 float top_content_offset);
98 void OnBottomControlsChanged(float bottom_controls_offset, 121 void OnBottomControlsChanged(float bottom_controls_offset,
99 float bottom_content_offset); 122 float bottom_content_offset);
100 void StartContentIntent(const GURL& content_url, bool is_main_frame); 123 void StartContentIntent(const GURL& content_url, bool is_main_frame);
101 124
102 ScopedAnchorView AcquireAnchorView(); 125 ScopedAnchorView AcquireAnchorView();
103 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 126 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
104 const gfx::RectF& bounds); 127 const gfx::RectF& bounds);
105 128
106 // This may return null. 129 // This may return null.
107 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); 130 base::android::ScopedJavaLocalRef<jobject> GetContainerView();
108 131
132 bool OnTouchEvent(const MotionEventAndroid& event, bool for_touch_handle);
boliu 2017/03/03 22:01:32 these are still public..? I think the original com
Jinsuk Kim 2017/03/06 04:07:34 Got the comments wrong. Done. Now ViewAndroid/Even
133 bool OnMouseEvent(const MotionEventAndroid& event);
134
135 // Virtual for testing.
136 virtual float GetDipScale();
137
109 protected: 138 protected:
110 ViewAndroid* parent_; 139 ViewAndroid* parent_;
111 140
112 private: 141 private:
113 void RemoveChild(ViewAndroid* child); 142 void RemoveChild(ViewAndroid* child);
114 143
144 bool HitTest(const EventSender& es, const MotionEventAndroid& event);
145
146 bool has_event_handler() const { return !!event_handler_; }
147
148 // Returns true if any node of the tree along the hierarchy (view's children
149 // and parents) already has |EventHandler| attached to it.
150 static bool ViewTreeHasEventHandler(ViewAndroid* view);
151
152 // Returns true if any children node (or self) has |EventHandler|.
153 static bool ChildrenHaveEventHandler(ViewAndroid* view);
154
115 // Returns the Java delegate for this view. This is used to delegate work 155 // Returns the Java delegate for this view. This is used to delegate work
116 // up to the embedding view (or the embedder that can deal with the 156 // up to the embedding view (or the embedder that can deal with the
117 // implementation details). 157 // implementation details).
118 const base::android::ScopedJavaLocalRef<jobject> 158 const base::android::ScopedJavaLocalRef<jobject>
119 GetViewAndroidDelegate() const; 159 GetViewAndroidDelegate() const;
120 160
121 std::list<ViewAndroid*> children_; 161 std::list<ViewAndroid*> children_;
122 scoped_refptr<cc::Layer> layer_; 162 scoped_refptr<cc::Layer> layer_;
123 JavaObjectWeakGlobalRef delegate_; 163 JavaObjectWeakGlobalRef delegate_;
124 gfx::Vector2dF content_offset_; // in CSS pixel 164
165 ViewClient* const client_;
166
167 // Basic view layout information. Used to do hit testing deciding whether
168 // the passed events should be processed by the view.
169 gfx::Point origin_; // In parent's coordinate space.
170 gfx::Size size_;
171 bool match_parent_; // Bounds matches that of the parent if true.
172
173 gfx::Vector2dF content_offset_; // in CSS pixel.
174 std::unique_ptr<EventHandler> event_handler_;
125 175
126 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 176 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
127 }; 177 };
128 178
129 } // namespace ui 179 } // namespace ui
130 180
131 #endif // UI_ANDROID_VIEW_ANDROID_H_ 181 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698