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 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 FocusActivationStore() | 137 FocusActivationStore() |
138 : activation_client_(NULL), | 138 : activation_client_(NULL), |
139 capture_client_(NULL), | 139 capture_client_(NULL), |
140 focus_client_(NULL), | 140 focus_client_(NULL), |
141 focused_(NULL), | 141 focused_(NULL), |
142 active_(NULL) { | 142 active_(NULL) { |
143 } | 143 } |
144 | 144 |
145 void Store(bool display_removed) { | 145 void Store(bool display_removed) { |
146 if (!activation_client_) { | 146 if (!activation_client_) { |
147 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 147 aura::Window* root = Shell::GetPrimaryRootWindow(); |
148 activation_client_ = aura::client::GetActivationClient(root); | 148 activation_client_ = aura::client::GetActivationClient(root); |
149 capture_client_ = aura::client::GetCaptureClient(root); | 149 capture_client_ = aura::client::GetCaptureClient(root); |
150 focus_client_ = aura::client::GetFocusClient(root); | 150 focus_client_ = aura::client::GetFocusClient(root); |
151 } | 151 } |
152 focused_ = focus_client_->GetFocusedWindow(); | 152 focused_ = focus_client_->GetFocusedWindow(); |
153 if (focused_) | 153 if (focused_) |
154 tracker_.Add(focused_); | 154 tracker_.Add(focused_); |
155 active_ = activation_client_->GetActiveWindow(); | 155 active_ = activation_client_->GetActiveWindow(); |
156 if (active_ && focused_ != active_) | 156 if (active_ && focused_ != active_) |
157 tracker_.Add(active_); | 157 tracker_.Add(active_); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 304 } |
305 | 305 |
306 void DisplayController::AddObserver(Observer* observer) { | 306 void DisplayController::AddObserver(Observer* observer) { |
307 observers_.AddObserver(observer); | 307 observers_.AddObserver(observer); |
308 } | 308 } |
309 | 309 |
310 void DisplayController::RemoveObserver(Observer* observer) { | 310 void DisplayController::RemoveObserver(Observer* observer) { |
311 observers_.RemoveObserver(observer); | 311 observers_.RemoveObserver(observer); |
312 } | 312 } |
313 | 313 |
314 aura::RootWindow* DisplayController::GetPrimaryRootWindow() { | 314 aura::Window* DisplayController::GetPrimaryRootWindow() { |
315 DCHECK(!root_windows_.empty()); | 315 DCHECK(!root_windows_.empty()); |
316 return root_windows_[primary_display_id]; | 316 return root_windows_[primary_display_id]; |
317 } | 317 } |
318 | 318 |
319 aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int64 id) { | 319 aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { |
320 return root_windows_[id]; | 320 return root_windows_[id]; |
321 } | 321 } |
322 | 322 |
323 void DisplayController::CloseChildWindows() { | 323 void DisplayController::CloseChildWindows() { |
324 for (std::map<int64, aura::RootWindow*>::const_iterator it = | 324 for (std::map<int64, aura::RootWindow*>::const_iterator it = |
325 root_windows_.begin(); it != root_windows_.end(); ++it) { | 325 root_windows_.begin(); it != root_windows_.end(); ++it) { |
326 aura::RootWindow* root_window = it->second; | 326 aura::RootWindow* root_window = it->second; |
327 internal::RootWindowController* controller = | 327 internal::RootWindowController* controller = |
328 internal::GetRootWindowController(root_window); | 328 internal::GetRootWindowController(root_window); |
329 if (controller) { | 329 if (controller) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 void DisplayController::EnsurePointerInDisplays() { | 488 void DisplayController::EnsurePointerInDisplays() { |
489 // If the mouse is currently on a display in native location, | 489 // If the mouse is currently on a display in native location, |
490 // use the same native location. Otherwise find the display closest | 490 // use the same native location. Otherwise find the display closest |
491 // to the current cursor location in screen coordinates. | 491 // to the current cursor location in screen coordinates. |
492 | 492 |
493 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 493 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); |
494 gfx::Point target_location_in_native; | 494 gfx::Point target_location_in_native; |
495 int64 closest_distance_squared = -1; | 495 int64 closest_distance_squared = -1; |
496 internal::DisplayManager* display_manager = GetDisplayManager(); | 496 internal::DisplayManager* display_manager = GetDisplayManager(); |
497 | 497 |
498 aura::RootWindow* dst_root_window = NULL; | 498 aura::Window* dst_root_window = NULL; |
499 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 499 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
500 const gfx::Display& display = display_manager->GetDisplayAt(i); | 500 const gfx::Display& display = display_manager->GetDisplayAt(i); |
501 const internal::DisplayInfo display_info = | 501 const internal::DisplayInfo display_info = |
502 display_manager->GetDisplayInfo(display.id()); | 502 display_manager->GetDisplayInfo(display.id()); |
503 aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id()); | 503 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
504 if (display_info.bounds_in_native().Contains( | 504 if (display_info.bounds_in_native().Contains( |
505 cursor_location_in_native_coords_for_restore_)) { | 505 cursor_location_in_native_coords_for_restore_)) { |
506 dst_root_window = root_window; | 506 dst_root_window = root_window; |
507 target_location_in_native = cursor_location_in_native_coords_for_restore_; | 507 target_location_in_native = cursor_location_in_native_coords_for_restore_; |
508 break; | 508 break; |
509 } | 509 } |
510 gfx::Point center = display.bounds().CenterPoint(); | 510 gfx::Point center = display.bounds().CenterPoint(); |
511 // Use the distance squared from the center of the dislay. This is not | 511 // Use the distance squared from the center of the dislay. This is not |
512 // exactly "closest" display, but good enough to pick one | 512 // exactly "closest" display, but good enough to pick one |
513 // appropriate (and there are at most two displays). | 513 // appropriate (and there are at most two displays). |
514 // We don't care about actual distance, only relative to other displays, so | 514 // We don't care about actual distance, only relative to other displays, so |
515 // using the LengthSquared() is cheaper than Length(). | 515 // using the LengthSquared() is cheaper than Length(). |
516 | 516 |
517 int64 distance_squared = (center - point_in_screen).LengthSquared(); | 517 int64 distance_squared = (center - point_in_screen).LengthSquared(); |
518 if (closest_distance_squared < 0 || | 518 if (closest_distance_squared < 0 || |
519 closest_distance_squared > distance_squared) { | 519 closest_distance_squared > distance_squared) { |
520 aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id()); | 520 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
521 aura::client::ScreenPositionClient* client = | 521 aura::client::ScreenPositionClient* client = |
522 aura::client::GetScreenPositionClient(root_window); | 522 aura::client::GetScreenPositionClient(root_window); |
523 client->ConvertPointFromScreen(root_window, ¢er); | 523 client->ConvertPointFromScreen(root_window, ¢er); |
524 root_window->ConvertPointToNativeScreen(¢er); | 524 root_window->GetDispatcher()->ConvertPointToNativeScreen(¢er); |
525 dst_root_window = root_window; | 525 dst_root_window = root_window; |
526 target_location_in_native = center; | 526 target_location_in_native = center; |
527 closest_distance_squared = distance_squared; | 527 closest_distance_squared = distance_squared; |
528 } | 528 } |
529 } | 529 } |
530 dst_root_window->ConvertPointFromNativeScreen(&target_location_in_native); | 530 dst_root_window->GetDispatcher()->ConvertPointFromNativeScreen( |
| 531 &target_location_in_native); |
531 dst_root_window->MoveCursorTo(target_location_in_native); | 532 dst_root_window->MoveCursorTo(target_location_in_native); |
532 } | 533 } |
533 | 534 |
534 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( | 535 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( |
535 const aura::Window* window, | 536 const aura::Window* window, |
536 const gfx::Insets& insets) { | 537 const gfx::Insets& insets) { |
537 const aura::RootWindow* root_window = window->GetRootWindow(); | 538 const aura::Window* root_window = window->GetRootWindow(); |
538 int64 id = internal::GetRootWindowSettings(root_window)->display_id; | 539 int64 id = internal::GetRootWindowSettings(root_window)->display_id; |
539 // if id is |kInvaildDisplayID|, it's being deleted. | 540 // if id is |kInvaildDisplayID|, it's being deleted. |
540 DCHECK(id != gfx::Display::kInvalidDisplayID); | 541 DCHECK(id != gfx::Display::kInvalidDisplayID); |
541 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 542 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
542 } | 543 } |
543 | 544 |
544 const gfx::Display& DisplayController::GetDisplayNearestWindow( | 545 const gfx::Display& DisplayController::GetDisplayNearestWindow( |
545 const aura::Window* window) const { | 546 const aura::Window* window) const { |
546 if (!window) | 547 if (!window) |
547 return GetPrimaryDisplay(); | 548 return GetPrimaryDisplay(); |
548 const aura::RootWindow* root_window = window->GetRootWindow(); | 549 const aura::Window* root_window = window->GetRootWindow(); |
549 if (!root_window) | 550 if (!root_window) |
550 return GetPrimaryDisplay(); | 551 return GetPrimaryDisplay(); |
551 int64 id = internal::GetRootWindowSettings(root_window)->display_id; | 552 int64 id = internal::GetRootWindowSettings(root_window)->display_id; |
552 // if id is |kInvaildDisplayID|, it's being deleted. | 553 // if id is |kInvaildDisplayID|, it's being deleted. |
553 DCHECK(id != gfx::Display::kInvalidDisplayID); | 554 DCHECK(id != gfx::Display::kInvalidDisplayID); |
554 | 555 |
555 internal::DisplayManager* display_manager = GetDisplayManager(); | 556 internal::DisplayManager* display_manager = GetDisplayManager(); |
556 // RootWindow needs Display to determine its device scale factor. | 557 // RootWindow needs Display to determine its device scale factor. |
557 // TODO(oshima): We don't need full display info for mirror | 558 // TODO(oshima): We don't need full display info for mirror |
558 // window. Refactor so that RootWindow doesn't use it. | 559 // window. Refactor so that RootWindow doesn't use it. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 mirror_window_controller_->Close(); | 685 mirror_window_controller_->Close(); |
685 } | 686 } |
686 | 687 |
687 void DisplayController::PreDisplayConfigurationChange(bool display_removed) { | 688 void DisplayController::PreDisplayConfigurationChange(bool display_removed) { |
688 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 689 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
689 focus_activation_store_->Store(display_removed); | 690 focus_activation_store_->Store(display_removed); |
690 | 691 |
691 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 692 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); |
692 gfx::Display display = | 693 gfx::Display display = |
693 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); | 694 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); |
694 aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id()); | 695 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
695 | 696 |
696 aura::client::ScreenPositionClient* client = | 697 aura::client::ScreenPositionClient* client = |
697 aura::client::GetScreenPositionClient(root_window); | 698 aura::client::GetScreenPositionClient(root_window); |
698 client->ConvertPointFromScreen(root_window, &point_in_screen); | 699 client->ConvertPointFromScreen(root_window, &point_in_screen); |
699 root_window->ConvertPointToNativeScreen(&point_in_screen); | 700 root_window->GetDispatcher()->ConvertPointToNativeScreen(&point_in_screen); |
700 cursor_location_in_native_coords_for_restore_ = point_in_screen; | 701 cursor_location_in_native_coords_for_restore_ = point_in_screen; |
701 } | 702 } |
702 | 703 |
703 void DisplayController::PostDisplayConfigurationChange() { | 704 void DisplayController::PostDisplayConfigurationChange() { |
704 if (limiter_) | 705 if (limiter_) |
705 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 706 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
706 | 707 |
707 focus_activation_store_->Restore(); | 708 focus_activation_store_->Restore(); |
708 | 709 |
709 internal::DisplayManager* display_manager = GetDisplayManager(); | 710 internal::DisplayManager* display_manager = GetDisplayManager(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 768 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); |
768 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 769 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
769 #endif | 770 #endif |
770 } | 771 } |
771 | 772 |
772 void DisplayController::UpdateHostWindowNames() { | 773 void DisplayController::UpdateHostWindowNames() { |
773 #if defined(USE_X11) | 774 #if defined(USE_X11) |
774 // crbug.com/120229 - set the window title for the primary dislpay | 775 // crbug.com/120229 - set the window title for the primary dislpay |
775 // to "aura_root_0" so gtalk can find the primary root window to broadcast. | 776 // to "aura_root_0" so gtalk can find the primary root window to broadcast. |
776 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. | 777 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. |
777 aura::RootWindow* primary = Shell::GetPrimaryRootWindow(); | 778 aura::Window* primary = Shell::GetPrimaryRootWindow(); |
778 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 779 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
779 for (size_t i = 0; i < root_windows.size(); ++i) { | 780 for (size_t i = 0; i < root_windows.size(); ++i) { |
780 std::string name = | 781 std::string name = |
781 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 782 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
782 gfx::AcceleratedWidget xwindow = root_windows[i]->GetAcceleratedWidget(); | 783 gfx::AcceleratedWidget xwindow = |
| 784 root_windows[i]->GetDispatcher()->GetAcceleratedWidget(); |
783 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 785 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
784 } | 786 } |
785 #endif | 787 #endif |
786 } | 788 } |
787 | 789 |
788 } // namespace ash | 790 } // namespace ash |
OLD | NEW |