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

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

Issue 2702413004: Revert "ViewRoot class for event forwarding on Android" (Closed)
Patch Set: Created 3 years, 10 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/android/view_client.h"
14 #include "ui/gfx/geometry/rect_f.h" 13 #include "ui/gfx/geometry/rect_f.h"
15 14
16 namespace cc { 15 namespace cc {
17 class Layer; 16 class Layer;
18 } 17 }
19 18
20 namespace ui { 19 namespace ui {
21 20
22 class WindowAndroid; 21 class WindowAndroid;
23 22
24 // A simple container for a UI layer. 23 // A simple container for a UI layer.
25 // At the root of the hierarchy is a WindowAndroid, when attached. 24 // At the root of the hierarchy is a WindowAndroid, when attached.
26 // TODO(jinsukkim): Replace WindowAndroid with ViewRoot for the root of the
27 // view hierarchy. See https://crbug.com/671401
28 class UI_ANDROID_EXPORT ViewAndroid { 25 class UI_ANDROID_EXPORT ViewAndroid {
29 public: 26 public:
30 // Stores an anchored view to delete itself at the end of its lifetime 27 // Stores an anchored view to delete itself at the end of its lifetime
31 // automatically. This helps manage the lifecyle without the dependency 28 // automatically. This helps manage the lifecyle without the dependency
32 // on |ViewAndroid|. 29 // on |ViewAndroid|.
33 class ScopedAnchorView { 30 class ScopedAnchorView {
34 public: 31 public:
35 ScopedAnchorView(JNIEnv* env, 32 ScopedAnchorView(JNIEnv* env,
36 const base::android::JavaRef<jobject>& jview, 33 const base::android::JavaRef<jobject>& jview,
37 const base::android::JavaRef<jobject>& jdelegate); 34 const base::android::JavaRef<jobject>& jdelegate);
(...skipping 12 matching lines...) Expand all
50 private: 47 private:
51 // TODO(jinsukkim): Following weak refs can be cast to strong refs which 48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which
52 // cannot be garbage-collected and leak memory. Rewrite not to use them. 49 // cannot be garbage-collected and leak memory. Rewrite not to use them.
53 // see comments in crrev.com/2103243002. 50 // see comments in crrev.com/2103243002.
54 JavaObjectWeakGlobalRef view_; 51 JavaObjectWeakGlobalRef view_;
55 JavaObjectWeakGlobalRef delegate_; 52 JavaObjectWeakGlobalRef delegate_;
56 53
57 // Default copy/assign disabled by move constructor. 54 // Default copy/assign disabled by move constructor.
58 }; 55 };
59 56
60 explicit ViewAndroid(ViewClient* client); 57 // A ViewAndroid may have its own delegate or otherwise will
58 // use the next available parent's delegate.
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate);
61 60
62 ViewAndroid(); 61 ViewAndroid();
63 virtual ~ViewAndroid(); 62 virtual ~ViewAndroid();
64 63
65 // The content offset is in CSS pixels, and is used to translate 64 // The content offset is in CSS pixels, and is used to translate
66 // snapshots to the correct part of the view. 65 // snapshots to the correct part of the view.
67 void set_content_offset(const gfx::Vector2dF& content_offset) { 66 void set_content_offset(const gfx::Vector2dF& content_offset) {
68 content_offset_ = content_offset; 67 content_offset_ = content_offset;
69 } 68 }
70 69
71 gfx::Vector2dF content_offset() const { 70 gfx::Vector2dF content_offset() const {
72 return content_offset_; 71 return content_offset_;
73 } 72 }
74 73
75 // Returns the window at the root of this hierarchy, or |null| 74 // Returns the window at the root of this hierarchy, or |null|
76 // if disconnected. 75 // if disconnected.
77 virtual WindowAndroid* GetWindowAndroid() const; 76 virtual WindowAndroid* GetWindowAndroid() const;
78 77
79 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't
80 // attached to a |ViewRoot|.
81 virtual ViewAndroid* GetViewRoot();
82
83 // Used to return and set the layer for this view. May be |null|. 78 // Used to return and set the layer for this view. May be |null|.
84 cc::Layer* GetLayer() const; 79 cc::Layer* GetLayer() const;
85 void SetLayer(scoped_refptr<cc::Layer> layer); 80 void SetLayer(scoped_refptr<cc::Layer> layer);
86 81
87 void SetDelegate(const base::android::JavaRef<jobject>& delegate); 82 void SetDelegate(const base::android::JavaRef<jobject>& delegate);
88 83
89 // Adds a child to this view. 84 // Adds this view as a child of another view.
90 void AddChild(ViewAndroid* child); 85 void AddChild(ViewAndroid* child);
91 86
92 // Move the give child ViewAndroid to the top of the list
93 // so that it can be the first responder of events.
94 void MoveToTop(ViewAndroid* child);
95
96 // Detaches this view from its parent. 87 // Detaches this view from its parent.
97 void RemoveFromParent(); 88 void RemoveFromParent();
98 89
99 // Set the layout relative to parent. Used to do hit testing against events.
100 void SetLayout(int x, int y, int width, int height, bool match_parent);
101
102 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, 90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
103 const base::android::JavaRef<jobject>& jimage); 91 const base::android::JavaRef<jobject>& jimage);
104 92
105 ScopedAnchorView AcquireAnchorView(); 93 ScopedAnchorView AcquireAnchorView();
106 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, 94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
107 const gfx::RectF& bounds); 95 const gfx::RectF& bounds);
108 96
109 // This may return null. 97 // This may return null.
110 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); 98 base::android::ScopedJavaLocalRef<jobject> GetContainerView();
111 99
112 protected: 100 protected:
113 // Internal implementation of ViewClient forwarding calls to the interface.
114 bool OnTouchEventInternal(const MotionEventData& event);
115
116 // Virtual for testing.
117 virtual float GetDipScale();
118
119 ViewAndroid* parent_; 101 ViewAndroid* parent_;
120 102
121 private: 103 private:
122 // Returns true only if this is of type |ViewRoot|.
123 bool IsViewRoot();
124
125 void RemoveChild(ViewAndroid* child); 104 void RemoveChild(ViewAndroid* child);
126 105
127 // Returns the Java delegate for this view. This is used to delegate work 106 // Returns the Java delegate for this view. This is used to delegate work
128 // up to the embedding view (or the embedder that can deal with the 107 // up to the embedding view (or the embedder that can deal with the
129 // implementation details). 108 // implementation details).
130 const base::android::ScopedJavaLocalRef<jobject> 109 const base::android::ScopedJavaLocalRef<jobject>
131 GetViewAndroidDelegate() const; 110 GetViewAndroidDelegate() const;
132 111
133 // The child view at the back of the list receives event first.
134 std::list<ViewAndroid*> children_; 112 std::list<ViewAndroid*> children_;
135 scoped_refptr<cc::Layer> layer_; 113 scoped_refptr<cc::Layer> layer_;
136 JavaObjectWeakGlobalRef delegate_; 114 JavaObjectWeakGlobalRef delegate_;
137 ViewClient* const client_; 115 gfx::Vector2dF content_offset_; // in CSS pixel
138
139 // Basic view layout information. Used to do hit testing deciding whether
140 // the passed events should be processed by the view.
141 gfx::Point origin_; // In parent's coordinate space.
142 gfx::Size size_;
143 bool match_parent_; // Bounds matches that of the parent if true.
144
145 gfx::Vector2dF content_offset_; // In CSS pixel.
146 116
147 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); 117 DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
148 }; 118 };
149 119
150 } // namespace ui 120 } // namespace ui
151 121
152 #endif // UI_ANDROID_VIEW_ANDROID_H_ 122 #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