OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | |
6 #define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | |
7 | |
8 #include "ash/accelerometer/accelerometer_observer.h" | |
9 #include "ash/ash_export.h" | |
10 #include "ash/display/display_controller.h" | |
11 #include "ash/shell_observer.h" | |
12 #include "base/macros.h" | |
13 #include "base/observer_list.h" | |
14 #include "content/public/browser/screen_orientation_delegate.h" | |
15 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | |
16 #include "ui/gfx/display.h" | |
17 | |
18 namespace aura { | |
19 class Window; | |
20 } | |
21 | |
22 namespace content { | |
23 class WebContents; | |
24 } | |
25 | |
26 namespace ash { | |
27 | |
28 // Implements ChromeOS specific functionality for ScreenOrientationProvider. | |
29 class ASH_EXPORT ScreenOrientationController | |
30 : public AccelerometerObserver, | |
31 public content::ScreenOrientationDelegate, | |
32 public DisplayController::Observer, | |
33 public ShellObserver { | |
34 public: | |
35 // Observer that reports changes to the state of ScreenOrientationProvider's | |
36 // rotation lock. | |
37 class Observer { | |
38 public: | |
39 // Invoked when rotation is locked or unlocked. | |
40 virtual void OnRotationLockChanged(bool rotation_locked) {} | |
41 | |
42 protected: | |
43 virtual ~Observer() {} | |
44 }; | |
45 | |
46 ScreenOrientationController(); | |
47 virtual ~ScreenOrientationController(); | |
48 | |
49 // Add/Remove observers. | |
50 void AddObserver(Observer* observer); | |
51 void RemoveObserver(Observer* observer); | |
52 | |
53 bool ignore_display_configuration_updates() const { | |
54 return ignore_display_configuration_updates_; | |
55 } | |
56 | |
57 // True if |rotation_lock_| has been set and accelerometer updates should not | |
58 // rotate the display. | |
59 bool rotation_locked() { return rotation_locked_; } | |
oshima
2014/12/11 23:51:28
nit: const
jonross
2014/12/12 18:30:04
Done.
| |
60 | |
61 // If |rotation_locked| future accelerometer updates should not change the | |
62 // display rotation. | |
63 void SetRotationLocked(bool rotation_locked); | |
64 | |
65 // Sets the display rotation and suppresses display notifications. | |
66 void SetDisplayRotation(gfx::Display::Rotation rotation); | |
67 | |
68 // AccelerometerObserver: | |
69 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; | |
70 | |
71 // content::ScreenOrientationDelegate: | |
72 bool FullScreenRequired(content::WebContents* web_contents) override; | |
73 void Lock(content::WebContents* web_contents, | |
74 blink::WebScreenOrientationLockType lock_orientation) override; | |
75 bool ScreenOrientationProviderSupported() override; | |
76 void Unlock(content::WebContents* web_contents) override; | |
77 | |
78 // DisplayController::Observer: | |
79 void OnDisplayConfigurationChanged() override; | |
80 | |
81 // ShellObserver: | |
82 void OnMaximizeModeStarted() override; | |
83 void OnMaximizeModeEnded() override; | |
84 | |
85 private: | |
86 // Sets the display rotation to |rotation|. Future accelerometer updates | |
87 // should not be used to change the rotation. SetRotationLocked(false) removes | |
88 // the rotation lock. | |
89 void LockRotation(gfx::Display::Rotation rotation); | |
90 | |
91 // Locks rotation to the angle matching the primary orientation for | |
92 // |lock_orientation|. | |
93 void LockRotationToPrimaryOrientation( | |
94 blink::WebScreenOrientationLockType lock_orientation); | |
95 | |
96 // Locks rotation to the angle matching the secondary orientation for | |
97 // |lock_orientation|. | |
98 void LockRotationToSecondaryOrientation( | |
99 blink::WebScreenOrientationLockType lock_orientation); | |
100 | |
101 // For orientations that do not specify primary or secondary, locks to the | |
102 // current rotation if it matches |lock_orientation|. Otherwise locks to a | |
103 // matching rotation. | |
104 void LockToRotationMatchingOrientation( | |
105 blink::WebScreenOrientationLockType lock_orientation); | |
106 | |
107 // Detect screen rotation from |lid| accelerometer and automatically rotate | |
108 // screen. | |
109 void HandleScreenRotation(const gfx::Vector3dF& lid); | |
110 | |
111 // Checks DisplayManager for registered rotation lock, and rotation, | |
112 // preferences. These are then applied. | |
113 void LoadDisplayRotationProperties(); | |
114 | |
115 // The window that has applied the current lock. No other window can apply a | |
116 // lock until the current window unlocks rotation. | |
117 aura::Window* locking_window_; | |
118 | |
119 // The orientation of the display when at a rotation of 0. | |
120 blink::WebScreenOrientationLockType natural_orientation_; | |
121 | |
122 // True when changes being applied cause OnDisplayConfigurationChanged() to be | |
123 // called, and for which these changes should be ignored. | |
124 bool ignore_display_configuration_updates_; | |
125 | |
126 // When true then accelerometer updates should not rotate the display. | |
127 bool rotation_locked_; | |
128 | |
129 // The rotation of the display set by the user. This rotation will be | |
130 // restored upon exiting maximize mode. | |
131 gfx::Display::Rotation user_rotation_; | |
132 | |
133 // The current rotation set by ScreenOrientationController for the internal | |
134 // display. | |
135 gfx::Display::Rotation current_rotation_; | |
136 | |
137 // Rotation Lock observers. | |
138 ObserverList<Observer> observers_; | |
139 | |
140 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); | |
141 }; | |
142 | |
143 } // namespace ash | |
144 | |
145 #endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ | |
OLD | NEW |