Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / ash / content / display / screen_orientation_controller_chromeos.h
blobaa45734a24d31fad96436bc201a0d255fefbb27c
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 <map>
10 #include "ash/ash_export.h"
11 #include "ash/display/display_controller.h"
12 #include "ash/shell_observer.h"
13 #include "base/macros.h"
14 #include "base/observer_list.h"
15 #include "chromeos/accelerometer/accelerometer_reader.h"
16 #include "chromeos/accelerometer/accelerometer_types.h"
17 #include "content/public/browser/screen_orientation_delegate.h"
18 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
19 #include "ui/aura/window_observer.h"
20 #include "ui/gfx/display.h"
21 #include "ui/wm/public/activation_change_observer.h"
23 namespace aura {
24 class Window;
27 namespace content {
28 class WebContents;
31 namespace ash {
33 // Implements ChromeOS specific functionality for ScreenOrientationProvider.
34 class ASH_EXPORT ScreenOrientationController
35 : public aura::client::ActivationChangeObserver,
36 public aura::WindowObserver,
37 public chromeos::AccelerometerReader::Observer,
38 public content::ScreenOrientationDelegate,
39 public DisplayController::Observer,
40 public ShellObserver {
41 public:
42 // Observer that reports changes to the state of ScreenOrientationProvider's
43 // rotation lock.
44 class Observer {
45 public:
46 // Invoked when rotation is locked or unlocked.
47 virtual void OnRotationLockChanged(bool rotation_locked) {}
49 protected:
50 virtual ~Observer() {}
53 ScreenOrientationController();
54 ~ScreenOrientationController() override;
56 // Add/Remove observers.
57 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer);
60 bool ignore_display_configuration_updates() const {
61 return ignore_display_configuration_updates_;
64 // True if |rotation_lock_| has been set and accelerometer updates should not
65 // rotate the display.
66 bool rotation_locked() const { return rotation_locked_; }
68 // If |rotation_locked| future accelerometer updates should not change the
69 // display rotation.
70 void SetRotationLocked(bool rotation_locked);
72 // Sets the display rotation and suppresses display notifications.
73 void SetDisplayRotation(gfx::Display::Rotation rotation);
75 // aura::client::ActivationChangeObserver:
76 void OnWindowActivated(aura::Window* gained_active,
77 aura::Window* lost_active) override;
79 // aura::WindowObserver:
80 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
81 void OnWindowDestroying(aura::Window* window) override;
83 // chromeos::AccelerometerReader::Observer:
84 void OnAccelerometerUpdated(
85 scoped_refptr<const chromeos::AccelerometerUpdate> update) override;
87 // content::ScreenOrientationDelegate:
88 bool FullScreenRequired(content::WebContents* web_contents) override;
89 void Lock(content::WebContents* web_contents,
90 blink::WebScreenOrientationLockType lock_orientation) override;
91 bool ScreenOrientationProviderSupported() override;
92 void Unlock(content::WebContents* web_contents) override;
94 // DisplayController::Observer:
95 void OnDisplayConfigurationChanged() override;
97 // ShellObserver:
98 void OnMaximizeModeStarted() override;
99 void OnMaximizeModeEnded() override;
101 private:
102 // Sets the display rotation to |rotation|. Future accelerometer updates
103 // should not be used to change the rotation. SetRotationLocked(false) removes
104 // the rotation lock.
105 void LockRotation(gfx::Display::Rotation rotation);
107 // Sets the display rotation based on |lock_orientation|. Future accelerometer
108 // updates should not be used to change the rotation. SetRotationLocked(false)
109 // removes the rotation lock.
110 void LockRotationToOrientation(
111 blink::WebScreenOrientationLockType lock_orientation);
113 // Locks rotation to the angle matching the primary orientation for
114 // |lock_orientation|.
115 void LockRotationToPrimaryOrientation(
116 blink::WebScreenOrientationLockType lock_orientation);
118 // Locks rotation to the angle matching the secondary orientation for
119 // |lock_orientation|.
120 void LockRotationToSecondaryOrientation(
121 blink::WebScreenOrientationLockType lock_orientation);
123 // For orientations that do not specify primary or secondary, locks to the
124 // current rotation if it matches |lock_orientation|. Otherwise locks to a
125 // matching rotation.
126 void LockToRotationMatchingOrientation(
127 blink::WebScreenOrientationLockType lock_orientation);
129 // Detect screen rotation from |lid| accelerometer and automatically rotate
130 // screen.
131 void HandleScreenRotation(const chromeos::AccelerometerReading& lid);
133 // Checks DisplayManager for registered rotation lock, and rotation,
134 // preferences. These are then applied.
135 void LoadDisplayRotationProperties();
137 // Determines the rotation lock, and orientation, for the currently active
138 // window, and applies it. If there is none, rotation lock will be removed.
139 void ApplyLockForActiveWindow();
141 // Removes a window and its locking preference.
142 void RemoveLockingWindow(aura::Window* window);
144 // Both |blink::WebScreenOrientationLockLandscape| and
145 // |blink::WebScreenOrientationLockPortrait| allow for rotation between the
146 // two angles of the same screen orientation
147 // (http://www.w3.org/TR/screen-orientation/). Returns true if |rotation| is
148 // supported for the current |rotation_locked_orientation_|.
149 bool IsRotationAllowedInLockedState(gfx::Display::Rotation rotation);
151 // Certain orientation locks allow for rotation between the two angles of the
152 // same screen orientation. Returns true if |rotation_locked_orientation_|
153 // allows rotation.
154 bool CanRotateInLockedState();
156 // The orientation of the display when at a rotation of 0.
157 blink::WebScreenOrientationLockType natural_orientation_;
159 // True when changes being applied cause OnDisplayConfigurationChanged() to be
160 // called, and for which these changes should be ignored.
161 bool ignore_display_configuration_updates_;
163 // When true then accelerometer updates should not rotate the display.
164 bool rotation_locked_;
166 // The orientation to which the current |rotation_locked_| was applied.
167 blink::WebScreenOrientationLockType rotation_locked_orientation_;
169 // The rotation of the display set by the user. This rotation will be
170 // restored upon exiting maximize mode.
171 gfx::Display::Rotation user_rotation_;
173 // The current rotation set by ScreenOrientationController for the internal
174 // display.
175 gfx::Display::Rotation current_rotation_;
177 // Rotation Lock observers.
178 ObserverList<Observer> observers_;
180 // Tracks all windows that have requested a lock, as well as the requested
181 // orientation.
182 std::map<aura::Window*, blink::WebScreenOrientationLockType> locking_windows_;
184 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController);
187 } // namespace ash
189 #endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_