Chromium Code Reviews| Index: services/ui/ws/event_dispatcher.cc |
| diff --git a/services/ui/ws/event_dispatcher.cc b/services/ui/ws/event_dispatcher.cc |
| index c6e6897508347096389172210d6d3e9b91594479..a3980963f85f29761ce3e01e86a9816fad9e49a8 100644 |
| --- a/services/ui/ws/event_dispatcher.cc |
| +++ b/services/ui/ws/event_dispatcher.cc |
| @@ -83,8 +83,7 @@ void EventDispatcher::SetMousePointerDisplayLocation( |
| const gfx::Point& display_location, |
| const int64_t display_id) { |
| DCHECK(pointer_targets_.empty()); |
| - mouse_pointer_last_location_ = display_location; |
| - mouse_pointer_display_id_ = display_id; |
| + UpdateMousePointerLocation(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 |
| @@ -224,30 +223,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_->FindDeepestVisibleWindowForEvents( |
| + 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_->FindDeepestVisibleWindowForEvents( |
| + mouse_pointer_last_location_, mouse_pointer_display_id_, |
| + base::BindOnce(&EventDispatcher:: |
| + UpdateCursorProviderByLastKnownLocationOnFoundWindow, |
| + base::Unretained(this))); |
| } |
| } |
| @@ -313,8 +303,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())); |
| } |
| void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { |
| @@ -328,6 +320,13 @@ void EventDispatcher::SetMouseCursorSourceWindow(ServerWindow* window) { |
| ObserveWindow(mouse_cursor_source_window_); |
| } |
| +void EventDispatcher::UpdateMousePointerLocation( |
| + const gfx::Point& new_mouse_location, |
| + const 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 = |
| @@ -354,15 +353,25 @@ 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_found, |
| + const DeepestWindow& deepest_window, |
| + const gfx::Point& location_in_display, |
| + const int64_t display_id) { |
| + event_targeter_->ProcessNextHittesetRequestFromQueue(); |
| + |
| + 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_); |
| + UpdateMousePointerLocation(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 |
| @@ -381,15 +390,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_found.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; |
| } |
| @@ -397,7 +406,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_found); |
| if (is_mouse_event) |
| SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window); |
| @@ -410,7 +420,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); |
| @@ -425,10 +436,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) { |
| + UpdateCursorProviderByLastKnownLocationWithWindow( |
| + 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) |
| @@ -440,6 +454,45 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { |
| } |
| } |
| +void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow( |
| + const DeepestWindow& deepest_window, |
| + const gfx::Point& location_in_display, |
| + const int64_t display_id) { |
| + event_targeter_->ProcessNextHittesetRequestFromQueue(); |
|
sky
2017/06/02 21:17:51
Because this code is now processed async, I think
sky
2017/06/02 21:17:51
Why does this code need to call back to event_targ
riajiang
2017/06/02 22:56:17
Yes! Done.
riajiang
2017/06/02 22:56:17
I was thinking ui::ws::FindDeepestVisibleWindowFor
|
| + |
| + 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; |
| + } |
| + UpdateMousePointerLocation(location_in_display, display_id); |
| + delegate_->UpdateNativeCursorFromDispatcher(); |
| +} |
| + |
| +void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow( |
| + const DeepestWindow& deepest_window, |
| + const gfx::Point& location_in_display, |
| + const int64_t display_id) { |
| + event_targeter_->ProcessNextHittesetRequestFromQueue(); |
| + UpdateCursorProviderByLastKnownLocationWithWindow( |
| + deepest_window, location_in_display, display_id); |
| +} |
| + |
| +void EventDispatcher::UpdateCursorProviderByLastKnownLocationWithWindow( |
|
sky
2017/06/02 21:17:51
It's not clear what 'WithWindow' means here. Maybe
riajiang
2017/06/02 22:56:17
Since event_targeter_->ProcessNextHittesetRequestF
|
| + const DeepestWindow& deepest_window, |
| + const gfx::Point& location_in_display, |
| + const int64_t display_id) { |
| + SetMouseCursorSourceWindow(deepest_window.window); |
|
sky
2017/06/02 21:17:51
Similar comment here about early out if mouse_butt
riajiang
2017/06/02 22:56:16
Done.
|
| + 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; |
| + } |
| + UpdateMousePointerLocation(location_in_display, display_id); |
| + delegate_->UpdateNativeCursorFromDispatcher(); |
| +} |
| + |
| void EventDispatcher::StartTrackingPointer( |
| int32_t pointer_id, |
| const PointerTarget& pointer_target) { |
| @@ -457,22 +510,21 @@ 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_found) { |
|
sky
2017/06/02 21:17:51
pointer_target_found -> pointer_target
riajiang
2017/06/02 22:56:16
Done.
|
| if (!IsTrackingPointer(pointer_id)) { |
| - StartTrackingPointer(pointer_id, event_targeter_->PointerTargetForEvent( |
| - event, &event_display_id_)); |
| + StartTrackingPointer(pointer_id, pointer_target_found); |
| 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 == |
| + if (pointer_target_found.window == pointer_targets_[pointer_id].window && |
| + pointer_target_found.in_nonclient_area == |
| pointer_targets_[pointer_id].in_nonclient_area) { |
| // The targets are the same, only set the down state to true if necessary. |
| // Down going to up is handled by ProcessLocatedEvent(). |
| - if (pointer_target.is_pointer_down) |
| + if (pointer_target_found.is_pointer_down) |
| pointer_targets_[pointer_id].is_pointer_down = true; |
| return; |
| } |
| @@ -491,7 +543,7 @@ void EventDispatcher::UpdateTargetForPointer(int32_t pointer_id, |
| // Technically we're updating in place, but calling start then stop makes for |
| // simpler code. |
| StopTrackingPointer(pointer_id); |
| - StartTrackingPointer(pointer_id, pointer_target); |
| + StartTrackingPointer(pointer_id, pointer_target_found); |
| } |
| bool EventDispatcher::AreAnyPointersDown() const { |