Chromium Code Reviews| 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/cursor_window_controller.h" | |
| 12 #include "ash/display/display_layout_store.h" | 13 #include "ash/display/display_layout_store.h" |
| 13 #include "ash/display/display_manager.h" | 14 #include "ash/display/display_manager.h" |
| 14 #include "ash/display/mirror_window_controller.h" | 15 #include "ash/display/mirror_window_controller.h" |
| 15 #include "ash/display/root_window_transformers.h" | 16 #include "ash/display/root_window_transformers.h" |
| 16 #include "ash/display/virtual_keyboard_window_controller.h" | 17 #include "ash/display/virtual_keyboard_window_controller.h" |
| 17 #include "ash/host/root_window_host_factory.h" | 18 #include "ash/host/root_window_host_factory.h" |
| 18 #include "ash/root_window_controller.h" | 19 #include "ash/root_window_controller.h" |
| 19 #include "ash/root_window_settings.h" | 20 #include "ash/root_window_settings.h" |
| 20 #include "ash/screen_util.h" | 21 #include "ash/screen_util.h" |
| 21 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 22 #include "ash/shell_delegate.h" | 23 #include "ash/shell_delegate.h" |
| 24 #include "ash/shell_window_ids.h" | |
| 23 #include "ash/wm/coordinate_conversion.h" | 25 #include "ash/wm/coordinate_conversion.h" |
| 24 #include "base/command_line.h" | 26 #include "base/command_line.h" |
| 25 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 26 #include "ui/aura/client/activation_client.h" | 28 #include "ui/aura/client/activation_client.h" |
| 27 #include "ui/aura/client/capture_client.h" | 29 #include "ui/aura/client/capture_client.h" |
| 28 #include "ui/aura/client/focus_client.h" | 30 #include "ui/aura/client/focus_client.h" |
| 29 #include "ui/aura/client/screen_position_client.h" | 31 #include "ui/aura/client/screen_position_client.h" |
| 30 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
| 31 #include "ui/aura/root_window_transformer.h" | 33 #include "ui/aura/root_window_transformer.h" |
| 32 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { | 211 bool DisplayController::DisplayChangeLimiter::IsThrottled() const { |
| 210 return base::Time::Now() < throttle_timeout_; | 212 return base::Time::Now() < throttle_timeout_; |
| 211 } | 213 } |
| 212 | 214 |
| 213 //////////////////////////////////////////////////////////////////////////////// | 215 //////////////////////////////////////////////////////////////////////////////// |
| 214 // DisplayController | 216 // DisplayController |
| 215 | 217 |
| 216 DisplayController::DisplayController() | 218 DisplayController::DisplayController() |
| 217 : primary_root_window_for_replace_(NULL), | 219 : primary_root_window_for_replace_(NULL), |
| 218 focus_activation_store_(new internal::FocusActivationStore()), | 220 focus_activation_store_(new internal::FocusActivationStore()), |
| 219 mirror_window_controller_(new internal::MirrorWindowController), | 221 cursor_window_controller_(new internal::CursorWindowController()), |
| 222 mirror_window_controller_(new internal::MirrorWindowController()), | |
| 220 virtual_keyboard_window_controller_( | 223 virtual_keyboard_window_controller_( |
| 221 new internal::VirtualKeyboardWindowController) { | 224 new internal::VirtualKeyboardWindowController) { |
| 222 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
| 223 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 226 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 224 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && | 227 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && |
| 225 base::SysInfo::IsRunningOnChromeOS()) | 228 base::SysInfo::IsRunningOnChromeOS()) |
| 226 limiter_.reset(new DisplayChangeLimiter); | 229 limiter_.reset(new DisplayChangeLimiter); |
| 227 #endif | 230 #endif |
| 228 // Reset primary display to make sure that tests don't use | 231 // Reset primary display to make sure that tests don't use |
| 229 // stale display info from previous tests. | 232 // stale display info from previous tests. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 242 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 245 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 243 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 246 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
| 244 } | 247 } |
| 245 } | 248 } |
| 246 | 249 |
| 247 void DisplayController::Shutdown() { | 250 void DisplayController::Shutdown() { |
| 248 // Unset the display manager's delegate here because | 251 // Unset the display manager's delegate here because |
| 249 // DisplayManager outlives DisplayController. | 252 // DisplayManager outlives DisplayController. |
| 250 Shell::GetInstance()->display_manager()->set_delegate(NULL); | 253 Shell::GetInstance()->display_manager()->set_delegate(NULL); |
| 251 | 254 |
| 255 cursor_window_controller_.reset(); | |
| 252 mirror_window_controller_.reset(); | 256 mirror_window_controller_.reset(); |
| 253 virtual_keyboard_window_controller_.reset(); | 257 virtual_keyboard_window_controller_.reset(); |
| 254 | 258 |
| 255 Shell::GetScreen()->RemoveObserver(this); | 259 Shell::GetScreen()->RemoveObserver(this); |
| 256 // Delete all root window controllers, which deletes root window | 260 // Delete all root window controllers, which deletes root window |
| 257 // from the last so that the primary root window gets deleted last. | 261 // from the last so that the primary root window gets deleted last. |
| 258 for (std::map<int64, aura::Window*>::const_reverse_iterator it = | 262 for (std::map<int64, aura::Window*>::const_reverse_iterator it = |
| 259 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 263 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
| 260 internal::RootWindowController* controller = | 264 internal::RootWindowController* controller = |
| 261 internal::GetRootWindowController(it->second); | 265 internal::GetRootWindowController(it->second); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 base::Unretained(this))); | 397 base::Unretained(this))); |
| 394 } else { | 398 } else { |
| 395 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 399 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 396 } | 400 } |
| 397 #else | 401 #else |
| 398 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 402 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
| 399 #endif | 403 #endif |
| 400 } | 404 } |
| 401 } | 405 } |
| 402 | 406 |
| 407 void DisplayController::SetCursorCompositingEnabled(bool enabled) { | |
| 408 #if defined(OS_CHROMEOS) && defined(USE_X11) | |
| 409 if (cursor_window_controller_->is_cursor_compositing_enabled() != enabled) { | |
| 410 cursor_window_controller_->SetCursorCompositingEnabled(enabled); | |
| 411 UpdateCursorWindowContainer(); | |
| 412 } | |
| 413 #endif | |
| 414 } | |
| 415 | |
| 416 void DisplayController::SetDisplayForCursor(const gfx::Display& display) { | |
|
oshima
2014/02/05 23:43:39
Can you move this method to CursorWindowController
hshi1
2014/02/06 00:48:44
Done.
| |
| 417 if (!cursor_window_controller_->is_cursor_compositing_enabled()) | |
| 418 return; | |
| 419 | |
| 420 cursor_window_controller_->SetContainer( | |
| 421 internal::GetRootWindowController(root_windows_[display.id()])-> | |
| 422 GetContainer(internal::kShellWindowId_OverlayContainer)); | |
| 423 cursor_window_controller_->SetBoundsInScreen(display.bounds()); | |
| 424 } | |
| 425 | |
| 403 void DisplayController::SetPrimaryDisplayId(int64 id) { | 426 void DisplayController::SetPrimaryDisplayId(int64 id) { |
| 404 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); | 427 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); |
| 405 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) | 428 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) |
| 406 return; | 429 return; |
| 407 | 430 |
| 408 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); | 431 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); |
| 409 if (display.is_valid()) | 432 if (display.is_valid()) |
| 410 SetPrimaryDisplay(display); | 433 SetPrimaryDisplay(display); |
| 411 } | 434 } |
| 412 | 435 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 | 629 |
| 607 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { | 630 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { |
| 608 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 631 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 609 const_cast<aura::Window*>(root->window())); | 632 const_cast<aura::Window*>(root->window())); |
| 610 | 633 |
| 611 internal::DisplayManager* display_manager = GetDisplayManager(); | 634 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 612 if (display_manager->UpdateDisplayBounds( | 635 if (display_manager->UpdateDisplayBounds( |
| 613 display.id(), | 636 display.id(), |
| 614 root->host()->GetBounds())) { | 637 root->host()->GetBounds())) { |
| 615 mirror_window_controller_->UpdateWindow(); | 638 mirror_window_controller_->UpdateWindow(); |
| 639 UpdateCursorWindowContainer(); | |
| 616 } | 640 } |
| 617 } | 641 } |
| 618 | 642 |
| 619 void DisplayController::CreateOrUpdateNonDesktopDisplay( | 643 void DisplayController::CreateOrUpdateNonDesktopDisplay( |
| 620 const internal::DisplayInfo& info) { | 644 const internal::DisplayInfo& info) { |
| 621 switch (GetDisplayManager()->second_display_mode()) { | 645 switch (GetDisplayManager()->second_display_mode()) { |
| 622 case internal::DisplayManager::MIRRORING: | 646 case internal::DisplayManager::MIRRORING: |
| 623 mirror_window_controller_->UpdateWindow(info); | 647 mirror_window_controller_->UpdateWindow(info); |
| 624 virtual_keyboard_window_controller_->Close(); | 648 virtual_keyboard_window_controller_->Close(); |
| 649 UpdateCursorWindowContainer(); | |
| 625 break; | 650 break; |
| 626 case internal::DisplayManager::VIRTUAL_KEYBOARD: | 651 case internal::DisplayManager::VIRTUAL_KEYBOARD: |
| 627 mirror_window_controller_->Close(); | 652 mirror_window_controller_->Close(); |
| 628 virtual_keyboard_window_controller_->UpdateWindow(info); | 653 virtual_keyboard_window_controller_->UpdateWindow(info); |
| 654 UpdateCursorWindowContainer(); | |
| 629 break; | 655 break; |
| 630 case internal::DisplayManager::EXTENDED: | 656 case internal::DisplayManager::EXTENDED: |
| 631 NOTREACHED(); | 657 NOTREACHED(); |
| 632 } | 658 } |
| 633 } | 659 } |
| 634 | 660 |
| 635 void DisplayController::CloseNonDesktopDisplay() { | 661 void DisplayController::CloseNonDesktopDisplay() { |
| 636 mirror_window_controller_->Close(); | 662 mirror_window_controller_->Close(); |
| 637 virtual_keyboard_window_controller_->Close(); | 663 virtual_keyboard_window_controller_->Close(); |
| 664 UpdateCursorWindowContainer(); | |
| 638 } | 665 } |
| 639 | 666 |
| 640 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { | 667 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { |
| 641 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 668 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
| 642 focus_activation_store_->Store(clear_focus); | 669 focus_activation_store_->Store(clear_focus); |
| 643 gfx::Screen* screen = Shell::GetScreen(); | 670 gfx::Screen* screen = Shell::GetScreen(); |
| 644 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); | 671 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
| 645 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 672 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
| 646 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 673 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
| 647 | 674 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 for (size_t i = 0; i < root_windows.size(); ++i) { | 761 for (size_t i = 0; i < root_windows.size(); ++i) { |
| 735 std::string name = | 762 std::string name = |
| 736 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 763 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
| 737 gfx::AcceleratedWidget xwindow = | 764 gfx::AcceleratedWidget xwindow = |
| 738 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); | 765 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); |
| 739 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 766 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
| 740 } | 767 } |
| 741 #endif | 768 #endif |
| 742 } | 769 } |
| 743 | 770 |
| 771 void DisplayController::UpdateCursorWindowContainer() { | |
| 772 #if defined(OS_CHROMEOS) && defined(USE_X11) | |
| 773 if (cursor_window_controller_->is_cursor_compositing_enabled()) { | |
| 774 cursor_window_controller_->SetContainer( | |
| 775 Shell::GetPrimaryRootWindowController()->GetContainer( | |
| 776 internal::kShellWindowId_OverlayContainer)); | |
| 777 } else { | |
| 778 aura::RootWindow* mirror_root_window = | |
| 779 mirror_window_controller_->root_window(); | |
| 780 cursor_window_controller_->SetContainer( | |
| 781 mirror_root_window ? mirror_root_window->window() : NULL); | |
| 782 } | |
| 783 #endif | |
|
oshima
2014/02/05 23:43:39
Can this be in CursorWindowController too?
hshi1
2014/02/06 00:48:44
Done.
| |
| 784 } | |
| 785 | |
| 744 } // namespace ash | 786 } // namespace ash |
| OLD | NEW |