2019-06-15 19:55:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 16:34:26 +03:00
|
|
|
#include <AK/String.h>
|
2019-10-04 22:05:52 +03:00
|
|
|
#include <LibHTML/DOM/ParentNode.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
|
|
|
|
class Attribute {
|
|
|
|
public:
|
|
|
|
Attribute(const String& name, const String& value)
|
|
|
|
: m_name(name)
|
|
|
|
, m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-15 22:08:36 +03:00
|
|
|
const String& name() const { return m_name; }
|
|
|
|
const String& value() const { return m_value; }
|
|
|
|
|
|
|
|
void set_value(const String& value) { m_value = value; }
|
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
private:
|
|
|
|
String m_name;
|
|
|
|
String m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Element : public ParentNode {
|
|
|
|
public:
|
2019-09-29 12:43:07 +03:00
|
|
|
Element(Document&, const String& tag_name);
|
2019-06-15 19:55:47 +03:00
|
|
|
virtual ~Element() override;
|
|
|
|
|
2019-09-28 23:59:16 +03:00
|
|
|
virtual String tag_name() const override { return m_tag_name; }
|
2019-06-15 19:55:47 +03:00
|
|
|
|
2019-06-15 22:08:36 +03:00
|
|
|
String attribute(const String& name) const;
|
|
|
|
void set_attribute(const String& name, const String& value);
|
|
|
|
|
|
|
|
void set_attributes(Vector<Attribute>&&);
|
|
|
|
|
|
|
|
template<typename Callback>
|
2019-06-15 23:49:44 +03:00
|
|
|
void for_each_attribute(Callback callback) const
|
2019-06-15 22:08:36 +03:00
|
|
|
{
|
|
|
|
for (auto& attribute : m_attributes)
|
|
|
|
callback(attribute.name(), attribute.value());
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:40:21 +03:00
|
|
|
bool has_class(const StringView&) const;
|
|
|
|
|
2019-10-04 22:05:52 +03:00
|
|
|
virtual void apply_presentational_hints(StyleProperties&) const {}
|
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
private:
|
2019-06-15 22:08:36 +03:00
|
|
|
Attribute* find_attribute(const String& name);
|
|
|
|
const Attribute* find_attribute(const String& name) const;
|
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
String m_tag_name;
|
|
|
|
Vector<Attribute> m_attributes;
|
|
|
|
};
|