LibHTML: Flesh out the code to dump a StyleSheet object graph.
This commit is contained in:
parent
048705e1c2
commit
6469d7f043
Notes:
sideshowbarker
2024-07-19 13:29:22 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6469d7f043b
3 changed files with 42 additions and 1 deletions
|
@ -13,6 +13,16 @@ public:
|
||||||
|
|
||||||
~StyleRule();
|
~StyleRule();
|
||||||
|
|
||||||
|
const Vector<Selector>& selectors() const { return m_selectors; }
|
||||||
|
const Vector<NonnullRefPtr<StyleDeclaration>>& declarations() const { return m_declarations; }
|
||||||
|
|
||||||
|
template<typename C>
|
||||||
|
void for_each_declaration(C callback) const
|
||||||
|
{
|
||||||
|
for (auto& declaration : m_declarations)
|
||||||
|
callback(*declaration);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StyleRule(Vector<Selector>&&, Vector<NonnullRefPtr<StyleDeclaration>>&&);
|
StyleRule(Vector<Selector>&&, Vector<NonnullRefPtr<StyleDeclaration>>&&);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
|
||||||
|
virtual String to_string() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit StyleValue(Type);
|
explicit StyleValue(Type);
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
String to_string() const { return m_string; }
|
String to_string() const override { return m_string; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_string;
|
String m_string;
|
||||||
|
|
|
@ -70,4 +70,33 @@ void dump_tree(const LayoutNode& layout_node)
|
||||||
void dump_sheet(const StyleSheet& sheet)
|
void dump_sheet(const StyleSheet& sheet)
|
||||||
{
|
{
|
||||||
printf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue