"use strict"; function IsIMEOpenStateSupported() { // We support to control IME open state on Windows and Mac actually. However, // we cannot test it on Mac if the current keyboard layout is not CJK. And also // we cannot test it on Win32 if the system didn't be installed IME. So, // currently we should not run the open state testing. return false; } /** * @param {Node} aNode */ function nodeIsInShadowDOM(aNode) { for (let node = aNode; node; node = node.parentNode) { if (node instanceof ShadowRoot) { return true; } if (node == node.parentNode) { break; } } return false; } /** * @param {Node} aNode */ function nodeIsInDesignMode(aNode) { return ( aNode.isConnected && !nodeIsInShadowDOM(aNode) && aNode.ownerDocument.designMode == "on" ); } /** * param {Node} aNode */ function getEditingHost(aNode) { if (nodeIsInDesignMode(aNode)) { return aNode.ownerDocument.documentElement; } for ( let element = aNode.nodeType == Node.ELEMENT_NODE ? aNode : aNode.parentElement; element; element = element.parentElement ) { const contenteditable = element.getAttribute("contenteditable"); if (contenteditable === "true" || contenteditable === "") { return element; } if (contenteditable === "false") { return null; } } return null; } /** * @param {Node} aNode */ function nodeIsEditable(aNode) { if (nodeIsInDesignMode(aNode)) { return true; } if (!aNode.isConnected) { return false; } return getEditingHost(aNode) != null; } /** * @param {Element} aElement */ function elementIsEditingHost(aElement) { return ( nodeIsEditable(aElement) && (!aElement.parentElement || !getEditingHost(aElement) == aElement) ); } /** * @returns {Element} Retrieve focused element. If focused element is a element * in UA widget, this returns its host element. E.g., when * a button in the controls of