| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/display/window_tree_host_manager.h" | 5 #include "ash/display/window_tree_host_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "ui/aura/window_tracker.h" | 39 #include "ui/aura/window_tracker.h" |
| 40 #include "ui/aura/window_tree_host.h" | 40 #include "ui/aura/window_tree_host.h" |
| 41 #include "ui/base/ime/input_method_factory.h" | 41 #include "ui/base/ime/input_method_factory.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/compositor/compositor.h" | 43 #include "ui/compositor/compositor.h" |
| 44 #include "ui/display/display.h" | 44 #include "ui/display/display.h" |
| 45 #include "ui/display/manager/display_layout.h" | 45 #include "ui/display/manager/display_layout.h" |
| 46 #include "ui/display/manager/display_layout_store.h" | 46 #include "ui/display/manager/display_layout_store.h" |
| 47 #include "ui/display/manager/display_manager.h" | 47 #include "ui/display/manager/display_manager.h" |
| 48 #include "ui/display/screen.h" | 48 #include "ui/display/screen.h" |
| 49 #include "ui/display/types/display_constants.h" |
| 49 #include "ui/wm/core/coordinate_conversion.h" | 50 #include "ui/wm/core/coordinate_conversion.h" |
| 50 #include "ui/wm/public/activation_client.h" | 51 #include "ui/wm/public/activation_client.h" |
| 51 | 52 |
| 52 #if defined(USE_X11) | 53 #if defined(USE_X11) |
| 53 #include "ui/base/x/x11_util.h" // nogncheck | 54 #include "ui/base/x/x11_util.h" // nogncheck |
| 54 #include "ui/gfx/x/x11_types.h" // nogncheck | 55 #include "ui/gfx/x/x11_types.h" // nogncheck |
| 55 | 56 |
| 56 // Including this at the bottom to avoid other | 57 // Including this at the bottom to avoid other |
| 57 // potential conflict with chrome headers. | 58 // potential conflict with chrome headers. |
| 58 #include <X11/extensions/Xrandr.h> | 59 #include <X11/extensions/Xrandr.h> |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 }; | 232 }; |
| 232 | 233 |
| 233 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
| 234 // WindowTreeHostManager | 235 // WindowTreeHostManager |
| 235 | 236 |
| 236 WindowTreeHostManager::WindowTreeHostManager() | 237 WindowTreeHostManager::WindowTreeHostManager() |
| 237 : primary_tree_host_for_replace_(nullptr), | 238 : primary_tree_host_for_replace_(nullptr), |
| 238 focus_activation_store_(new FocusActivationStore()), | 239 focus_activation_store_(new FocusActivationStore()), |
| 239 cursor_window_controller_(new CursorWindowController()), | 240 cursor_window_controller_(new CursorWindowController()), |
| 240 mirror_window_controller_(new MirrorWindowController()), | 241 mirror_window_controller_(new MirrorWindowController()), |
| 241 cursor_display_id_for_restore_(display::Display::kInvalidDisplayID), | 242 cursor_display_id_for_restore_(display::kInvalidDisplayId), |
| 242 weak_ptr_factory_(this) { | 243 weak_ptr_factory_(this) { |
| 243 // Reset primary display to make sure that tests don't use | 244 // Reset primary display to make sure that tests don't use |
| 244 // stale display info from previous tests. | 245 // stale display info from previous tests. |
| 245 primary_display_id = display::Display::kInvalidDisplayID; | 246 primary_display_id = display::kInvalidDisplayId; |
| 246 } | 247 } |
| 247 | 248 |
| 248 WindowTreeHostManager::~WindowTreeHostManager() {} | 249 WindowTreeHostManager::~WindowTreeHostManager() {} |
| 249 | 250 |
| 250 void WindowTreeHostManager::Start() { | 251 void WindowTreeHostManager::Start() { |
| 251 display::Screen::GetScreen()->AddObserver(this); | 252 display::Screen::GetScreen()->AddObserver(this); |
| 252 Shell::GetInstance()->display_manager()->set_delegate(this); | 253 Shell::GetInstance()->display_manager()->set_delegate(this); |
| 253 } | 254 } |
| 254 | 255 |
| 255 void WindowTreeHostManager::Shutdown() { | 256 void WindowTreeHostManager::Shutdown() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 286 for (auto rwc : to_delete) | 287 for (auto rwc : to_delete) |
| 287 delete rwc; | 288 delete rwc; |
| 288 delete primary_rwc; | 289 delete primary_rwc; |
| 289 } | 290 } |
| 290 | 291 |
| 291 void WindowTreeHostManager::CreatePrimaryHost( | 292 void WindowTreeHostManager::CreatePrimaryHost( |
| 292 const AshWindowTreeHostInitParams& init_params) { | 293 const AshWindowTreeHostInitParams& init_params) { |
| 293 const display::Display& primary_candidate = | 294 const display::Display& primary_candidate = |
| 294 GetDisplayManager()->GetPrimaryDisplayCandidate(); | 295 GetDisplayManager()->GetPrimaryDisplayCandidate(); |
| 295 primary_display_id = primary_candidate.id(); | 296 primary_display_id = primary_candidate.id(); |
| 296 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id); | 297 CHECK_NE(display::kInvalidDisplayId, primary_display_id); |
| 297 AddWindowTreeHostForDisplay(primary_candidate, init_params); | 298 AddWindowTreeHostForDisplay(primary_candidate, init_params); |
| 298 } | 299 } |
| 299 | 300 |
| 300 void WindowTreeHostManager::InitHosts() { | 301 void WindowTreeHostManager::InitHosts() { |
| 301 RootWindowController::CreateForPrimaryDisplay( | 302 RootWindowController::CreateForPrimaryDisplay( |
| 302 window_tree_hosts_[primary_display_id]); | 303 window_tree_hosts_[primary_display_id]); |
| 303 display::DisplayManager* display_manager = GetDisplayManager(); | 304 display::DisplayManager* display_manager = GetDisplayManager(); |
| 304 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 305 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 305 const display::Display& display = display_manager->GetDisplayAt(i); | 306 const display::Display& display = display_manager->GetDisplayAt(i); |
| 306 if (primary_display_id != display.id()) { | 307 if (primary_display_id != display.id()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 317 void WindowTreeHostManager::AddObserver(Observer* observer) { | 318 void WindowTreeHostManager::AddObserver(Observer* observer) { |
| 318 observers_.AddObserver(observer); | 319 observers_.AddObserver(observer); |
| 319 } | 320 } |
| 320 | 321 |
| 321 void WindowTreeHostManager::RemoveObserver(Observer* observer) { | 322 void WindowTreeHostManager::RemoveObserver(Observer* observer) { |
| 322 observers_.RemoveObserver(observer); | 323 observers_.RemoveObserver(observer); |
| 323 } | 324 } |
| 324 | 325 |
| 325 // static | 326 // static |
| 326 int64_t WindowTreeHostManager::GetPrimaryDisplayId() { | 327 int64_t WindowTreeHostManager::GetPrimaryDisplayId() { |
| 327 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id); | 328 CHECK_NE(display::kInvalidDisplayId, primary_display_id); |
| 328 return primary_display_id; | 329 return primary_display_id; |
| 329 } | 330 } |
| 330 | 331 |
| 331 aura::Window* WindowTreeHostManager::GetPrimaryRootWindow() { | 332 aura::Window* WindowTreeHostManager::GetPrimaryRootWindow() { |
| 332 return GetRootWindowForDisplayId(primary_display_id); | 333 return GetRootWindowForDisplayId(primary_display_id); |
| 333 } | 334 } |
| 334 | 335 |
| 335 aura::Window* WindowTreeHostManager::GetRootWindowForDisplayId(int64_t id) { | 336 aura::Window* WindowTreeHostManager::GetRootWindowForDisplayId(int64_t id) { |
| 336 AshWindowTreeHost* host = GetAshWindowTreeHostForDisplayId(id); | 337 AshWindowTreeHost* host = GetAshWindowTreeHostForDisplayId(id); |
| 337 return host ? GetWindow(host) : nullptr; | 338 return host ? GetWindow(host) : nullptr; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 RootWindowController* controller = | 389 RootWindowController* controller = |
| 389 GetRootWindowController(GetWindow(it->second)); | 390 GetRootWindowController(GetWindow(it->second)); |
| 390 if (controller) | 391 if (controller) |
| 391 controllers.push_back(controller); | 392 controllers.push_back(controller); |
| 392 } | 393 } |
| 393 return controllers; | 394 return controllers; |
| 394 } | 395 } |
| 395 | 396 |
| 396 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { | 397 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { |
| 397 // TODO(oshima): Move primary display management to DisplayManager. | 398 // TODO(oshima): Move primary display management to DisplayManager. |
| 398 DCHECK_NE(display::Display::kInvalidDisplayID, id); | 399 DCHECK_NE(display::kInvalidDisplayId, id); |
| 399 if (id == display::Display::kInvalidDisplayID || primary_display_id == id || | 400 if (id == display::kInvalidDisplayId || primary_display_id == id || |
| 400 window_tree_hosts_.size() < 2) { | 401 window_tree_hosts_.size() < 2) { |
| 401 return; | 402 return; |
| 402 } | 403 } |
| 403 // TODO(oshima): Implement swapping primary for 2> displays. | 404 // TODO(oshima): Implement swapping primary for 2> displays. |
| 404 if (GetDisplayManager()->GetNumDisplays() > 2) | 405 if (GetDisplayManager()->GetNumDisplays() > 2) |
| 405 return; | 406 return; |
| 406 | 407 |
| 407 const display::Display& new_primary_display = | 408 const display::Display& new_primary_display = |
| 408 GetDisplayManager()->GetDisplayForId(id); | 409 GetDisplayManager()->GetDisplayForId(id); |
| 409 if (!new_primary_display.is_valid()) { | 410 if (!new_primary_display.is_valid()) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 dst_root_window->MoveCursorTo(target_location_in_root); | 555 dst_root_window->MoveCursorTo(target_location_in_root); |
| 555 #endif | 556 #endif |
| 556 } | 557 } |
| 557 | 558 |
| 558 bool WindowTreeHostManager::UpdateWorkAreaOfDisplayNearestWindow( | 559 bool WindowTreeHostManager::UpdateWorkAreaOfDisplayNearestWindow( |
| 559 const aura::Window* window, | 560 const aura::Window* window, |
| 560 const gfx::Insets& insets) { | 561 const gfx::Insets& insets) { |
| 561 const aura::Window* root_window = window->GetRootWindow(); | 562 const aura::Window* root_window = window->GetRootWindow(); |
| 562 int64_t id = GetRootWindowSettings(root_window)->display_id; | 563 int64_t id = GetRootWindowSettings(root_window)->display_id; |
| 563 // if id is |kInvaildDisplayID|, it's being deleted. | 564 // if id is |kInvaildDisplayID|, it's being deleted. |
| 564 DCHECK(id != display::Display::kInvalidDisplayID); | 565 DCHECK(id != display::kInvalidDisplayId); |
| 565 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 566 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
| 566 } | 567 } |
| 567 | 568 |
| 568 void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) { | 569 void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) { |
| 569 #if defined(OS_CHROMEOS) | 570 #if defined(OS_CHROMEOS) |
| 570 // If we're switching from/to offscreen WTH, we need to | 571 // If we're switching from/to offscreen WTH, we need to |
| 571 // create new WTH for primary display instead of reusing. | 572 // create new WTH for primary display instead of reusing. |
| 572 if (primary_tree_host_for_replace_ && | 573 if (primary_tree_host_for_replace_ && |
| 573 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 574 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
| 574 ->display_id == display::DisplayManager::kUnifiedDisplayId || | 575 ->display_id == display::DisplayManager::kUnifiedDisplayId || |
| 575 display.id() == display::DisplayManager::kUnifiedDisplayId)) { | 576 display.id() == display::DisplayManager::kUnifiedDisplayId)) { |
| 576 DCHECK_EQ(display::Display::kInvalidDisplayID, primary_display_id); | 577 DCHECK_EQ(display::kInvalidDisplayId, primary_display_id); |
| 577 primary_display_id = display.id(); | 578 primary_display_id = display.id(); |
| 578 | 579 |
| 579 AshWindowTreeHost* ash_host = | 580 AshWindowTreeHost* ash_host = |
| 580 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); | 581 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
| 581 RootWindowController::CreateForSecondaryDisplay(ash_host); | 582 RootWindowController::CreateForSecondaryDisplay(ash_host); |
| 582 | 583 |
| 583 // Magnifier controllers keep pointers to the current root window. | 584 // Magnifier controllers keep pointers to the current root window. |
| 584 // Update them here to avoid accessing them later. | 585 // Update them here to avoid accessing them later. |
| 585 Shell::GetInstance()->magnification_controller()->SwitchTargetRootWindow( | 586 Shell::GetInstance()->magnification_controller()->SwitchTargetRootWindow( |
| 586 ash_host->AsWindowTreeHost()->window(), false); | 587 ash_host->AsWindowTreeHost()->window(), false); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; | 626 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
| 626 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 627 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
| 627 ->display_id = display.id(); | 628 ->display_id = display.id(); |
| 628 primary_tree_host_for_replace_ = nullptr; | 629 primary_tree_host_for_replace_ = nullptr; |
| 629 const display::ManagedDisplayInfo& display_info = | 630 const display::ManagedDisplayInfo& display_info = |
| 630 GetDisplayManager()->GetDisplayInfo(display.id()); | 631 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 631 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 632 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
| 632 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 633 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
| 633 SetDisplayPropertiesOnHost(ash_host, display); | 634 SetDisplayPropertiesOnHost(ash_host, display); |
| 634 } else { | 635 } else { |
| 635 if (primary_display_id == display::Display::kInvalidDisplayID) | 636 if (primary_display_id == display::kInvalidDisplayId) |
| 636 primary_display_id = display.id(); | 637 primary_display_id = display.id(); |
| 637 DCHECK(!window_tree_hosts_.empty()); | 638 DCHECK(!window_tree_hosts_.empty()); |
| 638 AshWindowTreeHost* ash_host = | 639 AshWindowTreeHost* ash_host = |
| 639 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); | 640 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
| 640 RootWindowController::CreateForSecondaryDisplay(ash_host); | 641 RootWindowController::CreateForSecondaryDisplay(ash_host); |
| 641 } | 642 } |
| 642 } | 643 } |
| 643 | 644 |
| 644 void WindowTreeHostManager::DeleteHost(AshWindowTreeHost* host_to_delete) { | 645 void WindowTreeHostManager::DeleteHost(AshWindowTreeHost* host_to_delete) { |
| 645 ClearDisplayPropertiesOnHost(host_to_delete); | 646 ClearDisplayPropertiesOnHost(host_to_delete); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 656 void WindowTreeHostManager::OnDisplayRemoved(const display::Display& display) { | 657 void WindowTreeHostManager::OnDisplayRemoved(const display::Display& display) { |
| 657 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; | 658 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; |
| 658 CHECK(host_to_delete) << display.ToString(); | 659 CHECK(host_to_delete) << display.ToString(); |
| 659 | 660 |
| 660 // When the primary root window's display is removed, move the primary | 661 // When the primary root window's display is removed, move the primary |
| 661 // root to the other display. | 662 // root to the other display. |
| 662 if (primary_display_id == display.id()) { | 663 if (primary_display_id == display.id()) { |
| 663 // Temporarily store the primary root window in | 664 // Temporarily store the primary root window in |
| 664 // |primary_root_window_for_replace_| when replacing the display. | 665 // |primary_root_window_for_replace_| when replacing the display. |
| 665 if (window_tree_hosts_.size() == 1) { | 666 if (window_tree_hosts_.size() == 1) { |
| 666 primary_display_id = display::Display::kInvalidDisplayID; | 667 primary_display_id = display::kInvalidDisplayId; |
| 667 primary_tree_host_for_replace_ = host_to_delete; | 668 primary_tree_host_for_replace_ = host_to_delete; |
| 668 // Display for root window will be deleted when the Primary RootWindow | 669 // Display for root window will be deleted when the Primary RootWindow |
| 669 // is deleted by the Shell. | 670 // is deleted by the Shell. |
| 670 window_tree_hosts_.erase(display.id()); | 671 window_tree_hosts_.erase(display.id()); |
| 671 return; | 672 return; |
| 672 } | 673 } |
| 673 for (const auto& pair : window_tree_hosts_) { | 674 for (const auto& pair : window_tree_hosts_) { |
| 674 if (pair.first != display.id()) { | 675 if (pair.first != display.id()) { |
| 675 primary_display_id = pair.first; | 676 primary_display_id = pair.first; |
| 676 break; | 677 break; |
| 677 } | 678 } |
| 678 } | 679 } |
| 679 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id); | 680 CHECK_NE(display::kInvalidDisplayId, primary_display_id); |
| 680 | 681 |
| 681 AshWindowTreeHost* primary_host = host_to_delete; | 682 AshWindowTreeHost* primary_host = host_to_delete; |
| 682 // Delete the other host instead. | 683 // Delete the other host instead. |
| 683 host_to_delete = window_tree_hosts_[primary_display_id]; | 684 host_to_delete = window_tree_hosts_[primary_display_id]; |
| 684 GetRootWindowSettings(GetWindow(host_to_delete))->display_id = display.id(); | 685 GetRootWindowSettings(GetWindow(host_to_delete))->display_id = display.id(); |
| 685 | 686 |
| 686 // Setup primary root. | 687 // Setup primary root. |
| 687 window_tree_hosts_[primary_display_id] = primary_host; | 688 window_tree_hosts_[primary_display_id] = primary_host; |
| 688 GetRootWindowSettings(GetWindow(primary_host))->display_id = | 689 GetRootWindowSettings(GetWindow(primary_host))->display_id = |
| 689 primary_display_id; | 690 primary_display_id; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 773 |
| 773 display::DisplayManager* display_manager = GetDisplayManager(); | 774 display::DisplayManager* display_manager = GetDisplayManager(); |
| 774 display::DisplayLayoutStore* layout_store = display_manager->layout_store(); | 775 display::DisplayLayoutStore* layout_store = display_manager->layout_store(); |
| 775 if (display_manager->num_connected_displays() > 1) { | 776 if (display_manager->num_connected_displays() > 1) { |
| 776 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | 777 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); |
| 777 const display::DisplayLayout& layout = | 778 const display::DisplayLayout& layout = |
| 778 layout_store->GetRegisteredDisplayLayout(list); | 779 layout_store->GetRegisteredDisplayLayout(list); |
| 779 layout_store->UpdateMultiDisplayState( | 780 layout_store->UpdateMultiDisplayState( |
| 780 list, display_manager->IsInMirrorMode(), layout.default_unified); | 781 list, display_manager->IsInMirrorMode(), layout.default_unified); |
| 781 if (display::Screen::GetScreen()->GetNumDisplays() > 1) { | 782 if (display::Screen::GetScreen()->GetNumDisplays() > 1) { |
| 782 SetPrimaryDisplayId(layout.primary_id == | 783 SetPrimaryDisplayId(layout.primary_id == display::kInvalidDisplayId |
| 783 display::Display::kInvalidDisplayID | |
| 784 ? list[0] | 784 ? list[0] |
| 785 : layout.primary_id); | 785 : layout.primary_id); |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 for (const display::Display& display : | 789 for (const display::Display& display : |
| 790 display_manager->active_display_list()) { | 790 display_manager->active_display_list()) { |
| 791 bool output_is_secure = | 791 bool output_is_secure = |
| 792 !display_manager->IsInMirrorMode() && display.IsInternal(); | 792 !display_manager->IsInMirrorMode() && display.IsInternal(); |
| 793 GetAshWindowTreeHostForDisplayId(display.id()) | 793 GetAshWindowTreeHostForDisplayId(display.id()) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 SetDisplayPropertiesOnHost(ash_host, display); | 870 SetDisplayPropertiesOnHost(ash_host, display); |
| 871 | 871 |
| 872 #if defined(OS_CHROMEOS) | 872 #if defined(OS_CHROMEOS) |
| 873 if (switches::ConstrainPointerToRoot()) | 873 if (switches::ConstrainPointerToRoot()) |
| 874 ash_host->ConfineCursorToRootWindow(); | 874 ash_host->ConfineCursorToRootWindow(); |
| 875 #endif | 875 #endif |
| 876 return ash_host; | 876 return ash_host; |
| 877 } | 877 } |
| 878 | 878 |
| 879 } // namespace ash | 879 } // namespace ash |
| OLD | NEW |