summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-12 15:02:53 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-12 15:02:53 +0200
commit2530378f59ff8152a3da94c33569f2c246c9f761 (patch)
tree416204478ca10717c470eeb7996307bba0177772 /Libraries/LibHTML
parent14f0a5943b16345237c63bb932cdb9af5c85dd1d (diff)
downloadserenity-2530378f59ff8152a3da94c33569f2c246c9f761.zip
LibHTML+Browser: Add debug option to draw borders around line boxes
This will be very useful when debugging line layout.
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/HtmlView.cpp1
-rw-r--r--Libraries/LibHTML/HtmlView.h4
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.cpp2
-rw-r--r--Libraries/LibHTML/RenderingContext.h4
4 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index f3f8388158..6ac1a9ff0b 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -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);
}
diff --git a/Libraries/LibHTML/HtmlView.h b/Libraries/LibHTML/HtmlView.h
index bccd78286a..3d147b8f7e 100644
--- a/Libraries/LibHTML/HtmlView.h
+++ b/Libraries/LibHTML/HtmlView.h
@@ -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 };
};
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp
index 4373624c76..86f17ee514 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.cpp
+++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp
@@ -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);
}
}
diff --git a/Libraries/LibHTML/RenderingContext.h b/Libraries/LibHTML/RenderingContext.h
index 2e50ed82a5..bfba539968 100644
--- a/Libraries/LibHTML/RenderingContext.h
+++ b/Libraries/LibHTML/RenderingContext.h
@@ -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 };
};