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/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 Loading... | |
| 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 { |
|
boliu
2017/01/17 16:17:28
there's gfx::Rect, don't need to create your own c
Jinsuk Kim
2017/01/17 23:32:48
Used it at first but switched to my own in order t
| |
| 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 = -1; | |
| 66 | |
| 67 void SetBounds(const gfx::Point& origin, int width, int height); | |
| 68 bool IsInBounds(const MotionEventAndroid& event); | |
| 69 | |
| 70 private: | |
| 71 gfx::Point origin_; | |
| 72 int width_; | |
| 73 int height_; | |
| 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 | |
| 78 // Used to return and set the layer for this view. May be |null|. | 99 // Used to return and set the layer for this view. May be |null|. |
| 79 cc::Layer* GetLayer() const; | 100 cc::Layer* GetLayer() const; |
| 80 void SetLayer(scoped_refptr<cc::Layer> layer); | 101 void SetLayer(scoped_refptr<cc::Layer> layer); |
| 81 | 102 |
| 82 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 103 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
| 83 | 104 |
| 84 // Adds this view as a child of another view. | 105 // Adds a child to this view. |
| 85 void AddChild(ViewAndroid* child); | 106 void AddChild(ViewAndroid* child); |
| 86 | 107 |
| 87 // Detaches this view from its parent. | 108 // Detaches this view from its parent. |
| 88 void RemoveFromParent(); | 109 void RemoveFromParent(); |
| 89 | 110 |
| 111 // Set the bounds used to do hit testing against motion events. | |
| 112 void SetBounds(const gfx::Point& origin, int width, int height); | |
| 113 | |
| 114 // Returns true if the event hits the area of this view defined by |bounds_|. | |
| 115 bool IsInBounds(const MotionEventAndroid& event); | |
| 116 | |
| 90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 117 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 91 const base::android::JavaRef<jobject>& jimage); | 118 const base::android::JavaRef<jobject>& jimage); |
| 92 | 119 |
| 93 ScopedAnchorView AcquireAnchorView(); | 120 ScopedAnchorView AcquireAnchorView(); |
| 94 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 121 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
| 95 const gfx::RectF& bounds); | 122 const gfx::RectF& bounds); |
| 96 | 123 |
| 97 protected: | 124 protected: |
| 98 ViewAndroid* parent_; | 125 // Internal implementation of ViewClient forwarding calls to the interface. |
| 126 bool OnTouchEventInternal(const MotionEventAndroid& event, | |
| 127 bool is_touch_handle_event); | |
| 128 | |
| 129 // The child view at the front of the list receives event first. | |
| 130 std::list<ViewAndroid*> children_; | |
| 99 | 131 |
| 100 private: | 132 private: |
| 133 // Returns true only if this is of type |ViewRoot|. | |
| 134 bool IsViewRoot(); | |
| 135 | |
| 101 void RemoveChild(ViewAndroid* child); | 136 void RemoveChild(ViewAndroid* child); |
| 102 | 137 |
| 103 // Returns the Java delegate for this view. This is used to delegate work | 138 // Returns the Java delegate for this view. This is used to delegate work |
| 104 // up to the embedding view (or the embedder that can deal with the | 139 // up to the embedding view (or the embedder that can deal with the |
| 105 // implementation details). | 140 // implementation details). |
| 106 const base::android::ScopedJavaLocalRef<jobject> | 141 const base::android::ScopedJavaLocalRef<jobject> |
| 107 GetViewAndroidDelegate() const; | 142 GetViewAndroidDelegate() const; |
| 108 | 143 |
| 109 std::list<ViewAndroid*> children_; | 144 ViewAndroid* parent_; |
| 110 scoped_refptr<cc::Layer> layer_; | 145 scoped_refptr<cc::Layer> layer_; |
| 111 JavaObjectWeakGlobalRef delegate_; | 146 JavaObjectWeakGlobalRef delegate_; |
| 147 ViewClient* const client_; | |
| 148 Bounds bounds_; | |
| 149 | |
| 112 gfx::Vector2dF content_offset_; // in CSS pixel | 150 gfx::Vector2dF content_offset_; // in CSS pixel |
| 113 | 151 |
| 114 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 152 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 115 }; | 153 }; |
| 116 | 154 |
| 117 } // namespace ui | 155 } // namespace ui |
| 118 | 156 |
| 119 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 157 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |