Truly independent web browser
LibWeb: Disable editing state commands outside of editable content
Andreas Kling15e89ab6a5a4
diff --git a/Libraries/LibWeb/Editing/ExecCommand.cpp b/Libraries/LibWeb/Editing/ExecCommand.cppindex f801be22a0d..c04b4e56f43 100644--- a/Libraries/LibWeb/Editing/ExecCommand.cpp+++ b/Libraries/LibWeb/Editing/ExecCommand.cpp@@ -421,11 +421,15 @@ static bool command_is_enabled(Document& document, Utf16FlyString const& command// Among commands defined in this specification, those listed in Miscellaneous commands are always enabled, except// for the cut command and the paste command.// NOTE: cut and paste are actually in the Clipboard commands section+ // INTEROP: Browsers do not enable these commands if the active range's start node is neither editable nor an+ // editing host.if (command.is_one_of_ignoring_ascii_case(Editing::CommandNames::defaultParagraphSeparator,Editing::CommandNames::styleWithCSS,- Editing::CommandNames::useCSS))- return true;+ Editing::CommandNames::useCSS)) {+ auto active_range = Editing::active_range(document);+ return !active_range || active_range->start_container()->is_editable_or_editing_host();+ }// INTEROP: The spec lists undo and redo among the always-enabled miscellaneous commands, but in Chromium// queryCommandEnabled("undo") is true only when there is a step to undo, and execCommand("undo") on andiff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/exec-command-without-editable-element.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/exec-command-without-editable-element.tentative.txtindex 8f9e97d3b14..c49c9dc06c7 100644--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/exec-command-without-editable-element.tentative.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/exec-command-without-editable-element.tentative.txt@@ -1,9 +1,9 @@Harness status: OK-Found 384 tests+Found 382 tests-360 Pass-24 Fail+378 Pass+4 FailPass ChildDocument.execCommand(bold, false, bold) with a[b]c: calling execCommandPass ChildDocument.execCommand(bold, false, bold) with a[b]c: checking event on focused documentPass ChildDocument.execCommand(bold, false, bold) with a[b]c: checking event on executed document@@ -174,25 +174,24 @@ Pass ChildDocument.execCommand(formatblock, false, div) with a[b]c: checking evePass ChildDocument.execCommand(formatblock, false, div) with a[b]c: checking event on executed documentPass ChildDocument.execCommand(formatblock, false, div) with a[b]c: checking result content in focused documentPass ChildDocument.execCommand(formatblock, false, div) with a[b]c: checking result content in executed document-Fail ChildDocument.execCommand(styleWithCSS, false, true): calling execCommand to initialize+Pass ChildDocument.execCommand(styleWithCSS, false, true): calling execCommand to initializePass ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after initializingPass ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focus document after initializing-Fail ChildDocument.execCommand(styleWithCSS, false, true): calling execCommand to set state-Fail ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document+Pass ChildDocument.execCommand(styleWithCSS, false, true): calling execCommand to set state+Pass ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed documentPass ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focused document-Fail ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandValue on executed document-Fail ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after making executed document editable-Fail ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to initialize+Pass ChildDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after making executed document editable+Pass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to initializePass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed document after initializingPass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on focus document after initializing-Fail ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to set state+Pass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to set statePass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed documentPass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on focused documentPass ChildDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed document after making executed document editable-Fail ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to initialize+Pass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to initializePass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed document after initializingPass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on focus document after initializing-Fail ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to set state+Pass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to set statePass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed documentPass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on focused documentPass ChildDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed document after making executed document editable@@ -366,25 +365,24 @@ Pass ParentDocument.execCommand(formatblock, false, div) with a[b]c: checking evPass ParentDocument.execCommand(formatblock, false, div) with a[b]c: checking event on executed documentPass ParentDocument.execCommand(formatblock, false, div) with a[b]c: checking result content in focused documentPass ParentDocument.execCommand(formatblock, false, div) with a[b]c: checking result content in executed document-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling execCommand to initialize+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling execCommand to initializePass ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after initializing-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focus document after initializing-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling execCommand to set state-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focused document-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandValue on executed document-Fail ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after making executed document editable-Fail ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to initialize+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focus document after initializing+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling execCommand to set state+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on focused document+Pass ParentDocument.execCommand(styleWithCSS, false, true): calling queryCommandState on executed document after making executed document editable+Pass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to initializePass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed document after initializingPass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on focus document after initializing-Fail ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to set state+Pass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling execCommand to set statePass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed documentPass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on focused documentPass ParentDocument.execCommand(defaultParagraphSeparator, false, div): calling queryCommandState on executed document after making executed document editable-Fail ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to initialize+Pass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to initializePass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed document after initializingPass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on focus document after initializing-Fail ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to set state+Pass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling execCommand to set statePass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed documentPass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on focused documentPass ParentDocument.execCommand(defaultParagraphSeparator, false, p): calling queryCommandState on executed document after making executed document editable\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/Editing/execCommand-styleWithCSS.html b/Tests/LibWeb/Text/input/Editing/execCommand-styleWithCSS.htmlindex 58f1a194bb6..e38dadf6979 100644--- a/Tests/LibWeb/Text/input/Editing/execCommand-styleWithCSS.html+++ b/Tests/LibWeb/Text/input/Editing/execCommand-styleWithCSS.html@@ -3,10 +3,11 @@<div contenteditable="true">foobar</div><script>test(() => {+ const divElm = document.querySelector('div');const range = document.createRange();+ range.setStart(divElm, 0);getSelection().addRange(range);- const divElm = document.querySelector('div');const report = () => println(`Div contents: "${divElm.innerHTML}" bold state: ${document.queryCommandState('bold')}`);report();diff --git a/Tests/LibWeb/Text/input/Editing/execCommand-useCSS.html b/Tests/LibWeb/Text/input/Editing/execCommand-useCSS.htmlindex 450544be737..9123fbf5490 100644--- a/Tests/LibWeb/Text/input/Editing/execCommand-useCSS.html+++ b/Tests/LibWeb/Text/input/Editing/execCommand-useCSS.html@@ -3,10 +3,11 @@<div contenteditable="true">foobar</div><script>test(() => {+ const divElm = document.querySelector('div');const range = document.createRange();+ range.setStart(divElm, 0);getSelection().addRange(range);- const divElm = document.querySelector('div');const report = () => println(`Div contents: "${divElm.innerHTML}" bold state: ${document.queryCommandState('bold')}`);report();