EditContext: updateControlBounds() メソッド

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

EditContext インターフェイスの EditContext.updateControlBounds() メソッドは、オペレーティングシステムに EditContext オブジェクトの編集可能なテキスト領域の位置と大きさを知らせるために使われます。

オペレーティングシステムに現在の編集可能な領域の境界を知らせるため、このメソッドを呼びます。EditContext を初期化する時と、ウェブページがリサイズされた時など編集可能な領域の境界が変わった時に毎回、このメソッドを呼ぶべきです。この境界は、インプットメソッドエディター (IME) ウィンドウなどのプラットフォーム固有の編集関係の UI を配置するために使用されます。

構文

js
updateControlBounds(controlBounds)

引数

controlBounds

新しいコントロール境界を表す DOMRect オブジェクトです。

例外

  • 引数が渡されない場合、TypeError DOMException が投げられます。
  • 渡された引数が DOMRect でない場合、TypeError DOMException が投げられます。

エディターの初期化時とウィンドウのリサイズ時にコントロール境界を更新する

この例では、updateControlBounds() を用いてプラットフォームに編集可能な領域の位置を伝え続ける方法を示します。

css
#editor {
  border: 1px solid black;
  height: 50vw;
  width: 50vh;
}
html
<div id="editor"></div>
js
const editorEl = document.getElementById("editor");
const editContext = new EditContext();
editorEl.editContext = editContext;

function updateControlBounds() {
  const editorBounds = editorEl.getBoundingClientRect();
  editContext.updateControlBounds(editorBounds);
  console.log(
    `Updated control bounds to ${editorBounds.x}, ${editorBounds.y}, ${editorBounds.width}, ${editorBounds.height}`,
  );
}

// コントロール領域を今更新します。
updateControlBounds();
// ページがリサイズされた時にも更新します。
window.addEventListener("resize", updateControlBounds);

仕様書

Specification
EditContext API
# dom-editcontext-updatecontrolbounds

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
updateControlBounds
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

関連情報