LibHTML+Browser: Add debug option to draw borders around line boxes

This will be very useful when debugging line layout.
This commit is contained in:
Andreas Kling 2019-10-12 15:02:53 +02:00
parent 14f0a5943b
commit 2530378f59
Notes: sideshowbarker 2024-07-19 11:43:35 +09:00
5 changed files with 20 additions and 0 deletions

View file

@ -102,6 +102,15 @@ int main(int argc, char** argv)
debug_menu->add_action(GAction::create("Dump Layout tree", [&](auto&) {
dump_tree(*html_widget->document()->layout_node());
}));
debug_menu->add_separator();
auto line_box_borders_action = GAction::create("Line box borders", [&](auto& action) {
action.set_checked(!action.is_checked());
html_widget->set_should_show_line_box_borders(action.is_checked());
html_widget->update();
});
line_box_borders_action->set_checkable(true);
line_box_borders_action->set_checked(false);
debug_menu->add_action(line_box_borders_action);
menubar->add_menu(move(debug_menu));
auto help_menu = make<GMenu>("Help");

View file

@ -111,6 +111,7 @@ void HtmlView::paint_event(GPaintEvent& event)
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
RenderingContext context { painter };
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
m_layout_root->render(context);
}

View file

@ -23,6 +23,8 @@ public:
URL url() const;
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
Function<void(const String&)> on_link_click;
Function<void(const String&)> on_title_change;
Function<void(const URL&)> on_load_start;
@ -41,4 +43,6 @@ private:
RefPtr<Frame> m_main_frame;
RefPtr<Document> m_document;
RefPtr<LayoutNode> m_layout_root;
bool m_should_show_line_box_borders { false };
};

View file

@ -204,6 +204,8 @@ void LayoutBlock::render(RenderingContext& context)
if (children_are_inline()) {
for (auto& line_box : m_line_boxes) {
for (auto& fragment : line_box.fragments()) {
if (context.should_show_line_box_borders())
context.painter().draw_rect(fragment.rect(), Color::Green);
fragment.render(context);
}
}

View file

@ -11,6 +11,10 @@ public:
GPainter& painter() const { return m_painter; }
bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
private:
GPainter& m_painter;
bool m_should_show_line_box_borders { false };
};