Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/ui/ws/display.h" | 5 #include "services/ui/ws/display.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_helpers.h" | |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "services/service_manager/public/interfaces/connector.mojom.h" | 14 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 14 #include "services/ui/common/types.h" | 15 #include "services/ui/common/types.h" |
| 15 #include "services/ui/display/viewport_metrics.h" | 16 #include "services/ui/display/viewport_metrics.h" |
| 16 #include "services/ui/public/interfaces/cursor.mojom.h" | 17 #include "services/ui/public/interfaces/cursor.mojom.h" |
| 17 #include "services/ui/ws/display_binding.h" | 18 #include "services/ui/ws/display_binding.h" |
| 18 #include "services/ui/ws/display_manager.h" | 19 #include "services/ui/ws/display_manager.h" |
| 19 #include "services/ui/ws/focus_controller.h" | 20 #include "services/ui/ws/focus_controller.h" |
| 20 #include "services/ui/ws/platform_display.h" | 21 #include "services/ui/ws/platform_display.h" |
| 21 #include "services/ui/ws/user_activity_monitor.h" | 22 #include "services/ui/ws/user_activity_monitor.h" |
| 22 #include "services/ui/ws/window_manager_display_root.h" | 23 #include "services/ui/ws/window_manager_display_root.h" |
| 23 #include "services/ui/ws/window_manager_state.h" | 24 #include "services/ui/ws/window_manager_state.h" |
| 24 #include "services/ui/ws/window_manager_window_tree_factory.h" | 25 #include "services/ui/ws/window_manager_window_tree_factory.h" |
| 25 #include "services/ui/ws/window_server.h" | 26 #include "services/ui/ws/window_server.h" |
| 26 #include "services/ui/ws/window_server_delegate.h" | 27 #include "services/ui/ws/window_server_delegate.h" |
| 27 #include "services/ui/ws/window_tree.h" | 28 #include "services/ui/ws/window_tree.h" |
| 28 #include "services/ui/ws/window_tree_binding.h" | 29 #include "services/ui/ws/window_tree_binding.h" |
| 29 #include "ui/base/cursor/cursor.h" | 30 #include "ui/base/cursor/cursor.h" |
| 30 #include "ui/display/screen.h" | 31 #include "ui/display/screen.h" |
| 32 #include "ui/events/event_rewriter.h" | |
| 31 | 33 |
| 32 namespace ui { | 34 namespace ui { |
| 33 namespace ws { | 35 namespace ws { |
| 34 | 36 |
| 35 Display::Display(WindowServer* window_server) | 37 Display::Display(WindowServer* window_server) |
| 36 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { | 38 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { |
| 37 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); | 39 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); |
| 38 window_server_->user_id_tracker()->AddObserver(this); | 40 window_server_->user_id_tracker()->AddObserver(this); |
| 39 } | 41 } |
| 40 | 42 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 void Display::OnAcceleratedWidgetAvailable() { | 265 void Display::OnAcceleratedWidgetAvailable() { |
| 264 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | 266 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 265 InitWindowManagerDisplayRoots(); | 267 InitWindowManagerDisplayRoots(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 bool Display::IsInHighContrastMode() { | 270 bool Display::IsInHighContrastMode() { |
| 269 return window_server_->IsActiveUserInHighContrastMode(); | 271 return window_server_->IsActiveUserInHighContrastMode(); |
| 270 } | 272 } |
| 271 | 273 |
| 272 void Display::OnEvent(const ui::Event& event) { | 274 void Display::OnEvent(const ui::Event& event) { |
| 275 // Run UserActivityMonitor::OnUserActivity() for active user before exiting | |
| 276 // this function. | |
| 277 auto* activity_monitor = window_server_->GetUserActivityMonitorForUser( | |
| 278 window_server_->user_id_tracker()->active_id()); | |
| 279 base::ScopedClosureRunner scoped_runner( | |
|
sky
2017/03/15 19:48:11
Do we really need a ScopedClosureRunner? Can you c
Peng
2017/03/16 17:28:57
This function has several return statements, using
sky
2017/03/16 20:23:07
Sorry for not being clear. I wasn't suggesting you
| |
| 280 base::Bind(&UserActivityMonitor::OnUserActivity, | |
| 281 base::Unretained(activity_monitor))); | |
| 282 | |
| 273 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 283 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 274 if (display_root) | 284 if (!display_root) |
| 275 display_root->window_manager_state()->ProcessEvent(event, GetId()); | 285 return; |
| 276 window_server_ | 286 |
| 277 ->GetUserActivityMonitorForUser( | 287 std::unique_ptr<ui::Event> rewritten_event; |
| 278 window_server_->user_id_tracker()->active_id()) | 288 auto status = ui::EVENT_REWRITE_CONTINUE; |
|
sky
2017/03/15 19:48:11
Please don't overuse auto, it's make the code hard
Peng
2017/03/16 17:28:57
Done.
| |
| 279 ->OnUserActivity(); | 289 auto* event_rewriter = display_manager()->event_rewriter(); |
| 290 | |
| 291 // |event_rewriter| is null for non-ChromeOS build. | |
| 292 if (event_rewriter) | |
| 293 status = event_rewriter->RewriteEvent(event, &rewritten_event); | |
| 294 | |
| 295 if (status == ui::EVENT_REWRITE_DISCARD) { | |
| 296 DCHECK(!rewritten_event); | |
| 297 return; | |
| 298 } | |
| 299 | |
| 300 auto* wm_state = display_root->window_manager_state(); | |
| 301 if (status == ui::EVENT_REWRITE_CONTINUE) { | |
| 302 DCHECK(!rewritten_event); | |
| 303 wm_state->ProcessEvent(event, GetId()); | |
| 304 return; | |
| 305 } | |
| 306 | |
| 307 DCHECK(status == ui::EVENT_REWRITE_REWRITTEN || | |
| 308 status == ui::EVENT_REWRITE_DISPATCH_ANOTHER); | |
| 309 DCHECK(rewritten_event); | |
| 310 wm_state->ProcessEvent(*rewritten_event, GetId()); | |
| 311 | |
| 312 while (status == ui::EVENT_REWRITE_DISPATCH_ANOTHER) { | |
| 313 std::unique_ptr<Event> new_event; | |
| 314 status = event_rewriter->NextDispatchEvent(*rewritten_event, &new_event); | |
| 315 if (status == ui::EVENT_REWRITE_DISCARD) | |
| 316 break; | |
| 317 DCHECK_NE(EVENT_REWRITE_CONTINUE, status); | |
| 318 | |
| 319 DCHECK(new_event); | |
| 320 wm_state->ProcessEvent(*new_event, GetId()); | |
| 321 rewritten_event = std::move(new_event); | |
| 322 } | |
| 280 } | 323 } |
| 281 | 324 |
| 282 void Display::OnNativeCaptureLost() { | 325 void Display::OnNativeCaptureLost() { |
| 283 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 326 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 284 if (display_root) | 327 if (display_root) |
| 285 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); | 328 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); |
| 286 } | 329 } |
| 287 | 330 |
| 288 void Display::OnViewportMetricsChanged( | 331 void Display::OnViewportMetricsChanged( |
| 289 const display::ViewportMetrics& metrics) { | 332 const display::ViewportMetrics& metrics) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 } | 424 } |
| 382 | 425 |
| 383 void Display::OnWindowManagerWindowTreeFactoryReady( | 426 void Display::OnWindowManagerWindowTreeFactoryReady( |
| 384 WindowManagerWindowTreeFactory* factory) { | 427 WindowManagerWindowTreeFactory* factory) { |
| 385 if (!binding_) | 428 if (!binding_) |
| 386 CreateWindowManagerDisplayRootFromFactory(factory); | 429 CreateWindowManagerDisplayRootFromFactory(factory); |
| 387 } | 430 } |
| 388 | 431 |
| 389 } // namespace ws | 432 } // namespace ws |
| 390 } // namespace ui | 433 } // namespace ui |
| OLD | NEW |