This change renames ScreenOrientationDelegate to ScreenOrientationController to refle...
[chromium-blink-merge.git] / ash / content / display / screen_orientation_controller_chromeos.h
blob362e131134c4623a847b76a3bf909de2e92052d1
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.
5 #ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_
6 #define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_
8 #include "ash/ash_export.h"
9 #include "ash/display/display_controller.h"
10 #include "ash/shell_observer.h"
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "chromeos/accelerometer/accelerometer_reader.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"
18 namespace aura {
19 class Window;
22 namespace content {
23 class WebContents;
26 namespace ash {
28 // Implements ChromeOS specific functionality for ScreenOrientationProvider.
29 class ASH_EXPORT ScreenOrientationController
30 : public chromeos::AccelerometerReader::Observer,
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) {}
42 protected:
43 virtual ~Observer() {}
46 ScreenOrientationController();
47 ~ScreenOrientationController() override;
49 // Add/Remove observers.
50 void AddObserver(Observer* observer);
51 void RemoveObserver(Observer* observer);
53 bool ignore_display_configuration_updates() const {
54 return ignore_display_configuration_updates_;
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_; }
61 // If |rotation_locked| future accelerometer updates should not change the
62 // display rotation.
63 void SetRotationLocked(bool rotation_locked);
65 // Sets the display rotation and suppresses display notifications.
66 void SetDisplayRotation(gfx::Display::Rotation rotation);
68 // chromeos::AccelerometerReader::Observer:
69 void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override;
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;
78 // DisplayController::Observer:
79 void OnDisplayConfigurationChanged() override;
81 // ShellObserver:
82 void OnMaximizeModeStarted() override;
83 void OnMaximizeModeEnded() override;
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);
91 // Locks rotation to the angle matching the primary orientation for
92 // |lock_orientation|.
93 void LockRotationToPrimaryOrientation(
94 blink::WebScreenOrientationLockType lock_orientation);
96 // Locks rotation to the angle matching the secondary orientation for
97 // |lock_orientation|.
98 void LockRotationToSecondaryOrientation(
99 blink::WebScreenOrientationLockType lock_orientation);
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);
107 // Detect screen rotation from |lid| accelerometer and automatically rotate
108 // screen.
109 void HandleScreenRotation(const gfx::Vector3dF& lid);
111 // Checks DisplayManager for registered rotation lock, and rotation,
112 // preferences. These are then applied.
113 void LoadDisplayRotationProperties();
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_;
119 // The orientation of the display when at a rotation of 0.
120 blink::WebScreenOrientationLockType natural_orientation_;
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_;
126 // When true then accelerometer updates should not rotate the display.
127 bool rotation_locked_;
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_;
133 // The current rotation set by ScreenOrientationController for the internal
134 // display.
135 gfx::Display::Rotation current_rotation_;
137 // Rotation Lock observers.
138 ObserverList<Observer> observers_;
140 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController);
143 } // namespace ash
145 #endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_