mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:47:41 +00:00
LibWeb: Don't prune whitespace nodes from layout tree
Various whitespace-related issues have been fixed, and support for the different CSS white-space values is improved enough that I think we can stop doing the hack where we just prune whitespace nodes from the tree and actually let them show up. This is a nice step forward for correctness with the slight downside of cluttering up layout tree dumps with tons of whitespace text nodes. But hey, that's the web we know & love. :^) Fixes #4427.
This commit is contained in:
parent
29a4da30b7
commit
612827eff3
3 changed files with 0 additions and 24 deletions
|
@ -57,21 +57,6 @@ static bool is_all_whitespace(const StringView& string)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const String& TextNode::text_for_style(const CSS::StyleProperties& style) const
|
|
||||||
{
|
|
||||||
static String one_space = " ";
|
|
||||||
if (is_all_whitespace(dom_node().data())) {
|
|
||||||
switch (style.white_space().value_or(CSS::WhiteSpace::Normal)) {
|
|
||||||
case CSS::WhiteSpace::Pre:
|
|
||||||
case CSS::WhiteSpace::PreWrap:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return one_space;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dom_node().data();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment, PaintPhase phase) const
|
void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment, PaintPhase phase) const
|
||||||
{
|
{
|
||||||
auto& painter = context.painter();
|
auto& painter = context.painter();
|
||||||
|
|
|
@ -40,7 +40,6 @@ public:
|
||||||
|
|
||||||
const DOM::Text& dom_node() const { return static_cast<const DOM::Text&>(*Node::dom_node()); }
|
const DOM::Text& dom_node() const { return static_cast<const DOM::Text&>(*Node::dom_node()); }
|
||||||
|
|
||||||
const String& text_for_style(const CSS::StyleProperties&) const;
|
|
||||||
const String& text_for_rendering() const { return m_text_for_rendering; }
|
const String& text_for_rendering() const { return m_text_for_rendering; }
|
||||||
|
|
||||||
virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
|
virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
|
||||||
|
|
|
@ -91,18 +91,10 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node)
|
||||||
if (dom_node.parent() && !dom_node.parent()->layout_node())
|
if (dom_node.parent() && !dom_node.parent()->layout_node())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CSS::StyleProperties* parent_style = nullptr;
|
|
||||||
if (!m_parent_stack.is_empty() && m_parent_stack.last()->dom_node() && m_parent_stack.last()->dom_node()->is_element())
|
|
||||||
parent_style = downcast<DOM::Element>(*m_parent_stack.last()->dom_node()).specified_css_values();
|
|
||||||
|
|
||||||
auto layout_node = dom_node.create_layout_node();
|
auto layout_node = dom_node.create_layout_node();
|
||||||
if (!layout_node)
|
if (!layout_node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Discard empty whitespace nodes. This might not be ideal for correctness, but it does make the tree nicer.
|
|
||||||
if (is<TextNode>(*layout_node) && downcast<TextNode>(*layout_node).text_for_style(*parent_style) == " ")
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!dom_node.parent()) {
|
if (!dom_node.parent()) {
|
||||||
m_layout_root = layout_node;
|
m_layout_root = layout_node;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue