Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
The Screen Orientation API's goal is to provide an interface for web applications to be able to read the screen orientation state, to be informed when this state changes and to be able to lock the screen orientation to a specific state.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document was published by the Web Applications Working Group as a Working Draft.
This document is intended to become a W3C Recommendation.
If you wish to make comments regarding this document, please send them to
public-webapps@w3.org
(subscribe,
archives) with [screen-orient]
at the start of the subject header.
A bug list for this document is available.
All feedback is welcome.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This section is non-normative.
The Screen Orientation API provides an interface for web applications to access and lock the user's device's screen orientation state.
This examples is an application that shows the current screen orientation to the user every time the screen orientation state changes:
<!DOCTYPE html> <html> <script> function show() { alert("Screen orientation state is " + screen.orientation); } screen.addEventListener("orientationchange", show, false); show(); </script> </html>
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to expose the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL].
The EventHandler interface represents a callback used for event handlers as defined in [HTML5].
The concepts queue a task and fire a simple event are defined in [HTML5].
The terms event handlers and event handler event types are defined in [HTML5].
The concepts of browsing context and active document are defined in [HTML5].
The current orientation should be an orientation amongst those values:
portrait-primary
, if the orientation is in the primary portrait mode;portrait-secondary
, if the orientation is in the secondary portrait mode;landscape-primary
, if the orientation is in the primary landscape mode;landscape-secondary
, if the orientation is in the secondary landscape mode.
The notion of primary and secondary depends on the device and the
platform. Some devices are in portrait mode when the user holds the
device in the normal orientation, other devices are in landscape
mode when the user holds the device in its normal orientation. For
devices whose normal orientation is a landscape mode, that normal
orientation should be represented as landscape-primary
.
For devices whose normal orientation is a portrait mode, that normal
orientation should be represented as portrait-primary
.
In both if the device is in landscape-primary
and is
rotated 90 degrees clockwise, that should be represented as
portrait-primary
.
The allowed orientations should be orientations amongst those values:
portrait-primary
, if the orientation is in the primary portrait mode;portrait-secondary
, if the orientation is in the secondary portrait mode;landscape-primary
, if the orientation is in the primary landscape mode;landscape-secondary
, if the orientation is in the secondary landscape mode.portrait
, value that represents portrait-primary
and portrait-secondary
cases;
landscape
, value that represents landscape-primary
and landscape-secondary
cases;
The action to lock the orientation consists of forcing the rendering of the current browsing context
to be shown as if the screen was oriented in one or many of the current orientation.
If the lock is done on only one orientation, the screen orientation should stay on the given orientation and never change
until the screen orientation is unlocked. Otherwise, the screen orientation should be able to change from an orientation
to another as long as the orientations are amongst an orientation it has been locked to.
A set of orientations is said to be a supported orientation set if the user agent can lock the orientation to that set.
Screen
InterfaceScreen
interface [CSSOM-VIEW], which this specification extends:
partial interface Screen {
readonly attribute DOMString orientation;
boolean lockOrientation (DOMString orientation);
boolean lockOrientation (sequence<DOMString> orientations);
void unlockOrientation ();
[TreatNonCallableAsNull]
attribute EventHandler onorientationchange;
};
onorientationchange
of type EventHandler, nullableorientation
of type DOMString, readonlyThe user agent must return the value representing the orientation of the screen.
The returned orientation must be in the current orientation list.
lockOrientation
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
orientation | DOMString | ✘ | ✘ |
boolean
lockOrientation
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
orientations | sequence<DOMString> | ✘ | ✘ |
boolean
unlockOrientation
The user agent must disable the current lock applied on the screen with lockOrientation
.
If the current browsing context has a default orientation, the screen orientation should revert to that.
Otherwise, the screen orientation should revert to any value the user agent believes appropriate.
When the unlock is done, if the orientation actually changed, the user agent must fire a simple event
named orientationnchange
at the Screen
object.
void
When the screen orientation changes in the current browsing context, the user agent must queue a task
which updates the orientation
attribute and fire a simple event named orientationchange
at the Screen
object.
For example, that means if an application A is locked to landscape-primary
and application B is locked to portrait-primary
, switching from
application A to B or B to A will not fire an orientationchange
event because both applications will keep the orientation they had.
However, locking the orientation can fire an orientationchange
if the
orientation had to be changed to satisfy the lock requirements.
The steps for locking the screen orientation are the following:
orientationnchange
at the Screen
object.This section is non-normative.
This specification doesn't intend to specify a declarative orientation locking. However, other specifications specify ways to do that.
The Web Application Manifest Format and Management APIs [WEBAPPS-MANIFEST-API] specifies a way to declare a default orientation
for a web application inside the manifest file.
That specification tries to follow this specification regarding orientation keywords.
The CSS Device Adaptation specification [CSS-ADAPTATION] specifies a way to declare a default orientation for a web page.
That specification isn't yet in sync with this specification.
The following are the event handlers (and their corresponding
event handler event types) that must be supported as attributes
by the Screen
object:
event handler | event handler event type |
---|---|
onorientationchange |
orientationchange |