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

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

Issue 2884463002: Make event-targeting asynchronous in window server. (Closed)
Patch Set: WeakPtrFactory; const &; etc 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
« no previous file with comments | « no previous file | services/ui/ws/event_dispatcher.cc » ('j') | services/ui/ws/window_manager_state.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/ws/event_dispatcher.h
diff --git a/services/ui/ws/event_dispatcher.h b/services/ui/ws/event_dispatcher.h
index 8b084d7994f697a555d078ac1023b4dc5336f825..88a28032dd6a7f328d6c3d0066c10bdf6e4b544d 100644
--- a/services/ui/ws/event_dispatcher.h
+++ b/services/ui/ws/event_dispatcher.h
@@ -12,6 +12,7 @@
#include <utility>
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "services/ui/common/types.h"
#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
@@ -122,13 +123,14 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
// If the mouse cursor is still over |mouse_cursor_source_window_|, updates
// whether we are in the non-client area. Used when
- // |mouse_cursor_source_window_| has changed its properties.
- void UpdateNonClientAreaForCurrentWindow();
+ // |mouse_cursor_source_window_| has changed its properties. |callback| is
+ // called after the update is finished.
+ void UpdateNonClientAreaForCurrentWindow(const base::Closure& callback);
sky 2017/05/15 21:20:23 Having any of these functions take callbacks makes
riajiang 2017/05/17 02:01:59 Makes sense! With erg@'s CL https://codereview.chr
// Possibly updates the cursor. If we aren't in an implicit capture, we take
// the last known location of the mouse pointer, and look for the
- // ServerWindow* under it.
- void UpdateCursorProviderByLastKnownLocation();
+ // ServerWindow* under it. |callback| is called after the update is finished.
+ void UpdateCursorProviderByLastKnownLocation(const base::Closure& callback);
// Adds an accelerator with the given id and event-matcher. If an accelerator
// already exists with the same id or the same matcher, then the accelerator
@@ -144,6 +146,8 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
// handled this is again called with an AcceleratorMatchPhase of POST_ONLY.
void ProcessEvent(const ui::Event& event, AcceleratorMatchPhase match_phase);
+ bool HittestInFlight();
sky 2017/05/15 21:20:23 IsHitTestInFlight() and const. Also, use HitTest e
riajiang 2017/05/17 02:01:59 Done.
+
private:
friend class test::EventDispatcherTestApi;
@@ -168,6 +172,18 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
bool is_pointer_down;
};
+ using PointerTargetForEventCallback = base::OnceCallback<void(PointerTarget)>;
+ using HittestCallback = base::OnceCallback<void(DeepestWindow)>;
+
+ struct HittestRequest {
+ HittestRequest(const gfx::Point& location,
+ HittestCallback hittest_callback);
+ ~HittestRequest();
+
+ gfx::Point hittest_location;
+ HittestCallback hittest_callback;
+ };
+
void SetMouseCursorSourceWindow(ServerWindow* window);
void ProcessKeyEvent(const ui::KeyEvent& event,
@@ -187,6 +203,8 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
// This also generates exit events as appropriate. For example, if the mouse
// moves between one window to another an exit is generated on the first.
void ProcessPointerEvent(const ui::PointerEvent& event);
+ void ProcessPointerEventOnFoundTarget(const ui::PointerEvent& event,
+ PointerTarget pointer_target_found);
// Adds |pointer_target| to |pointer_targets_|.
void StartTrackingPointer(int32_t pointer_id,
@@ -199,12 +217,18 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
// pointer sends the appropriate event to the delegate and updates the
// currently tracked PointerTarget appropriately.
void UpdateTargetForPointer(int32_t pointer_id,
- const ui::LocatedEvent& event);
-
- // 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);
+ const ui::PointerEvent& event,
+ const PointerTarget& pointer_target_found);
+
+ // |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,
+ PointerTargetForEventCallback callback);
+ void PointerTargetForEventOnFoundWindow(
+ const ui::PointerEvent& event,
+ PointerTargetForEventCallback callback,
+ DeepestWindow deepest_window);
// Returns true if any pointers are in the pressed/down state.
bool AreAnyPointersDown() const;
@@ -234,7 +258,23 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
Accelerator* FindAccelerator(const ui::KeyEvent& event,
const ui::mojom::AcceleratorPhase phase);
- DeepestWindow FindDeepestVisibleWindowForEvents(const gfx::Point& location);
+ // Call WindowFinder to find the deepest visible window for |location|.
+ // |callback| is called with the window found.
+ void FindDeepestVisibleWindowForEvents(const gfx::Point& location,
+ HittestCallback callback);
+ void FindDeepestVisibleWindowForEventsImpl(const gfx::Point& location,
+ HittestCallback callback);
+ void FindDeepestVisibleWindowForEventsAsync(const gfx::Point& location,
+ HittestCallback callback);
+
+ void UpdateNonClientAreaForCurrentWindowOnFoundWindow(
+ const base::Closure& callback,
+ DeepestWindow deepest_window);
+ void UpdateCursorProviderByLastKnownLocationOnFoundWindow(
+ const base::Closure& callback,
+ DeepestWindow deepest_window);
+
+ void ProcessNextHittesetRequestFromQueue();
// Clears the implicit captures in |pointer_targets_|, with the exception of
// |window|. |window| may be null. |client_id| is the target client of
@@ -271,6 +311,10 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_;
+ // True if we are waiting for the result of a hit-test. False otherwise.
+ bool hittest_in_flight_;
+ std::queue<std::unique_ptr<HittestRequest>> hittest_request_queue_;
+
using PointerIdToTargetMap = std::map<int32_t, PointerTarget>;
// |pointer_targets_| contains the active pointers. For a mouse based pointer
// a PointerTarget is always active (and present in |pointer_targets_|). For
@@ -287,6 +331,8 @@ class EventDispatcher : public ServerWindowObserver, public DragCursorUpdater {
AcceleratorMatchPhase::ANY;
#endif
+ base::WeakPtrFactory<EventDispatcher> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
};
« no previous file with comments | « no previous file | services/ui/ws/event_dispatcher.cc » ('j') | services/ui/ws/window_manager_state.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698