Chromium Code Reviews| Index: ash/content/display/screen_orientation_controller_chromeos.h |
| diff --git a/ash/content/display/screen_orientation_delegate_chromeos.h b/ash/content/display/screen_orientation_controller_chromeos.h |
| similarity index 36% |
| rename from ash/content/display/screen_orientation_delegate_chromeos.h |
| rename to ash/content/display/screen_orientation_controller_chromeos.h |
| index d1f445572d3e1580adfb905245f3fa142f832cc8..2a063ab7224f6dec9e4b9a957ed266a48aef2954 100644 |
| --- a/ash/content/display/screen_orientation_delegate_chromeos.h |
| +++ b/ash/content/display/screen_orientation_controller_chromeos.h |
| @@ -2,12 +2,18 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ |
| -#define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ |
| +#ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| +#define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |
| +#include "ash/ash_export.h" |
| +#include "ash/display/display_controller.h" |
| +#include "ash/shell_observer.h" |
| #include "base/macros.h" |
| +#include "base/observer_list.h" |
| +#include "chromeos/accelerometer/accelerometer_reader.h" |
| #include "content/public/browser/screen_orientation_delegate.h" |
| #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" |
| +#include "ui/gfx/display.h" |
| namespace aura { |
| class Window; |
| @@ -20,10 +26,47 @@ class WebContents; |
| namespace ash { |
| // Implements ChromeOS specific functionality for ScreenOrientationProvider. |
| -class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { |
| +class ASH_EXPORT ScreenOrientationController |
| + : public chromeos::AccelerometerReader::Observer, |
| + public content::ScreenOrientationDelegate, |
| + public DisplayController::Observer, |
| + public ShellObserver { |
| public: |
| - ScreenOrientationDelegate(); |
| - virtual ~ScreenOrientationDelegate(); |
| + // Observer that reports changes to the state of ScreenOrientationProvider's |
| + // rotation lock. |
| + class Observer { |
| + public: |
| + // Invoked when rotation is locked or unlocked. |
| + virtual void OnRotationLockChanged(bool rotation_locked) {} |
| + |
| + protected: |
| + virtual ~Observer() {} |
| + }; |
| + |
| + ScreenOrientationController(); |
| + virtual ~ScreenOrientationController(); |
|
oshima
2015/01/09 21:23:55
nit: override
jonross
2015/01/12 14:46:49
Done.
|
| + |
| + // Add/Remove observers. |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| + bool ignore_display_configuration_updates() const { |
| + return ignore_display_configuration_updates_; |
| + } |
| + |
| + // True if |rotation_lock_| has been set and accelerometer updates should not |
| + // rotate the display. |
| + bool rotation_locked() const { return rotation_locked_; } |
| + |
| + // If |rotation_locked| future accelerometer updates should not change the |
| + // display rotation. |
| + void SetRotationLocked(bool rotation_locked); |
| + |
| + // Sets the display rotation and suppresses display notifications. |
| + void SetDisplayRotation(gfx::Display::Rotation rotation); |
| + |
| + // chromeos::AccelerometerReader::Observer: |
| + void OnAccelerometerUpdated(const ui::AccelerometerUpdate& update) override; |
| // content::ScreenOrientationDelegate: |
| bool FullScreenRequired(content::WebContents* web_contents) override; |
| @@ -32,7 +75,19 @@ class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { |
| bool ScreenOrientationProviderSupported() override; |
| void Unlock(content::WebContents* web_contents) override; |
| + // DisplayController::Observer: |
| + void OnDisplayConfigurationChanged() override; |
| + |
| + // ShellObserver: |
| + void OnMaximizeModeStarted() override; |
| + void OnMaximizeModeEnded() override; |
| + |
| private: |
| + // Sets the display rotation to |rotation|. Future accelerometer updates |
| + // should not be used to change the rotation. SetRotationLocked(false) removes |
| + // the rotation lock. |
| + void LockRotation(gfx::Display::Rotation rotation); |
| + |
| // Locks rotation to the angle matching the primary orientation for |
| // |lock_orientation|. |
| void LockRotationToPrimaryOrientation( |
| @@ -49,6 +104,14 @@ class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { |
| void LockToRotationMatchingOrientation( |
| blink::WebScreenOrientationLockType lock_orientation); |
| + // Detect screen rotation from |lid| accelerometer and automatically rotate |
| + // screen. |
| + void HandleScreenRotation(const gfx::Vector3dF& lid); |
| + |
| + // Checks DisplayManager for registered rotation lock, and rotation, |
| + // preferences. These are then applied. |
| + void LoadDisplayRotationProperties(); |
| + |
| // The window that has applied the current lock. No other window can apply a |
| // lock until the current window unlocks rotation. |
| aura::Window* locking_window_; |
| @@ -56,9 +119,27 @@ class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { |
| // The orientation of the display when at a rotation of 0. |
| blink::WebScreenOrientationLockType natural_orientation_; |
| - DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegate); |
| + // True when changes being applied cause OnDisplayConfigurationChanged() to be |
| + // called, and for which these changes should be ignored. |
| + bool ignore_display_configuration_updates_; |
| + |
| + // When true then accelerometer updates should not rotate the display. |
| + bool rotation_locked_; |
| + |
| + // The rotation of the display set by the user. This rotation will be |
| + // restored upon exiting maximize mode. |
| + gfx::Display::Rotation user_rotation_; |
| + |
| + // The current rotation set by ScreenOrientationController for the internal |
| + // display. |
| + gfx::Display::Rotation current_rotation_; |
| + |
| + // Rotation Lock observers. |
| + ObserverList<Observer> observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScreenOrientationController); |
| }; |
| } // namespace ash |
| -#endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ |
| +#endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_CONTROLLER_CHROMEOS_H_ |