1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

LibWeb: Set an attribute's owning element when it is known

This commit is contained in:
Timothy Flynn 2021-10-15 12:03:08 -04:00 committed by Linus Groh
parent e01dfaac9a
commit 454d218716
3 changed files with 7 additions and 6 deletions

View file

@ -9,15 +9,16 @@
namespace Web::DOM { namespace Web::DOM {
NonnullRefPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value) NonnullRefPtr<Attribute> Attribute::create(Document& document, FlyString local_name, String value, Element const* owner_element)
{ {
return adopt_ref(*new Attribute(document, move(local_name), move(value))); return adopt_ref(*new Attribute(document, move(local_name), move(value), owner_element));
} }
Attribute::Attribute(Document& document, FlyString local_name, String value) Attribute::Attribute(Document& document, FlyString local_name, String value, Element const* owner_element)
: Node(document, NodeType::ATTRIBUTE_NODE) : Node(document, NodeType::ATTRIBUTE_NODE)
, m_qualified_name(move(local_name), {}, {}) , m_qualified_name(move(local_name), {}, {})
, m_value(move(value)) , m_value(move(value))
, m_owner_element(owner_element)
{ {
} }

View file

@ -17,7 +17,7 @@ class Attribute final : public Node {
public: public:
using WrapperType = Bindings::AttributeWrapper; using WrapperType = Bindings::AttributeWrapper;
static NonnullRefPtr<Attribute> create(Document&, FlyString local_name, String value); static NonnullRefPtr<Attribute> create(Document&, FlyString local_name, String value, Element const* = nullptr);
virtual ~Attribute() override = default; virtual ~Attribute() override = default;
@ -38,7 +38,7 @@ public:
constexpr bool specified() const { return true; } constexpr bool specified() const { return true; }
private: private:
Attribute(Document&, FlyString local_name, String value); Attribute(Document&, FlyString local_name, String value, Element const*);
QualifiedName m_qualified_name; QualifiedName m_qualified_name;
String m_value; String m_value;

View file

@ -82,7 +82,7 @@ ExceptionOr<void> Element::set_attribute(const FlyString& name, const String& va
if (auto* attribute = find_attribute(name)) if (auto* attribute = find_attribute(name))
attribute->set_value(value); attribute->set_value(value);
else else
m_attributes.append(Attribute::create(document(), name, value)); m_attributes.append(Attribute::create(document(), name, value, this));
parse_attribute(name, value); parse_attribute(name, value);
return {}; return {};