diff --git a/LibHTML/CSS/StyleRule.h b/LibHTML/CSS/StyleRule.h
index ec40b7d28a..cfff791698 100644
--- a/LibHTML/CSS/StyleRule.h
+++ b/LibHTML/CSS/StyleRule.h
@@ -13,6 +13,16 @@ public:
~StyleRule();
+ const Vector& selectors() const { return m_selectors; }
+ const Vector>& declarations() const { return m_declarations; }
+
+ template
+ void for_each_declaration(C callback) const
+ {
+ for (auto& declaration : m_declarations)
+ callback(*declaration);
+ }
+
private:
StyleRule(Vector&&, Vector>&&);
diff --git a/LibHTML/CSS/StyleValue.h b/LibHTML/CSS/StyleValue.h
index aa1371a10e..3fc1930d42 100644
--- a/LibHTML/CSS/StyleValue.h
+++ b/LibHTML/CSS/StyleValue.h
@@ -20,6 +20,8 @@ public:
Type type() const { return m_type; }
+ virtual String to_string() const = 0;
+
protected:
explicit StyleValue(Type);
@@ -36,7 +38,7 @@ public:
{
}
- String to_string() const { return m_string; }
+ String to_string() const override { return m_string; }
private:
String m_string;
diff --git a/LibHTML/Dump.cpp b/LibHTML/Dump.cpp
index 3fb8d1a741..411ff8bffc 100644
--- a/LibHTML/Dump.cpp
+++ b/LibHTML/Dump.cpp
@@ -70,4 +70,33 @@ void dump_tree(const LayoutNode& layout_node)
void dump_sheet(const StyleSheet& sheet)
{
printf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());
+
+ for (auto& rule : sheet.rules()) {
+ printf("Rule:\n");
+ for (auto& selector : rule->selectors()) {
+ printf(" Selector:\n");
+ for (auto& component : selector.components()) {
+ const char* type_description = "Unknown";
+ switch (component.type) {
+ case Selector::Component::Type::Invalid:
+ type_description = "Invalid";
+ break;
+ case Selector::Component::Type::Id:
+ type_description = "Id";
+ break;
+ case Selector::Component::Type::Class:
+ type_description = "Class";
+ break;
+ case Selector::Component::Type::TagName:
+ type_description = "TagName";
+ break;
+ }
+ printf(" %s:%s", type_description, component.value.characters());
+ }
+ }
+ printf(" Declarations:\n");
+ rule->for_each_declaration([](auto& declaration) {
+ printf(" '%s': '%s'\n", declaration.property_name().characters(), declaration.value().to_string().characters());
+ });
+ }
}