| 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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return maximize_mode_window_manager_.get() != NULL; | 144 return maximize_mode_window_manager_.get() != NULL; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void MaximizeModeController::AddWindow(aura::Window* window) { | 147 void MaximizeModeController::AddWindow(aura::Window* window) { |
| 148 if (IsMaximizeModeWindowManagerEnabled()) | 148 if (IsMaximizeModeWindowManagerEnabled()) |
| 149 maximize_mode_window_manager_->AddWindow(window); | 149 maximize_mode_window_manager_->AddWindow(window); |
| 150 } | 150 } |
| 151 | 151 |
| 152 #if defined(OS_CHROMEOS) | 152 #if defined(OS_CHROMEOS) |
| 153 void MaximizeModeController::OnAccelerometerUpdated( | 153 void MaximizeModeController::OnAccelerometerUpdated( |
| 154 const chromeos::AccelerometerUpdate& update) { | 154 scoped_refptr<const chromeos::AccelerometerUpdate> update) { |
| 155 bool first_accelerometer_update = !have_seen_accelerometer_data_; | 155 bool first_accelerometer_update = !have_seen_accelerometer_data_; |
| 156 have_seen_accelerometer_data_ = true; | 156 have_seen_accelerometer_data_ = true; |
| 157 | 157 |
| 158 if (!update.has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) | 158 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 // Whether or not we enter maximize mode affects whether we handle screen | 161 // Whether or not we enter maximize mode affects whether we handle screen |
| 162 // rotation, so determine whether to enter maximize mode first. | 162 // rotation, so determine whether to enter maximize mode first. |
| 163 if (!update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { | 163 if (!update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { |
| 164 if (first_accelerometer_update) | 164 if (first_accelerometer_update) |
| 165 EnterMaximizeMode(); | 165 EnterMaximizeMode(); |
| 166 } else if (ui::IsAccelerometerReadingStable( | 166 } else if (ui::IsAccelerometerReadingStable( |
| 167 update, chromeos::ACCELEROMETER_SOURCE_SCREEN) && | 167 *update, chromeos::ACCELEROMETER_SOURCE_SCREEN) && |
| 168 ui::IsAccelerometerReadingStable( | 168 ui::IsAccelerometerReadingStable( |
| 169 update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) && | 169 *update, chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) && |
| 170 IsAngleBetweenAccelerometerReadingsStable(update)) { | 170 IsAngleBetweenAccelerometerReadingsStable(*update)) { |
| 171 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) | 171 // update.has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) |
| 172 // Ignore the reading if it appears unstable. The reading is considered | 172 // Ignore the reading if it appears unstable. The reading is considered |
| 173 // unstable if it deviates too much from gravity and/or the magnitude of the | 173 // unstable if it deviates too much from gravity and/or the magnitude of the |
| 174 // reading from the lid differs too much from the reading from the base. | 174 // reading from the lid differs too much from the reading from the base. |
| 175 HandleHingeRotation(update); | 175 HandleHingeRotation(update.get()); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 void MaximizeModeController::LidEventReceived(bool open, | 179 void MaximizeModeController::LidEventReceived(bool open, |
| 180 const base::TimeTicks& time) { | 180 const base::TimeTicks& time) { |
| 181 if (open) | 181 if (open) |
| 182 last_lid_open_time_ = time; | 182 last_lid_open_time_ = time; |
| 183 lid_is_closed_ = !open; | 183 lid_is_closed_ = !open; |
| 184 LeaveMaximizeMode(); | 184 LeaveMaximizeMode(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void MaximizeModeController::SuspendImminent() { | 187 void MaximizeModeController::SuspendImminent() { |
| 188 // The system is about to suspend, so record TouchView usage interval metrics | 188 // The system is about to suspend, so record TouchView usage interval metrics |
| 189 // based on whether TouchView mode is currently active. | 189 // based on whether TouchView mode is currently active. |
| 190 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); | 190 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void MaximizeModeController::SuspendDone( | 193 void MaximizeModeController::SuspendDone( |
| 194 const base::TimeDelta& sleep_duration) { | 194 const base::TimeDelta& sleep_duration) { |
| 195 // We do not want TouchView usage metrics to include time spent in suspend. | 195 // We do not want TouchView usage metrics to include time spent in suspend. |
| 196 touchview_usage_interval_start_time_ = base::Time::Now(); | 196 touchview_usage_interval_start_time_ = base::Time::Now(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void MaximizeModeController::HandleHingeRotation( | 199 void MaximizeModeController::HandleHingeRotation( |
| 200 const chromeos::AccelerometerUpdate& update) { | 200 const chromeos::AccelerometerUpdate* update) { |
| 201 static const gfx::Vector3dF hinge_vector(1.0f, 0.0f, 0.0f); | 201 static const gfx::Vector3dF hinge_vector(1.0f, 0.0f, 0.0f); |
| 202 // Ignore the component of acceleration parallel to the hinge for the purposes | 202 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 203 // of hinge angle calculation. | 203 // of hinge angle calculation. |
| 204 gfx::Vector3dF base_flattened(ui::ConvertAccelerometerReadingToVector3dF( | 204 gfx::Vector3dF base_flattened(ui::ConvertAccelerometerReadingToVector3dF( |
| 205 update.get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD))); | 205 update->get(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD))); |
| 206 gfx::Vector3dF lid_flattened(ui::ConvertAccelerometerReadingToVector3dF( | 206 gfx::Vector3dF lid_flattened(ui::ConvertAccelerometerReadingToVector3dF( |
| 207 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN))); | 207 update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN))); |
| 208 base_flattened.set_x(0.0f); | 208 base_flattened.set_x(0.0f); |
| 209 lid_flattened.set_x(0.0f); | 209 lid_flattened.set_x(0.0f); |
| 210 | 210 |
| 211 // As the hinge approaches a vertical angle, the base and lid accelerometers | 211 // As the hinge approaches a vertical angle, the base and lid accelerometers |
| 212 // approach the same values making any angle calculations highly inaccurate. | 212 // approach the same values making any angle calculations highly inaccurate. |
| 213 // Bail out early when it is too close. | 213 // Bail out early when it is too close. |
| 214 if (base_flattened.Length() < kHingeAngleDetectionThreshold || | 214 if (base_flattened.Length() < kHingeAngleDetectionThreshold || |
| 215 lid_flattened.Length() < kHingeAngleDetectionThreshold) { | 215 lid_flattened.Length() < kHingeAngleDetectionThreshold) { |
| 216 return; | 216 return; |
| 217 } | 217 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 return elapsed_time <= kLidRecentlyOpenedDuration; | 339 return elapsed_time <= kLidRecentlyOpenedDuration; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void MaximizeModeController::SetTickClockForTest( | 342 void MaximizeModeController::SetTickClockForTest( |
| 343 scoped_ptr<base::TickClock> tick_clock) { | 343 scoped_ptr<base::TickClock> tick_clock) { |
| 344 DCHECK(tick_clock_); | 344 DCHECK(tick_clock_); |
| 345 tick_clock_ = tick_clock.Pass(); | 345 tick_clock_ = tick_clock.Pass(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace ash | 348 } // namespace ash |
| OLD | NEW |