ScreenOrientationProvider Class
The screen of the device (https://w3c.github.io/screen-orientation/#the-current-screen-orientation-type-and-angle), read by screen.orientation and locked by screen.orientation.lock(), of the browsing contexts that share a BrowsingContextOptions (ScreenOrientationOptions.Provider). The default implementation simulates a screen that rotates to the orientation of each lock: set ScreenOrientationProvider.DeviceOrientation to simulate the user rotating the device. Override ScreenOrientationProvider.TryLock to lock the screen of the operating system, and call ScreenOrientationProvider.OnOrientationChanged when the orientation changes.
public class ScreenOrientationProviderRemarks
A provider can be shared by several browsing contexts, and used from any thread.
Constructors
| Name | Description |
|---|---|
| ScreenOrientationProvider() | Initializes a new instance of the ScreenOrientationProvider class, for a screen whose natural orientation is OrientationType.LandscapePrimary. |
| ScreenOrientationProvider(OrientationType) | Initializes a new instance of the ScreenOrientationProvider class. |
ScreenOrientationProvider overloads
ScreenOrientationProvider()
ScreenOrientation.csInitializes a new instance of the ScreenOrientationProvider class, for a screen whose natural orientation is OrientationType.LandscapePrimary.
public ScreenOrientationProvider()ScreenOrientationProvider(OrientationType)
ScreenOrientation.csInitializes a new instance of the ScreenOrientationProvider class.
public ScreenOrientationProvider(OrientationType naturalOrientation)Parameters
naturalOrientationOrientationType- The natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural), from which the angles are measured:
OrientationType.PortraitPrimaryfor a phone,OrientationType.LandscapePrimaryfor a tablet or a computer.
Exceptions
ArgumentOutOfRangeExceptionnaturalOrientationis not a primary orientation.
Properties
| Name | Description |
|---|---|
| ActiveLock | Gets the active orientation lock of the screen (https://w3c.github.io/screen-orientation/#dfn-active-orientation-lock), or null when it is unlocked. |
| CurrentAngle | Gets the current orientation angle of the screen in degrees (https://w3c.github.io/screen-orientation/#dfn-current-orientation-angle), from the screen orientation values lists. |
| CurrentType | Gets the current orientation type of the screen (https://w3c.github.io/screen-orientation/#dfn-current-orientation-type): the type of the orientation override when there is one (ScreenOrientationProvider.SetOrientationOverride). |
| DeviceOrientation | Gets or sets the orientation of the device, as the user holds it: the orientation of the screen when it is not locked (or locked to OrientationLockType.Any). It is the natural orientation by default. Setting it rotates the screen, and the documents fire their change events. |
| NaturalOrientation | Gets the natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural): the one of the orientation override when there is one (ScreenOrientationProvider.SetOrientationOverride). |
ActiveLock
ScreenOrientation.csGets the active orientation lock of the screen (https://w3c.github.io/screen-orientation/#dfn-active-orientation-lock), or null when it is unlocked.
public OrientationLockType? ActiveLock { get; }Property value
CurrentAngle
ScreenOrientation.csCurrentType
ScreenOrientation.csGets the current orientation type of the screen (https://w3c.github.io/screen-orientation/#dfn-current-orientation-type): the type of the orientation override when there is one (ScreenOrientationProvider.SetOrientationOverride).
public OrientationType CurrentType { get; }Property value
DeviceOrientation
ScreenOrientation.csGets or sets the orientation of the device, as the user holds it: the orientation of the screen when it is not locked (or locked to OrientationLockType.Any). It is the natural orientation by default. Setting it rotates the screen, and the documents fire their change events.
public OrientationType DeviceOrientation { get; set; }Property value
NaturalOrientation
ScreenOrientation.csGets the natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural): the one of the orientation override when there is one (ScreenOrientationProvider.SetOrientationOverride).
public OrientationType NaturalOrientation { get; }Property value
Methods
| Name | Description |
|---|---|
| ClearOrientationOverride() | Removes the orientation override of ScreenOrientationProvider.SetOrientationOverride: the screen gets its own orientation back. |
| IsSupported(OrientationLockType) | Returns whether the screen can be locked to an orientation (the lock request is rejected with a NotSupportedError otherwise). The default implementation returns true. It is called on the thread of an event loop, and must not block it. |
| OnOrientationChanged() | Raises ScreenOrientationProvider.OrientationChanged, then runs the screen orientation change steps (https://w3c.github.io/screen-orientation/#dfn-screen-orientation-change-steps) of the documents: they read ScreenOrientationProvider.CurrentType and ScreenOrientationProvider.CurrentAngle, and fire their change events. It can be called from any thread. |
| SetOrientationOverride(OrientationType, OrientationType) | Emulates the orientation of the screen, as the emulation.setScreenOrientationOverride command of WebDriver BiDi (https://w3c.github.io/webdriver-bidi/#command-emulation-setScreenOrientationOverride): the screen has the natural orientation and the current orientation type of the override, whatever the orientation of the device and the active orientation lock, until ScreenOrientationProvider.ClearOrientationOverride. The documents fire their change events. |
| TryLock(OrientationLockType?) | Attempts to lock the screen to an orientation, or to unlock it (https://w3c.github.io/screen-orientation/#dfn-lock-the-screen-orientation), and returns false when the platform refuses (the lock request is rejected with a NotSupportedError). The default implementation returns true: the screen rotates to the orientation of the lock (see ScreenOrientationProvider.CurrentType). It is called on the thread of an event loop, and must not block it. |
ClearOrientationOverride()
ScreenOrientation.csRemoves the orientation override of ScreenOrientationProvider.SetOrientationOverride: the screen gets its own orientation back.
public void ClearOrientationOverride()IsSupported(OrientationLockType)
ScreenOrientation.csReturns whether the screen can be locked to an orientation (the lock request is rejected with a NotSupportedError otherwise). The default implementation returns true. It is called on the thread of an event loop, and must not block it.
public virtual bool IsSupported(OrientationLockType orientation)OnOrientationChanged()
ScreenOrientation.csRaises ScreenOrientationProvider.OrientationChanged, then runs the screen orientation change steps (https://w3c.github.io/screen-orientation/#dfn-screen-orientation-change-steps) of the documents: they read ScreenOrientationProvider.CurrentType and ScreenOrientationProvider.CurrentAngle, and fire their change events. It can be called from any thread.
protected void OnOrientationChanged()SetOrientationOverride(OrientationType, OrientationType)
ScreenOrientation.csEmulates the orientation of the screen, as the emulation.setScreenOrientationOverride command of WebDriver BiDi (https://w3c.github.io/webdriver-bidi/#command-emulation-setScreenOrientationOverride): the screen has the natural orientation and the current orientation type of the override, whatever the orientation of the device and the active orientation lock, until ScreenOrientationProvider.ClearOrientationOverride. The documents fire their change events.
public void SetOrientationOverride(OrientationType naturalOrientation, OrientationType type)Parameters
naturalOrientationOrientationType- The natural orientation of the emulated screen:
OrientationType.PortraitPrimaryorOrientationType.LandscapePrimary. typeOrientationType- The current orientation type of the emulated screen.
Exceptions
ArgumentOutOfRangeExceptionnaturalOrientationis not a primary orientation.
TryLock(OrientationLockType?)
ScreenOrientation.csAttempts to lock the screen to an orientation, or to unlock it (https://w3c.github.io/screen-orientation/#dfn-lock-the-screen-orientation), and returns false when the platform refuses (the lock request is rejected with a NotSupportedError). The default implementation returns true: the screen rotates to the orientation of the lock (see ScreenOrientationProvider.CurrentType). It is called on the thread of an event loop, and must not block it.
protected virtual bool TryLock(OrientationLockType? orientation)Events
| Name | Description |
|---|---|
| OrientationChanged | Raised when the orientation of the screen changes (ScreenOrientationProvider.OnOrientationChanged). |
OrientationChanged
Raised when the orientation of the screen changes (ScreenOrientationProvider.OnOrientationChanged).
public event EventHandler? OrientationChanged