LibWeb: Make Element::has_attribute take a StringView
It calls Element::get_attribute which takes a StringView. Ultimately, this should be taking a FlyString, but to help in porting away from DeprecatedString, just leave a FIXME for that for now.
This commit is contained in:
parent
52fccae654
commit
79f97da4b4
Notes:
sideshowbarker
2024-07-16 20:05:14 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/79f97da4b4 Pull-request: https://github.com/SerenityOS/serenity/pull/21174 Reviewed-by: https://github.com/awesomekling
5 changed files with 8 additions and 5 deletions
|
@ -302,7 +302,7 @@ void Element::remove_attribute(StringView name)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-hasattribute
|
||||
bool Element::has_attribute(DeprecatedFlyString const& name) const
|
||||
bool Element::has_attribute(StringView name) const
|
||||
{
|
||||
return m_attributes->get_attribute(name) != nullptr;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,8 @@ public:
|
|||
// NOTE: This is for the JS bindings
|
||||
DeprecatedFlyString namespace_uri() const { return namespace_(); }
|
||||
|
||||
bool has_attribute(DeprecatedFlyString const& name) const;
|
||||
// FIXME: This should be taking a 'FlyString const&'
|
||||
bool has_attribute(StringView name) const;
|
||||
bool has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const;
|
||||
bool has_attributes() const;
|
||||
|
||||
|
@ -104,6 +105,7 @@ public:
|
|||
return String::from_deprecated_string(ret).release_value();
|
||||
}
|
||||
|
||||
// FIXME: This should be taking a 'FlyString const&' / 'Optional<FlyString> const&'
|
||||
DeprecatedString get_attribute(DeprecatedFlyString const& name) const;
|
||||
DeprecatedString get_attribute_value(DeprecatedFlyString const& local_name, DeprecatedFlyString const& namespace_ = {}) const;
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
WebIDL::ExceptionOr<Attr const*> remove_named_item_ns(Optional<String> const& namespace_, StringView local_name);
|
||||
|
||||
// Methods defined by the spec for internal use:
|
||||
// FIXME: These should be taking `FlyString const&' / 'Optional<FlyString> const&'
|
||||
Attr* get_attribute(StringView qualified_name, size_t* item_index = nullptr);
|
||||
Attr* get_attribute_ns(StringView namespace_, StringView local_name, size_t* item_index = nullptr);
|
||||
Attr const* get_attribute(StringView qualified_name, size_t* item_index = nullptr) const;
|
||||
|
|
|
@ -164,9 +164,9 @@ String const& HTMLSelectElement::type() const
|
|||
Optional<ARIA::Role> HTMLSelectElement::default_role() const
|
||||
{
|
||||
// https://www.w3.org/TR/html-aria/#el-select-multiple-or-size-greater-1
|
||||
if (has_attribute("multiple"))
|
||||
if (has_attribute(AttributeNames::multiple))
|
||||
return ARIA::Role::listbox;
|
||||
if (has_attribute("size")) {
|
||||
if (has_attribute(AttributeNames::size)) {
|
||||
auto size_attribute = deprecated_attribute("size").to_int();
|
||||
if (size_attribute.has_value() && size_attribute.value() > 1)
|
||||
return ARIA::Role::listbox;
|
||||
|
|
|
@ -94,7 +94,7 @@ JS::GCPtr<SVGGradientElement const> SVGGradientElement::linked_gradient() const
|
|||
// FIXME: This entire function is an ad-hoc hack!
|
||||
// It can only resolve #<ids> in the same document.
|
||||
|
||||
auto link = has_attribute("href") ? get_attribute("href") : get_attribute("xlink:href");
|
||||
auto link = has_attribute(AttributeNames::href) ? get_attribute(AttributeNames::href) : get_attribute("xlink:href"sv);
|
||||
if (auto href = link; !href.is_empty()) {
|
||||
auto url = document().parse_url(href);
|
||||
auto id = url.fragment();
|
||||
|
|
Loading…
Add table
Reference in a new issue