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/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 Loading... |
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 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 144 LeaveMaximizeMode(); |
145 event_blocker_.reset(); | |
146 } else if (!maximize_mode_engaged && | 145 } else if (!maximize_mode_engaged && |
147 angle > kEnterMaximizeModeAngle) { | 146 angle > kEnterMaximizeModeAngle) { |
148 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 147 EnterMaximizeMode(); |
149 event_blocker_.reset(new MaximizeModeEventBlocker); | |
150 } | 148 } |
151 } | 149 } |
152 | 150 |
153 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 151 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
154 bool maximize_mode_engaged = | 152 bool maximize_mode_engaged = |
155 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 153 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
156 | 154 |
| 155 if (!maximize_mode_engaged || rotation_locked_) |
| 156 return; |
| 157 |
157 DisplayManager* display_manager = | 158 DisplayManager* display_manager = |
158 Shell::GetInstance()->display_manager(); | 159 Shell::GetInstance()->display_manager(); |
159 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 160 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
160 gfx::Display::InternalDisplayId()).rotation(); | 161 gfx::Display::InternalDisplayId()).rotation(); |
161 | 162 |
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 | 163 // After determining maximize mode state, determine if the screen should |
183 // be rotated. | 164 // be rotated. |
184 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); | 165 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
185 float lid_flattened_length = lid_flattened.Length(); | 166 float lid_flattened_length = lid_flattened.Length(); |
186 // When the lid is close to being flat, don't change rotation as it is too | 167 // When the lid is close to being flat, don't change rotation as it is too |
187 // sensitive to slight movements. | 168 // sensitive to slight movements. |
188 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | 169 if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
189 return; | 170 return; |
190 | 171 |
191 // The reference vector is the angle of gravity when the device is rotated | 172 // 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 Loading... |
226 | 207 |
227 // When exiting maximize mode return rotation to 0. When entering, rotate to | 208 // When exiting maximize mode return rotation to 0. When entering, rotate to |
228 // match screen orientation. | 209 // match screen orientation. |
229 if (new_rotation == gfx::Display::ROTATE_0 || | 210 if (new_rotation == gfx::Display::ROTATE_0 || |
230 maximize_mode_engaged) { | 211 maximize_mode_engaged) { |
231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 212 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
232 new_rotation); | 213 new_rotation); |
233 } | 214 } |
234 } | 215 } |
235 | 216 |
| 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 |
236 } // namespace ash | 242 } // namespace ash |
OLD | NEW |