LibWeb: Make TextNode::ChunkIterator emit an empty chunk for content:""
This ensures that we create a line box for content:"", which would otherwise get pruned by the empty line cleanup in IFC. The empty line box is important in this case, since it gives us a reference point for measuring the automatic height of the IFC's containing block. By having an empty line, we can now correctly measure the impact of vertical margins on a generated box with content:"" and allow them to contribute to the block height.
This commit is contained in:
parent
c70801ddbc
commit
b062a0fb7c
Notes:
sideshowbarker
2024-07-17 06:45:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b062a0fb7c
3 changed files with 16 additions and 3 deletions
|
@ -264,7 +264,7 @@ void InlineLevelIterator::enter_text_node(Layout::TextNode const& text_node)
|
||||||
.do_respect_linebreaks = do_respect_linebreaks,
|
.do_respect_linebreaks = do_respect_linebreaks,
|
||||||
.is_first_chunk = true,
|
.is_first_chunk = true,
|
||||||
.is_last_chunk = false,
|
.is_last_chunk = false,
|
||||||
.chunk_iterator = TextNode::ChunkIterator { text_node.text_for_rendering(), do_wrap_lines, do_respect_linebreaks },
|
.chunk_iterator = TextNode::ChunkIterator { text_node.text_for_rendering(), do_wrap_lines, do_respect_linebreaks, text_node.is_generated() && text_node.text_for_rendering().is_empty() },
|
||||||
};
|
};
|
||||||
m_text_node_context->next_chunk = m_text_node_context->chunk_iterator.next();
|
m_text_node_context->next_chunk = m_text_node_context->chunk_iterator.next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,9 +85,10 @@ void TextNode::compute_text_for_rendering(bool collapse)
|
||||||
m_text_for_rendering = builder.to_string();
|
m_text_for_rendering = builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextNode::ChunkIterator::ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks)
|
TextNode::ChunkIterator::ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks, bool is_generated_empty_string)
|
||||||
: m_wrap_lines(wrap_lines)
|
: m_wrap_lines(wrap_lines)
|
||||||
, m_respect_linebreaks(respect_linebreaks)
|
, m_respect_linebreaks(respect_linebreaks)
|
||||||
|
, m_should_emit_one_empty_chunk(is_generated_empty_string)
|
||||||
, m_utf8_view(text)
|
, m_utf8_view(text)
|
||||||
, m_iterator(m_utf8_view.begin())
|
, m_iterator(m_utf8_view.begin())
|
||||||
{
|
{
|
||||||
|
@ -95,6 +96,17 @@ TextNode::ChunkIterator::ChunkIterator(StringView text, bool wrap_lines, bool re
|
||||||
|
|
||||||
Optional<TextNode::Chunk> TextNode::ChunkIterator::next()
|
Optional<TextNode::Chunk> TextNode::ChunkIterator::next()
|
||||||
{
|
{
|
||||||
|
if (m_should_emit_one_empty_chunk) {
|
||||||
|
m_should_emit_one_empty_chunk = false;
|
||||||
|
return Chunk {
|
||||||
|
.view = {},
|
||||||
|
.start = 0,
|
||||||
|
.length = 0,
|
||||||
|
.has_breaking_newline = false,
|
||||||
|
.is_all_whitespace = false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (m_iterator == m_utf8_view.end())
|
if (m_iterator == m_utf8_view.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
class ChunkIterator {
|
class ChunkIterator {
|
||||||
public:
|
public:
|
||||||
ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks);
|
ChunkIterator(StringView text, bool wrap_lines, bool respect_linebreaks, bool is_generated_empty_string);
|
||||||
Optional<Chunk> next();
|
Optional<Chunk> next();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
bool const m_wrap_lines;
|
bool const m_wrap_lines;
|
||||||
bool const m_respect_linebreaks;
|
bool const m_respect_linebreaks;
|
||||||
|
bool m_should_emit_one_empty_chunk { false };
|
||||||
Utf8View m_utf8_view;
|
Utf8View m_utf8_view;
|
||||||
Utf8View::Iterator m_iterator;
|
Utf8View::Iterator m_iterator;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue