1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:37:36 +00:00

LibWeb: Don't crash when dumping layout tree pre-layout

If we haven't run layout yet, there aren't any paintables attached to
the tree, so we have to null check them.
This commit is contained in:
Andreas Kling 2022-03-18 22:12:03 +01:00
parent 11dffbd96f
commit 3f55271c8e

View file

@ -166,11 +166,13 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
if (interactive) if (interactive)
builder.appendff("@{:p} ", &layout_node); builder.appendff("@{:p} ", &layout_node);
if (auto const* paint_box = box.paint_box()) {
builder.appendff("at ({},{}) content-size {}x{}", builder.appendff("at ({},{}) content-size {}x{}",
box.paint_box()->absolute_x(), paint_box->absolute_x(),
box.paint_box()->absolute_y(), paint_box->absolute_y(),
box.paint_box()->content_width(), paint_box->content_width(),
box.paint_box()->content_height()); paint_box->content_height());
}
if (box.is_positioned()) if (box.is_positioned())
builder.appendff(" {}positioned{}", positioned_color_on, color_off); builder.appendff(" {}positioned{}", positioned_color_on, color_off);
@ -205,7 +207,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
box.box_model().margin.left, box.box_model().margin.left,
box.box_model().border.left, box.box_model().border.left,
box.box_model().padding.left, box.box_model().padding.left,
box.paint_box()->content_width(), box.paint_box() ? box.paint_box()->content_width() : 0,
box.box_model().padding.right, box.box_model().padding.right,
box.box_model().border.right, box.box_model().border.right,
box.box_model().margin.right); box.box_model().margin.right);
@ -215,7 +217,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
box.box_model().margin.top, box.box_model().margin.top,
box.box_model().border.top, box.box_model().border.top,
box.box_model().padding.top, box.box_model().padding.top,
box.paint_box()->content_height(), box.paint_box() ? box.paint_box()->content_height() : 0,
box.box_model().padding.bottom, box.box_model().padding.bottom,
box.box_model().border.bottom, box.box_model().border.bottom,
box.box_model().margin.bottom); box.box_model().margin.bottom);
@ -226,7 +228,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
if (is<Layout::BlockContainer>(layout_node) && static_cast<Layout::BlockContainer const&>(layout_node).children_are_inline()) { if (is<Layout::BlockContainer>(layout_node) && static_cast<Layout::BlockContainer const&>(layout_node).children_are_inline()) {
auto& block = static_cast<Layout::BlockContainer const&>(layout_node); auto& block = static_cast<Layout::BlockContainer const&>(layout_node);
for (size_t line_box_index = 0; line_box_index < block.paint_box()->line_boxes().size(); ++line_box_index) { for (size_t line_box_index = 0; block.paint_box() && line_box_index < block.paint_box()->line_boxes().size(); ++line_box_index) {
auto& line_box = block.paint_box()->line_boxes()[line_box_index]; auto& line_box = block.paint_box()->line_boxes()[line_box_index];
for (size_t i = 0; i < indent; ++i) for (size_t i = 0; i < indent; ++i)
builder.append(" "); builder.append(" ");