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/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 have_seen_accelerometer_data_(false), | 138 have_seen_accelerometer_data_(false), |
139 in_set_screen_rotation_(false), | 139 in_set_screen_rotation_(false), |
140 user_rotation_(gfx::Display::ROTATE_0) { | 140 user_rotation_(gfx::Display::ROTATE_0) { |
141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
142 } | 142 } |
143 | 143 |
144 MaximizeModeController::~MaximizeModeController() { | 144 MaximizeModeController::~MaximizeModeController() { |
145 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 145 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
146 } | 146 } |
147 | 147 |
148 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { | |
149 if (rotation_locked_ == rotation_locked) | |
150 return; | |
151 rotation_locked_ = rotation_locked; | |
152 FOR_EACH_OBSERVER(Observer, observers_, | |
153 OnRotationLockChanged(rotation_locked_)); | |
154 } | |
155 | |
156 void MaximizeModeController::AddObserver(Observer* observer) { | |
157 observers_.AddObserver(observer); | |
158 } | |
159 | |
160 void MaximizeModeController::RemoveObserver(Observer* observer) { | |
161 observers_.RemoveObserver(observer); | |
162 } | |
163 | |
148 bool MaximizeModeController::CanEnterMaximizeMode() { | 164 bool MaximizeModeController::CanEnterMaximizeMode() { |
149 // If we have ever seen accelerometer data, then HandleHingeRotation may | 165 // If we have ever seen accelerometer data, then HandleHingeRotation may |
150 // trigger maximize mode at some point in the future. | 166 // trigger maximize mode at some point in the future. |
151 // The --enable-touch-view-testing switch can also mean that we may enter | 167 // The --enable-touch-view-testing switch can also mean that we may enter |
152 // maximize mode. | 168 // maximize mode. |
153 return have_seen_accelerometer_data_ || | 169 return have_seen_accelerometer_data_ || |
154 CommandLine::ForCurrentProcess()->HasSwitch( | 170 CommandLine::ForCurrentProcess()->HasSwitch( |
155 switches::kAshEnableTouchViewTesting); | 171 switches::kAshEnableTouchViewTesting); |
156 } | 172 } |
157 | 173 |
(...skipping 12 matching lines...) Expand all Loading... | |
170 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 186 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
171 return; | 187 return; |
172 } | 188 } |
173 | 189 |
174 // Responding to the hinge rotation can change the maximize mode state which | 190 // Responding to the hinge rotation can change the maximize mode state which |
175 // affects screen rotation, so we handle hinge rotation first. | 191 // affects screen rotation, so we handle hinge rotation first. |
176 HandleHingeRotation(base, lid); | 192 HandleHingeRotation(base, lid); |
177 HandleScreenRotation(lid); | 193 HandleScreenRotation(lid); |
178 } | 194 } |
179 | 195 |
196 void MaximizeModeController::OnDisplayConfigurationChanged() { | |
197 if (rotation_locked_ || in_set_screen_rotation_) | |
flackr
2014/05/30 00:47:24
If rotation is locked you should still track updat
jonross
2014/05/30 14:52:44
Done.
flackr
2014/05/30 18:58:59
Not exactly, if the rotation changes to current_ro
flackr
2014/06/02 15:11:11
Not changed yet?
jonross
2014/06/02 18:01:12
Apparently this is listed in the Diff from Patch #
| |
198 return; | |
199 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
200 gfx::Display::Rotation user_rotation = display_manager-> | |
201 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
202 if (user_rotation != current_rotation_) { | |
203 // A user may change other display configuration settings. When the user | |
204 // does change the rotation setting, then lock rotation to prevent the | |
205 // accelerometer from erasing their change. | |
206 SetRotationLocked(true); | |
207 user_rotation_ = user_rotation; | |
208 } | |
209 } | |
210 | |
180 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 211 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
181 const gfx::Vector3dF& lid) { | 212 const gfx::Vector3dF& lid) { |
182 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 213 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
183 bool maximize_mode_engaged = | 214 bool maximize_mode_engaged = |
184 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 215 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
185 // Ignore the component of acceleration parallel to the hinge for the purposes | 216 // Ignore the component of acceleration parallel to the hinge for the purposes |
186 // of hinge angle calculation. | 217 // of hinge angle calculation. |
187 gfx::Vector3dF base_flattened(base); | 218 gfx::Vector3dF base_flattened(base); |
188 gfx::Vector3dF lid_flattened(lid); | 219 gfx::Vector3dF lid_flattened(lid); |
189 base_flattened.set_y(0.0f); | 220 base_flattened.set_y(0.0f); |
(...skipping 22 matching lines...) Expand all Loading... | |
212 } else if (!maximize_mode_engaged && | 243 } else if (!maximize_mode_engaged && |
213 angle > kEnterMaximizeModeAngle) { | 244 angle > kEnterMaximizeModeAngle) { |
214 EnterMaximizeMode(); | 245 EnterMaximizeMode(); |
215 } | 246 } |
216 } | 247 } |
217 | 248 |
218 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 249 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
219 bool maximize_mode_engaged = | 250 bool maximize_mode_engaged = |
220 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 251 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
221 | 252 |
253 // TODO(jonross): track the updated rotation angle even when locked. So that | |
254 // when rotation lock is removed the accelerometer rotation can be applied | |
255 // without waiting for the next update. | |
222 if (!maximize_mode_engaged || rotation_locked_) | 256 if (!maximize_mode_engaged || rotation_locked_) |
223 return; | 257 return; |
224 | 258 |
225 DisplayManager* display_manager = | 259 DisplayManager* display_manager = |
226 Shell::GetInstance()->display_manager(); | 260 Shell::GetInstance()->display_manager(); |
227 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 261 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
228 gfx::Display::InternalDisplayId()).rotation(); | 262 gfx::Display::InternalDisplayId()).rotation(); |
229 | 263 |
230 // After determining maximize mode state, determine if the screen should | 264 // After determining maximize mode state, determine if the screen should |
231 // be rotated. | 265 // be rotated. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 308 |
275 if (new_rotation != current_rotation) | 309 if (new_rotation != current_rotation) |
276 SetDisplayRotation(display_manager, new_rotation); | 310 SetDisplayRotation(display_manager, new_rotation); |
277 } | 311 } |
278 | 312 |
279 void MaximizeModeController::SetDisplayRotation( | 313 void MaximizeModeController::SetDisplayRotation( |
280 DisplayManager* display_manager, | 314 DisplayManager* display_manager, |
281 gfx::Display::Rotation rotation) { | 315 gfx::Display::Rotation rotation) { |
282 base::AutoReset<bool> auto_in_set_screen_rotation( | 316 base::AutoReset<bool> auto_in_set_screen_rotation( |
283 &in_set_screen_rotation_, true); | 317 &in_set_screen_rotation_, true); |
318 current_rotation_ = rotation; | |
284 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 319 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
285 rotation); | 320 rotation); |
286 } | 321 } |
287 | 322 |
288 void MaximizeModeController::EnterMaximizeMode() { | 323 void MaximizeModeController::EnterMaximizeMode() { |
289 // TODO(jonross): Listen for display configuration changes. If the user | |
290 // causes a rotation change a rotation lock should be applied. | |
291 // https://crbug.com/369505 | |
292 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 324 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
293 user_rotation_ = display_manager-> | 325 current_rotation_ = user_rotation_ = display_manager-> |
294 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 326 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
295 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 327 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
296 event_blocker_.reset(new MaximizeModeEventBlocker); | 328 event_blocker_.reset(new MaximizeModeEventBlocker); |
297 #if defined(OS_CHROMEOS) | 329 #if defined(OS_CHROMEOS) |
298 event_handler_.reset(new ScreenshotActionHandler); | 330 event_handler_.reset(new ScreenshotActionHandler); |
299 #endif | 331 #endif |
332 Shell::GetInstance()->display_controller()->AddObserver(this); | |
300 } | 333 } |
301 | 334 |
302 void MaximizeModeController::LeaveMaximizeMode() { | 335 void MaximizeModeController::LeaveMaximizeMode() { |
303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 336 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
304 DisplayInfo info = display_manager-> | 337 gfx::Display::Rotation current_rotation = display_manager-> |
305 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 338 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
306 gfx::Display::Rotation current_rotation = info.rotation(); | |
307 if (current_rotation != user_rotation_) | 339 if (current_rotation != user_rotation_) |
308 SetDisplayRotation(display_manager, user_rotation_); | 340 SetDisplayRotation(display_manager, user_rotation_); |
309 rotation_locked_ = false; | 341 rotation_locked_ = false; |
310 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 342 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
311 event_blocker_.reset(); | 343 event_blocker_.reset(); |
312 event_handler_.reset(); | 344 event_handler_.reset(); |
345 Shell::GetInstance()->display_controller()->RemoveObserver(this); | |
313 } | 346 } |
314 | 347 |
315 } // namespace ash | 348 } // namespace ash |
OLD | NEW |