diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-19 16:39:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-19 16:39:32 +0100 |
commit | c8051f8b5bc037fb9d9559e8a733de6749d4e531 (patch) | |
tree | b52befc6380cf57b14309062647b4e9c7ec0f91e | |
parent | cf5eeb9f4b6bf4ebb2983b813aa8a597ae9d97b8 (diff) | |
download | serenity-c8051f8b5bc037fb9d9559e8a733de6749d4e531.zip |
LibWeb: Add Layout::Node::debug_description()
This returns a String with this format:
- LayoutNodeClassName<TAG_NAME>#id.class1.class2.class3
I've rewritten this function 10+ times at this point, so I'm just gonna
add it to the repository for future debugging needs. :^)
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index d8da6e9be3..910d63f73c 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -527,6 +527,25 @@ String Node::class_name() const return demangle(typeid(*this).name()); } +String Node::debug_description() const +{ + StringBuilder builder; + builder.append(class_name().substring_view(13)); + if (dom_node()) { + builder.appendff("<{}>", dom_node()->node_name()); + if (dom_node()->is_element()) { + auto& element = static_cast<DOM::Element const&>(*dom_node()); + if (auto id = element.get_attribute(HTML::AttributeNames::id); !id.is_null()) + builder.appendff("#{}", id); + for (auto const& class_name : element.class_names()) + builder.appendff(".{}", class_name); + } + } else { + builder.append("(anonymous)"); + } + return builder.to_string(); +} + bool Node::is_inline_block() const { return is_inline() && is<BlockContainer>(*this); diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index f427bb80d0..cb9e645456 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -74,6 +74,7 @@ public: bool is_root_element() const; String class_name() const; + String debug_description() const; bool has_style() const { return m_has_style; } |