mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
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:
parent
14f0a5943b
commit
2530378f59
5 changed files with 20 additions and 0 deletions
|
@ -102,6 +102,15 @@ int main(int argc, char** argv)
|
||||||
debug_menu->add_action(GAction::create("Dump Layout tree", [&](auto&) {
|
debug_menu->add_action(GAction::create("Dump Layout tree", [&](auto&) {
|
||||||
dump_tree(*html_widget->document()->layout_node());
|
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));
|
menubar->add_menu(move(debug_menu));
|
||||||
|
|
||||||
auto help_menu = make<GMenu>("Help");
|
auto help_menu = make<GMenu>("Help");
|
||||||
|
|
|
@ -111,6 +111,7 @@ void HtmlView::paint_event(GPaintEvent& event)
|
||||||
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
||||||
|
|
||||||
RenderingContext context { painter };
|
RenderingContext context { painter };
|
||||||
|
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
||||||
m_layout_root->render(context);
|
m_layout_root->render(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ public:
|
||||||
|
|
||||||
URL url() const;
|
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_link_click;
|
||||||
Function<void(const String&)> on_title_change;
|
Function<void(const String&)> on_title_change;
|
||||||
Function<void(const URL&)> on_load_start;
|
Function<void(const URL&)> on_load_start;
|
||||||
|
@ -41,4 +43,6 @@ private:
|
||||||
RefPtr<Frame> m_main_frame;
|
RefPtr<Frame> m_main_frame;
|
||||||
RefPtr<Document> m_document;
|
RefPtr<Document> m_document;
|
||||||
RefPtr<LayoutNode> m_layout_root;
|
RefPtr<LayoutNode> m_layout_root;
|
||||||
|
|
||||||
|
bool m_should_show_line_box_borders { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -204,6 +204,8 @@ void LayoutBlock::render(RenderingContext& context)
|
||||||
if (children_are_inline()) {
|
if (children_are_inline()) {
|
||||||
for (auto& line_box : m_line_boxes) {
|
for (auto& line_box : m_line_boxes) {
|
||||||
for (auto& fragment : line_box.fragments()) {
|
for (auto& fragment : line_box.fragments()) {
|
||||||
|
if (context.should_show_line_box_borders())
|
||||||
|
context.painter().draw_rect(fragment.rect(), Color::Green);
|
||||||
fragment.render(context);
|
fragment.render(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,10 @@ public:
|
||||||
|
|
||||||
GPainter& painter() const { return m_painter; }
|
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:
|
private:
|
||||||
GPainter& m_painter;
|
GPainter& m_painter;
|
||||||
|
bool m_should_show_line_box_borders { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue