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

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

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

Powered by Google App Engine
This is Rietveld 408576698