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

Unified Diff: ui/android/view_android.h

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: base::Bind (doesn't compile yet) Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: ui/android/view_android.h
diff --git a/ui/android/view_android.h b/ui/android/view_android.h
index 0abd77cdc40d55152a13aa423e46c79d90082f0c..e3dd4d449d43d855c34663a82b70f6615c06ae30 100644
--- a/ui/android/view_android.h
+++ b/ui/android/view_android.h
@@ -8,7 +8,9 @@
#include <list>
#include "base/android/jni_weak_ref.h"
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
+#include "ui/android/event_handler.h"
#include "ui/android/ui_android_export.h"
#include "ui/gfx/geometry/rect_f.h"
@@ -20,6 +22,9 @@ class Layer;
namespace ui {
+class EventSender;
+class MotionEventAndroid;
+class ViewClient;
class WindowAndroid;
// A simple container for a UI layer.
@@ -56,9 +61,40 @@ 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;
+ };
+
+ // Layout parameters used to set the view's position and size.
+ class LayoutParams {
+ public:
+ static LayoutParams MatchParent() { return {true, 0, 0, 0, 0}; }
boliu 2017/03/06 22:27:45 curious.. did clang not complain about inlining th
Jinsuk Kim 2017/03/07 05:02:24 No it didn't...
+ static LayoutParams Normal(int x, int y, int width, int height) {
+ return {false, x, y, width, height};
+ };
+
+ private:
+ friend class ViewAndroid;
+ LayoutParams(bool match_parent, int x, int y, int width, int height)
+ : match_parent(match_parent),
+ x(x),
+ y(y),
+ width(width),
+ height(height) {}
+
+ const bool match_parent;
boliu 2017/03/06 22:27:45 "_" suffix, or you can keep members public and mak
Jinsuk Kim 2017/03/07 05:02:24 Done.
+ const int x;
+ const int y;
+ const int width;
+ const int height;
+ };
+
+ explicit ViewAndroid(ViewClient* view_client);
ViewAndroid();
virtual ~ViewAndroid();
@@ -83,12 +119,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 front of the list so that it can be
+ // the first responder of events.
+ void MoveToFront(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(LayoutParams params);
Khushal 2017/03/07 04:17:08 Not for this patch but wanted to ask if this is in
Jinsuk Kim 2017/03/07 05:02:24 Ah yes - for now it is not necessary to do that si
Khushal 2017/03/07 06:32:05 Actually propagating them would be required precis
Jinsuk Kim 2017/03/08 02:16:16 Sorry I meant say 'child VA (RWHVA) is always set
+
bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
const base::android::JavaRef<jobject>& jimage);
@@ -106,12 +154,40 @@ class UI_ANDROID_EXPORT ViewAndroid {
// This may return null.
base::android::ScopedJavaLocalRef<jobject> GetContainerView();
+ // Virtual for testing.
+ virtual float GetDipScale();
+
protected:
ViewAndroid* parent_;
private:
+ friend class EventHandler;
+ friend class EventSendler;
+
+ bool OnTouchEvent(const MotionEventAndroid& event, bool for_touch_handle);
+ bool OnMouseEvent(const MotionEventAndroid& event);
+
void RemoveChild(ViewAndroid* child);
+ bool HitTest(
+ const base::Callback<bool(ViewClient*, const MotionEventAndroid&)>
+ send_to_client,
+ const base::Callback<bool(ViewAndroid*, const MotionEventAndroid&)>
+ send_to_view,
+ const MotionEventAndroid& event);
+
+ static bool SendToClient(ViewClient* client, const MotionEventAndroid& event);
+ static bool SendToView(ViewAndroid* view, 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 SubtreeHasEventHandler(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 +197,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.
boliu 2017/03/06 22:27:45 move comments here to LayoutParams maybe consider
Jinsuk Kim 2017/03/07 05:02:24 Done. Add copy ctor to |LayoutParams| for this (us
+ 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);
};

Powered by Google App Engine
This is Rietveld 408576698