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

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

Issue 261163004: Lock Rotation when screen is manually rotated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/accelerometer/accelerometer_controller.h" 7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" 10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 // Compute the angle between the base and the lid. 133 // Compute the angle between the base and the lid.
134 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, 134 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened,
135 lid_flattened, hinge_vector); 135 lid_flattened, hinge_vector);
136 136
137 // Toggle maximize mode on or off when corresponding thresholds are passed. 137 // Toggle maximize mode on or off when corresponding thresholds are passed.
138 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager 138 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager
139 // such that observations of state changes occur after the change and shell 139 // such that observations of state changes occur after the change and shell
140 // has fewer states to track. 140 // has fewer states to track.
141 DisplayManager* display_manager =
142 Shell::GetInstance()->display_manager();
143 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
144 gfx::Display::InternalDisplayId()).rotation();
145
141 if (maximize_mode_engaged && 146 if (maximize_mode_engaged &&
142 angle > kFullyOpenAngleErrorTolerance && 147 angle > kFullyOpenAngleErrorTolerance &&
143 angle < kExitMaximizeModeAngle) { 148 angle < kExitMaximizeModeAngle) {
149 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) {
150 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
151 gfx::Display::ROTATE_0);
152 }
144 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); 153 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
145 event_blocker_.reset(); 154 event_blocker_.reset();
oshima 2014/05/06 16:04:10 Would you mind defining MaximizeModeController::En
jonross 2014/05/06 21:49:00 I don't know if we want to do this. By having the
146 } else if (!maximize_mode_engaged && 155 } else if (!maximize_mode_engaged &&
147 angle > kEnterMaximizeModeAngle) { 156 angle > kEnterMaximizeModeAngle) {
157 // TODO(jonross): Create a property on the display to track user rotations.
158 // We should lock based on this property. Furthermore we should apply the
159 // lock if the user changes the display settings while we are in maximize
160 // mode. https://code.google.com/p/chromium/issues/detail?id=370443
flackr 2014/05/06 15:47:25 nit: just use http://crbug.com/370443
jonross 2014/05/06 21:49:00 Done.
161 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0;
148 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); 162 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
149 event_blocker_.reset(new MaximizeModeEventBlocker); 163 event_blocker_.reset(new MaximizeModeEventBlocker);
150 } 164 }
151 } 165 }
152 166
153 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { 167 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
154 bool maximize_mode_engaged = 168 bool maximize_mode_engaged =
155 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 169 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
156 170
171 if (!maximize_mode_engaged || rotation_locked_)
172 return;
173
157 DisplayManager* display_manager = 174 DisplayManager* display_manager =
158 Shell::GetInstance()->display_manager(); 175 Shell::GetInstance()->display_manager();
159 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( 176 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
160 gfx::Display::InternalDisplayId()).rotation(); 177 gfx::Display::InternalDisplayId()).rotation();
161 178
162 // If maximize mode is not engaged, ensure the screen is not rotated and
163 // do not rotate to match the current device orientation.
164 if (!maximize_mode_engaged) {
165 if (current_rotation != gfx::Display::ROTATE_0) {
166 // TODO(flackr): Currently this will prevent setting a manual rotation on
167 // the screen of a device with an accelerometer, this should only set it
168 // back to ROTATE_0 if it was last set by the accelerometer.
169 // Also, SetDisplayRotation will save the setting to the local store,
170 // this should be stored in a way that we can distinguish what the
171 // rotation was set by.
172 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
173 gfx::Display::ROTATE_0);
174 }
175 rotation_locked_ = false;
176 return;
177 }
178
179 if (rotation_locked_)
180 return;
181
182 // After determining maximize mode state, determine if the screen should 179 // After determining maximize mode state, determine if the screen should
183 // be rotated. 180 // be rotated.
184 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); 181 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f);
185 float lid_flattened_length = lid_flattened.Length(); 182 float lid_flattened_length = lid_flattened.Length();
186 // When the lid is close to being flat, don't change rotation as it is too 183 // When the lid is close to being flat, don't change rotation as it is too
187 // sensitive to slight movements. 184 // sensitive to slight movements.
188 if (lid_flattened_length < kMinimumAccelerationScreenRotation) 185 if (lid_flattened_length < kMinimumAccelerationScreenRotation)
189 return; 186 return;
190 187
191 // The reference vector is the angle of gravity when the device is rotated 188 // The reference vector is the angle of gravity when the device is rotated
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // When exiting maximize mode return rotation to 0. When entering, rotate to 224 // When exiting maximize mode return rotation to 0. When entering, rotate to
228 // match screen orientation. 225 // match screen orientation.
229 if (new_rotation == gfx::Display::ROTATE_0 || 226 if (new_rotation == gfx::Display::ROTATE_0 ||
230 maximize_mode_engaged) { 227 maximize_mode_engaged) {
231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 228 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
232 new_rotation); 229 new_rotation);
233 } 230 }
234 } 231 }
235 232
236 } // namespace ash 233 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698