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 08e7b028bf1b90a4a7f6d21a9458623df8459d90..d1bbb792e4ac55a3a861e52897c53c8c3df23db9 100644 |
| --- a/ui/aura/mus/window_tree_client.cc |
| +++ b/ui/aura/mus/window_tree_client.cc |
| @@ -1117,18 +1117,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)); |
| @@ -1137,14 +1125,30 @@ 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; |
| } |
|
sadrul
2017/02/23 17:13:00
This could be:
if (!window) {
... host = ...
|
| - WindowTreeHostMus* host = GetWindowTreeHostMus(window); |
| - DCHECK(host); |
| + 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) { |
| + window = WindowMus::Get(host->window()); |
| + if (event->IsLocatedEvent()) { |
| + event->AsLocatedEvent()->set_location( |
| + event->AsLocatedEvent()->root_location()); |
| + } |
|
sadrul
2017/02/23 17:13:00
Why do this?
|
| + } |
| // The location of the event is relative to |window|. As the event is handed |
| // to WindowTreeHost we need it to be relative to WindowTreeHost. |
| @@ -1328,14 +1332,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; |
| } |
| } |
| @@ -1827,4 +1827,16 @@ uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| this, focus_synchronizer_.get(), window)); |
| } |
| +WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( |
| + 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 |