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

Unified Diff: services/ui/ws/event_targeter.h

Issue 2884463002: Make event-targeting asynchronous in window server. (Closed)
Patch Set: rebase and use EventTargeter Created 3 years, 7 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: services/ui/ws/event_targeter.h
diff --git a/services/ui/ws/event_targeter.h b/services/ui/ws/event_targeter.h
index a59aba2b5b3d3e6c5b5ceb26167a3de0109e2421..8724c7305ac4c4481920dad7954170cbea692f0f 100644
--- a/services/ui/ws/event_targeter.h
+++ b/services/ui/ws/event_targeter.h
@@ -6,15 +6,15 @@
#define SERVICES_UI_WS_EVENT_TARGETER_H_
#include <stdint.h>
+#include <queue>
+#include "base/callback.h"
#include "base/macros.h"
-
-namespace gfx {
-class Point;
-}
+#include "base/memory/weak_ptr.h"
+#include "ui/gfx/geometry/point.h"
namespace ui {
-class LocatedEvent;
+class PointerEvent;
namespace ws {
struct DeepestWindow;
@@ -43,6 +43,9 @@ struct PointerTarget {
bool is_pointer_down;
};
+using PointerTargetForEventCallback = base::OnceCallback<void(PointerTarget)>;
+using HitTestCallback = base::OnceCallback<void(DeepestWindow)>;
+
// Finds the PointerTarget for an event or the DeepestWindow for a location.
class EventTargeter {
public:
@@ -50,21 +53,64 @@ class EventTargeter {
ModalWindowController* modal_window_controller);
~EventTargeter();
- // Returns a PointerTarget for the supplied |event|. If there is no valid
- // event target for the specified location |window| in the returned value is
- // null.
- PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event,
- int64_t* display_id);
+ // |callback| is called with a PointerTarget for the supplied |event|. If
+ // there is no valid event target for the specified location |window| in the
+ // returned value is null.
+ void PointerTargetForEvent(const ui::PointerEvent& event,
+ int64_t* display_id,
+ PointerTargetForEventCallback callback);
+
+ // Calls WindowFinder to find the deepest visible window for |location|.
+ // |callback| is called with the window found.
+ void FindDeepestVisibleWindowForEvents(gfx::Point* location,
+ int64_t* display_id,
+ HitTestCallback callback);
+
+ void ProcessNextHittesetRequestFromQueue();
- // Returns a DeepestWindow for the supplied |location|. If there is no valid
- // root window, |window| in the returned value is null.
- DeepestWindow FindDeepestVisibleWindowForEvents(gfx::Point* location,
- int64_t* display_id);
+ bool IsHitTestInFlight() const;
private:
+ struct HitTestRequest {
+ HitTestRequest(gfx::Point* location,
sky 2017/05/30 17:26:02 I'm nervous about keeping pointers to members from
riajiang 2017/05/31 22:44:03 Makes sense, changed to by value and return the up
+ int64_t* display_id,
+ HitTestCallback hittest_callback);
+ ~HitTestRequest();
+
+ gfx::Point* hittest_location;
+ int64_t* hittest_display_id;
+ HitTestCallback hittest_callback;
+ };
+
+ void PointerTargetForEventOnFoundWindow(const ui::PointerEvent& event,
+ DeepestWindow deepest_window);
+
+ void FindDeepestVisibleWindowForEventsImpl(gfx::Point* location,
+ int64_t* display_id);
+
+ void FindDeepestVisibleWindowForEventsAsync(gfx::Point* location,
+ int64_t* display_id);
+
EventDispatcherDelegate* event_dispatcher_delegate_;
ModalWindowController* modal_window_controller_;
+ PointerTargetForEventCallback target_callback_;
+
+ std::unique_ptr<gfx::Point> current_hittest_location_;
+ HitTestCallback hittest_callback_;
+
+ // True if we are waiting for the result of a hit-test. False otherwise.
+ bool hittest_in_flight_;
+
+ // Request would go into this queue if it's coming from EventDispatcher::
+ // UpdateNonClientAreaForCurrentWindow() or EventDispatcher::
+ // UpdateCursorProviderByLastKnownLocation(). If it's an event that needs
+ // targeting, it would only go to WindowManagerState::event_queue_ when it's
+ // waiting for an active hit-test.
+ std::queue<std::unique_ptr<HitTestRequest>> hittest_request_queue_;
+
+ base::WeakPtrFactory<EventTargeter> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(EventTargeter);
};

Powered by Google App Engine
This is Rietveld 408576698