| Index: services/ui/ws/event_dispatcher.cc
|
| diff --git a/services/ui/ws/event_dispatcher.cc b/services/ui/ws/event_dispatcher.cc
|
| index 56342211ce61b49ae3213181842baedea51d6cfa..d87aa2e3d7006a04f0c2086df8e10196255defe2 100644
|
| --- a/services/ui/ws/event_dispatcher.cc
|
| +++ b/services/ui/ws/event_dispatcher.cc
|
| @@ -80,10 +80,9 @@ void EventDispatcher::Reset() {
|
|
|
| void EventDispatcher::SetMousePointerDisplayLocation(
|
| const gfx::Point& display_location,
|
| - const int64_t display_id) {
|
| + int64_t display_id) {
|
| DCHECK(pointer_targets_.empty());
|
| - mouse_pointer_last_location_ = display_location;
|
| - mouse_pointer_display_id_ = display_id;
|
| + SetMousePointerLocation(display_location, display_id);
|
| UpdateCursorProviderByLastKnownLocation();
|
| // Write our initial location back to our shared screen coordinate. This
|
| // shouldn't cause problems because we already read the cursor before we
|
| @@ -223,30 +222,21 @@ const ServerWindow* EventDispatcher::GetWindowForMouseCursor() const {
|
|
|
| void EventDispatcher::UpdateNonClientAreaForCurrentWindow() {
|
| if (mouse_cursor_source_window_) {
|
| - DeepestWindow deepest_window =
|
| - event_targeter_->FindDeepestVisibleWindowForEvents(
|
| - &mouse_pointer_last_location_, &mouse_pointer_display_id_);
|
| - if (deepest_window.window == mouse_cursor_source_window_) {
|
| - mouse_cursor_in_non_client_area_ = mouse_cursor_source_window_
|
| - ? deepest_window.in_non_client_area
|
| - : false;
|
| - }
|
| + event_targeter_->FindDeepestVisibleWindowForLocation(
|
| + mouse_pointer_last_location_, mouse_pointer_display_id_,
|
| + base::BindOnce(
|
| + &EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow,
|
| + base::Unretained(this)));
|
| }
|
| }
|
|
|
| void EventDispatcher::UpdateCursorProviderByLastKnownLocation() {
|
| if (!mouse_button_down_) {
|
| - DeepestWindow deepest_window =
|
| - event_targeter_->FindDeepestVisibleWindowForEvents(
|
| - &mouse_pointer_last_location_, &mouse_pointer_display_id_);
|
| - SetMouseCursorSourceWindow(deepest_window.window);
|
| - if (mouse_cursor_source_window_) {
|
| - mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area;
|
| - } else {
|
| - SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(
|
| - &mouse_pointer_last_location_, &mouse_pointer_display_id_));
|
| - mouse_cursor_in_non_client_area_ = true;
|
| - }
|
| + event_targeter_->FindDeepestVisibleWindowForLocation(
|
| + mouse_pointer_last_location_, mouse_pointer_display_id_,
|
| + base::BindOnce(&EventDispatcher::
|
| + UpdateCursorProviderByLastKnownLocationOnFoundWindow,
|
| + base::Unretained(this)));
|
| }
|
| }
|
|
|
| @@ -279,7 +269,7 @@ void EventDispatcher::RemoveAccelerator(uint32_t id) {
|
| }
|
|
|
| void EventDispatcher::ProcessEvent(const ui::Event& event,
|
| - const int64_t display_id,
|
| + int64_t display_id,
|
| AcceleratorMatchPhase match_phase) {
|
| #if !defined(NDEBUG)
|
| if (match_phase == AcceleratorMatchPhase::POST_ONLY) {
|
| @@ -312,8 +302,10 @@ void EventDispatcher::ProcessEvent(const ui::Event& event,
|
| }
|
|
|
| DCHECK(event.IsPointerEvent());
|
| - ProcessPointerEvent(*event.AsPointerEvent());
|
| - return;
|
| + event_targeter_->PointerTargetForEvent(
|
| + *event.AsPointerEvent(), event_display_id_,
|
| + base::BindOnce(&EventDispatcher::ProcessPointerEventOnFoundTarget,
|
| + base::Unretained(this), *event.AsPointerEvent()));
|
| }
|
|
|
| ServerWindow* EventDispatcher::GetRootWindowContaining(
|
| @@ -322,6 +314,10 @@ ServerWindow* EventDispatcher::GetRootWindowContaining(
|
| return delegate_->GetRootWindowContaining(location_in_display, display_id);
|
| }
|
|
|
| +void EventDispatcher::ProcessNextEventFromQueue() {
|
| + delegate_->ProcessNextEventFromQueue();
|
| +}
|
| +
|
| void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) {
|
| if (mouse_cursor_source_window_ == window)
|
| return;
|
| @@ -333,6 +329,13 @@ void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) {
|
| ObserveWindow(mouse_cursor_source_window_);
|
| }
|
|
|
| +void EventDispatcher::SetMousePointerLocation(
|
| + const gfx::Point& new_mouse_location,
|
| + int64_t new_mouse_display_id) {
|
| + mouse_pointer_last_location_ = new_mouse_location;
|
| + mouse_pointer_display_id_ = new_mouse_display_id;
|
| +}
|
| +
|
| void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
|
| AcceleratorMatchPhase match_phase) {
|
| Accelerator* post_target =
|
| @@ -359,15 +362,23 @@ void EventDispatcher::ProcessKeyEvent(const ui::KeyEvent& event,
|
| EventDispatcherDelegate::AcceleratorPhase::POST);
|
| }
|
|
|
| -void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| - DCHECK(event.IsPointerEvent());
|
| +void EventDispatcher::ProcessPointerEventOnFoundTarget(
|
| + const ui::PointerEvent& event,
|
| + const PointerTarget& pointer_target,
|
| + const DeepestWindow& deepest_window,
|
| + const gfx::Point& location_in_display,
|
| + int64_t display_id) {
|
| + std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event);
|
| + if (display_id != event_display_id_) {
|
| + event_display_id_ = display_id;
|
| + cloned_event->AsLocatedEvent()->set_root_location(location_in_display);
|
| + }
|
| +
|
| const bool is_mouse_event = event.IsMousePointerEvent();
|
|
|
| if (is_mouse_event) {
|
| - mouse_pointer_last_location_ = event.root_location();
|
| - mouse_pointer_display_id_ = event_display_id_;
|
| - delegate_->OnMouseCursorLocationChanged(event.root_location(),
|
| - event_display_id_);
|
| + SetMousePointerLocation(location_in_display, display_id);
|
| + delegate_->OnMouseCursorLocationChanged(location_in_display, display_id);
|
| }
|
|
|
| // Release capture on pointer up. For mouse we only release if there are
|
| @@ -386,15 +397,15 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| }
|
|
|
| if (drag_controller_) {
|
| - const PointerTarget target =
|
| - event_targeter_->PointerTargetForEvent(event, &event_display_id_);
|
| - if (drag_controller_->DispatchPointerEvent(event, target.window))
|
| + if (drag_controller_->DispatchPointerEvent(*cloned_event->AsPointerEvent(),
|
| + pointer_target.window))
|
| return;
|
| }
|
|
|
| if (capture_window_) {
|
| SetMouseCursorSourceWindow(capture_window_);
|
| - DispatchToClient(capture_window_, capture_window_client_id_, event);
|
| + DispatchToClient(capture_window_, capture_window_client_id_,
|
| + *cloned_event->AsPointerEvent());
|
| return;
|
| }
|
|
|
| @@ -402,7 +413,8 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| if (!IsTrackingPointer(pointer_id) ||
|
| !pointer_targets_[pointer_id].is_pointer_down) {
|
| const bool any_pointers_down = AreAnyPointersDown();
|
| - UpdateTargetForPointer(pointer_id, event);
|
| + UpdateTargetForPointer(pointer_id, *cloned_event->AsPointerEvent(),
|
| + pointer_target);
|
| if (is_mouse_event)
|
| SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window);
|
|
|
| @@ -415,7 +427,8 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| delegate_->SetFocusedWindowFromEventDispatcher(pointer_target.window);
|
| ServerWindow* capture_window = pointer_target.window;
|
| if (!capture_window) {
|
| - gfx::Point event_location = event.root_location();
|
| + gfx::Point event_location =
|
| + cloned_event->AsPointerEvent()->root_location();
|
| int64_t event_display_id = event_display_id_;
|
| capture_window = delegate_->GetRootWindowContaining(
|
| &event_location, &event_display_id);
|
| @@ -430,10 +443,13 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| // up event to the window that had implicit capture. We have to set this
|
| // before we perform dispatch because the Delegate is going to read this
|
| // information from us.
|
| - if (is_pointer_going_up && is_mouse_event)
|
| - UpdateCursorProviderByLastKnownLocation();
|
| + if (is_pointer_going_up && is_mouse_event) {
|
| + UpdateCursorProviderByLastKnownLocationOnFoundWindow(
|
| + deepest_window, location_in_display, display_id);
|
| + }
|
|
|
| - DispatchToPointerTarget(pointer_targets_[pointer_id], event);
|
| + DispatchToPointerTarget(pointer_targets_[pointer_id],
|
| + *cloned_event->AsPointerEvent());
|
|
|
| if (is_pointer_going_up) {
|
| if (is_mouse_event)
|
| @@ -445,6 +461,40 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) {
|
| }
|
| }
|
|
|
| +void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow(
|
| + const DeepestWindow& deepest_window,
|
| + const gfx::Point& location_in_display,
|
| + int64_t display_id) {
|
| + if (!mouse_cursor_source_window_)
|
| + return;
|
| +
|
| + if (deepest_window.window == mouse_cursor_source_window_) {
|
| + mouse_cursor_in_non_client_area_ =
|
| + mouse_cursor_source_window_ ? deepest_window.in_non_client_area : false;
|
| + }
|
| + SetMousePointerLocation(location_in_display, display_id);
|
| + delegate_->UpdateNativeCursorFromDispatcher();
|
| +}
|
| +
|
| +void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow(
|
| + const DeepestWindow& deepest_window,
|
| + const gfx::Point& location_in_display,
|
| + int64_t display_id) {
|
| + if (mouse_button_down_)
|
| + return;
|
| +
|
| + SetMouseCursorSourceWindow(deepest_window.window);
|
| + if (mouse_cursor_source_window_) {
|
| + mouse_cursor_in_non_client_area_ = deepest_window.in_non_client_area;
|
| + } else {
|
| + SetMouseCursorSourceWindow(delegate_->GetRootWindowContaining(
|
| + &mouse_pointer_last_location_, &mouse_pointer_display_id_));
|
| + mouse_cursor_in_non_client_area_ = true;
|
| + }
|
| + SetMousePointerLocation(location_in_display, display_id);
|
| + delegate_->UpdateNativeCursorFromDispatcher();
|
| +}
|
| +
|
| void EventDispatcher::StartTrackingPointer(
|
| int32_t pointer_id,
|
| const PointerTarget& pointer_target) {
|
| @@ -462,16 +512,15 @@ void EventDispatcher::StopTrackingPointer(int32_t pointer_id) {
|
| UnobserveWindow(window);
|
| }
|
|
|
| -void EventDispatcher::UpdateTargetForPointer(int32_t pointer_id,
|
| - const ui::LocatedEvent& event) {
|
| +void EventDispatcher::UpdateTargetForPointer(
|
| + int32_t pointer_id,
|
| + const ui::PointerEvent& event,
|
| + const PointerTarget& pointer_target) {
|
| if (!IsTrackingPointer(pointer_id)) {
|
| - StartTrackingPointer(pointer_id, event_targeter_->PointerTargetForEvent(
|
| - event, &event_display_id_));
|
| + StartTrackingPointer(pointer_id, pointer_target);
|
| return;
|
| }
|
|
|
| - const PointerTarget pointer_target =
|
| - event_targeter_->PointerTargetForEvent(event, &event_display_id_);
|
| if (pointer_target.window == pointer_targets_[pointer_id].window &&
|
| pointer_target.in_nonclient_area ==
|
| pointer_targets_[pointer_id].in_nonclient_area) {
|
|
|