1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:15:07 +00:00

LibWeb: Port HTMLAnchorElement interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-03 16:15:27 +12:00 committed by Tim Flynn
parent 76af9d434c
commit e5910a4593
3 changed files with 21 additions and 16 deletions

View file

@ -105,32 +105,37 @@ Optional<ARIA::Role> HTMLAnchorElement::default_role() const
}
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-text
DeprecatedString HTMLAnchorElement::text() const
String HTMLAnchorElement::text() const
{
// The text attribute's getter must return this element's descendant text content.
return descendant_text_content();
return MUST(String::from_deprecated_string(descendant_text_content()));
}
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-text
void HTMLAnchorElement::set_text(DeprecatedString const& text)
void HTMLAnchorElement::set_text(String const& text)
{
// The text attribute's setter must string replace all with the given value within this element.
string_replace_all(text);
string_replace_all(text.to_deprecated_string());
}
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-referrerpolicy
DeprecatedString HTMLAnchorElement::referrer_policy() const
StringView HTMLAnchorElement::referrer_policy() const
{
// FIXME: This should probably be `Reflect` in the IDL.
// The IDL attribute referrerPolicy must reflect the referrerpolicy content attribute, limited to only known values.
auto policy_string = deprecated_attribute(HTML::AttributeNames::referrerpolicy);
auto maybe_policy = ReferrerPolicy::from_string(policy_string);
if (maybe_policy.has_value())
return ReferrerPolicy::to_string(maybe_policy.value());
return "";
auto maybe_policy_string = attribute(HTML::AttributeNames::referrerpolicy);
if (!maybe_policy_string.has_value())
return ""sv;
auto maybe_policy = ReferrerPolicy::from_string(maybe_policy_string.value());
if (!maybe_policy.has_value())
return ""sv;
return ReferrerPolicy::to_string(maybe_policy.value());
}
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-referrerpolicy
WebIDL::ExceptionOr<void> HTMLAnchorElement::set_referrer_policy(DeprecatedString const& referrer_policy)
WebIDL::ExceptionOr<void> HTMLAnchorElement::set_referrer_policy(String const& referrer_policy)
{
// The IDL attribute referrerPolicy must reflect the referrerpolicy content attribute, limited to only known values.
return set_attribute(HTML::AttributeNames::referrerpolicy, referrer_policy);