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 #ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ | 5 #ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
6 #define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ | 6 #define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | |
9 #include "ash/display/display_controller.h" | |
10 #include "ash/shell_observer.h" | |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/observer_list.h" | |
13 #include "chromeos/accelerometer/accelerometer_reader.h" | |
9 #include "content/public/browser/screen_orientation_delegate.h" | 14 #include "content/public/browser/screen_orientation_delegate.h" |
10 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 15 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" |
16 #include "ui/gfx/display.h" | |
11 | 17 |
12 namespace aura { | 18 namespace aura { |
13 class Window; | 19 class Window; |
14 } | 20 } |
15 | 21 |
16 namespace content { | 22 namespace content { |
17 class WebContents; | 23 class WebContents; |
18 } | 24 } |
19 | 25 |
20 namespace ash { | 26 namespace ash { |
21 | 27 |
22 // Implements ChromeOS specific functionality for ScreenOrientationProvider. | 28 // Implements ChromeOS specific functionality for ScreenOrientationProvider. |
23 class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { | 29 class ASH_EXPORT ScreenOrientationController |
30 : public chromeos::AccelerometerReader::Observer, | |
31 public content::ScreenOrientationDelegate, | |
32 public DisplayController::Observer, | |
33 public ShellObserver { | |
24 public: | 34 public: |
25 ScreenOrientationDelegate(); | 35 // Observer that reports changes to the state of ScreenOrientationProvider's |
26 virtual ~ScreenOrientationDelegate(); | 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(); | |
oshima
2015/01/09 21:23:55
nit: override
jonross
2015/01/12 14:46:49
Done.
| |
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() const { return rotation_locked_; } | |
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 // chromeos::AccelerometerReader::Observer: | |
69 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; | |
27 | 70 |
28 // content::ScreenOrientationDelegate: | 71 // content::ScreenOrientationDelegate: |
29 bool FullScreenRequired(content::WebContents* web_contents) override; | 72 bool FullScreenRequired(content::WebContents* web_contents) override; |
30 void Lock(content::WebContents* web_contents, | 73 void Lock(content::WebContents* web_contents, |
31 blink::WebScreenOrientationLockType lock_orientation) override; | 74 blink::WebScreenOrientationLockType lock_orientation) override; |
32 bool ScreenOrientationProviderSupported() override; | 75 bool ScreenOrientationProviderSupported() override; |
33 void Unlock(content::WebContents* web_contents) override; | 76 void Unlock(content::WebContents* web_contents) override; |
34 | 77 |
78 // DisplayController::Observer: | |
79 void OnDisplayConfigurationChanged() override; | |
80 | |
81 // ShellObserver: | |
82 void OnMaximizeModeStarted() override; | |
83 void OnMaximizeModeEnded() override; | |
84 | |
35 private: | 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 | |
36 // Locks rotation to the angle matching the primary orientation for | 91 // Locks rotation to the angle matching the primary orientation for |
37 // |lock_orientation|. | 92 // |lock_orientation|. |
38 void LockRotationToPrimaryOrientation( | 93 void LockRotationToPrimaryOrientation( |
39 blink::WebScreenOrientationLockType lock_orientation); | 94 blink::WebScreenOrientationLockType lock_orientation); |
40 | 95 |
41 // Locks rotation to the angle matching the secondary orientation for | 96 // Locks rotation to the angle matching the secondary orientation for |
42 // |lock_orientation|. | 97 // |lock_orientation|. |
43 void LockRotationToSecondaryOrientation( | 98 void LockRotationToSecondaryOrientation( |
44 blink::WebScreenOrientationLockType lock_orientation); | 99 blink::WebScreenOrientationLockType lock_orientation); |
45 | 100 |
46 // For orientations that do not specify primary or secondary, locks to the | 101 // For orientations that do not specify primary or secondary, locks to the |
47 // current rotation if it matches |lock_orientation|. Otherwise locks to a | 102 // current rotation if it matches |lock_orientation|. Otherwise locks to a |
48 // matching rotation. | 103 // matching rotation. |
49 void LockToRotationMatchingOrientation( | 104 void LockToRotationMatchingOrientation( |
50 blink::WebScreenOrientationLockType lock_orientation); | 105 blink::WebScreenOrientationLockType lock_orientation); |
51 | 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 | |
52 // The window that has applied the current lock. No other window can apply a | 115 // The window that has applied the current lock. No other window can apply a |
53 // lock until the current window unlocks rotation. | 116 // lock until the current window unlocks rotation. |
54 aura::Window* locking_window_; | 117 aura::Window* locking_window_; |
55 | 118 |
56 // The orientation of the display when at a rotation of 0. | 119 // The orientation of the display when at a rotation of 0. |
57 blink::WebScreenOrientationLockType natural_orientation_; | 120 blink::WebScreenOrientationLockType natural_orientation_; |
58 | 121 |
59 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegate); | 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); | |
60 }; | 141 }; |
61 | 142 |
62 } // namespace ash | 143 } // namespace ash |
63 | 144 |
64 #endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ | 145 #endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
OLD | NEW |