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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 limiter_.reset(new DisplayChangeLimiter); | 275 limiter_.reset(new DisplayChangeLimiter); |
276 #endif | 276 #endif |
277 // Reset primary display to make sure that tests don't use | 277 // Reset primary display to make sure that tests don't use |
278 // stale display info from previous tests. | 278 // stale display info from previous tests. |
279 primary_display_id = gfx::Display::kInvalidDisplayID; | 279 primary_display_id = gfx::Display::kInvalidDisplayID; |
280 } | 280 } |
281 | 281 |
282 WindowTreeHostManager::~WindowTreeHostManager() {} | 282 WindowTreeHostManager::~WindowTreeHostManager() {} |
283 | 283 |
284 void WindowTreeHostManager::Start() { | 284 void WindowTreeHostManager::Start() { |
285 Shell::GetScreen()->AddObserver(this); | 285 gfx::Screen::GetScreen()->AddObserver(this); |
286 Shell::GetInstance()->display_manager()->set_delegate(this); | 286 Shell::GetInstance()->display_manager()->set_delegate(this); |
287 } | 287 } |
288 | 288 |
289 void WindowTreeHostManager::Shutdown() { | 289 void WindowTreeHostManager::Shutdown() { |
290 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown()); | 290 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown()); |
291 | 291 |
292 // Unset the display manager's delegate here because | 292 // Unset the display manager's delegate here because |
293 // DisplayManager outlives WindowTreeHostManager. | 293 // DisplayManager outlives WindowTreeHostManager. |
294 Shell::GetInstance()->display_manager()->set_delegate(nullptr); | 294 Shell::GetInstance()->display_manager()->set_delegate(nullptr); |
295 | 295 |
296 cursor_window_controller_.reset(); | 296 cursor_window_controller_.reset(); |
297 mirror_window_controller_.reset(); | 297 mirror_window_controller_.reset(); |
298 | 298 |
299 Shell::GetScreen()->RemoveObserver(this); | 299 gfx::Screen::GetScreen()->RemoveObserver(this); |
300 | 300 |
301 int64_t primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); | 301 int64_t primary_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); |
302 | 302 |
303 // Delete non primary root window controllers first, then | 303 // Delete non primary root window controllers first, then |
304 // delete the primary root window controller. | 304 // delete the primary root window controller. |
305 aura::Window::Windows root_windows = | 305 aura::Window::Windows root_windows = |
306 WindowTreeHostManager::GetAllRootWindows(); | 306 WindowTreeHostManager::GetAllRootWindows(); |
307 std::vector<RootWindowController*> to_delete; | 307 std::vector<RootWindowController*> to_delete; |
308 RootWindowController* primary_rwc = nullptr; | 308 RootWindowController* primary_rwc = nullptr; |
309 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 309 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
310 iter != root_windows.end(); ++iter) { | 310 iter != root_windows.end(); ++iter) { |
311 RootWindowController* rwc = GetRootWindowController(*iter); | 311 RootWindowController* rwc = GetRootWindowController(*iter); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 #endif | 445 #endif |
446 } | 446 } |
447 | 447 |
448 void WindowTreeHostManager::SwapPrimaryDisplay() { | 448 void WindowTreeHostManager::SwapPrimaryDisplay() { |
449 if (limiter_) { | 449 if (limiter_) { |
450 if (limiter_->IsThrottled()) | 450 if (limiter_->IsThrottled()) |
451 return; | 451 return; |
452 limiter_->SetThrottleTimeout(kSwapDisplayThrottleTimeoutMs); | 452 limiter_->SetThrottleTimeout(kSwapDisplayThrottleTimeoutMs); |
453 } | 453 } |
454 | 454 |
455 if (Shell::GetScreen()->GetNumDisplays() > 1) { | 455 if (gfx::Screen::GetScreen()->GetNumDisplays() > 1) { |
456 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
457 DisplayAnimator* animation = Shell::GetInstance()->display_animator(); | 457 DisplayAnimator* animation = Shell::GetInstance()->display_animator(); |
458 if (animation) { | 458 if (animation) { |
459 animation->StartFadeOutAnimation( | 459 animation->StartFadeOutAnimation( |
460 base::Bind(&WindowTreeHostManager::OnFadeOutForSwapDisplayFinished, | 460 base::Bind(&WindowTreeHostManager::OnFadeOutForSwapDisplayFinished, |
461 weak_ptr_factory_.GetWeakPtr())); | 461 weak_ptr_factory_.GetWeakPtr())); |
462 } else { | 462 } else { |
463 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 463 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
464 } | 464 } |
465 #else | 465 #else |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 } | 497 } |
498 | 498 |
499 AshWindowTreeHost* non_primary_host = | 499 AshWindowTreeHost* non_primary_host = |
500 window_tree_hosts_[new_primary_display.id()]; | 500 window_tree_hosts_[new_primary_display.id()]; |
501 LOG_IF(ERROR, !non_primary_host) | 501 LOG_IF(ERROR, !non_primary_host) |
502 << "Unknown display is requested in SetPrimaryDisplay: id=" | 502 << "Unknown display is requested in SetPrimaryDisplay: id=" |
503 << new_primary_display.id(); | 503 << new_primary_display.id(); |
504 if (!non_primary_host) | 504 if (!non_primary_host) |
505 return; | 505 return; |
506 | 506 |
507 gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 507 gfx::Display old_primary_display = |
| 508 gfx::Screen::GetScreen()->GetPrimaryDisplay(); |
508 | 509 |
509 // Swap root windows between current and new primary display. | 510 // Swap root windows between current and new primary display. |
510 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; | 511 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; |
511 CHECK(primary_host); | 512 CHECK(primary_host); |
512 CHECK_NE(primary_host, non_primary_host); | 513 CHECK_NE(primary_host, non_primary_host); |
513 | 514 |
514 window_tree_hosts_[new_primary_display.id()] = primary_host; | 515 window_tree_hosts_[new_primary_display.id()] = primary_host; |
515 GetRootWindowSettings(GetWindow(primary_host))->display_id = | 516 GetRootWindowSettings(GetWindow(primary_host))->display_id = |
516 new_primary_display.id(); | 517 new_primary_display.id(); |
517 | 518 |
(...skipping 19 matching lines...) Expand all Loading... |
537 GetDisplayManager()->set_force_bounds_changed(true); | 538 GetDisplayManager()->set_force_bounds_changed(true); |
538 GetDisplayManager()->UpdateDisplays(display_info_list); | 539 GetDisplayManager()->UpdateDisplays(display_info_list); |
539 GetDisplayManager()->set_force_bounds_changed(false); | 540 GetDisplayManager()->set_force_bounds_changed(false); |
540 } | 541 } |
541 | 542 |
542 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() { | 543 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() { |
543 // If the mouse is currently on a display in native location, | 544 // If the mouse is currently on a display in native location, |
544 // use the same native location. Otherwise find the display closest | 545 // use the same native location. Otherwise find the display closest |
545 // to the current cursor location in screen coordinates. | 546 // to the current cursor location in screen coordinates. |
546 | 547 |
547 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 548 gfx::Point point_in_screen = gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
548 gfx::Point target_location_in_native; | 549 gfx::Point target_location_in_native; |
549 int64_t closest_distance_squared = -1; | 550 int64_t closest_distance_squared = -1; |
550 DisplayManager* display_manager = GetDisplayManager(); | 551 DisplayManager* display_manager = GetDisplayManager(); |
551 | 552 |
552 aura::Window* dst_root_window = nullptr; | 553 aura::Window* dst_root_window = nullptr; |
553 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 554 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
554 const gfx::Display& display = display_manager->GetDisplayAt(i); | 555 const gfx::Display& display = display_manager->GetDisplayAt(i); |
555 const DisplayInfo display_info = | 556 const DisplayInfo display_info = |
556 display_manager->GetDisplayInfo(display.id()); | 557 display_manager->GetDisplayInfo(display.id()); |
557 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 558 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 return; | 778 return; |
778 const DisplayInfo& display_info = | 779 const DisplayInfo& display_info = |
779 GetDisplayManager()->GetDisplayInfo(display.id()); | 780 GetDisplayManager()->GetDisplayInfo(display.id()); |
780 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 781 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
781 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 782 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
782 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 783 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
783 SetDisplayPropertiesOnHost(ash_host, display); | 784 SetDisplayPropertiesOnHost(ash_host, display); |
784 } | 785 } |
785 | 786 |
786 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { | 787 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { |
787 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 788 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayNearestWindow( |
788 const_cast<aura::Window*>(host->window())); | 789 const_cast<aura::Window*>(host->window())); |
789 | 790 |
790 DisplayManager* display_manager = GetDisplayManager(); | 791 DisplayManager* display_manager = GetDisplayManager(); |
791 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { | 792 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { |
792 mirror_window_controller_->UpdateWindow(); | 793 mirror_window_controller_->UpdateWindow(); |
793 cursor_window_controller_->UpdateContainer(); | 794 cursor_window_controller_->UpdateContainer(); |
794 } | 795 } |
795 } | 796 } |
796 | 797 |
797 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay( | 798 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay( |
(...skipping 13 matching lines...) Expand all Loading... |
811 // always on the desktop display (the visible cursor on the non-desktop | 812 // always on the desktop display (the visible cursor on the non-desktop |
812 // display is drawn through compositor mirroring). Therefore, it's unnecessary | 813 // display is drawn through compositor mirroring). Therefore, it's unnecessary |
813 // to handle the cursor_window at all. See: http://crbug.com/412910 | 814 // to handle the cursor_window at all. See: http://crbug.com/412910 |
814 if (!cursor_window_controller_->is_cursor_compositing_enabled()) | 815 if (!cursor_window_controller_->is_cursor_compositing_enabled()) |
815 cursor_window_controller_->UpdateContainer(); | 816 cursor_window_controller_->UpdateContainer(); |
816 } | 817 } |
817 | 818 |
818 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) { | 819 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) { |
819 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 820 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
820 focus_activation_store_->Store(clear_focus); | 821 focus_activation_store_->Store(clear_focus); |
821 gfx::Screen* screen = Shell::GetScreen(); | 822 gfx::Screen* screen = gfx::Screen::GetScreen(); |
822 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); | 823 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
823 cursor_location_in_screen_coords_for_restore_ = point_in_screen; | 824 cursor_location_in_screen_coords_for_restore_ = point_in_screen; |
824 | 825 |
825 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 826 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
826 cursor_display_id_for_restore_ = display.id(); | 827 cursor_display_id_for_restore_ = display.id(); |
827 | 828 |
828 gfx::Point point_in_native = point_in_screen; | 829 gfx::Point point_in_native = point_in_screen; |
829 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 830 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
830 ::wm::ConvertPointFromScreen(root_window, &point_in_native); | 831 ::wm::ConvertPointFromScreen(root_window, &point_in_native); |
831 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); | 832 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); |
832 cursor_location_in_native_coords_for_restore_ = point_in_native; | 833 cursor_location_in_native_coords_for_restore_ = point_in_native; |
833 } | 834 } |
834 | 835 |
835 void WindowTreeHostManager::PostDisplayConfigurationChange() { | 836 void WindowTreeHostManager::PostDisplayConfigurationChange() { |
836 if (limiter_) | 837 if (limiter_) |
837 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 838 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
838 | 839 |
839 focus_activation_store_->Restore(); | 840 focus_activation_store_->Restore(); |
840 | 841 |
841 DisplayManager* display_manager = GetDisplayManager(); | 842 DisplayManager* display_manager = GetDisplayManager(); |
842 DisplayLayoutStore* layout_store = display_manager->layout_store(); | 843 DisplayLayoutStore* layout_store = display_manager->layout_store(); |
843 if (display_manager->num_connected_displays() > 1) { | 844 if (display_manager->num_connected_displays() > 1) { |
844 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); | 845 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
845 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); | 846 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); |
846 layout_store->UpdateMultiDisplayState( | 847 layout_store->UpdateMultiDisplayState( |
847 pair, display_manager->IsInMirrorMode(), layout.default_unified); | 848 pair, display_manager->IsInMirrorMode(), layout.default_unified); |
848 | 849 |
849 if (Shell::GetScreen()->GetNumDisplays() > 1) { | 850 if (gfx::Screen::GetScreen()->GetNumDisplays() > 1) { |
850 int64_t primary_id = layout.primary_id; | 851 int64_t primary_id = layout.primary_id; |
851 SetPrimaryDisplayId(primary_id == gfx::Display::kInvalidDisplayID | 852 SetPrimaryDisplayId(primary_id == gfx::Display::kInvalidDisplayID |
852 ? pair.first | 853 ? pair.first |
853 : primary_id); | 854 : primary_id); |
854 // Update the primary_id in case the above call is | 855 // Update the primary_id in case the above call is |
855 // ignored. Happens when a) default layout's primary id | 856 // ignored. Happens when a) default layout's primary id |
856 // doesn't exist, or b) the primary_id has already been | 857 // doesn't exist, or b) the primary_id has already been |
857 // set to the same and didn't update it. | 858 // set to the same and didn't update it. |
858 layout_store->UpdatePrimaryDisplayId( | 859 layout_store->UpdatePrimaryDisplayId( |
859 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); | 860 pair, gfx::Screen::GetScreen()->GetPrimaryDisplay().id()); |
860 } | 861 } |
861 } | 862 } |
862 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 863 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
863 UpdateMouseLocationAfterDisplayChange(); | 864 UpdateMouseLocationAfterDisplayChange(); |
864 } | 865 } |
865 | 866 |
866 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( | 867 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( |
867 ui::KeyEvent* event) { | 868 ui::KeyEvent* event) { |
868 // Getting the active root window to dispatch the event. This isn't | 869 // Getting the active root window to dispatch the event. This isn't |
869 // significant as the event will be sent to the window resolved by | 870 // significant as the event will be sent to the window resolved by |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 925 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
925 Shell::GetInstance()->display_animator()->StartFadeInAnimation(); | 926 Shell::GetInstance()->display_animator()->StartFadeInAnimation(); |
926 #endif | 927 #endif |
927 } | 928 } |
928 | 929 |
929 void WindowTreeHostManager::SetMirrorModeAfterAnimation(bool mirror) { | 930 void WindowTreeHostManager::SetMirrorModeAfterAnimation(bool mirror) { |
930 GetDisplayManager()->SetMirrorMode(mirror); | 931 GetDisplayManager()->SetMirrorMode(mirror); |
931 } | 932 } |
932 | 933 |
933 } // namespace ash | 934 } // namespace ash |
OLD | NEW |