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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "ash/ash_root_window_transformer.h" | 10 #include "ash/ash_root_window_transformer.h" |
| 11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
| 12 #include "ash/display/display_manager.h" | 12 #include "ash/display/display_manager.h" |
| 13 #include "ash/display/display_pref_util.h" | 13 #include "ash/display/display_pref_util.h" |
| 14 #include "ash/host/root_window_host_factory.h" | 14 #include "ash/host/root_window_host_factory.h" |
| 15 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 16 #include "ash/screen_ash.h" | 16 #include "ash/screen_ash.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "ash/wm/coordinate_conversion.h" | 18 #include "ash/wm/coordinate_conversion.h" |
| 19 #include "ash/wm/property_util.h" | 19 #include "ash/wm/property_util.h" |
| 20 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 22 #include "base/json/json_value_converter.h" | 22 #include "base/json/json_value_converter.h" |
| 23 #include "base/string_piece.h" | 23 #include "base/string_piece.h" |
| 24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
| 25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| 27 #include "ui/aura/client/cursor_client.h" | |
| 27 #include "ui/aura/client/screen_position_client.h" | 28 #include "ui/aura/client/screen_position_client.h" |
| 28 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
| 29 #include "ui/aura/root_window.h" | 30 #include "ui/aura/root_window.h" |
| 30 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_property.h" | 32 #include "ui/aura/window_property.h" |
| 32 #include "ui/compositor/compositor.h" | 33 #include "ui/compositor/compositor.h" |
| 33 #include "ui/compositor/dip_util.h" | 34 #include "ui/compositor/dip_util.h" |
| 34 #include "ui/gfx/display.h" | 35 #include "ui/gfx/display.h" |
| 35 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
| 36 | 37 |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 GetDisplayManager()->set_force_bounds_changed(false); | 716 GetDisplayManager()->set_force_bounds_changed(false); |
| 716 } | 717 } |
| 717 | 718 |
| 718 gfx::Display* DisplayController::GetSecondaryDisplay() { | 719 gfx::Display* DisplayController::GetSecondaryDisplay() { |
| 719 internal::DisplayManager* display_manager = GetDisplayManager(); | 720 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 720 CHECK_EQ(2U, display_manager->GetNumDisplays()); | 721 CHECK_EQ(2U, display_manager->GetNumDisplays()); |
| 721 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? | 722 return display_manager->GetDisplayAt(0)->id() == primary_display_id ? |
| 722 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); | 723 display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0); |
| 723 } | 724 } |
| 724 | 725 |
| 726 void DisplayController::EnsurePointerInDisplays() { | |
| 727 // Don't try to move the pointer during the boot/startup. | |
| 728 if (!HasPrimaryDisplay()) | |
| 729 return; | |
| 730 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | |
| 731 gfx::Point target_location; | |
| 732 int64 closest_distance_squared = -1; | |
| 733 internal::DisplayManager* display_manager = GetDisplayManager(); | |
| 734 | |
| 735 aura::RootWindow* dst_root_window = NULL; | |
| 736 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | |
| 737 const gfx::Display* display = display_manager->GetDisplayAt(i); | |
| 738 aura::RootWindow* root_window = GetRootWindowForDisplayId(display->id()); | |
| 739 if (display->bounds().Contains(location_in_screen)) { | |
| 740 dst_root_window = root_window; | |
| 741 target_location = location_in_screen; | |
|
Jun Mukai
2013/04/06 03:13:39
in which case do we still need to call MoveCursorT
oshima
2013/04/08 18:00:40
Yes, we need to update the cursor when screen was
| |
| 742 break; | |
| 743 } | |
| 744 gfx::Point center = display->bounds().CenterPoint(); | |
| 745 // Use the distance squared from the center of the dislay. This is not | |
| 746 // exactly "closest" display, but good enough to pick one | |
| 747 // appropriate (and there are at most two displays). | |
| 748 // We don't care about actual distance, only relative to other displays, so | |
| 749 // using the LengthSquared() is cheaper than Length(). | |
| 750 | |
| 751 int64 distance_squared = (center - location_in_screen).LengthSquared(); | |
| 752 if (closest_distance_squared < 0 || | |
| 753 closest_distance_squared > distance_squared) { | |
| 754 dst_root_window = root_window; | |
| 755 target_location = center; | |
| 756 closest_distance_squared = distance_squared; | |
| 757 } | |
| 758 } | |
|
Jun Mukai
2013/04/06 03:13:39
It seems that this method doesn't ensure it if dst
oshima
2013/04/08 18:00:40
good point. done.
| |
| 759 if (dst_root_window) { | |
| 760 aura::client::ScreenPositionClient* client = | |
| 761 aura::client::GetScreenPositionClient(dst_root_window); | |
| 762 client->ConvertPointFromScreen(dst_root_window, &target_location); | |
| 763 dst_root_window->MoveCursorTo(target_location); | |
| 764 } | |
| 765 } | |
| 766 | |
| 767 gfx::Point DisplayController::GetNativeMouseCursorLocation() const { | |
| 768 gfx::Point location = Shell::GetScreen()->GetCursorScreenPoint(); | |
| 769 const gfx::Display& display = | |
| 770 Shell::GetScreen()->GetDisplayNearestPoint(location); | |
| 771 const aura::RootWindow* root_window = | |
| 772 root_windows_.find(display.id())->second; | |
| 773 aura::client::ScreenPositionClient* client = | |
| 774 aura::client::GetScreenPositionClient(root_window); | |
| 775 client->ConvertPointFromScreen(root_window, &location); | |
| 776 root_window->ConvertPointToNativeScreen(&location); | |
| 777 return location; | |
| 778 } | |
| 779 | |
| 780 void DisplayController::UpdateMouseCursor(const gfx::Point& point_in_native) { | |
| 781 std::vector<aura::RootWindow*> root_windows = GetAllRootWindows(); | |
| 782 for (std::vector<aura::RootWindow*>::iterator iter = root_windows.begin(); | |
| 783 iter != root_windows.end(); | |
| 784 ++iter) { | |
| 785 aura::RootWindow* root_window = *iter; | |
| 786 gfx::Rect bounds(root_window->GetHostOrigin(), root_window->GetHostSize()); | |
|
Jun Mukai
2013/04/06 03:13:39
bounds_in_native?
oshima
2013/04/08 18:00:40
Done.
| |
| 787 if (bounds.Contains(point_in_native)) { | |
| 788 gfx::Point point(point_in_native); | |
| 789 root_window->ConvertPointFromNativeScreen(&point); | |
| 790 root_window->MoveCursorTo(point); | |
| 791 break; | |
| 792 } | |
| 793 } | |
| 794 } | |
| 795 | |
| 725 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { | 796 void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 726 if (limiter_.get()) | 797 if (limiter_.get()) |
| 727 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 798 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
| 728 const internal::DisplayInfo& display_info = | 799 const internal::DisplayInfo& display_info = |
| 729 GetDisplayManager()->GetDisplayInfo(display.id()); | 800 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 730 DCHECK(!display_info.bounds_in_pixel().IsEmpty()); | 801 DCHECK(!display_info.bounds_in_pixel().IsEmpty()); |
| 731 | 802 |
| 732 UpdateDisplayBoundsForLayout(); | 803 UpdateDisplayBoundsForLayout(); |
| 733 aura::RootWindow* root = root_windows_[display.id()]; | 804 aura::RootWindow* root = root_windows_[display.id()]; |
| 734 SetDisplayPropertiesOnHostWindow(root, display); | 805 SetDisplayPropertiesOnHostWindow(root, display); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 } | 1009 } |
| 939 | 1010 |
| 940 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 1011 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
| 941 #if defined(OS_CHROMEOS) | 1012 #if defined(OS_CHROMEOS) |
| 942 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 1013 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); |
| 943 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 1014 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
| 944 #endif | 1015 #endif |
| 945 } | 1016 } |
| 946 | 1017 |
| 947 } // namespace ash | 1018 } // namespace ash |
| OLD | NEW |