mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:27:35 +00:00
LibWeb: Make Layout::TextNode::text_for_rendering() lazily computed
As it turns out, Layout::TreeBuilder never managed to wrap text within table boxes in anonymous wrapper boxes, since it relied on checking text_for_rendering(), and that was never initialized during that early stage of tree building. This patch fixes the issue by making text_for_rendering() compute the (potentially collapsed) text lazily when called. Note that the test included with this patch is still totally wrong, but that is now a TFC problem rather than a TreeBuilder problem. :^)
This commit is contained in:
parent
5cdb394400
commit
b918ce4022
5 changed files with 69 additions and 7 deletions
|
@ -258,9 +258,6 @@ void InlineLevelIterator::enter_text_node(Layout::TextNode const& text_node)
|
|||
if (text_node.dom_node().is_editable() && !text_node.dom_node().is_uninteresting_whitespace_node())
|
||||
do_collapse = false;
|
||||
|
||||
// FIXME: The const_cast here is gross.
|
||||
const_cast<TextNode&>(text_node).compute_text_for_rendering(do_collapse);
|
||||
|
||||
m_text_node_context = TextNodeContext {
|
||||
.do_collapse = do_collapse,
|
||||
.do_wrap_lines = do_wrap_lines,
|
||||
|
|
|
@ -41,9 +41,32 @@ static ErrorOr<DeprecatedString> apply_text_transform(DeprecatedString const& st
|
|||
return string;
|
||||
}
|
||||
|
||||
// NOTE: This collapses whitespace into a single ASCII space if collapse is true.
|
||||
void TextNode::compute_text_for_rendering(bool collapse)
|
||||
DeprecatedString const& TextNode::text_for_rendering() const
|
||||
{
|
||||
if (m_text_for_rendering.is_null())
|
||||
const_cast<TextNode*>(this)->compute_text_for_rendering();
|
||||
return m_text_for_rendering;
|
||||
}
|
||||
|
||||
// NOTE: This collapses whitespace into a single ASCII space if the CSS white-space property tells us to.
|
||||
void TextNode::compute_text_for_rendering()
|
||||
{
|
||||
bool collapse = [](CSS::WhiteSpace white_space) {
|
||||
switch (white_space) {
|
||||
case CSS::WhiteSpace::Normal:
|
||||
case CSS::WhiteSpace::Nowrap:
|
||||
case CSS::WhiteSpace::PreLine:
|
||||
return true;
|
||||
case CSS::WhiteSpace::Pre:
|
||||
case CSS::WhiteSpace::PreWrap:
|
||||
return false;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}(computed_values().white_space());
|
||||
|
||||
if (dom_node().is_editable() && !dom_node().is_uninteresting_whitespace_node())
|
||||
collapse = false;
|
||||
|
||||
auto data = apply_text_transform(dom_node().data(), computed_values().text_transform()).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
if (dom_node().is_password_input()) {
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
const DOM::Text& dom_node() const { return static_cast<const DOM::Text&>(*Node::dom_node()); }
|
||||
|
||||
DeprecatedString const& text_for_rendering() const { return m_text_for_rendering; }
|
||||
DeprecatedString const& text_for_rendering() const;
|
||||
|
||||
struct Chunk {
|
||||
Utf8View view;
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
Utf8View::Iterator m_iterator;
|
||||
};
|
||||
|
||||
void compute_text_for_rendering(bool collapse);
|
||||
void compute_text_for_rendering();
|
||||
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue