Browse Source

LibWeb: Treat grid items with z-index != auto as positioned elements

Aliaksandr Kalenik 1 year ago
parent
commit
cca779e7f6

+ 8 - 0
Tests/LibWeb/Ref/item-with-negative-z-index-ref.html

@@ -0,0 +1,8 @@
+<!doctype html><style type="text/css">
+* { outline: 1px solid black; }
+body { display: grid; }
+.foo {
+    grid-area: 1 / 1 / auto / auto;
+    background: pink;
+}
+</style><body><div class="foo">foo</div>

+ 13 - 0
Tests/LibWeb/Ref/item-with-negative-z-index.html

@@ -0,0 +1,13 @@
+<!doctype html><style type="text/css">
+* { outline: 1px solid black; }
+body { display: grid; }
+.foo {
+    grid-area: 1 / 1 / auto / auto;
+    background: pink;
+}
+.bar {
+    grid-area: 1 / 1 / auto / auto;
+    background: orange;
+    z-index: -1;
+}
+</style><body><div class="foo">foo</div><div class="bar">bar</div>

+ 1 - 0
Tests/LibWeb/Ref/manifest.json

@@ -1,4 +1,5 @@
 {
 {
+    "item-with-negative-z-index.html": "item-with-negative-z-index-ref.html",
     "img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html",
     "img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html",
     "grid-items-painting-order.html": "grid-items-painting-order-ref.html",
     "grid-items-painting-order.html": "grid-items-painting-order-ref.html",
     "square-flex.html": "square-ref.html",
     "square-flex.html": "square-ref.html",

+ 10 - 0
Userland/Libraries/LibWeb/Painting/Paintable.cpp

@@ -27,6 +27,16 @@ void Paintable::visit_edges(Cell::Visitor& visitor)
         visitor.visit(m_containing_block.value());
         visitor.visit(m_containing_block.value());
 }
 }
 
 
+bool Paintable::is_positioned() const
+{
+    if (layout_node().is_grid_item() && computed_values().z_index().has_value()) {
+        // https://www.w3.org/TR/css-grid-2/#z-order
+        // grid items with z_index should behave as if position were "relative"
+        return true;
+    }
+    return computed_values().position() != CSS::Position::Static;
+}
+
 void Paintable::set_dom_node(JS::GCPtr<DOM::Node> dom_node)
 void Paintable::set_dom_node(JS::GCPtr<DOM::Node> dom_node)
 {
 {
     m_dom_node = dom_node;
     m_dom_node = dom_node;

+ 1 - 1
Userland/Libraries/LibWeb/Painting/Paintable.h

@@ -56,7 +56,7 @@ class Paintable
 public:
 public:
     virtual ~Paintable() = default;
     virtual ~Paintable() = default;
 
 
-    [[nodiscard]] bool is_positioned() const { return layout_node().is_positioned(); }
+    [[nodiscard]] bool is_positioned() const;
     [[nodiscard]] bool is_fixed_position() const { return layout_node().is_fixed_position(); }
     [[nodiscard]] bool is_fixed_position() const { return layout_node().is_fixed_position(); }
     [[nodiscard]] bool is_absolutely_positioned() const { return layout_node().is_absolutely_positioned(); }
     [[nodiscard]] bool is_absolutely_positioned() const { return layout_node().is_absolutely_positioned(); }
     [[nodiscard]] bool is_floating() const { return layout_node().is_floating(); }
     [[nodiscard]] bool is_floating() const { return layout_node().is_floating(); }