Allow adjusting box offsets

This commit is contained in:
Manish Goregaokar 2020-07-24 10:39:15 -07:00
parent fc71345114
commit 96c0c50874
2 changed files with 22 additions and 0 deletions

View file

@ -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,

View file

@ -49,6 +49,16 @@ pub(crate) struct HoistedAbsolutelyPositionedBox {
pub fragment: ArcRefCell<Option<ArcRefCell<Fragment>>>,
}
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<Length>) {
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,