impl From<&'_ DefiniteContainingBlock> for ContainingBlock

This commit is contained in:
Simon Sapin 2019-12-07 23:40:36 +01:00
parent 14ddf39215
commit f09c14aa6b
2 changed files with 19 additions and 15 deletions

View file

@ -16,12 +16,12 @@ use crate::positioned::AbsolutelyPositionedBox;
use crate::replaced::ReplacedContent; use crate::replaced::ReplacedContent;
use crate::sizing::ContentSizesRequest; use crate::sizing::ContentSizesRequest;
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside}; use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside};
use crate::{ContainingBlock, DefiniteContainingBlock}; use crate::DefiniteContainingBlock;
use rayon::iter::{IntoParallelRefIterator, ParallelExtend, ParallelIterator}; use rayon::iter::{IntoParallelRefIterator, ParallelExtend, ParallelIterator};
use script_layout_interface::wrapper_traits::LayoutNode; use script_layout_interface::wrapper_traits::LayoutNode;
use servo_arc::Arc; use servo_arc::Arc;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::{Length, LengthOrAuto}; use style::values::computed::Length;
use style::Zero; use style::Zero;
use style_traits::CSSPixel; use style_traits::CSSPixel;
@ -99,31 +99,25 @@ impl BoxTreeRoot {
viewport: geom::Size<CSSPixel>, viewport: geom::Size<CSSPixel>,
) -> FragmentTreeRoot { ) -> FragmentTreeRoot {
let style = ComputedValues::initial_values(); let style = ComputedValues::initial_values();
let initial_containing_block_size = Vec2 { let initial_containing_block = DefiniteContainingBlock {
size: Vec2 {
inline: Length::new(viewport.width), inline: Length::new(viewport.width),
block: Length::new(viewport.height), block: Length::new(viewport.height),
}; },
let initial_containing_block = ContainingBlock {
inline_size: initial_containing_block_size.inline,
block_size: LengthOrAuto::LengthPercentage(initial_containing_block_size.block),
// FIXME: use the documents mode: // FIXME: use the documents mode:
// https://drafts.csswg.org/css-writing-modes/#principal-flow // https://drafts.csswg.org/css-writing-modes/#principal-flow
style, style,
}; };
let dummy_tree_rank = 0; let dummy_tree_rank = 0;
let mut absolutely_positioned_fragments = vec![]; let mut absolutely_positioned_fragments = vec![];
let mut independent_layout = self.0.layout( let mut independent_layout = self.0.layout(
layout_context, layout_context,
&initial_containing_block, &(&initial_containing_block).into(),
dummy_tree_rank, dummy_tree_rank,
&mut absolutely_positioned_fragments, &mut absolutely_positioned_fragments,
); );
let initial_containing_block = DefiniteContainingBlock {
size: initial_containing_block_size,
style,
};
independent_layout.fragments.par_extend( independent_layout.fragments.par_extend(
absolutely_positioned_fragments absolutely_positioned_fragments
.par_iter() .par_iter()

View file

@ -44,6 +44,16 @@ struct DefiniteContainingBlock<'a> {
style: &'a ComputedValues, style: &'a ComputedValues,
} }
impl<'a> From<&'_ DefiniteContainingBlock<'a>> for ContainingBlock<'a> {
fn from(definite: &DefiniteContainingBlock<'a>) -> Self {
ContainingBlock {
inline_size: definite.size.inline,
block_size: LengthOrAuto::LengthPercentage(definite.size.block),
style: definite.style,
}
}
}
/// https://drafts.csswg.org/css2/visuren.html#relative-positioning /// https://drafts.csswg.org/css2/visuren.html#relative-positioning
fn relative_adjustement( fn relative_adjustement(
style: &ComputedValues, style: &ComputedValues,