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_manager.h" | 5 #include "ash/display/display_manager.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "ash/accelerometer/accelerometer_controller.h" |
12 #include "ash/ash_switches.h" | 13 #include "ash/ash_switches.h" |
13 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
14 #include "ash/display/screen_ash.h" | 15 #include "ash/display/screen_ash.h" |
15 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
17 #include "base/auto_reset.h" | 18 #include "base/auto_reset.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
21 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "grit/ash_strings.h" | 26 #include "grit/ash_strings.h" |
26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/gfx/display.h" | 28 #include "ui/gfx/display.h" |
28 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
30 #include "ui/gfx/size_conversions.h" | 31 #include "ui/gfx/size_conversions.h" |
| 32 #include "ui/gfx/vector3d_f.h" |
31 | 33 |
32 #if defined(USE_X11) | 34 #if defined(USE_X11) |
33 #include "ui/base/x/x11_util.h" | 35 #include "ui/base/x/x11_util.h" |
34 #endif | 36 #endif |
35 | 37 |
36 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
37 #include "ash/display/output_configurator_animation.h" | 39 #include "ash/display/output_configurator_animation.h" |
38 #include "base/sys_info.h" | 40 #include "base/sys_info.h" |
39 #endif | 41 #endif |
40 | 42 |
(...skipping 18 matching lines...) Expand all Loading... |
59 | 61 |
60 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 62 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
61 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
62 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 64 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
63 // for the full list of resolutions. | 65 // for the full list of resolutions. |
64 const float kUIScalesFor2x[] = | 66 const float kUIScalesFor2x[] = |
65 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; | 67 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; |
66 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; | 68 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; |
67 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; | 69 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; |
68 | 70 |
| 71 // The angle which the screen has to be rotated past before the display will |
| 72 // rotate to match it (i.e. 45.0f is no stickiness). |
| 73 const float kDisplayRotationStickyAngleDegrees = 60.0f; |
| 74 |
69 struct DisplaySortFunctor { | 75 struct DisplaySortFunctor { |
70 bool operator()(const gfx::Display& a, const gfx::Display& b) { | 76 bool operator()(const gfx::Display& a, const gfx::Display& b) { |
71 return a.id() < b.id(); | 77 return a.id() < b.id(); |
72 } | 78 } |
73 }; | 79 }; |
74 | 80 |
75 struct DisplayInfoSortFunctor { | 81 struct DisplayInfoSortFunctor { |
76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 82 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
77 return a.id() < b.id(); | 83 return a.id() < b.id(); |
78 } | 84 } |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 delete screen_for_shutdown; | 968 delete screen_for_shutdown; |
963 screen_for_shutdown = screen_ash_->CloneForShutdown(); | 969 screen_for_shutdown = screen_ash_->CloneForShutdown(); |
964 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, | 970 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, |
965 screen_for_shutdown); | 971 screen_for_shutdown); |
966 if (native_is_ash) { | 972 if (native_is_ash) { |
967 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, | 973 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, |
968 screen_for_shutdown); | 974 screen_for_shutdown); |
969 } | 975 } |
970 } | 976 } |
971 | 977 |
| 978 void DisplayManager::OnAccelerometerUpdated(const gfx::Vector3dF& base, |
| 979 const gfx::Vector3dF& lid) { |
| 980 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
| 981 float lid_flattened_length = lid_flattened.Length(); |
| 982 // When the lid is close to being flat, don't change rotation as it is too |
| 983 // sensitive to slight movements. |
| 984 if (lid_flattened_length < 0.3) |
| 985 return; |
| 986 |
| 987 // The reference vector is the angle of gravity when the device is rotated |
| 988 // clockwise by 45 degrees. Computing the angle between this vector and |
| 989 // gravity we can easily determine the expected display rotation. |
| 990 gfx::Vector3dF reference(-1.0f, 1.0f, 0.0f); |
| 991 |
| 992 // Set the down vector to match the expected direction of gravity given the |
| 993 // last configured rotation. This is used to enforce a stickiness that the |
| 994 // user must overcome to rotate the display and prevents frequent rotations |
| 995 // when holding the device near 45 degrees. |
| 996 gfx::Display::Rotation current_rotation = |
| 997 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 998 gfx::Vector3dF down(0.0f, 0.0f, 0.0f); |
| 999 if (current_rotation == gfx::Display::ROTATE_0) |
| 1000 down.set_x(-1.0f); |
| 1001 else if (current_rotation == gfx::Display::ROTATE_90) |
| 1002 down.set_y(1.0f); |
| 1003 else if (current_rotation == gfx::Display::ROTATE_180) |
| 1004 down.set_x(1.0f); |
| 1005 else |
| 1006 down.set_y(-1.0f); |
| 1007 |
| 1008 // Don't rotate if the screen has not passed the threshold. |
| 1009 float sticky_angle = acos(gfx::DotProduct(down, lid_flattened) / |
| 1010 down.Length() / lid_flattened_length) * 180.0 / 3.1415965; |
| 1011 if (sticky_angle < kDisplayRotationStickyAngleDegrees) |
| 1012 return; |
| 1013 |
| 1014 float angle = acos(gfx::DotProduct(reference, lid_flattened) / |
| 1015 reference.Length() / lid_flattened_length) * 180.0 / 3.1415965; |
| 1016 |
| 1017 gfx::Vector3dF cross(reference); |
| 1018 cross.Cross(lid); |
| 1019 float sign = gfx::DotProduct(cross, gfx::Vector3dF(0.0f, 0.0f, 1.0f)); |
| 1020 if (sign < 0.0f) |
| 1021 angle = 360.0f - angle; |
| 1022 |
| 1023 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
| 1024 if (angle < 90.0f) |
| 1025 new_rotation = gfx::Display::ROTATE_0; |
| 1026 else if (angle < 180.0f) |
| 1027 new_rotation = gfx::Display::ROTATE_270; |
| 1028 else if (angle < 270.0f) |
| 1029 new_rotation = gfx::Display::ROTATE_180; |
| 1030 |
| 1031 SetDisplayRotation(gfx::Display::InternalDisplayId(), new_rotation); |
| 1032 } |
| 1033 |
972 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { | 1034 gfx::Display* DisplayManager::FindDisplayForId(int64 id) { |
973 for (DisplayList::iterator iter = displays_.begin(); | 1035 for (DisplayList::iterator iter = displays_.begin(); |
974 iter != displays_.end(); ++iter) { | 1036 iter != displays_.end(); ++iter) { |
975 if ((*iter).id() == id) | 1037 if ((*iter).id() == id) |
976 return &(*iter); | 1038 return &(*iter); |
977 } | 1039 } |
978 DLOG(WARNING) << "Could not find display:" << id; | 1040 DLOG(WARNING) << "Could not find display:" << id; |
979 return NULL; | 1041 return NULL; |
980 } | 1042 } |
981 | 1043 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 break; | 1172 break; |
1111 } | 1173 } |
1112 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1174 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
1113 secondary_display->set_bounds( | 1175 secondary_display->set_bounds( |
1114 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1176 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
1115 secondary_display->UpdateWorkAreaFromInsets(insets); | 1177 secondary_display->UpdateWorkAreaFromInsets(insets); |
1116 } | 1178 } |
1117 | 1179 |
1118 } // namespace internal | 1180 } // namespace internal |
1119 } // namespace ash | 1181 } // namespace ash |
OLD | NEW |