OLD | NEW |
---|---|
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. | |
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 Loading... | |
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 // Basic view layout information. Used to decide whether the passed events |
58 // use the next available parent's delegate. | 61 // should be processed by the view. |
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | 62 class Bounds { |
63 public: | |
64 // Used for |width_ | or |height_| to indicate that the bounds is matched | |
65 // with that of its parent. | |
66 static const int kMatchParent = 0x7FFFFFFF; | |
boliu
2017/01/24 23:47:12
there is no need to use special values here, just
Jinsuk Kim
2017/01/25 02:34:34
Done.
| |
67 | |
68 void SetBounds(const gfx::Point& origin, int width, int height); | |
69 bool IsInBounds(const MotionEventData& event); | |
70 gfx::Point origin() const { return rect_.origin(); } | |
71 | |
72 private: | |
73 gfx::Rect rect_; | |
74 }; | |
75 | |
76 explicit ViewAndroid(ViewClient* client); | |
60 | 77 |
61 ViewAndroid(); | 78 ViewAndroid(); |
62 virtual ~ViewAndroid(); | 79 virtual ~ViewAndroid(); |
63 | 80 |
64 // The content offset is in CSS pixels, and is used to translate | 81 // The content offset is in CSS pixels, and is used to translate |
65 // snapshots to the correct part of the view. | 82 // snapshots to the correct part of the view. |
66 void set_content_offset(const gfx::Vector2dF& content_offset) { | 83 void set_content_offset(const gfx::Vector2dF& content_offset) { |
67 content_offset_ = content_offset; | 84 content_offset_ = content_offset; |
68 } | 85 } |
69 | 86 |
70 gfx::Vector2dF content_offset() const { | 87 gfx::Vector2dF content_offset() const { |
71 return content_offset_; | 88 return content_offset_; |
72 } | 89 } |
73 | 90 |
74 // Returns the window at the root of this hierarchy, or |null| | 91 // Returns the window at the root of this hierarchy, or |null| |
75 // if disconnected. | 92 // if disconnected. |
76 virtual WindowAndroid* GetWindowAndroid() const; | 93 virtual WindowAndroid* GetWindowAndroid() const; |
77 | 94 |
95 // Returns |ViewRoot| of this hierarchy. |null| if the hierarchy isn't | |
96 // attached to a |ViewRoot|. | |
97 virtual ViewAndroid* GetViewRoot(); | |
98 | |
99 virtual float GetDipScale(); | |
boliu
2017/01/24 23:47:12
protected, and add a comment that says it's virtua
Jinsuk Kim
2017/01/25 02:34:33
Done.
| |
100 | |
78 // Used to return and set the layer for this view. May be |null|. | 101 // Used to return and set the layer for this view. May be |null|. |
79 cc::Layer* GetLayer() const; | 102 cc::Layer* GetLayer() const; |
80 void SetLayer(scoped_refptr<cc::Layer> layer); | 103 void SetLayer(scoped_refptr<cc::Layer> layer); |
81 | 104 |
82 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 105 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
83 | 106 |
84 // Adds this view as a child of another view. | 107 // Adds a child to this view. |
85 void AddChild(ViewAndroid* child); | 108 void AddChild(ViewAndroid* child); |
86 | 109 |
87 // Detaches this view from its parent. | 110 // Detaches this view from its parent. |
88 void RemoveFromParent(); | 111 void RemoveFromParent(); |
89 | 112 |
113 // Set the bounds used to do hit testing against motion events. | |
boliu
2017/01/24 23:47:12
relative to parent?
Jinsuk Kim
2017/01/25 02:34:34
Done.
| |
114 void SetBounds(const gfx::Point& origin, int width, int height); | |
boliu
2017/01/24 23:47:13
or just take a rect?
Jinsuk Kim
2017/01/25 02:34:33
Changed to get a rect and a bool.
| |
115 | |
116 // Returns true if the event hits the area of this view defined by |bounds_|. | |
117 bool IsInBounds(const MotionEventData& event); | |
boliu
2017/01/24 23:47:12
does this need to be public?
Jinsuk Kim
2017/01/25 02:34:33
No... made it private ( and then removed)
| |
118 | |
90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 119 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
91 const base::android::JavaRef<jobject>& jimage); | 120 const base::android::JavaRef<jobject>& jimage); |
92 | 121 |
93 ScopedAnchorView AcquireAnchorView(); | 122 ScopedAnchorView AcquireAnchorView(); |
94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 123 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
95 const gfx::RectF& bounds); | 124 const gfx::RectF& bounds); |
96 | 125 |
97 // This may return null. | 126 // This may return null. |
98 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); | 127 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); |
99 | 128 |
100 protected: | 129 protected: |
130 // Internal implementation of ViewClient forwarding calls to the interface. | |
131 bool OnTouchEventInternal(const MotionEventData& event); | |
132 | |
133 // The child view at the front of the list receives event first. | |
134 std::list<ViewAndroid*> children_; | |
135 | |
101 ViewAndroid* parent_; | 136 ViewAndroid* parent_; |
102 | 137 |
103 private: | 138 private: |
139 // Returns true only if this is of type |ViewRoot|. | |
140 bool IsViewRoot(); | |
141 | |
104 void RemoveChild(ViewAndroid* child); | 142 void RemoveChild(ViewAndroid* child); |
105 | 143 |
106 // Returns the Java delegate for this view. This is used to delegate work | 144 // 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 | 145 // up to the embedding view (or the embedder that can deal with the |
108 // implementation details). | 146 // implementation details). |
109 const base::android::ScopedJavaLocalRef<jobject> | 147 const base::android::ScopedJavaLocalRef<jobject> |
110 GetViewAndroidDelegate() const; | 148 GetViewAndroidDelegate() const; |
111 | 149 |
112 std::list<ViewAndroid*> children_; | |
113 scoped_refptr<cc::Layer> layer_; | 150 scoped_refptr<cc::Layer> layer_; |
boliu
2017/01/24 23:47:12
eventually constructing the layer tree probably sh
Jinsuk Kim
2017/01/25 02:34:33
Layer tree makes use of physical backing size for
| |
114 JavaObjectWeakGlobalRef delegate_; | 151 JavaObjectWeakGlobalRef delegate_; |
152 ViewClient* const client_; | |
153 Bounds bounds_; | |
154 | |
115 gfx::Vector2dF content_offset_; // in CSS pixel | 155 gfx::Vector2dF content_offset_; // in CSS pixel |
116 | 156 |
117 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 157 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
118 }; | 158 }; |
119 | 159 |
120 } // namespace ui | 160 } // namespace ui |
121 | 161 |
122 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 162 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |