Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: ash/system/chromeos/rotation/tray_rotation_lock.cc

Issue 2757493002: User orientation lock (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chromeos/rotation/tray_rotation_lock.h" 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h"
6 6
7 #include "ash/common/system/tray/actionable_view.h" 7 #include "ash/common/system/tray/actionable_view.h"
8 #include "ash/common/system/tray/system_tray.h" 8 #include "ash/common/system/tray/system_tray.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_popup_item_style.h" 10 #include "ash/common/system/tray/tray_popup_item_style.h"
(...skipping 16 matching lines...) Expand all
27 namespace ash { 27 namespace ash {
28 28
29 namespace { 29 namespace {
30 30
31 bool IsMaximizeModeWindowManagerEnabled() { 31 bool IsMaximizeModeWindowManagerEnabled() {
32 return WmShell::Get() 32 return WmShell::Get()
33 ->maximize_mode_controller() 33 ->maximize_mode_controller()
34 ->IsMaximizeModeWindowManagerEnabled(); 34 ->IsMaximizeModeWindowManagerEnabled();
35 } 35 }
36 36
37 bool IsRotationLocked() { 37 bool IsUserRotationLocked() {
38 return Shell::GetInstance() 38 return Shell::GetInstance()
39 ->screen_orientation_controller() 39 ->screen_orientation_controller()
40 ->rotation_locked(); 40 ->user_rotation_locked();
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 namespace tray { 45 namespace tray {
46 46
47 class RotationLockDefaultView : public ActionableView, 47 class RotationLockDefaultView : public ActionableView,
48 public ShellObserver, 48 public ShellObserver,
49 public ScreenOrientationController::Observer { 49 public ScreenOrientationController::Observer {
50 public: 50 public:
51 explicit RotationLockDefaultView(SystemTrayItem* owner); 51 explicit RotationLockDefaultView(SystemTrayItem* owner);
52 ~RotationLockDefaultView() override; 52 ~RotationLockDefaultView() override;
53 53
54 private: 54 private:
55 // Updates icon and label according to current rotation lock status. 55 // Updates icon and label according to current rotation lock status.
56 void Update(); 56 void Update();
57 57
58 // Stop observing rotation lock status. 58 // Stop observing rotation lock status.
59 void StopObservingRotation(); 59 void StopObservingRotation();
60 60
61 // ActionableView: 61 // ActionableView:
62 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 62 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
63 bool PerformAction(const ui::Event& event) override; 63 bool PerformAction(const ui::Event& event) override;
64 64
65 // ShellObserver: 65 // ShellObserver:
66 void OnMaximizeModeStarted() override; 66 void OnMaximizeModeStarted() override;
67 void OnMaximizeModeEnded() override; 67 void OnMaximizeModeEnded() override;
68 68
69 // ScreenOrientationController::Obsever: 69 // ScreenOrientationController::Obsever:
70 void OnRotationLockChanged(bool rotation_locked) override; 70 void OnUserRotationLockChanged() override;
71 71
72 views::ImageView* icon_; 72 views::ImageView* icon_;
73 views::Label* label_; 73 views::Label* label_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); 75 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView);
76 }; 76 };
77 77
78 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) 78 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner)
79 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), 79 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
80 icon_(TrayPopupUtils::CreateMainImageView()), 80 icon_(TrayPopupUtils::CreateMainImageView()),
(...skipping 15 matching lines...) Expand all
96 Shell::GetInstance()->AddShellObserver(this); 96 Shell::GetInstance()->AddShellObserver(this);
97 if (IsMaximizeModeWindowManagerEnabled()) 97 if (IsMaximizeModeWindowManagerEnabled())
98 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); 98 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this);
99 } 99 }
100 100
101 RotationLockDefaultView::~RotationLockDefaultView() { 101 RotationLockDefaultView::~RotationLockDefaultView() {
102 StopObservingRotation(); 102 StopObservingRotation();
103 Shell::GetInstance()->RemoveShellObserver(this); 103 Shell::GetInstance()->RemoveShellObserver(this);
104 } 104 }
105 105
106 void RotationLockDefaultView::Update() { 106 void RotationLockDefaultView::Update() {
jonross 2017/03/21 14:56:44 So this might become confusing for users. As an A
oshima 2017/03/21 15:10:57 Basically, we're making this consistent with Andro
jonross 2017/03/22 23:51:56 SGTM
107 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); 107 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
108 icon_->SetImage(gfx::CreateVectorIcon(IsRotationLocked() 108 icon_->SetImage(gfx::CreateVectorIcon(IsUserRotationLocked()
109 ? kSystemMenuRotationLockLockedIcon 109 ? kSystemMenuRotationLockLockedIcon
110 : kSystemMenuRotationLockAutoIcon, 110 : kSystemMenuRotationLockAutoIcon,
111 kMenuIconSize, style.GetIconColor())); 111 kMenuIconSize, style.GetIconColor()));
112 112
113 base::string16 label = l10n_util::GetStringUTF16( 113 base::string16 label = l10n_util::GetStringUTF16(
114 IsRotationLocked() ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED 114 IsUserRotationLocked() ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED
115 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); 115 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO);
116 label_->SetText(label); 116 label_->SetText(label);
117 style.SetupLabel(label_); 117 style.SetupLabel(label_);
118 118
119 Layout(); 119 Layout();
120 SchedulePaint(); 120 SchedulePaint();
121 } 121 }
122 122
123 void RotationLockDefaultView::StopObservingRotation() { 123 void RotationLockDefaultView::StopObservingRotation() {
124 ScreenOrientationController* controller = 124 ScreenOrientationController* controller =
125 Shell::GetInstance()->screen_orientation_controller(); 125 Shell::GetInstance()->screen_orientation_controller();
126 if (controller) 126 if (controller)
127 controller->RemoveObserver(this); 127 controller->RemoveObserver(this);
128 } 128 }
129 129
130 void RotationLockDefaultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 130 void RotationLockDefaultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
131 ActionableView::GetAccessibleNodeData(node_data); 131 ActionableView::GetAccessibleNodeData(node_data);
132 if (!label_->text().empty()) 132 if (!label_->text().empty())
133 node_data->SetName(label_->text()); 133 node_data->SetName(label_->text());
134 } 134 }
135 135
136 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { 136 bool RotationLockDefaultView::PerformAction(const ui::Event& event) {
137 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( 137 Shell::GetInstance()
138 !IsRotationLocked()); 138 ->screen_orientation_controller()
139 ->ToggleUserRotationLock();
139 return true; 140 return true;
140 } 141 }
141 142
142 void RotationLockDefaultView::OnMaximizeModeStarted() { 143 void RotationLockDefaultView::OnMaximizeModeStarted() {
143 Update(); 144 Update();
144 SetVisible(true); 145 SetVisible(true);
145 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); 146 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this);
146 } 147 }
147 148
148 void RotationLockDefaultView::OnMaximizeModeEnded() { 149 void RotationLockDefaultView::OnMaximizeModeEnded() {
149 SetVisible(false); 150 SetVisible(false);
150 StopObservingRotation(); 151 StopObservingRotation();
151 } 152 }
152 153
153 void RotationLockDefaultView::OnRotationLockChanged(bool rotation_locked) { 154 void RotationLockDefaultView::OnUserRotationLockChanged() {
154 Update(); 155 Update();
155 } 156 }
156 157
157 } // namespace tray 158 } // namespace tray
158 159
159 TrayRotationLock::TrayRotationLock(SystemTray* system_tray) 160 TrayRotationLock::TrayRotationLock(SystemTray* system_tray)
160 : TrayImageItem(system_tray, 161 : TrayImageItem(system_tray,
161 kSystemTrayRotationLockLockedIcon, 162 kSystemTrayRotationLockLockedIcon,
162 UMA_ROTATION_LOCK) { 163 UMA_ROTATION_LOCK) {
163 Shell::GetInstance()->AddShellObserver(this); 164 Shell::GetInstance()->AddShellObserver(this);
164 } 165 }
165 166
166 TrayRotationLock::~TrayRotationLock() { 167 TrayRotationLock::~TrayRotationLock() {
167 Shell::GetInstance()->RemoveShellObserver(this); 168 Shell::GetInstance()->RemoveShellObserver(this);
168 } 169 }
169 170
170 void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) { 171 void TrayRotationLock::OnUserRotationLockChanged() {
171 tray_view()->SetVisible(ShouldBeVisible()); 172 tray_view()->SetVisible(ShouldBeVisible());
172 } 173 }
173 174
174 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { 175 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) {
175 if (OnPrimaryDisplay()) 176 if (OnPrimaryDisplay())
176 return new tray::RotationLockDefaultView(this); 177 return new tray::RotationLockDefaultView(this);
177 return nullptr; 178 return nullptr;
178 } 179 }
179 180
180 void TrayRotationLock::OnMaximizeModeStarted() { 181 void TrayRotationLock::OnMaximizeModeStarted() {
181 tray_view()->SetVisible(IsRotationLocked()); 182 tray_view()->SetVisible(IsUserRotationLocked());
182 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); 183 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this);
183 } 184 }
184 185
185 void TrayRotationLock::OnMaximizeModeEnded() { 186 void TrayRotationLock::OnMaximizeModeEnded() {
186 tray_view()->SetVisible(false); 187 tray_view()->SetVisible(false);
187 StopObservingRotation(); 188 StopObservingRotation();
188 } 189 }
189 190
190 void TrayRotationLock::DestroyTrayView() { 191 void TrayRotationLock::DestroyTrayView() {
191 StopObservingRotation(); 192 StopObservingRotation();
192 Shell::GetInstance()->RemoveShellObserver(this); 193 Shell::GetInstance()->RemoveShellObserver(this);
193 TrayImageItem::DestroyTrayView(); 194 TrayImageItem::DestroyTrayView();
194 } 195 }
195 196
196 bool TrayRotationLock::GetInitialVisibility() { 197 bool TrayRotationLock::GetInitialVisibility() {
197 return ShouldBeVisible(); 198 return ShouldBeVisible();
198 } 199 }
199 200
200 bool TrayRotationLock::ShouldBeVisible() { 201 bool TrayRotationLock::ShouldBeVisible() {
201 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && 202 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() &&
202 IsRotationLocked(); 203 IsUserRotationLocked();
203 } 204 }
204 205
205 bool TrayRotationLock::OnPrimaryDisplay() const { 206 bool TrayRotationLock::OnPrimaryDisplay() const {
206 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView(); 207 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView();
207 display::Display parent_display = 208 display::Display parent_display =
208 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); 209 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view);
209 return parent_display.IsInternal(); 210 return parent_display.IsInternal();
210 } 211 }
211 212
212 void TrayRotationLock::StopObservingRotation() { 213 void TrayRotationLock::StopObservingRotation() {
213 ScreenOrientationController* controller = 214 ScreenOrientationController* controller =
214 Shell::GetInstance()->screen_orientation_controller(); 215 Shell::GetInstance()->screen_orientation_controller();
215 if (controller) 216 if (controller)
216 controller->RemoveObserver(this); 217 controller->RemoveObserver(this);
217 } 218 }
218 219
219 } // namespace ash 220 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698