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 ScreenOrientationProvider

Remarks

A provider can be shared by several browsing contexts, and used from any thread.

Constructors

NameDescription
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.cs

Initializes a new instance of the ScreenOrientationProvider class, for a screen whose natural orientation is OrientationType.LandscapePrimary.

public ScreenOrientationProvider()

ScreenOrientationProvider(OrientationType)

ScreenOrientation.cs

Initializes a new instance of the ScreenOrientationProvider class.

public ScreenOrientationProvider(OrientationType naturalOrientation)
Parameters
naturalOrientation OrientationType
The natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural), from which the angles are measured: OrientationType.PortraitPrimary for a phone, OrientationType.LandscapePrimary for a tablet or a computer.
Exceptions
ArgumentOutOfRangeException
naturalOrientation is not a primary orientation.

Properties

NameDescription
ActiveLockGets the active orientation lock of the screen (https://w3c.github.io/screen-orientation/#dfn-active-orientation-lock), or null when it is unlocked.
CurrentAngleGets 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.
CurrentTypeGets the current orientation type of the screen (https://w3c.github.io/screen-orientation/#dfn-current-orientation-type).
DeviceOrientationGets 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.
NaturalOrientationGets the natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural).

Gets 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

OrientationLockType?

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.

public ushort CurrentAngle { get; }

Property value

ushort

Gets the current orientation type of the screen (https://w3c.github.io/screen-orientation/#dfn-current-orientation-type).

public OrientationType CurrentType { get; }

Property value

OrientationType

DeviceOrientation

ScreenOrientation.cs

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.

public OrientationType DeviceOrientation { get; set; }

Property value

OrientationType

NaturalOrientation

ScreenOrientation.cs

Gets the natural orientation of the screen (https://w3c.github.io/screen-orientation/#dfn-natural).

public OrientationType NaturalOrientation { get; }

Property value

OrientationType

Methods

NameDescription
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.
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.

IsSupported(OrientationLockType)

ScreenOrientation.cs

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.

public virtual bool IsSupported(OrientationLockType orientation)

Parameters

orientation OrientationLockType
The orientation.

Returns

bool

OnOrientationChanged()

ScreenOrientation.cs

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.

protected void OnOrientationChanged()

TryLock(OrientationLockType?)

ScreenOrientation.cs

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.

protected virtual bool TryLock(OrientationLockType? orientation)

Parameters

orientation OrientationLockType?
The orientation, or null to unlock the screen.

Returns

bool

Events

NameDescription
OrientationChangedRaised when the orientation of the screen changes (ScreenOrientationProvider.OnOrientationChanged).

OrientationChanged

Raised when the orientation of the screen changes (ScreenOrientationProvider.OnOrientationChanged).

public event EventHandler? OrientationChanged