mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibWeb: Add a non-DeprecatedString version of Element::get_attribute
Renaming the DeprecatedString version of this function to Element::get_deprecated_attribute. While performing this rename, port over functions where it is trivial to do so to the Optional<String> version of this function.
This commit is contained in:
parent
ebe01b51c8
commit
50350fb79c
17 changed files with 52 additions and 56 deletions
|
@ -64,7 +64,7 @@ DOMTokenList::DOMTokenList(Element& associated_element, FlyString associated_att
|
|||
, m_associated_element(associated_element)
|
||||
, m_associated_attribute(move(associated_attribute))
|
||||
{
|
||||
auto value = associated_element.get_attribute(m_associated_attribute.to_deprecated_fly_string());
|
||||
auto value = associated_element.deprecated_get_attribute(m_associated_attribute);
|
||||
associated_attribute_changed(value);
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ void Element::visit_edges(Cell::Visitor& visitor)
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattribute
|
||||
DeprecatedString Element::get_attribute(StringView name) const
|
||||
Optional<String> Element::get_attribute(StringView name) const
|
||||
{
|
||||
// 1. Let attr be the result of getting an attribute given qualifiedName and this.
|
||||
auto const* attribute = m_attributes->get_attribute(name);
|
||||
|
@ -143,7 +143,16 @@ DeprecatedString Element::get_attribute(StringView name) const
|
|||
return {};
|
||||
|
||||
// 3. Return attr’s value.
|
||||
return attribute->value().to_deprecated_string();
|
||||
return attribute->value();
|
||||
}
|
||||
|
||||
DeprecatedString Element::deprecated_get_attribute(StringView name) const
|
||||
{
|
||||
auto maybe_attribute = get_attribute(name);
|
||||
if (!maybe_attribute.has_value())
|
||||
return {};
|
||||
|
||||
return maybe_attribute->to_deprecated_string();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-value
|
||||
|
|
|
@ -99,17 +99,12 @@ public:
|
|||
bool has_attributes() const;
|
||||
|
||||
// FIXME: This should be taking a 'FlyString const&'
|
||||
DeprecatedString deprecated_attribute(StringView name) const { return get_attribute(name); }
|
||||
Optional<String> attribute(StringView name) const
|
||||
{
|
||||
auto ret = deprecated_attribute(name);
|
||||
if (ret.is_null())
|
||||
return {};
|
||||
return String::from_deprecated_string(ret).release_value();
|
||||
}
|
||||
DeprecatedString deprecated_attribute(StringView name) const { return deprecated_get_attribute(name); }
|
||||
Optional<String> attribute(StringView name) const { return get_attribute(name); }
|
||||
|
||||
// FIXME: This should be taking a 'FlyString const&' / 'Optional<FlyString> const&'
|
||||
DeprecatedString get_attribute(StringView name) const;
|
||||
Optional<String> get_attribute(StringView name) const;
|
||||
DeprecatedString deprecated_get_attribute(StringView name) const;
|
||||
DeprecatedString get_attribute_value(StringView local_name, DeprecatedFlyString const& namespace_ = {}) const;
|
||||
|
||||
WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value);
|
||||
|
@ -257,7 +252,7 @@ public:
|
|||
#define ARIA_IMPL(name, attribute) \
|
||||
DeprecatedString name() const override \
|
||||
{ \
|
||||
return get_attribute(attribute); \
|
||||
return deprecated_get_attribute(attribute); \
|
||||
} \
|
||||
\
|
||||
WebIDL::ExceptionOr<void> set_##name(DeprecatedString const& value) override \
|
||||
|
|
|
@ -28,7 +28,7 @@ interface Element : Node {
|
|||
readonly attribute DOMString localName;
|
||||
readonly attribute DOMString tagName;
|
||||
|
||||
DOMString? getAttribute(DOMString qualifiedName);
|
||||
[ImplementedAs=deprecated_get_attribute] DOMString? getAttribute(DOMString qualifiedName);
|
||||
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
|
||||
[CEReactions] undefined setAttributeNS(DOMString? namespace , DOMString qualifiedName , DOMString value);
|
||||
[CEReactions] Attr? setAttributeNode(Attr attr);
|
||||
|
|
|
@ -1387,7 +1387,7 @@ bool Node::is_equal_node(Node const* other_node) const
|
|||
// If A is an element, each attribute in its attribute list has an attribute that equals an attribute in B’s attribute list.
|
||||
bool has_same_attributes = true;
|
||||
this_element.for_each_attribute([&](auto& name, auto& value) {
|
||||
if (other_element.get_attribute(name) != value)
|
||||
if (other_element.deprecated_get_attribute(name) != value)
|
||||
has_same_attributes = false;
|
||||
});
|
||||
if (!has_same_attributes)
|
||||
|
@ -1473,8 +1473,8 @@ DeprecatedString Node::debug_description() const
|
|||
builder.append(node_name().to_deprecated_fly_string().to_lowercase());
|
||||
if (is_element()) {
|
||||
auto& element = static_cast<DOM::Element const&>(*this);
|
||||
if (auto id = element.get_attribute(HTML::AttributeNames::id); !id.is_null())
|
||||
builder.appendff("#{}", id);
|
||||
if (auto id = element.get_attribute(HTML::AttributeNames::id); id.has_value())
|
||||
builder.appendff("#{}", id.value());
|
||||
for (auto const& class_name : element.class_names())
|
||||
builder.appendff(".{}", class_name);
|
||||
}
|
||||
|
|
|
@ -60,44 +60,38 @@ FlyString RadioNodeList::value() const
|
|||
return String {};
|
||||
|
||||
// 3. If element is an element with no value attribute, return the string "on".
|
||||
auto const value = element->get_attribute(HTML::AttributeNames::value);
|
||||
if (value.is_null())
|
||||
return "on"_fly_string;
|
||||
|
||||
// 4. Otherwise, return the value of element's value attribute.
|
||||
return MUST(FlyString::from_deprecated_fly_string(value));
|
||||
return element->get_attribute(HTML::AttributeNames::value).value_or("on"_string);
|
||||
}
|
||||
|
||||
void RadioNodeList::set_value(FlyString const& value)
|
||||
{
|
||||
HTML::HTMLInputElement* element = nullptr;
|
||||
|
||||
auto deprecated_value = value.to_deprecated_fly_string();
|
||||
|
||||
// 1. If the new value is the string "on": let element be the first element in tree order represented by the RadioNodeList object
|
||||
// that is an input element whose type attribute is in the Radio Button state and whose value content attribute is either absent,
|
||||
// or present and equal to the new value, if any. If no such element exists, then instead let element be null.
|
||||
if (value == "on"sv) {
|
||||
element = verify_cast<HTML::HTMLInputElement>(first_matching([&deprecated_value](auto const& node) {
|
||||
element = verify_cast<HTML::HTMLInputElement>(first_matching([&value](auto const& node) {
|
||||
auto const* button = radio_button(node);
|
||||
if (!button)
|
||||
return false;
|
||||
|
||||
auto const value = button->get_attribute(HTML::AttributeNames::value);
|
||||
return value.is_null() || value == deprecated_value;
|
||||
auto const maybe_value = button->get_attribute(HTML::AttributeNames::value);
|
||||
return !maybe_value.has_value() || maybe_value.value() == value;
|
||||
}));
|
||||
}
|
||||
// 2. Otherwise: let element be the first element in tree order represented by the RadioNodeList object that is an input element whose
|
||||
// type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. If
|
||||
// no such element exists, then instead let element be null.
|
||||
// type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. If
|
||||
// no such element exists, then instead let element be null.
|
||||
else {
|
||||
element = verify_cast<HTML::HTMLInputElement>(first_matching([&deprecated_value](auto const& node) {
|
||||
element = verify_cast<HTML::HTMLInputElement>(first_matching([&value](auto const& node) {
|
||||
auto const* button = radio_button(node);
|
||||
if (!button)
|
||||
return false;
|
||||
|
||||
auto const value = button->get_attribute(HTML::AttributeNames::value);
|
||||
return !value.is_null() && value == deprecated_value;
|
||||
auto const maybe_value = button->get_attribute(HTML::AttributeNames::value);
|
||||
return maybe_value.has_value() && maybe_value.value() == value;
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue