1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibHTML: More work on the CSS object model.

This commit is contained in:
Andreas Kling 2019-06-21 19:19:49 +02:00
parent d343fb2429
commit 02e02ca3a5
6 changed files with 41 additions and 12 deletions

View file

@ -1,6 +1,8 @@
#include <LibHTML/CSS/StyleDeclaration.h> #include <LibHTML/CSS/StyleDeclaration.h>
StyleDeclaration::StyleDeclaration() StyleDeclaration::StyleDeclaration(const String& property_name, NonnullRefPtr<StyleValue>&& value)
: m_property_name(property_name)
, m_value(move(value))
{ {
} }

View file

@ -3,15 +3,21 @@
#include <AK/AKString.h> #include <AK/AKString.h>
#include <LibHTML/CSS/StyleValue.h> #include <LibHTML/CSS/StyleValue.h>
class StyleDeclaration { class StyleDeclaration : public RefCounted<StyleDeclaration> {
public: public:
StyleDeclaration(); NonnullRefPtr<StyleDeclaration> create(const String& property_name, NonnullRefPtr<StyleValue>&& value)
{
return adopt(*new StyleDeclaration(property_name, move(value)));
}
~StyleDeclaration(); ~StyleDeclaration();
const String& property_name() const { return m_property_name; } const String& property_name() const { return m_property_name; }
const StyleValue& value() const { return *m_value; } const StyleValue& value() const { return *m_value; }
public: public:
StyleDeclaration(const String& property_name, NonnullRefPtr<StyleValue>&&);
String m_property_name; String m_property_name;
RefPtr<StyleValue> m_value; NonnullRefPtr<StyleValue> m_value;
}; };

View file

@ -0,0 +1,8 @@
#include <LibHTML/CSS/StyleRule.h>
StyleRule::StyleRule(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
: m_selectors(move(selectors))
, m_declarations(move(declarations))
{
}

View file

@ -4,12 +4,18 @@
#include <LibHTML/CSS/Selector.h> #include <LibHTML/CSS/Selector.h>
#include <LibHTML/CSS/StyleDeclaration.h> #include <LibHTML/CSS/StyleDeclaration.h>
class StyleRule { class StyleRule : public RefCounted<StyleRule> {
public: public:
StyleRule(); NonnullRefPtr<StyleRule> create(Vector<Selector>&& selectors, Vector<NonnullRefPtr<StyleDeclaration>>&& declarations)
{
return adopt(*new StyleRule(move(selectors), move(declarations)));
}
~StyleRule(); ~StyleRule();
private: private:
StyleRule(Vector<Selector>&&, Vector<NonnullRefPtr<StyleDeclaration>>&&);
Vector<Selector> m_selectors; Vector<Selector> m_selectors;
Vector<StyleDeclaration> m_declarations; Vector<NonnullRefPtr<StyleDeclaration>> m_declarations;
}; };

View file

@ -1,6 +1,7 @@
#include <LibHTML/CSS/StyleSheet.h> #include <LibHTML/CSS/StyleSheet.h>
StyleSheet::StyleSheet() StyleSheet::StyleSheet(Vector<NonnullRefPtr<StyleRule>>&& rules)
: m_rules(move(rules))
{ {
} }

View file

@ -3,13 +3,19 @@
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibHTML/CSS/StyleRule.h> #include <LibHTML/CSS/StyleRule.h>
class StyleSheet { class StyleSheet : public RefCounted<StyleSheet> {
public: public:
StyleSheet(); NonnullRefPtr<StyleSheet> create(Vector<NonnullRefPtr<StyleRule>>&& rules)
{
return adopt(*new StyleSheet(move(rules)));
}
~StyleSheet(); ~StyleSheet();
const Vector<StyleRule>& rules() const { return m_rules; } const Vector<NonnullRefPtr<StyleRule>>& rules() const { return m_rules; }
private: private:
Vector<StyleRule> m_rules; explicit StyleSheet(Vector<NonnullRefPtr<StyleRule>>&&);
Vector<NonnullRefPtr<StyleRule>> m_rules;
}; };