Chromium Code Reviews| 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/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" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 have_seen_accelerometer_data_(false), | 138 have_seen_accelerometer_data_(false), |
| 139 in_set_screen_rotation_(false), | 139 in_set_screen_rotation_(false), |
| 140 user_rotation_(gfx::Display::ROTATE_0) { | 140 user_rotation_(gfx::Display::ROTATE_0) { |
| 141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 142 } | 142 } |
| 143 | 143 |
| 144 MaximizeModeController::~MaximizeModeController() { | 144 MaximizeModeController::~MaximizeModeController() { |
| 145 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 145 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { | |
| 149 if (rotation_locked_ == rotation_locked) | |
| 150 return; | |
| 151 rotation_locked_ = rotation_locked; | |
| 152 FOR_EACH_OBSERVER(Observer, observers_, OnRotationLockChanged()); | |
| 153 } | |
| 154 | |
| 155 void MaximizeModeController::AddObserver(Observer* observer) { | |
| 156 observers_.AddObserver(observer); | |
| 157 } | |
| 158 | |
| 159 void MaximizeModeController::RemoveObserver(Observer* observer) { | |
| 160 observers_.RemoveObserver(observer); | |
| 161 } | |
| 162 | |
| 148 bool MaximizeModeController::CanEnterMaximizeMode() { | 163 bool MaximizeModeController::CanEnterMaximizeMode() { |
| 149 // If we have ever seen accelerometer data, then HandleHingeRotation may | 164 // If we have ever seen accelerometer data, then HandleHingeRotation may |
| 150 // trigger maximize mode at some point in the future. | 165 // trigger maximize mode at some point in the future. |
| 151 // The --enable-touch-view-testing switch can also mean that we may enter | 166 // The --enable-touch-view-testing switch can also mean that we may enter |
| 152 // maximize mode. | 167 // maximize mode. |
| 153 return have_seen_accelerometer_data_ || | 168 return have_seen_accelerometer_data_ || |
| 154 CommandLine::ForCurrentProcess()->HasSwitch( | 169 CommandLine::ForCurrentProcess()->HasSwitch( |
| 155 switches::kAshEnableTouchViewTesting); | 170 switches::kAshEnableTouchViewTesting); |
| 156 } | 171 } |
| 157 | 172 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 170 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 185 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
| 171 return; | 186 return; |
| 172 } | 187 } |
| 173 | 188 |
| 174 // Responding to the hinge rotation can change the maximize mode state which | 189 // Responding to the hinge rotation can change the maximize mode state which |
| 175 // affects screen rotation, so we handle hinge rotation first. | 190 // affects screen rotation, so we handle hinge rotation first. |
| 176 HandleHingeRotation(base, lid); | 191 HandleHingeRotation(base, lid); |
| 177 HandleScreenRotation(lid); | 192 HandleScreenRotation(lid); |
| 178 } | 193 } |
| 179 | 194 |
| 195 void MaximizeModeController::OnDisplayConfigurationChanged() { | |
| 196 if (rotation_locked_ || in_set_screen_rotation_) | |
| 197 return; | |
| 198 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 199 user_rotation_ = display_manager-> | |
|
flackr
2014/05/28 14:48:04
Updating the user_rotation_ might be an unexpected
jonross
2014/05/28 19:13:33
Done.
| |
| 200 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
| 201 if (user_rotation_ != current_rotation_) | |
|
flackr
2014/05/28 14:48:04
nit: It would be helpful to have a comment here. P
jonross
2014/05/28 19:13:33
Done.
| |
| 202 SetRotationLocked(true); | |
| 203 } | |
| 204 | |
| 180 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 205 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| 181 const gfx::Vector3dF& lid) { | 206 const gfx::Vector3dF& lid) { |
| 182 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 207 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
| 183 bool maximize_mode_engaged = | 208 bool maximize_mode_engaged = |
| 184 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 209 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| 185 // Ignore the component of acceleration parallel to the hinge for the purposes | 210 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 186 // of hinge angle calculation. | 211 // of hinge angle calculation. |
| 187 gfx::Vector3dF base_flattened(base); | 212 gfx::Vector3dF base_flattened(base); |
| 188 gfx::Vector3dF lid_flattened(lid); | 213 gfx::Vector3dF lid_flattened(lid); |
| 189 base_flattened.set_y(0.0f); | 214 base_flattened.set_y(0.0f); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 212 } else if (!maximize_mode_engaged && | 237 } else if (!maximize_mode_engaged && |
| 213 angle > kEnterMaximizeModeAngle) { | 238 angle > kEnterMaximizeModeAngle) { |
| 214 EnterMaximizeMode(); | 239 EnterMaximizeMode(); |
| 215 } | 240 } |
| 216 } | 241 } |
| 217 | 242 |
| 218 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 243 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| 219 bool maximize_mode_engaged = | 244 bool maximize_mode_engaged = |
| 220 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 245 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| 221 | 246 |
| 222 if (!maximize_mode_engaged || rotation_locked_) | 247 if (!maximize_mode_engaged || rotation_locked_) |
|
flackr
2014/05/28 14:48:04
It might be useful to track accelerometer rotation
jonross
2014/05/28 19:13:33
Added todo
| |
| 223 return; | 248 return; |
| 224 | 249 |
| 225 DisplayManager* display_manager = | 250 DisplayManager* display_manager = |
| 226 Shell::GetInstance()->display_manager(); | 251 Shell::GetInstance()->display_manager(); |
| 227 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 252 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| 228 gfx::Display::InternalDisplayId()).rotation(); | 253 gfx::Display::InternalDisplayId()).rotation(); |
|
flackr
2014/05/28 14:48:04
This might be a local variable now. current_rotati
jonross
2014/05/28 19:13:33
This can be switched when we address the todo for
| |
| 229 | 254 |
| 230 // After determining maximize mode state, determine if the screen should | 255 // After determining maximize mode state, determine if the screen should |
| 231 // be rotated. | 256 // be rotated. |
| 232 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); | 257 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
| 233 float lid_flattened_length = lid_flattened.Length(); | 258 float lid_flattened_length = lid_flattened.Length(); |
| 234 // When the lid is close to being flat, don't change rotation as it is too | 259 // When the lid is close to being flat, don't change rotation as it is too |
| 235 // sensitive to slight movements. | 260 // sensitive to slight movements. |
| 236 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | 261 if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
| 237 return; | 262 return; |
| 238 | 263 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 | 299 |
| 275 if (new_rotation != current_rotation) | 300 if (new_rotation != current_rotation) |
| 276 SetDisplayRotation(display_manager, new_rotation); | 301 SetDisplayRotation(display_manager, new_rotation); |
| 277 } | 302 } |
| 278 | 303 |
| 279 void MaximizeModeController::SetDisplayRotation( | 304 void MaximizeModeController::SetDisplayRotation( |
| 280 DisplayManager* display_manager, | 305 DisplayManager* display_manager, |
| 281 gfx::Display::Rotation rotation) { | 306 gfx::Display::Rotation rotation) { |
| 282 base::AutoReset<bool> auto_in_set_screen_rotation( | 307 base::AutoReset<bool> auto_in_set_screen_rotation( |
| 283 &in_set_screen_rotation_, true); | 308 &in_set_screen_rotation_, true); |
| 309 current_rotation_ = rotation; | |
| 284 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 310 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 285 rotation); | 311 rotation); |
| 286 } | 312 } |
| 287 | 313 |
| 288 void MaximizeModeController::EnterMaximizeMode() { | 314 void MaximizeModeController::EnterMaximizeMode() { |
| 289 // TODO(jonross): Listen for display configuration changes. If the user | |
| 290 // causes a rotation change a rotation lock should be applied. | |
| 291 // https://crbug.com/369505 | |
| 292 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 315 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 293 user_rotation_ = display_manager-> | 316 user_rotation_ = display_manager-> |
|
flackr
2014/05/28 14:48:04
nit: Just use current_rotation_ = user_rotation_ =
jonross
2014/05/28 19:13:33
Done.
| |
| 294 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 317 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 318 current_rotation_ = user_rotation_; | |
| 295 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 319 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| 296 event_blocker_.reset(new MaximizeModeEventBlocker); | 320 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 297 #if defined(OS_CHROMEOS) | 321 #if defined(OS_CHROMEOS) |
| 298 event_handler_.reset(new ScreenshotActionHandler); | 322 event_handler_.reset(new ScreenshotActionHandler); |
| 299 #endif | 323 #endif |
| 324 Shell::GetInstance()->display_controller()->AddObserver(this); | |
| 300 } | 325 } |
| 301 | 326 |
| 302 void MaximizeModeController::LeaveMaximizeMode() { | 327 void MaximizeModeController::LeaveMaximizeMode() { |
| 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 328 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 304 DisplayInfo info = display_manager-> | 329 gfx::Display::Rotation current_rotation = display_manager-> |
| 305 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 330 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 306 gfx::Display::Rotation current_rotation = info.rotation(); | |
| 307 if (current_rotation != user_rotation_) | 331 if (current_rotation != user_rotation_) |
| 308 SetDisplayRotation(display_manager, user_rotation_); | 332 SetDisplayRotation(display_manager, user_rotation_); |
| 309 rotation_locked_ = false; | 333 rotation_locked_ = false; |
| 310 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 334 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| 311 event_blocker_.reset(); | 335 event_blocker_.reset(); |
| 312 event_handler_.reset(); | 336 event_handler_.reset(); |
| 337 Shell::GetInstance()->display_controller()->RemoveObserver(this); | |
| 313 } | 338 } |
| 314 | 339 |
| 315 } // namespace ash | 340 } // namespace ash |
| OLD | NEW |