Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: ui/aura/mus/window_tree_client.cc

Issue 2696873002: Change OnWindowInputEvent to use display_id to find the host and update event root_location in WS. (Closed)
Patch Set: TODO Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 82f54f0d6d4d97dc79c56cebfb063cc8c2b5661e..e925e69e51850cd22e7cbde68dcb73f9292555b3 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
@@ -1132,18 +1139,6 @@ void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
WindowMus* window = GetWindowByServerId(window_id); // May be null.
sadrul 2017/03/14 16:12:17 Update the comment to explain when this can be nul
riajiang 2017/03/14 19:03:26 Done.
- 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));
@@ -1152,28 +1147,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());
+ }
sadrul 2017/03/14 16:12:16 Actually, can this happen in DispatchEventToTarget
riajiang 2017/03/14 19:03:26 Done.
+
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;
sadrul 2017/03/14 16:12:16 Don't need return. When it's removed, don't need t
riajiang 2017/03/14 19:03:26 Right! Done.
}
}
@@ -1829,4 +1839,18 @@ uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
this, focus_synchronizer_.get(), window));
}
+WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId(
+ int64_t display_id) {
+ // TODO(riajiang): Figure out how to get the correct WindowTreeHost we need
+ // in external window mode.
+ 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

Powered by Google App Engine
This is Rietveld 408576698