From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- widget/tests/file_ime_state_test_helper.js | 197 +++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 widget/tests/file_ime_state_test_helper.js (limited to 'widget/tests/file_ime_state_test_helper.js') diff --git a/widget/tests/file_ime_state_test_helper.js b/widget/tests/file_ime_state_test_helper.js new file mode 100644 index 0000000000..0cee5c036f --- /dev/null +++ b/widget/tests/file_ime_state_test_helper.js @@ -0,0 +1,197 @@ +"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