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

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

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

Powered by Google App Engine
This is Rietveld 408576698