aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <infra@servo.org>2023-06-23 08:59:37 +0200
committerGitHub <noreply@github.com>2023-06-23 08:59:37 +0200
commitd3bb2170b87e6fe03ecadd2a59f09e5655943f65 (patch)
tree482fec17aeaebc9de91ef0d65aa1e99887d7ff07
parentbefb472c9d43d77d69ff86b447e857c392fe85e0 (diff)
parent0ced74cde39a88a2173f11b166ae1b0a4d130358 (diff)
downloadservo-d3bb2170b87e6fe03ecadd2a59f09e5655943f65.tar.gz
servo-d3bb2170b87e6fe03ecadd2a59f09e5655943f65.zip
Auto merge of #29910 - mrobinson:static-absolute-of-inline-box, r=Loirooriol
Fix positioning of statically positioned absolute child of inline box <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
-rw-r--r--components/layout_2020/flow/inline.rs14
-rw-r--r--components/layout_2020/positioned.rs17
-rw-r--r--tests/wpt/meta/MANIFEST.json17
-rw-r--r--tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block-ref.html11
-rw-r--r--tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block.html12
5 files changed, 63 insertions, 8 deletions
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index aba8790987a..e713d9c2a8e 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -659,13 +659,20 @@ fn layout_atomic(
containing_block_for_children.style.writing_mode,
"Mixed writing modes are not supported yet"
);
- // FIXME: Do we need to adjust the static position of the hoisted fragments in the positioning
- // context somewhere near here?
+
+ let collects_for_nearest_positioned_ancestor = ifc
+ .positioning_context
+ .collects_for_nearest_positioned_ancestor();
+ let mut child_positioning_context =
+ PositioningContext::new_for_subtree(collects_for_nearest_positioned_ancestor);
let independent_layout = non_replaced.layout(
layout_context,
- ifc.positioning_context,
+ &mut child_positioning_context,
&containing_block_for_children,
);
+ child_positioning_context
+ .adjust_static_position_of_hoisted_fragments_with_offset(&start_corner);
+ ifc.positioning_context.append(child_positioning_context);
// https://drafts.csswg.org/css2/visudet.html#block-root-margin
let tentative_block_size = box_size
@@ -685,6 +692,7 @@ fn layout_atomic(
inline: inline_size,
},
};
+
BoxFragment::new(
non_replaced.base_fragment_info,
non_replaced.style.clone(),
diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs
index b1ab687a4e9..07831f8dbf8 100644
--- a/components/layout_2020/positioned.rs
+++ b/components/layout_2020/positioned.rs
@@ -166,20 +166,27 @@ impl PositioningContext {
&mut self,
parent_fragment: &Fragment,
) {
- let fragment_rect = match &parent_fragment {
- Fragment::Box(b) | Fragment::Float(b) => &b.content_rect,
+ let start_offset = match &parent_fragment {
+ Fragment::Box(b) | Fragment::Float(b) => &b.content_rect.start_corner,
Fragment::AbsoluteOrFixedPositioned(_) => return,
- Fragment::Anonymous(a) => &a.rect,
+ Fragment::Anonymous(a) => &a.rect.start_corner,
_ => unreachable!(),
};
+ self.adjust_static_position_of_hoisted_fragments_with_offset(start_offset);
+ }
+ /// See documentation for [adjust_static_position_of_hoisted_fragments].
+ pub(crate) fn adjust_static_position_of_hoisted_fragments_with_offset(
+ &mut self,
+ start_offset: &Vec2<CSSPixelLength>,
+ ) {
let update_fragment_if_needed = |hoisted_fragment: &mut HoistedAbsolutelyPositionedBox| {
let mut fragment = hoisted_fragment.fragment.borrow_mut();
if let AbsoluteBoxOffsets::StaticStart { start } = &mut fragment.box_offsets.inline {
- *start += fragment_rect.start_corner.inline;
+ *start += start_offset.inline;
}
if let AbsoluteBoxOffsets::StaticStart { start } = &mut fragment.box_offsets.block {
- *start += fragment_rect.start_corner.block;
+ *start += start_offset.block;
}
};
diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json
index f0b065a74d8..d39c79550ed 100644
--- a/tests/wpt/meta/MANIFEST.json
+++ b/tests/wpt/meta/MANIFEST.json
@@ -31605,6 +31605,19 @@
{}
]
],
+ "static-inside-inline-block.html": [
+ "327e8e6dacdeabb4d2d57ab700d80f966ccde76b",
+ [
+ null,
+ [
+ [
+ "/css/CSS2/abspos/static-inside-inline-block-ref.html",
+ "=="
+ ]
+ ],
+ {}
+ ]
+ ],
"static-inside-table-cell.html": [
"712bfbaf1e8f2d6a7a8fdd8dfa65792770f004e3",
[
@@ -355090,6 +355103,10 @@
"hypothetical-inline-alone-on-second-line-ref.html": [
"1ceebb0f7e39896003508a769c772cc6e6bf54cd",
[]
+ ],
+ "static-inside-inline-block-ref.html": [
+ "e76a2ccb972a2c056ffdd6380e60e5590b87b36e",
+ []
]
},
"backgrounds": {
diff --git a/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block-ref.html b/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block-ref.html
new file mode 100644
index 00000000000..e76a2ccb972
--- /dev/null
+++ b/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<title>Static position inside inline-block</title>
+<link rel="author" title="Martin Robinson" href="mrobinson@igalia.com">
+<link rel="help" href="https://www.w3.org/TR/CSS22/visudet.html#abs-non-replaced-width" title="10.3.7 Absolutely positioned, non-replaced elements">
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
+<div style="display: inline-block; width: 100px; height: 100px;"></div>
+<div style="display: inline-block; width: 100px; height: 100px; background: red;">
+ <div style="width: 100px; height: 100px; background: green;"></div>
+</div>
+<div style="display: inline-block; width: 100px; height: 100px;"></div>
diff --git a/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block.html b/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block.html
new file mode 100644
index 00000000000..327e8e6dacd
--- /dev/null
+++ b/tests/wpt/web-platform-tests/css/CSS2/abspos/static-inside-inline-block.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<title>Static position inside inline-block</title>
+<link rel="author" title="Martin Robinson" href="mrobinson@igalia.com">
+<link rel="help" href="https://www.w3.org/TR/CSS22/visudet.html#abs-non-replaced-width" title="10.3.7 Absolutely positioned, non-replaced elements">
+<link rel="match" href="static-inside-inline-block-ref.html">
+
+<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
+<div style="display: inline-block; width: 100px; height: 100px;"></div>
+<div style="display: inline-block; width: 100px; height: 100px; background: red;">
+ <div style="position: absolute; width: 100px; height: 100px; background: green;"></div>
+</div>
+<div style="display: inline-block; width: 100px; height: 100px;"></div>