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

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

Issue 271133002: Revert 268794 "Lock Rotation when screen is manually rotated" (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | Annotate | Revision Log
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (maximize_mode_engaged && 141 if (maximize_mode_engaged &&
142 angle > kFullyOpenAngleErrorTolerance && 142 angle > kFullyOpenAngleErrorTolerance &&
143 angle < kExitMaximizeModeAngle) { 143 angle < kExitMaximizeModeAngle) {
144 LeaveMaximizeMode(); 144 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
145 event_blocker_.reset();
145 } else if (!maximize_mode_engaged && 146 } else if (!maximize_mode_engaged &&
146 angle > kEnterMaximizeModeAngle) { 147 angle > kEnterMaximizeModeAngle) {
147 EnterMaximizeMode(); 148 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
149 event_blocker_.reset(new MaximizeModeEventBlocker);
148 } 150 }
149 } 151 }
150 152
151 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { 153 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
152 bool maximize_mode_engaged = 154 bool maximize_mode_engaged =
153 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 155 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
154 156
155 if (!maximize_mode_engaged || rotation_locked_)
156 return;
157
158 DisplayManager* display_manager = 157 DisplayManager* display_manager =
159 Shell::GetInstance()->display_manager(); 158 Shell::GetInstance()->display_manager();
160 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( 159 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
161 gfx::Display::InternalDisplayId()).rotation(); 160 gfx::Display::InternalDisplayId()).rotation();
162 161
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
163 // After determining maximize mode state, determine if the screen should 182 // After determining maximize mode state, determine if the screen should
164 // be rotated. 183 // be rotated.
165 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); 184 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f);
166 float lid_flattened_length = lid_flattened.Length(); 185 float lid_flattened_length = lid_flattened.Length();
167 // When the lid is close to being flat, don't change rotation as it is too 186 // When the lid is close to being flat, don't change rotation as it is too
168 // sensitive to slight movements. 187 // sensitive to slight movements.
169 if (lid_flattened_length < kMinimumAccelerationScreenRotation) 188 if (lid_flattened_length < kMinimumAccelerationScreenRotation)
170 return; 189 return;
171 190
172 // The reference vector is the angle of gravity when the device is rotated 191 // The reference vector is the angle of gravity when the device is rotated
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 226
208 // When exiting maximize mode return rotation to 0. When entering, rotate to 227 // When exiting maximize mode return rotation to 0. When entering, rotate to
209 // match screen orientation. 228 // match screen orientation.
210 if (new_rotation == gfx::Display::ROTATE_0 || 229 if (new_rotation == gfx::Display::ROTATE_0 ||
211 maximize_mode_engaged) { 230 maximize_mode_engaged) {
212 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
213 new_rotation); 232 new_rotation);
214 } 233 }
215 } 234 }
216 235
217 void MaximizeModeController::EnterMaximizeMode() {
218 // TODO(jonross): Create a property on the display to track user rotations.
219 // We should lock based on this property. Furthermore we should apply the
220 // lock if the user changes the display settings while we are in maximize
221 // mode. https://crbug.com/369505
222 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
223 gfx::Display::Rotation current_rotation = display_manager->
224 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
225 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0;
226 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
227 event_blocker_.reset(new MaximizeModeEventBlocker);
228 }
229
230 void MaximizeModeController::LeaveMaximizeMode() {
231 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
232 gfx::Display::Rotation current_rotation = display_manager->
233 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
234 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) {
235 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
236 gfx::Display::ROTATE_0);
237 }
238 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
239 event_blocker_.reset();
240 }
241
242 } // namespace ash 236 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698