Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout `position: fixed` in the initial containing block #25273

Merged
merged 13 commits into from Dec 13, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Make adjust_static_positions a method of PositioningContext

  • Loading branch information
SimonSapin committed Dec 12, 2019
commit 9edda952c9b2c19337e4096b989fcc047c59ea18
@@ -11,7 +11,6 @@ use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment};
use crate::fragments::{CollapsedBlockMargins, CollapsedMargin};
use crate::geom::flow_relative::{Rect, Sides, Vec2};
use crate::positioned::adjust_static_positions;
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext};
use crate::replaced::ReplacedContent;
use crate::style_ext::ComputedValuesExt;
@@ -194,62 +193,57 @@ fn layout_block_level_children<'a>(
current_block_direction_position: Length,
}

let abspos_so_far = positioning_context.abspos.len();
let mut placement_state = PlacementState {
next_in_flow_margin_collapses_with_parent_start_margin:
collapsible_with_parent_start_margin.0,
start_margin: CollapsedMargin::zero(),
current_margin: CollapsedMargin::zero(),
current_block_direction_position: Length::zero(),
};
let mut fragments: Vec<_>;
if float_context.is_some() || !layout_context.use_rayon {
// Because floats are involved, we do layout for this block formatting context
// in tree order without parallelism. This enables mutable access
// to a `FloatContext` that tracks every float encountered so far (again in tree order).
fragments = child_boxes
.iter()
.enumerate()
.map(|(tree_rank, box_)| {
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(
let fragments = positioning_context.adjust_static_positions(tree_rank, |positioning_context| {
if float_context.is_some() || !layout_context.use_rayon {
// Because floats are involved, we do layout for this block formatting context
// in tree order without parallelism. This enables mutable access
// to a `FloatContext` that tracks every float encountered so far (again in tree order).
child_boxes
.iter()
.enumerate()
.map(|(tree_rank, box_)| {
let mut fragment = 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)
float_context.as_mut().map(|c| &mut **c),
);
place_block_level_fragment(&mut fragment, &mut placement_state);
fragment
})
.collect()
} else {
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 {
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(
self,
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],
child_fragments: &[Fragment],
tree_rank_in_parent: usize,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.