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/shell_port.h" |
11 #include "ash/strings/grit/ash_strings.h" | 11 #include "ash/strings/grit/ash_strings.h" |
12 #include "ash/system/tray/actionable_view.h" | 12 #include "ash/system/tray/actionable_view.h" |
13 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
15 #include "ash/system/tray/tray_popup_item_style.h" | 15 #include "ash/system/tray/tray_popup_item_style.h" |
16 #include "ash/system/tray/tray_popup_utils.h" | 16 #include "ash/system/tray/tray_popup_utils.h" |
17 #include "ash/system/tray/tri_view.h" | 17 #include "ash/system/tray/tri_view.h" |
18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 18 #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
19 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
22 #include "ui/display/manager/managed_display_info.h" | 22 #include "ui/display/manager/managed_display_info.h" |
23 #include "ui/gfx/paint_vector_icon.h" | 23 #include "ui/gfx/paint_vector_icon.h" |
24 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
25 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
26 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
27 | 27 |
28 namespace ash { | 28 namespace ash { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 bool IsMaximizeModeWindowManagerEnabled() { | 32 bool IsTabletModeWindowManagerEnabled() { |
33 return Shell::Get() | 33 return Shell::Get() |
34 ->maximize_mode_controller() | 34 ->tablet_mode_controller() |
35 ->IsMaximizeModeWindowManagerEnabled(); | 35 ->IsTabletModeWindowManagerEnabled(); |
36 } | 36 } |
37 | 37 |
38 bool IsUserRotationLocked() { | 38 bool IsUserRotationLocked() { |
39 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); | 39 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); |
40 } | 40 } |
41 | 41 |
42 bool IsCurrentRotationPortrait() { | 42 bool IsCurrentRotationPortrait() { |
43 display::Display::Rotation current_rotation = | 43 display::Display::Rotation current_rotation = |
44 ShellPort::Get() | 44 ShellPort::Get() |
45 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 45 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
(...skipping 18 matching lines...) Expand all Loading... |
64 void Update(); | 64 void Update(); |
65 | 65 |
66 // Stop observing rotation lock status. | 66 // Stop observing rotation lock status. |
67 void StopObservingRotation(); | 67 void StopObservingRotation(); |
68 | 68 |
69 // ActionableView: | 69 // ActionableView: |
70 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 70 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
71 bool PerformAction(const ui::Event& event) override; | 71 bool PerformAction(const ui::Event& event) override; |
72 | 72 |
73 // ShellObserver: | 73 // ShellObserver: |
74 void OnMaximizeModeStarted() override; | 74 void OnTabletModeStarted() override; |
75 void OnMaximizeModeEnded() override; | 75 void OnTabletModeEnded() override; |
76 | 76 |
77 // ScreenOrientationController::Obsever: | 77 // ScreenOrientationController::Obsever: |
78 void OnUserRotationLockChanged() override; | 78 void OnUserRotationLockChanged() override; |
79 | 79 |
80 views::ImageView* icon_; | 80 views::ImageView* icon_; |
81 views::Label* label_; | 81 views::Label* label_; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); | 83 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); |
84 }; | 84 }; |
85 | 85 |
86 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) | 86 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) |
87 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), | 87 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), |
88 icon_(TrayPopupUtils::CreateMainImageView()), | 88 icon_(TrayPopupUtils::CreateMainImageView()), |
89 label_(TrayPopupUtils::CreateDefaultLabel()) { | 89 label_(TrayPopupUtils::CreateDefaultLabel()) { |
90 SetLayoutManager(new views::FillLayout); | 90 SetLayoutManager(new views::FillLayout); |
91 | 91 |
92 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 92 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
93 AddChildView(tri_view); | 93 AddChildView(tri_view); |
94 | 94 |
95 tri_view->AddView(TriView::Container::START, icon_); | 95 tri_view->AddView(TriView::Container::START, icon_); |
96 tri_view->AddView(TriView::Container::CENTER, label_); | 96 tri_view->AddView(TriView::Container::CENTER, label_); |
97 tri_view->SetContainerVisible(TriView::Container::END, false); | 97 tri_view->SetContainerVisible(TriView::Container::END, false); |
98 | 98 |
99 Update(); | 99 Update(); |
100 | 100 |
101 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 101 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
102 | 102 |
103 SetVisible(IsMaximizeModeWindowManagerEnabled()); | 103 SetVisible(IsTabletModeWindowManagerEnabled()); |
104 Shell::Get()->AddShellObserver(this); | 104 Shell::Get()->AddShellObserver(this); |
105 if (IsMaximizeModeWindowManagerEnabled()) | 105 if (IsTabletModeWindowManagerEnabled()) |
106 Shell::Get()->screen_orientation_controller()->AddObserver(this); | 106 Shell::Get()->screen_orientation_controller()->AddObserver(this); |
107 } | 107 } |
108 | 108 |
109 RotationLockDefaultView::~RotationLockDefaultView() { | 109 RotationLockDefaultView::~RotationLockDefaultView() { |
110 StopObservingRotation(); | 110 StopObservingRotation(); |
111 Shell::Get()->RemoveShellObserver(this); | 111 Shell::Get()->RemoveShellObserver(this); |
112 } | 112 } |
113 | 113 |
114 void RotationLockDefaultView::Update() { | 114 void RotationLockDefaultView::Update() { |
115 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 115 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
(...skipping 30 matching lines...) Expand all Loading... |
146 ActionableView::GetAccessibleNodeData(node_data); | 146 ActionableView::GetAccessibleNodeData(node_data); |
147 if (!label_->text().empty()) | 147 if (!label_->text().empty()) |
148 node_data->SetName(label_->text()); | 148 node_data->SetName(label_->text()); |
149 } | 149 } |
150 | 150 |
151 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { | 151 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { |
152 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); | 152 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
153 return true; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 void RotationLockDefaultView::OnMaximizeModeStarted() { | 156 void RotationLockDefaultView::OnTabletModeStarted() { |
157 Update(); | 157 Update(); |
158 SetVisible(true); | 158 SetVisible(true); |
159 Shell::Get()->screen_orientation_controller()->AddObserver(this); | 159 Shell::Get()->screen_orientation_controller()->AddObserver(this); |
160 } | 160 } |
161 | 161 |
162 void RotationLockDefaultView::OnMaximizeModeEnded() { | 162 void RotationLockDefaultView::OnTabletModeEnded() { |
163 SetVisible(false); | 163 SetVisible(false); |
164 StopObservingRotation(); | 164 StopObservingRotation(); |
165 } | 165 } |
166 | 166 |
167 void RotationLockDefaultView::OnUserRotationLockChanged() { | 167 void RotationLockDefaultView::OnUserRotationLockChanged() { |
168 Update(); | 168 Update(); |
169 } | 169 } |
170 | 170 |
171 } // namespace tray | 171 } // namespace tray |
172 | 172 |
(...skipping 11 matching lines...) Expand all Loading... |
184 void TrayRotationLock::OnUserRotationLockChanged() { | 184 void TrayRotationLock::OnUserRotationLockChanged() { |
185 UpdateTrayImage(); | 185 UpdateTrayImage(); |
186 } | 186 } |
187 | 187 |
188 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { | 188 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { |
189 if (OnPrimaryDisplay()) | 189 if (OnPrimaryDisplay()) |
190 return new tray::RotationLockDefaultView(this); | 190 return new tray::RotationLockDefaultView(this); |
191 return nullptr; | 191 return nullptr; |
192 } | 192 } |
193 | 193 |
194 void TrayRotationLock::OnMaximizeModeStarted() { | 194 void TrayRotationLock::OnTabletModeStarted() { |
195 tray_view()->SetVisible(ShouldBeVisible()); | 195 tray_view()->SetVisible(ShouldBeVisible()); |
196 UpdateTrayImage(); | 196 UpdateTrayImage(); |
197 Shell::Get()->screen_orientation_controller()->AddObserver(this); | 197 Shell::Get()->screen_orientation_controller()->AddObserver(this); |
198 } | 198 } |
199 | 199 |
200 void TrayRotationLock::OnMaximizeModeEnded() { | 200 void TrayRotationLock::OnTabletModeEnded() { |
201 tray_view()->SetVisible(false); | 201 tray_view()->SetVisible(false); |
202 StopObservingRotation(); | 202 StopObservingRotation(); |
203 } | 203 } |
204 | 204 |
205 void TrayRotationLock::DestroyTrayView() { | 205 void TrayRotationLock::DestroyTrayView() { |
206 StopObservingRotation(); | 206 StopObservingRotation(); |
207 Shell::Get()->RemoveShellObserver(this); | 207 Shell::Get()->RemoveShellObserver(this); |
208 TrayImageItem::DestroyTrayView(); | 208 TrayImageItem::DestroyTrayView(); |
209 } | 209 } |
210 | 210 |
211 bool TrayRotationLock::GetInitialVisibility() { | 211 bool TrayRotationLock::GetInitialVisibility() { |
212 return ShouldBeVisible(); | 212 return ShouldBeVisible(); |
213 } | 213 } |
214 | 214 |
215 void TrayRotationLock::UpdateTrayImage() { | 215 void TrayRotationLock::UpdateTrayImage() { |
216 TrayImageItem::SetImageIcon(IsUserRotationLocked() | 216 TrayImageItem::SetImageIcon(IsUserRotationLocked() |
217 ? kSystemTrayRotationLockLockedIcon | 217 ? kSystemTrayRotationLockLockedIcon |
218 : kSystemTrayRotationLockAutoIcon); | 218 : kSystemTrayRotationLockAutoIcon); |
219 } | 219 } |
220 | 220 |
221 bool TrayRotationLock::ShouldBeVisible() { | 221 bool TrayRotationLock::ShouldBeVisible() { |
222 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled(); | 222 return OnPrimaryDisplay() && IsTabletModeWindowManagerEnabled(); |
223 } | 223 } |
224 | 224 |
225 bool TrayRotationLock::OnPrimaryDisplay() const { | 225 bool TrayRotationLock::OnPrimaryDisplay() const { |
226 gfx::NativeView native_window = system_tray()->GetWidget()->GetNativeWindow(); | 226 gfx::NativeView native_window = system_tray()->GetWidget()->GetNativeWindow(); |
227 display::Display parent_display = | 227 display::Display parent_display = |
228 display::Screen::GetScreen()->GetDisplayNearestWindow(native_window); | 228 display::Screen::GetScreen()->GetDisplayNearestWindow(native_window); |
229 return parent_display.IsInternal(); | 229 return parent_display.IsInternal(); |
230 } | 230 } |
231 | 231 |
232 void TrayRotationLock::StopObservingRotation() { | 232 void TrayRotationLock::StopObservingRotation() { |
233 ScreenOrientationController* controller = | 233 ScreenOrientationController* controller = |
234 Shell::Get()->screen_orientation_controller(); | 234 Shell::Get()->screen_orientation_controller(); |
235 if (controller) | 235 if (controller) |
236 controller->RemoveObserver(this); | 236 controller->RemoveObserver(this); |
237 } | 237 } |
238 | 238 |
239 } // namespace ash | 239 } // namespace ash |
OLD | NEW |