全画面 API

現行標準 — 最終更新

参加方法:
GitHub whatwg/fullscreen (新規 issue, 既存の issue)
Matrix でチャット
コミット履歴:
GitHub whatwg/fullscreen/commits
このコミット時点のスナップショット
@fullscreenapi
テスト:
web-platform-tests fullscreen/ (進行中の作業)
翻訳 (参考情報):
日本語
简体中文
한국어

概要

全画面 API 現行標準は、要素を全画面表示するための API を定義します。

1. 用語

この仕様は Infra Standard に依存します。[INFRA]

この仕様で使用されるほとんどの用語は、CSS、DOM、HTML、Web IDL からのものです。[CSS] [DOM] [HTML] [WEBIDL]

2. モデル

すべての 要素には、fullscreen flag が関連付けられています。特に指定がない限り、これは未設定です。

すべての iframe 要素には、iframe fullscreen flag が関連付けられています。特に指定がない限り、これは未設定です。

すべての 文書には、fullscreen element が関連付けられています。 fullscreen element は、 文書top layer において fullscreen flag が設定されている最上位の 要素 です。該当しない場合は null です。

すべての 文書には、list of pending fullscreen events が関連付けられています。 これは (string, 要素) からなる タプル順序付き集合 です。初期状態は空です。

element を fullscreen にする手順:

  1. hideUntil に、topmost popover ancestorelement, null, false を渡して実行した結果を設定する。

  2. hideUntil が null の場合、elementnode documenthideUntil に設定する。

  3. hide all popovers untilhideUntil, false, true を渡して実行する。

  4. elementfullscreen flag を設定する。

  5. Remove from the top layer immediatelyelement を渡して実行する。

  6. Add to the top layerelement を渡して実行する。

element の fullscreen を解除するには、 elementfullscreen flag および iframe fullscreen flag(存在する場合)を未設定にし、 remove from the top layer immediatelyelement を渡して実行する。

document の fullscreen を解除するには、 documenttop layer 内で fullscreen flag が設定されているすべての 要素 に対して unfullscreen を実行する。


fully exit fullscreendocument document に対して実行するには、次の手順を実行する:

  1. documentfullscreen element が null なら、これ以降の手順を終了する。

  2. documenttop layer 内で、fullscreen flag が設定されている fullscreen element 以外の要素について Unfullscreen elements を実行する。

  3. Exit fullscreen document.

removing stepsremovedNode で実行されるときは、次の手順を実行する:

  1. documentremovedNodenode document を設定する。

  2. nodesremovedNodeshadow-including inclusive descendants のうち fullscreen flag が設定されているものを shadow-including tree order で取得する。

  3. node について、次のとおり:

    1. nodedocumentfullscreen element なら、 exit fullscreen document を実行する。

    2. それ以外の場合は、node の fullscreen を解除する

    3. documenttop layernode含む場合、 remove from the top layer immediatelynode を渡して実行する。

      他の仕様でも top layer に要素を追加・削除できるため、 nodedocumentfullscreen element でない場合もあります。 例えば node が開いている dialog 要素である場合などです。

unloading document cleanup stepsdocument で実行されるとき、 fully exit fullscreendocument に実行する。


Fullscreen がサポートされるのは、 事前に設定されたユーザーの好み、安全上のリスク、またはプラットフォームの制限がない場合です。


run the fullscreen stepsdocument document に対して実行するには、次の手順を実行する:

  1. pendingEventsdocumentlist of pending fullscreen events を設定する。

  2. document の list of pending fullscreen events を空にする

  3. (type, element) について、pendingEvents の中で:

    1. elementconnected かつ、 その node documentdocument なら targetelement を設定し、そうでなければ targetdocument を設定する。

    2. Fire an event という名前で typebubblescomposed 属性を true にして target でイベントを発火する。

これらの手順は HTML で定義されている event loop と統合されています。[HTML]

3. API

enum FullscreenNavigationUI {
  "auto",
  "show",
  "hide"
};

dictionary FullscreenOptions {
  FullscreenNavigationUI navigationUI = "auto";
};

partial interface Element {
  Promise<undefined> requestFullscreen(optional FullscreenOptions options = {});

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface Document {
  [LegacyLenientSetter] readonly attribute boolean fullscreenEnabled;
  [LegacyLenientSetter, Unscopable] readonly attribute boolean fullscreen; // historical

  Promise<undefined> exitFullscreen();

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface mixin DocumentOrShadowRoot {
  [LegacyLenientSetter] readonly attribute Element? fullscreenElement;
};
promise = element . requestFullscreen([options])
element を全画面表示し、完了時に promise が解決されます。

options が指定された場合、optionsnavigationUI メンバーは、全画面表示中にナビゲーション UI の表示を優先するかどうかを示します。 "show" の場合はナビゲーションの簡易さを画面スペースよりも優先し、"hide" の場合は画面スペースをより優先します。ユーザーエージェントは常にアプリケーションの設定よりもユーザーの好みを優先してもかまいません。デフォルト値 "auto" はアプリケーションの好みがないことを示します。

document . fullscreenEnabled

document要素 を全画面表示でき、 全画面表示がサポートされている場合は true、そうでなければ false を返します。

promise = document . exitFullscreen()

documentfullscreen element の全画面表示を終了し、完了時に promise が解決されます。

document . fullscreenElement

documentfullscreen element を返します。

shadowroot . fullscreenElement

shadowrootfullscreen element を返します。

fullscreen element ready check は、要素 element に対して、以下すべてが true の場合 true を返し、そうでなければ false を返します:

requestFullscreen(options) メソッドの 手順は以下の通りです:

  1. pendingDocthisnode document を設定する。

  2. promise に新しい promise を作成する。

  3. pendingDocfully active でない場合、promiseTypeError 例外で reject し、promise を返す。

  4. error に false を設定する。

  5. 次のいずれかの条件が false の場合、error を true にする:

  6. error が false の場合、consume user activationpendingDocrelevant global object で実行する。

  7. promise を返し、残りの手順を 並列で実行する。

  8. error が false の場合、pendingDocnode navigabletop-level traversableactive document のビューポートサイズを options["navigationUI"] を考慮して変更する(任意):

    ビューポートサイズ
    "hide" 出力デバイス画面の全サイズ
    "show" ユーザーエージェントがページナビゲーションコントロールを表示できるように制限された出力デバイス画面のサイズ
    "auto" 上記いずれかに一致するユーザーエージェント定義

    必要に応じて、ユーザーがこれを元に戻す方法を知らせるメッセージを表示することができます。

  9. 次のいずれかの条件が false の場合、error を true にする:

  10. error が true の場合:

    1. Append (fullscreenerror, this) を pendingDoclist of pending fullscreen events に追加する。

    2. promiseTypeError 例外で reject し、これ以降の手順を終了する。

  11. fullscreenElements順序付き集合 を新規作成し、 初期値として this を入れる。

  12. while true:

    1. lastfullscreenElements の最後の 要素 を設定する。

    2. containerlastnode navigablecontainer を設定する。

    3. container が null なら break する。

    4. AppendcontainerfullscreenElements に追加する。

  13. element について fullscreenElements の中で:

    1. docelementnode document を設定する。

    2. elementdocfullscreen element なら continue する。

      何も変化していない場合はオブザーバに通知する必要はありません。

    3. elementthis かつ thisiframe 要素 なら、elementiframe fullscreen flag を設定する。

    4. Fullscreen elementdoc で実行する。

    5. Append (fullscreenchange, element) を doclist of pending fullscreen events に追加する。

    要素が fullscreened される順序は観測できません。run the fullscreen stepstree order で呼ばれるためです。

  14. promise を undefined で解決する。

アウトオブプロセスの navigables を持つ実装は読者への課題として残されています。改善案のフィードバック歓迎です。

fullscreenEnabled ゲッターの手順は、 this が "fullscreen" 機能の allowed to use であり、 全画面表示がサポートされている場合 true を返し、 そうでなければ false を返すことです。

fullscreen ゲッターの手順は、 thisfullscreen element が null なら false を返し、そうでなければ true を返すことです。

fullscreenElement 属性を代わりに利用してください。

fullscreenElement ゲッターの手順は以下の通りです:

  1. thisshadow root かつその hostconnected でないなら、null を返す。

  2. candidateretargetingfullscreen elementthis で実行した結果を設定する。

  3. candidatethis が同じ tree に属しているなら、 candidate を返す。

  4. null を返す。

文書は、その top layerfullscreen flag が設定されている 要素 がちょうど 1 つだけある場合、 単純な全画面文書(simple fullscreen document)とされます。

文書top layer要素 が 2 つある場合でも 単純な全画面文書となる場合があります。 例えば、fullscreen element の他に 開いている dialog 要素がある場合などです。

collect documents to unfullscreendoc に対して実行する手順は以下の通りです:

  1. docsdoc を含む 順序付き集合 を作成する。

  2. while true:

    1. lastDocdocs の最後の 文書 を設定する。

    2. 保証: lastDocfullscreen element は null ではない。

    3. lastDoc単純な全画面文書でない場合、 break する。

    4. containerlastDocnode navigablecontainer を設定する。

    5. container が null の場合、break する。

    6. containeriframe fullscreen flag が設定されている場合、 break する。

    7. Appendcontainernode documentdocs に追加する。

  3. docs を返す。

    これは fullscreen elementfullscreen解除を行う文書集合ですが、 docs の最後の文書には 要素top layer に複数 fullscreen flag が設定されている場合があり、 その場合その文書は引き続き全画面状態となります。

exit fullscreen文書 doc に対して実行する手順は以下の通りです:

  1. promise に新しい promise を作成する。

  2. docfully active でない、または docfullscreen element が null の場合、promiseTypeError 例外で reject し、promise を返す。

  3. resize に false を設定する。

  4. docscollect documents to unfullscreendoc に対して実行した結果を設定する。

  5. topLevelDocdocnode navigabletop-level traversableactive document を設定する。

  6. topLevelDocdocs に含まれていて、かつ 単純な全画面文書の場合、 doctopLevelDoc を設定し、 resize を true にする。

  7. docfullscreen elementconnectedでない場合:

    1. Append (fullscreenchange, docfullscreen element) を doclist of pending fullscreen events に追加する。

    2. fullscreen解除docfullscreen element に対して実行する。

  8. promise を返し、残りの手順を 並列で実行する。

  9. 画面の向きを完全に解除する手順doc で実行する。

  10. resize が true の場合、doc のビューポートを「通常」のサイズに変更する。

  11. docfullscreen element が null なら、 promise を undefined で解決し、これ以降の手順を終了する。

  12. exitDocscollect documents to unfullscreendoc に対して実行した結果を設定する。

  13. descendantDocsdocdescendant navigablesactive document のうち fullscreen element が null でないものを tree order で順序付き集合として取得する。

  14. exitDoc について exitDocs の中で:

    1. Append (fullscreenchange, exitDocfullscreen element) を exitDoclist of pending fullscreen events に追加する。

    2. resize が true の場合、exitDoc の fullscreen を解除する。

    3. それ以外の場合、fullscreen解除exitDocfullscreen element に対して実行する。

  15. descendantDoc について descendantDocs の中で:

    1. Append (fullscreenchange, descendantDocfullscreen element) を descendantDoclist of pending fullscreen events に追加する。

    2. descendantDoc の fullscreen を解除する。

    文書が fullscreen解除 される順序は観測できません。 run the fullscreen stepstree order で呼ばれるためです。

  16. promise を undefined で解決する。

exitFullscreen() メソッドの手順は、 exit fullscreenthis に対して実行した結果を返すことです。


以下は イベントハンドラ(および対応する イベントハンドラ イベント型)であり、 Element および Document オブジェクトで event handler IDL attributes としてサポートされなければなりません:

イベントハンドラ イベントハンドラ イベント型
onfullscreenchange fullscreenchange
onfullscreenerror fullscreenerror

これらは ShadowRootWindow オブジェクトではサポートされていません。また、いかなる名前空間でも Element オブジェクトに対応する event handler content attributes はありません。

4. UI

ユーザーエージェントは、ネイティブのメディア全画面コントロールの実装に requestFullscreen() および exitFullscreen() を利用することが推奨されます。

ユーザーが クローズリクエスト を開始すると、これは 全画面から完全に退出する アルゴリズムを クローズリクエスト手順の一部として起動します。これは クローズウォッチャー よりも優先されます。

ユーザーエージェントは、ユーザーエージェントが必要と判断した場合、クローズリクエストexitFullscreen() の呼び出しなしで、いつでも全画面セッションを終了することができます。

5. レンダリング

このセクションは HTML のレンダリングセクションと同等に解釈されます。[HTML]

5.1. :fullscreen 疑似クラス

:fullscreen 疑似クラスは、次のいずれかの条件が true である 要素 element にマッチしなければなりません:

これは fullscreenElement API と異なり、API は最上位の fullscreen element を返します。

5.2. ユーザーエージェントレベルのスタイルシートのデフォルト

@namespace "http://www.w3.org/1999/xhtml";

*|*:not(:root):fullscreen {
  position:fixed !important;
  inset:0 !important;
  margin:0 !important;
  box-sizing:border-box !important;
  min-width:0 !important;
  max-width:none !important;
  min-height:0 !important;
  max-height:none !important;
  width:100% !important;
  height:100% !important;
  transform:none !important;

  /* intentionally not !important */
  object-fit:contain;
}

iframe:fullscreen {
  border:none !important;
  padding:0 !important;
}

*|*:not(:root):fullscreen::backdrop {
  background:black;
}

6. Permissions Policy 統合

この仕様は、"fullscreen" という文字列で識別される ポリシー制御機能を定義します。 その デフォルト許可リスト'self' です。

文書permissions policy は、その文書内のコンテンツが全画面表示できるかどうかを決定します。いずれかの文書で無効化されている場合、その文書内のコンテンツは 全画面表示の使用が許可されません

HTML allowfullscreen 属性は、iframe 要素の container policy に影響します。allow 属性で上書きされない限り、iframe の allowfullscreen を設定することは <iframe allow="fullscreen *"> と同等です。 詳細は Permissions Policy § 6.3.1 allowfullscreen を参照してください。

7. セキュリティとプライバシーに関する考慮事項

ユーザーエージェントは、例えばオーバーレイにより、最終的なユーザーが何かが全画面表示されていることを認識できるようにするべきです。ユーザーエージェントは、常に機能する全画面解除手段を提供し、それをユーザーに通知するべきです。これは、全画面時にサイトがユーザーエージェントやオペレーティングシステムの環境を再現してユーザーを欺くことを防ぐためです。requestFullscreen() の定義も参照してください。

子ナビゲーブル内のコンテンツが全画面表示を行うには、permissions policy により明示的に許可されている必要があります。 具体的には、HTML allowfullscreen 属性や iframe 要素の適切な allow 属性、またはそのドキュメントを経由して配信される `Permissions-Policy` HTTP ヘッダー で明示的に許可する必要があります。

これにより、例えばサードパーティのコンテンツが明示的な許可なしに全画面表示されることを防ぎます。

この仕様では以前、::backdrop や文書の top layer の概念を定義していました。

謝辞

最初のモデル設計と素晴らしい貢献をしてくれた Robert O’Callahan 氏に多大なる感謝を申し上げます。

以下の方々にも感謝します: Andy Earnshaw, Changwan Hong, Chris Pearce, Darin Fisher, Dave Tapuska, fantasai, Giuseppe Pascale, Glenn Maynard, Ian Clelland, Ian Hickson, Ignacio Solla, João Eiras, Josh Soref, Kagami Sascha Rosylight, Matt Falkenhagen, Mihai Balan, Mounir Lamouri, Øyvind Stenhaug, Pat Ladd, Rafał Chłodnicki, Riff Jiang, Rune Lillesveen, Sigbjørn Vik, Simon Pieters, Tab Atkins-Bittner, Takayoshi Kochi, Theresa O’Connor, triple-underscore, Vincent Scheib, Xidorn Quan も素晴らしい貢献者です。

この標準は Philip Jägenstedt (Google, philip@foolip.org) によって編集されています。元の執筆者は Anne van Kesteren (Apple, annevk@annevk.nl) です。 Tantek Çelik (Mozilla, tantek@cs.stanford.edu) は法的な整理を担当しました。

知的財産権

Copyright © WHATWG (Apple, Google, Mozilla, Microsoft). この成果物は Creative Commons Attribution 4.0 International License の下でライセンスされています。その一部がソースコードに組み込まれる場合、その部分は BSD 3-Clause License の下でライセンスされます。

これは現行標準です。 特許審査版に興味がある方は 現行標準審査ドラフト をご覧ください。

索引

この仕様で定義されている用語

参照で定義されている用語

参考文献

規範的参考文献

[CSS]
Bert Bos 他. カスケーディング・スタイル・シート レベル2 改訂1 (CSS 2.1) 仕様。URL: https://drafts.csswg.org/css2/
[CSS-POSITION-4]
CSS Positioned Layout Module Level 4。 URL: https://drafts.csswg.org/css-position-4/
[DOM]
Anne van Kesteren. DOM 現行標準。現行標準。 URL: https://dom.spec.whatwg.org/
[HTML]
Anne van Kesteren 他. HTML 現行標準。 現行標準。URL: https://html.spec.whatwg.org/multipage/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra 現行標準。現行標準。URL: https://infra.spec.whatwg.org/
[MATHML]
Patrick D F Ion; Robert R Miner. 数学記法言語 (MathML™) 1.01 仕様。2023年3月7日。REC。URL: https://www.w3.org/TR/REC-MathML/
[PERMISSIONS-POLICY-1]
Ian Clelland. Permissions Policy。URL: https://w3c.github.io/webappsec-permissions-policy/
[SCREEN-ORIENTATION]
Marcos Caceres. Screen Orientation。 URL: https://w3c.github.io/screen-orientation/
[SVG]
Erik Dahlström 他. スケーラブル・ベクター・グラフィックス (SVG) 1.1 (第2版)。2011年8月16日。REC。URL: https://www.w3.org/TR/SVG11/
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL 現行標準。現行標準。URL: https://webidl.spec.whatwg.org/

IDL 索引

enum FullscreenNavigationUI {
  "auto",
  "show",
  "hide"
};

dictionary FullscreenOptions {
  FullscreenNavigationUI navigationUI = "auto";
};

partial interface Element {
  Promise<undefined> requestFullscreen(optional FullscreenOptions options = {});

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface Document {
  [LegacyLenientSetter] readonly attribute boolean fullscreenEnabled;
  [LegacyLenientSetter, Unscopable] readonly attribute boolean fullscreen; // historical

  Promise<undefined> exitFullscreen();

  attribute EventHandler onfullscreenchange;
  attribute EventHandler onfullscreenerror;
};

partial interface mixin DocumentOrShadowRoot {
  [LegacyLenientSetter] readonly attribute Element? fullscreenElement;
};

MDN

Document/exitFullscreen

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenchange_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+

Element/fullscreenchange_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenElement

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenEnabled

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView?Samsung Internet?Opera Mobile50+
MDN

Document/fullscreenerror_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+

Element/fullscreenerror_event

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Element/requestFullscreen

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera58+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android64+iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile50+
MDN

Element

In all current engines.

Firefox1+Safari1+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile10.1+
MDN

ShadowRoot/fullscreenElement

In all current engines.

Firefox64+Safari16.4+Chrome71+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

:fullscreen

Firefox64+SafariNoneChrome71+
Opera?Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS SafariNoneChrome for Android?Android WebView71+Samsung Internet?Opera Mobile?
MDN

Headers/Feature-Policy/fullscreen

In only one current engine.

FirefoxNoneSafariNoneChrome62+
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

Headers/Permissions-Policy/fullscreen

In only one current engine.

FirefoxNoneSafariNoneChrome88+
Opera?Edge88+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?