mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 12:47:34 +00:00
LibHTML: Give LayoutNodes a rect.
Also improve the layout tree dump format somewhat.
This commit is contained in:
parent
c52d553249
commit
fec098b5cd
2 changed files with 32 additions and 8 deletions
|
@ -10,7 +10,7 @@ void dump_tree(const Node& node)
|
||||||
{
|
{
|
||||||
static int indent = 0;
|
static int indent = 0;
|
||||||
for (int i = 0; i < indent; ++i)
|
for (int i = 0; i < indent; ++i)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
if (node.is_document()) {
|
if (node.is_document()) {
|
||||||
printf("*Document*\n");
|
printf("*Document*\n");
|
||||||
} else if (node.is_element()) {
|
} else if (node.is_element()) {
|
||||||
|
@ -31,17 +31,36 @@ void dump_tree(const Node& node)
|
||||||
--indent;
|
--indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_tree(const LayoutNode& node)
|
void dump_tree(const LayoutNode& layout_node)
|
||||||
{
|
{
|
||||||
static int indent = 0;
|
static int indent = 0;
|
||||||
for (int i = 0; i < indent; ++i)
|
for (int i = 0; i < indent; ++i)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
printf("%s{%p}", node.class_name(), &node);
|
|
||||||
if (node.is_text())
|
String tag_name;
|
||||||
printf(" \"%s\"", static_cast<const LayoutText&>(node).text().characters());
|
if (layout_node.is_anonymous())
|
||||||
|
tag_name = "(anonymous)";
|
||||||
|
else if (layout_node.node()->is_text())
|
||||||
|
tag_name = "#text";
|
||||||
|
else if (layout_node.node()->is_document())
|
||||||
|
tag_name = "#document";
|
||||||
|
else if (layout_node.node()->is_element())
|
||||||
|
tag_name = static_cast<const Element&>(*layout_node.node()).tag_name();
|
||||||
|
else
|
||||||
|
tag_name = "???";
|
||||||
|
|
||||||
|
printf("%s {%s} at (%d,%d) size %dx%d",
|
||||||
|
layout_node.class_name(),
|
||||||
|
tag_name.characters(),
|
||||||
|
layout_node.rect().x(),
|
||||||
|
layout_node.rect().y(),
|
||||||
|
layout_node.rect().width(),
|
||||||
|
layout_node.rect().height());
|
||||||
|
if (layout_node.is_text())
|
||||||
|
printf(" \"%s\"", static_cast<const LayoutText&>(layout_node).text().characters());
|
||||||
printf("\n");
|
printf("\n");
|
||||||
++indent;
|
++indent;
|
||||||
node.for_each_child([](auto& child) {
|
layout_node.for_each_child([](auto& child) {
|
||||||
dump_tree(child);
|
dump_tree(child);
|
||||||
});
|
});
|
||||||
--indent;
|
--indent;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <AK/Retained.h>
|
#include <AK/Retained.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <SharedGraphics/Rect.h>
|
||||||
|
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
|
@ -13,6 +14,10 @@ public:
|
||||||
void release();
|
void release();
|
||||||
int retain_count() const { return m_retain_count; }
|
int retain_count() const { return m_retain_count; }
|
||||||
|
|
||||||
|
const Rect& rect() const { return m_rect; }
|
||||||
|
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||||
|
|
||||||
|
bool is_anonymous() const { return !m_node; }
|
||||||
const Node* node() const { return m_node; }
|
const Node* node() const { return m_node; }
|
||||||
|
|
||||||
LayoutNode* next_sibling() { return m_next_sibling; }
|
LayoutNode* next_sibling() { return m_next_sibling; }
|
||||||
|
@ -50,5 +55,5 @@ private:
|
||||||
LayoutNode* m_last_child { nullptr };
|
LayoutNode* m_last_child { nullptr };
|
||||||
LayoutNode* m_next_sibling { nullptr };
|
LayoutNode* m_next_sibling { nullptr };
|
||||||
LayoutNode* m_previous_sibling { nullptr };
|
LayoutNode* m_previous_sibling { nullptr };
|
||||||
|
Rect m_rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue