Skip to content

Move the entry point of the API to the window.navigator interface. #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Among the values that the device-posture query can take are:
/*for a monitor scenario*/
@media (device-posture: flat) and (orientation: portrait) { ... }
```
### New JS object in `window.screen`: `posture`
### New JS object in `window.navigator`: `devicePosture`

The Window property screen returns a reference to the screen object associated with the window. It already houses a similar property [`orientation`](https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation) that itself has a value for an [angle](https://w3c.github.io/screen-orientation/#idl-index).
The Navigator property of Window [navigator](https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object) should host device capabilities and system states.

#### Proposed Object
```javascript
Expand Down
22 changes: 11 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ <h2>
provide a different layout for it depending on the posture state in which the device is being used.
</p>
</section>
<section data-dfn-for="Screen">
<section data-dfn-for="Navigator">
<h2>
Extensions to the `Screen` interface
Extensions to the `Navigator` interface
</h2>
<p>
The [[cssom-view]] specification defines the <dfn>Screen</dfn> interface,
The [[HTML]] specification defines the <dfn>Navigator</dfn> interface,
which this specification extends:
</p>
<pre class="idl">
[SecureContext]
partial interface Screen {
[SameObject] readonly attribute DevicePosture posture;
[SecureContext, Exposed=(Window)]
partial interface Navigator {
[SameObject] readonly attribute DevicePosture devicePosture;
};
</pre>
</section>
Expand Down Expand Up @@ -508,7 +508,7 @@ <h2>
</li>
<li>
<a>Fire an event</a> named `change` at |document|'s
{{Screen.posture}} object.
{{Window.navigator.devicePosture}} object.
</li>
</ol>
</li>
Expand All @@ -535,14 +535,14 @@ <h2>
<ol>
<li>
<a>Fire an event</a> named `change` at the |document|'s
{{Screen.posture}} object.
{{Window.navigator.devicePosture}} object.
</li>
</ol>
</li>
</ol>
<div class="note">
<p>
Developers need to be aware that a {{Screen.posture}} object
Developers need to be aware that a {{Window.navigator.devicePosture}} object
from a <a>document</a> that is not visible, as per
[[PAGE-VISIBILITY]], will not receive an orientation change event.
This is to prevent unnecessary changes to layout, etc. in the
Expand Down Expand Up @@ -640,8 +640,8 @@ <h2>
<h3>Example 1: Posture data</h3>
<p>This is a simple use case of the <a>posture</a> being printed on the console. </p>
<pre class="example js" title="React to poster change">
screen.posture.addEventListener("change", () => {
console.log(`The current posture is: ${screen.posture.type}!`);
navigator.devicePosture.addEventListener("change", () => {
console.log(`The current posture is: ${navigator.devicePosture.type}!`);
})
</pre>
<h3>Example 2: device-posture</h3>
Expand Down