mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
layout: Simplify PositioningContext
by having it hold a single Vec
(#36795)
`PositioningContext` held two vectors, one inside an `Option`, to differentiate between the version used for a containing block for all descendants (including `position: absolute` and `position: fixed`) or only for `position: absolute` descendants. This distinction was really hard to reason about and required a lot of bookkeeping about what kind of `PositioningContext` a layout box's parent expected. In addition, it led to a lot of mistakes. This change simplifies things so that `PositioningContext` only holds a single vector. When it comes time to lay out hoisted absolutely positioned fragments, the code then: - lays out all of them (in the case of a `PositioningContext` for all descendants), or - only lays out the `position: absolute` descendants and preserves the `position: fixed` descendants (in the case the `PositioningContext` is only for `position: absolute`.), or - lays out none of them if the `PositioningContext` was created for box that did not establish a containing block for absolutes. It's possible that this way of dealing with hoisted absolutes is a bit less efficient, but, the number of these descendants is typically quite small, so it should not be significant. In addition, this decreases the size in memory of all `PositioningContexts` which are created in more situations as time goes on. Testing: There is a new WPT test with this change. Fixes: #36696. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
e25e63b587
commit
9bc16482a3
12 changed files with 203 additions and 323 deletions
|
@ -331,7 +331,7 @@ impl LineItemLayout<'_, '_> {
|
|||
self.calculate_inline_box_block_start(inline_box_state, space_above_baseline);
|
||||
|
||||
let positioning_context_or_start_offset_in_parent =
|
||||
match inline_box.base.new_positioning_context() {
|
||||
match PositioningContext::new_for_layout_box_base(&inline_box.base) {
|
||||
Some(positioning_context) => Either::Left(positioning_context),
|
||||
None => Either::Right(self.current_positioning_context_mut().len()),
|
||||
};
|
||||
|
|
|
@ -2004,9 +2004,7 @@ impl IndependentFormattingContext {
|
|||
bidi_level: Level,
|
||||
) {
|
||||
// We need to know the inline size of the atomic before deciding whether to do the line break.
|
||||
let mut child_positioning_context = self
|
||||
.new_positioning_context()
|
||||
.unwrap_or_else(|| PositioningContext::new_for_subtree(true));
|
||||
let mut child_positioning_context = PositioningContext::default();
|
||||
let IndependentFloatOrAtomicLayoutResult {
|
||||
mut fragment,
|
||||
baselines,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue