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

Side by Side Diff: ash/common/wm/maximize_mode/maximize_mode_controller.cc

Issue 2775683002: CrOS: Apply flag which enables us to force maximize mode. (Closed)
Patch Set: Rebased. Created 3 years, 8 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/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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 ui::ConvertAccelerometerReadingToVector3dF( 78 ui::ConvertAccelerometerReadingToVector3dF(
79 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN)) 79 update.get(chromeos::ACCELEROMETER_SOURCE_SCREEN))
80 .Length()) <= kNoisyMagnitudeDeviation; 80 .Length()) <= kNoisyMagnitudeDeviation;
81 } 81 }
82 82
83 bool IsEnabled() { 83 bool IsEnabled() {
84 return base::CommandLine::ForCurrentProcess()->HasSwitch( 84 return base::CommandLine::ForCurrentProcess()->HasSwitch(
85 switches::kAshEnableTouchView); 85 switches::kAshEnableTouchView);
86 } 86 }
87 87
88 // Checks the command line to see which force maximize mode is turned on, if
89 // any.
90 MaximizeModeController::ForceTabletMode GetMaximizeMode() {
91 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
92 if (command_line->HasSwitch(switches::kAshForceTabletMode)) {
93 std::string switch_value =
94 command_line->GetSwitchValueASCII(switches::kAshForceTabletMode);
95 if (switch_value == switches::kAshForceTabletModeClamshell)
96 return MaximizeModeController::ForceTabletMode::CLAMSHELL;
97
98 if (switch_value == switches::kAshForceTabletModeTouchView)
99 return MaximizeModeController::ForceTabletMode::TOUCHVIEW;
100 }
101 return MaximizeModeController::ForceTabletMode::NONE;
102 }
103
88 } // namespace 104 } // namespace
89 105
90 MaximizeModeController::MaximizeModeController() 106 MaximizeModeController::MaximizeModeController()
91 : have_seen_accelerometer_data_(false), 107 : have_seen_accelerometer_data_(false),
92 can_detect_lid_angle_(false), 108 can_detect_lid_angle_(false),
93 touchview_usage_interval_start_time_(base::Time::Now()), 109 touchview_usage_interval_start_time_(base::Time::Now()),
94 tick_clock_(new base::DefaultTickClock()), 110 tick_clock_(new base::DefaultTickClock()),
95 tablet_mode_switch_is_on_(false), 111 tablet_mode_switch_is_on_(false),
96 lid_is_closed_(false), 112 lid_is_closed_(false),
97 weak_factory_(this) { 113 weak_factory_(this) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 maximize_mode_window_manager_->AddWindow(window); 189 maximize_mode_window_manager_->AddWindow(window);
174 } 190 }
175 191
176 void MaximizeModeController::BindRequest( 192 void MaximizeModeController::BindRequest(
177 mojom::TouchViewManagerRequest request) { 193 mojom::TouchViewManagerRequest request) {
178 bindings_.AddBinding(this, std::move(request)); 194 bindings_.AddBinding(this, std::move(request));
179 } 195 }
180 196
181 void MaximizeModeController::OnAccelerometerUpdated( 197 void MaximizeModeController::OnAccelerometerUpdated(
182 scoped_refptr<const chromeos::AccelerometerUpdate> update) { 198 scoped_refptr<const chromeos::AccelerometerUpdate> update) {
199 if (!AllowEnterExitMaximizeMode())
200 return;
201
183 have_seen_accelerometer_data_ = true; 202 have_seen_accelerometer_data_ = true;
184 can_detect_lid_angle_ = 203 can_detect_lid_angle_ =
185 update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN) && 204 update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN) &&
186 update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD); 205 update->has(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD);
187 206
188 if (!can_detect_lid_angle_) 207 if (!can_detect_lid_angle_)
189 return; 208 return;
190 209
191 if (!display::Display::HasInternalDisplay()) 210 if (!display::Display::HasInternalDisplay())
192 return; 211 return;
(...skipping 14 matching lines...) Expand all
207 // Ignore the reading if it appears unstable. The reading is considered 226 // Ignore the reading if it appears unstable. The reading is considered
208 // unstable if it deviates too much from gravity and/or the magnitude of the 227 // unstable if it deviates too much from gravity and/or the magnitude of the
209 // reading from the lid differs too much from the reading from the base. 228 // reading from the lid differs too much from the reading from the base.
210 HandleHingeRotation(update); 229 HandleHingeRotation(update);
211 } 230 }
212 } 231 }
213 232
214 void MaximizeModeController::LidEventReceived( 233 void MaximizeModeController::LidEventReceived(
215 chromeos::PowerManagerClient::LidState state, 234 chromeos::PowerManagerClient::LidState state,
216 const base::TimeTicks& time) { 235 const base::TimeTicks& time) {
236 if (!AllowEnterExitMaximizeMode())
237 return;
238
217 const bool open = state == chromeos::PowerManagerClient::LidState::OPEN; 239 const bool open = state == chromeos::PowerManagerClient::LidState::OPEN;
218 if (open) 240 if (open)
219 last_lid_open_time_ = time; 241 last_lid_open_time_ = time;
220 lid_is_closed_ = !open; 242 lid_is_closed_ = !open;
221 LeaveMaximizeMode(); 243 LeaveMaximizeMode();
222 } 244 }
223 245
224 void MaximizeModeController::TabletModeEventReceived( 246 void MaximizeModeController::TabletModeEventReceived(
225 chromeos::PowerManagerClient::TabletMode mode, 247 chromeos::PowerManagerClient::TabletMode mode,
226 const base::TimeTicks& time) { 248 const base::TimeTicks& time) {
249 if (!AllowEnterExitMaximizeMode())
250 return;
251
227 const bool on = mode == chromeos::PowerManagerClient::TabletMode::ON; 252 const bool on = mode == chromeos::PowerManagerClient::TabletMode::ON;
228 tablet_mode_switch_is_on_ = on; 253 tablet_mode_switch_is_on_ = on;
229 // Do not change if docked. 254 // Do not change if docked.
230 if (!display::Display::HasInternalDisplay() || 255 if (!display::Display::HasInternalDisplay() ||
231 !WmShell::Get()->IsActiveDisplayId( 256 !WmShell::Get()->IsActiveDisplayId(
232 display::Display::InternalDisplayId())) { 257 display::Display::InternalDisplayId())) {
233 return; 258 return;
234 } 259 }
235 // The tablet mode switch activates at 300 degrees, so it is always reliable 260 // The tablet mode switch activates at 300 degrees, so it is always reliable
236 // when |on|. However we wish to exit maximize mode at a smaller angle, so 261 // when |on|. However we wish to exit maximize mode at a smaller angle, so
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 void MaximizeModeController::OnMaximizeModeStarted() { 371 void MaximizeModeController::OnMaximizeModeStarted() {
347 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE); 372 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_INACTIVE);
348 } 373 }
349 374
350 // Called after maximize mode has ended, windows might still be returning to 375 // Called after maximize mode has ended, windows might still be returning to
351 // their original position. 376 // their original position.
352 void MaximizeModeController::OnMaximizeModeEnded() { 377 void MaximizeModeController::OnMaximizeModeEnded() {
353 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_ACTIVE); 378 RecordTouchViewUsageInterval(TOUCH_VIEW_INTERVAL_ACTIVE);
354 } 379 }
355 380
381 void MaximizeModeController::OnShellInitialized() {
382 force_tablet_mode_ = GetMaximizeMode();
383 if (force_tablet_mode_ == ForceTabletMode::TOUCHVIEW)
384 EnterMaximizeMode();
385 }
386
356 void MaximizeModeController::OnDisplayConfigurationChanged() { 387 void MaximizeModeController::OnDisplayConfigurationChanged() {
357 if (!display::Display::HasInternalDisplay() || 388 if (!display::Display::HasInternalDisplay() ||
358 !WmShell::Get()->IsActiveDisplayId( 389 !WmShell::Get()->IsActiveDisplayId(
359 display::Display::InternalDisplayId())) { 390 display::Display::InternalDisplayId())) {
360 LeaveMaximizeMode(); 391 LeaveMaximizeMode();
361 } else if (tablet_mode_switch_is_on_ && 392 } else if (tablet_mode_switch_is_on_ &&
362 !IsMaximizeModeWindowManagerEnabled()) { 393 !IsMaximizeModeWindowManagerEnabled()) {
363 // The internal display has returned, as we are exiting docked mode. 394 // The internal display has returned, as we are exiting docked mode.
364 // The device is still in tablet mode, so trigger maximize mode, as this 395 // The device is still in tablet mode, so trigger maximize mode, as this
365 // switch leads to the ignoring of accelerometer events. When the switch is 396 // switch leads to the ignoring of accelerometer events. When the switch is
(...skipping 29 matching lines...) Expand all
395 if (IsMaximizeModeWindowManagerEnabled()) 426 if (IsMaximizeModeWindowManagerEnabled())
396 return TOUCH_VIEW_INTERVAL_ACTIVE; 427 return TOUCH_VIEW_INTERVAL_ACTIVE;
397 return TOUCH_VIEW_INTERVAL_INACTIVE; 428 return TOUCH_VIEW_INTERVAL_INACTIVE;
398 } 429 }
399 430
400 void MaximizeModeController::AddObserver(mojom::TouchViewObserverPtr observer) { 431 void MaximizeModeController::AddObserver(mojom::TouchViewObserverPtr observer) {
401 observer->OnTouchViewToggled(IsMaximizeModeWindowManagerEnabled()); 432 observer->OnTouchViewToggled(IsMaximizeModeWindowManagerEnabled());
402 observers_.AddPtr(std::move(observer)); 433 observers_.AddPtr(std::move(observer));
403 } 434 }
404 435
436 bool MaximizeModeController::AllowEnterExitMaximizeMode() const {
437 return force_tablet_mode_ == ForceTabletMode::NONE;
438 }
439
405 void MaximizeModeController::OnAppTerminating() { 440 void MaximizeModeController::OnAppTerminating() {
406 // The system is about to shut down, so record TouchView usage interval 441 // The system is about to shut down, so record TouchView usage interval
407 // metrics based on whether TouchView mode is currently active. 442 // metrics based on whether TouchView mode is currently active.
408 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType()); 443 RecordTouchViewUsageInterval(CurrentTouchViewIntervalType());
409 444
410 if (CanEnterMaximizeMode()) { 445 if (CanEnterMaximizeMode()) {
411 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", 446 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal",
412 total_touchview_time_.InMinutes(), 1, 447 total_touchview_time_.InMinutes(), 1,
413 base::TimeDelta::FromDays(7).InMinutes(), 50); 448 base::TimeDelta::FromDays(7).InMinutes(), 50);
414 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", 449 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal",
(...skipping 26 matching lines...) Expand all
441 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds; 476 return elapsed_time.InSeconds() <= kLidRecentlyOpenedDurationSeconds;
442 } 477 }
443 478
444 void MaximizeModeController::SetTickClockForTest( 479 void MaximizeModeController::SetTickClockForTest(
445 std::unique_ptr<base::TickClock> tick_clock) { 480 std::unique_ptr<base::TickClock> tick_clock) {
446 DCHECK(tick_clock_); 481 DCHECK(tick_clock_);
447 tick_clock_ = std::move(tick_clock); 482 tick_clock_ = std::move(tick_clock);
448 } 483 }
449 484
450 } // namespace ash 485 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/maximize_mode/maximize_mode_controller.h ('k') | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698