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

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

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: unittest Created 3 years, 11 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
« no previous file with comments | « ui/android/ui_android_jni_registrar.cc ('k') | ui/android/view_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/events/android/motion_event_android.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
22 class ViewClient;
21 class WindowAndroid; 23 class WindowAndroid;
22 24
23 // A simple container for a UI layer. 25 // A simple container for a UI layer.
24 // At the root of the hierarchy is a WindowAndroid, when attached. 26 // At the root of the hierarchy is a ViewRoot, a subclass of ViewAndroid.
25 class UI_ANDROID_EXPORT ViewAndroid { 27 class UI_ANDROID_EXPORT ViewAndroid {
26 public: 28 public:
27 // Stores an anchored view to delete itself at the end of its lifetime 29 // Stores an anchored view to delete itself at the end of its lifetime
28 // automatically. This helps manage the lifecyle without the dependency 30 // automatically. This helps manage the lifecyle without the dependency
29 // on |ViewAndroid|. 31 // on |ViewAndroid|.
30 class ScopedAnchorView { 32 class ScopedAnchorView {
31 public: 33 public:
32 ScopedAnchorView(JNIEnv* env, 34 ScopedAnchorView(JNIEnv* env,
33 const base::android::JavaRef<jobject>& jview, 35 const base::android::JavaRef<jobject>& jview,
34 const base::android::JavaRef<jobject>& jdelegate); 36 const base::android::JavaRef<jobject>& jdelegate);
(...skipping 12 matching lines...) Expand all
47 private: 49 private:
48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which 50 // 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. 51 // cannot be garbage-collected and leak memory. Rewrite not to use them.
50 // see comments in crrev.com/2103243002. 52 // see comments in crrev.com/2103243002.
51 JavaObjectWeakGlobalRef view_; 53 JavaObjectWeakGlobalRef view_;
52 JavaObjectWeakGlobalRef delegate_; 54 JavaObjectWeakGlobalRef delegate_;
53 55
54 // Default copy/assign disabled by move constructor. 56 // Default copy/assign disabled by move constructor.
55 }; 57 };
56 58
57 // A ViewAndroid may have its own delegate or otherwise will 59 // Basic view bounds information. Used to decide whether the passed events
58 // use the next available parent's delegate. 60 // should be processed by the view.
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); 61 class Bounds {
62 public:
63 // Used for |width_ | or |height_| to indicate that the bounds is matched
64 // with that of its parent.
65 static const int kMatchParent = 0x7FFFFFFF;
66
67 void SetBounds(const gfx::Point& origin, int width, int height);
68 bool IsInBounds(const MotionEventAndroid& event);
69 std::string ToString() const {
70 return rect_.ToString();
71 }
72
73 private:
74 gfx::Rect rect_;
75 };
76
77 explicit ViewAndroid(ViewClient* client);
60 78
61 ViewAndroid(); 79 ViewAndroid();
62 virtual ~ViewAndroid(); 80 virtual ~ViewAndroid();
63 81
64 // The content offset is in CSS pixels, and is used to translate 82 // The content offset is in CSS pixels, and is used to translate
65 // snapshots to the correct part of the view. 83 // snapshots to the correct part of the view.
66 void set_content_offset(const gfx::Vector2dF& content_offset) { 84 void set_content_offset(const gfx::Vector2dF& content_offset) {
67 content_offset_ = content_offset; 85 content_offset_ = content_offset;
68 } 86 }
69 87
70 gfx::Vector2dF content_offset() const { 88 gfx::Vector2dF content_offset() const {
71 return content_offset_; 89 return content_offset_;
72 } 90 }
73 91
74 // Returns the window at the root of this hierarchy, or |null| 92 // Returns the window at the root of this hierarchy, or |null|
75 // if disconnected. 93 // if disconnected.
76 virtual WindowAndroid* GetWindowAndroid() const; 94 virtual WindowAndroid* GetWindowAndroid() const;
77 95
96 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't
97 // attached to a |ViewRoot|.
98 virtual ViewAndroid* GetViewRoot();
99
78 // Used to return and set the layer for this view. May be |null|. 100 // Used to return and set the layer for this view. May be |null|.
79 cc::Layer* GetLayer() const; 101 cc::Layer* GetLayer() const;
80 void SetLayer(scoped_refptr<cc::Layer> layer); 102 void SetLayer(scoped_refptr<cc::Layer> layer);
81 103
82 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 104 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
83 105
84 // Adds this view as a child of another view. 106 // Adds a child to this view.
85 void AddChild(ViewAndroid* child); 107 void AddChild(ViewAndroid* child);
86 108
87 // Detaches this view from its parent. 109 // Detaches this view from its parent.
88 void RemoveFromParent(); 110 void RemoveFromParent();
89 111
112 // Set the bounds used to do hit testing against motion events.
113 void SetBounds(const gfx::Point& origin, int width, int height);
114
115 // Returns true if the event hits the area of this view defined by |bounds_|.
116 bool IsInBounds(const MotionEventAndroid& event);
117
90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 118 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
91 const base::android::JavaRef<jobject>& jimage); 119 const base::android::JavaRef<jobject>& jimage);
92 120
93 ScopedAnchorView AcquireAnchorView(); 121 ScopedAnchorView AcquireAnchorView();
94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 122 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
95 const gfx::RectF& bounds); 123 const gfx::RectF& bounds);
96 124
97 // This may return null. 125 // This may return null.
98 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); 126 base::android::ScopedJavaLocalRef<jobject> GetContainerView();
99 127
100 protected: 128 protected:
101 ViewAndroid* parent_; 129 // Internal implementation of ViewClient forwarding calls to the interface.
130 bool OnTouchEventInternal(const MotionEventAndroid& event,
131 bool is_touch_handle_event);
132
133 // The child view at the front of the list receives event first.
134 std::list<ViewAndroid*> children_;
102 135
103 private: 136 private:
137 // Returns true only if this is of type |ViewRoot|.
138 bool IsViewRoot();
139
104 void RemoveChild(ViewAndroid* child); 140 void RemoveChild(ViewAndroid* child);
105 141
106 // Returns the Java delegate for this view. This is used to delegate work 142 // 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 143 // up to the embedding view (or the embedder that can deal with the
108 // implementation details). 144 // implementation details).
109 const base::android::ScopedJavaLocalRef<jobject> 145 const base::android::ScopedJavaLocalRef<jobject>
110 GetViewAndroidDelegate() const; 146 GetViewAndroidDelegate() const;
111 147
112 std::list<ViewAndroid*> children_; 148 ViewAndroid* parent_;
113 scoped_refptr<cc::Layer> layer_; 149 scoped_refptr<cc::Layer> layer_;
114 JavaObjectWeakGlobalRef delegate_; 150 JavaObjectWeakGlobalRef delegate_;
151 ViewClient* const client_;
152 Bounds bounds_;
153
115 gfx::Vector2dF content_offset_; // in CSS pixel 154 gfx::Vector2dF content_offset_; // in CSS pixel
116 155
117 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 156 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
118 }; 157 };
119 158
120 } // namespace ui 159 } // namespace ui
121 160
122 #endif // UI_ANDROID_VIEW_ANDROID_H_ 161 #endif // UI_ANDROID_VIEW_ANDROID_H_
OLDNEW
« no previous file with comments | « ui/android/ui_android_jni_registrar.cc ('k') | ui/android/view_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698