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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: EventHandler 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 MotionEventAndroid;
25 class ViewClient;
23 class WindowAndroid; 26 class WindowAndroid;
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 {
(...skipping 16 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
92 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 97 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
93 const base::android::JavaRef<jobject>& jimage); 98 const base::android::JavaRef<jobject>& jimage);
94 99
95 void OnBackgroundColorChanged(unsigned int color); 100 void OnBackgroundColorChanged(unsigned int color);
96 void OnTopControlsChanged(float top_controls_offset, 101 void OnTopControlsChanged(float top_controls_offset,
97 float top_content_offset); 102 float top_content_offset);
98 void OnBottomControlsChanged(float bottom_controls_offset, 103 void OnBottomControlsChanged(float bottom_controls_offset,
99 float bottom_content_offset); 104 float bottom_content_offset);
100 void StartContentIntent(const GURL& content_url, bool is_main_frame); 105 void StartContentIntent(const GURL& content_url, bool is_main_frame);
101 106
102 ScopedAnchorView AcquireAnchorView(); 107 ScopedAnchorView AcquireAnchorView();
103 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 108 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
104 const gfx::RectF& bounds); 109 const gfx::RectF& bounds);
105 110
106 // This may return null. 111 // This may return null.
107 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); 112 base::android::ScopedJavaLocalRef<jobject> GetContainerView();
108 113
114 bool OnTouchEvent(const MotionEventAndroid& event,
115 bool is_touch_handle_event);
116 bool OnMouseEvent(const MotionEventAndroid& event, int action_button);
117
118 // Virtual for testing.
119 virtual float GetDipScale();
120
109 protected: 121 protected:
110 ViewAndroid* parent_; 122 ViewAndroid* parent_;
111 123
112 private: 124 private:
113 void RemoveChild(ViewAndroid* child); 125 void RemoveChild(ViewAndroid* child);
114 126
127 bool has_event_handler() const { return !!event_handler_; }
128
129 static bool ViewTreeHasEventHandler(ViewAndroid* view);
130
115 // Returns the Java delegate for this view. This is used to delegate work 131 // 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 132 // up to the embedding view (or the embedder that can deal with the
117 // implementation details). 133 // implementation details).
118 const base::android::ScopedJavaLocalRef<jobject> 134 const base::android::ScopedJavaLocalRef<jobject>
119 GetViewAndroidDelegate() const; 135 GetViewAndroidDelegate() const;
120 136
121 std::list<ViewAndroid*> children_; 137 std::list<ViewAndroid*> children_;
122 scoped_refptr<cc::Layer> layer_; 138 scoped_refptr<cc::Layer> layer_;
123 JavaObjectWeakGlobalRef delegate_; 139 JavaObjectWeakGlobalRef delegate_;
124 gfx::Vector2dF content_offset_; // in CSS pixel 140
141 ViewClient* const client_;
142
143 gfx::Vector2dF content_offset_; // in CSS pixel.
144 std::unique_ptr<EventHandler> event_handler_;
145 float dip_scale_;
125 146
126 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 147 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
127 }; 148 };
128 149
129 } // namespace ui 150 } // namespace ui
130 151
131 #endif // UI_ANDROID_VIEW_ANDROID_H_ 152 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698