From 96c0c508743344d40139d4aa049a3b2d6f67ee3c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 24 Jul 2020 10:39:15 -0700 Subject: [PATCH] Allow adjusting box offsets --- components/layout_2020/flow/mod.rs | 3 +++ components/layout_2020/positioned.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index b5898fc6146..cb1e410871f 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -352,6 +352,9 @@ impl BlockLevelBox { BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => { let hoisted_box = AbsolutelyPositionedBox::to_hoisted( box_.clone(), + // This is incorrect, however we do not know the + // correct positioning until later, in place_block_level_fragment, + // and this value will be adjusted there Vec2::zero(), tree_rank, containing_block, diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index 853b22347e9..eb455eb4990 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -49,6 +49,16 @@ pub(crate) struct HoistedAbsolutelyPositionedBox { pub fragment: ArcRefCell>>, } +impl HoistedAbsolutelyPositionedBox { + /// In some cases `inset: auto`-positioned elements do not know their precise + /// position until after they're hoisted. This lets us adjust auto values + /// after the fact. + pub(crate) fn adjust_offsets(&mut self, offsets: Vec2) { + self.box_offsets.inline.adjust_offset(offsets.inline); + self.box_offsets.block.adjust_offset(offsets.block); + } +} + #[derive(Clone, Debug)] pub(crate) enum AbsoluteBoxOffsets { StaticStart { @@ -66,6 +76,15 @@ pub(crate) enum AbsoluteBoxOffsets { }, } +impl AbsoluteBoxOffsets { + fn adjust_offset(&mut self, new_offset: Length) { + match *self { + AbsoluteBoxOffsets::StaticStart {ref mut start} => *start = new_offset, + _ => () + } + } +} + impl AbsolutelyPositionedBox { pub fn construct<'dom>( context: &LayoutContext,