| 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 <utility> | 10 #include <utility> |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), | 239 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), |
| 240 weak_ptr_factory_(this) { | 240 weak_ptr_factory_(this) { |
| 241 // Reset primary display to make sure that tests don't use | 241 // Reset primary display to make sure that tests don't use |
| 242 // stale display info from previous tests. | 242 // stale display info from previous tests. |
| 243 primary_display_id = gfx::Display::kInvalidDisplayID; | 243 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 244 } | 244 } |
| 245 | 245 |
| 246 WindowTreeHostManager::~WindowTreeHostManager() {} | 246 WindowTreeHostManager::~WindowTreeHostManager() {} |
| 247 | 247 |
| 248 void WindowTreeHostManager::Start() { | 248 void WindowTreeHostManager::Start() { |
| 249 Shell::GetScreen()->AddObserver(this); | 249 gfx::Screen::GetScreen()->AddObserver(this); |
| 250 Shell::GetInstance()->display_manager()->set_delegate(this); | 250 Shell::GetInstance()->display_manager()->set_delegate(this); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void WindowTreeHostManager::Shutdown() { | 253 void WindowTreeHostManager::Shutdown() { |
| 254 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown()); | 254 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown()); |
| 255 | 255 |
| 256 // Unset the display manager's delegate here because | 256 // Unset the display manager's delegate here because |
| 257 // DisplayManager outlives WindowTreeHostManager. | 257 // DisplayManager outlives WindowTreeHostManager. |
| 258 Shell::GetInstance()->display_manager()->set_delegate(nullptr); | 258 Shell::GetInstance()->display_manager()->set_delegate(nullptr); |
| 259 | 259 |
| 260 cursor_window_controller_.reset(); | 260 cursor_window_controller_.reset(); |
| 261 mirror_window_controller_.reset(); | 261 mirror_window_controller_.reset(); |
| 262 | 262 |
| 263 Shell::GetScreen()->RemoveObserver(this); | 263 gfx::Screen::GetScreen()->RemoveObserver(this); |
| 264 | 264 |
| 265 int64_t primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); | 265 int64_t primary_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 266 | 266 |
| 267 // Delete non primary root window controllers first, then | 267 // Delete non primary root window controllers first, then |
| 268 // delete the primary root window controller. | 268 // delete the primary root window controller. |
| 269 aura::Window::Windows root_windows = | 269 aura::Window::Windows root_windows = |
| 270 WindowTreeHostManager::GetAllRootWindows(); | 270 WindowTreeHostManager::GetAllRootWindows(); |
| 271 std::vector<RootWindowController*> to_delete; | 271 std::vector<RootWindowController*> to_delete; |
| 272 RootWindowController* primary_rwc = nullptr; | 272 RootWindowController* primary_rwc = nullptr; |
| 273 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 273 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
| 274 iter != root_windows.end(); ++iter) { | 274 iter != root_windows.end(); ++iter) { |
| 275 RootWindowController* rwc = GetRootWindowController(*iter); | 275 RootWindowController* rwc = GetRootWindowController(*iter); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 it != window_tree_hosts_.end(); ++it) { | 384 it != window_tree_hosts_.end(); ++it) { |
| 385 RootWindowController* controller = | 385 RootWindowController* controller = |
| 386 GetRootWindowController(GetWindow(it->second)); | 386 GetRootWindowController(GetWindow(it->second)); |
| 387 if (controller) | 387 if (controller) |
| 388 controllers.push_back(controller); | 388 controllers.push_back(controller); |
| 389 } | 389 } |
| 390 return controllers; | 390 return controllers; |
| 391 } | 391 } |
| 392 | 392 |
| 393 void WindowTreeHostManager::SwapPrimaryDisplayForTest() { | 393 void WindowTreeHostManager::SwapPrimaryDisplayForTest() { |
| 394 if (Shell::GetScreen()->GetNumDisplays() <= 1) | 394 if (gfx::Screen::GetScreen()->GetNumDisplays() <= 1) |
| 395 return; | 395 return; |
| 396 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 396 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { | 399 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { |
| 400 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); | 400 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); |
| 401 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) | 401 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) |
| 402 return; | 402 return; |
| 403 | 403 |
| 404 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); | 404 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 425 } | 425 } |
| 426 | 426 |
| 427 AshWindowTreeHost* non_primary_host = | 427 AshWindowTreeHost* non_primary_host = |
| 428 window_tree_hosts_[new_primary_display.id()]; | 428 window_tree_hosts_[new_primary_display.id()]; |
| 429 LOG_IF(ERROR, !non_primary_host) | 429 LOG_IF(ERROR, !non_primary_host) |
| 430 << "Unknown display is requested in SetPrimaryDisplay: id=" | 430 << "Unknown display is requested in SetPrimaryDisplay: id=" |
| 431 << new_primary_display.id(); | 431 << new_primary_display.id(); |
| 432 if (!non_primary_host) | 432 if (!non_primary_host) |
| 433 return; | 433 return; |
| 434 | 434 |
| 435 gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 435 gfx::Display old_primary_display = |
| 436 gfx::Screen::GetScreen()->GetPrimaryDisplay(); |
| 436 | 437 |
| 437 // Swap root windows between current and new primary display. | 438 // Swap root windows between current and new primary display. |
| 438 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; | 439 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; |
| 439 CHECK(primary_host); | 440 CHECK(primary_host); |
| 440 CHECK_NE(primary_host, non_primary_host); | 441 CHECK_NE(primary_host, non_primary_host); |
| 441 | 442 |
| 442 window_tree_hosts_[new_primary_display.id()] = primary_host; | 443 window_tree_hosts_[new_primary_display.id()] = primary_host; |
| 443 GetRootWindowSettings(GetWindow(primary_host))->display_id = | 444 GetRootWindowSettings(GetWindow(primary_host))->display_id = |
| 444 new_primary_display.id(); | 445 new_primary_display.id(); |
| 445 | 446 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 460 GetDisplayManager()->set_force_bounds_changed(true); | 461 GetDisplayManager()->set_force_bounds_changed(true); |
| 461 GetDisplayManager()->UpdateDisplays(); | 462 GetDisplayManager()->UpdateDisplays(); |
| 462 GetDisplayManager()->set_force_bounds_changed(false); | 463 GetDisplayManager()->set_force_bounds_changed(false); |
| 463 } | 464 } |
| 464 | 465 |
| 465 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() { | 466 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() { |
| 466 // If the mouse is currently on a display in native location, | 467 // If the mouse is currently on a display in native location, |
| 467 // use the same native location. Otherwise find the display closest | 468 // use the same native location. Otherwise find the display closest |
| 468 // to the current cursor location in screen coordinates. | 469 // to the current cursor location in screen coordinates. |
| 469 | 470 |
| 470 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 471 gfx::Point point_in_screen = gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
| 471 gfx::Point target_location_in_native; | 472 gfx::Point target_location_in_native; |
| 472 int64_t closest_distance_squared = -1; | 473 int64_t closest_distance_squared = -1; |
| 473 DisplayManager* display_manager = GetDisplayManager(); | 474 DisplayManager* display_manager = GetDisplayManager(); |
| 474 | 475 |
| 475 aura::Window* dst_root_window = nullptr; | 476 aura::Window* dst_root_window = nullptr; |
| 476 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 477 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 477 const gfx::Display& display = display_manager->GetDisplayAt(i); | 478 const gfx::Display& display = display_manager->GetDisplayAt(i); |
| 478 const DisplayInfo display_info = | 479 const DisplayInfo display_info = |
| 479 display_manager->GetDisplayInfo(display.id()); | 480 display_manager->GetDisplayInfo(display.id()); |
| 480 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 481 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return; | 701 return; |
| 701 const DisplayInfo& display_info = | 702 const DisplayInfo& display_info = |
| 702 GetDisplayManager()->GetDisplayInfo(display.id()); | 703 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 703 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 704 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
| 704 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 705 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
| 705 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 706 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
| 706 SetDisplayPropertiesOnHost(ash_host, display); | 707 SetDisplayPropertiesOnHost(ash_host, display); |
| 707 } | 708 } |
| 708 | 709 |
| 709 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { | 710 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { |
| 710 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 711 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayNearestWindow( |
| 711 const_cast<aura::Window*>(host->window())); | 712 const_cast<aura::Window*>(host->window())); |
| 712 | 713 |
| 713 DisplayManager* display_manager = GetDisplayManager(); | 714 DisplayManager* display_manager = GetDisplayManager(); |
| 714 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { | 715 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { |
| 715 mirror_window_controller_->UpdateWindow(); | 716 mirror_window_controller_->UpdateWindow(); |
| 716 cursor_window_controller_->UpdateContainer(); | 717 cursor_window_controller_->UpdateContainer(); |
| 717 } | 718 } |
| 718 } | 719 } |
| 719 | 720 |
| 720 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay( | 721 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 734 // always on the desktop display (the visible cursor on the non-desktop | 735 // always on the desktop display (the visible cursor on the non-desktop |
| 735 // display is drawn through compositor mirroring). Therefore, it's unnecessary | 736 // display is drawn through compositor mirroring). Therefore, it's unnecessary |
| 736 // to handle the cursor_window at all. See: http://crbug.com/412910 | 737 // to handle the cursor_window at all. See: http://crbug.com/412910 |
| 737 if (!cursor_window_controller_->is_cursor_compositing_enabled()) | 738 if (!cursor_window_controller_->is_cursor_compositing_enabled()) |
| 738 cursor_window_controller_->UpdateContainer(); | 739 cursor_window_controller_->UpdateContainer(); |
| 739 } | 740 } |
| 740 | 741 |
| 741 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) { | 742 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) { |
| 742 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 743 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 743 focus_activation_store_->Store(clear_focus); | 744 focus_activation_store_->Store(clear_focus); |
| 744 gfx::Screen* screen = Shell::GetScreen(); | 745 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 745 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); | 746 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
| 746 cursor_location_in_screen_coords_for_restore_ = point_in_screen; | 747 cursor_location_in_screen_coords_for_restore_ = point_in_screen; |
| 747 | 748 |
| 748 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 749 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
| 749 cursor_display_id_for_restore_ = display.id(); | 750 cursor_display_id_for_restore_ = display.id(); |
| 750 | 751 |
| 751 gfx::Point point_in_native = point_in_screen; | 752 gfx::Point point_in_native = point_in_screen; |
| 752 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 753 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
| 753 ::wm::ConvertPointFromScreen(root_window, &point_in_native); | 754 ::wm::ConvertPointFromScreen(root_window, &point_in_native); |
| 754 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); | 755 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); |
| 755 cursor_location_in_native_coords_for_restore_ = point_in_native; | 756 cursor_location_in_native_coords_for_restore_ = point_in_native; |
| 756 } | 757 } |
| 757 | 758 |
| 758 void WindowTreeHostManager::PostDisplayConfigurationChange() { | 759 void WindowTreeHostManager::PostDisplayConfigurationChange() { |
| 759 focus_activation_store_->Restore(); | 760 focus_activation_store_->Restore(); |
| 760 | 761 |
| 761 DisplayManager* display_manager = GetDisplayManager(); | 762 DisplayManager* display_manager = GetDisplayManager(); |
| 762 DisplayLayoutStore* layout_store = display_manager->layout_store(); | 763 DisplayLayoutStore* layout_store = display_manager->layout_store(); |
| 763 if (display_manager->num_connected_displays() > 1) { | 764 if (display_manager->num_connected_displays() > 1) { |
| 764 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); | 765 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
| 765 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); | 766 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); |
| 766 layout_store->UpdateMultiDisplayState( | 767 layout_store->UpdateMultiDisplayState( |
| 767 pair, display_manager->IsInMirrorMode(), layout.default_unified); | 768 pair, display_manager->IsInMirrorMode(), layout.default_unified); |
| 768 | 769 |
| 769 if (Shell::GetScreen()->GetNumDisplays() > 1) { | 770 if (gfx::Screen::GetScreen()->GetNumDisplays() > 1) { |
| 770 int64_t primary_id = layout.primary_id; | 771 int64_t primary_id = layout.primary_id; |
| 771 SetPrimaryDisplayId(primary_id == gfx::Display::kInvalidDisplayID | 772 SetPrimaryDisplayId(primary_id == gfx::Display::kInvalidDisplayID |
| 772 ? pair.first | 773 ? pair.first |
| 773 : primary_id); | 774 : primary_id); |
| 774 // Update the primary_id in case the above call is | 775 // Update the primary_id in case the above call is |
| 775 // ignored. Happens when a) default layout's primary id | 776 // ignored. Happens when a) default layout's primary id |
| 776 // doesn't exist, or b) the primary_id has already been | 777 // doesn't exist, or b) the primary_id has already been |
| 777 // set to the same and didn't update it. | 778 // set to the same and didn't update it. |
| 778 layout_store->UpdatePrimaryDisplayId( | 779 layout_store->UpdatePrimaryDisplayId( |
| 779 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); | 780 pair, gfx::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 780 } | 781 } |
| 781 } | 782 } |
| 782 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 783 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
| 783 UpdateMouseLocationAfterDisplayChange(); | 784 UpdateMouseLocationAfterDisplayChange(); |
| 784 } | 785 } |
| 785 | 786 |
| 786 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( | 787 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( |
| 787 ui::KeyEvent* event) { | 788 ui::KeyEvent* event) { |
| 788 // Getting the active root window to dispatch the event. This isn't | 789 // Getting the active root window to dispatch the event. This isn't |
| 789 // significant as the event will be sent to the window resolved by | 790 // significant as the event will be sent to the window resolved by |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 SetDisplayPropertiesOnHost(ash_host, display); | 834 SetDisplayPropertiesOnHost(ash_host, display); |
| 834 | 835 |
| 835 #if defined(OS_CHROMEOS) | 836 #if defined(OS_CHROMEOS) |
| 836 if (switches::ConstrainPointerToRoot()) | 837 if (switches::ConstrainPointerToRoot()) |
| 837 ash_host->ConfineCursorToRootWindow(); | 838 ash_host->ConfineCursorToRootWindow(); |
| 838 #endif | 839 #endif |
| 839 return ash_host; | 840 return ash_host; |
| 840 } | 841 } |
| 841 | 842 |
| 842 } // namespace ash | 843 } // namespace ash |
| OLD | NEW |