| 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 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // If there is a |binding_| then the tree was created specifically for this | 55 // If there is a |binding_| then the tree was created specifically for this |
| 56 // display (which corresponds to a WindowTreeHost). | 56 // display (which corresponds to a WindowTreeHost). |
| 57 window_server_->DestroyTree(window_manager_display_root_map_.begin() | 57 window_server_->DestroyTree(window_manager_display_root_map_.begin() |
| 58 ->second->window_manager_state() | 58 ->second->window_manager_state() |
| 59 ->window_tree()); | 59 ->window_tree()); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void Display::Init(const PlatformDisplayInitParams& init_params, | 63 void Display::Init(const PlatformDisplayInitParams& init_params, |
| 64 std::unique_ptr<DisplayBinding> binding) { | 64 std::unique_ptr<DisplayBinding> binding) { |
| 65 if (window_server_->IsInExternalWindowMode()) |
| 66 DCHECK(binding); |
| 67 |
| 65 binding_ = std::move(binding); | 68 binding_ = std::move(binding); |
| 66 display_manager()->AddDisplay(this); | 69 display_manager()->AddDisplay(this); |
| 67 | 70 |
| 68 CreateRootWindow(init_params.metrics.pixel_size); | 71 CreateRootWindow(init_params.metrics.pixel_size); |
| 69 PlatformDisplayInitParams params_copy = init_params; | 72 PlatformDisplayInitParams params_copy = init_params; |
| 70 params_copy.root_window = root_.get(); | 73 params_copy.root_window = root_.get(); |
| 71 | 74 |
| 72 platform_display_ = PlatformDisplay::Create(params_copy); | 75 platform_display_ = PlatformDisplay::Create(params_copy); |
| 73 platform_display_->Init(this); | 76 platform_display_->Init(this); |
| 74 } | 77 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 200 } |
| 198 | 201 |
| 199 void Display::SetSize(const gfx::Size& size) { | 202 void Display::SetSize(const gfx::Size& size) { |
| 200 platform_display_->SetViewportSize(size); | 203 platform_display_->SetViewportSize(size); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void Display::SetTitle(const std::string& title) { | 206 void Display::SetTitle(const std::string& title) { |
| 204 platform_display_->SetTitle(base::UTF8ToUTF16(title)); | 207 platform_display_->SetTitle(base::UTF8ToUTF16(title)); |
| 205 } | 208 } |
| 206 | 209 |
| 210 void Display::InitDisplayRoot() { |
| 211 DCHECK(window_server_->IsInExternalWindowMode()); |
| 212 DCHECK(binding_); |
| 213 |
| 214 external_mode_root_ = base::MakeUnique<WindowManagerDisplayRoot>(this); |
| 215 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = |
| 216 external_mode_root_.get(); |
| 217 |
| 218 ServerWindow* server_window = external_mode_root_->root(); |
| 219 WindowTree* window_tree = window_server_->GetTreeForExternalWindowMode(); |
| 220 window_tree->AddRoot(server_window); |
| 221 window_tree->DoOnEmbed(nullptr /*mojom::WindowTreePtr*/, server_window); |
| 222 } |
| 223 |
| 207 void Display::InitWindowManagerDisplayRoots() { | 224 void Display::InitWindowManagerDisplayRoots() { |
| 225 // Tests can create ws::Display instances, directly by-passing |
| 226 // WindowTreeHostFactory. |
| 208 if (binding_) { | 227 if (binding_) { |
| 209 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( | 228 std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr( |
| 210 new WindowManagerDisplayRoot(this)); | 229 new WindowManagerDisplayRoot(this)); |
| 211 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); | 230 WindowManagerDisplayRoot* display_root = display_root_ptr.get(); |
| 212 // For this case we never create additional displays roots, so any | 231 // For this case we never create additional displays roots, so any |
| 213 // id works. | 232 // id works. |
| 214 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = | 233 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = |
| 215 display_root_ptr.get(); | 234 display_root_ptr.get(); |
| 216 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); | 235 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); |
| 217 display_root->window_manager_state_ = window_tree->window_manager_state(); | 236 display_root->window_manager_state_ = window_tree->window_manager_state(); |
| 218 window_tree->window_manager_state()->AddWindowManagerDisplayRoot( | 237 window_tree->window_manager_state()->AddWindowManagerDisplayRoot( |
| 219 std::move(display_root_ptr)); | 238 std::move(display_root_ptr)); |
| 220 } else { | 239 } else { |
| 221 CreateWindowManagerDisplayRootsFromFactories(); | 240 CreateWindowManagerDisplayRootsFromFactories(); |
| 222 } | 241 } |
| 223 display_manager()->OnDisplayUpdate(this); | |
| 224 } | 242 } |
| 225 | 243 |
| 226 void Display::CreateWindowManagerDisplayRootsFromFactories() { | 244 void Display::CreateWindowManagerDisplayRootsFromFactories() { |
| 227 std::vector<WindowManagerWindowTreeFactory*> factories = | 245 std::vector<WindowManagerWindowTreeFactory*> factories = |
| 228 window_server_->window_manager_window_tree_factory_set()->GetFactories(); | 246 window_server_->window_manager_window_tree_factory_set()->GetFactories(); |
| 229 for (WindowManagerWindowTreeFactory* factory : factories) { | 247 for (WindowManagerWindowTreeFactory* factory : factories) { |
| 230 if (factory->window_tree()) | 248 if (factory->window_tree()) |
| 231 CreateWindowManagerDisplayRootFromFactory(factory); | 249 CreateWindowManagerDisplayRootFromFactory(factory); |
| 232 } | 250 } |
| 233 } | 251 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 display::Display Display::GetDisplay() { | 285 display::Display Display::GetDisplay() { |
| 268 return ToDisplay(); | 286 return ToDisplay(); |
| 269 } | 287 } |
| 270 | 288 |
| 271 ServerWindow* Display::GetRootWindow() { | 289 ServerWindow* Display::GetRootWindow() { |
| 272 return root_.get(); | 290 return root_.get(); |
| 273 } | 291 } |
| 274 | 292 |
| 275 void Display::OnAcceleratedWidgetAvailable() { | 293 void Display::OnAcceleratedWidgetAvailable() { |
| 276 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); | 294 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 277 InitWindowManagerDisplayRoots(); | 295 |
| 296 if (window_server_->IsInExternalWindowMode()) |
| 297 InitDisplayRoot(); |
| 298 else |
| 299 InitWindowManagerDisplayRoots(); |
| 300 |
| 301 display_manager()->OnDisplayUpdate(this); |
| 278 } | 302 } |
| 279 | 303 |
| 280 bool Display::IsInHighContrastMode() { | 304 bool Display::IsInHighContrastMode() { |
| 281 return window_server_->IsActiveUserInHighContrastMode(); | 305 return window_server_->IsActiveUserInHighContrastMode(); |
| 282 } | 306 } |
| 283 | 307 |
| 284 void Display::OnEvent(const ui::Event& event) { | 308 void Display::OnEvent(const ui::Event& event) { |
| 285 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 309 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 286 if (display_root) | 310 if (display_root && display_root->window_manager_state()) |
| 287 display_root->window_manager_state()->ProcessEvent(event, GetId()); | 311 display_root->window_manager_state()->ProcessEvent(event, GetId()); |
| 288 window_server_ | 312 window_server_ |
| 289 ->GetUserActivityMonitorForUser( | 313 ->GetUserActivityMonitorForUser( |
| 290 window_server_->user_id_tracker()->active_id()) | 314 window_server_->user_id_tracker()->active_id()) |
| 291 ->OnUserActivity(); | 315 ->OnUserActivity(); |
| 292 } | 316 } |
| 293 | 317 |
| 294 void Display::OnNativeCaptureLost() { | 318 void Display::OnNativeCaptureLost() { |
| 295 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 319 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 296 if (display_root) | 320 if (display_root && display_root->window_manager_state()) |
| 297 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); | 321 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); |
| 298 } | 322 } |
| 299 | 323 |
| 300 void Display::OnViewportMetricsChanged( | 324 void Display::OnViewportMetricsChanged( |
| 301 const display::ViewportMetrics& metrics) { | 325 const display::ViewportMetrics& metrics) { |
| 302 if (root_->bounds().size() == metrics.pixel_size) | 326 if (root_->bounds().size() == metrics.pixel_size) |
| 303 return; | 327 return; |
| 304 | 328 |
| 305 gfx::Rect new_bounds(metrics.pixel_size); | 329 gfx::Rect new_bounds(metrics.pixel_size); |
| 306 root_->SetBounds(new_bounds, allocator_.GenerateId()); | 330 root_->SetBounds(new_bounds, allocator_.GenerateId()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 if (embedded_tree_new && embedded_tree_new != owning_tree_old && | 393 if (embedded_tree_new && embedded_tree_new != owning_tree_old && |
| 370 embedded_tree_new != embedded_tree_old) { | 394 embedded_tree_new != embedded_tree_old) { |
| 371 DCHECK_NE(owning_tree_new, embedded_tree_new); | 395 DCHECK_NE(owning_tree_new, embedded_tree_new); |
| 372 embedded_tree_new->ProcessFocusChanged(old_focused_window, | 396 embedded_tree_new->ProcessFocusChanged(old_focused_window, |
| 373 new_focused_window); | 397 new_focused_window); |
| 374 } | 398 } |
| 375 } | 399 } |
| 376 | 400 |
| 377 // WindowManagers are always notified of focus changes. | 401 // WindowManagers are always notified of focus changes. |
| 378 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); | 402 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); |
| 379 if (display_root) { | 403 if (display_root && display_root->window_manager_state()) { |
| 380 WindowTree* wm_tree = display_root->window_manager_state()->window_tree(); | 404 WindowTree* wm_tree = display_root->window_manager_state()->window_tree(); |
| 381 if (wm_tree != owning_tree_old && wm_tree != embedded_tree_old && | 405 if (wm_tree != owning_tree_old && wm_tree != embedded_tree_old && |
| 382 wm_tree != owning_tree_new && wm_tree != embedded_tree_new) { | 406 wm_tree != owning_tree_new && wm_tree != embedded_tree_new) { |
| 383 wm_tree->ProcessFocusChanged(old_focused_window, new_focused_window); | 407 wm_tree->ProcessFocusChanged(old_focused_window, new_focused_window); |
| 384 } | 408 } |
| 385 } | 409 } |
| 386 | 410 |
| 387 UpdateTextInputState(new_focused_window, | 411 UpdateTextInputState(new_focused_window, |
| 388 new_focused_window->text_input_state()); | 412 new_focused_window->text_input_state()); |
| 389 } | 413 } |
| 390 | 414 |
| 391 void Display::OnUserIdRemoved(const UserId& id) { | 415 void Display::OnUserIdRemoved(const UserId& id) { |
| 392 window_manager_display_root_map_.erase(id); | 416 window_manager_display_root_map_.erase(id); |
| 393 } | 417 } |
| 394 | 418 |
| 395 void Display::OnWindowManagerWindowTreeFactoryReady( | 419 void Display::OnWindowManagerWindowTreeFactoryReady( |
| 396 WindowManagerWindowTreeFactory* factory) { | 420 WindowManagerWindowTreeFactory* factory) { |
| 397 if (!binding_) | 421 if (!binding_) |
| 398 CreateWindowManagerDisplayRootFromFactory(factory); | 422 CreateWindowManagerDisplayRootFromFactory(factory); |
| 399 } | 423 } |
| 400 | 424 |
| 401 } // namespace ws | 425 } // namespace ws |
| 402 } // namespace ui | 426 } // namespace ui |
| OLD | NEW |