OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/rotation/tray_rotation_lock.h" | 5 #include "ash/system/rotation/tray_rotation_lock.h" |
6 | 6 |
7 #include "ash/display/screen_orientation_controller_chromeos.h" | 7 #include "ash/display/screen_orientation_controller_chromeos.h" |
8 #include "ash/resources/vector_icons/vector_icons.h" | 8 #include "ash/resources/vector_icons/vector_icons.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_port.h" |
10 #include "ash/strings/grit/ash_strings.h" | 11 #include "ash/strings/grit/ash_strings.h" |
11 #include "ash/system/tray/actionable_view.h" | 12 #include "ash/system/tray/actionable_view.h" |
12 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
13 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
14 #include "ash/system/tray/tray_popup_item_style.h" | 15 #include "ash/system/tray/tray_popup_item_style.h" |
15 #include "ash/system/tray/tray_popup_utils.h" | 16 #include "ash/system/tray/tray_popup_utils.h" |
16 #include "ash/system/tray/tri_view.h" | 17 #include "ash/system/tray/tri_view.h" |
17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
18 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 22 #include "ui/display/manager/managed_display_info.h" |
21 #include "ui/gfx/paint_vector_icon.h" | 23 #include "ui/gfx/paint_vector_icon.h" |
22 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
23 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
25 | 27 |
26 namespace ash { | 28 namespace ash { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 bool IsMaximizeModeWindowManagerEnabled() { | 32 bool IsMaximizeModeWindowManagerEnabled() { |
31 return Shell::Get() | 33 return Shell::Get() |
32 ->maximize_mode_controller() | 34 ->maximize_mode_controller() |
33 ->IsMaximizeModeWindowManagerEnabled(); | 35 ->IsMaximizeModeWindowManagerEnabled(); |
34 } | 36 } |
35 | 37 |
36 bool IsUserRotationLocked() { | 38 bool IsUserRotationLocked() { |
37 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); | 39 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); |
38 } | 40 } |
39 | 41 |
| 42 bool IsCurrentRotationPortrait() { |
| 43 display::Display::Rotation current_rotation = |
| 44 ShellPort::Get() |
| 45 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
| 46 .GetActiveRotation(); |
| 47 return current_rotation == display::Display::ROTATE_90 || |
| 48 current_rotation == display::Display::ROTATE_270; |
| 49 } |
| 50 |
40 } // namespace | 51 } // namespace |
41 | 52 |
42 namespace tray { | 53 namespace tray { |
43 | 54 |
44 class RotationLockDefaultView : public ActionableView, | 55 class RotationLockDefaultView : public ActionableView, |
45 public ShellObserver, | 56 public ShellObserver, |
46 public ScreenOrientationController::Observer { | 57 public ScreenOrientationController::Observer { |
47 public: | 58 public: |
48 explicit RotationLockDefaultView(SystemTrayItem* owner); | 59 explicit RotationLockDefaultView(SystemTrayItem* owner); |
49 ~RotationLockDefaultView() override; | 60 ~RotationLockDefaultView() override; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 Shell::Get()->screen_orientation_controller()->AddObserver(this); | 106 Shell::Get()->screen_orientation_controller()->AddObserver(this); |
96 } | 107 } |
97 | 108 |
98 RotationLockDefaultView::~RotationLockDefaultView() { | 109 RotationLockDefaultView::~RotationLockDefaultView() { |
99 StopObservingRotation(); | 110 StopObservingRotation(); |
100 Shell::Get()->RemoveShellObserver(this); | 111 Shell::Get()->RemoveShellObserver(this); |
101 } | 112 } |
102 | 113 |
103 void RotationLockDefaultView::Update() { | 114 void RotationLockDefaultView::Update() { |
104 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 115 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
105 icon_->SetImage(gfx::CreateVectorIcon(IsUserRotationLocked() | 116 base::string16 label; |
106 ? kSystemMenuRotationLockLockedIcon | 117 if (IsUserRotationLocked()) { |
107 : kSystemMenuRotationLockAutoIcon, | 118 icon_->SetImage(gfx::CreateVectorIcon( |
108 kMenuIconSize, style.GetIconColor())); | 119 IsCurrentRotationPortrait() ? kSystemMenuRotationLockPortraitIcon |
109 | 120 : kSystemMenuRotationLockLandscapeIcon, |
110 base::string16 label = l10n_util::GetStringUTF16( | 121 kMenuIconSize, style.GetIconColor())); |
111 IsUserRotationLocked() ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED | 122 label = l10n_util::GetStringUTF16( |
112 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); | 123 IsCurrentRotationPortrait() |
| 124 ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_PORTRAIT |
| 125 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LANDSCAPE); |
| 126 } else { |
| 127 icon_->SetImage(gfx::CreateVectorIcon(kSystemMenuRotationLockAutoIcon, |
| 128 kMenuIconSize, style.GetIconColor())); |
| 129 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); |
| 130 } |
113 label_->SetText(label); | 131 label_->SetText(label); |
114 style.SetupLabel(label_); | 132 style.SetupLabel(label_); |
115 | 133 |
116 Layout(); | 134 Layout(); |
117 SchedulePaint(); | 135 SchedulePaint(); |
118 } | 136 } |
119 | 137 |
120 void RotationLockDefaultView::StopObservingRotation() { | 138 void RotationLockDefaultView::StopObservingRotation() { |
121 ScreenOrientationController* controller = | 139 ScreenOrientationController* controller = |
122 Shell::Get()->screen_orientation_controller(); | 140 Shell::Get()->screen_orientation_controller(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 kSystemTrayRotationLockLockedIcon, | 175 kSystemTrayRotationLockLockedIcon, |
158 UMA_ROTATION_LOCK) { | 176 UMA_ROTATION_LOCK) { |
159 Shell::Get()->AddShellObserver(this); | 177 Shell::Get()->AddShellObserver(this); |
160 } | 178 } |
161 | 179 |
162 TrayRotationLock::~TrayRotationLock() { | 180 TrayRotationLock::~TrayRotationLock() { |
163 Shell::Get()->RemoveShellObserver(this); | 181 Shell::Get()->RemoveShellObserver(this); |
164 } | 182 } |
165 | 183 |
166 void TrayRotationLock::OnUserRotationLockChanged() { | 184 void TrayRotationLock::OnUserRotationLockChanged() { |
167 tray_view()->SetVisible(ShouldBeVisible()); | 185 UpdateTrayImage(); |
168 } | 186 } |
169 | 187 |
170 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { | 188 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { |
171 if (OnPrimaryDisplay()) | 189 if (OnPrimaryDisplay()) |
172 return new tray::RotationLockDefaultView(this); | 190 return new tray::RotationLockDefaultView(this); |
173 return nullptr; | 191 return nullptr; |
174 } | 192 } |
175 | 193 |
176 void TrayRotationLock::OnMaximizeModeStarted() { | 194 void TrayRotationLock::OnMaximizeModeStarted() { |
177 tray_view()->SetVisible(IsUserRotationLocked()); | 195 tray_view()->SetVisible(ShouldBeVisible()); |
| 196 UpdateTrayImage(); |
178 Shell::Get()->screen_orientation_controller()->AddObserver(this); | 197 Shell::Get()->screen_orientation_controller()->AddObserver(this); |
179 } | 198 } |
180 | 199 |
181 void TrayRotationLock::OnMaximizeModeEnded() { | 200 void TrayRotationLock::OnMaximizeModeEnded() { |
182 tray_view()->SetVisible(false); | 201 tray_view()->SetVisible(false); |
183 StopObservingRotation(); | 202 StopObservingRotation(); |
184 } | 203 } |
185 | 204 |
186 void TrayRotationLock::DestroyTrayView() { | 205 void TrayRotationLock::DestroyTrayView() { |
187 StopObservingRotation(); | 206 StopObservingRotation(); |
188 Shell::Get()->RemoveShellObserver(this); | 207 Shell::Get()->RemoveShellObserver(this); |
189 TrayImageItem::DestroyTrayView(); | 208 TrayImageItem::DestroyTrayView(); |
190 } | 209 } |
191 | 210 |
192 bool TrayRotationLock::GetInitialVisibility() { | 211 bool TrayRotationLock::GetInitialVisibility() { |
193 return ShouldBeVisible(); | 212 return ShouldBeVisible(); |
194 } | 213 } |
195 | 214 |
| 215 void TrayRotationLock::UpdateTrayImage() { |
| 216 TrayImageItem::SetImageIcon(IsUserRotationLocked() |
| 217 ? kSystemTrayRotationLockLockedIcon |
| 218 : kSystemTrayRotationLockAutoIcon); |
| 219 } |
| 220 |
196 bool TrayRotationLock::ShouldBeVisible() { | 221 bool TrayRotationLock::ShouldBeVisible() { |
197 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && | 222 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled(); |
198 IsUserRotationLocked(); | |
199 } | 223 } |
200 | 224 |
201 bool TrayRotationLock::OnPrimaryDisplay() const { | 225 bool TrayRotationLock::OnPrimaryDisplay() const { |
202 gfx::NativeView native_window = system_tray()->GetWidget()->GetNativeWindow(); | 226 gfx::NativeView native_window = system_tray()->GetWidget()->GetNativeWindow(); |
203 display::Display parent_display = | 227 display::Display parent_display = |
204 display::Screen::GetScreen()->GetDisplayNearestWindow(native_window); | 228 display::Screen::GetScreen()->GetDisplayNearestWindow(native_window); |
205 return parent_display.IsInternal(); | 229 return parent_display.IsInternal(); |
206 } | 230 } |
207 | 231 |
208 void TrayRotationLock::StopObservingRotation() { | 232 void TrayRotationLock::StopObservingRotation() { |
209 ScreenOrientationController* controller = | 233 ScreenOrientationController* controller = |
210 Shell::Get()->screen_orientation_controller(); | 234 Shell::Get()->screen_orientation_controller(); |
211 if (controller) | 235 if (controller) |
212 controller->RemoveObserver(this); | 236 controller->RemoveObserver(this); |
213 } | 237 } |
214 | 238 |
215 } // namespace ash | 239 } // namespace ash |
OLD | NEW |