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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.h

Issue 412013002: Prevent entering maximize mode when the lid is closed or has recently opened. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified enter/exit maximize mode logic and minor nit fixes. Created 6 years, 4 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 #ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ 5 #ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ 6 #define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
7 7
8 #include "ash/accelerometer/accelerometer_observer.h" 8 #include "ash/accelerometer/accelerometer_observer.h"
9 #include "ash/ash_export.h" 9 #include "ash/ash_export.h"
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
11 #include "ash/display/display_manager.h" 11 #include "ash/display/display_manager.h"
12 #include "ash/shell_observer.h" 12 #include "ash/shell_observer.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/power_monitor/power_observer.h"
17 #include "ui/gfx/display.h" 16 #include "ui/gfx/display.h"
18 17
18 #if defined(OS_CHROMEOS)
19 #include "chromeos/dbus/power_manager_client.h"
20 #endif // OS_CHROMEOS
21
22 namespace base {
23 class TickClock;
24 }
25
19 namespace ui { 26 namespace ui {
20 class EventHandler; 27 class EventHandler;
21 } 28 }
22 29
23 namespace ash { 30 namespace ash {
24 31
25 class MaximizeModeControllerTest; 32 class MaximizeModeControllerTest;
26 class ScopedDisableInternalMouseAndKeyboard; 33 class ScopedDisableInternalMouseAndKeyboard;
27 class MaximizeModeWindowManager; 34 class MaximizeModeWindowManager;
28 class MaximizeModeWindowManagerTest; 35 class MaximizeModeWindowManagerTest;
29 36
30 // MaximizeModeController listens to accelerometer events and automatically 37 // MaximizeModeController listens to accelerometer events and automatically
31 // enters and exits maximize mode when the lid is opened beyond the triggering 38 // enters and exits maximize mode when the lid is opened beyond the triggering
32 // angle and rotates the display to match the device when in maximize mode. 39 // angle and rotates the display to match the device when in maximize mode.
33 class ASH_EXPORT MaximizeModeController : public AccelerometerObserver, 40 class ASH_EXPORT MaximizeModeController
34 public base::PowerObserver, 41 : public AccelerometerObserver,
flackr 2014/07/31 20:21:41 Also, indent 4 (making all of the following indent
bruthig 2014/08/05 18:06:43 Done.
42 #if defined(OS_CHROMEOS)
43 public chromeos::PowerManagerClient::Observer,
44 #endif // OS_CHROMEOS
35 public ShellObserver, 45 public ShellObserver,
36 public DisplayController::Observer { 46 public DisplayController::Observer {
37 public: 47 public:
38 // Observer that reports changes to the state of MaximizeModeController's 48 // Observer that reports changes to the state of MaximizeModeController's
39 // rotation lock. 49 // rotation lock.
40 class Observer { 50 class Observer {
41 public: 51 public:
42 // Invoked whenever |rotation_locked_| is changed. 52 // Invoked whenever |rotation_locked_| is changed.
43 virtual void OnRotationLockChanged(bool rotation_locked) {} 53 virtual void OnRotationLockChanged(bool rotation_locked) {}
44 54
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 101
92 // AccelerometerObserver: 102 // AccelerometerObserver:
93 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base, 103 virtual void OnAccelerometerUpdated(const gfx::Vector3dF& base,
94 const gfx::Vector3dF& lid) OVERRIDE; 104 const gfx::Vector3dF& lid) OVERRIDE;
95 105
96 // ShellObserver: 106 // ShellObserver:
97 virtual void OnAppTerminating() OVERRIDE; 107 virtual void OnAppTerminating() OVERRIDE;
98 virtual void OnMaximizeModeStarted() OVERRIDE; 108 virtual void OnMaximizeModeStarted() OVERRIDE;
99 virtual void OnMaximizeModeEnded() OVERRIDE; 109 virtual void OnMaximizeModeEnded() OVERRIDE;
100 110
101 // base::PowerObserver:
102 virtual void OnSuspend() OVERRIDE;
103 virtual void OnResume() OVERRIDE;
104
105 // DisplayController::Observer: 111 // DisplayController::Observer:
106 virtual void OnDisplayConfigurationChanged() OVERRIDE; 112 virtual void OnDisplayConfigurationChanged() OVERRIDE;
107 113
114 #if defined(OS_CHROMEOS)
115 // PowerManagerClient::Observer:
116 virtual void LidEventReceived(bool open,
117 const base::TimeTicks& time) OVERRIDE;
118 virtual void SuspendImminent() OVERRIDE;
119 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE;
120 #endif // OS_CHROMEOS
121
108 private: 122 private:
109 friend class MaximizeModeControllerTest; 123 friend class MaximizeModeControllerTest;
110 friend class MaximizeModeWindowManagerTest; 124 friend class MaximizeModeWindowManagerTest;
111 125
126 // Set the TickClock. This is only to be used by tests that need to
127 // artificially and deterministically control the current time.
128 void SetTickClockForTest(scoped_ptr<base::TickClock> tick_clock);
129
112 // Detect hinge rotation from |base| and |lid| accelerometers and 130 // Detect hinge rotation from |base| and |lid| accelerometers and
113 // automatically start / stop maximize mode. 131 // automatically start / stop maximize mode.
114 void HandleHingeRotation(const gfx::Vector3dF& base, 132 void HandleHingeRotation(const gfx::Vector3dF& base,
115 const gfx::Vector3dF& lid); 133 const gfx::Vector3dF& lid);
116 134
117 // Detect screen rotation from |lid| accelerometer and automatically rotate 135 // Detect screen rotation from |lid| accelerometer and automatically rotate
118 // screen. 136 // screen.
119 void HandleScreenRotation(const gfx::Vector3dF& lid); 137 void HandleScreenRotation(const gfx::Vector3dF& lid);
120 138
121 // Sets the display rotation and suppresses display notifications. 139 // Sets the display rotation and suppresses display notifications.
122 void SetDisplayRotation(DisplayManager* display_manager, 140 void SetDisplayRotation(DisplayManager* display_manager,
123 gfx::Display::Rotation rotation); 141 gfx::Display::Rotation rotation);
124 142
143 // Returns true if the lid was recently opened.
144 bool WasLidOpenedRecently() const;
145
125 // Enables MaximizeModeWindowManager, and determines the current state of 146 // Enables MaximizeModeWindowManager, and determines the current state of
126 // rotation lock. 147 // rotation lock.
127 void EnterMaximizeMode(); 148 void EnterMaximizeMode();
128 149
129 // Removes MaximizeModeWindowManager and resets the display rotation if there 150 // Removes MaximizeModeWindowManager and resets the display rotation if there
130 // is no rotation lock. 151 // is no rotation lock.
131 void LeaveMaximizeMode(); 152 void LeaveMaximizeMode();
132 153
133 // Record UMA stats tracking touchview usage. 154 // Record UMA stats tracking touchview usage.
134 void RecordTouchViewStateTransition(); 155 void RecordTouchViewStateTransition();
(...skipping 27 matching lines...) Expand all
162 gfx::Display::Rotation current_rotation_; 183 gfx::Display::Rotation current_rotation_;
163 184
164 // Rotation Lock observers. 185 // Rotation Lock observers.
165 ObserverList<Observer> observers_; 186 ObserverList<Observer> observers_;
166 187
167 // Tracks time spent in (and out of) touchview mode. 188 // Tracks time spent in (and out of) touchview mode.
168 base::Time last_touchview_transition_time_; 189 base::Time last_touchview_transition_time_;
169 base::TimeDelta total_touchview_time_; 190 base::TimeDelta total_touchview_time_;
170 base::TimeDelta total_non_touchview_time_; 191 base::TimeDelta total_non_touchview_time_;
171 192
193 // Tracks the last time we received a lid open event. This is used to suppress
194 // erroneous accelerometer readings as the lid is opened but the accelerometer
195 // reports readings that make the lid to appear near fully open.
196 base::TimeTicks last_lid_open_time_;
197
198 // Source for the current time in base::TimeTicks.
199 scoped_ptr<base::TickClock> tick_clock_;
200
201 // Tracks when the lid is closed. Used to prevent entering maximize mode.
202 bool lid_is_closed_;
203
172 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController); 204 DISALLOW_COPY_AND_ASSIGN(MaximizeModeController);
173 }; 205 };
174 206
175 } // namespace ash 207 } // namespace ash
176 208
177 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_ 209 #endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | ash/wm/maximize_mode/maximize_mode_controller.cc » ('j') | ash/wm/maximize_mode/maximize_mode_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698