1. 6 ユーザーとの対話処理
    1. 6.1 hidden属性
    2. 6.2 不活性サブツリー
    3. 6.3 アクティベーション
    4. 6.4 フォーカス
      1. 6.4.1 導入
      2. 6.4.2 データモデル
      3. 6.4.3 tabindex属性
      4. 6.4.4 Processing model
      5. 6.4.5 シーケンシャルフォーカスナビゲーション
      6. 6.4.6 フォーカス管理API
    5. 6.5 キーボードショートカットの割り当て
      1. 6.5.1 導入
      2. 6.5.2 accesskey属性
      3. 6.5.3 Processing model
    6. 6.6 編集
      1. 6.6.1 編集可能な文書領域を作成する:contenteditableコンテンツ属性
      2. 6.6.2 Making entire documents editable: the designMode IDL attribute
      3. 6.6.3 ページ内編集者のためのベストプラクティス
      4. 6.6.4 編集API
      5. 6.6.5 スペルと文法チェック
    7. 6.7 ドラッグアンドドロップ
      1. 6.7.1 導入
      2. 6.7.2 ドラッグデータストア
      3. 6.7.3 DataTransferインターフェイス
        1. 6.7.3.1 DataTransferItemListインターフェイス
        2. 6.7.3.2 DataTransferItemインターフェイス
      4. 6.7.4 DragEventインターフェイス
      5. 6.7.5 Processing model
      6. 6.7.6 イベントの概要
      7. 6.7.7 draggable属性
      8. 6.7.8 dropzone属性
      9. 6.7.9 Security risks in the drag-and-drop model

6 ユーザーとの対話処理

6.1 hidden属性

Support: hiddenChrome for Android 56+Chrome 6+iOS Safari 5.0+UC Browser for Android 11+Firefox 4+IE 11+Samsung Internet 4+Opera Mini all+Android Browser 4+Safari 5.1+Edge 12+Opera 11.1+

Source: caniuse.com

すべてのHTML要素hiddenコンテンツ属性設定を持ってもよい。hidden属性は真偽属性である。要素で指定される場合、それは、要素がまだないこと、またはもはやページの現在の状態には直接関係がない、または、ユーザーが直接アクセスするのとは対照的に、ページの他の部分で再利用するコンテンツを宣言するために使用されていることを示す。ユーザーエージェントは、hiddenが指定された属性を持つ要素をレンダリングすべきでない。この要件は、スタイルレイヤーを通して間接的に実装されてもよい。たとえば、HTML+CSSユーザーエージェントは、レンダリングの節で提案される規則を使用してこの要件を実装することができる。

この属性は通常CSSを使用して実装されているため、CSSを使用して上書きすることもできる。たとえば、'display: block'をすべての要素に適用する規則は、hidden属性の影響を相殺するだろう。したがって著者は、期待通りに属性がスタイル付けされていることを確認し、そのスタイルシートを書く際に注意する必要がある。

以下の骨格の例において、属性は、ユーザーがログインするまでウェブゲームのメイン画面を非表示にするために使用される:

  <h1>The Example Game</h1>
  <section id="login">
   <h2>Login</h2>
   <form>
    ...
    <!-- calls login() once the user's credentials have been checked -->
   </form>
   <script>
    function login() {
      // switch screens
      document.getElementById('login').hidden = true;
      document.getElementById('game').hidden = false;
    }
   </script>
  </section>
  <section id="game" hidden>
   ...
  </section>

hidden属性は、別のプレゼンテーションに合法的に示すことができたコンテンツを隠すために使用されてはならない。たとえば、タブ付きインターフェイスは単にオーバーフロープレゼンテーションの一種であるため、タブ付きダイアログでパネルを隠すためにhiddenを使用することは誤りである。―それはスクロールバーをもつ1つの大きなページ内のすべてのフォームコントロールを示すのと同様である。ちょうど1つのプレゼンテーションからコンテンツを非表示にするためにこの属性を使用することも同様に誤りである。―何かがhiddenとマークされる場合、それは、たとえばスクリーンリーダーなどを含む、すべてのプレゼンテーションから隠されている。

自身がhiddenでない要素は、hiddenである要素へハイパーリンクされてはならない。自身がhiddenでないlabelおよびoutput要素のfor属性も同様に、hiddenである要素を参照してはならない。どちらの場合も、このような参照はユーザーの混乱を引き起こすだろう。

しかし、要素およびスクリプトは、他のコンテキストでhiddenである要素を参照してもよい。

たとえば、hidden属性でマークされたセクションにリンクするhref属性を使用するのは誤りだろう。コンテンツが適切または関連しない場合、それにリンクする理由はない。

しかし、自身がhiddenである説明を参照するために、ARIA aria-describedby属性を使用することは構わない。説明を非表示にすることはそれらが単独で有用でないことを意味する一方で、それらは、それらが説明する画像から参照される特定のコンテキストにおいて有用である方法で記述することもできる。

同様に、hidden属性を持つcanvas要素は、オフスクリーンバッファとしてスクリプト化されたグラフィックスエンジンによって使用されるかもしれず、フォームコントロールは、form属性を使用する隠しform要素を参照するかもしれない。

hidden属性によって非表示にされたセクション内の要素は依然としてアクティブである。たとえば、そのようなセクションでのスクリプトやフォームコントロールは、依然として実行および送信する。それらのプレゼンテーションのみがユーザーに変更される。

hidden IDL属性は、同じ名前のコンテンツ属性を反映しなければならない。

6.2 不活性サブツリー

この節は、"inert"という名前のいかなるコンテンツ属性を定義または作成しない。この節は、単に不活性の抽象的な概念を定義する。

(特に要素やテキストノード)あるノードは不活性としてマークすることができる。ノードが不活性であるとき、あたかもノードがユーザーインタラクションイベントを対象する目的のために不在であるかのように、ユーザーエージェントは動作しなければならず、テキスト検索ユーザーインターフェイス(一般に"ページ内検索"として知られる)の目的に対してノードを無視してもよく、そのノード内のテキストの選択からユーザーを防いでもよい。しかし、ユーザーエージェントは、ユーザーが検索とテキスト選択に制限を上書きできるようにすべきである。

たとえば、bodyの中央に位置する単一の不活性段落からなるページを考えてみる。ユーザーがbody上から不活性段落へポインティングデバイスを移動させ、段落上をクリックする場合、mouseoverイベントは発火せず、mousemoveおよびclickイベントは段落よりむしろbody要素で発火するだろう。

ノードが不活性である場合、ノードは一般にフォーカスできない。コマンドである不活性ノードはまた、無効であるだろう。

ブラウジングコンテキストコンテナ不活性としてマークされる間に、そのネストされたブラウジングコンテキストアクティブ文書、およびそのDocumentにおけるすべてのノードは、不活性としてマークされなければならない。

Document全体は、モーダルダイアログダイアログによってブロックされるsubjectとしてマークすることができる。Documentがそのようにマークされている一方で、subject要素およびその子孫を除いて、Document内のすべてのノードは、不活性とマークされなければならない。(この段落で除外される要素は、さらに他の手段を介して不活性にマークすることができる。モーダルダイアログの一部であることは不活性とマークされることからノードを"守る"ことはない。)

一度に1つのみ要素がモーダルダイアログによってブロックされているとしてDocumentをマークすることができる。新しいdialogDocumentブロックするために作成された場合、前の要素がもしあれば、Documentのブロックを中止する。

dialog要素のshowModal()メソッドは、このメカニズムを利用する。

6.3 アクティベーション

HTMLの特定の要素は、ユーザーがアクティブにすることができることを意味する、アクティベーション動作を持つ。This is always caused by a click event.

The user agent should allow the user to manually trigger elements that have an activation behavior, for instance using keyboard or voice input, or through mouse clicks. When the user triggers an element with a defined activation behavior in a manner other than clicking it, the default action of the interaction event must be to fire a click event at the element.

An algorithm is triggered by user activation if any of the following conditions is true:

element . click()

あたかも要素をクリックされたかのように動作する。

Each element has an associated click in progress flag, which is initially unset.

The click() method must run the following steps:

  1. If this element is a form control that is disabled, then abort these steps.

  2. If this element's click in progress flag is set, then abort these steps.

  3. Set this element's click in progress flag.

  4. Fire a synthetic mouse event at this element, with the not trusted flag set.

  5. Unset this element's click in progress flag.

6.4 フォーカス

6.4.1 導入

この節は非規範的である。

HTMLユーザーインターフェイスは典型的に、フォームコントロール、スクロール可能領域、リンク、ダイアログボックス、ブラウザータブなど、複数のインタラクティブウィジットから成る。これらウィジェットは、他(たとえば、リンク、フォームコントロール)を含むもの(たとえば、ブラウザータブ、ダイアログボックス)をもつ、階層構造を形成する。

キーボードを使用するインターフェイスと情報交換する場合、アクティブなウィジェットから、フォーカスされると呼ばれる、インタラクティブなウィジェットの階層構造を通して、キー入力はシステムから流れる。

グラフィカル環境で動作するブラウザータブにおいて動作するHTMLアプリケーションを考えてみる。Suppose this application had a page with some text controls and links, and was currently showing a modal dialog, which itself had a text control and a button.

このシナリオにおいて、その子の間でHTMLアプリケーションを含むブラウザータブを持つだろう、フォーカス可能なウィジェットの階層構造は、ブラウザーウィンドウを含むかもしれない。The tab itself would have as its children the various links and text controls, as well as the dialog. The dialog itself would have as its children the text control and the button.

If the widget with focus in this example was the text control in the dialog box, then key input would be channeled from the graphical system to ① the Web browser, then to ② the tab, then to ③ the dialog, and finally to ④ the text control.

キーボードイベントは、常にこのフォーカスされた要素で対象にされる。

6.4.2 データモデル

用語フォーカス可能領域は、キーボード入力の対象になることができるインターフェイスの領域を参照するために使用される。フォーカス可能領域は、要素、要素の一部、またはユーザーエージェントによって処理される他の領域となることができる。

フォーカス可能領域は、DOMでフォーカス可能領域の位置を表すNodeオブジェクトである、DOMアンカーを持つ。(フォーカス可能領域Node自身である場合、それはそれ自身のDOM anchorである。)フォーカス可能領域を表すために他のDOMオブジェクトが存在しない場合、DOMアンカーは、フォーカス可能領域に適するようないくつかのAPIで使用される。

以下のテーブルは、どのオブジェクトがフォーカス可能領域となることができるかを説明する。左の列におけるセルは、フォーカス可能領域となることができるオブジェクトを説明する。右の列におけるセルは、この要素に対するDOMアンカーを説明する。(両方の列をまたぐセルは、非規範的な例である。)

フォーカス可能領域 DOMアンカー
実際に無効でない、明確に不活性でない、および描画されているまたは関連するキャンバスフォールバックコンテンツとして使用されているかのいずれかである、そのタブインデックスフォーカスフラグ設定を持つ要素 要素自身。

iframe<input type=text>、時に<a href=""> (プラットフォーム慣習に依存する)。

描画されているおよび明示的に不活性でないimg要素に関連するイメージマップにおけるarea要素の形状。 img要素

次の例において、それぞれ画像の、area要素は2つの形状を作成する。最初の形状のDOMアンカーは、最初のimg要素であり、2つめの形状のDOM anchorは、2つめのimg要素である。

<map id=wallmap><area alt="Enter Door" coords="10,10,100,200" href="door.html"></map>
...
<img src="images/innerwall.jpeg" alt="There is a white wall here, with a door." usemap="#wallmap">
...
<img src="images/outerwall.jpeg" alt="There is a red wall here, with a door." usemap="#wallmap">
要素のサブウィジェットを提供されるユーザーエージェントは、描画されているかつ実際に無効または明確に不活性でない。 フォーカス可能領域がサブウィジェットとなる要素。

video要素に対するユーザーに公開されるユーザーインターフェイスにおけるコントロール<input type=number>のスピンコントロールバージョンにおけるアップ・ダウンボタン、<input type=range multiple>における2つの範囲コントロールウィジェット、キーボード入力を用いた開くまたは閉じるために要素を有効にしたdetails要素のレンダリングの一部。

レンダリングされているかつ明確に不活性でない要素のスクロール可能な領域。 スクロール可能な領域のスクロールが作成されたボックスに対する要素

The CSS 'overflow' property's 'scroll' value typically creates a scrollable region.

ブラウジングコンテキストを持ちかつ不活性でないDocumentビューポート ビューポートが作成されたDocument

iframeのコンテンツ。

特にアクセシビリティーを支援する、またはよりプラットフォーム慣習にマッチする、任意の他の要素または要素の一部。 要素。

ユーザーエージェントがリスト項目弾丸をフォーカス可能にすることができ、その結果ユーザーはより簡単にリストをそうさすることができる。

同様に、ユーザーエージェントがtitle属性をもつすべての要素をフォーカス可能にすることができ、その結果要素の助言情報はアクセスされることができる。

ブラウジングコンテキストコンテナ(たとえばiframe)は、フォーカス可能領域であるが、ブラウジングコンテキストコンテナに送られるキーイベントは、ネストされたブラウジングコンテキストアクティブ文書に送られる。同様に、逐次的フォーカスナビゲーションにおいてブラウジングコンテキストコンテナは本質的にそのネストされるブラウジングコンテキストアクティブ文書に対するプレースホルダーとして単に動作する。


次はコントロールグループを作成する:

対応するDocumentオブジェクトまたはdialog要素が作成したコントロールグループ所有者オブジェクトである。(There is always a 1-to-1 mapping of control groups to control group owner objects.)

フォーカス可能領域は、次のとおりコントロールグループに属する。フォーカス可能領域DOMアンカーコントロールグループ所有者オブジェクトである場合、そのフォーカス可能領域は、そのコントロールグループ所有者オブジェクトコントロールグループに所属する。そうでなければ、フォーカス可能領域は、そのDOMアンカーの最も近い祖先コントロールグループ所有者オブジェクトコントロールグループに所属する。

Thus:

フォーカス可能領域がないようにするために、コントロールグループが空にすることは可能である。


An element is expressly inert if it is inert and its nearest ancestor control group owner object is not inert.

In a page with no dialog elements, all elements that are inert are expressly inert, and vice-versa.

Inside an inert dialog element, all descendant elements are not expressly inert, even if they are inert.

A dialog element is expressly inert if it is inert and not nested inside another inert dialog.


コントロールグループ所有者オブジェクトはまた、ダイアロググループ管理者として動作することができる。

open属性を指定されかつレンダリングされている(すなわち、コントロールグループ所有者オブジェクトである)かつ明示的に不活性でない各dialog要素は、管理者dialog要素の最も近い祖先コントロールグループ所有者オブジェクトであるダイアロググループに属する。

その最も近い祖先コントロールグループ所有者オブジェクトとしてdialog要素が特定のコントロールグループ所有者オブジェクトを持たない場合、そのコントロールグループ所有者オブジェクトは一切のダイアロググループを持たない。

ダイアロググループは、ダイアロググループのフォーカスされたダイアログと呼ばれるdialogを持つことができる。どのdialogがそのように呼ばれるかは時間とともに変化し、この仕様におけるアルゴリズムに基づく。

ダイアロググループにおける要素は、ツリー順で並べられる。


各空でないコントロールグループにおける1つのフォーカス可能領域は、コントロールグループの被フォーカス可能領域と呼ばれる。どのコントロールがそのように呼ばれるかは時間とともに変化し、この仕様におけるアルゴリズムに基づく。コントロールグループが空である場合、コントロールグループは被フォーカス領域を持たない。

コントロールグループにおけるフォーカス可能領域は、その領域のDOMアンカーツリー順に関連して並べられる。コントロールグループで同じDOMアンカーをもつフォーカス可能領域は、ボックスツリーの深さ優先走査でそのCSSボックスの関連する位置に関連して並べられる。[CSS]


特定の時間でトップレベルブラウジングコンテキストの現在の被フォーカス領域は、フォーカス可能領域またはこのアルゴリズムによって返されるdialogである。

  1. candidateトップレベルブラウジングコンテキストDocumentにする。

  2. candidateが指定されたダイアロググループの被フォーカスダイアログをともなうダイアロググループを持つ場合、candidateを指定されたダイアロググループの被フォーカスダイアログにし、このステップを再実行する。

    Otherwise, if candidate has a non-empty control group, and the designated focused area of the control group is a browsing context container with a non-null nested browsing context, then let candidate be the active document of that browsing context container's nested browsing context, and redo this step.

    そうでなければ、candidateが空でないコントロールグループを持つ場合、candidateを指定されたコントロールグループの被フォーカス領域にする。

  3. candidateを返す。

フォーカス可能領域DOMアンカーである要素は、フォーカス可能領域トップレベルブラウジングコンテキストの被フォーカス領域になる場合に利得フォーカスと呼ばれる。要素がトップレベルブラウジングコンテキストの現在の被フォーカス領域に属するフォーカス可能領域DOMアンカーである場合、要素は被フォーカスである。

The focus chain of a focusable area or control group owner object subject is the ordered list constructed as follows:

  1. Let current object be subject.

  2. Let output be an empty list.

  3. Loop: Append current object to output.

  4. If current object is an area element's shape, append that area element to output.

    Otherwise, if current object is a focusable area whose DOM anchor is an element that is not current object itself, append that DOM anchor element to output.

  5. If current object is a dialog object in a dialog group, let current object be that dialog group's manager, and return to the step labeled loop.

    Otherwise, if current object is a focusable area, let current object be that focusable area's control group's owner object, and return to the step labeled loop.

    Otherwise, if current object is a Document in a nested browsing context, let current object be its browsing context container, and return to the step labeled loop.

  6. Return output.

    The chain starts with subject and (if subject is or can be the currently focused area of a top-level browsing context) continues up the focus hierarchy up to the Document of the top-level browsing context.

6.4.3 tabindex属性

tabindexコンテンツ属性は、著者が、要素がフォーカスできることを仮定するかどうか、それが順次フォーカスナビゲーションを使用して到達することを仮定するかどうか、何がシーケンシャルフォーカスナビゲーションのための要素の相対的な順序になるかを指示できる。名前"tab index"は、フォーカス可能な要素を通してナビゲートする"tab"キーの一般的な使用方法から来ている。用語"tabbing"は、順次フォーカスナビゲーションを使用して到達することができるフォーカス可能な要素を前方に移動することを指す。

Support: tabindex-attrChrome 15+iOS Safari 3.2+Firefox 4+IE 7+Safari 5.1+Edge 12+Opera 9.5+

Source: caniuse.com

属性が省略される場合、ユーザーエージェントはデフォルトを適用する。(描画されている要素を利用不能にすることなしにまたは不活性にすることなしにフォーカス可能にさせる方法は存在しない。)

tabindex属性が指定される場合、妥当な整数である値を持たなければならない。正の数はシーケンシャルフォーカスナビゲーション順で要素のフォーカス可能領域の関連位置を指定し、負の数はシーケンシャルフォーカスナビゲーショによって到達不能となるコントロールを示す。

0または-1以外の値を使用している場合、開発者は、これが正しく行うために複雑になるよう、自身のtabindex属性に対して用心すべきである。

Each element can have a tabindex focus flag set, as defined below. This flag is a factor that contributes towards determining whether an element is a focusable area, as described in the previous section.

If the tabindex attribute is specified on an element, it must be parsed using the rules for parsing integers. The attribute's values, or lack thereof, must be interpreted as follows:

If the attribute is omitted or parsing the value returns an error

The user agent should follow platform conventions to determine if the element's tabindex focus flag is set and, if so, whether the element and any focusable areas that have the element as their DOM anchor can be reached using sequential focus navigation, and if so, what their relative position in the sequential focus navigation order is to be.

Modulo platform conventions, it is suggested that for the following elements, the tabindex focus flag be set:

If the value is a negative integer

The user agent must set the element's tabindex focus flag, but should omit the element from the sequential focus navigation order.

One valid reason to ignore the requirement that sequential focus navigation not allow the author to lead to the element would be if the user's only mechanism for moving the focus is sequential focus navigation. For instance, a keyboard-only user would be unable to click on a text control with a negative tabindex, so that user's user agent would be well justified in allowing the user to tab to the control regardless.

If the value is a zero

The user agent must set the element's tabindex focus flag, should allow the element and any focusable areas that have the element as their DOM anchor to be reached using sequential focus navigation, following platform conventions to determine the element's relative position in the sequential focus navigation order.

If the value is greater than zero

The user agent must set the element's tabindex focus flag, should allow the element and any focusable areas that have the element as their DOM anchor to be reached using sequential focus navigation, and should place the element — referenced as candidate below — and the aforementioned focusable areas in the sequential focus navigation order so that, relative to other focusable areas in the sequential focus navigation order, they are:

An element with the tabindex attribute specified is interactive content.

The tabIndex IDL attribute must reflect the value of the tabindex content attribute. Its default value is 0 for elements that are focusable and −1 for elements that are not focusable.

6.4.4 Processing model

The focusing steps for an object new focus target that is either a focusable area, or an element that is not a focusable area, or a browsing context, are as follows. They can optionally be run with a fallback target.

  1. If new focus target is neither a dialog element that has an open attribute specified and that is being rendered (i.e. that is a control group owner object), nor a focusable area, then run the first matching set of steps from the following list:

    If new focus target is an area element with one or more shapes that are focusable areas

    Let new focus target be the shape corresponding to the first img element in tree order that uses the image map to which the area element belongs.

    If new focus target is an element with one or more scrollable regions that are focusable areas

    Let new focus target be the element's first scrollable region, according to a pre-order, depth-first traversal of the box tree. [CSS]

    If new focus target is the document element of its Document

    Let new focus target be the Document's viewport.

    If new focus target is a browsing context

    Let new focus target be the browsing context's active document.

    If new focus target is a browsing context container with a non-null nested browsing context

    Let new focus target be the browsing context container's nested browsing context's active document.

    そうでなければ

    If no fallback target was specified, abort the focusing steps.

    Otherwise, let new focus target be the fallback target.

  2. If new focus target is a control group owner object that is not a focusable area, but does have a dialog group, and that dialog group has a designated focused dialog, then let new focus target be the focused dialog of the dialog group, and redo this step.

    Otherwise, if new focus target is a control group owner object that is not a focusable area, and its control group is not empty, then designate new focus target as the focused area of the control group, and redo this step.

    Otherwise, if new focus target is a browsing context container with non-null nested browsing context, then let new focus target be the nested browsing context's active document, and redo this step.

    A dialog element can be both a control group owner object and a focusable area, if it has both an open attribute specified and a tabindex attribute specified and is being rendered.

  3. If new focus target is a focusable area and its DOM anchor is inert, then abort these steps.

  4. If new focus target is the currently focused area of a top-level browsing context, then abort these steps.

  5. Let old chain be the focus chain of the currently focused area of the top-level browsing context in which new focus target finds itself.

  6. Let new chain be the focus chain of new focus target.

  7. Run the focus update steps with old chain, new chain, and new focus target respectively.

User agents must immediately run the focusing steps for a focusable area, dialog, or browsing context candidate whenever the user attempts to move the focus to candidate.

The unfocusing steps for an object old focus target that is either a focusable area or an element that is not a focusable area are as follows:

  1. If old focus target is inert, then abort these steps.

  2. If old focus target is an area element and one of its shapes is the currently focused area of a top-level browsing context, or, if old focus target is an element with one or more scrollable regions, and one of them is the currently focused area of a top-level browsing context, then let old focus target be that currently focused area of a top-level browsing context.

  3. Let old chain be the focus chain of the currently focused area of a top-level browsing context.

  4. If old focus target is not one of the entries in old chain, then abort these steps.

  5. If old focus target is a dialog in a dialog group, and the dialog group manager has a non-empty control group, then let new focus target be the designated focused area of that focus group.

    Otherwise, if old focus target is a focusable area, then let new focus target be the first focusable area of its control group (if the control group owner object is a Document, this will always be a viewport).

    Otherwise, let new focus target be null.

  6. If new focus target is not null, then run the focusing steps for new focus target.

When the currently focused area of a top-level browsing context is somehow unfocused without another element being explicitly focused in its stead, the user agent must immediately run the unfocusing steps for that object.

The unfocusing steps do not always result in the focus changing, even when applied to the currently focused area of a top-level browsing context. For example, if the currently focused area of a top-level browsing context is a viewport, then it will usually keep its focus regardless until another focusable area is explicitly focused with the focusing steps.


When a focusable area is added to an empty control group, it must be designated the focused area of the control group.

When a dialog group is formed, if the dialog group manager has an empty control group, the first non-inert dialog in the dialog group, if any, or else the first dialog in the dialog group regardless of inertness, must be designated the focused dialog of the dialog group.

Focus fixup rule one: When the designated focused area of a control group is removed from that control group in some way (e.g. it stops being a focusable area, it is removed from the DOM, it becomes expressly inert, etc), and the control group is still not empty: designate the first non-inert focusable area in that control group to be the new focused area of the control group, if any; if they are all inert, then designate the first focusable area in that control group to be the new focused area of the control group regardless of inertness. If such a removal instead results in the control group being empty, then there is simply no longer a focused area of the control group.

For example, this might happen because an element is removed from its Document, or has a hidden attribute added. It might also happen to an input element when the element gets disabled.

In a Document without dialog elements, whose focused area is a button element, removing, disabling, or hiding that button would cause the page's new focused area to be the viewport of the Document. This would, in turn, be reflected through the activeElement API as the body element.

Focus fixup rule two: When a dialog group has no designated focused dialog of the dialog group, and its dialog group manager's control group changes from being non-empty to being empty, the first non-inert dialog in the dialog group, if any, or else the first dialog in the dialog group regardless of inertness, must be designated the focused dialog of the dialog group.

Focus fixup rule three: When the designated focused dialog of a dialog group is removed from that dialog group in some way (e.g. it stops being rendered, it loses its open attribute, it becomes expressly inert, etc), and there is still a dialog group (because the dialog in question was not the last dialog in that dialog group): if the dialog group's manager's control group is non-empty, let there be no designated focused dialog of the dialog group any more; otherwise (in the case that the control group is empty), designate the first non-inert dialog in the dialog group to be the focused dialog of the dialog group, or, if they are all inert, designate the first dialog in the dialog group to be the focused dialog of the dialog group regardless of inertness.

When the currently focused area of a top-level browsing context was a focusable area but stops being a focusable area, or when it was a dialog in a dialog group and stops being part of that dialog group, or when it starts being inert, the user agent must run the following steps:

  1. Let old focus target be whatever the currently focused area of the top-level browsing context was immediately before this algorithm became applicable (e.g. before the element was disabled, or the dialog was closed, or whatever caused this algorithm to run).

  2. Let old chain be the focus chain of the currently focused area of the top-level browsing context at the same time.

  3. Make sure that the changes implied by the focus fixup rules one, two, and three above are applied.

  4. Let new focus target be the currently focused area of a top-level browsing context.

  5. If old focus target and new focus target are the same, abort these steps.

  6. Let new chain be the focus chain of new focus target.

  7. Run the focus update steps with old chain, new chain, and new focus target respectively.


The focus update steps, given an old chain, a new chain, and a new focus target respectively, are as follows:

  1. If the last entry in old chain and the last entry in new chain are the same, pop the last entry from old chain and the last entry from new chain and redo this step.

  2. For each entry entry in old chain, in order, run these substeps:

    1. If entry is an input element, and the change event applies to the element, and the element does not have a defined activation behavior, and the user has changed the element's value or its list of selected files while the control was focused without committing that change (such that it is different to what it was when the control was first focused), then fire an event named change at the element, with the bubbles attribute initialized to true.

    2. If entry is an element, let blur event target be entry.

      If entry is a Document object, let blur event target be that Document object's Window object.

      Otherwise, let blur event target be null.

    3. If entry is the last entry in old chain, and entry is an Element, and the last entry in new chain is also an Element, then let related blur target be the last entry in new chain. Otherwise, let related blur target be null.

    4. If blur event target is not null, fire a focus event named blur at blur event target, with related blur target as the related target.

      In some cases, e.g. if entry is an area element's shape, a scrollable region, or a viewport, no event is fired.

  3. Apply any relevant platform-specific conventions for focusing new focus target. (For example, some platforms select the contents of a text control when that control is focused.)

  4. For each entry entry in new chain, in reverse order, run these substeps:

    1. If entry is a dialog element: let entry be the designated focused dialog of its dialog group.

    2. If entry is a focusable area: designate entry as the focused area of the control group. If its control group's owner object is also a dialog group manager, then let there be no designated focused dialog in that dialog group.

      It is possible for entry to be both a dialog element and a focusable area, in which case it is its own control group owner object.

    3. If entry is an element, let focus event target be entry.

      If entry is a Document object, let focus event target be that Document object's Window object.

      Otherwise, let focus event target be null.

    4. If entry is the last entry in new chain, and entry is an Element, and the last entry in old chain is also an Element, then let related focus target be the last entry in old chain. Otherwise, let related focus target be null.

    5. If focus event target is not null, fire a focus event named focus at focus event target, with related focus target as the related target.

      In some cases, e.g. if entry is an area element's shape, a scrollable region, or a viewport, no event is fired.

To fire a focus event named e at an element t and with a given related target r, fire an event named e at t, using FocusEvent, with the relatedTarget attribute initialized to r and the view attribute initialized to t's node document's Window object.


When a key event is to be routed in a top-level browsing context, the user agent must run the following steps:

  1. Let target area be the currently focused area of the top-level browsing context.

  2. If target area is a focusable area, let target node be target area's DOM anchor. Otherwise, target area is a dialog; let target node be target area.

  3. If target node is a Document that has a body element, then let target node be the body element of that Document.

    Otherwise, if target node is a Document object that has a non-null document element, then let target node be that document element.

  4. If target node is not inert, then:

    It is possible for the currently focused area of a top-level browsing context to be inert, for example if a modal dialog is shown, and then that dialog element is made inert. It is likely to be the result of a logic error in the application, though.

    1. Let canHandle be the result of dispatching the key event at target node.

    2. If canHandle is true, then let target area handle the key event. This might include firing a click event at target node.


The has focus steps, given a Document object target, are as follows:

  1. candidateトップレベルブラウジングコンテキストDocumentにする。

  2. If candidate is target, return true and abort these steps.

  3. candidateが指定されたダイアロググループの被フォーカスダイアログをともなうダイアロググループを持つ場合、candidateを指定されたダイアロググループの被フォーカスダイアログにし、このステップを再実行する。

    Otherwise, if candidate has a non-empty control group, and the designated focused area of the control group is a browsing context container with a non-null nested browsing context, and the active document of that browsing context container's nested browsing context is target, then return true and abort these steps.

    Otherwise, if candidate has a non-empty control group, and the designated focused area of the control group is a browsing context container with a non-null nested browsing context, then let candidate be the active document of that browsing context container's nested browsing context, and redo this step.

    Otherwise, return false and abort these steps.

6.4.5 シーケンシャルフォーカスナビゲーション

Each control group has a sequential focus navigation order, which orders some or all of the focusable areas in the control group relative to each other. The order in the sequential focus navigation order does not have to be related to the order in the control group itself. If a focusable area is omitted from the sequential focus navigation order of its control group, then it is unreachable via sequential focus navigation.

There can also be a sequential focus navigation starting point. It is initially unset. The user agent may set it when the user indicates that it should be moved.

For example, the user agent could set it to the position of the user's click if the user clicks on the document contents.

When the user requests that focus move from the currently focused area of a top-level browsing context to the next or previous focusable area (e.g. as the default action of pressing the tab key), or when the user requests that focus sequentially move to a top-level browsing context in the first place (e.g. from the browser's location bar), the user agent must use the following algorithm:

  1. Let starting point be the currently focused area of a top-level browsing context, if the user requested to move focus sequentially from there, or else the top-level browsing context itself, if the user instead requested to move focus from outside the top-level browsing context.

  2. If there is a sequential focus navigation starting point defined and it is inside starting point, then let starting point be the sequential focus navigation starting point instead.

  3. Let direction be forward if the user requested the next control, and backward if the user requested the previous control.

    Typically, pressing tab requests the next control, and pressing shift+tab requests the previous control.

  4. Loop: Let selection mechanism be sequential if the starting point is a browsing context or if starting point is in its control group's sequential focus navigation order.

    Otherwise, starting point is not in its control group's sequential focus navigation order; let selection mechanism be DOM.

  5. Let candidate be the result of running the sequential navigation search algorithm with starting point, direction, and selection mechanism as the arguments.

  6. If candidate is not null, then run the focusing steps for candidate and abort these steps.

  7. Otherwise, unset the sequential focus navigation starting point.

  8. If starting point is the top-level browsing context, or a focusable area in the top-level browsing context, the user agent should transfer focus to its own controls appropriately (if any), honouring direction, and then abort these steps.

    For example, if direction is backward, then the last focusable control before the browser's rendering area would be the control to focus.

    If the user agent has no focusable controls — a kiosk-mode browser, for instance — then the user agent may instead restart these steps with the starting point being the top-level browsing context itself.

  9. Otherwise, starting point is a focusable area in a nested browsing context. Let starting point be that nested browsing context's browsing context container, and return to the step labeled loop.

The sequential navigation search algorithm consists of the following steps. This algorithm takes three arguments: starting point, direction, and selection mechanism.

  1. Pick the appropriate cell from the following table, and follow the instructions in that cell.

    The appropriate cell is the one that is from the column whose header describes direction and from the first row whose header describes starting point and selection mechanism.

    direction is forward direction is backward
    starting point is a browsing context Let candidate be the first suitable sequentially focusable area in starting point's active document's primary control group, if any; or else null Let candidate be the last suitable sequentially focusable area in starting point's active document's primary control group, if any; or else null
    selection mechanism is DOM Let candidate be the first suitable sequentially focusable area in the home control group following starting point, if any; or else null Let candidate be the last suitable sequentially focusable area in the home control group preceding starting point, if any; or else null
    selection mechanism is sequential Let candidate be the first suitable sequentially focusable area in the home sequential focus navigation order following starting point, if any; or else null Let candidate be the last suitable sequentially focusable area in the home sequential focus navigation order preceding starting point, if any; or else null

    A suitable sequentially focusable area is a focusable area whose DOM anchor is not inert and that is in its control group's sequential focus navigation order.

    The primary control group of a control group owner object X is the control group of X if X has no dialog group or if its dialog group has no designated focused dialog of the dialog group, otherwise, it is the primary control group of X's dialog group's designated focused dialog of the dialog group.

    The home control group is the control group to which starting point belongs.

    The home sequential focus navigation order is the sequential focus navigation order to which starting point belongs.

    The home sequential focus navigation order is the home control group's sequential focus navigation order, but is only used when the starting point is in that sequential focus navigation order (when it's not, selection mechanism will be DOM).

  2. If candidate is a browsing context container with a non-null nested browsing context, then let new candidate be the result of running the sequential navigation search algorithm with candidate's nested browsing context as the first argument, direction as the second, and sequential as the third.

    If new candidate is null, then let starting point be candidate, and return to the top of this algorithm. Otherwise, let candidate be new candidate.

  3. candidateを返す。

6.4.6 フォーカス管理API

document . activeElement

キーイベントが送られるまたは送る文書における最も深い要素を返す。大まかに言って、これは文書における被フォーカス要素である。

このAPIのために、子ブラウジングコンテキストが被フォーカスである場合、そのブラウジングコンテキストコンテナ親ブラウジングコンテキスト被フォーカスである。For example, if the user moves the focus to a text control in an iframe, the iframe is the element returned by the activeElement API in the iframe's node document.

document . hasFocus()

キーイベントが文書を通してまたは文書に向かって送られる場合にtrueを返し、そうでなければfalseを返す。大まかに言って、これは文書、この内側でネストされた文書、被フォーカスに対応する。

window . focus()

可能であれば、フォーカスをウィンドウのブラウジングコンテキストに移動する。

element . focus()

フォーカスを要素に移動する。

要素がブラウジングコンテキストコンテナである場合、代わりにネストされたブラウジングコンテキストにフォーカスを移動する。

element . blur()

フォーカスをビューポートに移動する。このメソッドの使用が妨げられ、ビューポートにフォーカスしたい場合、Document文書要素上のfocus()メソッドを呼び出す。

見苦しいフォーカスリングを発見する場合、フォーカスリングを非表示にするためにこの方法を使用してはならない。代わりに、'outline'プロパティを上書きするためにCSS規則を使用し、要素がフォーカスされるものを表示する別の方法を提供する。代替フォーカススタイルが利用可能にならないか、ページが主にキーボードを使用してページをナビゲートする人に対して著しく使用可能にならないか、ページをナビゲートするのに役立つフォーカスアウトラインを使う人の刺客を減少させないかどうかに注意する。

たとえば、リンクからアウトラインを隠し、代わりにフォーカスを示すために黄色の背景を使用するために、次を使うことができる:

:link:focus, :visited:focus { outline: none; background: yellow; color: black; }

The activeElement attribute on Document objects must return the value returned by the following steps:

  1. Let candidate be the Document on which the method was invoked.

  2. candidateが指定されたダイアロググループの被フォーカスダイアログをともなうダイアロググループを持つ場合、candidateを指定されたダイアロググループの被フォーカスダイアログにし、このステップを再実行する。

  3. If candidate has a non-empty control group, let candidate be the designated focused area of the control group.

  4. If candidate is a focusable area, let candidate be candidate's DOM anchor.

  5. If candidate is a Document that has a body element, then let candidate be the body element of that Document.

    Otherwise, if candidate is a Document with a non-null document element, then let candidate be that document element.

    Otherwise, if candidate is a Document, then let candidate be null.

  6. candidateを返す。

The hasFocus() method on the Document object, when invoked, must return the result of running the has focus steps with the Document object as the argument.

The focus() method on the Window object, when invoked, must run the focusing steps with the Window object's browsing context. Additionally, if this browsing context is a top-level browsing context, user agents are encouraged to trigger some sort of notification to indicate to the user that the page is attempting to gain focus.

The blur() method on the Window object, when invoked, provides a hint to the user agent that the script believes the user probably is not currently interested in the contents of the browsing context of the Window object on which the method was invoked, but that the contents might become interesting again in the future.

User agents are encouraged to ignore calls to this blur() method entirely.

Historically, the focus() and blur() methods actually affected the system-level focus of the system widget (e.g. tab or window) that contained the browsing context, but hostile sites widely abuse this behavior to the user's detriment.

The focus() method on elements, when invoked, must run the following algorithm:

  1. If the element is marked as locked for focus, then abort these steps.

  2. Mark the element as locked for focus.

  3. Run the focusing steps for the element.

  4. Unmark the element as locked for focus.

The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called. User agents may selectively or uniformly ignore calls to this method for usability reasons.

For example, if the blur() method is unwisely being used to remove the focus ring for aesthetics reasons, the page would become unusable by keyboard users. Ignoring calls to this method would thus allow keyboard users to interact with the page.

6.5 キーボードショートカットの割り当て

6.5.1 導入

この節は非規範的である。

アクティブまたはフォーカスさせることができる各要素はaccesskey属性を使用して、それをアクティブにするための単一のキーの組み合わせを割り当てることができる。

正確なショートカットは、ユーザーエージェントによって決定され、ユーザーのキーボードに関する情報に基づき、どのキーボードショートカットが既にプラットフォーム上に存在し、他にどのようなショートカットがページ上で指定され、ガイドとしてaccesskey属性に提供された情報を使用する。

関連するキーボードショートカットが多種多様な入力デバイスで利用可能であることを確実にするために、著者はaccesskey属性で多数の選択肢を提供できる。

各選択肢は、文字または数字のような、単一の文字で構成される。

ユーザーエージェントは、キーボードショートカットの一覧をユーザーに提供できるが、著者は行うことも推奨される。accessKeyLabel IDL属性は、ユーザーエージェントによって割り当てられた実際のキーの組み合わせを表す文字列を返す。

この例において、著者はショートカットキーを使用して呼び出すことができるボタンを提供してきた。フルキーボードをサポートするために、著者は可能なキーとして"C"を提供している。テンキーのみを搭載したデバイスをサポートするために、著者は別の可能なキーとして"1"を提供している。

<input type=button value=Collect onclick="collect()"
       accesskey="C 1" id=c>

ショートカットキーが何であるかをユーザーに伝えるために、著者は明示的にボタンのラベルにキーの組み合わせを追加するために選択しているここでのこのスクリプトを持つ。

function addShortcutKeyLabel(button) {
  if (button.accessKeyLabel != '')
    button.value += ' (' + button.accessKeyLabel + ')';
}
addShortcutKeyLabel(document.getElementById('c'));

異なるプラットフォーム上のブラウザーは、たとえ同じキーの組み合わせであっても、そのプラットフォーム上で普及している規則に基づいて異なるラベルを表示する。たとえば、キーの組み合わせが、Controlキー、Shiftキー、および文字Cである場合、Macのブラウザーが"^⇧C"を表示するかもしれない一方で、Windowsのブラウザーは"Ctrl+Shift+C"を表示するかもしれない。一方でEmacsのブラウザーは単に"C-C"を表示するかもしれない。同様に、キーの組み合わせがAltキーとEscキーである場合、Windowsは"Alt+Esc"を使用するかもしれず、Macは"⌥⎋"を使用するかもしれず、Emacsのブラウザーは、"M-ESC"または"ESC ESC"を使用するかもしれない。

したがって、一般に、accessKeyLabel IDL属性から返された値を解析しようとするのは賢明ではない。

6.5.2 accesskey属性

すべてのHTML要素は、accesskeyコンテンツ属性の設定を持ってもよい。accesskey属性値は、要素をアクティブまたはフォーカスするキーボードショートカットを作成するためのガイドとして、ユーザーエージェントによって使用される。

指定される場合、値は大文字・小文字区別である一意なスペース区切りトークンの順序付き集合でなければならず、その各々が正確に1つのUnicodeコードポイントの長さでなければならない。

次の例において、サイトを熟知するキーボードユーザーがより迅速に関連するページに移動できるよう、さまざまなリンクがアクセスキーとともに与えられる:

<nav>
 <p>
  <a title="Consortium Activities" accesskey="A" href="/Consortium/activities">Activities</a> |
  <a title="Technical Reports and Recommendations" accesskey="T" href="/TR/">Technical Reports</a> |
  <a title="Alphabetical Site Index" accesskey="S" href="/Consortium/siteindex">Site Index</a> |
  <a title="About This Site" accesskey="B" href="/Consortium/">About Consortium</a> |
  <a title="Contact Consortium" accesskey="C" href="/Consortium/contact">Contact</a>
 </p>
</nav>

次の例において、検索フィールドは2つの可能なアクセスキー、"s"と"0"(この順番で)が与えられる。テンキー付きの小さなデバイス上のユーザーエージェントは単なる簡素なキー0を選ぶかもしれないが、フルキーボードを搭載したデバイスでのユーザーエージェントは、ショートカットキーとしてCtrl+Alt+Sを選ぶかもしれない:

<form action="/search">
 <label>Search: <input type="search" name="q" accesskey="s 0"></label>
 <input type="submit">
</form>

次の例において、ボタンは説明可能なアクセスキーを持つ。このスクリプトは次に、ユーザーエージェントが選択したキーの組み合わせを通知するためにボタンのラベルの更新を試みる。

<input type=submit accesskey="N @ 1" value="Compose">
...
<script>
 function labelButton(button) {
   if (button.accessKeyLabel)
     button.value += ' (' + button.accessKeyLabel + ')';
 }
 var inputs = document.getElementsByTagName('input');
 for (var i = 0; i < inputs.length; i += 1) {
   if (inputs[i].type == "submit")
     labelButton(inputs[i]);
 }
</script>

あるユーザーエージェントにおいて、ボタンのラベルは"Compose(⌘N)"になるかもしれない。別のものにおいて、これは"Compose(Alt+⇧+1)"になるかもしれない。ユーザーエージェントがキーを割り当てない場合、単に"Compose"になる。正確な文字列は割り当てられるアクセスキーが何であるか、およびどのようにユーザーエージェントがそのキーの組み合わせを表すかに依存する。

6.5.3 Processing model

An element's assigned access key is a key combination derived from the element's accesskey content attribute. Initially, an element must not have an assigned access key.

Whenever an element's accesskey attribute is set, changed, or removed, the user agent must update the element's assigned access key by running the following steps:

  1. If the element has no accesskey attribute, then skip to the fallback step below.

  2. Otherwise, split the attribute's value on ASCII whitespace, and let keys be the resulting tokens.

  3. For each value in keys in turn, in the order the tokens appeared in the attribute's value, run the following substeps:

    1. If the value is not a string exactly one Unicode code point in length, then skip the remainder of these steps for this value.

    2. If the value does not correspond to a key on the system's keyboard, then skip the remainder of these steps for this value.

    3. If the user agent can find a mix of zero or more modifier keys that, combined with the key that corresponds to the value given in the attribute, can be used as the access key, then the user agent may assign that combination of keys as the element's assigned access key and abort these steps. (This is a fingerprinting vector.)

  4. Fallback: Optionally, the user agent may assign a key combination of its choosing as the element's assigned access key and then abort these steps.

  5. If this step is reached, the element has no assigned access key.

Once a user agent has selected and assigned an access key for an element, the user agent should not change the element's assigned access key unless the accesskey content attribute is changed or the element is moved to another Document.

When the user presses the key combination corresponding to the assigned access key for an element, if the element defines a command, the command's Hidden State facet is false (visible), the command's Disabled State facet is also false (enabled), the element is in a document that has a browsing context, and neither the element nor any of its ancestors has a hidden attribute specified, then the user agent must trigger the Action of the command.

User agents might expose elements that have an accesskey attribute in other ways as well, e.g. in a menu displayed in response to a specific key combination.


The accessKey IDL attribute must reflect the accesskey content attribute.

The accessKeyLabel IDL attribute must return a string that represents the element's assigned access key, if any. If the element does not have one, then the IDL attribute must return the empty string.

6.6 編集

6.6.1 編集可能な文書領域を作成する:contenteditableコンテンツ属性

Support: contenteditableChrome for Android 56+Chrome 4+iOS Safari 5.0+UC Browser for Android 11+Firefox 3.5+IE 5.5+Samsung Internet 4+Opera Mini NoneAndroid Browser 3+Safari 3.1+Edge 12+Opera 9+

Source: caniuse.com

[NoInterfaceObject]
interface ElementContentEditable {
  [CEReactions] attribute DOMString contentEditable;
  readonly attribute boolean isContentEditable;
};

contenteditableコンテンツ属性は、キーワードが空文字列、true、おとびfalseとなる列挙属性である。空の文字列およびtrueキーワードは、true状態に対応する。falseキーワードは、false状態に対応する。さらに、inherit状態という第3の状態が存在する。これは欠損値のデフォルト(および不正な値のデフォルト)である。

true状態は、要素が編集可能であることを示す。inherit状態は、その親が存在する場合、要素が編集可能であることを示す。false状態は、要素が編集可能でないことを示す。

たとえば、ユーザーがHTMLを使用する記事を書くことが期待される、新しい記事を公開するためにformおよびtextareaを持つページを考えてみる:

<form method=POST>
 <fieldset>
  <legend>New article</legend>
  <textarea name=article>&lt;p>Hello world.&lt;/p></textarea>
 </fieldset>
 <p><button>Publish</button></p>
</form>

When scripting is enabled, the textarea element could be replaced with a rich text control instead, using the contenteditable attribute:

<form method=POST>
 <fieldset>
  <legend>New article</legend>
  <textarea id=textarea name=article>&lt;p>Hello world.&lt;/p></textarea>
  <div id=div style="white-space: pre-wrap" hidden><p>Hello world.</p></div>
  <script>
   let textarea = document.getElementById("textarea");
   let div = document.getElementById("div");
   textarea.hidden = true;
   div.hidden = false;
   div.contentEditable = "true";
   div.oninput = (e) => {
     textarea.value = div.innerHTML;
   };
  </script>
 </fieldset>
 <p><button>Publish</button></p>
</form>

たとえば挿入リンクを挿入する機能は、document.execCommand()APIを使用する、またはSelectionAPIおよび他のDOM APIを使用して実装することができる。[EXECCOMMAND] [SELECTION] [DOM]

contenteditable属性はまた、大きな効果を使用することができる:

<!doctype html>
<html lang=en>
<title>Live CSS editing!</title>
<style style=white-space:pre contenteditable>
html { margin:.2em; font-size:2em; color:lime; background:purple }
head, title, style { display:block }
body { display:none }
</style>
element . contentEditable [ = value ]

contenteditable属性の状態に基づいて、"true"、"false"、または"inherit"を返す。

その状態を変更する設定が可能である。

新しい値がこれらの文字列のいずれかでない場合、"SyntaxError" DOMExceptionを投げる。

element . isContentEditable

要素が編集可能な場合にtrueを返す。そうでなければfalseを返す。

The contentEditable IDL attribute, on getting, must return the string "true" if the content attribute is set to the true state, "false" if the content attribute is set to the false state, and "inherit" otherwise. On setting, if the new value is an ASCII case-insensitive match for the string "inherit" then the content attribute must be removed, if the new value is an ASCII case-insensitive match for the string "true" then the content attribute must be set to the string "true", if the new value is an ASCII case-insensitive match for the string "false" then the content attribute must be set to the string "false", and otherwise the attribute setter must throw a "SyntaxError" DOMException.

The isContentEditable IDL attribute, on getting, must return true if the element is either an editing host or editable, and false otherwise.

6.6.2 Making entire documents editable: the designMode IDL attribute

Documents have a designMode, which can be either enabled or disabled.

document . designMode [ = value ]

文書が編集可能である場合に"on"を返し、ない場合に"off"を返す。

文書の現在の状態を変更する設定が可能である。これは、文書をフォーカスし、その文書で文書の選択をリセットする。

The designMode IDL attribute on the Document object takes two values, "on" and "off". On setting, the new value must be compared in an ASCII case-insensitive manner to these two values; if it matches the "on" value, then designMode must be enabled, and if it matches the "off" value, then designMode must be disabled. Other values must be ignored.

On getting, if designMode is enabled, the IDL attribute must return the value "on"; otherwise it is disabled, and the attribute must return the value "off".

The last state set must persist until the document is destroyed or the state is changed. Initially, documents must have their designMode disabled.

When the designMode changes from being disabled to being enabled, the user agent must immediately reset the document's active range's start and end boundary points to be at the start of the Document and then run the focusing steps for the document element of the Document, if non-null.

6.6.3 ページ内編集者のためのベストプラクティス

著者は、もともと値'pre-wrap'へこれら編集のメカニズムを介して作成された編集ホストおよびマークアップ上の'white-space'プロパティを設定することを奨める。デフォルトのHTML空白処理は、あまりWYSIWYG編集に向かず、そして'white-space'がデフォルト値のままである場合、いくつかのコーナーの場合において、行の折り返しは正しく動作しない。

デフォルト'normal'値が代わりに使用される場合に発生する問題の例として、単語の間に2つのスペース(ここでは"␣"によって表される)とともに、"yellow␣␣ball"と入力したユーザーの場合を考える。'white-space'のデフォルト値('normal')のための場所での編集規則ともに、結果のマークアップは、"yellow&nbsp; ball"または"yellow &nbsp;ball"のいずれかで構成される。すなわち、2つの単語間の非開票スペースに加えて、通常スペースが存在する。'white-space'に対する'normal'値は共に相殺するために隣接する通常スペースを必要とするため、これは必要である。

前者の場合において、たとえ行の末尾で"yellow"単独で一致するとしても、"yellow⍽"は次の行("⍽"は非改行スペースを表すためにここで使用されている)に折り返す。後者の場合において、行の先頭に包まれる場合、"⍽ball"は非改行スペース由来の可視インデントを持つだろう。

しかし、'white-space'が'pre-wrap'に設定される場合、編集規則は、代わりに単に単語間に2つの通常のスペースを置き、2つの単語が行末で分割されるべきであり、スペースはレンダリングから削除されてきれいになる。

6.6.4 編集API

用語アクティブ範囲編集ホスト、および編集可能の定義、編集ホストまたは編集可能である要素のユーザーインターフェイス要件、execCommand()queryCommandEnabled()queryCommandIndeterm()queryCommandState()queryCommandState()queryCommandSupported()、およびqueryCommandValue()メソッド、テキスト選択、および選択削除アルゴリズムは、execCommandで定義される。[EXECCOMMAND]

6.6.5 スペルと文法チェック

Support: spellcheck-attributeChrome for Android (limited) 56+Chrome 9+iOS Safari (limited) 3.2+UC Browser for Android (limited) 11+Firefox 2+IE 10+Samsung Internet (limited) 4+Opera Mini (limited) all+Android Browser (limited) 2.1+Safari 5.1+Edge 12+Opera 10.5+

Source: caniuse.com

User agents can support the checking of spelling and grammar of editable text, either in form controls (such as the value of textarea elements), or in elements in an editing host (e.g. using contenteditable).

For each element, user agents must establish a default behavior, either through defaults or through preferences expressed by the user. There are three possible default behaviors for each element:

true-by-default
The element will be checked for spelling and grammar if its contents are editable and spellchecking is not explicitly disabled through the spellcheck attribute.
false-by-default
The element will never be checked for spelling and grammar unless spellchecking is explicitly enabled through the spellcheck attribute.
inherit-by-default
The element's default behavior is the same as its parent element's. Elements that have no parent element cannot have this as their default behavior.

spellcheck属性は、キーワードが空文字列、trueおよびfalseとなる列挙属性である。空の文字列およびtrueキーワードは、true状態に対応する。falseキーワードは、false状態に対応する。さらに、default状態という第3の状態が存在する。これは欠損値のデフォルト(および不正な値のデフォルト)である。

true状態は、要素がそのスペルおよび文法チェックを持つことを示す。default状態は、以下で定義されるように、親要素の独自のspellcheck状態におそらく基づいて、デフォルトの動作に応じて動作する要素であることを示す。false状態は、要素がチェックされないことを示す。


element . spellcheck [ = value ]

要素がスペルや文法チェックを持つ場合はtrueを返す。そうでなければfalseを返す。

デフォルトを上書きしてspellcheckコンテンツ属性を設定するための、設定が可能である。

element . forceSpellCheck()

ユーザーが要素にフォーカスを当てたことがない場合でも、(チェックが有効である場合)要素のスペルと文法エラーを報告することをユーザーエージェントに強制する。(メソッドが呼び出されない場合、ユーザーエージェントは、単にユーザーによって入力されなかったテキストのエラーを非表示にできる。)

The spellcheck IDL attribute, on getting, must return true if the element's spellcheck content attribute is in the true state, or if the element's spellcheck content attribute is in the default state and the element's default behavior is true-by-default, or if the element's spellcheck content attribute is in the default state and the element's default behavior is inherit-by-default and the element's parent element's spellcheck IDL attribute would return true; otherwise, if none of those conditions applies, then the attribute must instead return false.

The spellcheck IDL attribute is not affected by user preferences that override the spellcheck content attribute, and therefore might not reflect the actual spellchecking state.

On setting, if the new value is true, then the element's spellcheck content attribute must be set to the literal string "true", otherwise it must be set to the literal string "false".


User agents must only consider the following pieces of text as checkable for the purposes of this feature:

For text that is part of a Text node, the element with which the text is associated is the element that is the immediate parent of the first character of the word, sentence, or other piece of text. For text in attributes, it is the attribute's element. For the values of input and textarea elements, it is the element itself.

To determine if a word, sentence, or other piece of text in an applicable element (as defined above) is to have spelling- and grammar-checking enabled, the UA must use the following algorithm:

  1. If the user has disabled the checking for this text, then the checking is disabled.
  2. Otherwise, if the user has forced the checking for this text to always be enabled, then the checking is enabled.
  3. Otherwise, if the element with which the text is associated has a spellcheck content attribute, then: if that attribute is in the true state, then checking is enabled; otherwise, if that attribute is in the false state, then checking is disabled.
  4. Otherwise, if there is an ancestor element with a spellcheck content attribute that is not in the default state, then: if the nearest such ancestor's spellcheck content attribute is in the true state, then checking is enabled; otherwise, checking is disabled.
  5. Otherwise, if the element's default behavior is true-by-default, then checking is enabled.
  6. Otherwise, if the element's default behavior is false-by-default, then checking is disabled.
  7. Otherwise, if the element's parent element has its checking enabled, then checking is enabled.
  8. Otherwise, checking is disabled.

If the checking is enabled for a word/sentence/text, the user agent should indicate spelling and grammar errors in that text. User agents should take into account the other semantics given in the document when suggesting spelling and grammar corrections. User agents may use the language of the element to determine what spelling and grammar rules to use, or may use the user's preferred language settings. UAs should use input element attributes such as pattern to ensure that the resulting value is valid, where possible.

If checking is disabled, the user agent should not indicate spelling or grammar errors for that text.

Even when checking is enabled, user agents may opt to not report spelling or grammar errors in text that the user agent deems the user has no interest in having checked (e.g. text that was already present when the page was loaded, or that the user did not type, or text in controls that the user has not focused, or in parts of e-mail addresses that the user agent is not confident were misspelt). The forceSpellCheck() method, when invoked on an element, must override this behavior, forcing the user agent to consider all spelling and grammar errors in text in that element for which checking is enabled to be of interest to the user.

The element with ID "a" in the following example would be the one used to determine if the word "Hello" is checked for spelling errors. In this example, it would not be.

<div contenteditable="true">
 <span spellcheck="false" id="a">Hell</span><em>o!</em>
</div>

The element with ID "b" in the following example would have checking enabled (the leading space character in the attribute's value on the input element causes the attribute to be ignored, so the ancestor's value is used instead, regardless of the default).

<p spellcheck="true">
 <label>Name: <input spellcheck=" false" id="b"></label>
</p>

この仕様は、スペルや文法チェッカーに対するユーザーインターフェイスを定義しない。ユーザーエージェントはオンデマンドチェックを提供するかもしれず、チェックが有効である間に連続的なチェックを実行するかもしれず、または他のインターフェイスを使用するかもしれない。

6.7 ドラッグアンドドロップ

Support: dragndropChrome for Android NoneChrome 4+iOS Safari NoneUC Browser for Android NoneFirefox 3.5+IE (limited) 5.5+Samsung Internet NoneOpera Mini NoneAndroid Browser NoneSafari 3.1+Edge (limited) 12+Opera 12+

Source: caniuse.com

このセクションは、イベントベースのドラッグアンドドロップのメカニズムを定義する。

この仕様は、ドラッグアンドドロップ操作が実際に何であるかを正確に定義しない。

ポインティングデバイスをもつ視覚メディア上に、ドラッグ操作は一連のmousemoveイベントが続くmousedownイベントのデフォルトアクションであるかもしれず、ドロップは解放されているマウスによって引き起こされるかもしれない。

ポインティングデバイス以外の入力モダリティを使用する場合、ユーザーはおそらくドラッグアンドドロップ操作を実行するために明示的に意思表示する必要があり、それらがドラッグを望み、ドロップを望む場所を、それぞれ主張する。

However it is implemented, drag-and-drop operations must have a starting point (e.g. where the mouse was clicked, or the start of the selection or element that was selected for the drag), may have any number of intermediate steps (elements that the mouse moves over during a drag, or elements that the user picks as possible drop points as they cycle through possibilities), and must either have an end point (the element above which the mouse button was released, or the element that was finally selected), or be canceled. The end point must be the last element selected as a possible drop point before the drop occurs (so if the operation is not canceled, there must be at least one element in the middle step).

6.7.1 導入

この節は非規範的である。

要素をドラッグ可能にすることは簡単である:要素にdraggable属性を与え、ドラッグされているデータを格納するdragstartドラッグに対してイベントリスナーを設定する。

イベントハンドラーは典型的に、それがドラッグされているテキスト選択でないことをチェックする必要があり、次にDataTransferオブジェクトにデータを格納し、許可される効果(コピー、移動、リンク、またはいくつかの組み合わせ)を設定する必要がある。

たとえば:

<p>What fruits do you like?</p>
<ol ondragstart="dragStartHandler(event)">
 <li draggable="true" data-value="fruit-apple">Apples</li>
 <li draggable="true" data-value="fruit-orange">Oranges</li>
 <li draggable="true" data-value="fruit-pear">Pears</li>
</ol>
<script>
  var internalDNDType = 'text/x-example'; // set this to something specific to your site
  function dragStartHandler(event) {
    if (event.target instanceof HTMLLIElement) {
      // use the element's data-value="" attribute as the value to be moving:
      event.dataTransfer.setData(internalDNDType, event.target.dataset.value);
      event.dataTransfer.effectAllowed = 'move'; // only allow moves
    } else {
      event.preventDefault(); // don't allow selection to be dragged
    }
  }
</script>

ドロップを受け入れるために、ドロップターゲットがdropzone属性を持ち、かつdropイベントをリッスンする必要がある。

dropzone属性値は、どのデータの種類を受け入れるか(たとえば任意のテキスト文字列を受け入れる"string:text/plain"、またはPNG画像ファイルを受け入れる"file:image/png"など)およびどのフィードバックの種類を与えるかを指定する(たとえばデータが移動されることを示すために"move"など)。

dropzone属性を使用する代わりに、ドロップターゲットは、dragenterイベント(ドロップターゲットがドロップを受け入れるかどうかを報告する)およびdragoverイベント(フィードバックがユーザーに表示されるかを指定する)を処理できる。

dropイベントは実際のドロップを許可する。このイベントは、dropEffect属性値がソースで使用できるので、キャンセルする必要がある(そうでなければリセットである)。

たとえば:

<p>Drop your favorite fruits below:</p>
<ol dropzone="move string:text/x-example" ondrop="dropHandler(event)">
 <!-- don't forget to change the "text/x-example" type to something
 specific to your site -->
</ol>
<script>
  var internalDNDType = 'text/x-example'; // set this to something specific to your site
  function dropHandler(event) {
    var li = document.createElement('li');
    var data = event.dataTransfer.getData(internalDNDType);
    if (data == 'fruit-apple') {
      li.textContent = 'Apples';
    } else if (data == 'fruit-orange') {
      li.textContent = 'Oranges';
    } else if (data == 'fruit-pear') {
      li.textContent = 'Pears';
    } else {
      li.textContent = 'Unknown Fruit';
    }
    event.target.appendChild(li);
  }
</script>

ディスプレイからオリジナルの要素(ドラッグされたもの)を削除するために、dragendイベントを使用できる。

ここで私たちの例のために、それはそのイベントを処理するために元のマークアップを更新することを意味する:

<p>What fruits do you like?</p>
<ol ondragstart="dragStartHandler(event)" ondragend="dragEndHandler(event)">
 ...as before...
</ol>
<script>
  function dragStartHandler(event) {
    // ...as before...
  }
  function dragEndHandler(event) {
    if (event.dataTransfer.dropEffect == 'move') {
      // remove the dragged element
      event.target.parentNode.removeChild(event.target);
    }
  }
</script>

6.7.2 ドラッグデータストア

ドラッグデータストアとして知られる、ドラッグアンドドロップ操作を支えるデータは次の情報で構成される:

When a drag data store is created, it must be initialized such that its drag data store item list is empty, it has no drag data store default feedback, it has no drag data store bitmap and drag data store hot spot coordinate, its drag data store mode is protected mode, and its drag data store allowed effects state is the string "uninitialized".

6.7.3 DataTransferインターフェイス

DataTransferオブジェクトは、ドラッグアンドドロップ操作を支えるドラッグデータストアを公開するために使用される。

interface DataTransfer {
  attribute DOMString dropEffect;
  attribute DOMString effectAllowed;

  [SameObject] readonly attribute DataTransferItemList items;

  void setDragImage(Element image, long x, long y);

  /* old interface */
  readonly attribute FrozenArray<DOMString> types;
  DOMString getData(DOMString format);
  void setData(DOMString format, DOMString data);
  void clearData(optional DOMString format);
  [SameObject] readonly attribute FileList files;
};
dataTransfer . dropEffect [ = value ]

現在選択されている操作の種類を返す。操作の種類がeffectAllowed属性によって許可されるものの1つでない場合、操作は失敗する。

選択した操作を変更す設定が可能である。

可能な値は、"none"、"copy"、"link"、および"move"である。

dataTransfer . effectAllowed [ = value ]

許可される操作の種類を返す。

許可される操作を変更するために、(dragstartイベント中に)設定可能である。

可能な値は、"none"、"copy"、"copyLink"、"copyMove"、"link"、"linkMove"、"move"、"all"、および"uninitialized"である。

dataTransfer . items

ドラッグデータとともに、DataTransferItemListオブジェクトを返す。

dataTransfer . setDragImage(element, x, y)

以前に指定されたフィードバックを置換し、ドラッグフィードバックを更新するために指定された要素を使用する。

dataTransfer . types

Returns a frozen array listing the formats that were set in the dragstart event. In addition, if any files are being dragged, then one of the types will be the string "Files".

data = dataTransfer . getData(format)

指定されたデータを返す。そのようなデータが存在しない場合、空の文字列を返す。

dataTransfer . setData(format, data)

指定されたデータを追加する。

dataTransfer . clearData( [ format ] )

指定した書式のデータを削除する。引数が省略された場合、すべてのデータを削除する。

dataTransfer . files

もしあれば、ドラッグされているファイルのFileListを返す。

DataTransferオブジェクトはドラッグアンドドロップイベントの間に使用され、それらのイベントが発生している間のみ有効である。

A DataTransfer object is associated with a drag data store while it is valid.

A DataTransfer object has an associated types array, which is a FrozenArray<DOMString>, initially empty. When the contents of the DataTransfer object's drag data store item list change, or when the DataTransfer object becomes no longer associated with a drag data store, run the following steps:

  1. Let L be an empty sequence.

  2. If the DataTransfer object is still associated with a drag data store, then:

    1. For each item in the DataTransfer object's drag data store item list whose kind is Plain Unicode string, add an entry to L consisting of the item's type string.

    2. If there are any items in the DataTransfer object's drag data store item list whose kind is File, then add an entry to L consisting of the string "Files". (This value can be distinguished from the other values because it is not lowercase.)

  3. Set the DataTransfer object's types array to the result of creating a frozen array from L.

The dropEffect attribute controls the drag-and-drop feedback that the user is given during a drag-and-drop operation. When the DataTransfer object is created, the dropEffect attribute is set to a string value. On getting, it must return its current value. On setting, if the new value is one of "none", "copy", "link", or "move", then the attribute's current value must be set to the new value. Other values must be ignored.

The effectAllowed attribute is used in the drag-and-drop processing model to initialize the dropEffect attribute during the dragenter and dragover events. When the DataTransfer object is created, the effectAllowed attribute is set to a string value. On getting, it must return its current value. On setting, if drag data store's mode is the read/write mode and the new value is one of "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", or "uninitialized", then the attribute's current value must be set to the new value. Otherwise it must be left unchanged.

The items attribute must return a DataTransferItemList object associated with the DataTransfer object.

The setDragImage(element, x, y) method must run the following steps:

  1. If the DataTransfer object is no longer associated with a drag data store, abort these steps. Nothing happens.

  2. If the drag data store's mode is not the read/write mode, abort these steps. Nothing happens.

  3. If element is an img element, then set the drag data store bitmap to the element's image (at its intrinsic size); otherwise, set the drag data store bitmap to an image generated from the given element (the exact mechanism for doing so is not currently specified).

  4. Set the drag data store hot spot coordinate to the given x, y coordinate.

The types attribute must return this DataTransfer object's types array.

The getData(format) method must run the following steps:

  1. If the DataTransfer object is no longer associated with a drag data store, return the empty string and abort these steps.

  2. If the drag data store's mode is the protected mode, return the empty string and abort these steps.

  3. Let format be the first argument, converted to ASCII lowercase.

  4. Let convert-to-URL be false.

  5. If format equals "text", change it to "text/plain".

  6. If format equals "url", change it to "text/uri-list" and set convert-to-URL to true.

  7. If there is no item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to format, return the empty string and abort these steps.

  8. Let result be the data of the item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to format.

  9. If convert-to-URL is true, then parse result as appropriate for text/uri-list data, and then set result to the first URL from the list, if any, or the empty string otherwise. [RFC2483]

  10. Return result.

The setData(format, data) method must run the following steps:

  1. If the DataTransfer object is no longer associated with a drag data store, abort these steps. Nothing happens.

  2. If the drag data store's mode is not the read/write mode, abort these steps. Nothing happens.

  3. Let format be the first argument, converted to ASCII lowercase.

  4. If format equals "text", change it to "text/plain".

    If format equals "url", change it to "text/uri-list".

  5. Remove the item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to format, if there is one.

  6. Add an item to the drag data store item list whose kind is Plain Unicode string, whose type string is equal to format, and whose data is the string given by the method's second argument.

The clearData() method must run the following steps:

  1. If the DataTransfer object is no longer associated with a drag data store, abort these steps. Nothing happens.

  2. If the drag data store's mode is not the read/write mode, abort these steps. Nothing happens.

  3. If the method was called with no arguments, remove each item in the drag data store item list whose kind is Plain Unicode string, and abort these steps.

  4. Let format be the first argument, converted to ASCII lowercase.

  5. If format equals "text", change it to "text/plain".

    If format equals "url", change it to "text/uri-list".

  6. Remove the item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to format, if there is one.

The clearData() method does not affect whether any files were included in the drag, so the types attribute's list might still not be empty after calling clearData() (it would still contain the "Files" string if any files were included in the drag).

The files attribute must return a live FileList sequence consisting of File objects representing the files found by the following steps. Furthermore, for a given FileList object and a given underlying file, the same File object must be used each time.

  1. Start with an empty list L.

  2. If the DataTransfer object is no longer associated with a drag data store, the FileList is empty. Abort these steps; return the empty list L.

  3. If the drag data store's mode is the protected mode, abort these steps; return the empty list L.

  4. For each item in the drag data store item list whose kind is File , add the item's data (the file, in particular its name and contents, as well as its type) to the list L.

  5. The files found by these steps are those in the list L.

This version of the API does not expose the types of the files during the drag.

6.7.3.1 DataTransferItemListインターフェイス

DataTransferオブジェクトはDataTransferItemListオブジェクトに関連付けられる。

interface DataTransferItemList {
  readonly attribute unsigned long length;
  getter DataTransferItem (unsigned long index);
  DataTransferItem? add(DOMString data, DOMString type);
  DataTransferItem? add(File data);
  void remove(unsigned long index);
  void clear();
};
items . length

ドラッグデータストア内のアイテムの数を返す。

items[index]

ドラッグデータストア内のindex番目のエントリを表すDataTransferItemオブジェクトを返す。

items . remove(index)

ドラッグデータストア内のindex番目のエントリを削除する。

items . clear()

ドラッグデータストア内のすべてのエントリを削除する。

items . add(data)
items . add(data, type)

ドラッグデータストアに指定されたデータに対する新しいエントリを追加する。データがプレーンテキストである場合、type文字列も提供される必要がある。

While the DataTransferItemList object's DataTransfer object is associated with a drag data store, the DataTransferItemList object's mode is the same as the drag data store mode. When the DataTransferItemList object's DataTransfer object is not associated with a drag data store, the DataTransferItemList object's mode is the disabled mode. The drag data store referenced in this section (which is used only when the DataTransferItemList object is not in the disabled mode) is the drag data store with which the DataTransferItemList object's DataTransfer object is associated.

The length attribute must return zero if the object is in the disabled mode; otherwise it must return the number of items in the drag data store item list.

When a DataTransferItemList object is not in the disabled mode, its supported property indices are the numbers in the range 0 .. n-1, where n is the number of items in the drag data store item list.

To determine the value of an indexed property i of a DataTransferItemList object, the user agent must return a DataTransferItem object representing the ith item in the drag data store. The same object must be returned each time a particular item is obtained from this DataTransferItemList object. The DataTransferItem object must be associated with the same DataTransfer object as the DataTransferItemList object when it is first created.

The add() method must run the following steps:

  1. If the DataTransferItemList object is not in the read/write mode, return null and abort these steps.

  2. Jump to the appropriate set of steps from the following list:

    If the first argument to the method is a string

    If there is already an item in the drag data store item list whose kind is Plain Unicode string and whose type string is equal to the value of the method's second argument, converted to ASCII lowercase, then throw a "NotSupportedError" DOMException and abort these steps.

    Otherwise, add an item to the drag data store item list whose kind is Plain Unicode string, whose type string is equal to the value of the method's second argument, converted to ASCII lowercase, and whose data is the string given by the method's first argument.

    If the first argument to the method is a File

    Add an item to the drag data store item list whose kind is File, whose type string is the type of the File, converted to ASCII lowercase, and whose data is the same as the File's data.

  3. Determine the value of the indexed property corresponding to the newly added item, and return that value (a newly created DataTransferItem object).

The remove() method, when invoked with the argument i, must run these steps:

  1. If the DataTransferItemList object is not in the read/write mode, throw an "InvalidStateError" DOMException and abort these steps.

  2. Remove the ith item from the drag data store.

The clear() method, if the DataTransferItemList object is in the read/write mode, must remove all the items from the drag data store. Otherwise, it must do nothing.

6.7.3.2 DataTransferItemインターフェイス

DataTransferItemオブジェクトはDataTransferオブジェクトに関連付けられる。

interface DataTransferItem {
  readonly attribute DOMString kind;
  readonly attribute DOMString type;
  void getAsString(FunctionStringCallback? _callback);
  File? getAsFile();
};

callback FunctionStringCallback = void (DOMString data);
item . kind

ドラッグデータ項目の種類、"string"、"file"のいずれかを返す。

item . type

ドラッグデータ項目型文字列を返す。

item . getAsString(callback)

ドラッグデータ項目の種類プレーンUnicode文字列である場合、引数として文字列データをもつコールバックを呼び出す。

file = item . getAsFile()

ドラッグデータアイテムの種類Fileである場合、Fileオブジェクトを返す。

While the DataTransferItem object's DataTransfer object is associated with a drag data store and that drag data store's drag data store item list still contains the item that the DataTransferItem object represents, the DataTransferItem object's mode is the same as the drag data store mode. When the DataTransferItem object's DataTransfer object is not associated with a drag data store, or if the item that the DataTransferItem object represents has been removed from the relevant drag data store item list, the DataTransferItem object's mode is the disabled mode. The drag data store referenced in this section (which is used only when the DataTransferItem object is not in the disabled mode) is the drag data store with which the DataTransferItem object's DataTransfer object is associated.

The kind attribute must return the empty string if the DataTransferItem object is in the disabled mode; otherwise it must return the string given in the cell from the second column of the following table from the row whose cell in the first column contains the drag data item kind of the item represented by the DataTransferItem object:

Kind String
プレーンUnicode文字列 "string"
File "file"

The type attribute must return the empty string if the DataTransferItem object is in the disabled mode; otherwise it must return the drag data item type string of the item represented by the DataTransferItem object.

The getAsString(callback) method must run the following steps:

  1. If the callback is null, abort these steps.

  2. If the DataTransferItem object is not in the read/write mode or the read-only mode, abort these steps. The callback is never invoked.

  3. If the drag data item kind is not Plain Unicode string, abort these steps. The callback is never invoked.

  4. Otherwise, queue a task to invoke callback, passing the actual data of the item represented by the DataTransferItem object as the argument.

The getAsFile() method must run the following steps:

  1. If the DataTransferItem object is not in the read/write mode or the read-only mode, return null and abort these steps.

  2. If the drag data item kind is not File, then return null and abort these steps.

  3. Return a new File object representing the actual data of the item represented by the DataTransferItem object.

6.7.4 DragEventインターフェイス

ドラッグアンドドロップ処理モデルは、複数のイベントを含む。これらはすべてDragEventインターフェイスを使用する。

[Constructor(DOMString type, optional DragEventInit eventInitDict)]
interface DragEvent : MouseEvent {
  readonly attribute DataTransfer? dataTransfer;
};

dictionary DragEventInit : MouseEventInit {
  DataTransfer? dataTransfer = null;
};
event . dataTransfer

イベントのDataTransferオブジェクトを返す。

他のイベントインターフェイスとの整合性を保つため、DragEventインターフェイスはコンストラクタを持つけれども、特に有用ではない。DataTransferオブジェクトは、ドラッグアンドドロップの間にブラウザーによって調整される処理およびセキュリティーモデルを持つので、特に、スクリプトから有用なDataTransferオブジェクトを作成する方法はない。

The dataTransfer attribute of the DragEvent interface must return the value it was initialized to. It represents the context information for the event.

When a user agent is required to fire a DND event named e at an element, using a particular drag data store, and optionally with a specific related target, the user agent must run the following steps:

  1. If no specific related target was provided, set related target to null.

  2. Let window be the Window object of the Document object of the specified target element.

  3. If e is dragstart, set the drag data store mode to the read/write mode.

    If e is drop, set the drag data store mode to the read-only mode.

  4. Let dataTransfer be a newly created DataTransfer object associated with the given drag data store.

  5. Set the effectAllowed attribute to the drag data store's drag data store allowed effects state.

  6. Set the dropEffect attribute to "none" if e is dragstart, drag, dragexit, or dragleave; to the value corresponding to the current drag operation if e is drop or dragend; and to a value based on the effectAllowed attribute's value and the drag-and-drop source, as given by the following table, otherwise (i.e. if e is dragenter or dragover):

    effectAlloweddropEffect
    "none""none"
    "copy""copy"
    "copyLink""copy", or, if appropriate, "link"
    "copyMove""copy", or, if appropriate, "move"
    "all""copy", or, if appropriate, either "link" or "move"
    "link""link"
    "linkMove""link", or, if appropriate, "move"
    "move""move"
    "uninitialized" when what is being dragged is a selection from a text control"move", or, if appropriate, either "copy" or "link"
    "uninitialized" when what is being dragged is a selection"copy", or, if appropriate, either "link" or "move"
    "uninitialized" when what is being dragged is an a element with an href attribute"link", or, if appropriate, either "copy" or "move"
    Any other case"copy", or, if appropriate, either "link" or "move"

    Where the table above provides possibly appropriate alternatives, user agents may instead use the listed alternative values if platform conventions dictate that the user has requested those alternate effects.

    For example, Windows platform conventions are such that dragging while holding the "alt" key indicates a preference for linking the data, rather than moving or copying it. Therefore, on a Windows system, if "link" is an option according to the table above while the "alt" key is depressed, the user agent could select that instead of "copy" or "move".

  7. Let event be the result of creating an event using DragEvent.

  8. Initialize event's type attribute to e, its bubbles attribute to true, its view attribute to window, its relatedTarget attribute to related target, and its dataTransfer attribute to dataTransfer.

  9. If e is not dragexit, dragleave, or dragend, then initialize event's cancelable attribute to true.

  10. Initialize event's mouse and key attributes initialized according to the state of the input devices as they would be for user interaction events.

    If there is no relevant pointing device, then initialize event's screenX, screenY, clientX, clientY, and button attributes to 0.

  11. Dispatch event at the specified target element.

  12. Set the drag data store allowed effects state to the current value of dataTransfer's effectAllowed attribute. (It can only have changed value if e is dragstart.)

  13. Set the drag data store mode back to the protected mode if it was changed in the first step.

  14. Break the association between dataTransfer and the drag data store.

6.7.5 Processing model

When the user attempts to begin a drag operation, the user agent must run the following steps. User agents must act as if these steps were run even if the drag actually started in another document or application and the user agent was not aware that the drag was occurring until it intersected with a document under the user agent's purview.

  1. Determine what is being dragged, as follows:

    If the drag operation was invoked on a selection, then it is the selection that is being dragged.

    Otherwise, if the drag operation was invoked on a Document, it is the first element, going up the ancestor chain, starting at the node that the user tried to drag, that has the IDL attribute draggable set to true. If there is no such element, then nothing is being dragged; abort these steps, the drag-and-drop operation is never started.

    Otherwise, the drag operation was invoked outside the user agent's purview. What is being dragged is defined by the document or application where the drag was started.

    img elements and a elements with an href attribute have their draggable attribute set to true by default.

  2. Create a drag data store. All the DND events fired subsequently by the steps in this section must use this drag data store.

  3. Establish which DOM node is the source node, as follows:

    If it is a selection that is being dragged, then the source node is the Text node that the user started the drag on (typically the Text node that the user originally clicked). If the user did not specify a particular node, for example if the user just told the user agent to begin a drag of "the selection", then the source node is the first Text node containing a part of the selection.

    Otherwise, if it is an element that is being dragged, then the source node is the element that is being dragged.

    Otherwise, the source node is part of another document or application. When this specification requires that an event be dispatched at the source node in this case, the user agent must instead follow the platform-specific conventions relevant to that situation.

    Multiple events are fired on the source node during the course of the drag-and-drop operation.

  4. Determine the list of dragged nodes, as follows:

    If it is a selection that is being dragged, then the list of dragged nodes contains, in tree order, every node that is partially or completely included in the selection (including all their ancestors).

    Otherwise, the list of dragged nodes contains only the source node, if any.

  5. If it is a selection that is being dragged, then add an item to the drag data store item list, with its properties set as follows:

    ドラッグデータ項目型文字列
    "text/plain"
    ドラッグデータアイテムの種類
    プレーンUnicode文字列
    実際のデータ
    The text of the selection

    Otherwise, if any files are being dragged, then add one item per file to the drag data store item list, with their properties set as follows:

    ドラッグデータ項目型文字列
    The MIME type of the file, if known, or "application/octet-stream" otherwise.
    ドラッグデータアイテムの種類
    File
    実際のデータ
    The file's contents and name.

    Dragging files can currently only happen from outside a browsing context, for example from a file system manager application.

    If the drag initiated outside of the application, the user agent must add items to the drag data store item list as appropriate for the data being dragged, honoring platform conventions where appropriate; however, if the platform conventions do not use MIME types to label dragged data, the user agent must make a best-effort attempt to map the types to MIME types, and, in any case, all the drag data item type strings must be converted to ASCII lowercase.

    User agents may also add one or more items representing the selection or dragged element(s) in other forms, e.g. as HTML.

  6. If the list of dragged nodes is not empty, then extract the microdata from those nodes into a JSON form, and add one item to the drag data store item list, with its properties set as follows:

    ドラッグデータ項目型文字列
    application/microdata+json
    ドラッグデータアイテムの種類
    プレーンUnicode文字列
    実際のデータ
    The resulting JSON string.
  7. 次のサブ手順を実行する:

    1. Let urls be an empty list of absolute URLs.

    2. For each node in the list of dragged nodes:

      If the node is an a element with an href attribute
      Add to urls the result of parsing the element's href content attribute relative to the element's node document.
      If the node is an img element with a src attribute
      Add to urls the result of parsing the element's src content attribute relative to the element's node document.
    3. If urls is still empty, abort these substeps.

    4. Let url string be the result of concatenating the strings in urls, in the order they were added, separated by a U+000D CARRIAGE RETURN U+000A LINE FEED character pair (CRLF).

    5. Add one item to the drag data store item list, with its properties set as follows:

      ドラッグデータ項目型文字列
      text/uri-list
      ドラッグデータアイテムの種類
      プレーンUnicode文字列
      実際のデータ
      url string
  8. Update the drag data store default feedback as appropriate for the user agent (if the user is dragging the selection, then the selection would likely be the basis for this feedback; if the user is dragging an element, then that element's rendering would be used; if the drag began outside the user agent, then the platform conventions for determining the drag feedback should be used).

  9. Fire a DND event named dragstart at the source node.

    If the event is canceled, then the drag-and-drop operation should not occur; abort these steps.

    Since events with no event listeners registered are, almost by definition, never canceled, drag-and-drop is always available to the user if the author does not specifically prevent it.

  10. Initiate the drag-and-drop operation in a manner consistent with platform conventions, and as described below.

    The drag-and-drop feedback must be generated from the first of the following sources that is available:

    1. The drag data store bitmap, if any. In this case, the drag data store hot spot coordinate should be used as hints for where to put the cursor relative to the resulting image. The values are expressed as distances in CSS pixels from the left side and from the top side of the image respectively. [CSS]
    2. The drag data store default feedback.

From the moment that the user agent is to initiate the drag-and-drop operation, until the end of the drag-and-drop operation, device input events (e.g. mouse and keyboard events) must be suppressed.

During the drag operation, the element directly indicated by the user as the drop target is called the immediate user selection. (Only elements can be selected by the user; other nodes must not be made available as drop targets.) However, the immediate user selection is not necessarily the current target element, which is the element currently selected for the drop part of the drag-and-drop operation.

The immediate user selection changes as the user selects different elements (either by pointing at them with a pointing device, or by selecting them in some other way). The current target element changes when the immediate user selection changes, based on the results of event listeners in the document, as described below.

Both the current target element and the immediate user selection can be null, which means no target element is selected. They can also both be elements in other (DOM-based) documents, or other (non-Web) programs altogether. (For example, a user could drag text to a word-processor.) The current target element is initially null.

In addition, there is also a current drag operation, which can take on the values "none", "copy", "link", and "move". Initially, it has the value "none". It is updated by the user agent as described in the steps below.

User agents must, as soon as the drag operation is initiated and every 350ms (±200ms) thereafter for as long as the drag operation is ongoing, queue a task to perform the following steps in sequence:

  1. If the user agent is still performing the previous iteration of the sequence (if any) when the next iteration becomes due, abort these steps for this iteration (effectively "skipping missed frames" of the drag-and-drop operation).

  2. Fire a DND event named drag at the source node. If this event is canceled, the user agent must set the current drag operation to "none" (no drag operation).

  3. If the drag event was not canceled and the user has not ended the drag-and-drop operation, check the state of the drag-and-drop operation, as follows:

    1. If the user is indicating a different immediate user selection than during the last iteration (or if this is the first iteration), and if this immediate user selection is not the same as the current target element, then fire a DND event named dragexit at the current target element, and then update the current target element as follows:

      If the new immediate user selection is null

      Set the current target element to null also.

      If the new immediate user selection is in a non-DOM document or application

      Set the current target element to the immediate user selection.

      そうでなければ

      Fire a DND event named dragenter at the immediate user selection.

      If the event is canceled, then set the current target element to the immediate user selection.

      Otherwise, run the appropriate step from the following list:

      If the immediate user selection is a text control (e.g., textarea, or an input element whose type attribute is in the Text state) or an editing host or editable element, and the drag data store item list has an item with the drag data item type string "text/plain" and the drag data item kind Plain Unicode string

      Set the current target element to the immediate user selection anyway.

      If the immediate user selection is an element with a dropzone attribute that matches the drag data store

      Set the current target element to the immediate user selection anyway.

      If the immediate user selection is an element that itself has an ancestor element with a dropzone attribute that matches the drag data store

      Let new target be the nearest (deepest) such ancestor element.

      If the immediate user selection is new target, then leave the current target element unchanged.

      Otherwise, fire a DND event named dragenter at new target, with the current current target element as the specific related target. Then, set the current target element to new target, regardless of whether that event was canceled or not.

      If the immediate user selection is the body element

      Leave the current target element unchanged.

      そうでなければ

      Fire a DND event named dragenter at the body element, if there is one, or at the Document object, if not. Then, set the current target element to the body element, regardless of whether that event was canceled or not.

    2. If the previous step caused the current target element to change, and if the previous target element was not null or a part of a non-DOM document, then fire a DND event named dragleave at the previous target element, with the new current target element as the specific related target.

    3. If the current target element is a DOM element, then fire a DND event named dragover at this current target element.

      If the dragover event is not canceled, run the appropriate step from the following list:

      If the current target element is a text control (e.g., textarea, or an input element whose type attribute is in the Text state) or an editing host or editable element, and the drag data store item list has an item with the drag data item type string "text/plain" and the drag data item kind Plain Unicode string

      Set the current drag operation to either "copy" or "move", as appropriate given the platform conventions.

      If the current target element is an element with a dropzone attribute that matches the drag data store and specifies an operation

      Set the current drag operation to the operation specified by the dropzone attribute of the current target element.

      If the current target element is an element with a dropzone attribute that matches the drag data store and does not specify an operation

      Set the current drag operation to "copy".

      そうでなければ

      Reset the current drag operation to "none".

      Otherwise (if the dragover event is canceled), set the current drag operation based on the values of the effectAllowed and dropEffect attributes of the DragEvent object's dataTransfer object as they stood after the event dispatch finished, as per the following table:

      effectAlloweddropEffectDrag operation
      "uninitialized", "copy", "copyLink", "copyMove", or "all""copy""copy"
      "uninitialized", "link", "copyLink", "linkMove", or "all""link""link"
      "uninitialized", "move", "copyMove", "linkMove", or "all""move""move"
      Any other case"none"
    4. Otherwise, if the current target element is not a DOM element, use platform-specific mechanisms to determine what drag operation is being performed (none, copy, link, or move), and set the current drag operation accordingly.

    5. Update the drag feedback (e.g. the mouse cursor) to match the current drag operation, as follows:

      Drag operationFeedback
      "copy"Data will be copied if dropped here.
      "link"Data will be linked if dropped here.
      "move"Data will be moved if dropped here.
      "none"No operation allowed, dropping here will cancel the drag-and-drop operation.
  4. Otherwise, if the user ended the drag-and-drop operation (e.g. by releasing the mouse button in a mouse-driven drag-and-drop interface), or if the drag event was canceled, then this will be the last iteration. Run the following steps, then stop the drag-and-drop operation:

    1. If the current drag operation is "none" (no drag operation), or, if the user ended the drag-and-drop operation by canceling it (e.g. by hitting the Escape key), or if the current target element is null, then the drag operation failed. Run these substeps:

      1. Let dropped be false.

      2. If the current target element is a DOM element, fire a DND event named dragleave at it; otherwise, if it is not null, use platform-specific conventions for drag cancelation.

      3. Set the current drag operation to "none".

      Otherwise, the drag operation might be a success; run these substeps:

      1. Let dropped be true.

      2. If the current target element is a DOM element, fire a DND event named drop at it; otherwise, use platform-specific conventions for indicating a drop.

      3. If the event is canceled, set the current drag operation to the value of the dropEffect attribute of the DragEvent object's dataTransfer object as it stood after the event dispatch finished.

        Otherwise, the event is not canceled; perform the event's default action, which depends on the exact target as follows:

        If the current target element is a text control (e.g., textarea, or an input element whose type attribute is in the Text state) or an editing host or editable element, and the drag data store item list has an item with the drag data item type string "text/plain" and the drag data item kind Plain Unicode string

        Insert the actual data of the first item in the drag data store item list to have a drag data item type string of "text/plain" and a drag data item kind that is Plain Unicode string into the text control or editing host or editable element in a manner consistent with platform-specific conventions (e.g. inserting it at the current mouse cursor position, or inserting it at the end of the field).

        そうでなければ

        Reset the current drag operation to "none".

    2. Fire a DND event named dragend at the source node.

    3. Run the appropriate steps from the following list as the default action of the dragend event:

      If dropped is true, the current target element is a text control (see below), the current drag operation is "move", and the source of the drag-and-drop operation is a selection in the DOM that is entirely contained within an editing host

      Delete the selection.

      If dropped is true, the current target element is a text control (see below), the current drag operation is "move", and the source of the drag-and-drop operation is a selection in a text control

      The user agent should delete the dragged selection from the relevant text control.

      If dropped is false or if the current drag operation is "none"

      The drag was canceled. If the platform conventions dictate that this be represented to the user (e.g. by animating the dragged selection going back to the source of the drag-and-drop operation), then do so.

      そうでなければ

      The event has no default action.

      For the purposes of this step, a text control is a textarea element or an input element whose type attribute is in one of the Text, Search, Tel, URL, E-mail, Password, or Number states.

User agents are encouraged to consider how to react to drags near the edge of scrollable regions. For example, if a user drags a link to the bottom of the viewport on a long page, it might make sense to scroll the page so that the user can drop the link lower on the page.

This model is independent of which Document object the nodes involved are from; the events are fired as described above and the rest of the processing model runs as described above, irrespective of how many documents are involved in the operation.

6.7.6 イベントの概要

この節は非規範的である。

次のイベントは、ドラッグアンドドロップモデルに関与する。

イベント名 ターゲット 取消可能か? ドラッグデータストアモード dropEffect デフォルトの動作
dragstartソースノード✓取消可能読み書きモード "none"ドラッグアンドドロップ操作を開始する
dragソースノード✓取消可能保護モード "none"ドラッグアンドドロップ操作を続行する
dragenterイミディエイトユーザーセレクションまたはbody要素✓取消可能保護モード effectAllowed値をベースにする潜在的なターゲット要素として即時のユーザーの選択を拒絶する
dragexit前のターゲット要素保護モード "none"なし
dragleave前のターゲット要素保護モード "none"なし
dragover現在のターゲット要素✓取消可能保護モード effectAllowed値をベースにする"none"現在のドラッグ操作リセットする
drop現在のターゲット要素✓取消可能読み取り専用モード 現在のドラッグ操作変化する
dragendソースノード保護モード 現在のドラッグ操作変化する

Not shown in the above table: all these events bubble, are composed, and the effectAllowed attribute always has the value it had after the dragstart event, defaulting to "uninitialized" in the dragstart event.

6.7.7 draggable属性

Spec bugs: 26024

すべてのHTML要素draggableコンテンツ属性設定を持ってもよい。draggable属性は、列挙属性である。それは3つの状態を持つ。1番目の状態はtrueであり、それはキーワードtrueを持つ。2番目の状態はfalseであり、それはキーワードfalseを持つ。3番目の状態はautoである。それは、キーワードを持たない、欠損値がデフォルトである。

true状態は要素がドラッグ可能であることを意味し、false状態はそうでないことを意味する。auto状態はユーザーエージェントのデフォルト動作を使用する。

draggable属性を持つ要素はまた、非視覚的な相互作用の目的のために要素を名付けるtitle属性を持つべきである。

element . draggable [ = value ]

要素がドラッグ可能である場合にtrueを返す。そうでなければfalseを返す。

デフォルトを上書きしdraggableコンテンツの属性を設定するための、設定が可能である。

The draggable IDL attribute, whose value depends on the content attribute's in the way described below, controls whether or not the element is draggable. Generally, only text selections are draggable, but elements whose draggable IDL attribute is true become draggable as well.

If an element's draggable content attribute has the state true, the draggable IDL attribute must return true.

Otherwise, if the element's draggable content attribute has the state false, the draggable IDL attribute must return false.

Otherwise, the element's draggable content attribute has the state auto. If the element is an img element, an object element that represents an image, or an a element with an href content attribute, the draggable IDL attribute must return true; otherwise, the draggable IDL attribute must return false.

If the draggable IDL attribute is set to the value false, the draggable content attribute must be set to the literal value "false". If the draggable IDL attribute is set to the value true, the draggable content attribute must be set to the literal value "true".

6.7.8 dropzone属性

すべてのHTML要素は、dropzoneコンテンツ属性設定をもってもよい。指定された場合、その値はASCII大文字・小文字不区別一意なスペース区切りトークンの順不同の集合でなければならない。許可される値は次のとおり:

copy

要素で受け入れられるアイテムのドロップが、ドラッグしたデータのコピーになることを示す。

move

要素で受け入れられるアイテムのドロップが、新しい場所に移動されてドラッグされたデータになることを示す。

link

要素で受け入れられるアイテムのドロップが、元のデータへのリンクになることを示す。

大文字・小文字不区別で文字列"string:"にマッチするもので始まる、8文字以上を持つ任意のキーワード。

ドラッグデータ項目の種類プレーンUnicode文字列およびドラッグデータ項目の種類の文字列をもつ項目が受け入れられるキーワードの残りの部分と一致する値に設定することを示す。

大文字・小文字不区別で文字列"file:"にマッチするもので始まる、6文字以上を持つ任意のキーワード。

ドラッグデータ項目の種類Fileおよびドラッグデータ項目の種類の文字列をもつ項目が、受け入れられるキーワードの残りの部分と一致する値に設定することを示す。

dropzoneコンテンツ属性の値は、指定された3つのフィードバック値のいずれか(copymove、およびlink)より多くを持ってはならない。何も指定されない場合、copy値が暗黙的に指定される。

dropzone属性を持つ要素はまた、非視覚的な相互作用の目的のために要素を名付けるtitle属性を持つべきである。

A dropzone attribute matches a drag data store if the dropzone processing steps result in a match.

A dropzone attribute specifies an operation if the dropzone processing steps result in a specified operation. The specified operation is as given by those steps.

The dropzone processing steps are as follows. They either result in a match or not, and separate from this result either in a specified operation or not, as defined below.

  1. Let value be the value of the dropzone attribute.

  2. Let keywords be the result of splitting value on ASCII whitespace.

  3. Let matched be false.

  4. Let operation be unspecified.

  5. For each value in keywords, if any, in the order that they were found in value, run the following steps.

    1. Let keyword be the keyword.

    2. If keyword is one of "copy", "move", or "link", then: run the following substeps:

      1. If operation is still unspecified, then let operation be the string given by keyword.

      2. Skip to the step labeled end of keyword below.

    3. If keyword does not contain a U+003A COLON character (:), or if the first such character in keyword is either the first character or the last character in the string, then skip to the step labeled end of keyword below.

    4. Let kind code be the substring of keyword from the first character in the string to the last character in the string that is before the first U+003A COLON character (:) in the string, converted to ASCII lowercase.

    5. Jump to the appropriate step from the list below, based on the value of kind code:

      If kind code is the string "string"

      Let kind be Plain Unicode string.

      If kind code is the string "file"

      Let kind be File.

      そうでなければ

      Skip to the step labeled end of keyword below.

    6. Let type be the substring of keyword from the first character after the first U+003A COLON character (:) in the string, to the last character in the string, converted to ASCII lowercase.

    7. If there exist any items in the drag data store item list whose drag data item kind is the kind given in kind and whose drag data item type string is type, then let matched be true.

    8. End of keyword: Go on to the next keyword, if any, or the next step in the overall algorithm, if there are no more.

  6. The algorithm results in a match if matched is true, and does not otherwise.

    The algorithm results in a specified operation if operation is not unspecified. The specified operation, if one is specified, is the one given by operation.

The dropzone IDL attribute must reflect the content attribute of the same name.

The supported tokens for dropzone are the allowed values defined for the dropzone attribute that are supported by the user agent.

この例において、div要素はdropzone属性を使用する画像ファイルに対してドロップターゲットとなる。ターゲットにドロップされた画像が表示される。

<div dropzone="copy file:image/png file:image/gif file:image/jpeg" ondrop="receive(event, this)">
 <p>Drop an image here to have it displayed.</p>
</div>
<script>
 function receive(event, element) {
   var data = event.dataTransfer.items;
   for (var i = 0; i < data.length; i += 1) {
     if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
       var img = new Image();
       img.src = window.createObjectURL(data[i].getAsFile());
       element.appendChild(img);
     }
   }
 }
</script>

6.7.9 Security risks in the drag-and-drop model

User agents must not make the data added to the DataTransfer object during the dragstart event available to scripts until the drop event, because otherwise, if a user were to drag sensitive information from one document to a second document, crossing a hostile third document in the process, the hostile document could intercept the data.

For the same reason, user agents must consider a drop to be successful only if the user specifically ended the drag operation — if any scripts end the drag operation, it must be considered unsuccessful (canceled) and the drop event must not be fired.

User agents should take care to not start drag-and-drop operations in response to script actions. For example, in a mouse-and-window environment, if a script moves a window while the user has their mouse button depressed, the UA would not consider that to start a drag. This is important because otherwise UAs could cause data to be dragged from sensitive sources and dropped into hostile documents without the user's consent.

User agents should filter potentially active (scripted) content (e.g. HTML) when it is dragged and when it is dropped, using a safelist of known-safe features. Similarly, relative URLs should be turned into absolute URLs to avoid references changing in unexpected ways. This specification does not specify how this is performed.

Consider a hostile page providing some content and getting the user to select and drag and drop (or indeed, copy and paste) that content to a victim page's contenteditable region. If the browser does not ensure that only safe content is dragged, potentially unsafe content such as scripts and event handlers in the selection, once dropped (or pasted) into the victim site, get the privileges of the victim site. This would thus enable a cross-site scripting attack.