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..c9d070f6c3f207e047921a765d97b45be78559b9 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,15 +1125,31 @@ 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; |
} |
- |
- WindowTreeHostMus* host = GetWindowTreeHostMus(window); |
+ if (!window) { |
+ window = WindowMus::Get(host->window()); |
+ if (event->IsLocatedEvent()) { |
+ event->AsLocatedEvent()->set_location( |
+ event->AsLocatedEvent()->root_location()); |
+ } |
+ } |
DCHECK(host); |
sky
2017/02/23 00:56:27
Remove this DCHECK given the conditional for !host
riajiang
2017/02/23 04:06:05
Done.
|
+ if (event->IsKeyEvent()) { |
sky
2017/02/23 00:56:27
Move this above 1136 as the conditional on 1136 is
riajiang
2017/02/23 04:06:05
Done.
|
+ 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; |
+ } |
+ |
// The location of the event is relative to |window|. As the event is handed |
// to WindowTreeHost we need it to be relative to WindowTreeHost. |
if (event->IsLocatedEvent()) { |
@@ -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 |