mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
LibWeb: Honor CSS display value in is_inline() and is_inline_block()
These were totally ad-hoc before, is_inline() was based on a boolean flag on Layout::Node that we set in various situations. Meanwhile, is_inline_block() was a combination on is_inline() plus a type check to see if the layout node inherited from BlockContainer. This patch replaces the above mess with simple lookups of the CSS display value. Note that layout nodes without their own style (i.e text nodes) are automatically assumed to be inline and non-blocks. This has to be special-cased since layout nodes without style will consult the style of their parent, so without short-circuiting this would break.
This commit is contained in:
parent
fe03149a47
commit
5989a3ee77
2 changed files with 21 additions and 4 deletions
|
@ -579,9 +579,26 @@ String Node::debug_description() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
void Node::set_inline(bool) { }
|
||||
|
||||
bool Node::is_inline() const
|
||||
{
|
||||
if (!has_style()) {
|
||||
// NOTE: If this node doesn't have its own style, computed_values() will get style from the parent.
|
||||
// This could give unwanted results. Besides, if we don't have style, we're some kind of inline text node.
|
||||
return true;
|
||||
}
|
||||
return computed_values().display().is_inline_outside();
|
||||
}
|
||||
|
||||
bool Node::is_inline_block() const
|
||||
{
|
||||
return is_inline() && is<BlockContainer>(*this);
|
||||
if (!has_style()) {
|
||||
// NOTE: If this node doesn't have its own style, computed_values() will get style from the parent.
|
||||
// This could give unwanted results. Besides, if we don't have style, we're some kind of inline text node.
|
||||
return false;
|
||||
}
|
||||
return computed_values().display().is_inline_outside() && computed_values().display().is_flow_root_inside();
|
||||
}
|
||||
|
||||
NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
|
||||
|
|
|
@ -68,9 +68,10 @@ public:
|
|||
|
||||
virtual bool can_have_children() const { return true; }
|
||||
|
||||
bool is_inline() const { return m_inline; }
|
||||
void set_inline(bool b) { m_inline = b; }
|
||||
// FIXME: Remove this.
|
||||
void set_inline(bool);
|
||||
|
||||
bool is_inline() const;
|
||||
bool is_inline_block() const;
|
||||
|
||||
bool is_out_of_flow(FormattingContext const&) const;
|
||||
|
@ -149,7 +150,6 @@ private:
|
|||
|
||||
size_t m_serial_id { 0 };
|
||||
|
||||
bool m_inline { false };
|
||||
bool m_has_style { false };
|
||||
bool m_visible { true };
|
||||
bool m_children_are_inline { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue