| 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 30 matching lines...) Expand all Loading... |
| 41 #include "ui/aura/window_property.h" | 41 #include "ui/aura/window_property.h" |
| 42 #include "ui/aura/window_tracker.h" | 42 #include "ui/aura/window_tracker.h" |
| 43 #include "ui/aura/window_tree_host.h" | 43 #include "ui/aura/window_tree_host.h" |
| 44 #include "ui/base/ime/input_method_factory.h" | 44 #include "ui/base/ime/input_method_factory.h" |
| 45 #include "ui/compositor/compositor.h" | 45 #include "ui/compositor/compositor.h" |
| 46 #include "ui/gfx/display.h" | 46 #include "ui/gfx/display.h" |
| 47 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
| 48 #include "ui/wm/core/coordinate_conversion.h" | 48 #include "ui/wm/core/coordinate_conversion.h" |
| 49 #include "ui/wm/public/activation_client.h" | 49 #include "ui/wm/public/activation_client.h" |
| 50 | 50 |
| 51 #if defined(OS_CHROMEOS) | |
| 52 #include "ash/display/display_animator.h" | |
| 53 #include "base/sys_info.h" | |
| 54 #include "base/time/time.h" | |
| 55 #endif // defined(OS_CHROMEOS) | |
| 56 | |
| 57 #if defined(USE_X11) | 51 #if defined(USE_X11) |
| 58 #include "ui/base/x/x11_util.h" | 52 #include "ui/base/x/x11_util.h" |
| 59 #include "ui/gfx/x/x11_types.h" | 53 #include "ui/gfx/x/x11_types.h" |
| 60 | 54 |
| 61 // Including this at the bottom to avoid other | 55 // Including this at the bottom to avoid other |
| 62 // potential conflict with chrome headers. | 56 // potential conflict with chrome headers. |
| 63 #include <X11/extensions/Xrandr.h> | 57 #include <X11/extensions/Xrandr.h> |
| 64 #undef RootWindow | 58 #undef RootWindow |
| 65 #endif // defined(USE_X11) | 59 #endif // defined(USE_X11) |
| 66 | 60 |
| 67 #if defined(OS_CHROMEOS) && defined(USE_OZONE) | 61 #if defined(OS_CHROMEOS) && defined(USE_OZONE) |
| 68 #include "ui/events/ozone/chromeos/cursor_controller.h" | 62 #include "ui/events/ozone/chromeos/cursor_controller.h" |
| 69 #endif | 63 #endif |
| 70 | 64 |
| 71 namespace ash { | 65 namespace ash { |
| 72 namespace { | 66 namespace { |
| 73 | 67 |
| 74 // Primary display stored in global object as it can be | 68 // Primary display stored in global object as it can be |
| 75 // accessed after Shell is deleted. A separate display instance is created | 69 // accessed after Shell is deleted. A separate display instance is created |
| 76 // during the shutdown instead of always keeping two display instances | 70 // during the shutdown instead of always keeping two display instances |
| 77 // (one here and another one in display_manager) in sync, which is error prone. | 71 // (one here and another one in display_manager) in sync, which is error prone. |
| 78 // This is initialized in the constructor, and then in CreatePrimaryHost(). | 72 // This is initialized in the constructor, and then in CreatePrimaryHost(). |
| 79 int64_t primary_display_id = -1; | 73 int64_t primary_display_id = -1; |
| 80 | 74 |
| 81 // Specifies how long the display change should have been disabled | |
| 82 // after each display change operations. | |
| 83 // |kCycleDisplayThrottleTimeoutMs| is set to be longer to avoid | |
| 84 // changing the settings while the system is still configurating | |
| 85 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| | |
| 86 // when the display change happens, so the actual timeout is much shorter. | |
| 87 const int64_t kAfterDisplayChangeThrottleTimeoutMs = 500; | |
| 88 const int64_t kCycleDisplayThrottleTimeoutMs = 4000; | |
| 89 const int64_t kSwapDisplayThrottleTimeoutMs = 500; | |
| 90 | |
| 91 #if defined(USE_OZONE) && defined(OS_CHROMEOS) | 75 #if defined(USE_OZONE) && defined(OS_CHROMEOS) |
| 92 // Add 20% more cursor motion on non-integrated displays. | 76 // Add 20% more cursor motion on non-integrated displays. |
| 93 const float kCursorMultiplierForExternalDisplays = 1.2f; | 77 const float kCursorMultiplierForExternalDisplays = 1.2f; |
| 94 #endif | 78 #endif |
| 95 | 79 |
| 96 DisplayManager* GetDisplayManager() { | 80 DisplayManager* GetDisplayManager() { |
| 97 return Shell::GetInstance()->display_manager(); | 81 return Shell::GetInstance()->display_manager(); |
| 98 } | 82 } |
| 99 | 83 |
| 100 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, | 84 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 aura::client::CaptureClient* capture_client_; | 222 aura::client::CaptureClient* capture_client_; |
| 239 aura::client::FocusClient* focus_client_; | 223 aura::client::FocusClient* focus_client_; |
| 240 aura::WindowTracker tracker_; | 224 aura::WindowTracker tracker_; |
| 241 aura::Window* focused_; | 225 aura::Window* focused_; |
| 242 aura::Window* active_; | 226 aura::Window* active_; |
| 243 | 227 |
| 244 DISALLOW_COPY_AND_ASSIGN(FocusActivationStore); | 228 DISALLOW_COPY_AND_ASSIGN(FocusActivationStore); |
| 245 }; | 229 }; |
| 246 | 230 |
| 247 //////////////////////////////////////////////////////////////////////////////// | 231 //////////////////////////////////////////////////////////////////////////////// |
| 248 // DisplayChangeLimiter | |
| 249 | |
| 250 WindowTreeHostManager::DisplayChangeLimiter::DisplayChangeLimiter() | |
| 251 : throttle_timeout_(base::Time::Now()) {} | |
| 252 | |
| 253 void WindowTreeHostManager::DisplayChangeLimiter::SetThrottleTimeout( | |
| 254 int64_t throttle_ms) { | |
| 255 throttle_timeout_ = | |
| 256 base::Time::Now() + base::TimeDelta::FromMilliseconds(throttle_ms); | |
| 257 } | |
| 258 | |
| 259 bool WindowTreeHostManager::DisplayChangeLimiter::IsThrottled() const { | |
| 260 return base::Time::Now() < throttle_timeout_; | |
| 261 } | |
| 262 | |
| 263 //////////////////////////////////////////////////////////////////////////////// | |
| 264 // WindowTreeHostManager | 232 // WindowTreeHostManager |
| 265 | 233 |
| 266 WindowTreeHostManager::WindowTreeHostManager() | 234 WindowTreeHostManager::WindowTreeHostManager() |
| 267 : primary_tree_host_for_replace_(nullptr), | 235 : primary_tree_host_for_replace_(nullptr), |
| 268 focus_activation_store_(new FocusActivationStore()), | 236 focus_activation_store_(new FocusActivationStore()), |
| 269 cursor_window_controller_(new CursorWindowController()), | 237 cursor_window_controller_(new CursorWindowController()), |
| 270 mirror_window_controller_(new MirrorWindowController()), | 238 mirror_window_controller_(new MirrorWindowController()), |
| 271 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), | 239 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), |
| 272 weak_ptr_factory_(this) { | 240 weak_ptr_factory_(this) { |
| 273 #if defined(OS_CHROMEOS) | |
| 274 if (base::SysInfo::IsRunningOnChromeOS()) | |
| 275 limiter_.reset(new DisplayChangeLimiter); | |
| 276 #endif | |
| 277 // Reset primary display to make sure that tests don't use | 241 // Reset primary display to make sure that tests don't use |
| 278 // stale display info from previous tests. | 242 // stale display info from previous tests. |
| 279 primary_display_id = gfx::Display::kInvalidDisplayID; | 243 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 280 } | 244 } |
| 281 | 245 |
| 282 WindowTreeHostManager::~WindowTreeHostManager() {} | 246 WindowTreeHostManager::~WindowTreeHostManager() {} |
| 283 | 247 |
| 284 void WindowTreeHostManager::Start() { | 248 void WindowTreeHostManager::Start() { |
| 285 Shell::GetScreen()->AddObserver(this); | 249 Shell::GetScreen()->AddObserver(this); |
| 286 Shell::GetInstance()->display_manager()->set_delegate(this); | 250 Shell::GetInstance()->display_manager()->set_delegate(this); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); | 383 for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); |
| 420 it != window_tree_hosts_.end(); ++it) { | 384 it != window_tree_hosts_.end(); ++it) { |
| 421 RootWindowController* controller = | 385 RootWindowController* controller = |
| 422 GetRootWindowController(GetWindow(it->second)); | 386 GetRootWindowController(GetWindow(it->second)); |
| 423 if (controller) | 387 if (controller) |
| 424 controllers.push_back(controller); | 388 controllers.push_back(controller); |
| 425 } | 389 } |
| 426 return controllers; | 390 return controllers; |
| 427 } | 391 } |
| 428 | 392 |
| 429 void WindowTreeHostManager::ToggleMirrorMode() { | 393 void WindowTreeHostManager::SwapPrimaryDisplayForTest() { |
| 430 DisplayManager* display_manager = GetDisplayManager(); | 394 if (Shell::GetScreen()->GetNumDisplays() <= 1) |
| 431 if (display_manager->num_connected_displays() <= 1) | |
| 432 return; | 395 return; |
| 433 | 396 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 434 if (limiter_) { | |
| 435 if (limiter_->IsThrottled()) | |
| 436 return; | |
| 437 limiter_->SetThrottleTimeout(kCycleDisplayThrottleTimeoutMs); | |
| 438 } | |
| 439 #if defined(OS_CHROMEOS) | |
| 440 Shell* shell = Shell::GetInstance(); | |
| 441 DisplayAnimator* animation = shell->display_animator(); | |
| 442 animation->StartFadeOutAnimation(base::Bind( | |
| 443 &WindowTreeHostManager::SetMirrorModeAfterAnimation, | |
| 444 weak_ptr_factory_.GetWeakPtr(), !display_manager->IsInMirrorMode())); | |
| 445 #endif | |
| 446 } | |
| 447 | |
| 448 void WindowTreeHostManager::SwapPrimaryDisplay() { | |
| 449 if (limiter_) { | |
| 450 if (limiter_->IsThrottled()) | |
| 451 return; | |
| 452 limiter_->SetThrottleTimeout(kSwapDisplayThrottleTimeoutMs); | |
| 453 } | |
| 454 | |
| 455 if (Shell::GetScreen()->GetNumDisplays() > 1) { | |
| 456 #if defined(OS_CHROMEOS) | |
| 457 DisplayAnimator* animation = Shell::GetInstance()->display_animator(); | |
| 458 if (animation) { | |
| 459 animation->StartFadeOutAnimation( | |
| 460 base::Bind(&WindowTreeHostManager::OnFadeOutForSwapDisplayFinished, | |
| 461 weak_ptr_factory_.GetWeakPtr())); | |
| 462 } else { | |
| 463 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | |
| 464 } | |
| 465 #else | |
| 466 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | |
| 467 #endif | |
| 468 } | |
| 469 } | 397 } |
| 470 | 398 |
| 471 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { | 399 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { |
| 472 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); | 400 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); |
| 473 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) | 401 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) |
| 474 return; | 402 return; |
| 475 | 403 |
| 476 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); | 404 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); |
| 477 if (display.is_valid()) | 405 if (display.is_valid()) |
| 478 SetPrimaryDisplay(display); | 406 SetPrimaryDisplay(display); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 cursor_display_id_for_restore_ = display.id(); | 754 cursor_display_id_for_restore_ = display.id(); |
| 827 | 755 |
| 828 gfx::Point point_in_native = point_in_screen; | 756 gfx::Point point_in_native = point_in_screen; |
| 829 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 757 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
| 830 ::wm::ConvertPointFromScreen(root_window, &point_in_native); | 758 ::wm::ConvertPointFromScreen(root_window, &point_in_native); |
| 831 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); | 759 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); |
| 832 cursor_location_in_native_coords_for_restore_ = point_in_native; | 760 cursor_location_in_native_coords_for_restore_ = point_in_native; |
| 833 } | 761 } |
| 834 | 762 |
| 835 void WindowTreeHostManager::PostDisplayConfigurationChange() { | 763 void WindowTreeHostManager::PostDisplayConfigurationChange() { |
| 836 if (limiter_) | |
| 837 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | |
| 838 | |
| 839 focus_activation_store_->Restore(); | 764 focus_activation_store_->Restore(); |
| 840 | 765 |
| 841 DisplayManager* display_manager = GetDisplayManager(); | 766 DisplayManager* display_manager = GetDisplayManager(); |
| 842 DisplayLayoutStore* layout_store = display_manager->layout_store(); | 767 DisplayLayoutStore* layout_store = display_manager->layout_store(); |
| 843 if (display_manager->num_connected_displays() > 1) { | 768 if (display_manager->num_connected_displays() > 1) { |
| 844 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); | 769 DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
| 845 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); | 770 DisplayLayout layout = layout_store->GetRegisteredDisplayLayout(pair); |
| 846 layout_store->UpdateMultiDisplayState( | 771 layout_store->UpdateMultiDisplayState( |
| 847 pair, display_manager->IsInMirrorMode(), layout.default_unified); | 772 pair, display_manager->IsInMirrorMode(), layout.default_unified); |
| 848 | 773 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 window_tree_hosts_[display.id()] = ash_host; | 837 window_tree_hosts_[display.id()] = ash_host; |
| 913 SetDisplayPropertiesOnHost(ash_host, display); | 838 SetDisplayPropertiesOnHost(ash_host, display); |
| 914 | 839 |
| 915 #if defined(OS_CHROMEOS) | 840 #if defined(OS_CHROMEOS) |
| 916 if (switches::ConstrainPointerToRoot()) | 841 if (switches::ConstrainPointerToRoot()) |
| 917 ash_host->ConfineCursorToRootWindow(); | 842 ash_host->ConfineCursorToRootWindow(); |
| 918 #endif | 843 #endif |
| 919 return ash_host; | 844 return ash_host; |
| 920 } | 845 } |
| 921 | 846 |
| 922 void WindowTreeHostManager::OnFadeOutForSwapDisplayFinished() { | |
| 923 #if defined(OS_CHROMEOS) | |
| 924 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | |
| 925 Shell::GetInstance()->display_animator()->StartFadeInAnimation(); | |
| 926 #endif | |
| 927 } | |
| 928 | |
| 929 void WindowTreeHostManager::SetMirrorModeAfterAnimation(bool mirror) { | |
| 930 GetDisplayManager()->SetMirrorMode(mirror); | |
| 931 } | |
| 932 | |
| 933 } // namespace ash | 847 } // namespace ash |
| OLD | NEW |