Create HoistedSharedFragment

This commit is contained in:
Manish Goregaokar 2020-07-24 15:08:25 -07:00
parent 96c0c50874
commit d476a10773
3 changed files with 23 additions and 8 deletions

View file

@ -916,7 +916,7 @@ impl AbsoluteOrFixedPositionedFragment {
stacking_context: &mut StackingContext, stacking_context: &mut StackingContext,
) { ) {
let hoisted_fragment = self.hoisted_fragment.borrow(); let hoisted_fragment = self.hoisted_fragment.borrow();
let fragment_ref = match hoisted_fragment.as_ref() { let fragment_ref = match hoisted_fragment.fragment.as_ref() {
Some(fragment_ref) => fragment_ref, Some(fragment_ref) => fragment_ref,
None => unreachable!("Found hoisted box with missing fragment."), None => unreachable!("Found hoisted box with missing fragment."),
}; };

View file

@ -8,6 +8,7 @@ use crate::geom::flow_relative::{Rect, Sides};
use crate::geom::{PhysicalPoint, PhysicalRect}; use crate::geom::{PhysicalPoint, PhysicalRect};
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use crate::layout_debug; use crate::layout_debug;
use crate::positioned::HoistedSharedFragment;
use gfx::font::FontMetrics as GfxFontMetrics; use gfx::font::FontMetrics as GfxFontMetrics;
use gfx::text::glyph::GlyphStore; use gfx::text::glyph::GlyphStore;
use gfx_traits::print_tree::PrintTree; use gfx_traits::print_tree::PrintTree;
@ -74,7 +75,7 @@ pub(crate) enum Fragment {
#[derive(Serialize)] #[derive(Serialize)]
pub(crate) struct AbsoluteOrFixedPositionedFragment { pub(crate) struct AbsoluteOrFixedPositionedFragment {
pub position: ComputedPosition, pub position: ComputedPosition,
pub hoisted_fragment: ArcRefCell<Option<ArcRefCell<Fragment>>>, pub hoisted_fragment: ArcRefCell<HoistedSharedFragment>,
} }
#[derive(Serialize)] #[derive(Serialize)]

View file

@ -46,7 +46,21 @@ pub(crate) struct HoistedAbsolutelyPositionedBox {
/// A reference to a Fragment which is shared between this `HoistedAbsolutelyPositionedBox` /// A reference to a Fragment which is shared between this `HoistedAbsolutelyPositionedBox`
/// and its placeholder `AbsoluteOrFixedPositionedFragment` in the original tree position. /// and its placeholder `AbsoluteOrFixedPositionedFragment` in the original tree position.
/// This will be used later in order to paint this hoisted box in tree order. /// This will be used later in order to paint this hoisted box in tree order.
pub fragment: ArcRefCell<Option<ArcRefCell<Fragment>>>, pub fragment: ArcRefCell<HoistedSharedFragment>,
}
/// A reference to a Fragment which is shared between `HoistedAbsolutelyPositionedBox`
/// and its placeholder `AbsoluteOrFixedPositionedFragment` in the original tree position.
/// This will be used later in order to paint this hoisted box in tree order.
#[derive(Serialize)]
pub(crate) struct HoistedSharedFragment {
pub fragment: Option<ArcRefCell<Fragment>>,
}
impl HoistedSharedFragment {
pub(crate) fn new() -> Self {
HoistedSharedFragment { fragment: None }
}
} }
impl HoistedAbsolutelyPositionedBox { impl HoistedAbsolutelyPositionedBox {
@ -79,8 +93,8 @@ pub(crate) enum AbsoluteBoxOffsets {
impl AbsoluteBoxOffsets { impl AbsoluteBoxOffsets {
fn adjust_offset(&mut self, new_offset: Length) { fn adjust_offset(&mut self, new_offset: Length) {
match *self { match *self {
AbsoluteBoxOffsets::StaticStart {ref mut start} => *start = new_offset, AbsoluteBoxOffsets::StaticStart { ref mut start } => *start = new_offset,
_ => () _ => (),
} }
} }
} }
@ -149,7 +163,7 @@ impl AbsolutelyPositionedBox {
HoistedAbsolutelyPositionedBox { HoistedAbsolutelyPositionedBox {
tree_rank, tree_rank,
box_offsets, box_offsets,
fragment: ArcRefCell::new(None), fragment: ArcRefCell::new(HoistedSharedFragment::new()),
absolutely_positioned_box: self_, absolutely_positioned_box: self_,
} }
} }
@ -376,7 +390,7 @@ impl HoistedAbsolutelyPositionedBox {
containing_block, containing_block,
))); )));
*box_.fragment.borrow_mut() = Some(new_fragment.clone()); box_.fragment.borrow_mut().fragment = Some(new_fragment.clone());
new_fragment new_fragment
}, },
Vec::new, Vec::new,
@ -389,7 +403,7 @@ impl HoistedAbsolutelyPositionedBox {
for_nearest_containing_block_for_all_descendants, for_nearest_containing_block_for_all_descendants,
containing_block, containing_block,
))); )));
*box_.fragment.borrow_mut() = Some(new_fragment.clone()); box_.fragment.borrow_mut().fragment = Some(new_fragment.clone());
new_fragment new_fragment
})) }))
} }