Chromium Code Reviews| 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/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 ViewClient; | |
| 23 class WindowAndroid; | 25 class WindowAndroid; |
| 26 struct MotionEventData; | |
| 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 { |
| 33 public: | 36 public: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 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(); | |
|
Khushal
2017/03/02 21:46:15
Why create a new instance each time? Shouldn't thi
| |
| 90 | |
| 91 // Adds a child to this view. | |
| 87 void AddChild(ViewAndroid* child); | 92 void AddChild(ViewAndroid* child); |
| 88 | 93 |
| 94 // Move the give child ViewAndroid to the top of the list so that it can be | |
| 95 // the first responder of events. | |
| 96 void MoveToTop(ViewAndroid* child); | |
| 97 | |
| 89 // Detaches this view from its parent. | 98 // Detaches this view from its parent. |
| 90 void RemoveFromParent(); | 99 void RemoveFromParent(); |
| 91 | 100 |
| 101 // Set the layout relative to parent. Used to do hit testing against events. | |
| 102 void SetLayout(int x, int y, int width, int height, bool match_parent); | |
| 103 | |
| 92 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 104 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 93 const base::android::JavaRef<jobject>& jimage); | 105 const base::android::JavaRef<jobject>& jimage); |
| 94 | 106 |
| 95 void OnBackgroundColorChanged(unsigned int color); | 107 void OnBackgroundColorChanged(unsigned int color); |
| 96 void OnTopControlsChanged(float top_controls_offset, | 108 void OnTopControlsChanged(float top_controls_offset, |
| 97 float top_content_offset); | 109 float top_content_offset); |
| 98 void OnBottomControlsChanged(float bottom_controls_offset, | 110 void OnBottomControlsChanged(float bottom_controls_offset, |
| 99 float bottom_content_offset); | 111 float bottom_content_offset); |
| 100 void StartContentIntent(const GURL& content_url, bool is_main_frame); | 112 void StartContentIntent(const GURL& content_url, bool is_main_frame); |
| 101 | 113 |
| 102 ScopedAnchorView AcquireAnchorView(); | 114 ScopedAnchorView AcquireAnchorView(); |
| 103 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 115 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
| 104 const gfx::RectF& bounds); | 116 const gfx::RectF& bounds); |
| 105 | 117 |
| 106 // This may return null. | 118 // This may return null. |
| 107 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); | 119 base::android::ScopedJavaLocalRef<jobject> GetContainerView(); |
| 108 | 120 |
| 121 bool OnTouchEvent(const MotionEventData& event); | |
| 122 bool OnMouseEvent(const MotionEventData& event); | |
| 123 | |
| 124 // Virtual for testing. | |
| 125 virtual float GetDipScale(); | |
| 126 | |
| 109 protected: | 127 protected: |
| 110 ViewAndroid* parent_; | 128 ViewAndroid* parent_; |
| 111 | 129 |
| 112 private: | 130 private: |
| 131 // Returns the root of this ViewAndroid hierarchy from which events starts | |
| 132 // trickling down. Note that it may not be the actual top of the tree. | |
| 133 ViewAndroid* GetViewRoot(); | |
| 134 | |
| 113 void RemoveChild(ViewAndroid* child); | 135 void RemoveChild(ViewAndroid* child); |
| 114 | 136 |
| 137 bool has_event_handler() const { return !!event_handler_; } | |
| 138 | |
| 139 static bool ViewTreeHasEventHandler(ViewAndroid* view); | |
| 140 | |
| 115 // Returns the Java delegate for this view. This is used to delegate work | 141 // 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 | 142 // up to the embedding view (or the embedder that can deal with the |
| 117 // implementation details). | 143 // implementation details). |
| 118 const base::android::ScopedJavaLocalRef<jobject> | 144 const base::android::ScopedJavaLocalRef<jobject> |
| 119 GetViewAndroidDelegate() const; | 145 GetViewAndroidDelegate() const; |
| 120 | 146 |
| 121 std::list<ViewAndroid*> children_; | 147 std::list<ViewAndroid*> children_; |
| 122 scoped_refptr<cc::Layer> layer_; | 148 scoped_refptr<cc::Layer> layer_; |
| 123 JavaObjectWeakGlobalRef delegate_; | 149 JavaObjectWeakGlobalRef delegate_; |
| 124 gfx::Vector2dF content_offset_; // in CSS pixel | 150 |
| 151 ViewClient* const client_; | |
| 152 | |
| 153 // Basic view layout information. Used to do hit testing deciding whether | |
| 154 // the passed events should be processed by the view. | |
| 155 gfx::Point origin_; // In parent's coordinate space. | |
| 156 gfx::Size size_; | |
| 157 bool match_parent_; // Bounds matches that of the parent if true. | |
| 158 | |
| 159 gfx::Vector2dF content_offset_; // in CSS pixel. | |
| 160 std::unique_ptr<EventHandler> event_handler_; | |
| 125 | 161 |
| 126 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 162 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 127 }; | 163 }; |
| 128 | 164 |
| 129 } // namespace ui | 165 } // namespace ui |
| 130 | 166 |
| 131 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 167 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |