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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 210 |
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), |
| 220 is_cursor_compositing_enabled_(false), |
218 focus_activation_store_(new internal::FocusActivationStore()), | 221 focus_activation_store_(new internal::FocusActivationStore()), |
219 mirror_window_controller_(new internal::MirrorWindowController), | 222 cursor_window_controller_(new internal::CursorWindowController()), |
| 223 mirror_window_controller_(new internal::MirrorWindowController( |
| 224 cursor_window_controller_.get())), |
220 virtual_keyboard_window_controller_( | 225 virtual_keyboard_window_controller_( |
221 new internal::VirtualKeyboardWindowController) { | 226 new internal::VirtualKeyboardWindowController) { |
222 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
223 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 228 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
224 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && | 229 if (!command_line->HasSwitch(switches::kAshDisableDisplayChangeLimiter) && |
225 base::SysInfo::IsRunningOnChromeOS()) | 230 base::SysInfo::IsRunningOnChromeOS()) |
226 limiter_.reset(new DisplayChangeLimiter); | 231 limiter_.reset(new DisplayChangeLimiter); |
227 #endif | 232 #endif |
228 // Reset primary display to make sure that tests don't use | 233 // Reset primary display to make sure that tests don't use |
229 // stale display info from previous tests. | 234 // stale display info from previous tests. |
(...skipping 13 matching lines...) Expand all Loading... |
243 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 248 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
244 } | 249 } |
245 } | 250 } |
246 | 251 |
247 void DisplayController::Shutdown() { | 252 void DisplayController::Shutdown() { |
248 // Unset the display manager's delegate here because | 253 // Unset the display manager's delegate here because |
249 // DisplayManager outlives DisplayController. | 254 // DisplayManager outlives DisplayController. |
250 Shell::GetInstance()->display_manager()->set_delegate(NULL); | 255 Shell::GetInstance()->display_manager()->set_delegate(NULL); |
251 | 256 |
252 mirror_window_controller_.reset(); | 257 mirror_window_controller_.reset(); |
| 258 cursor_window_controller_.reset(); |
253 virtual_keyboard_window_controller_.reset(); | 259 virtual_keyboard_window_controller_.reset(); |
254 | 260 |
255 Shell::GetScreen()->RemoveObserver(this); | 261 Shell::GetScreen()->RemoveObserver(this); |
256 // Delete all root window controllers, which deletes root window | 262 // Delete all root window controllers, which deletes root window |
257 // from the last so that the primary root window gets deleted last. | 263 // from the last so that the primary root window gets deleted last. |
258 for (std::map<int64, aura::Window*>::const_reverse_iterator it = | 264 for (std::map<int64, aura::Window*>::const_reverse_iterator it = |
259 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { | 265 root_windows_.rbegin(); it != root_windows_.rend(); ++it) { |
260 internal::RootWindowController* controller = | 266 internal::RootWindowController* controller = |
261 internal::GetRootWindowController(it->second); | 267 internal::GetRootWindowController(it->second); |
262 DCHECK(controller); | 268 DCHECK(controller); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 base::Unretained(this))); | 399 base::Unretained(this))); |
394 } else { | 400 } else { |
395 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 401 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
396 } | 402 } |
397 #else | 403 #else |
398 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); | 404 SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay()); |
399 #endif | 405 #endif |
400 } | 406 } |
401 } | 407 } |
402 | 408 |
| 409 void DisplayController::SetCursorCompositingEnabled(bool enabled) { |
| 410 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 411 if (is_cursor_compositing_enabled_ != enabled) { |
| 412 is_cursor_compositing_enabled_ = enabled; |
| 413 UpdateCursorWindowContainer(); |
| 414 } |
| 415 #endif |
| 416 } |
| 417 |
| 418 void DisplayController::SetDisplayForCursor(const gfx::Display& display) { |
| 419 if (!is_cursor_compositing_enabled_) |
| 420 return; |
| 421 |
| 422 cursor_window_controller_->SetContainer( |
| 423 internal::GetRootWindowController(root_windows_[display.id()])-> |
| 424 GetContainer(internal::kShellWindowId_OverlayContainer)); |
| 425 cursor_window_controller_->SetDisplayBounds(display.bounds()); |
| 426 } |
| 427 |
403 void DisplayController::SetPrimaryDisplayId(int64 id) { | 428 void DisplayController::SetPrimaryDisplayId(int64 id) { |
404 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); | 429 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); |
405 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) | 430 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id) |
406 return; | 431 return; |
407 | 432 |
408 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); | 433 const gfx::Display& display = GetDisplayManager()->GetDisplayForId(id); |
409 if (display.is_valid()) | 434 if (display.is_valid()) |
410 SetPrimaryDisplay(display); | 435 SetPrimaryDisplay(display); |
411 } | 436 } |
412 | 437 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 631 |
607 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { | 632 void DisplayController::OnWindowTreeHostResized(const aura::RootWindow* root) { |
608 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 633 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
609 const_cast<aura::Window*>(root->window())); | 634 const_cast<aura::Window*>(root->window())); |
610 | 635 |
611 internal::DisplayManager* display_manager = GetDisplayManager(); | 636 internal::DisplayManager* display_manager = GetDisplayManager(); |
612 if (display_manager->UpdateDisplayBounds( | 637 if (display_manager->UpdateDisplayBounds( |
613 display.id(), | 638 display.id(), |
614 root->host()->GetBounds())) { | 639 root->host()->GetBounds())) { |
615 mirror_window_controller_->UpdateWindow(); | 640 mirror_window_controller_->UpdateWindow(); |
| 641 UpdateCursorWindowContainer(); |
616 } | 642 } |
617 } | 643 } |
618 | 644 |
619 void DisplayController::CreateOrUpdateNonDesktopDisplay( | 645 void DisplayController::CreateOrUpdateNonDesktopDisplay( |
620 const internal::DisplayInfo& info) { | 646 const internal::DisplayInfo& info) { |
621 switch (GetDisplayManager()->second_display_mode()) { | 647 switch (GetDisplayManager()->second_display_mode()) { |
622 case internal::DisplayManager::MIRRORING: | 648 case internal::DisplayManager::MIRRORING: |
623 mirror_window_controller_->UpdateWindow(info); | 649 mirror_window_controller_->UpdateWindow(info); |
624 virtual_keyboard_window_controller_->Close(); | 650 virtual_keyboard_window_controller_->Close(); |
| 651 UpdateCursorWindowContainer(); |
625 break; | 652 break; |
626 case internal::DisplayManager::VIRTUAL_KEYBOARD: | 653 case internal::DisplayManager::VIRTUAL_KEYBOARD: |
627 mirror_window_controller_->Close(); | 654 mirror_window_controller_->Close(); |
628 virtual_keyboard_window_controller_->UpdateWindow(info); | 655 virtual_keyboard_window_controller_->UpdateWindow(info); |
| 656 UpdateCursorWindowContainer(); |
629 break; | 657 break; |
630 case internal::DisplayManager::EXTENDED: | 658 case internal::DisplayManager::EXTENDED: |
631 NOTREACHED(); | 659 NOTREACHED(); |
632 } | 660 } |
633 } | 661 } |
634 | 662 |
635 void DisplayController::CloseNonDesktopDisplay() { | 663 void DisplayController::CloseNonDesktopDisplay() { |
636 mirror_window_controller_->Close(); | 664 mirror_window_controller_->Close(); |
637 virtual_keyboard_window_controller_->Close(); | 665 virtual_keyboard_window_controller_->Close(); |
| 666 UpdateCursorWindowContainer(); |
638 } | 667 } |
639 | 668 |
640 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { | 669 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { |
641 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 670 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
642 focus_activation_store_->Store(clear_focus); | 671 focus_activation_store_->Store(clear_focus); |
643 gfx::Screen* screen = Shell::GetScreen(); | 672 gfx::Screen* screen = Shell::GetScreen(); |
644 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); | 673 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
645 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 674 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
646 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 675 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
647 | 676 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 for (size_t i = 0; i < root_windows.size(); ++i) { | 763 for (size_t i = 0; i < root_windows.size(); ++i) { |
735 std::string name = | 764 std::string name = |
736 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 765 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
737 gfx::AcceleratedWidget xwindow = | 766 gfx::AcceleratedWidget xwindow = |
738 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); | 767 root_windows[i]->GetDispatcher()->host()->GetAcceleratedWidget(); |
739 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 768 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
740 } | 769 } |
741 #endif | 770 #endif |
742 } | 771 } |
743 | 772 |
| 773 void DisplayController::UpdateCursorWindowContainer() { |
| 774 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 775 if (is_cursor_compositing_enabled_) { |
| 776 cursor_window_controller_->SetMirroring(false); |
| 777 cursor_window_controller_->SetContainer( |
| 778 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 779 internal::kShellWindowId_OverlayContainer)); |
| 780 } else { |
| 781 aura::RootWindow* mirror_root_window = |
| 782 mirror_window_controller_->root_window(); |
| 783 if (mirror_root_window) { |
| 784 cursor_window_controller_->SetMirroring(true); |
| 785 cursor_window_controller_->SetContainer(mirror_root_window->window()); |
| 786 } else { |
| 787 cursor_window_controller_->SetContainer(NULL); |
| 788 } |
| 789 } |
| 790 #endif |
| 791 } |
| 792 |
744 } // namespace ash | 793 } // namespace ash |
OLD | NEW |