Chromium Code Reviews| Index: ui/android/view_android.h |
| diff --git a/ui/android/view_android.h b/ui/android/view_android.h |
| index 0abd77cdc40d55152a13aa423e46c79d90082f0c..9251c63dc80936bb830625604f9addb4001872f8 100644 |
| --- a/ui/android/view_android.h |
| +++ b/ui/android/view_android.h |
| @@ -20,6 +20,10 @@ class Layer; |
| namespace ui { |
| +class EventHandler; |
| +class EventSender; |
| +class MotionEventAndroid; |
| +class ViewClient; |
| class WindowAndroid; |
| // A simple container for a UI layer. |
| @@ -56,9 +60,16 @@ class UI_ANDROID_EXPORT ViewAndroid { |
| // Default copy/assign disabled by move constructor. |
| }; |
| - // A ViewAndroid may have its own delegate or otherwise will |
| - // use the next available parent's delegate. |
| - ViewAndroid(const base::android::JavaRef<jobject>& delegate); |
| + // Abstracts out the dispatcher for various types of events. Used for hit |
| + // testing logic. |
| + struct EventSender { |
| + virtual bool SendToView(ViewAndroid* view, |
| + const MotionEventAndroid& event) const = 0; |
| + virtual bool SendToClient(ViewClient* client, |
| + const MotionEventAndroid& event) const = 0; |
| + }; |
| + |
| + explicit ViewAndroid(ViewClient* view_client); |
| ViewAndroid(); |
| virtual ~ViewAndroid(); |
| @@ -83,12 +94,24 @@ class UI_ANDROID_EXPORT ViewAndroid { |
| void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
| - // Adds this view as a child of another view. |
| + // Gets (creates one if not present) Java object of the EventHandler |
| + // for a view tree in the view hierarchy including this node. |
| + // Only one instance per the view tree is allowed. |
| + base::android::ScopedJavaLocalRef<jobject> GetEventHandler(); |
| + |
| + // Adds a child to this view. |
| void AddChild(ViewAndroid* child); |
| + // Moves the give child ViewAndroid to the top of the list so that it can be |
| + // the first responder of events. |
| + void MoveToTop(ViewAndroid* child); |
| + |
| // Detaches this view from its parent. |
| void RemoveFromParent(); |
| + // Sets the layout relative to parent. Used to do hit testing against events. |
| + void SetLayout(int x, int y, int width, int height, bool match_parent); |
| + |
| bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| const base::android::JavaRef<jobject>& jimage); |
| @@ -106,12 +129,29 @@ class UI_ANDROID_EXPORT ViewAndroid { |
| // This may return null. |
| base::android::ScopedJavaLocalRef<jobject> GetContainerView(); |
| + bool OnTouchEvent(const MotionEventAndroid& event, bool for_touch_handle); |
|
boliu
2017/03/03 22:01:32
these are still public..? I think the original com
Jinsuk Kim
2017/03/06 04:07:34
Got the comments wrong. Done. Now ViewAndroid/Even
|
| + bool OnMouseEvent(const MotionEventAndroid& event); |
| + |
| + // Virtual for testing. |
| + virtual float GetDipScale(); |
| + |
| protected: |
| ViewAndroid* parent_; |
| private: |
| void RemoveChild(ViewAndroid* child); |
| + bool HitTest(const EventSender& es, const MotionEventAndroid& event); |
| + |
| + bool has_event_handler() const { return !!event_handler_; } |
| + |
| + // Returns true if any node of the tree along the hierarchy (view's children |
| + // and parents) already has |EventHandler| attached to it. |
| + static bool ViewTreeHasEventHandler(ViewAndroid* view); |
| + |
| + // Returns true if any children node (or self) has |EventHandler|. |
| + static bool ChildrenHaveEventHandler(ViewAndroid* view); |
| + |
| // Returns the Java delegate for this view. This is used to delegate work |
| // up to the embedding view (or the embedder that can deal with the |
| // implementation details). |
| @@ -121,7 +161,17 @@ class UI_ANDROID_EXPORT ViewAndroid { |
| std::list<ViewAndroid*> children_; |
| scoped_refptr<cc::Layer> layer_; |
| JavaObjectWeakGlobalRef delegate_; |
| - gfx::Vector2dF content_offset_; // in CSS pixel |
| + |
| + ViewClient* const client_; |
| + |
| + // Basic view layout information. Used to do hit testing deciding whether |
| + // the passed events should be processed by the view. |
| + gfx::Point origin_; // In parent's coordinate space. |
| + gfx::Size size_; |
| + bool match_parent_; // Bounds matches that of the parent if true. |
| + |
| + gfx::Vector2dF content_offset_; // in CSS pixel. |
| + std::unique_ptr<EventHandler> event_handler_; |
| DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| }; |