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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 289583002: Lock rotation when screen is manually rotated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Define sources for rotation Created 6 years, 7 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/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"
11 #include "ash/display/display_manager.h" 11 #include "ash/display/display_manager.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "ui/base/accelerators/accelerator.h" 15 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/display/types/display_constants.h"
16 #include "ui/events/event.h" 17 #include "ui/events/event.h"
17 #include "ui/events/event_handler.h" 18 #include "ui/events/event_handler.h"
18 #include "ui/events/keycodes/keyboard_codes.h" 19 #include "ui/events/keycodes/keyboard_codes.h"
19 #include "ui/gfx/vector3d_f.h" 20 #include "ui/gfx/vector3d_f.h"
20 21
21 namespace ash { 22 namespace ash {
22 23
23 namespace { 24 namespace {
24 25
25 // The hinge angle at which to enter maximize mode. 26 // The hinge angle at which to enter maximize mode.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, 197 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened,
197 lid_flattened, hinge_vector); 198 lid_flattened, hinge_vector);
198 199
199 // Toggle maximize mode on or off when corresponding thresholds are passed. 200 // Toggle maximize mode on or off when corresponding thresholds are passed.
200 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager 201 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager
201 // such that observations of state changes occur after the change and shell 202 // such that observations of state changes occur after the change and shell
202 // has fewer states to track. 203 // has fewer states to track.
203 if (maximize_mode_engaged && 204 if (maximize_mode_engaged &&
204 angle > kFullyOpenAngleErrorTolerance && 205 angle > kFullyOpenAngleErrorTolerance &&
205 angle < kExitMaximizeModeAngle) { 206 angle < kExitMaximizeModeAngle) {
206 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); 207 LeaveMaximizeMode();
207 event_blocker_.reset();
208 event_handler_.reset();
209 } else if (!maximize_mode_engaged && 208 } else if (!maximize_mode_engaged &&
210 angle > kEnterMaximizeModeAngle) { 209 angle > kEnterMaximizeModeAngle) {
211 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); 210 EnterMaximizeMode();
212 event_blocker_.reset(new MaximizeModeEventBlocker);
213 #if defined(OS_CHROMEOS)
214 event_handler_.reset(new ScreenshotActionHandler);
215 #endif
216 } 211 }
217 } 212 }
218 213
219 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { 214 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
220 bool maximize_mode_engaged = 215 bool maximize_mode_engaged =
221 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 216 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
222 217
218 if (!maximize_mode_engaged || rotation_locked_)
219 return;
220
223 DisplayManager* display_manager = 221 DisplayManager* display_manager =
224 Shell::GetInstance()->display_manager(); 222 Shell::GetInstance()->display_manager();
225 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( 223 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
226 gfx::Display::InternalDisplayId()).rotation(); 224 gfx::Display::InternalDisplayId()).rotation();
227 225
228 // If maximize mode is not engaged, ensure the screen is not rotated and
229 // do not rotate to match the current device orientation.
230 if (!maximize_mode_engaged) {
231 if (current_rotation != gfx::Display::ROTATE_0) {
232 // TODO(flackr): Currently this will prevent setting a manual rotation on
233 // the screen of a device with an accelerometer, this should only set it
234 // back to ROTATE_0 if it was last set by the accelerometer.
235 // Also, SetDisplayRotation will save the setting to the local store,
236 // this should be stored in a way that we can distinguish what the
237 // rotation was set by.
238 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
239 gfx::Display::ROTATE_0);
240 }
241 rotation_locked_ = false;
242 return;
243 }
244
245 if (rotation_locked_)
246 return;
247
248 // After determining maximize mode state, determine if the screen should 226 // After determining maximize mode state, determine if the screen should
249 // be rotated. 227 // be rotated.
250 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); 228 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f);
251 float lid_flattened_length = lid_flattened.Length(); 229 float lid_flattened_length = lid_flattened.Length();
252 // When the lid is close to being flat, don't change rotation as it is too 230 // When the lid is close to being flat, don't change rotation as it is too
253 // sensitive to slight movements. 231 // sensitive to slight movements.
254 if (lid_flattened_length < kMinimumAccelerationScreenRotation) 232 if (lid_flattened_length < kMinimumAccelerationScreenRotation)
255 return; 233 return;
256 234
257 // The reference vector is the angle of gravity when the device is rotated 235 // The reference vector is the angle of gravity when the device is rotated
(...skipping 30 matching lines...) Expand all
288 else if (angle < 180.0f) 266 else if (angle < 180.0f)
289 new_rotation = gfx::Display::ROTATE_270; 267 new_rotation = gfx::Display::ROTATE_270;
290 else if (angle < 270.0f) 268 else if (angle < 270.0f)
291 new_rotation = gfx::Display::ROTATE_180; 269 new_rotation = gfx::Display::ROTATE_180;
292 270
293 // When exiting maximize mode return rotation to 0. When entering, rotate to 271 // When exiting maximize mode return rotation to 0. When entering, rotate to
294 // match screen orientation. 272 // match screen orientation.
295 if (new_rotation == gfx::Display::ROTATE_0 || 273 if (new_rotation == gfx::Display::ROTATE_0 ||
296 maximize_mode_engaged) { 274 maximize_mode_engaged) {
297 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 275 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
298 new_rotation); 276 new_rotation,
277 ui::ACCELEROMETER);
299 } 278 }
300 } 279 }
301 280
281 void MaximizeModeController::EnterMaximizeMode() {
282 // TODO(jonross): Listen for display configuration changes. If the user
283 // causes a rotation change a rotation lock should be applied.
284 // https://crbug.com/369505
285 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
286 gfx::Display::Rotation current_rotation = display_manager->
287 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
288 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0;
flackr 2014/05/16 16:00:22 What do you think of not locking on non-zero rotat
jonross 2014/05/16 17:25:28 Considering that the user is enacting a state chan
289 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
290 event_blocker_.reset(new MaximizeModeEventBlocker);
291 #if defined(OS_CHROMEOS)
292 event_handler_.reset(new ScreenshotActionHandler);
293 #endif
294 }
295
296 void MaximizeModeController::LeaveMaximizeMode() {
297 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
298 DisplayInfo info = display_manager->
299 GetDisplayInfo(gfx::Display::InternalDisplayId());
300 gfx::Display::Rotation user_rotation = info.GetRotation(ui::USER);
301 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
302 user_rotation,
303 ui::USER);
304 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
305 event_blocker_.reset();
306 event_handler_.reset();
307 }
308
302 } // namespace ash 309 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698