EditContext: characterBounds() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

EditContext 接口的 characterBounds() 方法返回一个包含 EditContext 对象中字符边界矩形列表的 Array

操作系统使用 EditContext 对象中字符的位置和大小,以在需要时正确地定位特定于平台的编辑相关 UI 表面,例如 输入法编辑器 (IME) 窗口。这在操作系统无法自动检测字符位置和大小时尤其重要,例如在 <canvas> 元素中渲染文本时。

Web 开发者最可能感兴趣的是结合使用 characterboundsupdate 事件和 EditContext.updateCharacterBounds() 方法,以便在操作系统指示需要字符位置和大小信息时更新字符边界。

characterBounds() 方法返回使用 updateCharacterBounds() 最后更新的字符边界列表。该列表不包含 EditContext 对象中每个字符的条目,只包含使用 updateCharacterBounds() 更新的字符。要了解字符在 EditContext 对象中的位置,请使用 EditContext.characterBoundsRangeStart 属性。

语法

js
characterBounds()

参数

无。

返回值

包含 DOMRect 对象的 Array

规范

规范
EditContext API
# dom-editcontext-characterbounds

浏览器兼容性

另见