diff --git a/Libraries/LibWeb/ARIA/ARIAMixin.h b/Libraries/LibWeb/ARIA/ARIAMixin.h index 13be0d2858f..19f37cdd53e 100644 --- a/Libraries/LibWeb/ARIA/ARIAMixin.h +++ b/Libraries/LibWeb/ARIA/ARIAMixin.h @@ -34,7 +34,7 @@ public: #define __ENUMERATE_ARIA_ATTRIBUTE(name, attribute) \ virtual Optional name() const = 0; \ - virtual WebIDL::ExceptionOr set_##name(Optional const&) = 0; + virtual void set_##name(Optional const&) = 0; ENUMERATE_ARIA_ATTRIBUTES #undef __ENUMERATE_ARIA_ATTRIBUTE diff --git a/Libraries/LibWeb/Bindings/AudioConstructor.cpp b/Libraries/LibWeb/Bindings/AudioConstructor.cpp index 5a233f76f7d..795ba565675 100644 --- a/Libraries/LibWeb/Bindings/AudioConstructor.cpp +++ b/Libraries/LibWeb/Bindings/AudioConstructor.cpp @@ -49,7 +49,7 @@ JS::ThrowCompletionOr> AudioConstructor::construct(FunctionO auto audio = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { return DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); })); // 3. Set an attribute value for audio using "preload" and "auto". - MUST(audio->set_attribute(HTML::AttributeNames::preload, "auto"_string)); + audio->set_attribute_value(HTML::AttributeNames::preload, "auto"_string); auto src_value = vm.argument(0); @@ -57,7 +57,7 @@ JS::ThrowCompletionOr> AudioConstructor::construct(FunctionO // (This will cause the user agent to invoke the object's resource selection algorithm before returning.) if (!src_value.is_undefined()) { auto src = TRY(src_value.to_string(vm)); - MUST(audio->set_attribute(HTML::AttributeNames::src, move(src))); + audio->set_attribute_value(HTML::AttributeNames::src, move(src)); } // 5. Return audio. diff --git a/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 8111de81942..4cd21a321b4 100644 --- a/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -53,13 +53,13 @@ JS::ThrowCompletionOr> ImageConstructor::construct(FunctionO // 3. If width is given, then set an attribute value for img using "width" and width. if (vm.argument_count() > 0) { u32 width = TRY(vm.argument(0).to_u32(vm)); - MUST(image_element->set_attribute(HTML::AttributeNames::width, MUST(String::formatted("{}", width)))); + image_element->set_attribute_value(HTML::AttributeNames::width, MUST(String::formatted("{}", width))); } // 4. If height is given, then set an attribute value for img using "height" and height. if (vm.argument_count() > 1) { u32 height = TRY(vm.argument(1).to_u32(vm)); - MUST(image_element->set_attribute(HTML::AttributeNames::height, MUST(String::formatted("{}", height)))); + image_element->set_attribute_value(HTML::AttributeNames::height, MUST(String::formatted("{}", height))); } // 5. Return img. diff --git a/Libraries/LibWeb/Bindings/OptionConstructor.cpp b/Libraries/LibWeb/Bindings/OptionConstructor.cpp index 95542237d1b..8793bb3b194 100644 --- a/Libraries/LibWeb/Bindings/OptionConstructor.cpp +++ b/Libraries/LibWeb/Bindings/OptionConstructor.cpp @@ -69,14 +69,14 @@ JS::ThrowCompletionOr> OptionConstructor::construct(Function // 4. If value is given, then set an attribute value for option using "value" and value. if (!vm.argument(1).is_undefined()) { auto value = TRY(vm.argument(1).to_string(vm)); - MUST(option_element->set_attribute(HTML::AttributeNames::value, value)); + option_element->set_attribute_value(HTML::AttributeNames::value, value); } // 5. If defaultSelected is true, then set an attribute value for option using "selected" and the empty string. if (vm.argument_count() > 2) { auto default_selected = vm.argument(2).to_boolean(); if (default_selected) { - MUST(option_element->set_attribute(HTML::AttributeNames::selected, String {})); + option_element->set_attribute_value(HTML::AttributeNames::selected, String {}); } } diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index aecb60a3d30..9df630cb444 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -48,7 +48,7 @@ void CSSStyleDeclaration::update_style_attribute() set_is_updating(true); // 5. Set an attribute value for owner node using "style" and the result of serializing declaration block. - MUST(owner_node()->element().set_attribute(HTML::AttributeNames::style, serialized())); + owner_node()->element().set_attribute_value(HTML::AttributeNames::style, serialized()); // 6. Unset declaration block’s updating flag. set_is_updating(false); diff --git a/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Libraries/LibWeb/DOM/DOMTokenList.cpp index 8ab3466f0e6..5fc5b761c9a 100644 --- a/Libraries/LibWeb/DOM/DOMTokenList.cpp +++ b/Libraries/LibWeb/DOM/DOMTokenList.cpp @@ -258,7 +258,7 @@ void DOMTokenList::set_value(String const& value) if (!associated_element) return; - MUST(associated_element->set_attribute(m_associated_attribute, value)); + associated_element->set_attribute_value(m_associated_attribute, value); } WebIDL::ExceptionOr DOMTokenList::validate_token(StringView token) const @@ -294,7 +294,7 @@ void DOMTokenList::run_update_steps() return; // 2. Set an attribute value for the associated element using associated attribute’s local name and the result of running the ordered set serializer for token set. - MUST(associated_element->set_attribute(m_associated_attribute, serialize_ordered_set())); + associated_element->set_attribute_value(m_associated_attribute, serialize_ordered_set()); } Optional DOMTokenList::item_value(size_t index) const diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index a6ec996c82b..654ddccd43f 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -3189,7 +3189,7 @@ String Document::fg_color() const void Document::set_fg_color(String const& value) { if (auto* body_element = body(); body_element && !is(*body_element)) - MUST(body_element->set_attribute(HTML::AttributeNames::text, value)); + body_element->set_attribute_value(HTML::AttributeNames::text, value); } String Document::link_color() const @@ -3202,7 +3202,7 @@ String Document::link_color() const void Document::set_link_color(String const& value) { if (auto* body_element = body(); body_element && !is(*body_element)) - MUST(body_element->set_attribute(HTML::AttributeNames::link, value)); + body_element->set_attribute_value(HTML::AttributeNames::link, value); } String Document::vlink_color() const @@ -3215,7 +3215,7 @@ String Document::vlink_color() const void Document::set_vlink_color(String const& value) { if (auto* body_element = body(); body_element && !is(*body_element)) - MUST(body_element->set_attribute(HTML::AttributeNames::vlink, value)); + body_element->set_attribute_value(HTML::AttributeNames::vlink, value); } String Document::alink_color() const @@ -3228,7 +3228,7 @@ String Document::alink_color() const void Document::set_alink_color(String const& value) { if (auto* body_element = body(); body_element && !is(*body_element)) - MUST(body_element->set_attribute(HTML::AttributeNames::alink, value)); + body_element->set_attribute_value(HTML::AttributeNames::alink, value); } String Document::bg_color() const @@ -3241,7 +3241,7 @@ String Document::bg_color() const void Document::set_bg_color(String const& value) { if (auto* body_element = body(); body_element && !is(*body_element)) - MUST(body_element->set_attribute(HTML::AttributeNames::bgcolor, value)); + body_element->set_attribute_value(HTML::AttributeNames::bgcolor, value); } String Document::dump_dom_tree_as_json() const diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cpp index d92a6db0aaf..b647d51c567 100644 --- a/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -296,7 +296,7 @@ static WebIDL::ExceptionOr> load_media_document(HTML::Nav }; auto style_element = TRY(DOM::create_element(document, HTML::TagNames::style, Namespace::HTML)); - MUST(style_element->set_text_content(R"~~~( + style_element->string_replace_all(R"~~~( :root { background-color: #222; } @@ -310,29 +310,29 @@ static WebIDL::ExceptionOr> load_media_document(HTML::Nav img { background-color: #fff; } - )~~~"_utf16)); + )~~~"_utf16); TRY(document->head()->append_child(style_element)); auto url_string = document->url_string(); if (type.is_image()) { auto img_element = TRY(DOM::create_element(document, HTML::TagNames::img, Namespace::HTML)); - TRY(img_element->set_attribute(HTML::AttributeNames::src, url_string)); + img_element->set_attribute_value(HTML::AttributeNames::src, url_string); TRY(document->body()->append_child(img_element)); TRY(insert_title(document, url_string)); } else if (type.type() == "video"sv) { auto video_element = TRY(DOM::create_element(document, HTML::TagNames::video, Namespace::HTML)); - TRY(video_element->set_attribute(HTML::AttributeNames::src, url_string)); - TRY(video_element->set_attribute(HTML::AttributeNames::autoplay, String {})); - TRY(video_element->set_attribute(HTML::AttributeNames::controls, String {})); + video_element->set_attribute_value(HTML::AttributeNames::src, url_string); + video_element->set_attribute_value(HTML::AttributeNames::autoplay, String {}); + video_element->set_attribute_value(HTML::AttributeNames::controls, String {}); TRY(document->body()->append_child(video_element)); TRY(insert_title(document, url_string)); } else if (type.type() == "audio"sv) { auto audio_element = TRY(DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML)); - TRY(audio_element->set_attribute(HTML::AttributeNames::src, url_string)); - TRY(audio_element->set_attribute(HTML::AttributeNames::autoplay, String {})); - TRY(audio_element->set_attribute(HTML::AttributeNames::controls, String {})); + audio_element->set_attribute_value(HTML::AttributeNames::src, url_string); + audio_element->set_attribute_value(HTML::AttributeNames::autoplay, String {}); + audio_element->set_attribute_value(HTML::AttributeNames::controls, String {}); TRY(document->body()->append_child(audio_element)); TRY(insert_title(document, url_string)); diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index fd2293d56b8..85a71449dbc 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -210,7 +210,7 @@ GC::Ptr Element::get_attribute_node_ns(Optional const& namespac // FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 // https://whatpr.org/dom/1268.html#dom-element-setattribute -WebIDL::ExceptionOr Element::set_attribute(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) +WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) { // 1. If qualifiedName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException. if (!is_valid_attribute_local_name(qualified_name)) @@ -245,9 +245,9 @@ WebIDL::ExceptionOr Element::set_attribute(FlyString qualified_name, Varia // FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 // https://whatpr.org/dom/1268.html#dom-element-setattribute -WebIDL::ExceptionOr Element::set_attribute(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value) +WebIDL::ExceptionOr Element::set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value) { - return set_attribute(move(qualified_name), + return set_attribute_for_bindings(move(qualified_name), value.visit( [](auto const& trusted_type) -> Variant, GC::Root, GC::Root, Utf16String> { return trusted_type; }, [](String const& string) -> Variant, GC::Root, GC::Root, Utf16String> { return Utf16String::from_utf8(string); })); @@ -365,7 +365,7 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option // FIXME: Trusted Types integration with DOM is still under review https://github.com/whatwg/dom/pull/1268 // https://whatpr.org/dom/1268.html#dom-element-setattributens -WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) +WebIDL::ExceptionOr Element::set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value) { // 1. Let (namespace, prefix, localName) be the result of validating and extracting namespace and qualifiedName given "element". auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name, ValidationContext::Element)); @@ -421,14 +421,14 @@ void Element::set_attribute_value(FlyString const& local_name, String const& val } // https://dom.spec.whatwg.org/#dom-element-setattributenode -WebIDL::ExceptionOr> Element::set_attribute_node(Attr& attr) +WebIDL::ExceptionOr> Element::set_attribute_node_for_bindings(Attr& attr) { // The setAttributeNode(attr) and setAttributeNodeNS(attr) methods steps are to return the result of setting an attribute given attr and this. return attributes()->set_attribute(attr); } // https://dom.spec.whatwg.org/#dom-element-setattributenodens -WebIDL::ExceptionOr> Element::set_attribute_node_ns(Attr& attr) +WebIDL::ExceptionOr> Element::set_attribute_node_ns_for_bindings(Attr& attr) { // The setAttributeNode(attr) and setAttributeNodeNS(attr) methods steps are to return the result of setting an attribute given attr and this. return attributes()->set_attribute(attr); @@ -1746,7 +1746,7 @@ i32 Element::tab_index() const // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex void Element::set_tab_index(i32 tab_index) { - MUST(set_attribute(HTML::AttributeNames::tabindex, String::number(tab_index))); + set_attribute_value(HTML::AttributeNames::tabindex, String::number(tab_index)); } // https://drafts.csswg.org/cssom-view/#potentially-scrollable @@ -2544,6 +2544,22 @@ ErrorOr Element::scroll_into_view(Optional Element::name() const \ + { \ + return get_attribute(ARIA::AttributeNames::name); \ + } \ + \ + void Element::set_##name(Optional const& value) \ + { \ + if (value.has_value()) \ + set_attribute_value(ARIA::AttributeNames::name, *value); \ + else \ + remove_attribute(ARIA::AttributeNames::name); \ + } +ENUMERATE_ARIA_ATTRIBUTES +#undef __ENUMERATE_ARIA_ATTRIBUTE + void Element::invalidate_style_after_attribute_change(FlyString const& attribute_name, Optional const& old_value, Optional const& new_value) { Vector changed_properties; diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 1ae51ce3220..74b6bbfcd22 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -149,13 +149,13 @@ public: Optional lang() const; - WebIDL::ExceptionOr set_attribute(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value); - WebIDL::ExceptionOr set_attribute(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); + WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); + WebIDL::ExceptionOr set_attribute_for_bindings(FlyString qualified_name, Variant, GC::Root, GC::Root, String> const& value); - WebIDL::ExceptionOr set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); + WebIDL::ExceptionOr set_attribute_ns_for_bindings(Optional const& namespace_, FlyString const& qualified_name, Variant, GC::Root, GC::Root, Utf16String> const& value); void set_attribute_value(FlyString const& local_name, String const& value, Optional const& prefix = {}, Optional const& namespace_ = {}); - WebIDL::ExceptionOr> set_attribute_node(Attr&); - WebIDL::ExceptionOr> set_attribute_node_ns(Attr&); + WebIDL::ExceptionOr> set_attribute_node_for_bindings(Attr&); + WebIDL::ExceptionOr> set_attribute_node_ns_for_bindings(Attr&); void append_attribute(FlyString const& name, String const& value); void append_attribute(Attr&); @@ -336,20 +336,9 @@ public: ErrorOr scroll_into_view(Optional> = {}); // https://www.w3.org/TR/wai-aria-1.2/#ARIAMixin -#define __ENUMERATE_ARIA_ATTRIBUTE(name, attribute) \ - Optional name() const override \ - { \ - return get_attribute(ARIA::AttributeNames::name); \ - } \ - \ - WebIDL::ExceptionOr set_##name(Optional const& value) override \ - { \ - if (value.has_value()) \ - TRY(set_attribute(ARIA::AttributeNames::name, *value)); \ - else \ - remove_attribute(ARIA::AttributeNames::name); \ - return {}; \ - } +#define __ENUMERATE_ARIA_ATTRIBUTE(name, attribute) \ + virtual Optional name() const override; \ + virtual void set_##name(Optional const& value) override; ENUMERATE_ARIA_ATTRIBUTES #undef __ENUMERATE_ARIA_ATTRIBUTE diff --git a/Libraries/LibWeb/DOM/Element.idl b/Libraries/LibWeb/DOM/Element.idl index f2f9c2e4f62..2fa94bb1ad6 100644 --- a/Libraries/LibWeb/DOM/Element.idl +++ b/Libraries/LibWeb/DOM/Element.idl @@ -54,8 +54,8 @@ interface Element : Node { sequence getAttributeNames(); DOMString? getAttribute(DOMString qualifiedName); DOMString? getAttributeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName); - [CEReactions] undefined setAttribute(DOMString qualifiedName, (TrustedType or Utf16DOMString) value); - [CEReactions] undefined setAttributeNS([FlyString] DOMString? namespace , [FlyString] DOMString qualifiedName , (TrustedType or Utf16DOMString) value); + [CEReactions, ImplementedAs=set_attribute_for_bindings] undefined setAttribute(DOMString qualifiedName, (TrustedType or Utf16DOMString) value); + [CEReactions, ImplementedAs=set_attribute_ns_for_bindings] undefined setAttributeNS([FlyString] DOMString? namespace, [FlyString] DOMString qualifiedName, (TrustedType or Utf16DOMString) value); [CEReactions] undefined removeAttribute([FlyString] DOMString qualifiedName); [CEReactions] undefined removeAttributeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName); [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); @@ -64,8 +64,8 @@ interface Element : Node { Attr? getAttributeNode([FlyString] DOMString qualifiedName); Attr? getAttributeNodeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName); - [CEReactions] Attr? setAttributeNode(Attr attr); - [CEReactions] Attr? setAttributeNodeNS(Attr attr); + [CEReactions, ImplementedAs=set_attribute_node_for_bindings] Attr? setAttributeNode(Attr attr); + [CEReactions, ImplementedAs=set_attribute_node_ns_for_bindings] Attr? setAttributeNodeNS(Attr attr); [CEReactions] Attr removeAttributeNode(Attr attr); ShadowRoot attachShadow(ShadowRootInit init); diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index 3e8544104f3..2c2471b3390 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -86,7 +86,7 @@ bool command_create_link_action(DOM::Document& document, Utf16String const& valu return IterationDecision::Break; if (auto* anchor = as_if(*ancestor); anchor && anchor->is_editable() && anchor->has_attribute(HTML::AttributeNames::href)) - MUST(anchor->set_href(value.to_utf8_but_should_be_ported_to_utf16())); + anchor->set_href(value.to_utf8_but_should_be_ported_to_utf16()); visited_ancestors.set(ancestor.ptr()); return IterationDecision::Continue; }); @@ -1324,7 +1324,7 @@ bool command_insert_image_action(DOM::Document& document, Utf16String const& val auto img = MUST(DOM::create_element(document, HTML::TagNames::img, Namespace::HTML)); // 7. Run setAttribute("src", value) on img. - MUST(img->set_attribute(HTML::AttributeNames::src, value)); + img->set_attribute_value(HTML::AttributeNames::src, value.to_utf8_but_should_be_ported_to_utf16()); // 8. Run insertNode(img) on range. MUST(range->insert_node(img)); @@ -1690,7 +1690,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16String const& // 23. Copy all attributes of container to new container. container_element.for_each_attribute([&new_container](FlyString const& name, String const& value) { - MUST(new_container->set_attribute(name, value)); + new_container->set_attribute_value(name, value); }); // 24. If new container has an id attribute, unset it. diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index e4053bf50ea..1b9e288df3a 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -1465,7 +1465,7 @@ void force_the_value(GC::Ref node, FlyString const& command, Optional // 2. Set the color attribute of new parent to the result of applying the rules for serializing simple color // values to new value (interpreted as a simple color). - MUST(new_parent->set_attribute(HTML::AttributeNames::color, new_value_color->to_string_without_alpha())); + new_parent->set_attribute_value(HTML::AttributeNames::color, new_value_color->to_string_without_alpha()); } } @@ -1473,7 +1473,7 @@ void force_the_value(GC::Ref node, FlyString const& command, Optional // ownerDocument of node, then set the face attribute of new parent to new value. if (command == CommandNames::fontName) { new_parent = MUST(DOM::create_element(document, HTML::TagNames::font, Namespace::HTML)); - MUST(new_parent->set_attribute(HTML::AttributeNames::face, *new_value)); + new_parent->set_attribute_value(HTML::AttributeNames::face, new_value.value().to_utf8_but_should_be_ported_to_utf16()); } } @@ -1483,7 +1483,7 @@ void force_the_value(GC::Ref node, FlyString const& command, Optional new_parent = MUST(DOM::create_element(document, HTML::TagNames::a, Namespace::HTML)); // 2. Set the href attribute of new parent to new value. - MUST(new_parent->set_attribute(HTML::AttributeNames::href, *new_value)); + new_parent->set_attribute_value(HTML::AttributeNames::href, new_value.value().to_utf8_but_should_be_ported_to_utf16()); // 3. Let ancestor be node's parent. GC::Ptr ancestor = node->parent(); @@ -1516,7 +1516,7 @@ void force_the_value(GC::Ref node, FlyString const& command, Optional // * xx-large: 6 // * xxx-large: 7 auto size = font_sizes.first_index_of(new_value.value()).value() + 1; - MUST(new_parent->set_attribute(HTML::AttributeNames::size, String::number(size))); + new_parent->set_attribute_value(HTML::AttributeNames::size, String::number(size)); } // 13. If command is "subscript" or "superscript" and new value is "subscript", let new parent be the result of @@ -3793,7 +3793,7 @@ GC::Ref set_the_tag_name(GC::Ref element, FlyString // 5. Copy all attributes of element to replacement element, in order. element->for_each_attribute([&replacement_element](FlyString const& name, String const& value) { - MUST(replacement_element->set_attribute(name, value)); + replacement_element->set_attribute_value(name, value); }); // 6. While element has children, append the first child of element as the last child of replacement element, preserving ranges. diff --git a/Libraries/LibWeb/HTML/AutocompleteElement.cpp b/Libraries/LibWeb/HTML/AutocompleteElement.cpp index 5433389e154..433522fd64b 100644 --- a/Libraries/LibWeb/HTML/AutocompleteElement.cpp +++ b/Libraries/LibWeb/HTML/AutocompleteElement.cpp @@ -48,11 +48,10 @@ String AutocompleteElement::autocomplete() const return details.value; } -WebIDL::ExceptionOr AutocompleteElement::set_autocomplete(String const& value) +void AutocompleteElement::set_autocomplete(String const& value) { // The autocomplete IDL attribute [...] on setting, must reflect the content attribute of the same name. - TRY(autocomplete_element_to_html_element().set_attribute(AttributeNames::autocomplete, value)); - return {}; + autocomplete_element_to_html_element().set_attribute_value(AttributeNames::autocomplete, value); } enum class Category { diff --git a/Libraries/LibWeb/HTML/AutocompleteElement.h b/Libraries/LibWeb/HTML/AutocompleteElement.h index 548aa5b5c5b..b90112f7d37 100644 --- a/Libraries/LibWeb/HTML/AutocompleteElement.h +++ b/Libraries/LibWeb/HTML/AutocompleteElement.h @@ -30,7 +30,7 @@ public: Vector autocomplete_tokens() const; String autocomplete() const; - WebIDL::ExceptionOr set_autocomplete(String const&); + void set_autocomplete(String const&); // Each input element to which the autocomplete attribute applies [...] has // an autofill hint set, an autofill scope, an autofill field name, diff --git a/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Libraries/LibWeb/HTML/DOMStringMap.cpp index c9515971bbf..42ae31b2316 100644 --- a/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -167,7 +167,7 @@ WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(String c return WebIDL::InvalidCharacterError::create(realm(), "Name is not a valid attribute local name."_utf16); // 5. Set an attribute value for the DOMStringMap's associated element using name and value. - TRY(m_associated_element->set_attribute(data_name, value)); + m_associated_element->set_attribute_value(data_name, value); return {}; } diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp index c74901017c5..df59feeb902 100644 --- a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp +++ b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp @@ -230,10 +230,10 @@ String FormAssociatedElement::form_action() const return {}; } -WebIDL::ExceptionOr FormAssociatedElement::set_form_action(String const& value) +void FormAssociatedElement::set_form_action(String const& value) { auto& html_element = form_associated_element_to_html_element(); - return html_element.set_attribute(HTML::AttributeNames::formaction, value); + html_element.set_attribute_value(HTML::AttributeNames::formaction, value); } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-reportvalidity diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.h b/Libraries/LibWeb/HTML/FormAssociatedElement.h index 8fd3235baf3..4017dc546ee 100644 --- a/Libraries/LibWeb/HTML/FormAssociatedElement.h +++ b/Libraries/LibWeb/HTML/FormAssociatedElement.h @@ -138,7 +138,7 @@ public: virtual void clear_algorithm(); String form_action() const; - WebIDL::ExceptionOr set_form_action(String const&); + void set_form_action(String const&); // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-reportvalidity bool report_validity(); diff --git a/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index 5afc6514b2f..c6338dd590e 100644 --- a/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -57,9 +57,9 @@ Optional HTMLAnchorElement::hyperlink_element_utils_href() const return attribute(HTML::AttributeNames::href); } -WebIDL::ExceptionOr HTMLAnchorElement::set_hyperlink_element_utils_href(String href) +void HTMLAnchorElement::set_hyperlink_element_utils_href(String href) { - return set_attribute(HTML::AttributeNames::href, move(href)); + set_attribute_value(HTML::AttributeNames::href, move(href)); } Optional HTMLAnchorElement::hyperlink_element_utils_referrerpolicy() const diff --git a/Libraries/LibWeb/HTML/HTMLAnchorElement.h b/Libraries/LibWeb/HTML/HTMLAnchorElement.h index 8ffd4095063..6eb6b280b77 100644 --- a/Libraries/LibWeb/HTML/HTMLAnchorElement.h +++ b/Libraries/LibWeb/HTML/HTMLAnchorElement.h @@ -55,7 +55,7 @@ private: virtual DOM::Document& hyperlink_element_utils_document() override { return document(); } virtual DOM::Element& hyperlink_element_utils_element() override { return *this; } virtual Optional hyperlink_element_utils_href() const override; - virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) override; + virtual void set_hyperlink_element_utils_href(String) override; virtual Optional hyperlink_element_utils_referrerpolicy() const override; virtual bool hyperlink_element_utils_is_html_anchor_element() const final { return true; } virtual bool hyperlink_element_utils_is_connected() const final { return is_connected(); } diff --git a/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLAreaElement.cpp index 343ea5af3ef..68066fda6bc 100644 --- a/Libraries/LibWeb/HTML/HTMLAreaElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLAreaElement.cpp @@ -59,9 +59,9 @@ Optional HTMLAreaElement::hyperlink_element_utils_href() const return attribute(HTML::AttributeNames::href); } -WebIDL::ExceptionOr HTMLAreaElement::set_hyperlink_element_utils_href(String href) +void HTMLAreaElement::set_hyperlink_element_utils_href(String href) { - return set_attribute(HTML::AttributeNames::href, move(href)); + set_attribute_value(HTML::AttributeNames::href, move(href)); } Optional HTMLAreaElement::hyperlink_element_utils_referrerpolicy() const diff --git a/Libraries/LibWeb/HTML/HTMLAreaElement.h b/Libraries/LibWeb/HTML/HTMLAreaElement.h index cdcdd0417fa..2c224d7b755 100644 --- a/Libraries/LibWeb/HTML/HTMLAreaElement.h +++ b/Libraries/LibWeb/HTML/HTMLAreaElement.h @@ -38,7 +38,7 @@ private: virtual DOM::Document& hyperlink_element_utils_document() override { return document(); } virtual DOM::Element& hyperlink_element_utils_element() override { return *this; } virtual Optional hyperlink_element_utils_href() const override; - virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) override; + virtual void set_hyperlink_element_utils_href(String) override; virtual Optional hyperlink_element_utils_referrerpolicy() const override; virtual bool hyperlink_element_utils_is_html_anchor_element() const override { return false; } virtual bool hyperlink_element_utils_is_connected() const override { return is_connected(); } diff --git a/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index a6e7bf63e65..758fd95a001 100644 --- a/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -122,10 +122,10 @@ String HTMLBaseElement::href() const } // https://html.spec.whatwg.org/multipage/semantics.html#dom-base-href -WebIDL::ExceptionOr HTMLBaseElement::set_href(String const& href) +void HTMLBaseElement::set_href(String const& href) { // The href IDL attribute, on setting, must set the href content attribute to the given new value. - return set_attribute(AttributeNames::href, href); + set_attribute_value(AttributeNames::href, href); } } diff --git a/Libraries/LibWeb/HTML/HTMLBaseElement.h b/Libraries/LibWeb/HTML/HTMLBaseElement.h index dfa7806ba83..2d7bab65145 100644 --- a/Libraries/LibWeb/HTML/HTMLBaseElement.h +++ b/Libraries/LibWeb/HTML/HTMLBaseElement.h @@ -18,7 +18,7 @@ public: virtual ~HTMLBaseElement() override; String href() const; - WebIDL::ExceptionOr set_href(String const& href); + void set_href(String const& href); URL::URL const& frozen_base_url() const { return m_frozen_base_url; } diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index c416c61866e..9adb8b56362 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -93,10 +93,10 @@ String HTMLButtonElement::type_for_bindings() const } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-button-type -WebIDL::ExceptionOr HTMLButtonElement::set_type_for_bindings(String const& type) +void HTMLButtonElement::set_type_for_bindings(String const& type) { // The type setter steps are to set the type content attribute to the given value. - return set_attribute(HTML::AttributeNames::type, type); + set_attribute_value(HTML::AttributeNames::type, type); } void HTMLButtonElement::form_associated_element_attribute_changed(FlyString const& name, Optional const&, Optional const& value, Optional const& namespace_) @@ -339,9 +339,9 @@ String HTMLButtonElement::command() const } // https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:dom-button-command-2 -WebIDL::ExceptionOr HTMLButtonElement::set_command(String const& value) +void HTMLButtonElement::set_command(String const& value) { - return set_attribute(AttributeNames::command, value); + set_attribute_value(AttributeNames::command, value); } } diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Libraries/LibWeb/HTML/HTMLButtonElement.h index d0c860b8133..87f57230a56 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -41,7 +41,7 @@ public: TypeAttributeState type_state() const; String type_for_bindings() const; - WebIDL::ExceptionOr set_type_for_bindings(String const&); + void set_type_for_bindings(String const&); virtual void form_associated_element_attribute_changed(FlyString const& name, Optional const& old_value, Optional const& value, Optional const& namespace_) override; @@ -81,7 +81,7 @@ public: virtual void activation_behavior(DOM::Event const&) override; String command() const; - WebIDL::ExceptionOr set_command(String const&); + void set_command(String const&); GC::Ptr command_for_element() { return m_command_for_element; } void set_command_for_element(GC::Ptr value) { m_command_for_element = value; } diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.idl b/Libraries/LibWeb/HTML/HTMLButtonElement.idl index cf3514310c6..54522143cc0 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.idl +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.idl @@ -26,7 +26,7 @@ interface HTMLButtonElement : HTMLElement { [CEReactions, Reflect=formtarget] attribute DOMString formTarget; [CEReactions, Reflect] attribute DOMString name; [CEReactions, ImplementedAs=type_for_bindings, Enumerated=ButtonTypeState] attribute DOMString type; - [CEReactions, Reflect] attribute Utf16DOMString value; + [CEReactions, Reflect] attribute DOMString value; readonly attribute boolean willValidate; readonly attribute ValidityState validity; diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 5c2ede4f833..d840a54b899 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -162,26 +162,24 @@ void HTMLCanvasElement::notify_context_about_canvas_size_change() }); } -WebIDL::ExceptionOr HTMLCanvasElement::set_width(unsigned value) +void HTMLCanvasElement::set_width(unsigned value) { if (value > 2147483647) value = 300; - TRY(set_attribute(HTML::AttributeNames::width, String::number(value))); + set_attribute_value(HTML::AttributeNames::width, String::number(value)); notify_context_about_canvas_size_change(); reset_context_to_default_state(); - return {}; } -WebIDL::ExceptionOr HTMLCanvasElement::set_height(WebIDL::UnsignedLong value) +void HTMLCanvasElement::set_height(WebIDL::UnsignedLong value) { if (value > 2147483647) value = 150; - TRY(set_attribute(HTML::AttributeNames::height, String::number(value))); + set_attribute_value(HTML::AttributeNames::height, String::number(value)); notify_context_about_canvas_size_change(); reset_context_to_default_state(); - return {}; } void HTMLCanvasElement::attribute_changed(FlyString const& local_name, Optional const& old_value, Optional const& value, Optional const& namespace_) diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Libraries/LibWeb/HTML/HTMLCanvasElement.h index ab708f9d47b..4c1bc173204 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -34,8 +34,8 @@ public: WebIDL::UnsignedLong width() const; WebIDL::UnsignedLong height() const; - WebIDL::ExceptionOr set_width(WebIDL::UnsignedLong); - WebIDL::ExceptionOr set_height(WebIDL::UnsignedLong); + void set_width(WebIDL::UnsignedLong); + void set_height(WebIDL::UnsignedLong); virtual void attribute_changed(FlyString const& local_name, Optional const& old_value, Optional const& value, Optional const& namespace_) override; diff --git a/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index 655d4ba8903..4ef5abd82e0 100644 --- a/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -243,7 +243,7 @@ WebIDL::ExceptionOr HTMLDetailsElement::create_shadow_tree_if_needed() // The third child element is either a link or style element with the following styles for the default summary: auto style = TRY(DOM::create_element(document(), HTML::TagNames::style, Namespace::HTML)); - MUST(style->set_text_content(R"~~~( + auto style_text = realm.create(document(), R"~~~( :host summary { display: list-item; counter-increment: list-item 0; @@ -252,7 +252,8 @@ WebIDL::ExceptionOr HTMLDetailsElement::create_shadow_tree_if_needed() :host([open]) summary { list-style-type: disclosure-open; } - )~~~"_utf16)); + )~~~"_utf16); + MUST(style->append_child(style_text)); MUST(shadow_root->append_child(style)); m_summary_slot = static_cast(*summary_slot); @@ -300,14 +301,14 @@ void HTMLDetailsElement::update_shadow_tree_style() return; if (has_attribute(HTML::AttributeNames::open)) { - MUST(m_descendants_slot->set_attribute(HTML::AttributeNames::style, R"~~~( + m_descendants_slot->set_attribute_value(HTML::AttributeNames::style, R"~~~( display: block; - )~~~"_string)); + )~~~"_string); } else { - MUST(m_descendants_slot->set_attribute(HTML::AttributeNames::style, R"~~~( + m_descendants_slot->set_attribute_value(HTML::AttributeNames::style, R"~~~( display: block; content-visibility: hidden; - )~~~"_string)); + )~~~"_string); } shadow_root()->set_needs_layout_tree_update(true, DOM::SetNeedsLayoutTreeUpdateReason::DetailsElementOpenedOrClosed); diff --git a/Libraries/LibWeb/HTML/HTMLDialogElement.cpp b/Libraries/LibWeb/HTML/HTMLDialogElement.cpp index 33352026d13..288bc1bc0eb 100644 --- a/Libraries/LibWeb/HTML/HTMLDialogElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLDialogElement.cpp @@ -133,7 +133,7 @@ WebIDL::ExceptionOr HTMLDialogElement::show() queue_a_dialog_toggle_event_task("closed"_string, "open"_string, nullptr); // 6. Add an open attribute to this, whose value is the empty string. - TRY(set_attribute(AttributeNames::open, String {})); + set_attribute_value(AttributeNames::open, String {}); // 7. Assert: this's node document's open dialogs list does not contain this. VERIFY(!m_document->open_dialogs_list().contains_slow(GC::Ref(*this))); @@ -230,7 +230,7 @@ WebIDL::ExceptionOr HTMLDialogElement::show_a_modal_dialog(HTMLDialogEleme subject.queue_a_dialog_toggle_event_task("closed"_string, "open"_string, source); // 11. Add an open attribute to subject, whose value is the empty string. - TRY(subject.set_attribute(AttributeNames::open, String {})); + subject.set_attribute_value(AttributeNames::open, String {}); // 12. Set is modal of subject to true. subject.set_is_modal(true); diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index 1aa171c2468..86d9e68e311 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -122,9 +122,9 @@ void HTMLElement::set_translate(bool new_value) // On setting, it must set the content attribute's value to "yes" if the new value is true, and set the content // attribute's value to "no" otherwise. if (new_value) - MUST(set_attribute(HTML::AttributeNames::translate, "yes"_string)); + set_attribute_value(HTML::AttributeNames::translate, "yes"_string); else - MUST(set_attribute(HTML::AttributeNames::translate, "no"_string)); + set_attribute_value(HTML::AttributeNames::translate, "no"_string); } // https://html.spec.whatwg.org/multipage/dom.html#dom-dir @@ -144,7 +144,7 @@ StringView HTMLElement::dir() const void HTMLElement::set_dir(String const& dir) { - MUST(set_attribute(HTML::AttributeNames::dir, dir)); + set_attribute_value(HTML::AttributeNames::dir, dir); } bool HTMLElement::is_focusable() const @@ -183,15 +183,15 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(StringView content_e return {}; } if (content_editable.equals_ignoring_ascii_case("true"sv)) { - MUST(set_attribute(HTML::AttributeNames::contenteditable, "true"_string)); + set_attribute_value(HTML::AttributeNames::contenteditable, "true"_string); return {}; } if (content_editable.equals_ignoring_ascii_case("plaintext-only"sv)) { - MUST(set_attribute(HTML::AttributeNames::contenteditable, "plaintext-only"_string)); + set_attribute_value(HTML::AttributeNames::contenteditable, "plaintext-only"_string); return {}; } if (content_editable.equals_ignoring_ascii_case("false"sv)) { - MUST(set_attribute(HTML::AttributeNames::contenteditable, "false"_string)); + set_attribute_value(HTML::AttributeNames::contenteditable, "false"_string); return {}; } return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', 'plaintext-only' or 'inherit'"_utf16); @@ -879,7 +879,7 @@ void HTMLElement::set_hidden(Variant const& given_value) if (given_value.has()) { auto const& string = given_value.get(); if (string.equals_ignoring_ascii_case("until-found"sv)) { - MUST(set_attribute(HTML::AttributeNames::hidden, "until-found"_string)); + set_attribute_value(HTML::AttributeNames::hidden, "until-found"_string); return; } // 3. Otherwise, if the given value is the empty string, then remove the hidden attribute. @@ -910,7 +910,7 @@ void HTMLElement::set_hidden(Variant const& given_value) } } // 7. Otherwise, set the hidden attribute to the empty string. - MUST(set_attribute(HTML::AttributeNames::hidden, ""_string)); + set_attribute_value(HTML::AttributeNames::hidden, ""_string); } // https://html.spec.whatwg.org/multipage/interaction.html#dom-click @@ -1189,15 +1189,14 @@ Optional HTMLElement::popover() const } // https://html.spec.whatwg.org/multipage/popover.html#dom-popover -WebIDL::ExceptionOr HTMLElement::set_popover(Optional value) +void HTMLElement::set_popover(Optional value) { // FIXME: This should probably be `Reflect` in the IDL. // The popover IDL attribute must reflect the popover attribute, limited to only known values. if (value.has_value()) - return set_attribute(HTML::AttributeNames::popover, value.release_value()); - - remove_attribute(HTML::AttributeNames::popover); - return {}; + set_attribute_value(HTML::AttributeNames::popover, value.release_value()); + else + remove_attribute(HTML::AttributeNames::popover); } void HTMLElement::adjust_computed_style(CSS::ComputedProperties& style) @@ -2143,6 +2142,11 @@ bool HTMLElement::draggable() const return false; } +void HTMLElement::set_draggable(bool draggable) +{ + set_attribute_value(HTML::AttributeNames::draggable, draggable ? "true"_string : "false"_string); +} + // https://html.spec.whatwg.org/multipage/interaction.html#dom-spellcheck bool HTMLElement::spellcheck() const { @@ -2200,9 +2204,9 @@ void HTMLElement::set_spellcheck(bool spellcheck) { // On setting, if the new value is true, then the element's spellcheck content attribute must be set to "true", otherwise it must be set to "false". if (spellcheck) - MUST(set_attribute(HTML::AttributeNames::spellcheck, "true"_string)); + set_attribute_value(HTML::AttributeNames::spellcheck, "true"_string); else - MUST(set_attribute(HTML::AttributeNames::spellcheck, "false"_string)); + set_attribute_value(HTML::AttributeNames::spellcheck, "false"_string); } // https://html.spec.whatwg.org/multipage/interaction.html#dom-writingsuggestions @@ -2239,7 +2243,7 @@ String HTMLElement::writing_suggestions() const void HTMLElement::set_writing_suggestions(String const& given_value) { // 1. Set this's writingsuggestions content attribute to the given value. - MUST(set_attribute(HTML::AttributeNames::writingsuggestions, given_value)); + set_attribute_value(HTML::AttributeNames::writingsuggestions, given_value); } // https://html.spec.whatwg.org/multipage/interaction.html#own-autocapitalization-hint @@ -2332,7 +2336,7 @@ String HTMLElement::autocapitalize() const void HTMLElement::set_autocapitalize(String const& given_value) { // The autocapitalize setter steps are to set the autocapitalize content attribute to the given value. - MUST(set_attribute(HTML::AttributeNames::autocapitalize, given_value)); + set_attribute_value(HTML::AttributeNames::autocapitalize, given_value); } // https://html.spec.whatwg.org/multipage/interaction.html#used-autocorrection-state @@ -2390,9 +2394,9 @@ void HTMLElement::set_autocorrect(bool given_value) { // The setter steps are: if the given value is true, then the element's autocorrect attribute must be set to "on"; otherwise it must be set to "off". if (given_value) - MUST(set_attribute(HTML::AttributeNames::autocorrect, "on"_string)); + set_attribute_value(HTML::AttributeNames::autocorrect, "on"_string); else - MUST(set_attribute(HTML::AttributeNames::autocorrect, "off"_string)); + set_attribute_value(HTML::AttributeNames::autocorrect, "off"_string); } } diff --git a/Libraries/LibWeb/HTML/HTMLElement.h b/Libraries/LibWeb/HTML/HTMLElement.h index 267a87b2fac..be2a770fbe7 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Libraries/LibWeb/HTML/HTMLElement.h @@ -158,7 +158,7 @@ public: WebIDL::ExceptionOr> attach_internals(); - WebIDL::ExceptionOr set_popover(Optional value); + void set_popover(Optional value); Optional popover() const; Optional opened_in_popover_mode() const { return m_opened_in_popover_mode; } @@ -186,7 +186,7 @@ public: bool is_inert() const { return m_inert; } bool draggable() const; - void set_draggable(bool draggable) { MUST(set_attribute(HTML::AttributeNames::draggable, draggable ? "true"_string : "false"_string)); } + void set_draggable(bool draggable); virtual bool is_valid_invoker_command(String&) { return false; } virtual void invoker_command_steps(DOM::Element&, String&) { } diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 924670f5059..90f57d0a986 100644 --- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -692,10 +692,10 @@ GC::Ref HTMLFormElement::rel_list() } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method -WebIDL::ExceptionOr HTMLFormElement::set_method(String const& method) +void HTMLFormElement::set_method(String const& method) { // The method and enctype IDL attributes must reflect the respective content attributes of the same name, limited to only known values. - return set_attribute(AttributeNames::method, method); + set_attribute_value(AttributeNames::method, method); } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action @@ -715,9 +715,9 @@ String HTMLFormElement::action() const } // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-action -WebIDL::ExceptionOr HTMLFormElement::set_action(String const& value) +void HTMLFormElement::set_action(String const& value) { - return set_attribute(AttributeNames::action, value); + set_attribute_value(AttributeNames::action, value); } void HTMLFormElement::attribute_changed(FlyString const& name, Optional const& old_value, Optional const& value, Optional const& namespace_) diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.h b/Libraries/LibWeb/HTML/HTMLFormElement.h index 5d3cea330a5..ab02f4a393e 100644 --- a/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -96,12 +96,12 @@ public: bool constructing_entry_list() const { return m_constructing_entry_list; } void set_constructing_entry_list(bool value) { m_constructing_entry_list = value; } - WebIDL::ExceptionOr set_method(String const&); + void set_method(String const&); GC::Ref rel_list(); String action() const; - WebIDL::ExceptionOr set_action(String const&); + void set_action(String const&); FormAssociatedElement* default_button() const; diff --git a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index ccf884d88b2..994bd5e8bf5 100644 --- a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -446,17 +446,17 @@ String HTMLHyperlinkElementUtils::href() const } // https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-href -WebIDL::ExceptionOr HTMLHyperlinkElementUtils::set_href(String href) +void HTMLHyperlinkElementUtils::set_href(String href) { // The href attribute's setter must set this element's href content attribute's value to the given value. - return set_hyperlink_element_utils_href(move(href)); + set_hyperlink_element_utils_href(move(href)); } // https://html.spec.whatwg.org/multipage/links.html#update-href void HTMLHyperlinkElementUtils::update_href() { // To update href, set the element's href content attribute's value to the element's url, serialized. - MUST(set_hyperlink_element_utils_href(m_url->serialize())); + set_hyperlink_element_utils_href(m_url->serialize()); } bool HTMLHyperlinkElementUtils::cannot_navigate() const diff --git a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h index fc79bcabdc2..7481bf40210 100644 --- a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h +++ b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.h @@ -21,7 +21,7 @@ public: String origin() const; String href() const; - WebIDL::ExceptionOr set_href(String); + void set_href(String); String protocol() const; void set_protocol(StringView); @@ -54,7 +54,7 @@ protected: virtual DOM::Document& hyperlink_element_utils_document() = 0; virtual DOM::Element& hyperlink_element_utils_element() = 0; virtual Optional hyperlink_element_utils_href() const = 0; - virtual WebIDL::ExceptionOr set_hyperlink_element_utils_href(String) = 0; + virtual void set_hyperlink_element_utils_href(String) = 0; virtual Optional hyperlink_element_utils_referrerpolicy() const = 0; virtual bool hyperlink_element_utils_is_html_anchor_element() const = 0; virtual bool hyperlink_element_utils_is_connected() const = 0; diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 67080e513d5..2d536d57a41 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include namespace Web::HTML { diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp index d878ad79cae..b73a7440591 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -242,11 +242,11 @@ WebIDL::UnsignedLong HTMLImageElement::width() const return 0; } -WebIDL::ExceptionOr HTMLImageElement::set_width(WebIDL::UnsignedLong width) +void HTMLImageElement::set_width(WebIDL::UnsignedLong width) { if (width > 2147483647) width = 0; - return set_attribute(HTML::AttributeNames::width, String::number(width)); + set_attribute_value(HTML::AttributeNames::width, String::number(width)); } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-height @@ -273,11 +273,11 @@ WebIDL::UnsignedLong HTMLImageElement::height() const return 0; } -WebIDL::ExceptionOr HTMLImageElement::set_height(WebIDL::UnsignedLong height) +void HTMLImageElement::set_height(WebIDL::UnsignedLong height) { if (height > 2147483647) height = 0; - return set_attribute(HTML::AttributeNames::height, String::number(height)); + set_attribute_value(HTML::AttributeNames::height, String::number(height)); } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.h b/Libraries/LibWeb/HTML/HTMLImageElement.h index 652267ff801..e5115408fd2 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -53,10 +53,10 @@ public: virtual RefPtr default_image_bitmap_sized(Gfx::IntSize) const override; WebIDL::UnsignedLong width() const; - WebIDL::ExceptionOr set_width(WebIDL::UnsignedLong); + void set_width(WebIDL::UnsignedLong); WebIDL::UnsignedLong height() const; - WebIDL::ExceptionOr set_height(WebIDL::UnsignedLong); + void set_height(WebIDL::UnsignedLong); unsigned natural_width() const; unsigned natural_height() const; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 3c8da034550..4964e0dcf65 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -719,7 +719,7 @@ WebIDL::ExceptionOr HTMLInputElement::set_value(Utf16String const& value) case ValueAttributeMode::Default: case ValueAttributeMode::DefaultOn: // On setting, set the value of the element's value content attribute to the new value. - TRY(set_attribute(HTML::AttributeNames::value, value)); + set_attribute_value(HTML::AttributeNames::value, value.to_utf8_but_should_be_ported_to_utf16()); break; // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-filename @@ -1031,7 +1031,7 @@ void HTMLInputElement::create_button_input_shadow_tree() auto shadow_root = realm().create(document(), *this, Bindings::ShadowRootMode::Closed); set_shadow_root(shadow_root); auto text_container = MUST(DOM::create_element(document(), HTML::TagNames::span, Namespace::HTML)); - MUST(text_container->set_attribute(HTML::AttributeNames::style, "display: inline-block; pointer-events: none;"_string)); + text_container->set_attribute_value(HTML::AttributeNames::style, "display: inline-block; pointer-events: none;"_string); m_text_node = realm().create(document(), button_label()); MUST(text_container->append_child(*m_text_node)); @@ -1079,10 +1079,9 @@ void HTMLInputElement::create_text_input_shadow_tree() } MUST(element->append_child(*m_inner_text_element)); - m_text_node = realm().create(document(), Utf16String {}); + m_text_node = realm().create(document(), m_value); if (type_state() == TypeAttributeState::Password) m_text_node->set_is_password_input({}, true); - MUST(m_text_node->set_text_content(m_value)); handle_maxlength_attribute(); MUST(m_inner_text_element->append_child(*m_text_node)); @@ -1099,11 +1098,22 @@ void HTMLInputElement::create_text_input_shadow_tree() // Up button auto up_button = MUST(DOM::create_element(document(), HTML::TagNames::button, Namespace::HTML)); // FIXME: This cursor property doesn't work - MUST(up_button->set_attribute(HTML::AttributeNames::style, R"~~~( + up_button->set_attribute_value(HTML::AttributeNames::style, R"~~~( padding: 0; cursor: default; - )~~~"_string)); - MUST(up_button->set_inner_html(""_utf16)); + )~~~"_string); + + auto up_button_svg = MUST(DOM::create_element(document(), SVG::TagNames::svg, Namespace::SVG)); + up_button_svg->set_attribute_value(HTML::AttributeNames::style, "width: 1em; height: 1em;"_string); + up_button_svg->set_attribute_value(SVG::AttributeNames::xmlns, Namespace::SVG.to_string()); + up_button_svg->set_attribute_value(SVG::AttributeNames::viewBox, "0 0 24 24"_string); + MUST(up_button->append_child(up_button_svg)); + + auto up_button_svg_path = MUST(DOM::create_element(document(), SVG::TagNames::path, Namespace::SVG)); + up_button_svg_path->set_attribute_value(SVG::AttributeNames::fill, "currentColor"_string); + up_button_svg_path->set_attribute_value(SVG::AttributeNames::d, "M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z"_string); + MUST(up_button_svg->append_child(up_button_svg_path)); + MUST(element->append_child(up_button)); auto mouseup_callback_function = JS::NativeFunction::create( @@ -1131,11 +1141,22 @@ void HTMLInputElement::create_text_input_shadow_tree() // Down button auto down_button = MUST(DOM::create_element(document(), HTML::TagNames::button, Namespace::HTML)); - MUST(down_button->set_attribute(HTML::AttributeNames::style, R"~~~( + down_button->set_attribute_value(HTML::AttributeNames::style, R"~~~( padding: 0; cursor: default; - )~~~"_string)); - MUST(down_button->set_inner_html(""_utf16)); + )~~~"_string); + + auto down_button_svg = MUST(DOM::create_element(document(), SVG::TagNames::svg, Namespace::SVG)); + down_button_svg->set_attribute_value(HTML::AttributeNames::style, "width: 1em; height: 1em;"_string); + down_button_svg->set_attribute_value(SVG::AttributeNames::xmlns, Namespace::SVG.to_string()); + down_button_svg->set_attribute_value(SVG::AttributeNames::viewBox, "0 0 24 24"_string); + MUST(down_button->append_child(down_button_svg)); + + auto down_button_svg_path = MUST(DOM::create_element(document(), SVG::TagNames::path, Namespace::SVG)); + down_button_svg_path->set_attribute_value(SVG::AttributeNames::fill, "currentColor"_string); + down_button_svg_path->set_attribute_value(SVG::AttributeNames::d, "M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z"_string); + MUST(down_button_svg->append_child(down_button_svg_path)); + MUST(element->append_child(down_button)); auto down_callback_function = JS::NativeFunction::create( @@ -1160,21 +1181,21 @@ void HTMLInputElement::create_color_input_shadow_tree() auto color = value_sanitization_algorithm(m_value); auto border = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors(); - MUST(border->set_attribute(HTML::AttributeNames::style, R"~~~( + border->set_attribute_value(HTML::AttributeNames::style, R"~~~( width: fit-content; height: fit-content; padding: 4px; border: 1px solid ButtonBorder; background-color: ButtonFace; -)~~~"_string)); +)~~~"_string); m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors(); - MUST(m_color_well_element->set_attribute(HTML::AttributeNames::style, R"~~~( + m_color_well_element->set_attribute_value(HTML::AttributeNames::style, R"~~~( width: 32px; height: 16px; border: 1px solid ButtonBorder; box-sizing: border-box; -)~~~"_string)); +)~~~"_string); MUST(m_color_well_element->style_for_bindings()->set_property(CSS::PropertyID::BackgroundColor, color.to_utf8_but_should_be_ported_to_utf16())); MUST(border->append_child(*m_color_well_element)); @@ -1200,7 +1221,7 @@ void HTMLInputElement::create_file_input_shadow_tree() m_file_button->set_use_pseudo_element(CSS::PseudoElement::FileSelectorButton); m_file_label = DOM::create_element(document(), HTML::TagNames::label, Namespace::HTML).release_value_but_fixme_should_propagate_errors(); - MUST(m_file_label->set_attribute(HTML::AttributeNames::style, "padding-left: 4px;"_string)); + m_file_label->set_attribute_value(HTML::AttributeNames::style, "padding-left: 4px;"_string); auto on_button_click = [this](JS::VM&) { show_the_picker_if_applicable(*this); @@ -1225,15 +1246,15 @@ void HTMLInputElement::update_file_input_shadow_tree() return; auto files_label = has_attribute(HTML::AttributeNames::multiple) ? "files"sv : "file"sv; - MUST(m_file_button->set_text_content(Utf16String::formatted("Select {}...", files_label))); + m_file_button->string_replace_all(Utf16String::formatted("Select {}...", files_label)); if (m_selected_files && m_selected_files->length() > 0) { if (m_selected_files->length() == 1) - MUST(m_file_label->set_text_content(Utf16String::from_utf8(m_selected_files->item(0)->name()))); + m_file_label->string_replace_all(Utf16String::from_utf8(m_selected_files->item(0)->name())); else - MUST(m_file_label->set_text_content(Utf16String::formatted("{} files selected.", m_selected_files->length()))); + m_file_label->string_replace_all(Utf16String::formatted("{} files selected.", m_selected_files->length())); } else { - MUST(m_file_label->set_text_content(Utf16String::formatted("No {} selected.", files_label))); + m_file_label->string_replace_all(Utf16String::formatted("No {} selected.", files_label)); } } @@ -1465,7 +1486,7 @@ void HTMLInputElement::type_attribute_changed(TypeAttributeState old_state, Type // value is not the empty string, and the new state of the element's type attribute puts the value IDL attribute in either // the default mode or the default/on mode, then set the element's value content attribute to the element's value. if (old_value_attribute_mode == ValueAttributeMode::Value && !m_value.is_empty() && (first_is_one_of(new_value_attribute_mode, ValueAttributeMode::Default, ValueAttributeMode::DefaultOn))) { - MUST(set_attribute(HTML::AttributeNames::value, m_value)); + set_attribute_value(HTML::AttributeNames::value, m_value.to_utf8_but_should_be_ported_to_utf16()); } // 2. Otherwise, if the previous state of the element's type attribute put the value IDL attribute in any mode other @@ -1619,9 +1640,9 @@ StringView HTMLInputElement::type() const VERIFY_NOT_REACHED(); } -WebIDL::ExceptionOr HTMLInputElement::set_type(String const& type) +void HTMLInputElement::set_type(String const& type) { - return set_attribute(HTML::AttributeNames::type, type); + set_attribute_value(HTML::AttributeNames::type, type); } bool HTMLInputElement::can_have_text_editing_cursor() const @@ -2172,7 +2193,8 @@ WebIDL::Long HTMLInputElement::max_length() const WebIDL::ExceptionOr HTMLInputElement::set_max_length(WebIDL::Long value) { // The maxLength IDL attribute must reflect the maxlength content attribute, limited to only non-negative numbers. - return set_attribute(HTML::AttributeNames::maxlength, TRY(convert_non_negative_integer_to_string(realm(), value))); + set_attribute_value(HTML::AttributeNames::maxlength, TRY(convert_non_negative_integer_to_string(realm(), value))); + return {}; } // https://html.spec.whatwg.org/multipage/input.html#dom-input-minlength @@ -2189,7 +2211,8 @@ WebIDL::Long HTMLInputElement::min_length() const WebIDL::ExceptionOr HTMLInputElement::set_min_length(WebIDL::Long value) { // The minLength IDL attribute must reflect the minlength content attribute, limited to only non-negative numbers. - return set_attribute(HTML::AttributeNames::minlength, TRY(convert_non_negative_integer_to_string(realm(), value))); + set_attribute_value(HTML::AttributeNames::minlength, TRY(convert_non_negative_integer_to_string(realm(), value))); + return {}; } // https://html.spec.whatwg.org/multipage/input.html#the-size-attribute @@ -2210,7 +2233,8 @@ WebIDL::ExceptionOr HTMLInputElement::set_size(WebIDL::UnsignedLong value) return WebIDL::IndexSizeError::create(realm(), "Size must be greater than zero"_utf16); if (value > 2147483647) value = 20; - return set_attribute(HTML::AttributeNames::size, String::number(value)); + set_attribute_value(HTML::AttributeNames::size, String::number(value)); + return {}; } // https://html.spec.whatwg.org/multipage/input.html#dom-input-height @@ -2240,12 +2264,12 @@ WebIDL::UnsignedLong HTMLInputElement::height() const return 0; } -WebIDL::ExceptionOr HTMLInputElement::set_height(WebIDL::UnsignedLong value) +void HTMLInputElement::set_height(WebIDL::UnsignedLong value) { if (value > 2147483647) value = 0; - return set_attribute(HTML::AttributeNames::height, String::number(value)); + set_attribute_value(HTML::AttributeNames::height, String::number(value)); } // https://html.spec.whatwg.org/multipage/input.html#dom-input-width @@ -2275,12 +2299,12 @@ WebIDL::UnsignedLong HTMLInputElement::width() const return 0; } -WebIDL::ExceptionOr HTMLInputElement::set_width(WebIDL::UnsignedLong value) +void HTMLInputElement::set_width(WebIDL::UnsignedLong value) { if (value > 2147483647) value = 0; - return set_attribute(HTML::AttributeNames::width, String::number(value)); + set_attribute_value(HTML::AttributeNames::width, String::number(value)); } // https://html.spec.whatwg.org/multipage/input.html#month-state-(type=month):concept-input-value-string-number diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index 184a1be1a25..999901ff1cf 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -76,7 +76,7 @@ public: StringView type() const; TypeAttributeState type_state() const { return m_type; } - WebIDL::ExceptionOr set_type(String const&); + void set_type(String const&); String default_value() const { return get_attribute_value(HTML::AttributeNames::value); } @@ -139,10 +139,10 @@ public: WebIDL::ExceptionOr set_size(WebIDL::UnsignedLong value); WebIDL::UnsignedLong height() const; - WebIDL::ExceptionOr set_height(WebIDL::UnsignedLong value); + void set_height(WebIDL::UnsignedLong value); WebIDL::UnsignedLong width() const; - WebIDL::ExceptionOr set_width(WebIDL::UnsignedLong value); + void set_width(WebIDL::UnsignedLong value); struct SelectedCoordinate { int x { 0 }; diff --git a/Libraries/LibWeb/HTML/HTMLLIElement.cpp b/Libraries/LibWeb/HTML/HTMLLIElement.cpp index dde08a0a7b8..a0b64c70b1a 100644 --- a/Libraries/LibWeb/HTML/HTMLLIElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLIElement.cpp @@ -52,6 +52,11 @@ WebIDL::Long HTMLLIElement::value() return 0; } +void HTMLLIElement::set_value(WebIDL::Long value) +{ + set_attribute_value(AttributeNames::value, String::number(value)); +} + bool HTMLLIElement::is_presentational_hint(FlyString const& name) const { if (Base::is_presentational_hint(name)) diff --git a/Libraries/LibWeb/HTML/HTMLLIElement.h b/Libraries/LibWeb/HTML/HTMLLIElement.h index f6bdf6a53df..b09fed8746f 100644 --- a/Libraries/LibWeb/HTML/HTMLLIElement.h +++ b/Libraries/LibWeb/HTML/HTMLLIElement.h @@ -36,10 +36,7 @@ public: } WebIDL::Long value(); - void set_value(WebIDL::Long value) - { - MUST(set_attribute(AttributeNames::value, String::number(value))); - } + void set_value(WebIDL::Long value); virtual bool is_html_li_element() const override { return true; } diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 184a2812508..77e378f502f 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -111,8 +111,7 @@ GC::Ref HTMLLinkElement::sizes() void HTMLLinkElement::set_media(String media) { - (void)set_attribute(HTML::AttributeNames::media, media); - + set_attribute_value(HTML::AttributeNames::media, media); if (auto sheet = m_loaded_style_sheet) sheet->set_media(move(media)); } diff --git a/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp b/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp index d87fc43fe96..1f08c0878fa 100644 --- a/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp @@ -87,11 +87,11 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_amount() } // https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrollamount -WebIDL::ExceptionOr HTMLMarqueeElement::set_scroll_amount(WebIDL::UnsignedLong value) +void HTMLMarqueeElement::set_scroll_amount(WebIDL::UnsignedLong value) { if (value > 2147483647) value = 6; - return set_attribute(HTML::AttributeNames::scrollamount, String::number(value)); + set_attribute_value(HTML::AttributeNames::scrollamount, String::number(value)); } // https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrolldelay @@ -106,11 +106,11 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_delay() } // https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrolldelay -WebIDL::ExceptionOr HTMLMarqueeElement::set_scroll_delay(WebIDL::UnsignedLong value) +void HTMLMarqueeElement::set_scroll_delay(WebIDL::UnsignedLong value) { if (value > 2147483647) value = 85; - return set_attribute(HTML::AttributeNames::scrolldelay, String::number(value)); + set_attribute_value(HTML::AttributeNames::scrolldelay, String::number(value)); } } diff --git a/Libraries/LibWeb/HTML/HTMLMarqueeElement.h b/Libraries/LibWeb/HTML/HTMLMarqueeElement.h index 95a0f5635ee..429a97c3026 100644 --- a/Libraries/LibWeb/HTML/HTMLMarqueeElement.h +++ b/Libraries/LibWeb/HTML/HTMLMarqueeElement.h @@ -21,10 +21,10 @@ public: virtual ~HTMLMarqueeElement() override; WebIDL::UnsignedLong scroll_amount(); - WebIDL::ExceptionOr set_scroll_amount(WebIDL::UnsignedLong); + void set_scroll_amount(WebIDL::UnsignedLong); WebIDL::UnsignedLong scroll_delay(); - WebIDL::ExceptionOr set_scroll_delay(WebIDL::UnsignedLong); + void set_scroll_delay(WebIDL::UnsignedLong); private: HTMLMarqueeElement(DOM::Document&, DOM::QualifiedName); diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index 7733329584e..b8bb784cd2c 100644 --- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -68,7 +68,7 @@ void HTMLMediaElement::initialize(JS::Realm& realm) m_document_observer->set_document_became_inactive([this]() { // If the media element's node document stops being a fully active document, then the playback will stop until // the document is active again. - pause_element().release_value_but_fixme_should_propagate_errors(); + pause_element(); }); document().page().register_media_element({}, unique_id()); @@ -136,7 +136,7 @@ void HTMLMediaElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root) return; // 3. ⌛ Run the internal pause steps for the media element. - pause_element().release_value_but_fixme_should_propagate_errors(); + pause_element(); } // https://html.spec.whatwg.org/multipage/media.html#fatal-decode-error @@ -369,7 +369,7 @@ void HTMLMediaElement::set_duration(double duration) paintable->set_needs_display(); } -WebIDL::ExceptionOr> HTMLMediaElement::play() +GC::Ref HTMLMediaElement::play() { auto& realm = this->realm(); @@ -387,37 +387,33 @@ WebIDL::ExceptionOr> HTMLMediaElement::play() m_pending_play_promises.append(promise); // 4. Run the internal play steps for the media element. - TRY(play_element()); + play_element(); // 5. Return promise. return promise; } // https://html.spec.whatwg.org/multipage/media.html#dom-media-pause -WebIDL::ExceptionOr HTMLMediaElement::pause() +void HTMLMediaElement::pause() { // 1. If the media element's networkState attribute has the value NETWORK_EMPTY, invoke the media element's resource // selection algorithm. if (m_network_state == NetworkState::Empty) - TRY(select_resource()); + select_resource(); // 2. Run the internal pause steps for the media element. - TRY(pause_element()); - - return {}; + pause_element(); } -WebIDL::ExceptionOr HTMLMediaElement::toggle_playback() +void HTMLMediaElement::toggle_playback() { // AD-HOC: An execution context is required for Promise creation hooks. TemporaryExecutionContext execution_context { realm() }; if (potentially_playing()) - TRY(pause()); + pause(); else - TRY(play()); - - return {}; + play(); } // https://html.spec.whatwg.org/multipage/media.html#dom-media-volume @@ -628,7 +624,7 @@ WebIDL::ExceptionOr HTMLMediaElement::load_element() m_can_autoplay = true; // 9. Invoke the media element's resource selection algorithm. - TRY(select_resource()); + select_resource(); // 10. NOTE: Playback of any previously playing media resource for this element stops. return {}; @@ -825,7 +821,7 @@ void HTMLMediaElement::children_changed(ChildrenChangedMetadata const* metadata) } // https://html.spec.whatwg.org/multipage/media.html#concept-media-load-algorithm -WebIDL::ExceptionOr HTMLMediaElement::select_resource() +void HTMLMediaElement::select_resource() { auto& realm = this->realm(); @@ -972,8 +968,6 @@ WebIDL::ExceptionOr HTMLMediaElement::select_resource() break; } }); - - return {}; } enum class FetchMode { @@ -1592,12 +1586,12 @@ void HTMLMediaElement::on_playback_manager_state_change() } // https://html.spec.whatwg.org/multipage/media.html#internal-play-steps -WebIDL::ExceptionOr HTMLMediaElement::play_element() +void HTMLMediaElement::play_element() { // 1. If the media element's networkState attribute has the value NETWORK_EMPTY, invoke the media element's resource // selection algorithm. if (m_network_state == NetworkState::Empty) - TRY(select_resource()); + select_resource(); // 2. If the playback has ended and the direction of playback is forwards, seek to the earliest possible position // of the media resource. @@ -1654,12 +1648,10 @@ WebIDL::ExceptionOr HTMLMediaElement::play_element() // 5. Set the media element's can autoplay flag to false. m_can_autoplay = false; - - return {}; } // https://html.spec.whatwg.org/multipage/media.html#internal-pause-steps -WebIDL::ExceptionOr HTMLMediaElement::pause_element() +void HTMLMediaElement::pause_element() { // 1. Set the media element's can autoplay flag to false. m_can_autoplay = false; @@ -1689,8 +1681,6 @@ WebIDL::ExceptionOr HTMLMediaElement::pause_element() // 4. Set the official playback position to the current playback position. m_official_playback_position = m_current_playback_position; } - - return {}; } // https://html.spec.whatwg.org/multipage/media.html#dom-media-seek @@ -2217,14 +2207,14 @@ void HTMLMediaElement::reject_pending_play_promises(ReadonlySpan HTMLMediaElement::handle_keydown(Badge, UIEvents::KeyCode key, u32 modifiers) +bool HTMLMediaElement::handle_keydown(Badge, UIEvents::KeyCode key, u32 modifiers) { if (modifiers != UIEvents::KeyModifier::Mod_None) return false; switch (key) { case UIEvents::KeyCode::Key_Space: - TRY(toggle_playback()); + toggle_playback(); break; case UIEvents::KeyCode::Key_Home: @@ -2258,7 +2248,8 @@ WebIDL::ExceptionOr HTMLMediaElement::handle_keydown(Badge select_resource(); + void select_resource(); enum class NetworkState : u16 { Empty, @@ -106,9 +106,9 @@ public: bool paused() const { return m_paused; } bool ended() const; bool potentially_playing() const; - WebIDL::ExceptionOr> play(); - WebIDL::ExceptionOr pause(); - WebIDL::ExceptionOr toggle_playback(); + GC::Ref play(); + void pause(); + void toggle_playback(); double volume() const { return m_volume; } WebIDL::ExceptionOr set_volume(double); @@ -138,7 +138,7 @@ public: GC::Ref add_text_track(Bindings::TextTrackKind kind, String const& label, String const& language); - WebIDL::ExceptionOr handle_keydown(Badge, UIEvents::KeyCode, u32 modifiers); + bool handle_keydown(Badge, UIEvents::KeyCode, u32 modifiers); enum class MediaComponent { PlaybackButton, @@ -203,8 +203,8 @@ private: void set_ready_state(ReadyState); void on_playback_manager_state_change(); - WebIDL::ExceptionOr play_element(); - WebIDL::ExceptionOr pause_element(); + void play_element(); + void pause_element(); void seek_element(double playback_position, MediaSeekMode = MediaSeekMode::Accurate); void finish_seeking_element(); void notify_about_playing(); diff --git a/Libraries/LibWeb/HTML/HTMLMeterElement.cpp b/Libraries/LibWeb/HTML/HTMLMeterElement.cpp index ab5c088fc05..895d3c85d42 100644 --- a/Libraries/LibWeb/HTML/HTMLMeterElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLMeterElement.cpp @@ -54,11 +54,10 @@ double HTMLMeterElement::value() const return clamp(candidate_value, min(), max()); } -WebIDL::ExceptionOr HTMLMeterElement::set_value(double value) +void HTMLMeterElement::set_value(double value) { - TRY(set_attribute(HTML::AttributeNames::value, String::number(value))); + set_attribute_value(HTML::AttributeNames::value, String::number(value)); update_meter_value_element(); - return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-meter-minimum @@ -72,11 +71,10 @@ double HTMLMeterElement::min() const return 0; } -WebIDL::ExceptionOr HTMLMeterElement::set_min(double value) +void HTMLMeterElement::set_min(double value) { - TRY(set_attribute(HTML::AttributeNames::min, String::number(value))); + set_attribute_value(HTML::AttributeNames::min, String::number(value)); update_meter_value_element(); - return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-meter-maximum @@ -93,11 +91,10 @@ double HTMLMeterElement::max() const return AK::max(candidate_max, min()); } -WebIDL::ExceptionOr HTMLMeterElement::set_max(double value) +void HTMLMeterElement::set_max(double value) { - TRY(set_attribute(HTML::AttributeNames::max, String::number(value))); + set_attribute_value(HTML::AttributeNames::max, String::number(value)); update_meter_value_element(); - return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-meter-low @@ -116,11 +113,10 @@ double HTMLMeterElement::low() const return clamp(candidate_low, min(), max()); } -WebIDL::ExceptionOr HTMLMeterElement::set_low(double value) +void HTMLMeterElement::set_low(double value) { - TRY(set_attribute(HTML::AttributeNames::low, String::number(value))); + set_attribute_value(HTML::AttributeNames::low, String::number(value)); update_meter_value_element(); - return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-meter-high @@ -139,11 +135,10 @@ double HTMLMeterElement::high() const return clamp(candidate_high, low(), max()); } -WebIDL::ExceptionOr HTMLMeterElement::set_high(double value) +void HTMLMeterElement::set_high(double value) { - TRY(set_attribute(HTML::AttributeNames::high, String::number(value))); + set_attribute_value(HTML::AttributeNames::high, String::number(value)); update_meter_value_element(); - return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-meter-optimum @@ -162,11 +157,10 @@ double HTMLMeterElement::optimum() const return clamp(candidate_optimum, min(), max()); } -WebIDL::ExceptionOr HTMLMeterElement::set_optimum(double value) +void HTMLMeterElement::set_optimum(double value) { - TRY(set_attribute(HTML::AttributeNames::optimum, String::number(value))); + set_attribute_value(HTML::AttributeNames::optimum, String::number(value)); update_meter_value_element(); - return {}; } void HTMLMeterElement::inserted() diff --git a/Libraries/LibWeb/HTML/HTMLMeterElement.h b/Libraries/LibWeb/HTML/HTMLMeterElement.h index 3f58caf67d2..ba1dbdbb211 100644 --- a/Libraries/LibWeb/HTML/HTMLMeterElement.h +++ b/Libraries/LibWeb/HTML/HTMLMeterElement.h @@ -21,17 +21,17 @@ public: virtual ~HTMLMeterElement() override; double value() const; - WebIDL::ExceptionOr set_value(double); + void set_value(double); double min() const; - WebIDL::ExceptionOr set_min(double value); + void set_min(double value); double max() const; - WebIDL::ExceptionOr set_max(double value); + void set_max(double value); double low() const; - WebIDL::ExceptionOr set_low(double value); + void set_low(double value); double high() const; - WebIDL::ExceptionOr set_high(double value); + void set_high(double value); double optimum() const; - WebIDL::ExceptionOr set_optimum(double value); + void set_optimum(double value); // ^HTMLElement virtual void inserted() override; diff --git a/Libraries/LibWeb/HTML/HTMLOListElement.cpp b/Libraries/LibWeb/HTML/HTMLOListElement.cpp index 03e8e2599ae..55f3da5d914 100644 --- a/Libraries/LibWeb/HTML/HTMLOListElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLOListElement.cpp @@ -52,6 +52,11 @@ WebIDL::Long HTMLOListElement::start() return 1; } +void HTMLOListElement::set_start(WebIDL::Long start) +{ + set_attribute_value(AttributeNames::start, String::number(start)); +} + // https://html.spec.whatwg.org/multipage/grouping-content.html#concept-ol-start AK::Checked HTMLOListElement::starting_value() const { diff --git a/Libraries/LibWeb/HTML/HTMLOListElement.h b/Libraries/LibWeb/HTML/HTMLOListElement.h index b7a002e8504..14488a6ced3 100644 --- a/Libraries/LibWeb/HTML/HTMLOListElement.h +++ b/Libraries/LibWeb/HTML/HTMLOListElement.h @@ -24,10 +24,7 @@ public: virtual Optional default_role() const override { return ARIA::Role::list; } WebIDL::Long start(); - void set_start(WebIDL::Long start) - { - MUST(set_attribute(AttributeNames::start, String::number(start))); - } + void set_start(WebIDL::Long start); AK::Checked starting_value() const; diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 04cf6087144..e0bf49e0d44 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -180,6 +180,11 @@ String HTMLObjectElement::data() const return maybe_url->to_string(); } +void HTMLObjectElement::set_data(String const& data) +{ + set_attribute_value(HTML::AttributeNames::data, data); +} + GC::Ptr HTMLObjectElement::create_layout_node(GC::Ref style) { switch (m_representation) { diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.h index 9285405bc25..6a238b3cae4 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -37,7 +37,7 @@ public: virtual void form_associated_element_was_removed(DOM::Node*) override; String data() const; - void set_data(String const& data) { MUST(set_attribute(HTML::AttributeNames::data, data)); } + void set_data(String const& data); String type() const { return get_attribute_value(HTML::AttributeNames::type); } diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index ccf061991fe..2ac85890252 100644 --- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -99,9 +99,9 @@ Utf16String HTMLOptionElement::value() const } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-value -WebIDL::ExceptionOr HTMLOptionElement::set_value(Utf16String const& value) +void HTMLOptionElement::set_value(Utf16String const& value) { - return set_attribute(HTML::AttributeNames::value, value); + set_attribute_value(HTML::AttributeNames::value, value.to_utf8_but_should_be_ported_to_utf16()); } static void concatenate_descendants_text_content(DOM::Node const* node, StringBuilder& builder) @@ -129,7 +129,7 @@ String HTMLOptionElement::label() const // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-label void HTMLOptionElement::set_label(String const& label) { - MUST(set_attribute(HTML::AttributeNames::label, label)); + set_attribute_value(HTML::AttributeNames::label, label); // Note: this causes attribute_changed() to be called, which will update the