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 8be65049bb4e1bfab45fad7d2c50210667c347bc..b057c8bd6da5c4e52f88c27e0cb707a717c0f60c 100644 |
| --- a/services/ui/ws/event_dispatcher.cc |
| +++ b/services/ui/ws/event_dispatcher.cc |
| @@ -79,7 +79,7 @@ void EventDispatcher::Reset() { |
| void EventDispatcher::SetMousePointerDisplayLocation( |
| const gfx::Point& display_location, |
| - const int64_t display_id) { |
| + int64_t display_id) { |
| DCHECK(pointer_targets_.empty()); |
| SetMousePointerLocation(display_location, display_id); |
| UpdateCursorProviderByLastKnownLocation(); |
| @@ -221,34 +221,21 @@ const ServerWindow* EventDispatcher::GetWindowForMouseCursor() const { |
| void EventDispatcher::UpdateNonClientAreaForCurrentWindow() { |
| if (mouse_cursor_source_window_) { |
| - LocationTarget location_target = event_targeter_->FindTargetForLocation( |
| - mouse_pointer_last_location_, mouse_pointer_display_id_); |
| - if (location_target.deepest_window.window == mouse_cursor_source_window_) { |
| - mouse_cursor_in_non_client_area_ = |
| - mouse_cursor_source_window_ |
| - ? location_target.deepest_window.in_non_client_area |
| - : false; |
| - } |
| - SetMousePointerLocation(location_target.location_in_root, |
| - location_target.display_id); |
| + event_targeter_->FindTargetForLocation( |
| + mouse_pointer_last_location_, mouse_pointer_display_id_, |
| + base::BindOnce( |
| + &EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow, |
| + base::Unretained(this))); |
|
sadrul
2017/06/07 20:16:04
I guess using base::Unretained here (and below) is
riajiang
2017/06/07 21:46:25
Yes so |this| still exists when the callback is ru
|
| } |
| } |
| void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
| if (!mouse_button_down_) { |
| - LocationTarget location_target = event_targeter_->FindTargetForLocation( |
| - mouse_pointer_last_location_, mouse_pointer_display_id_); |
| - SetMouseCursorSourceWindow(location_target.deepest_window.window); |
| - if (mouse_cursor_source_window_) { |
| - mouse_cursor_in_non_client_area_ = |
| - location_target.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_target.location_in_root, |
| - location_target.display_id); |
| + event_targeter_->FindTargetForLocation( |
| + mouse_pointer_last_location_, mouse_pointer_display_id_, |
| + base::BindOnce(&EventDispatcher:: |
| + UpdateCursorProviderByLastKnownLocationOnFoundWindow, |
| + base::Unretained(this))); |
| } |
| } |
| @@ -280,8 +267,12 @@ void EventDispatcher::RemoveAccelerator(uint32_t id) { |
| accelerators_.erase(it); |
| } |
| +bool EventDispatcher::IsProcessingEvent() { |
| + return event_targeter_->IsHitTestInFlight(); |
| +} |
| + |
| 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) { |
| @@ -314,8 +305,10 @@ void EventDispatcher::ProcessEvent(const ui::Event& event, |
| } |
| DCHECK(event.IsPointerEvent()); |
| - ProcessPointerEvent(*event.AsPointerEvent()); |
| - return; |
| + event_targeter_->FindTargetForLocation( |
| + event.AsPointerEvent()->root_location(), event_display_id_, |
| + base::BindOnce(&EventDispatcher::ProcessPointerEventOnFoundTarget, |
| + base::Unretained(this), *event.AsPointerEvent())); |
| } |
| ServerWindow* EventDispatcher::GetRootWindowContaining( |
| @@ -324,6 +317,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; |
| @@ -368,12 +365,10 @@ 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 LocationTarget& location_target) { |
| PointerTarget pointer_target; |
| - LocationTarget location_target = event_targeter_->FindTargetForLocation( |
| - event.root_location(), event_display_id_); |
| pointer_target.window = modal_window_controller_.GetTargetForWindow( |
| location_target.deepest_window.window); |
| pointer_target.is_mouse_event = event.IsMousePointerEvent(); |
| @@ -462,7 +457,7 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { |
| // before we perform dispatch because the Delegate is going to read this |
| // information from us. |
| if (is_pointer_going_up && is_mouse_event) |
| - UpdateCursorProviderByLastKnownLocation(); |
| + UpdateCursorProviderByLastKnownLocationOnFoundWindow(location_target); |
| DispatchToPointerTarget(pointer_targets_[pointer_id], |
| *cloned_event->AsPointerEvent()); |
| @@ -477,6 +472,41 @@ void EventDispatcher::ProcessPointerEvent(const ui::PointerEvent& event) { |
| } |
| } |
| +void EventDispatcher::UpdateNonClientAreaForCurrentWindowOnFoundWindow( |
| + const LocationTarget& location_target) { |
| + if (!mouse_cursor_source_window_) |
| + return; |
| + |
| + if (location_target.deepest_window.window == mouse_cursor_source_window_) { |
| + mouse_cursor_in_non_client_area_ = |
| + mouse_cursor_source_window_ |
| + ? location_target.deepest_window.in_non_client_area |
| + : false; |
| + } |
| + SetMousePointerLocation(location_target.location_in_root, |
| + location_target.display_id); |
| + delegate_->UpdateNativeCursorFromDispatcher(); |
| +} |
| + |
| +void EventDispatcher::UpdateCursorProviderByLastKnownLocationOnFoundWindow( |
| + const LocationTarget& location_target) { |
| + if (mouse_button_down_) |
| + return; |
| + |
| + SetMouseCursorSourceWindow(location_target.deepest_window.window); |
| + if (mouse_cursor_source_window_) { |
| + mouse_cursor_in_non_client_area_ = |
| + location_target.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_target.location_in_root, |
| + location_target.display_id); |
| + delegate_->UpdateNativeCursorFromDispatcher(); |
| +} |
| + |
| void EventDispatcher::StartTrackingPointer( |
| int32_t pointer_id, |
| const PointerTarget& pointer_target) { |