1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-01 23:42:06 +00:00

LibWeb: Rename Element::attribute to Element::deprecated_attribute

This should allow us to add a Element::attribute which returns an
Optional<String>. Eventually all callers should be ported to switch from
the DeprecatedString version, but in the meantime, this should allow us
to port some more IDL interfaces away from DeprecatedString.
This commit is contained in:
Shannon Booth 2023-09-03 14:58:18 +12:00 committed by Tim Flynn
parent da637a527d
commit 0f6782fae6
42 changed files with 141 additions and 141 deletions

View file

@ -249,7 +249,7 @@ bool HTMLImageElement::complete() const
return true;
// - The srcset attribute is omitted and the src attribute's value is the empty string.
if (!has_attribute(HTML::AttributeNames::srcset) && attribute(HTML::AttributeNames::src) == ""sv)
if (!has_attribute(HTML::AttributeNames::srcset) && deprecated_attribute(HTML::AttributeNames::src) == ""sv)
return true;
// - The img element's current request's state is completely available and its pending request is null.
@ -342,8 +342,8 @@ ErrorOr<void> HTMLImageElement::update_the_image_data(bool restart_animations, b
// and it has a src attribute specified whose value is not the empty string,
// then set selected source to the value of the element's src attribute
// and set selected pixel density to 1.0.
if (!uses_srcset_or_picture() && has_attribute(HTML::AttributeNames::src) && !attribute(HTML::AttributeNames::src).is_empty()) {
selected_source = TRY(String::from_deprecated_string(attribute(HTML::AttributeNames::src)));
if (!uses_srcset_or_picture() && has_attribute(HTML::AttributeNames::src) && !deprecated_attribute(HTML::AttributeNames::src).is_empty()) {
selected_source = TRY(String::from_deprecated_string(deprecated_attribute(HTML::AttributeNames::src)));
selected_pixel_density = 1.0f;
}
@ -542,7 +542,7 @@ after_step_7:
request->set_initiator(Fetch::Infrastructure::Request::Initiator::ImageSet);
// 21. Set request's referrer policy to the current state of the element's referrerpolicy attribute.
request->set_referrer_policy(ReferrerPolicy::from_string(attribute(HTML::AttributeNames::referrerpolicy)));
request->set_referrer_policy(ReferrerPolicy::from_string(deprecated_attribute(HTML::AttributeNames::referrerpolicy)));
// FIXME: 22. Set request's priority to the current state of the element's fetchpriority attribute.
@ -757,7 +757,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
request->set_initiator(Fetch::Infrastructure::Request::Initiator::ImageSet);
// 3. Set request's referrer policy to the current state of the element's referrerpolicy attribute.
request->set_referrer_policy(ReferrerPolicy::from_string(attribute(HTML::AttributeNames::referrerpolicy)));
request->set_referrer_policy(ReferrerPolicy::from_string(deprecated_attribute(HTML::AttributeNames::referrerpolicy)));
// FIXME: 4. Set request's priority to the current state of the element's fetchpriority attribute.
@ -864,37 +864,37 @@ static void update_the_source_set(DOM::Element& element)
// 4. If el is an img element that has a srcset attribute, then set srcset to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto srcset_value = element.attribute(HTML::AttributeNames::srcset); !srcset_value.is_null())
if (auto srcset_value = element.deprecated_attribute(HTML::AttributeNames::srcset); !srcset_value.is_null())
srcset = String::from_deprecated_string(srcset_value).release_value_but_fixme_should_propagate_errors();
}
// 5. Otherwise, if el is a link element that has an imagesrcset attribute, then set srcset to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto imagesrcset_value = element.attribute(HTML::AttributeNames::imagesrcset); !imagesrcset_value.is_null())
if (auto imagesrcset_value = element.deprecated_attribute(HTML::AttributeNames::imagesrcset); !imagesrcset_value.is_null())
srcset = String::from_deprecated_string(imagesrcset_value).release_value_but_fixme_should_propagate_errors();
}
// 6. If el is an img element that has a sizes attribute, then set sizes to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto sizes_value = element.attribute(HTML::AttributeNames::sizes); !sizes_value.is_null())
if (auto sizes_value = element.deprecated_attribute(HTML::AttributeNames::sizes); !sizes_value.is_null())
sizes = String::from_deprecated_string(sizes_value).release_value_but_fixme_should_propagate_errors();
}
// 7. Otherwise, if el is a link element that has an imagesizes attribute, then set sizes to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto imagesizes_value = element.attribute(HTML::AttributeNames::imagesizes); !imagesizes_value.is_null())
if (auto imagesizes_value = element.deprecated_attribute(HTML::AttributeNames::imagesizes); !imagesizes_value.is_null())
sizes = String::from_deprecated_string(imagesizes_value).release_value_but_fixme_should_propagate_errors();
}
// 8. If el is an img element that has a src attribute, then set default source to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto src_value = element.attribute(HTML::AttributeNames::src); !src_value.is_null())
if (auto src_value = element.deprecated_attribute(HTML::AttributeNames::src); !src_value.is_null())
default_source = String::from_deprecated_string(src_value).release_value_but_fixme_should_propagate_errors();
}
// 9. Otherwise, if el is a link element that has an href attribute, then set default source to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto href_value = element.attribute(HTML::AttributeNames::href); !href_value.is_null())
if (auto href_value = element.deprecated_attribute(HTML::AttributeNames::href); !href_value.is_null())
default_source = String::from_deprecated_string(href_value).release_value_but_fixme_should_propagate_errors();
}
@ -914,7 +914,7 @@ static void update_the_source_set(DOM::Element& element)
continue;
// 4. Parse child's srcset attribute and let the returned source set be source set.
auto source_set = parse_a_srcset_attribute(child->attribute(HTML::AttributeNames::srcset));
auto source_set = parse_a_srcset_attribute(child->deprecated_attribute(HTML::AttributeNames::srcset));
// 5. If source set has zero image sources, continue to the next child.
if (source_set.is_empty())
@ -923,14 +923,14 @@ static void update_the_source_set(DOM::Element& element)
// 6. If child has a media attribute, and its value does not match the environment, continue to the next child.
if (child->has_attribute(HTML::AttributeNames::media)) {
auto media_query = parse_media_query(CSS::Parser::ParsingContext { element.document() },
child->attribute(HTML::AttributeNames::media));
child->deprecated_attribute(HTML::AttributeNames::media));
if (!media_query || !media_query->evaluate(element.document().window())) {
continue;
}
}
// 7. Parse child's sizes attribute, and let source set's source size be the returned value.
source_set.m_source_size = parse_a_sizes_attribute(element.document(), child->attribute(HTML::AttributeNames::sizes));
source_set.m_source_size = parse_a_sizes_attribute(element.document(), child->deprecated_attribute(HTML::AttributeNames::sizes));
// FIXME: 8. If child has a type attribute, and its value is an unknown or unsupported MIME type, continue to the next child.
if (child->has_attribute(HTML::AttributeNames::type)) {
@ -1000,7 +1000,7 @@ void HTMLImageElement::animate()
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attributes
HTMLImageElement::LazyLoading HTMLImageElement::lazy_loading() const
{
auto value = attribute(HTML::AttributeNames::loading);
auto value = deprecated_attribute(HTML::AttributeNames::loading);
if (value.equals_ignoring_ascii_case("lazy"sv))
return LazyLoading::Lazy;
return LazyLoading::Eager;