Make AbsolutelyPositionedBox be 'static

This commit is contained in:
Anthony Ramine 2020-03-13 12:22:32 +01:00 committed by Patrick Walton
parent 7ade924683
commit c3932185ec
7 changed files with 42 additions and 48 deletions

View file

@ -525,7 +525,7 @@ where
kind, kind,
}); });
} else { } else {
let box_ = Arc::new(InlineLevelBox::OutOfFlowAbsolutelyPositionedBox( let box_ = Arc::new(InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(Arc::new(
AbsolutelyPositionedBox::construct( AbsolutelyPositionedBox::construct(
self.context, self.context,
node, node,
@ -533,7 +533,7 @@ where
display_inside, display_inside,
contents, contents,
), ),
)); )));
self.current_inline_level_boxes().push(box_.clone()); self.current_inline_level_boxes().push(box_.clone());
box_slot.set(LayoutBox::InlineLevel(box_)) box_slot.set(LayoutBox::InlineLevel(box_))
} }
@ -687,13 +687,13 @@ where
contents, contents,
} => { } => {
let block_level_box = Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox( let block_level_box = Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
AbsolutelyPositionedBox::construct( Arc::new(AbsolutelyPositionedBox::construct(
context, context,
node, node,
style, style,
display_inside, display_inside,
contents, contents,
), )),
)); ));
(block_level_box, ContainsFloats::No) (block_level_box, ContainsFloats::No)
}, },

View file

@ -34,7 +34,7 @@ pub(crate) struct InlineFormattingContext {
pub(crate) enum InlineLevelBox { pub(crate) enum InlineLevelBox {
InlineBox(InlineBox), InlineBox(InlineBox),
TextRun(TextRun), TextRun(TextRun),
OutOfFlowAbsolutelyPositionedBox(AbsolutelyPositionedBox), OutOfFlowAbsolutelyPositionedBox(Arc<AbsolutelyPositionedBox>),
OutOfFlowFloatBox(FloatBox), OutOfFlowFloatBox(FloatBox),
Atomic(IndependentFormattingContext), Atomic(IndependentFormattingContext),
} }
@ -77,7 +77,7 @@ struct PartialInlineBoxFragment<'box_tree> {
} }
struct InlineFormattingContextState<'box_tree, 'a, 'b> { struct InlineFormattingContextState<'box_tree, 'a, 'b> {
positioning_context: &'a mut PositioningContext<'box_tree>, positioning_context: &'a mut PositioningContext,
containing_block: &'b ContainingBlock<'b>, containing_block: &'b ContainingBlock<'b>,
lines: Lines, lines: Lines,
inline_position: Length, inline_position: Length,
@ -204,10 +204,10 @@ impl InlineFormattingContext {
computation.paragraph computation.paragraph
} }
pub(super) fn layout<'a>( pub(super) fn layout(
&'a self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
) -> FlowLayout { ) -> FlowLayout {

View file

@ -50,7 +50,7 @@ pub(crate) enum BlockLevelBox {
style: Arc<ComputedValues>, style: Arc<ComputedValues>,
contents: BlockContainer, contents: BlockContainer,
}, },
OutOfFlowAbsolutelyPositionedBox(AbsolutelyPositionedBox), OutOfFlowAbsolutelyPositionedBox(Arc<AbsolutelyPositionedBox>),
OutOfFlowFloatBox(FloatBox), OutOfFlowFloatBox(FloatBox),
Independent(IndependentFormattingContext), Independent(IndependentFormattingContext),
} }
@ -65,10 +65,10 @@ struct FlowLayout {
struct CollapsibleWithParentStartMargin(bool); struct CollapsibleWithParentStartMargin(bool);
impl BlockFormattingContext { impl BlockFormattingContext {
pub(super) fn layout<'a>( pub(super) fn layout(
&'a self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
) -> IndependentLayout { ) -> IndependentLayout {
@ -101,10 +101,10 @@ impl BlockFormattingContext {
} }
impl BlockContainer { impl BlockContainer {
fn layout<'a>( fn layout(
&'a self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
float_context: Option<&mut FloatContext>, float_context: Option<&mut FloatContext>,
@ -130,10 +130,10 @@ impl BlockContainer {
} }
} }
fn layout_block_level_children<'a>( fn layout_block_level_children(
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
child_boxes: &'a [Arc<BlockLevelBox>], child_boxes: &[Arc<BlockLevelBox>],
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
mut float_context: Option<&mut FloatContext>, mut float_context: Option<&mut FloatContext>,
@ -256,10 +256,10 @@ fn layout_block_level_children<'a>(
} }
impl BlockLevelBox { impl BlockLevelBox {
fn layout<'a>( fn layout(
&'a self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
float_context: Option<&mut FloatContext>, float_context: Option<&mut FloatContext>,
@ -338,13 +338,13 @@ enum NonReplacedContents<'a> {
/// https://drafts.csswg.org/css2/visudet.html#blockwidth /// https://drafts.csswg.org/css2/visudet.html#blockwidth
/// https://drafts.csswg.org/css2/visudet.html#normal-block /// https://drafts.csswg.org/css2/visudet.html#normal-block
fn layout_in_flow_non_replaced_block_level<'a>( fn layout_in_flow_non_replaced_block_level(
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tag: OpaqueNode, tag: OpaqueNode,
style: &Arc<ComputedValues>, style: &Arc<ComputedValues>,
block_level_kind: NonReplacedContents<'a>, block_level_kind: NonReplacedContents,
tree_rank: usize, tree_rank: usize,
float_context: Option<&mut FloatContext>, float_context: Option<&mut FloatContext>,
) -> BoxFragment { ) -> BoxFragment {

View file

@ -84,13 +84,13 @@ fn construct_for_root_element<'dom>(
( (
ContainsFloats::No, ContainsFloats::No,
vec![Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox( vec![Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
AbsolutelyPositionedBox::construct( Arc::new(AbsolutelyPositionedBox::construct(
context, context,
root_element, root_element,
style, style,
display_inside, display_inside,
contents, contents,
), )),
))], ))],
) )
} else if box_style.float.is_floating() { } else if box_style.float.is_floating() {

View file

@ -104,11 +104,11 @@ impl IndependentFormattingContext {
} }
} }
impl<'a> NonReplacedIFC<'a> { impl NonReplacedIFC<'_> {
pub fn layout( pub fn layout(
&self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
positioning_context: &mut PositioningContext<'a>, positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
tree_rank: usize, tree_rank: usize,
) -> IndependentLayout { ) -> IndependentLayout {

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(arbitrary_self_types)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#[macro_use] #[macro_use]

View file

@ -36,19 +36,18 @@ pub(crate) struct AbsolutelyPositionedBox {
pub contents: IndependentFormattingContext, pub contents: IndependentFormattingContext,
} }
pub(crate) struct PositioningContext<'box_tree> { pub(crate) struct PositioningContext {
for_nearest_positioned_ancestor: Option<Vec<HoistedAbsolutelyPositionedBox<'box_tree>>>, for_nearest_positioned_ancestor: Option<Vec<HoistedAbsolutelyPositionedBox>>,
// For nearest `containing block for all descendants` as defined by the CSS transforms // For nearest `containing block for all descendants` as defined by the CSS transforms
// spec. // spec.
// https://www.w3.org/TR/css-transforms-1/#containing-block-for-all-descendants // https://www.w3.org/TR/css-transforms-1/#containing-block-for-all-descendants
for_nearest_containing_block_for_all_descendants: for_nearest_containing_block_for_all_descendants: Vec<HoistedAbsolutelyPositionedBox>,
Vec<HoistedAbsolutelyPositionedBox<'box_tree>>,
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct HoistedAbsolutelyPositionedBox<'box_tree> { pub(crate) struct HoistedAbsolutelyPositionedBox {
absolutely_positioned_box: &'box_tree AbsolutelyPositionedBox, absolutely_positioned_box: Arc<AbsolutelyPositionedBox>,
/// The rank of the child from which this absolutely positioned fragment /// The rank of the child from which this absolutely positioned fragment
/// came from, when doing the layout of a block container. Used to compute /// came from, when doing the layout of a block container. Used to compute
@ -110,7 +109,7 @@ impl AbsolutelyPositionedBox {
} }
pub(crate) fn to_hoisted( pub(crate) fn to_hoisted(
&self, self: Arc<Self>,
initial_start_corner: Vec2<Length>, initial_start_corner: Vec2<Length>,
tree_rank: usize, tree_rank: usize,
) -> HoistedAbsolutelyPositionedBox { ) -> HoistedAbsolutelyPositionedBox {
@ -150,7 +149,7 @@ impl AbsolutelyPositionedBox {
} }
} }
impl<'box_tree> PositioningContext<'box_tree> { impl PositioningContext {
pub(crate) fn new_for_containing_block_for_all_descendants() -> Self { pub(crate) fn new_for_containing_block_for_all_descendants() -> Self {
Self { Self {
for_nearest_positioned_ancestor: None, for_nearest_positioned_ancestor: None,
@ -220,9 +219,7 @@ impl<'box_tree> PositioningContext<'box_tree> {
fn create_and_layout_positioned( fn create_and_layout_positioned(
layout_context: &LayoutContext, layout_context: &LayoutContext,
style: &ComputedValues, style: &ComputedValues,
for_nearest_containing_block_for_all_descendants: &mut Vec< for_nearest_containing_block_for_all_descendants: &mut Vec<HoistedAbsolutelyPositionedBox>,
HoistedAbsolutelyPositionedBox<'box_tree>,
>,
fragment_layout_fn: impl FnOnce(&mut Self) -> BoxFragment, fragment_layout_fn: impl FnOnce(&mut Self) -> BoxFragment,
) -> BoxFragment { ) -> BoxFragment {
if style.establishes_containing_block_for_all_descendants() { if style.establishes_containing_block_for_all_descendants() {
@ -296,7 +293,7 @@ impl<'box_tree> PositioningContext<'box_tree> {
new_fragment new_fragment
} }
pub(crate) fn push(&mut self, box_: HoistedAbsolutelyPositionedBox<'box_tree>) { pub(crate) fn push(&mut self, box_: HoistedAbsolutelyPositionedBox) {
if let Some(nearest) = &mut self.for_nearest_positioned_ancestor { if let Some(nearest) = &mut self.for_nearest_positioned_ancestor {
match box_ match box_
.absolutely_positioned_box .absolutely_positioned_box
@ -412,14 +409,12 @@ impl<'box_tree> PositioningContext<'box_tree> {
} }
} }
impl<'box_tree> HoistedAbsolutelyPositionedBox<'box_tree> { impl HoistedAbsolutelyPositionedBox {
pub(crate) fn layout_many( pub(crate) fn layout_many(
layout_context: &LayoutContext, layout_context: &LayoutContext,
boxes: &[Self], boxes: &[Self],
fragments: &mut Vec<Fragment>, fragments: &mut Vec<Fragment>,
for_nearest_containing_block_for_all_descendants: &mut Vec< for_nearest_containing_block_for_all_descendants: &mut Vec<HoistedAbsolutelyPositionedBox>,
HoistedAbsolutelyPositionedBox<'box_tree>,
>,
containing_block: &DefiniteContainingBlock, containing_block: &DefiniteContainingBlock,
) { ) {
if layout_context.use_rayon { if layout_context.use_rayon {
@ -449,9 +444,7 @@ impl<'box_tree> HoistedAbsolutelyPositionedBox<'box_tree> {
pub(crate) fn layout( pub(crate) fn layout(
&self, &self,
layout_context: &LayoutContext, layout_context: &LayoutContext,
for_nearest_containing_block_for_all_descendants: &mut Vec< for_nearest_containing_block_for_all_descendants: &mut Vec<HoistedAbsolutelyPositionedBox>,
HoistedAbsolutelyPositionedBox<'box_tree>,
>,
containing_block: &DefiniteContainingBlock, containing_block: &DefiniteContainingBlock,
) -> BoxFragment { ) -> BoxFragment {
let style = &self.absolutely_positioned_box.contents.style; let style = &self.absolutely_positioned_box.contents.style;