summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-13 17:24:00 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-13 18:47:16 +0200
commit44979ad7a50f336b5f13789a64f3679c7c879e23 (patch)
tree81318f50c77dc72623c489fd5d96e1d6e5ca2c9e /Libraries/LibHTML
parent282456dc375d5b9fe532e260baa7e52649dd368b (diff)
downloadserenity-44979ad7a50f336b5f13789a64f3679c7c879e23.zip
LibHTML: Fix broken line splitting behavior in LayoutReplaced
Replaced elements will now properly create line breaks when they use up the available horizontal space. This fixes an issue with <img>'s lining up instead of breaking.
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.cpp13
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.h3
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.h3
-rw-r--r--Libraries/LibHTML/Layout/LayoutReplaced.cpp7
4 files changed, 23 insertions, 3 deletions
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp
index 86f17ee514..5ca5f386b6 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.cpp
+++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp
@@ -244,3 +244,16 @@ NonnullRefPtr<StyleProperties> LayoutBlock::style_for_anonymous_block() const
return new_style;
}
+
+LineBox& LayoutBlock::ensure_last_line_box()
+{
+ if (m_line_boxes.is_empty())
+ m_line_boxes.append(LineBox());
+ return m_line_boxes.last();
+}
+
+LineBox& LayoutBlock::add_line_box()
+{
+ m_line_boxes.append(LineBox());
+ return m_line_boxes.last();
+}
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.h b/Libraries/LibHTML/Layout/LayoutBlock.h
index a9d242effd..dc10c36752 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.h
+++ b/Libraries/LibHTML/Layout/LayoutBlock.h
@@ -22,6 +22,9 @@ public:
Vector<LineBox>& line_boxes() { return m_line_boxes; }
const Vector<LineBox>& line_boxes() const { return m_line_boxes; }
+ LineBox& ensure_last_line_box();
+ LineBox& add_line_box();
+
virtual HitTestResult hit_test(const Point&) const override;
private:
diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h
index 38cd663d8d..5ff6b65a18 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.h
+++ b/Libraries/LibHTML/Layout/LayoutNode.h
@@ -28,6 +28,9 @@ public:
Rect& rect() { return m_rect; }
void set_rect(const Rect& rect) { m_rect = rect; }
+ int width() const { return rect().width(); }
+ int height() const { return rect().height(); }
+
BoxModelMetrics& box_model() { return m_box_metrics; }
const BoxModelMetrics& box_model() const { return m_box_metrics; }
diff --git a/Libraries/LibHTML/Layout/LayoutReplaced.cpp b/Libraries/LibHTML/Layout/LayoutReplaced.cpp
index fabfdd2067..46acbcefee 100644
--- a/Libraries/LibHTML/Layout/LayoutReplaced.cpp
+++ b/Libraries/LibHTML/Layout/LayoutReplaced.cpp
@@ -17,7 +17,8 @@ void LayoutReplaced::split_into_lines(LayoutBlock& container)
{
layout();
- if (container.line_boxes().is_empty())
- container.line_boxes().append(LineBox());
- container.line_boxes().last().add_fragment(*this, 0, 0, rect().width(), rect().height());
+ auto* line_box = &container.ensure_last_line_box();
+ if (line_box->width() + width() > container.width())
+ line_box = &container.add_line_box();
+ line_box->add_fragment(*this, 0, 0, width(), height());
}