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

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 }
153 rotation_locked_ = false;
flackr 2014/05/05 20:53:56 What if we don't reset the rotation lock on exitin
jonross 2014/05/06 15:07:54 Done.
144 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); 154 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
145 event_blocker_.reset(); 155 event_blocker_.reset();
146 } else if (!maximize_mode_engaged && 156 } else if (!maximize_mode_engaged &&
147 angle > kEnterMaximizeModeAngle) { 157 angle > kEnterMaximizeModeAngle) {
158 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0;
flackr 2014/05/05 20:53:56 This seems like a good heuristic for manual extern
jonross 2014/05/06 15:07:54 Filed: https://code.google.com/p/chromium/issues/d
148 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); 159 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
149 event_blocker_.reset(new MaximizeModeEventBlocker); 160 event_blocker_.reset(new MaximizeModeEventBlocker);
150 } 161 }
151 } 162 }
152 163
153 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { 164 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) {
154 bool maximize_mode_engaged = 165 bool maximize_mode_engaged =
155 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); 166 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
156 167
168 if (!maximize_mode_engaged || rotation_locked_)
169 return;
170
157 DisplayManager* display_manager = 171 DisplayManager* display_manager =
158 Shell::GetInstance()->display_manager(); 172 Shell::GetInstance()->display_manager();
159 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( 173 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo(
160 gfx::Display::InternalDisplayId()).rotation(); 174 gfx::Display::InternalDisplayId()).rotation();
161 175
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 176 // After determining maximize mode state, determine if the screen should
183 // be rotated. 177 // be rotated.
184 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); 178 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f);
185 float lid_flattened_length = lid_flattened.Length(); 179 float lid_flattened_length = lid_flattened.Length();
186 // When the lid is close to being flat, don't change rotation as it is too 180 // When the lid is close to being flat, don't change rotation as it is too
187 // sensitive to slight movements. 181 // sensitive to slight movements.
188 if (lid_flattened_length < kMinimumAccelerationScreenRotation) 182 if (lid_flattened_length < kMinimumAccelerationScreenRotation)
189 return; 183 return;
190 184
191 // The reference vector is the angle of gravity when the device is rotated 185 // 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 221 // When exiting maximize mode return rotation to 0. When entering, rotate to
228 // match screen orientation. 222 // match screen orientation.
229 if (new_rotation == gfx::Display::ROTATE_0 || 223 if (new_rotation == gfx::Display::ROTATE_0 ||
230 maximize_mode_engaged) { 224 maximize_mode_engaged) {
231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 225 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
232 new_rotation); 226 new_rotation);
233 } 227 }
234 } 228 }
235 229
236 } // namespace ash 230 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698