LibWeb: Implement HTMLBaseElement.href

This commit is contained in:
Luke Wilde 2022-06-19 15:45:09 +01:00 committed by Linus Groh
parent 1f820f8840
commit 0a989d1bfd
Notes: sideshowbarker 2024-07-17 10:04:33 +09:00
3 changed files with 34 additions and 0 deletions

View file

@ -63,4 +63,34 @@ void HTMLBaseElement::set_the_frozen_base_url()
m_frozen_base_url = move(url_record);
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-base-href
String HTMLBaseElement::href() const
{
// 1. Let document be element's node document.
auto& document = this->document();
// 2. Let url be the value of the href attribute of this element, if it has one, and the empty string otherwise.
auto url = String::empty();
if (has_attribute(AttributeNames::href))
url = attribute(AttributeNames::href);
// 3. Let urlRecord be the result of parsing url with document's fallback base URL, and document's character encoding. (Thus, the base element isn't affected by other base elements or itself.)
// FIXME: Pass in document's character encoding.
auto url_record = document.fallback_base_url().complete_url(url);
// 4. If urlRecord is failure, return url.
if (!url_record.is_valid())
return url;
// 5. Return the serialization of urlRecord.
return url_record.to_string();
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-base-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.
set_attribute(AttributeNames::href, href);
}
}

View file

@ -17,6 +17,9 @@ public:
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);
virtual ~HTMLBaseElement() override;
String href() const;
void set_href(String const& href);
AK::URL const& frozen_base_url() const { return m_frozen_base_url; }
virtual void inserted() override;

View file

@ -2,6 +2,7 @@
interface HTMLBaseElement : HTMLElement {
[CEReactions] attribute USVString href;
[Reflect] attribute DOMString target;
};