Chromium Code Reviews| Index: ui/aura/mus/window_tree_client.cc |
| diff --git a/ui/aura/mus/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc |
| index 3574d71869b49e99c77187a926118eda7c4e9e75..94380a335c04adca4202494c39c47ef06c9b8f0c 100644 |
| --- a/ui/aura/mus/window_tree_client.cc |
| +++ b/ui/aura/mus/window_tree_client.cc |
| @@ -162,10 +162,17 @@ void ConvertEventLocationToDip(int64_t display_id, ui::LocatedEvent* event) { |
| // Set the |target| to be the target window of this |event| and send it to |
| // the EventProcessor. |
| -void DispatchEventToTarget(ui::Event* event, WindowMus* target) { |
| - ui::Event::DispatcherApi dispatch_helper(event); |
| - dispatch_helper.set_target(target->GetWindow()); |
| - GetWindowTreeHostMus(target)->SendEventToProcessor(event); |
| +void DispatchEventToTarget(ui::Event* event, |
| + WindowTreeHostMus* host, |
| + WindowMus* target) { |
| + // Set the event target if target window is not null, otherwise leave the |
| + // event target empty so we can look for target window starting from root in |
| + // EventProcessor. |
| + if (target) { |
| + ui::Event::DispatcherApi dispatch_helper(event); |
| + dispatch_helper.set_target(target->GetWindow()); |
| + } |
| + host->SendEventToProcessor(event); |
| } |
| } // namespace |
| @@ -1131,18 +1138,6 @@ void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| WindowMus* window = GetWindowByServerId(window_id); // May be null. |
| - if (event->IsKeyEvent()) { |
| - DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| - if (!window || !window->GetWindow()->GetHost()) { |
| - tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| - return; |
| - } |
| - InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); |
| - input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| - CreateEventResultCallback(event_id)); |
| - return; |
| - } |
| - |
| if (matches_pointer_watcher && has_pointer_watcher_) { |
| DCHECK(event->IsPointerEvent()); |
| std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
| @@ -1151,28 +1146,47 @@ void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| window ? window->GetWindow() : nullptr); |
| } |
| - // TODO: use |display_id| to find host and send there. |
| - if (!window || !window->GetWindow()->GetHost()) { |
| + // This |window| might have already been deleted by the time |
| + // OnWindowInputEvent is called, so we use the |display_id| to find the host |
| + // for event dispatching. |
| + WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
| + if (!host) { |
| tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| return; |
| } |
| + if (event->IsKeyEvent()) { |
| + DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| + InputMethodMus* input_method = host->input_method(); |
| + input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| + CreateEventResultCallback(event_id)); |
| + return; |
| + } |
| + |
| + // If |window| has already been deleted, update event location to use its |
| + // root location and then find the next best target window starting from root |
| + // window to dispatch the event to. |
| + if (!window && event->IsLocatedEvent()) { |
| + event->AsLocatedEvent()->set_location( |
| + event->AsLocatedEvent()->root_location()); |
| + } |
| + |
| EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| // ui::TouchEvent once we have proper support for pointer events. |
| if (event->IsMousePointerEvent()) { |
| if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| - DispatchEventToTarget(&mapped_event, window); |
| + DispatchEventToTarget(&mapped_event, host, window); |
| } else { |
| ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| - DispatchEventToTarget(&mapped_event, window); |
| + DispatchEventToTarget(&mapped_event, host, window); |
| } |
| } else if (event->IsTouchPointerEvent()) { |
| ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
| - DispatchEventToTarget(&mapped_event, window); |
| + DispatchEventToTarget(&mapped_event, host, window); |
| } else { |
| - DispatchEventToTarget(event.get(), window); |
| + DispatchEventToTarget(event.get(), host, window); |
| } |
| ack_handler.set_handled(event->handled()); |
| } |
| @@ -1330,14 +1344,10 @@ void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
| void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
| DCHECK(window_manager_delegate_); |
| - for (WindowMus* root : roots_) { |
| - DCHECK(root->GetWindow()->GetHost()); |
| - WindowTreeHostMus* window_tree_host = |
| - static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); |
| - if (window_tree_host->display_id() == display_id) { |
| - window_manager_delegate_->OnWmDisplayRemoved(window_tree_host); |
| - return; |
| - } |
| + WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
| + if (host) { |
| + window_manager_delegate_->OnWmDisplayRemoved(host); |
| + return; |
| } |
| } |
| @@ -1829,4 +1839,16 @@ uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| this, focus_synchronizer_.get(), window)); |
| } |
| +WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( |
|
kylechar
2017/03/13 15:08:14
It looks like tonikitoo/fwang have external mode s
riajiang
2017/03/13 21:08:27
Added a TODO to find the correct WTH in external m
|
| + int64_t display_id) { |
| + for (WindowMus* root : roots_) { |
| + DCHECK(root->GetWindow()->GetHost()); |
| + WindowTreeHostMus* window_tree_host = |
| + static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); |
| + if (window_tree_host->display_id() == display_id) |
| + return window_tree_host; |
| + } |
| + return nullptr; |
| +} |
| + |
| } // namespace aura |