mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Make adjust_static_positions a method of PositioningContext
This commit is contained in:
parent
b43a3de51d
commit
9edda952c9
2 changed files with 55 additions and 46 deletions
|
@ -11,7 +11,6 @@ use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout
|
||||||
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment};
|
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment};
|
||||||
use crate::fragments::{CollapsedBlockMargins, CollapsedMargin};
|
use crate::fragments::{CollapsedBlockMargins, CollapsedMargin};
|
||||||
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
||||||
use crate::positioned::adjust_static_positions;
|
|
||||||
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext};
|
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext};
|
||||||
use crate::replaced::ReplacedContent;
|
use crate::replaced::ReplacedContent;
|
||||||
use crate::style_ext::ComputedValuesExt;
|
use crate::style_ext::ComputedValuesExt;
|
||||||
|
@ -194,7 +193,6 @@ fn layout_block_level_children<'a>(
|
||||||
current_block_direction_position: Length,
|
current_block_direction_position: Length,
|
||||||
}
|
}
|
||||||
|
|
||||||
let abspos_so_far = positioning_context.abspos.len();
|
|
||||||
let mut placement_state = PlacementState {
|
let mut placement_state = PlacementState {
|
||||||
next_in_flow_margin_collapses_with_parent_start_margin:
|
next_in_flow_margin_collapses_with_parent_start_margin:
|
||||||
collapsible_with_parent_start_margin.0,
|
collapsible_with_parent_start_margin.0,
|
||||||
|
@ -202,54 +200,50 @@ fn layout_block_level_children<'a>(
|
||||||
current_margin: CollapsedMargin::zero(),
|
current_margin: CollapsedMargin::zero(),
|
||||||
current_block_direction_position: Length::zero(),
|
current_block_direction_position: Length::zero(),
|
||||||
};
|
};
|
||||||
let mut fragments: Vec<_>;
|
let fragments = positioning_context.adjust_static_positions(tree_rank, |positioning_context| {
|
||||||
if float_context.is_some() || !layout_context.use_rayon {
|
if float_context.is_some() || !layout_context.use_rayon {
|
||||||
// Because floats are involved, we do layout for this block formatting context
|
// Because floats are involved, we do layout for this block formatting context
|
||||||
// in tree order without parallelism. This enables mutable access
|
// in tree order without parallelism. This enables mutable access
|
||||||
// to a `FloatContext` that tracks every float encountered so far (again in tree order).
|
// to a `FloatContext` that tracks every float encountered so far (again in tree order).
|
||||||
fragments = child_boxes
|
child_boxes
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(tree_rank, box_)| {
|
.map(|(tree_rank, box_)| {
|
||||||
let mut fragment = box_.layout(
|
let mut fragment = box_.layout(
|
||||||
layout_context,
|
|
||||||
positioning_context,
|
|
||||||
containing_block,
|
|
||||||
tree_rank,
|
|
||||||
float_context.as_mut().map(|c| &mut **c),
|
|
||||||
);
|
|
||||||
place_block_level_fragment(&mut fragment, &mut placement_state);
|
|
||||||
fragment
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
fragments = child_boxes
|
|
||||||
.par_iter()
|
|
||||||
.enumerate()
|
|
||||||
.mapfold_reduce_into(
|
|
||||||
positioning_context,
|
|
||||||
|positioning_context, (tree_rank, box_)| {
|
|
||||||
box_.layout(
|
|
||||||
layout_context,
|
layout_context,
|
||||||
positioning_context,
|
positioning_context,
|
||||||
containing_block,
|
containing_block,
|
||||||
tree_rank,
|
tree_rank,
|
||||||
/* float_context = */ None,
|
float_context.as_mut().map(|c| &mut **c),
|
||||||
)
|
);
|
||||||
},
|
place_block_level_fragment(&mut fragment, &mut placement_state);
|
||||||
|left, right| left.append(right),
|
fragment
|
||||||
)
|
})
|
||||||
.collect();
|
.collect()
|
||||||
for fragment in &mut fragments {
|
} else {
|
||||||
place_block_level_fragment(fragment, &mut placement_state)
|
let mut fragments = child_boxes
|
||||||
|
.par_iter()
|
||||||
|
.enumerate()
|
||||||
|
.mapfold_reduce_into(
|
||||||
|
positioning_context,
|
||||||
|
|positioning_context, (tree_rank, box_)| {
|
||||||
|
box_.layout(
|
||||||
|
layout_context,
|
||||||
|
positioning_context,
|
||||||
|
containing_block,
|
||||||
|
tree_rank,
|
||||||
|
/* float_context = */ None,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|left, right| left.append(right),
|
||||||
|
)
|
||||||
|
.collect();
|
||||||
|
for fragment in &mut fragments {
|
||||||
|
place_block_level_fragment(fragment, &mut placement_state)
|
||||||
|
}
|
||||||
|
fragments
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
adjust_static_positions(
|
|
||||||
&mut positioning_context.abspos[abspos_so_far..],
|
|
||||||
&mut fragments,
|
|
||||||
tree_rank,
|
|
||||||
);
|
|
||||||
|
|
||||||
FlowLayout {
|
FlowLayout {
|
||||||
fragments,
|
fragments,
|
||||||
|
|
|
@ -133,6 +133,21 @@ impl PositioningContext<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn adjust_static_positions(
|
||||||
|
&mut self,
|
||||||
|
tree_rank_in_parent: usize,
|
||||||
|
f: impl FnOnce(&mut Self) -> Vec<Fragment>,
|
||||||
|
) -> Vec<Fragment> {
|
||||||
|
let abspos_so_far = self.abspos.len();
|
||||||
|
let fragments = f(self);
|
||||||
|
adjust_static_positions(
|
||||||
|
&mut self.abspos[abspos_so_far..],
|
||||||
|
&fragments,
|
||||||
|
tree_rank_in_parent,
|
||||||
|
);
|
||||||
|
fragments
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn layout_abspos(
|
pub(crate) fn layout_abspos(
|
||||||
self,
|
self,
|
||||||
layout_context: &LayoutContext,
|
layout_context: &LayoutContext,
|
||||||
|
@ -430,7 +445,7 @@ fn solve_axis(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn adjust_static_positions(
|
fn adjust_static_positions(
|
||||||
absolutely_positioned_fragments: &mut [CollectedAbsolutelyPositionedBox],
|
absolutely_positioned_fragments: &mut [CollectedAbsolutelyPositionedBox],
|
||||||
child_fragments: &[Fragment],
|
child_fragments: &[Fragment],
|
||||||
tree_rank_in_parent: usize,
|
tree_rank_in_parent: usize,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue