w3c / device-posture

Device Posture API
https://www.w3.org/TR/device-posture/
Other
33 stars 21 forks source link
favicon favicon

Device Posture API

Authors

Abstract

This document specifies an API that allows web applications to request and be notified of changes of the posture of a device.

Goals

The device posture is the physical position in which a device holds which may be derived from sensors in addition to the angle. New types of mobile devices are appearing that have some sort of capabilities that allow them to change their posture. The most common types of devices are the ones that can fold (their screen or around their screen), allowing them to physically alter their form factor. The main interest in knowing the posture of a device is to enable new user experiences with responsive design.

A lot of example of responsive designs can be found here.

Complementary existing proposals:

Before discussing the solution proposal - let's overview existing proposals that are relevant and applicable to the problem space. As matter of principle we should generally avoid creating redundant concepts if we can reuse existing platform APIs and capabilities.

Additionally, while not a solution in the same sense, a "[css-media-queries] Foldables support and enablement" issue discusses the problem space and outlines some details and touches upon outlined issues.

Proposals

New CSS media query: device-posture

We propose a media query that would resolve to a set of fixed postures. These postures consist of a number of predefined values that each encompass a physical state of the device.

Among the values that the device-posture query can take are:

The API is also flexible enough that we can add new postures if new devices come to the market.

Examples

/*using the device in a 'book' posture*/
@media (device-posture: folded) { ... }

New JS object in window.navigator: devicePosture

The Navigator property of Window navigator should host device capabilities and system states.

Proposed Object

DevicePosture : EventTarget {
  readonly attribute DevicePostureType type;
  attribute EventHandler onchange;
}

enum DevicePostureType {
  "folded",
  “...”,
}

Demos

https://github.com/foldable-devices/demos

Stakeholder Feedback

Mozilla Position: https://github.com/mozilla/standards-positions/issues/882

WebKit Position: https://github.com/WebKit/standards-positions/issues/328

Chrome Status Entry: https://chromestatus.com/feature/5185813744975872

References & Acknowledgements

Many thanks for valuable feedback and advice from:

'drawing of different postures'