| 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/common/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 tick_clock_(new base::DefaultTickClock()), | 91 tick_clock_(new base::DefaultTickClock()), |
| 92 tablet_mode_switch_is_on_(false), | 92 tablet_mode_switch_is_on_(false), |
| 93 lid_is_closed_(false) { | 93 lid_is_closed_(false) { |
| 94 WmShell::Get()->AddShellObserver(this); | 94 WmShell::Get()->AddShellObserver(this); |
| 95 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); | 95 WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED); |
| 96 | 96 |
| 97 // TODO(jonross): Do not create MaximizeModeController if the flag is | 97 // TODO(jonross): Do not create MaximizeModeController if the flag is |
| 98 // unavailable. This will require refactoring | 98 // unavailable. This will require refactoring |
| 99 // IsMaximizeModeWindowManagerEnabled to check for the existance of the | 99 // IsMaximizeModeWindowManagerEnabled to check for the existance of the |
| 100 // controller. | 100 // controller. |
| 101 const bool is_enabled = IsEnabled(); | 101 if (IsEnabled()) { |
| 102 if (is_enabled) | |
| 103 WmShell::Get()->AddDisplayObserver(this); | 102 WmShell::Get()->AddDisplayObserver(this); |
| 104 | |
| 105 if (is_enabled) | |
| 106 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 103 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
| 104 } |
| 107 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 105 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 108 this); | 106 this); |
| 109 } | 107 } |
| 110 | 108 |
| 111 MaximizeModeController::~MaximizeModeController() { | 109 MaximizeModeController::~MaximizeModeController() { |
| 112 WmShell::Get()->RemoveShellObserver(this); | 110 WmShell::Get()->RemoveShellObserver(this); |
| 113 const bool is_enabled = IsEnabled(); | 111 |
| 114 if (is_enabled) | 112 if (IsEnabled()) { |
| 115 WmShell::Get()->RemoveDisplayObserver(this); | 113 WmShell::Get()->RemoveDisplayObserver(this); |
| 116 | |
| 117 if (is_enabled) | |
| 118 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 114 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
| 115 } |
| 119 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 116 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 120 this); | 117 this); |
| 121 } | 118 } |
| 122 | 119 |
| 123 bool MaximizeModeController::CanEnterMaximizeMode() { | 120 bool MaximizeModeController::CanEnterMaximizeMode() { |
| 124 // If we have ever seen accelerometer data, then HandleHingeRotation may | 121 // If we have ever seen accelerometer data, then HandleHingeRotation may |
| 125 // trigger maximize mode at some point in the future. | 122 // trigger maximize mode at some point in the future. |
| 126 // The --enable-touch-view-testing switch can also mean that we may enter | 123 // All TouchView-enabled devices can enter maximized mode. |
| 127 // maximize mode. | 124 return have_seen_accelerometer_data_ || IsEnabled(); |
| 128 // TODO(mgiuca): This can result in false positives, as it returns true for | |
| 129 // any device with an accelerometer. Have TouchView-enabled devices explicitly | |
| 130 // set a flag, and change this implementation to simply return true iff the | |
| 131 // flag is present (http://crbug.com/457445). | |
| 132 return have_seen_accelerometer_data_ || | |
| 133 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 134 switches::kAshEnableTouchViewTesting); | |
| 135 } | 125 } |
| 136 | 126 |
| 137 // TODO(jcliang): Hide or remove EnableMaximizeModeWindowManager | 127 // TODO(jcliang): Hide or remove EnableMaximizeModeWindowManager |
| 138 // (http://crbug.com/620241). | 128 // (http://crbug.com/620241). |
| 139 void MaximizeModeController::EnableMaximizeModeWindowManager( | 129 void MaximizeModeController::EnableMaximizeModeWindowManager( |
| 140 bool should_enable) { | 130 bool should_enable) { |
| 141 bool is_enabled = !!maximize_mode_window_manager_.get(); | 131 bool is_enabled = !!maximize_mode_window_manager_.get(); |
| 142 if (should_enable == is_enabled) | 132 if (should_enable == is_enabled) |
| 143 return; | 133 return; |
| 144 | 134 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 EnterMaximizeMode(); | 299 EnterMaximizeMode(); |
| 310 } | 300 } |
| 311 } | 301 } |
| 312 | 302 |
| 313 void MaximizeModeController::EnterMaximizeMode() { | 303 void MaximizeModeController::EnterMaximizeMode() { |
| 314 // Always reset first to avoid creation before destruction of a previous | 304 // Always reset first to avoid creation before destruction of a previous |
| 315 // object. | 305 // object. |
| 316 event_blocker_ = | 306 event_blocker_ = |
| 317 WmShell::Get()->CreateScopedDisableInternalMouseAndKeyboard(); | 307 WmShell::Get()->CreateScopedDisableInternalMouseAndKeyboard(); |
| 318 | 308 |
| 319 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 320 switches::kAshEnableTouchViewTesting)) { | |
| 321 // We don't let accelerometer updates interfere with the maximize mode | |
| 322 // status as set by the touch-view-testing keyboard shortcut. | |
| 323 return; | |
| 324 } | |
| 325 | |
| 326 if (IsMaximizeModeWindowManagerEnabled()) | 309 if (IsMaximizeModeWindowManagerEnabled()) |
| 327 return; | 310 return; |
| 328 EnableMaximizeModeWindowManager(true); | 311 EnableMaximizeModeWindowManager(true); |
| 329 } | 312 } |
| 330 | 313 |
| 331 void MaximizeModeController::LeaveMaximizeMode() { | 314 void MaximizeModeController::LeaveMaximizeMode() { |
| 332 event_blocker_.reset(); | 315 event_blocker_.reset(); |
| 333 | 316 |
| 334 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 335 switches::kAshEnableTouchViewTesting)) { | |
| 336 // We don't let accelerometer updates interfere with the maximize mode | |
| 337 // status as set by the touch-view-testing keyboard shortcut. | |
| 338 return; | |
| 339 } | |
| 340 | |
| 341 if (!IsMaximizeModeWindowManagerEnabled()) | 317 if (!IsMaximizeModeWindowManagerEnabled()) |
| 342 return; | 318 return; |
| 343 EnableMaximizeModeWindowManager(false); | 319 EnableMaximizeModeWindowManager(false); |
| 344 } | 320 } |
| 345 | 321 |
| 346 // Called after maximize mode has started, windows might still animate though. | 322 // Called after maximize mode has started, windows might still animate though. |
| 347 void MaximizeModeController::OnMaximizeModeStarted() { | 323 void MaximizeModeController::OnMaximizeModeStarted() { |
| 348 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE); | 324 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE); |
| 349 } | 325 } |
| 350 | 326 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; | 403 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; |
| 428 } | 404 } |
| 429 | 405 |
| 430 void MaximizeModeController::SetTickClockForTest( | 406 void MaximizeModeController::SetTickClockForTest( |
| 431 std::unique_ptr<base::TickClock> tick_clock) { | 407 std::unique_ptr<base::TickClock> tick_clock) { |
| 432 DCHECK(tick_clock_); | 408 DCHECK(tick_clock_); |
| 433 tick_clock_ = std::move(tick_clock); | 409 tick_clock_ = std::move(tick_clock); |
| 434 } | 410 } |
| 435 | 411 |
| 436 } // namespace ash | 412 } // namespace ash |
| OLD | NEW |