1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 04:17:34 +00:00

LibWeb: Use DOMException in HTMLElement::set_content_editable()

This commit is contained in:
Linus Groh 2021-02-20 00:43:08 +01:00 committed by Andreas Kling
parent dd621cc650
commit 4e1de09340
2 changed files with 9 additions and 6 deletions

View file

@ -28,8 +28,10 @@
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Parser.h> #include <LibJS/Parser.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/ScriptFunction.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventListener.h> #include <LibWeb/DOM/EventListener.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/HTML/EventHandler.h> #include <LibWeb/HTML/EventHandler.h>
#include <LibWeb/HTML/HTMLAnchorElement.h> #include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/HTMLElement.h> #include <LibWeb/HTML/HTMLElement.h>
@ -89,21 +91,22 @@ String HTMLElement::content_editable() const
} }
} }
void HTMLElement::set_content_editable(const String& content_editable) // https://html.spec.whatwg.org/multipage/interaction.html#contenteditable
DOM::ExceptionOr<void> HTMLElement::set_content_editable(const String& content_editable)
{ {
if (content_editable.equals_ignoring_case("inherit")) { if (content_editable.equals_ignoring_case("inherit")) {
remove_attribute(HTML::AttributeNames::contenteditable); remove_attribute(HTML::AttributeNames::contenteditable);
return; return {};
} }
if (content_editable.equals_ignoring_case("true")) { if (content_editable.equals_ignoring_case("true")) {
set_attribute(HTML::AttributeNames::contenteditable, "true"); set_attribute(HTML::AttributeNames::contenteditable, "true");
return; return {};
} }
if (content_editable.equals_ignoring_case("false")) { if (content_editable.equals_ignoring_case("false")) {
set_attribute(HTML::AttributeNames::contenteditable, "false"); set_attribute(HTML::AttributeNames::contenteditable, "false");
return; return {};
} }
// FIXME: otherwise the attribute setter must throw a "SyntaxError" DOMException. return DOM::SyntaxError::create("Invalid contentEditable value, must be 'true', 'false', or 'inherit'");
} }
void HTMLElement::set_inner_text(StringView text) void HTMLElement::set_inner_text(StringView text)

View file

@ -45,7 +45,7 @@ public:
virtual bool is_editable() const final; virtual bool is_editable() const final;
String content_editable() const; String content_editable() const;
void set_content_editable(const String&); DOM::ExceptionOr<void> set_content_editable(const String&);
String inner_text(); String inner_text();
void set_inner_text(StringView); void set_inner_text(StringView);