| 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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/display/display_layout_store.h" | 12 #include "ash/display/display_layout_store.h" |
| 13 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
| 14 #include "ash/display/mirror_window_controller.h" | 14 #include "ash/display/mirror_window_controller.h" |
| 15 #include "ash/display/root_window_transformers.h" | 15 #include "ash/display/root_window_transformers.h" |
| 16 #include "ash/display/virtual_keyboard_window_controller.h" | 16 #include "ash/display/virtual_keyboard_window_controller.h" |
| 17 #include "ash/host/root_window_host_factory.h" | 17 #include "ash/host/root_window_host_factory.h" |
| 18 #include "ash/root_window_controller.h" | 18 #include "ash/root_window_controller.h" |
| 19 #include "ash/root_window_settings.h" | 19 #include "ash/root_window_settings.h" |
| 20 #include "ash/screen_ash.h" | 20 #include "ash/screen_util.h" |
| 21 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 22 #include "ash/shell_delegate.h" | 22 #include "ash/shell_delegate.h" |
| 23 #include "ash/wm/coordinate_conversion.h" | 23 #include "ash/wm/coordinate_conversion.h" |
| 24 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "third_party/skia/include/utils/SkMatrix44.h" | |
| 27 #include "ui/aura/client/activation_client.h" | 26 #include "ui/aura/client/activation_client.h" |
| 28 #include "ui/aura/client/capture_client.h" | 27 #include "ui/aura/client/capture_client.h" |
| 29 #include "ui/aura/client/cursor_client.h" | |
| 30 #include "ui/aura/client/focus_client.h" | 28 #include "ui/aura/client/focus_client.h" |
| 31 #include "ui/aura/client/screen_position_client.h" | 29 #include "ui/aura/client/screen_position_client.h" |
| 32 #include "ui/aura/root_window.h" | 30 #include "ui/aura/root_window.h" |
| 33 #include "ui/aura/root_window_transformer.h" | 31 #include "ui/aura/root_window_transformer.h" |
| 34 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 35 #include "ui/aura/window_property.h" | 33 #include "ui/aura/window_property.h" |
| 36 #include "ui/aura/window_tracker.h" | 34 #include "ui/aura/window_tracker.h" |
| 37 #include "ui/compositor/compositor.h" | 35 #include "ui/compositor/compositor.h" |
| 38 #include "ui/compositor/dip_util.h" | |
| 39 #include "ui/gfx/display.h" | 36 #include "ui/gfx/display.h" |
| 40 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
| 41 | 38 |
| 42 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 43 #include "base/sys_info.h" | 40 #include "base/sys_info.h" |
| 44 #include "base/time/time.h" | 41 #include "base/time/time.h" |
| 45 #if defined(USE_X11) | 42 #if defined(USE_X11) |
| 46 #include "ash/display/output_configurator_animation.h" | 43 #include "ash/display/output_configurator_animation.h" |
| 47 #include "chromeos/display/output_configurator.h" | 44 #include "chromeos/display/output_configurator.h" |
| 48 #include "ui/base/x/x11_util.h" | 45 #include "ui/base/x/x11_util.h" |
| 49 #include "ui/gfx/x/x11_types.h" | 46 #include "ui/gfx/x/x11_types.h" |
| 50 | 47 |
| 51 // Including this at the bottom to avoid other | 48 // Including this at the bottom to avoid other |
| 52 // potential conflict with chrome headers. | 49 // potential conflict with chrome headers. |
| 53 #include <X11/extensions/Xrandr.h> | 50 #include <X11/extensions/Xrandr.h> |
| 54 #undef RootWindow | 51 #undef RootWindow |
| 55 #endif // defined(USE_X11) | 52 #endif // defined(USE_X11) |
| 56 #endif // defined(OS_CHROMEOS) | 53 #endif // defined(OS_CHROMEOS) |
| 57 | 54 |
| 58 namespace ash { | 55 namespace ash { |
| 59 namespace { | 56 namespace { |
| 60 | 57 |
| 61 // Primary display stored in global object as it can be | 58 // Primary display stored in global object as it can be |
| 62 // accessed after Shell is deleted. A separate display instance is created | 59 // accessed after Shell is deleted. A separate display instance is created |
| 63 // during the shutdown instead of always keeping two display instances | 60 // during the shutdown instead of always keeping two display instances |
| 64 // (one here and another one in display_manager) in sync, which is error prone. | 61 // (one here and another one in display_manager) in sync, which is error prone. |
| 65 int64 primary_display_id = gfx::Display::kInvalidDisplayID; | 62 int64 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 66 gfx::Display* primary_display_for_shutdown = NULL; | |
| 67 // Keeps the number of displays during the shutdown after | |
| 68 // ash::Shell:: is deleted. | |
| 69 int num_displays_for_shutdown = -1; | |
| 70 | 63 |
| 71 // Specifies how long the display change should have been disabled | 64 // Specifies how long the display change should have been disabled |
| 72 // after each display change operations. | 65 // after each display change operations. |
| 73 // |kCycleDisplayThrottleTimeoutMs| is set to be longer to avoid | 66 // |kCycleDisplayThrottleTimeoutMs| is set to be longer to avoid |
| 74 // changing the settings while the system is still configurating | 67 // changing the settings while the system is still configurating |
| 75 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| | 68 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| |
| 76 // when the display change happens, so the actual timeout is much shorter. | 69 // when the display change happens, so the actual timeout is much shorter. |
| 77 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; | 70 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; |
| 78 const int64 kCycleDisplayThrottleTimeoutMs = 4000; | 71 const int64 kCycleDisplayThrottleTimeoutMs = 4000; |
| 79 const int64 kSwapDisplayThrottleTimeoutMs = 500; | 72 const int64 kSwapDisplayThrottleTimeoutMs = 500; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 new internal::VirtualKeyboardWindowController) { | 221 new internal::VirtualKeyboardWindowController) { |
| 229 #if defined(OS_CHROMEOS) | 222 #if defined(OS_CHROMEOS) |
| 230 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 223 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 231 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && | 224 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && |
| 232 base::SysInfo::IsRunningOnChromeOS()) | 225 base::SysInfo::IsRunningOnChromeOS()) |
| 233 limiter_.reset(new DisplayChangeLimiter); | 226 limiter_.reset(new DisplayChangeLimiter); |
| 234 #endif | 227 #endif |
| 235 // Reset primary display to make sure that tests don't use | 228 // Reset primary display to make sure that tests don't use |
| 236 // stale display info from previous tests. | 229 // stale display info from previous tests. |
| 237 primary_display_id = gfx::Display::kInvalidDisplayID; | 230 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 238 delete primary_display_for_shutdown; | |
| 239 primary_display_for_shutdown = NULL; | |
| 240 num_displays_for_shutdown = -1; | |
| 241 } | 231 } |
| 242 | 232 |
| 243 DisplayController::~DisplayController() { | 233 DisplayController::~DisplayController() { |
| 244 DCHECK(primary_display_for_shutdown); | |
| 245 } | 234 } |
| 246 | 235 |
| 247 void DisplayController::Start() { | 236 void DisplayController::Start() { |
| 248 Shell::GetScreen()->AddObserver(this); | 237 Shell::GetScreen()->AddObserver(this); |
| 249 Shell::GetInstance()->display_manager()->set_delegate(this); | 238 Shell::GetInstance()->display_manager()->set_delegate(this); |
| 250 | 239 |
| 251 if (Shell::GetInstance()->delegate()->IsFirstRunAfterBoot()) { | 240 if (Shell::GetInstance()->delegate()->IsFirstRunAfterBoot()) { |
| 252 // Update the display pref with the initial power state. | 241 // Update the display pref with the initial power state. |
| 253 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 242 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 254 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 243 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
| 255 } | 244 } |
| 256 } | 245 } |
| 257 | 246 |
| 258 void DisplayController::Shutdown() { | 247 void DisplayController::Shutdown() { |
| 259 // Unset the display manager's delegate here because | 248 // Unset the display manager's delegate here because |
| 260 // DisplayManager outlives DisplayController. | 249 // DisplayManager outlives DisplayController. |
| 261 Shell::GetInstance()->display_manager()->set_delegate(NULL); | 250 Shell::GetInstance()->display_manager()->set_delegate(NULL); |
| 262 | 251 |
| 263 mirror_window_controller_.reset(); | 252 mirror_window_controller_.reset(); |
| 264 virtual_keyboard_window_controller_.reset(); | 253 virtual_keyboard_window_controller_.reset(); |
| 265 | 254 |
| 266 DCHECK(!primary_display_for_shutdown); | |
| 267 primary_display_for_shutdown = new gfx::Display( | |
| 268 GetDisplayManager()->GetDisplayForId(primary_display_id)); | |
| 269 num_displays_for_shutdown = GetDisplayManager()->GetNumDisplays(); | |
| 270 | |
| 271 Shell::GetScreen()->RemoveObserver(this); | 255 Shell::GetScreen()->RemoveObserver(this); |
| 272 // Delete all root window controllers, which deletes root window | 256 // Delete all root window controllers, which deletes root window |
| 273 // from the last so that the primary root window gets deleted last. | 257 // from the last so that the primary root window gets deleted last. |
| 274 for (std::map<int64, aura::Window*>::const_reverse_iterator it = | 258 for (std::map<int64, aura::Window*>::const_reverse_iterator it = |
| 275 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 259 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
| 276 internal::RootWindowController* controller = | 260 internal::RootWindowController* controller = |
| 277 internal::GetRootWindowController(it->second); | 261 internal::GetRootWindowController(it->second); |
| 278 DCHECK(controller); | 262 DCHECK(controller); |
| 279 delete controller; | 263 delete controller; |
| 280 } | 264 } |
| 281 } | 265 } |
| 282 | 266 |
| 283 // static | |
| 284 const gfx::Display& DisplayController::GetPrimaryDisplay() { | |
| 285 DCHECK_NE(primary_display_id, gfx::Display::kInvalidDisplayID); | |
| 286 if (primary_display_for_shutdown) | |
| 287 return *primary_display_for_shutdown; | |
| 288 return GetDisplayManager()->GetDisplayForId(primary_display_id); | |
| 289 } | |
| 290 | |
| 291 // static | |
| 292 int DisplayController::GetNumDisplays() { | |
| 293 if (num_displays_for_shutdown >= 0) | |
| 294 return num_displays_for_shutdown; | |
| 295 return GetDisplayManager()->GetNumDisplays(); | |
| 296 } | |
| 297 | |
| 298 void DisplayController::InitPrimaryDisplay() { | 267 void DisplayController::InitPrimaryDisplay() { |
| 299 const gfx::Display& primary_candidate = | 268 const gfx::Display& primary_candidate = |
| 300 GetDisplayManager()->GetPrimaryDisplayCandidate(); | 269 GetDisplayManager()->GetPrimaryDisplayCandidate(); |
| 301 primary_display_id = primary_candidate.id(); | 270 primary_display_id = primary_candidate.id(); |
| 302 AddRootWindowForDisplay(primary_candidate); | 271 AddRootWindowForDisplay(primary_candidate); |
| 303 } | 272 } |
| 304 | 273 |
| 305 void DisplayController::InitSecondaryDisplays() { | 274 void DisplayController::InitSecondaryDisplays() { |
| 306 internal::DisplayManager* display_manager = GetDisplayManager(); | 275 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 307 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 276 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 308 const gfx::Display& display = display_manager->GetDisplayAt(i); | 277 const gfx::Display& display = display_manager->GetDisplayAt(i); |
| 309 if (primary_display_id != display.id()) { | 278 if (primary_display_id != display.id()) { |
| 310 aura::RootWindow* root = AddRootWindowForDisplay(display); | 279 aura::RootWindow* root = AddRootWindowForDisplay(display); |
| 311 internal::RootWindowController::CreateForSecondaryDisplay(root); | 280 internal::RootWindowController::CreateForSecondaryDisplay(root); |
| 312 } | 281 } |
| 313 } | 282 } |
| 314 UpdateHostWindowNames(); | 283 UpdateHostWindowNames(); |
| 315 } | 284 } |
| 316 | 285 |
| 317 void DisplayController::AddObserver(Observer* observer) { | 286 void DisplayController::AddObserver(Observer* observer) { |
| 318 observers_.AddObserver(observer); | 287 observers_.AddObserver(observer); |
| 319 } | 288 } |
| 320 | 289 |
| 321 void DisplayController::RemoveObserver(Observer* observer) { | 290 void DisplayController::RemoveObserver(Observer* observer) { |
| 322 observers_.RemoveObserver(observer); | 291 observers_.RemoveObserver(observer); |
| 323 } | 292 } |
| 324 | 293 |
| 294 // static |
| 295 int64 DisplayController::GetPrimaryDisplayId() { |
| 296 return primary_display_id; |
| 297 } |
| 298 |
| 325 aura::Window* DisplayController::GetPrimaryRootWindow() { | 299 aura::Window* DisplayController::GetPrimaryRootWindow() { |
| 326 DCHECK(!root_windows_.empty()); | 300 DCHECK(!root_windows_.empty()); |
| 327 return root_windows_[primary_display_id]; | 301 return root_windows_[primary_display_id]; |
| 328 } | 302 } |
| 329 | 303 |
| 330 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { | 304 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { |
| 331 return root_windows_[id]; | 305 return root_windows_[id]; |
| 332 } | 306 } |
| 333 | 307 |
| 334 void DisplayController::CloseChildWindows() { | 308 void DisplayController::CloseChildWindows() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 385 |
| 412 if (Shell::GetScreen()->GetNumDisplays() > 1) { | 386 if (Shell::GetScreen()->GetNumDisplays() > 1) { |
| 413 #if defined(OS_CHROMEOS) && defined(USE_X11) | 387 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 414 internal::OutputConfiguratorAnimation* animation = | 388 internal::OutputConfiguratorAnimation* animation = |
| 415 Shell::GetInstance()->output_configurator_animation(); | 389 Shell::GetInstance()->output_configurator_animation(); |
| 416 if (animation) { | 390 if (animation) { |
| 417 animation->StartFadeOutAnimation(base::Bind( | 391 animation->StartFadeOutAnimation(base::Bind( |
| 418 &DisplayController::OnFadeOutForSwapDisplayFinished, | 392 &DisplayController::OnFadeOutForSwapDisplayFinished, |
| 419 base::Unretained(this))); | 393 base::Unretained(this))); |
| 420 } else { | 394 } else { |
| 421 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 395 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 422 } | 396 } |
| 423 #else | 397 #else |
| 424 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 398 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 425 #endif | 399 #endif |
| 426 } | 400 } |
| 427 } | 401 } |
| 428 | 402 |
| 429 void DisplayController::SetPrimaryDisplayId(int64 id) { | 403 void DisplayController::SetPrimaryDisplayId(int64 id) { |
| 430 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); | 404 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); |
| 431 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) | 405 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) |
| 432 return; | 406 return; |
| 433 | 407 |
| 434 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); | 408 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 454 return; | 428 return; |
| 455 } | 429 } |
| 456 | 430 |
| 457 aura::Window* non_primary_root = root_windows_[new_primary_display.id()]; | 431 aura::Window* non_primary_root = root_windows_[new_primary_display.id()]; |
| 458 LOG_IF(ERROR, !non_primary_root) | 432 LOG_IF(ERROR, !non_primary_root) |
| 459 << "Unknown display is requested in SetPrimaryDisplay: id=" | 433 << "Unknown display is requested in SetPrimaryDisplay: id=" |
| 460 << new_primary_display.id(); | 434 << new_primary_display.id(); |
| 461 if (!non_primary_root) | 435 if (!non_primary_root) |
| 462 return; | 436 return; |
| 463 | 437 |
| 464 gfx::Display old_primary_display = GetPrimaryDisplay(); | 438 gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 465 | 439 |
| 466 // Swap root windows between current and new primary display. | 440 // Swap root windows between current and new primary display. |
| 467 aura::Window* primary_root = root_windows_[primary_display_id]; | 441 aura::Window* primary_root = root_windows_[primary_display_id]; |
| 468 DCHECK(primary_root); | 442 DCHECK(primary_root); |
| 469 DCHECK_NE(primary_root, non_primary_root); | 443 DCHECK_NE(primary_root, non_primary_root); |
| 470 | 444 |
| 471 root_windows_[new_primary_display.id()] = primary_root; | 445 root_windows_[new_primary_display.id()] = primary_root; |
| 472 internal::GetRootWindowSettings(primary_root)->display_id = | 446 internal::GetRootWindowSettings(primary_root)->display_id = |
| 473 new_primary_display.id(); | 447 new_primary_display.id(); |
| 474 | 448 |
| 475 root_windows_[old_primary_display.id()] = non_primary_root; | 449 root_windows_[old_primary_display.id()] = non_primary_root; |
| 476 internal::GetRootWindowSettings(non_primary_root)->display_id = | 450 internal::GetRootWindowSettings(non_primary_root)->display_id = |
| 477 old_primary_display.id(); | 451 old_primary_display.id(); |
| 478 | 452 |
| 479 primary_display_id = new_primary_display.id(); | 453 primary_display_id = new_primary_display.id(); |
| 480 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( | 454 GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( |
| 481 display_manager->GetCurrentDisplayIdPair(), primary_display_id); | 455 display_manager->GetCurrentDisplayIdPair(), primary_display_id); |
| 482 | 456 |
| 483 UpdateWorkAreaOfDisplayNearestWindow( | 457 UpdateWorkAreaOfDisplayNearestWindow( |
| 484 primary_root, old_primary_display.GetWorkAreaInsets()); | 458 primary_root, old_primary_display.GetWorkAreaInsets()); |
| 485 UpdateWorkAreaOfDisplayNearestWindow( | 459 UpdateWorkAreaOfDisplayNearestWindow( |
| 486 non_primary_root, new_primary_display.GetWorkAreaInsets()); | 460 non_primary_root, new_primary_display.GetWorkAreaInsets()); |
| 487 | 461 |
| 488 // Update the dispay manager with new display info. | 462 // Update the dispay manager with new display info. |
| 489 std::vector<internal::DisplayInfo> display_info_list; | 463 std::vector<internal::DisplayInfo> display_info_list; |
| 490 display_info_list.push_back(display_manager->GetDisplayInfo( | 464 display_info_list.push_back(display_manager->GetDisplayInfo( |
| 491 primary_display_id)); | 465 primary_display_id)); |
| 492 display_info_list.push_back(display_manager->GetDisplayInfo( | 466 display_info_list.push_back(display_manager->GetDisplayInfo( |
| 493 ScreenAsh::GetSecondaryDisplay().id())); | 467 ScreenUtil::GetSecondaryDisplay().id())); |
| 494 GetDisplayManager()->set_force_bounds_changed(true); | 468 GetDisplayManager()->set_force_bounds_changed(true); |
| 495 GetDisplayManager()->UpdateDisplays(display_info_list); | 469 GetDisplayManager()->UpdateDisplays(display_info_list); |
| 496 GetDisplayManager()->set_force_bounds_changed(false); | 470 GetDisplayManager()->set_force_bounds_changed(false); |
| 497 } | 471 } |
| 498 | 472 |
| 499 void DisplayController::EnsurePointerInDisplays() { | 473 void DisplayController::EnsurePointerInDisplays() { |
| 500 // If the mouse is currently on a display in native location, | 474 // If the mouse is currently on a display in native location, |
| 501 // use the same native location. Otherwise find the display closest | 475 // use the same native location. Otherwise find the display closest |
| 502 // to the current cursor location in screen coordinates. | 476 // to the current cursor location in screen coordinates. |
| 503 | 477 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( | 520 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( |
| 547 const aura::Window* window, | 521 const aura::Window* window, |
| 548 const gfx::Insets& insets) { | 522 const gfx::Insets& insets) { |
| 549 const aura::Window* root_window = window->GetRootWindow(); | 523 const aura::Window* root_window = window->GetRootWindow(); |
| 550 int64 id = internal::GetRootWindowSettings(root_window)->display_id; | 524 int64 id = internal::GetRootWindowSettings(root_window)->display_id; |
| 551 // if id is |kInvaildDisplayID|, it's being deleted. | 525 // if id is |kInvaildDisplayID|, it's being deleted. |
| 552 DCHECK(id != gfx::Display::kInvalidDisplayID); | 526 DCHECK(id != gfx::Display::kInvalidDisplayID); |
| 553 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 527 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
| 554 } | 528 } |
| 555 | 529 |
| 556 const gfx::Display& DisplayController::GetDisplayNearestWindow( | |
| 557 const aura::Window* window) const { | |
| 558 if (!window) | |
| 559 return GetPrimaryDisplay(); | |
| 560 const aura::Window* root_window = window->GetRootWindow(); | |
| 561 if (!root_window) | |
| 562 return GetPrimaryDisplay(); | |
| 563 int64 id = internal::GetRootWindowSettings(root_window)->display_id; | |
| 564 // if id is |kInvaildDisplayID|, it's being deleted. | |
| 565 DCHECK(id != gfx::Display::kInvalidDisplayID); | |
| 566 | |
| 567 internal::DisplayManager* display_manager = GetDisplayManager(); | |
| 568 // RootWindow needs Display to determine its device scale factor | |
| 569 // for non desktop display. | |
| 570 if (display_manager->non_desktop_display().id() == id) | |
| 571 return display_manager->non_desktop_display(); | |
| 572 return display_manager->GetDisplayForId(id); | |
| 573 } | |
| 574 | |
| 575 const gfx::Display& DisplayController::GetDisplayNearestPoint( | |
| 576 const gfx::Point& point) const { | |
| 577 const gfx::Display& display = | |
| 578 GetDisplayManager()->FindDisplayContainingPoint(point); | |
| 579 if (display.is_valid()) | |
| 580 return display; | |
| 581 | |
| 582 // Fallback to the display that has the shortest Manhattan distance from | |
| 583 // the |point|. This is correct in the only areas that matter, namely in the | |
| 584 // corners between the physical screens. | |
| 585 int min_distance = INT_MAX; | |
| 586 const gfx::Display* nearest_display = NULL; | |
| 587 for (size_t i = 0; i < GetDisplayManager()->GetNumDisplays(); ++i) { | |
| 588 const gfx::Display& display = GetDisplayManager()->GetDisplayAt(i); | |
| 589 int distance = display.bounds().ManhattanDistanceToPoint(point); | |
| 590 if (distance < min_distance) { | |
| 591 min_distance = distance; | |
| 592 nearest_display = &display; | |
| 593 } | |
| 594 } | |
| 595 // There should always be at least one display that is less than INT_MAX away. | |
| 596 DCHECK(nearest_display); | |
| 597 return *nearest_display; | |
| 598 } | |
| 599 | |
| 600 const gfx::Display& DisplayController::GetDisplayMatching( | |
| 601 const gfx::Rect& rect) const { | |
| 602 if (rect.IsEmpty()) | |
| 603 return GetDisplayNearestPoint(rect.origin()); | |
| 604 | |
| 605 int max_area = 0; | |
| 606 const gfx::Display* matching = NULL; | |
| 607 for (size_t i = 0; i < GetDisplayManager()->GetNumDisplays(); ++i) { | |
| 608 const gfx::Display& display = GetDisplayManager()->GetDisplayAt(i); | |
| 609 gfx::Rect intersect = gfx::IntersectRects(display.bounds(), rect); | |
| 610 int area = intersect.width() * intersect.height(); | |
| 611 if (area > max_area) { | |
| 612 max_area = area; | |
| 613 matching = &display; | |
| 614 } | |
| 615 } | |
| 616 // Fallback to the primary display if there is no matching display. | |
| 617 return matching ? *matching : GetPrimaryDisplay(); | |
| 618 } | |
| 619 | |
| 620 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 530 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 621 const internal::DisplayInfo& display_info = | 531 const internal::DisplayInfo& display_info = |
| 622 GetDisplayManager()->GetDisplayInfo(display.id()); | 532 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 623 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 533 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
| 624 aura::WindowEventDispatcher* dispatcher = | 534 aura::WindowEventDispatcher* dispatcher = |
| 625 root_windows_[display.id()]->GetDispatcher(); | 535 root_windows_[display.id()]->GetDispatcher(); |
| 626 dispatcher->host()->SetBounds(display_info.bounds_in_native()); | 536 dispatcher->host()->SetBounds(display_info.bounds_in_native()); |
| 627 SetDisplayPropertiesOnHostWindow(dispatcher, display); | 537 SetDisplayPropertiesOnHostWindow(dispatcher, display); |
| 628 } | 538 } |
| 629 | 539 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 // root to the other display. | 572 // root to the other display. |
| 663 if (primary_display_id == display.id()) { | 573 if (primary_display_id == display.id()) { |
| 664 // Temporarily store the primary root window in | 574 // Temporarily store the primary root window in |
| 665 // |primary_root_window_for_replace_| when replacing the display. | 575 // |primary_root_window_for_replace_| when replacing the display. |
| 666 if (root_windows_.size() == 0) { | 576 if (root_windows_.size() == 0) { |
| 667 primary_display_id = gfx::Display::kInvalidDisplayID; | 577 primary_display_id = gfx::Display::kInvalidDisplayID; |
| 668 primary_root_window_for_replace_ = root_to_delete; | 578 primary_root_window_for_replace_ = root_to_delete; |
| 669 return; | 579 return; |
| 670 } | 580 } |
| 671 DCHECK_EQ(1U, root_windows_.size()); | 581 DCHECK_EQ(1U, root_windows_.size()); |
| 672 primary_display_id = ScreenAsh::GetSecondaryDisplay().id(); | 582 primary_display_id = ScreenUtil::GetSecondaryDisplay().id(); |
| 673 aura::Window* primary_root = root_to_delete; | 583 aura::Window* primary_root = root_to_delete; |
| 674 | 584 |
| 675 // Delete the other root instead. | 585 // Delete the other root instead. |
| 676 root_to_delete = root_windows_[primary_display_id]; | 586 root_to_delete = root_windows_[primary_display_id]; |
| 677 internal::GetRootWindowSettings(root_to_delete)->display_id = display.id(); | 587 internal::GetRootWindowSettings(root_to_delete)->display_id = display.id(); |
| 678 | 588 |
| 679 // Setup primary root. | 589 // Setup primary root. |
| 680 root_windows_[primary_display_id] = primary_root; | 590 root_windows_[primary_display_id] = primary_root; |
| 681 internal::GetRootWindowSettings(primary_root)->display_id = | 591 internal::GetRootWindowSettings(primary_root)->display_id = |
| 682 primary_display_id; | 592 primary_display_id; |
| 683 | 593 |
| 684 OnDisplayBoundsChanged( | 594 OnDisplayBoundsChanged( |
| 685 GetDisplayManager()->GetDisplayForId(primary_display_id)); | 595 GetDisplayManager()->GetDisplayForId(primary_display_id)); |
| 686 } | 596 } |
| 687 internal::RootWindowController* controller = | 597 internal::RootWindowController* controller = |
| 688 internal::GetRootWindowController(root_to_delete); | 598 internal::GetRootWindowController(root_to_delete); |
| 689 DCHECK(controller); | 599 DCHECK(controller); |
| 690 controller->MoveWindowsTo(GetPrimaryRootWindow()); | 600 controller->MoveWindowsTo(GetPrimaryRootWindow()); |
| 691 // Delete most of root window related objects, but don't delete | 601 // Delete most of root window related objects, but don't delete |
| 692 // root window itself yet because the stack may be using it. | 602 // root window itself yet because the stack may be using it. |
| 693 controller->Shutdown(); | 603 controller->Shutdown(); |
| 694 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); | 604 base::MessageLoop::current()->DeleteSoon(FROM_HERE, controller); |
| 695 } | 605 } |
| 696 | 606 |
| 697 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { | 607 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { |
| 608 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 609 const_cast<aura::Window*>(root->window())); |
| 610 |
| 698 internal::DisplayManager* display_manager = GetDisplayManager(); | 611 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 699 gfx::Display display = GetDisplayNearestWindow(root->window()); | |
| 700 if (display_manager->UpdateDisplayBounds( | 612 if (display_manager->UpdateDisplayBounds( |
| 701 display.id(), | 613 display.id(), |
| 702 root->host()->GetBounds())) { | 614 root->host()->GetBounds())) { |
| 703 mirror_window_controller_->UpdateWindow(); | 615 mirror_window_controller_->UpdateWindow(); |
| 704 } | 616 } |
| 705 } | 617 } |
| 706 | 618 |
| 707 void DisplayController::CreateOrUpdateNonDesktopDisplay( | 619 void DisplayController::CreateOrUpdateNonDesktopDisplay( |
| 708 const internal::DisplayInfo& info) { | 620 const internal::DisplayInfo& info) { |
| 709 switch (GetDisplayManager()->second_display_mode()) { | 621 switch (GetDisplayManager()->second_display_mode()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 721 } | 633 } |
| 722 | 634 |
| 723 void DisplayController::CloseNonDesktopDisplay() { | 635 void DisplayController::CloseNonDesktopDisplay() { |
| 724 mirror_window_controller_->Close(); | 636 mirror_window_controller_->Close(); |
| 725 virtual_keyboard_window_controller_->Close(); | 637 virtual_keyboard_window_controller_->Close(); |
| 726 } | 638 } |
| 727 | 639 |
| 728 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { | 640 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { |
| 729 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 641 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 730 focus_activation_store_->Store(clear_focus); | 642 focus_activation_store_->Store(clear_focus); |
| 731 | 643 gfx::Screen* screen = Shell::GetScreen(); |
| 732 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 644 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
| 733 gfx::Display display = GetDisplayNearestPoint(point_in_screen); | 645 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
| 734 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 646 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
| 735 | 647 |
| 736 aura::client::ScreenPositionClient* client = | 648 aura::client::ScreenPositionClient* client = |
| 737 aura::client::GetScreenPositionClient(root_window); | 649 aura::client::GetScreenPositionClient(root_window); |
| 738 client->ConvertPointFromScreen(root_window, &point_in_screen); | 650 client->ConvertPointFromScreen(root_window, &point_in_screen); |
| 739 root_window->GetDispatcher()->host()->ConvertPointToNativeScreen( | 651 root_window->GetDispatcher()->host()->ConvertPointToNativeScreen( |
| 740 &point_in_screen); | 652 &point_in_screen); |
| 741 cursor_location_in_native_coords_for_restore_ = point_in_screen; | 653 cursor_location_in_native_coords_for_restore_ = point_in_screen; |
| 742 } | 654 } |
| 743 | 655 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 756 | 668 |
| 757 if (Shell::GetScreen()->GetNumDisplays() > 1 ) { | 669 if (Shell::GetScreen()->GetNumDisplays() > 1 ) { |
| 758 int64 primary_id = layout.primary_id; | 670 int64 primary_id = layout.primary_id; |
| 759 SetPrimaryDisplayId( | 671 SetPrimaryDisplayId( |
| 760 primary_id == gfx::Display::kInvalidDisplayID ? | 672 primary_id == gfx::Display::kInvalidDisplayID ? |
| 761 pair.first : primary_id); | 673 pair.first : primary_id); |
| 762 // Update the primary_id in case the above call is | 674 // Update the primary_id in case the above call is |
| 763 // ignored. Happens when a) default layout's primary id | 675 // ignored. Happens when a) default layout's primary id |
| 764 // doesn't exist, or b) the primary_id has already been | 676 // doesn't exist, or b) the primary_id has already been |
| 765 // set to the same and didn't update it. | 677 // set to the same and didn't update it. |
| 766 layout_store->UpdatePrimaryDisplayId(pair, GetPrimaryDisplay().id()); | 678 layout_store->UpdatePrimaryDisplayId( |
| 679 pair, Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 767 } | 680 } |
| 768 } | 681 } |
| 769 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 682 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
| 770 UpdateHostWindowNames(); | 683 UpdateHostWindowNames(); |
| 771 EnsurePointerInDisplays(); | 684 EnsurePointerInDisplays(); |
| 772 } | 685 } |
| 773 | 686 |
| 774 aura::RootWindow* DisplayController::AddRootWindowForDisplay( | 687 aura::RootWindow* DisplayController::AddRootWindowForDisplay( |
| 775 const gfx::Display& display) { | 688 const gfx::Display& display) { |
| 776 static int root_window_count = 0; | 689 static int root_window_count = 0; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 799 CommandLine::ForCurrentProcess()->HasSwitch( | 712 CommandLine::ForCurrentProcess()->HasSwitch( |
| 800 switches::kAshConstrainPointerToRoot); | 713 switches::kAshConstrainPointerToRoot); |
| 801 if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) | 714 if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) |
| 802 root_window->host()->ConfineCursorToRootWindow(); | 715 root_window->host()->ConfineCursorToRootWindow(); |
| 803 #endif | 716 #endif |
| 804 return root_window; | 717 return root_window; |
| 805 } | 718 } |
| 806 | 719 |
| 807 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 720 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
| 808 #if defined(OS_CHROMEOS) && defined(USE_X11) | 721 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 809 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 722 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 810 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 723 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
| 811 #endif | 724 #endif |
| 812 } | 725 } |
| 813 | 726 |
| 814 void DisplayController::UpdateHostWindowNames() { | 727 void DisplayController::UpdateHostWindowNames() { |
| 815 #if defined(USE_X11) | 728 #if defined(USE_X11) |
| 816 // crbug.com/120229 - set the window title for the primary dislpay | 729 // crbug.com/120229 - set the window title for the primary dislpay |
| 817 // to "aura_root_0" so gtalk can find the primary root window to broadcast. | 730 // to "aura_root_0" so gtalk can find the primary root window to broadcast. |
| 818 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. | 731 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. |
| 819 aura::Window* primary = Shell::GetPrimaryRootWindow(); | 732 aura::Window* primary = Shell::GetPrimaryRootWindow(); |
| 820 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 733 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 821 for (size_t i = 0; i < root_windows.size(); ++i) { | 734 for (size_t i = 0; i < root_windows.size(); ++i) { |
| 822 std::string name = | 735 std::string name = |
| 823 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 736 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
| 824 gfx::AcceleratedWidget xwindow = | 737 gfx::AcceleratedWidget xwindow = |
| 825 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); | 738 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); |
| 826 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 739 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
| 827 } | 740 } |
| 828 #endif | 741 #endif |
| 829 } | 742 } |
| 830 | 743 |
| 831 } // namespace ash | 744 } // namespace ash |
| OLD | NEW |