Gecko:FullScreenAPI: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Requirements ==
== Requirements ==


* Scripts should be able to initiate and terminate fullscreen
* Scripts should be able to initiate and terminate full-screen
** Allows custom, in-page, discoverable UI to active fullscreen
** Allows custom, in-page, discoverable UI to active full-screen
* Arbitrary Web content should be visible fullscreen
* Arbitrary Web content should be visible full-screen
** <video>, <canvas>, multicolumn text, etc
** <video>, <canvas>, multicolumn text, etc
** Required for scripted video controls
** Required for scripted video controls
* Entering and exiting fullscreen must trigger events
* Entering and exiting full-screen must trigger events
** To allow scripted changes to content, e.g. resizing of canvas content
** To allow scripted changes to content, e.g. resizing of canvas content
* Scripts should be able to opt in to having alphanumeric keyboard input disabled during fullscreen
* Scripts should be able to opt in to having alphanumeric keyboard input disabled during full-screen
** Enables less restrictive anti-spoofing measures
** Enables less restrictive anti-spoofing measures
* Actual fullscreen transitions must be allowed to be asynchronous and entirely at the discretion of the UA
* Actual full-screen transitions must be allowed to be asynchronous and entirely at the discretion of the UA
** To enable passive notification/confirmation UI
** To enable passive notification/confirmation UI
** To enable a wide range of security measures to prevent spoofing or other abuse
** To enable a wide range of security measures to prevent spoofing or other abuse


* Making a single element fullscreen should be as simple as possible
* Making a single element full-screen should be as simple as possible


* Content in IFRAMEs should be able go fullscreen
* Content in IFRAMEs should be able go full-screen
** To enable "widgets" such as embedded videos to offer fullscreen UI
** To enable "widgets" such as embedded videos to offer full-screen UI


== Proposed Specification ==
== Proposed Specification ==


A Document can be in the "fullscreen state". What exactly this means is up to the UA, but typically it means that the Document covers most or all of the screen and some or all of the normal UA UI is not visible.
A Document can be in the "full-screen state". What exactly this means is up to the UA, but typically it means that the Document covers most or all of the screen and some or all of the normal UA UI is not visible.


It is possible for non-toplevel browsing contexts to have their Document in the fullscreen state. The parent browsing context of a browsing context with its Document in the fullscreen state must also have its Document in the fullscreen state.
It is possible for non-toplevel browsing contexts to have their Document in the full-screen state. The parent browsing context of a browsing context with its Document in the full-screen state must also have its Document in the full-screen state.


The user agent may transition a Document into or out of the fullscreen state at any time, whether or not script has requested it. User agents are encouraged to provide standard UI to exit the fullscreen state, for example if the user presses the Escape key.
The user agent may transition a Document into or out of the full-screen state at any time, whether or not script has requested it. User agents are encouraged to provide standard UI to exit the full-screen state, for example if the user presses the Escape key.


Toplevel browsing contexts can be in a "keys disabled" state. In this state,
Toplevel browsing contexts can be in a "keys disabled" state. In this state,
Line 33: Line 33:
* DOM_VK_SEMICOLON to DOM_VK_EQUALS, inclusive
* DOM_VK_SEMICOLON to DOM_VK_EQUALS, inclusive
* DOM_VK_MULTIPLY to DOM_VK_META, inclusive
* DOM_VK_MULTIPLY to DOM_VK_META, inclusive
Such events are not dispatched to any nodes in any document of the toplevel browsing context or descendant browsing contexts. This includes suppression of any internal key event processing that would insert text into form controls or editable content. The user agent might respond to such events by leaving fullscreen mode.
Such events are not dispatched to any nodes in any document of the toplevel browsing context or descendant browsing contexts. This includes suppression of any internal key event processing that would insert text into form controls or editable content. The user agent might respond to such events by leaving full-screen mode.


Each document has an optional "current fullscreen element".
Each document has an optional "current full-screen element".


New method of Document:
New method of Document:
Line 41: Line 41:
* void cancelFullScreen()
* void cancelFullScreen()


Requests that the UA exit fullscreen mode. The UA is not required to honor this, for example the UA might require that only a Document that last triggered fullscreen can cancel it.
Requests that the UA exit full-screen mode. The UA is not required to honor this, for example the UA might require that only a Document that last triggered full-screen can cancel it.


The current fullscreen element for the document is cleared.
The current full-screen element for the document is cleared.


New methods of Element:
New methods of Element:
Line 49: Line 49:
* void requestFullScreenWithKeys()
* void requestFullScreenWithKeys()


The current fullscreen element for the document is set to this element.
The current full-screen element for the document is set to this element.


Typically the user agent would react by transitioning the Document to the fullscreen state, or by presenting asynchronous confirmation UI and transitioning to the fullscreen state if/when the user responds affirmatively. However, the user agent is not required to do anything at all in response to requestFullScreen. The user agent's behavior is allowed to vary depending on whether requestFullScreen is called during a user event (e.g. a mouse click handler).
Typically the user agent would react by transitioning the Document to the full-screen state, or by presenting asynchronous confirmation UI and transitioning to the full-screen state if/when the user responds affirmatively. However, the user agent is not required to do anything at all in response to requestFullScreen. The user agent's behavior is allowed to vary depending on whether requestFullScreen is called during a user event (e.g. a mouse click handler).


* void requestFullScreen()
* void requestFullScreen()


As requestFullScreenWithKeys, but hints to the UA that while in fullscreen state, the toplevel browsing context for this Document should have keys disabled. While keys are disabled, there may be a reduced risk of spoofing attacks inducing the user to input inappropriate data, and the UA may choose to relax restrictions on entering fullscreen state with keys disabled.
As requestFullScreenWithKeys, but hints to the UA that while in full-screen state, the toplevel browsing context for this Document should have keys disabled. While keys are disabled, there may be a reduced risk of spoofing attacks inducing the user to input inappropriate data, and the UA may choose to relax restrictions on entering full-screen state with keys disabled.


New DOM attribute of Document:
New DOM attribute of Document:
Line 61: Line 61:
* readonly attribute boolean fullScreen
* readonly attribute boolean fullScreen


Returns true while the document is in the fullscreen state.
Returns true while the document is in the full-screen state.


* readonly attribute boolean fullScreenKeyboardInputAllowed
* readonly attribute boolean fullScreenKeyboardInputAllowed


Returns true while the window's toplevel browsing context is fullscreen and not in a "keys disabled" state.
Returns true while the window's toplevel browsing context is full-screen and not in a "keys disabled" state.


New content attribute of the <iframe> element:
New content attribute of the <iframe> element:
Line 71: Line 71:
* allowfullscreen
* allowfullscreen


This is a boolean attribute. When this attribute is not set, UAs must ignore fullscreen requests in the iframe or its descendant frames.
This is a boolean attribute. When this attribute is not set, UAs must ignore full-screen requests in the iframe or its descendant frames.


New events:
New events:
Line 77: Line 77:
* fullscreenchange
* fullscreenchange


When a Document enters or leaves the fullscreen state, the user agent must queue a task to dispatch this event. When the event is dispatched, if the document's current fullscreen element is an element in the document, then the event target is that element, otherwise the event target is the document. The event bubbles and is not cancellable.
When a Document enters or leaves the full-screen state, the user agent must queue a task to dispatch this event. When the event is dispatched, if the document's current full-screen element is an element in the document, then the event target is that element, otherwise the event target is the document. The event bubbles and is not cancellable.


The 'onfullscreenchange' event handling attribute is supported on HTML elements.
The 'onfullscreenchange' event handling attribute is supported on HTML elements.
Line 85: Line 85:
* :full-screen
* :full-screen


While a Document is in the fullscreen state, and the document's current fullscreen element is an element in the document, the 'full-screen' pseudoclass applies to that element. Also, an <iframe>, <object> or <embed> element whose child browsing context's Document is in the fullscreen state has the 'full-screen' pseudoclass applied.
While a Document is in the full-screen state, and the document's current full-screen element is an element in the document, the 'full-screen' pseudoclass applies to that element. Also, an <iframe>, <object> or <embed> element whose child browsing context's Document is in the full-screen state has the 'full-screen' pseudoclass applied.


New CSS media query selector:
New CSS media query selector:
Line 96: Line 96:
* <code>off</code>
* <code>off</code>


While a Document is in the fullscreen state, the fullscreen media type is active for the document.
While a Document is in the full-screen state, the full-screen media type is active for the document.


Suggested UA stylesheet rules:
Suggested UA stylesheet rules:


  /* A fullscreen element that is not the root element should be stretched
  /* A full-screen element that is not the root element should be stretched
     to cover the viewport. */
     to cover the viewport. */
  :full-screen:not(:root) {
  :full-screen:not(:root) {
Line 111: Line 111:
   background:black;
   background:black;
  }
  }
  /* In fullscreen mode, if the root element itself is not fullscreen then
  /* In full-screen mode, if the root element itself is not full-screen then
     we should hide the viewport scrollbar. */
     we should hide the viewport scrollbar. */
  @media all and (full-screen:on) {
  @media all and (full-screen:on) {
Line 125: Line 125:
The specification intentionally gives UAs great freedom in policy, because no one policy can fit all users, devices, and user interface designs. However, here is a policy that should be acceptable for conventional desktop browsers.
The specification intentionally gives UAs great freedom in policy, because no one policy can fit all users, devices, and user interface designs. However, here is a policy that should be acceptable for conventional desktop browsers.


* requestFullScreen while the window is already in the fullscreen state is approved.
* requestFullScreen while the window is already in the full-screen state is approved.
* Otherwise, requestFullScreen outside a user action (e.g. a non-synthesized input event handler) is denied.
* Otherwise, requestFullScreen outside a user action (e.g. a non-synthesized input event handler) is denied.
* Otherwise, requestFullScreen without the ALLOW_KEYBOARD_INPUT flag is approved.
* Otherwise, requestFullScreen without the ALLOW_KEYBOARD_INPUT flag is approved.
Line 132: Line 132:
== Implications ==
== Implications ==


There is no requirement to exit fullscreen state when a browsing context is navigated to a new page.
There is no requirement to exit full-screen state when a browsing context is navigated to a new page.


There is no requirement to exit fullscreen state if the current fullscreen element shifts to another element, or ceases to be an element in the document (e.g. because requestFullScreen was called again in the document or in some descendant document, or because the element is removed).
There is no requirement to exit full-screen state if the current full-screen element shifts to another element, or ceases to be an element in the document (e.g. because requestFullScreen was called again in the document or in some descendant document, or because the element is removed).


Nothing in this specification depends on whether the current fullscreen element is visible (e.g. whether it has "display:none").
Nothing in this specification depends on whether the current full-screen element is visible (e.g. whether it has "display:none").


Nothing in this specification affects or depends on focus.
Nothing in this specification affects or depends on focus.
Line 142: Line 142:
== Examples ==
== Examples ==


1. Make a video element display fullscreen when clicked and leave fullscreen when it ends.
1. Make a video element display full-screen when clicked and leave full-screen when it ends.


  &lt;video src="pelican.webm" autoplay
  &lt;video src="pelican.webm" autoplay
Line 149: Line 149:
  &lt;/video&gt;
  &lt;/video&gt;


2. Make a canvas element display fullscreen in response to user input. Resize the canvas to the appropriate resolution while it's fullscreen.
2. Make a canvas element display full-screen in response to user input. Resize the canvas to the appropriate resolution while it's full-screen.


  &lt;script&gt;
  &lt;script&gt;
Line 166: Line 166:
  &lt;/button&gt;
  &lt;/button&gt;


3. Hide advertisements while the window is fullscreen.
3. Hide advertisements while the window is full-screen.


  @media all and (full-screen:on) {
  @media all and (full-screen:on) {
Line 185: Line 185:
** the Firefox 4 "View" menu item "Full Screen" (shift-command-F)
** the Firefox 4 "View" menu item "Full Screen" (shift-command-F)


 
''roc: Elika and I resolved to use 'full-screen' everywhere.''
Whichever we pick, we should be consistent, e.g., EITHER:
 
1. one word
* '''fullscreen'''
** :fullscreen
** media query selector feature: fullscreen
** cancelFullscreen()
** requestFullscreen()
** requestFullscreenWithKeys()
 
OR
 
2. two words
* '''full screen'''
** :full-screen
** media query selector feature: full-screen
** cancelFullScreen()
** requestFullScreen()
** requestFullScreenWithKeys()
 
OR
 
3. come up with a good case (e.g. CSS vs DOM) to split them consistently:
* '''full screen'''
** :fullscreen
** media query selector feature: fullscreen
** cancelFullScreen()
** requestFullScreen()
** requestFullScreenWithKeys()
 
 
=== media type vs media query selector ===
 
<code>@media full-screen</code> vs. <code>@media all and (full-screen: on)</code>
 
Originally spec'd:
 
New CSS media type:
 
* full-screen
 
While a Document is in the fullscreen state, the full-screen media type is active for the document.
 
 
Per discussion among [[User:Fantasai]], [[User:Roc]], [[User:Tantek]] a media query selector for the fullscreen state (on or off) may be better, e.g. it can be combined with all media types:
 
<code>@media all and (full-screen: on)</code>
 
or can be special cased for specific media types:
 
<code>@media handheld and (full-screen: on)</code>
 
<code>@media screen and (full-screen: on)</code>
 
<code>@media tv and (full-screen: on)</code>
 
If we resolve the naming issue based on one word rather than two, then we'll rename this CSS feature accordingly ( :fullscreen , media query selector "fullscreen" )


=== avoiding ancestor reflow ===
=== avoiding ancestor reflow ===
Line 250: Line 193:


The underlying background of this new opaque CSS canvas comes from the fullscreened element, just as the underlying background of a window comes from the root element of the document in that window.
The underlying background of this new opaque CSS canvas comes from the fullscreened element, just as the underlying background of a window comes from the root element of the document in that window.
''roc: I don't want to do it this way. Creating additional views is very difficult to fit into the architecture of Gecko and other engines. The existing way seems fine in practice. Reflowing the document is not going to be a significant performance issue.''


=== avoiding drawing anything else ===
=== avoiding drawing anything else ===
Also, the suggested UA stylesheet rules use z-index to put the fullscreened element above everything else. Instead we may want to specify that when something is fullscreened, that we don't bother rendering any other windows/tabs, nor the parent document.
Also, the suggested UA stylesheet rules use z-index to put the fullscreened element above everything else. Instead we may want to specify that when something is fullscreened, that we don't bother rendering any other windows/tabs, nor the parent document.
''roc: Again this is more invasive to the engine than necessary. The z-index approach should work fine and is simple, without requiring any special engine support.''

Revision as of 23:48, 11 April 2011

Requirements

  • Scripts should be able to initiate and terminate full-screen
    • Allows custom, in-page, discoverable UI to active full-screen
  • Arbitrary Web content should be visible full-screen
    • <video>, <canvas>, multicolumn text, etc
    • Required for scripted video controls
  • Entering and exiting full-screen must trigger events
    • To allow scripted changes to content, e.g. resizing of canvas content
  • Scripts should be able to opt in to having alphanumeric keyboard input disabled during full-screen
    • Enables less restrictive anti-spoofing measures
  • Actual full-screen transitions must be allowed to be asynchronous and entirely at the discretion of the UA
    • To enable passive notification/confirmation UI
    • To enable a wide range of security measures to prevent spoofing or other abuse
  • Making a single element full-screen should be as simple as possible
  • Content in IFRAMEs should be able go full-screen
    • To enable "widgets" such as embedded videos to offer full-screen UI

Proposed Specification

A Document can be in the "full-screen state". What exactly this means is up to the UA, but typically it means that the Document covers most or all of the screen and some or all of the normal UA UI is not visible.

It is possible for non-toplevel browsing contexts to have their Document in the full-screen state. The parent browsing context of a browsing context with its Document in the full-screen state must also have its Document in the full-screen state.

The user agent may transition a Document into or out of the full-screen state at any time, whether or not script has requested it. User agents are encouraged to provide standard UI to exit the full-screen state, for example if the user presses the Escape key.

Toplevel browsing contexts can be in a "keys disabled" state. In this state, the user agent must suppress all keyup, keydown and keypress events whose keyCode is not in one of the following ranges:

  • DOM_VK_CANCEL to DOM_VK_CAPS_LOCK, inclusive
  • DOM_VK_SPACE to DOM_VK_DELETE, inclusive
  • DOM_VK_SEMICOLON to DOM_VK_EQUALS, inclusive
  • DOM_VK_MULTIPLY to DOM_VK_META, inclusive

Such events are not dispatched to any nodes in any document of the toplevel browsing context or descendant browsing contexts. This includes suppression of any internal key event processing that would insert text into form controls or editable content. The user agent might respond to such events by leaving full-screen mode.

Each document has an optional "current full-screen element".

New method of Document:

  • void cancelFullScreen()

Requests that the UA exit full-screen mode. The UA is not required to honor this, for example the UA might require that only a Document that last triggered full-screen can cancel it.

The current full-screen element for the document is cleared.

New methods of Element:

  • void requestFullScreenWithKeys()

The current full-screen element for the document is set to this element.

Typically the user agent would react by transitioning the Document to the full-screen state, or by presenting asynchronous confirmation UI and transitioning to the full-screen state if/when the user responds affirmatively. However, the user agent is not required to do anything at all in response to requestFullScreen. The user agent's behavior is allowed to vary depending on whether requestFullScreen is called during a user event (e.g. a mouse click handler).

  • void requestFullScreen()

As requestFullScreenWithKeys, but hints to the UA that while in full-screen state, the toplevel browsing context for this Document should have keys disabled. While keys are disabled, there may be a reduced risk of spoofing attacks inducing the user to input inappropriate data, and the UA may choose to relax restrictions on entering full-screen state with keys disabled.

New DOM attribute of Document:

  • readonly attribute boolean fullScreen

Returns true while the document is in the full-screen state.

  • readonly attribute boolean fullScreenKeyboardInputAllowed

Returns true while the window's toplevel browsing context is full-screen and not in a "keys disabled" state.

New content attribute of the <iframe> element:

  • allowfullscreen

This is a boolean attribute. When this attribute is not set, UAs must ignore full-screen requests in the iframe or its descendant frames.

New events:

  • fullscreenchange

When a Document enters or leaves the full-screen state, the user agent must queue a task to dispatch this event. When the event is dispatched, if the document's current full-screen element is an element in the document, then the event target is that element, otherwise the event target is the document. The event bubbles and is not cancellable.

The 'onfullscreenchange' event handling attribute is supported on HTML elements.

New CSS psuedoclass:

  • :full-screen

While a Document is in the full-screen state, and the document's current full-screen element is an element in the document, the 'full-screen' pseudoclass applies to that element. Also, an <iframe>, <object> or <embed> element whose child browsing context's Document is in the full-screen state has the 'full-screen' pseudoclass applied.

New CSS media query selector:

  • full-screen

that accepts two states:

  • on
  • off

While a Document is in the full-screen state, the full-screen media type is active for the document.

Suggested UA stylesheet rules:

/* A full-screen element that is not the root element should be stretched
   to cover the viewport. */
:full-screen:not(:root) {
  position:fixed;
  top:0;
  left:0;
  right:0;
  bottom:0;
  z-index:2147483647;
  background:black;
}
/* In full-screen mode, if the root element itself is not full-screen then
   we should hide the viewport scrollbar. */
@media all and (full-screen:on) {
  :root:not(:full-screen) {
    overflow:hidden;
  }
}

Note that it is possible for a document to position content over an element with the :full-screen pseudo-class, for example if the :full-screen element is in a container with z-index not 'auto'.

Suggested UA Policy

The specification intentionally gives UAs great freedom in policy, because no one policy can fit all users, devices, and user interface designs. However, here is a policy that should be acceptable for conventional desktop browsers.

  • requestFullScreen while the window is already in the full-screen state is approved.
  • Otherwise, requestFullScreen outside a user action (e.g. a non-synthesized input event handler) is denied.
  • Otherwise, requestFullScreen without the ALLOW_KEYBOARD_INPUT flag is approved.
  • Otherwise, passive confirmation UI is presented and requestFullScreen is approved if and when the user approves it.

Implications

There is no requirement to exit full-screen state when a browsing context is navigated to a new page.

There is no requirement to exit full-screen state if the current full-screen element shifts to another element, or ceases to be an element in the document (e.g. because requestFullScreen was called again in the document or in some descendant document, or because the element is removed).

Nothing in this specification depends on whether the current full-screen element is visible (e.g. whether it has "display:none").

Nothing in this specification affects or depends on focus.

Examples

1. Make a video element display full-screen when clicked and leave full-screen when it ends.

<video src="pelican.webm" autoplay
       onclick="event.target.requestFullScreen()"
       onended="document.cancelFullScreen()">
</video>

2. Make a canvas element display full-screen in response to user input. Resize the canvas to the appropriate resolution while it's full-screen.

<script>
function redrawCanvas(c) { ... }
function resizeCanvas() {
  var c = document.getElementById("c");
  var rect = c.getBoundingClientRect();
  c.width = rect.width;
  c.height = rect.height;
  redrawCanvas(c);
}
</script>
<canvas id="c" onfullscreenchange="resizeCanvas()"></canvas>
<button onclick="document.getElementById('c').requestFullScreen()">
  Go Fullscreen!
</button>

3. Hide advertisements while the window is full-screen.

@media all and (full-screen:on) {
  .advertisement { display:none; }
}

Issues

naming one word or two

fullscreen vs full screen

  • fullscreen
    • text of this page repeatedly uses "fullscreen"
    • Wikipedia prefers "fullscreen" and redirects "full screen" to that page.
  • full screen
    • title of this page implies "full screen" from the camelcase: (FullScreenAPI)
    • the Firefox 4 "View" menu item "Full Screen" (shift-command-F)

roc: Elika and I resolved to use 'full-screen' everywhere.

avoiding ancestor reflow

Currently, the suggested UA stylesheet rules for a non-root fullscreen element take it out of the flow and make it position fixed, which has the side-effect of causing its ancestors to reflow, which is unnecessary, and thus an undesirable performance hit.

Instead, we should consider simply defining the fullscreened element as creating a new view with itself as the root box of a CSS presentation, with its own opaque CSS canvas (as defined in CSS), thereby avoiding the reflow problem.

The underlying background of this new opaque CSS canvas comes from the fullscreened element, just as the underlying background of a window comes from the root element of the document in that window.

roc: I don't want to do it this way. Creating additional views is very difficult to fit into the architecture of Gecko and other engines. The existing way seems fine in practice. Reflowing the document is not going to be a significant performance issue.

avoiding drawing anything else

Also, the suggested UA stylesheet rules use z-index to put the fullscreened element above everything else. Instead we may want to specify that when something is fullscreened, that we don't bother rendering any other windows/tabs, nor the parent document.

roc: Again this is more invasive to the engine than necessary. The z-index approach should work fine and is simple, without requiring any special engine support.