summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-10-06 14:39:11 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-06 15:29:38 +0200
commit5989a3ee77463aa0ed029019364faf64e54ebb62 (patch)
treefcb4ff77536655c245827475d78e5177494211f0 /Userland/Libraries/LibWeb/Layout
parentfe03149a470840defa8783cb633b3f46bdff703c (diff)
downloadserenity-5989a3ee77463aa0ed029019364faf64e54ebb62.zip
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp19
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.h6
2 files changed, 21 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index db2ae08e4f..2fb2fe07ec 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -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
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h
index ae5bb7805f..8c72e81aec 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.h
+++ b/Userland/Libraries/LibWeb/Layout/Node.h
@@ -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 };