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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "services/service_manager/public/interfaces/connector.mojom.h" | 13 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 14 #include "services/ui/common/types.h" | 14 #include "services/ui/common/types.h" |
| 15 #include "services/ui/public/interfaces/cursor.mojom.h" | 15 #include "services/ui/public/interfaces/cursor.mojom.h" |
| 16 #include "services/ui/ws/display_binding.h" | 16 #include "services/ui/ws/display_binding.h" |
| 17 #include "services/ui/ws/display_manager.h" | 17 #include "services/ui/ws/display_manager.h" |
| 18 #include "services/ui/ws/focus_controller.h" | 18 #include "services/ui/ws/focus_controller.h" |
| 19 #include "services/ui/ws/platform_display.h" | 19 #include "services/ui/ws/platform_display.h" |
| 20 #include "services/ui/ws/platform_display_init_params.h" | 20 #include "services/ui/ws/platform_display_init_params.h" |
| 21 #include "services/ui/ws/user_activity_monitor.h" | 21 #include "services/ui/ws/user_activity_monitor.h" |
| 22 #include "services/ui/ws/window_manager_display_root.h" | 22 #include "services/ui/ws/window_manager_display_root.h" |
| 23 #include "services/ui/ws/window_manager_state.h" | 23 #include "services/ui/ws/window_manager_state.h" |
| 24 #include "services/ui/ws/window_manager_window_tree_factory.h" | 24 #include "services/ui/ws/window_manager_window_tree_factory.h" |
| 25 #include "services/ui/ws/window_server.h" | 25 #include "services/ui/ws/window_server.h" |
| 26 #include "services/ui/ws/window_server_delegate.h" | 26 #include "services/ui/ws/window_server_delegate.h" |
| 27 #include "services/ui/ws/window_tree.h" | 27 #include "services/ui/ws/window_tree.h" |
| 28 #include "services/ui/ws/window_tree_binding.h" | 28 #include "services/ui/ws/window_tree_binding.h" |
| 29 #include "services/ui/ws/window_tree_host_factory.h" | |
| 29 #include "ui/base/cursor/cursor.h" | 30 #include "ui/base/cursor/cursor.h" |
| 30 | 31 |
| 31 namespace ui { | 32 namespace ui { |
| 32 namespace ws { | 33 namespace ws { |
| 33 | 34 |
| 34 Display::Display(WindowServer* window_server) | 35 Display::Display(WindowServer* window_server) |
| 35 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { | 36 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { |
| 36 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); | 37 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); |
| 37 window_server_->user_id_tracker()->AddObserver(this); | 38 window_server_->user_id_tracker()->AddObserver(this); |
| 38 } | 39 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 55 // If there is a |binding_| then the tree was created specifically for this | 56 // If there is a |binding_| then the tree was created specifically for this |
| 56 // display (which corresponds to a WindowTreeHost). | 57 // display (which corresponds to a WindowTreeHost). |
| 57 window_server_->DestroyTree(window_manager_display_root_map_.begin() | 58 window_server_->DestroyTree(window_manager_display_root_map_.begin() |
| 58 ->second->window_manager_state() | 59 ->second->window_manager_state() |
| 59 ->window_tree()); | 60 ->window_tree()); |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 void Display::Init(const PlatformDisplayInitParams& init_params, | 64 void Display::Init(const PlatformDisplayInitParams& init_params, |
| 64 std::unique_ptr<DisplayBinding> binding) { | 65 std::unique_ptr<DisplayBinding> binding) { |
| 66 if (window_server_->IsInExternalWindowMode()) | |
| 67 DCHECK(window_server_->window_tree_host_factory() && binding); | |
|
kylechar
2017/03/07 18:19:37
DCHECKs are compiled out in release builds, that m
tonikitoo
2017/03/07 20:09:36
BuildBots (including release bots) seem happy, but
| |
| 68 | |
| 65 binding_ = std::move(binding); | 69 binding_ = std::move(binding); |
| 66 display_manager()->AddDisplay(this); | 70 display_manager()->AddDisplay(this); |
| 67 | 71 |
| 68 CreateRootWindow(init_params.metrics.pixel_size); | 72 CreateRootWindow(init_params.metrics.pixel_size); |
| 69 PlatformDisplayInitParams params_copy = init_params; | 73 PlatformDisplayInitParams params_copy = init_params; |
| 70 params_copy.root_window = root_.get(); | 74 params_copy.root_window = root_.get(); |
| 71 | 75 |
| 72 platform_display_ = PlatformDisplay::Create(params_copy); | 76 platform_display_ = PlatformDisplay::Create(params_copy); |
| 73 platform_display_->Init(this); | 77 platform_display_->Init(this); |
| 74 } | 78 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } | 201 } |
| 198 | 202 |
| 199 void Display::SetSize(const gfx::Size& size) { | 203 void Display::SetSize(const gfx::Size& size) { |
| 200 platform_display_->SetViewportSize(size); | 204 platform_display_->SetViewportSize(size); |
| 201 } | 205 } |
| 202 | 206 |
| 203 void Display::SetTitle(const std::string& title) { | 207 void Display::SetTitle(const std::string& title) { |
| 204 platform_display_->SetTitle(base::UTF8ToUTF16(title)); | 208 platform_display_->SetTitle(base::UTF8ToUTF16(title)); |
| 205 } | 209 } |
| 206 | 210 |
| 211 void Display::InitDisplayRoot() { | |
| 212 DCHECK(window_server_->IsInExternalWindowMode()); | |
| 213 DCHECK(window_server_->window_tree_host_factory()); | |
| 214 DCHECK(binding_); | |
| 215 | |
| 216 external_window_mode_display_root_ = | |
| 217 base::MakeUnique<WindowManagerDisplayRoot>(this); | |
| 218 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = | |
|
kylechar
2017/03/07 18:19:37
Once you aren't using WindowManagerDisplayRoot any
tonikitoo
2017/03/07 20:09:36
This is still needed, but should be clean up indee
| |
| 219 external_window_mode_display_root_.get(); | |
| 220 | |
| 221 ServerWindow* server_window = external_window_mode_display_root_->root(); | |
| 222 WindowTree* window_tree = | |
| 223 window_server_->window_tree_host_factory()->window_tree(); | |
| 224 window_tree->AddRoot(server_window); | |
| 225 window_tree->DoOnEmbed(nullptr /*mojom::WindowTreePtr*/, server_window); | |
| 226 } | |
| 227 | |
| 207 void Display::InitWindowManagerDisplayRoots() { | 228 void Display::InitWindowManagerDisplayRoots() { |
| 229 // Tests can create ws::Display instances, directly by-passing | |
|
kylechar
2017/03/07 18:19:37
The if (binding_) path is only for tests now?
tonikitoo
2017/03/07 20:09:36
Yes and No.
Yes, because I believe only tests exe
| |
| 230 // WindowTreeHostFactory. | |
| 208 if (binding_) { | 231 if (binding_) { |
| 209 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( | 232 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( |
| 210 new WindowManagerDisplayRoot(this)); | 233 new WindowManagerDisplayRoot(this)); |
| 211 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); | 234 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); |
| 212 // For this case we never create additional displays roots, so any | 235 // For this case we never create additional displays roots, so any |
| 213 // id works. | 236 // id works. |
| 214 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = | 237 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = |
| 215 display_root_ptr.get(); | 238 display_root_ptr.get(); |
| 216 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); | 239 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); |
| 217 display_root->window_manager_state_ = window_tree->window_manager_state(); | 240 display_root->window_manager_state_ = window_tree->window_manager_state(); |
| 218 window_tree->window_manager_state()->AddWindowManagerDisplayRoot( | 241 window_tree->window_manager_state()->AddWindowManagerDisplayRoot( |
| 219 std::move(display_root_ptr)); | 242 std::move(display_root_ptr)); |
| 220 } else { | 243 } else { |
| 221 CreateWindowManagerDisplayRootsFromFactories(); | 244 CreateWindowManagerDisplayRootsFromFactories(); |
| 222 } | 245 } |
| 223 display_manager()->OnDisplayUpdate(this); | |
| 224 } | 246 } |
| 225 | 247 |
| 226 void Display::CreateWindowManagerDisplayRootsFromFactories() { | 248 void Display::CreateWindowManagerDisplayRootsFromFactories() { |
| 227 std::vector<WindowManagerWindowTreeFactory*> factories = | 249 std::vector<WindowManagerWindowTreeFactory*> factories = |
| 228 window_server_->window_manager_window_tree_factory_set()->GetFactories(); | 250 window_server_->window_manager_window_tree_factory_set()->GetFactories(); |
| 229 for (WindowManagerWindowTreeFactory* factory : factories) { | 251 for (WindowManagerWindowTreeFactory* factory : factories) { |
| 230 if (factory->window_tree()) | 252 if (factory->window_tree()) |
| 231 CreateWindowManagerDisplayRootFromFactory(factory); | 253 CreateWindowManagerDisplayRootFromFactory(factory); |
| 232 } | 254 } |
| 233 } | 255 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 display::Display Display::GetDisplay() { | 289 display::Display Display::GetDisplay() { |
| 268 return ToDisplay(); | 290 return ToDisplay(); |
| 269 } | 291 } |
| 270 | 292 |
| 271 ServerWindow* Display::GetRootWindow() { | 293 ServerWindow* Display::GetRootWindow() { |
| 272 return root_.get(); | 294 return root_.get(); |
| 273 } | 295 } |
| 274 | 296 |
| 275 void Display::OnAcceleratedWidgetAvailable() { | 297 void Display::OnAcceleratedWidgetAvailable() { |
| 276 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | 298 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 277 InitWindowManagerDisplayRoots(); | 299 |
| 300 if (window_server_->IsInExternalWindowMode()) | |
| 301 InitDisplayRoot(); | |
| 302 else | |
| 303 InitWindowManagerDisplayRoots(); | |
| 304 | |
| 305 display_manager()->OnDisplayUpdate(this); | |
| 278 } | 306 } |
| 279 | 307 |
| 280 bool Display::IsInHighContrastMode() { | 308 bool Display::IsInHighContrastMode() { |
| 281 return window_server_->IsActiveUserInHighContrastMode(); | 309 return window_server_->IsActiveUserInHighContrastMode(); |
| 282 } | 310 } |
| 283 | 311 |
| 284 void Display::OnEvent(const ui::Event& event) { | 312 void Display::OnEvent(const ui::Event& event) { |
| 285 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 313 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 286 if (display_root) | 314 if (display_root && display_root->window_manager_state()) |
| 287 display_root->window_manager_state()->ProcessEvent(event, GetId()); | 315 display_root->window_manager_state()->ProcessEvent(event, GetId()); |
| 288 window_server_ | 316 window_server_ |
| 289 ->GetUserActivityMonitorForUser( | 317 ->GetUserActivityMonitorForUser( |
| 290 window_server_->user_id_tracker()->active_id()) | 318 window_server_->user_id_tracker()->active_id()) |
| 291 ->OnUserActivity(); | 319 ->OnUserActivity(); |
| 292 } | 320 } |
| 293 | 321 |
| 294 void Display::OnNativeCaptureLost() { | 322 void Display::OnNativeCaptureLost() { |
| 295 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 323 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 296 if (display_root) | 324 if (display_root && display_root->window_manager_state()) |
| 297 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); | 325 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); |
| 298 } | 326 } |
| 299 | 327 |
| 300 void Display::OnViewportMetricsChanged( | 328 void Display::OnViewportMetricsChanged( |
| 301 const display::ViewportMetrics& metrics) { | 329 const display::ViewportMetrics& metrics) { |
| 302 if (root_->bounds().size() == metrics.pixel_size) | 330 if (root_->bounds().size() == metrics.pixel_size) |
| 303 return; | 331 return; |
| 304 | 332 |
| 305 gfx::Rect new_bounds(metrics.pixel_size); | 333 gfx::Rect new_bounds(metrics.pixel_size); |
| 306 root_->SetBounds(new_bounds); | 334 root_->SetBounds(new_bounds); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 if (embedded_tree_new && embedded_tree_new != owning_tree_old && | 397 if (embedded_tree_new && embedded_tree_new != owning_tree_old && |
| 370 embedded_tree_new != embedded_tree_old) { | 398 embedded_tree_new != embedded_tree_old) { |
| 371 DCHECK_NE(owning_tree_new, embedded_tree_new); | 399 DCHECK_NE(owning_tree_new, embedded_tree_new); |
| 372 embedded_tree_new->ProcessFocusChanged(old_focused_window, | 400 embedded_tree_new->ProcessFocusChanged(old_focused_window, |
| 373 new_focused_window); | 401 new_focused_window); |
| 374 } | 402 } |
| 375 } | 403 } |
| 376 | 404 |
| 377 // WindowManagers are always notified of focus changes. | 405 // WindowManagers are always notified of focus changes. |
| 378 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 406 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 379 if (display_root) { | 407 if (display_root && display_root->window_manager_state()) { |
| 380 WindowTree* wm_tree = display_root->window_manager_state()->window_tree(); | 408 WindowTree* wm_tree = display_root->window_manager_state()->window_tree(); |
| 381 if (wm_tree != owning_tree_old && wm_tree != embedded_tree_old && | 409 if (wm_tree != owning_tree_old && wm_tree != embedded_tree_old && |
| 382 wm_tree != owning_tree_new && wm_tree != embedded_tree_new) { | 410 wm_tree != owning_tree_new && wm_tree != embedded_tree_new) { |
| 383 wm_tree->ProcessFocusChanged(old_focused_window, new_focused_window); | 411 wm_tree->ProcessFocusChanged(old_focused_window, new_focused_window); |
| 384 } | 412 } |
| 385 } | 413 } |
| 386 | 414 |
| 387 UpdateTextInputState(new_focused_window, | 415 UpdateTextInputState(new_focused_window, |
| 388 new_focused_window->text_input_state()); | 416 new_focused_window->text_input_state()); |
| 389 } | 417 } |
| 390 | 418 |
| 391 void Display::OnUserIdRemoved(const UserId& id) { | 419 void Display::OnUserIdRemoved(const UserId& id) { |
| 392 window_manager_display_root_map_.erase(id); | 420 window_manager_display_root_map_.erase(id); |
| 393 } | 421 } |
| 394 | 422 |
| 395 void Display::OnWindowManagerWindowTreeFactoryReady( | 423 void Display::OnWindowManagerWindowTreeFactoryReady( |
| 396 WindowManagerWindowTreeFactory* factory) { | 424 WindowManagerWindowTreeFactory* factory) { |
| 397 if (!binding_) | 425 if (!binding_) |
| 398 CreateWindowManagerDisplayRootFromFactory(factory); | 426 CreateWindowManagerDisplayRootFromFactory(factory); |
| 399 } | 427 } |
| 400 | 428 |
| 401 } // namespace ws | 429 } // namespace ws |
| 402 } // namespace ui | 430 } // namespace ui |
| OLD | NEW |