From fa1adf2ad31206a3dcade6015569c1266fd95ecd Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 7 Dec 2019 13:40:57 +0100 Subject: [PATCH] Containing blocks contains styles rather than just a writing mode --- components/layout_2020/flow/inline.rs | 9 +++++---- components/layout_2020/flow/mod.rs | 14 +++++++++----- components/layout_2020/flow/root.rs | 7 ++++--- components/layout_2020/geom.rs | 3 ++- components/layout_2020/lib.rs | 9 ++++----- components/layout_2020/positioned.rs | 14 +++++++------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index 5b73737d151..3c763fbe390 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -69,7 +69,7 @@ struct PartialInlineBoxFragment<'box_tree> { struct InlineFormattingContextState<'box_tree, 'a> { absolutely_positioned_fragments: &'a mut Vec>, - containing_block: &'a ContainingBlock, + containing_block: &'a ContainingBlock<'a>, line_boxes: LinesBoxes, inline_position: Length, partial_inline_boxes_stack: Vec>, @@ -292,7 +292,7 @@ impl LinesBoxes { self.boxes.push(Fragment::Anonymous(AnonymousFragment { children: std::mem::take(&mut top_nesting_level.fragments_so_far), rect: Rect { start_corner, size }, - mode: containing_block.mode, + mode: containing_block.style.writing_mode, })) } } @@ -446,10 +446,11 @@ fn layout_atomic<'box_tree>( let containing_block_for_children = ContainingBlock { inline_size, block_size, - mode: atomic.style.writing_mode, + style: &atomic.style, }; assert_eq!( - ifc.containing_block.mode, containing_block_for_children.mode, + ifc.containing_block.style.writing_mode, + containing_block_for_children.style.writing_mode, "Mixed writing modes are not supported yet" ); // FIXME is this correct? diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs index aafaf1eb0fa..7138ffe3eb0 100644 --- a/components/layout_2020/flow/mod.rs +++ b/components/layout_2020/flow/mod.rs @@ -324,11 +324,15 @@ impl BlockLevelBox { }, BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(box_) => { absolutely_positioned_fragments.push(box_.layout(Vec2::zero(), tree_rank)); - Fragment::Anonymous(AnonymousFragment::no_op(containing_block.mode)) + Fragment::Anonymous(AnonymousFragment::no_op( + containing_block.style.writing_mode, + )) }, BlockLevelBox::OutOfFlowFloatBox(_box_) => { // TODO - Fragment::Anonymous(AnonymousFragment::no_op(containing_block.mode)) + Fragment::Anonymous(AnonymousFragment::no_op( + containing_block.style.writing_mode, + )) }, } } @@ -413,11 +417,11 @@ fn layout_in_flow_non_replaced_block_level<'a>( let containing_block_for_children = ContainingBlock { inline_size, block_size, - mode: style.writing_mode, + style, }; // https://drafts.csswg.org/css-writing-modes/#orthogonal-flows assert_eq!( - containing_block.mode, containing_block_for_children.mode, + containing_block.style.writing_mode, containing_block_for_children.style.writing_mode, "Mixed writing modes are not supported yet" ); @@ -494,7 +498,7 @@ fn layout_in_flow_non_replaced_block_level<'a>( &mut flow_layout.fragments, &content_rect.size, &padding, - containing_block_for_children.mode, + style, ) } BoxFragment { diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index 882a6b0f58d..f1c301771f9 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -20,7 +20,7 @@ use crate::{ContainingBlock, DefiniteContainingBlock}; use rayon::iter::{IntoParallelRefIterator, ParallelExtend, ParallelIterator}; use script_layout_interface::wrapper_traits::LayoutNode; use servo_arc::Arc; -use style::logical_geometry::WritingMode; +use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; use style::Zero; use style_traits::CSSPixel; @@ -98,6 +98,7 @@ impl BoxTreeRoot { layout_context: &LayoutContext, viewport: geom::Size, ) -> FragmentTreeRoot { + let style = ComputedValues::initial_values(); let initial_containing_block_size = Vec2 { inline: Length::new(viewport.width), block: Length::new(viewport.height), @@ -108,7 +109,7 @@ impl BoxTreeRoot { block_size: LengthOrAuto::LengthPercentage(initial_containing_block_size.block), // FIXME: use the document’s mode: // https://drafts.csswg.org/css-writing-modes/#principal-flow - mode: WritingMode::empty(), + style, }; let dummy_tree_rank = 0; let mut absolutely_positioned_fragments = vec![]; @@ -121,7 +122,7 @@ impl BoxTreeRoot { let initial_containing_block = DefiniteContainingBlock { size: initial_containing_block_size, - mode: initial_containing_block.mode, + style, }; independent_layout.fragments.par_extend( absolutely_positioned_fragments diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index 73cc8fef2a7..2eafb78051e 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -4,7 +4,8 @@ use std::fmt; use std::ops::{Add, AddAssign, Sub}; -use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection, PhysicalCorner, WritingMode}; +use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection}; +use style::logical_geometry::{PhysicalCorner, WritingMode}; use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto}; use style::Zero; use style_traits::CSSPixel; diff --git a/components/layout_2020/lib.rs b/components/layout_2020/lib.rs index 654c35f6941..f0c56afa6f1 100644 --- a/components/layout_2020/lib.rs +++ b/components/layout_2020/lib.rs @@ -29,20 +29,19 @@ pub use flow::{BoxTreeRoot, FragmentTreeRoot}; use crate::geom::flow_relative::Vec2; use crate::style_ext::ComputedValuesExt; use style::computed_values::position::T as Position; -use style::logical_geometry::WritingMode; use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto}; use style::Zero; -struct ContainingBlock { +struct ContainingBlock<'a> { inline_size: Length, block_size: LengthOrAuto, - mode: WritingMode, + style: &'a ComputedValues, } -struct DefiniteContainingBlock { +struct DefiniteContainingBlock<'a> { size: Vec2, - mode: WritingMode, + style: &'a ComputedValues, } /// https://drafts.csswg.org/css2/visuren.html#relative-positioning diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index 1748c9f8f3b..7aed850a5ca 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -12,7 +12,6 @@ use crate::style_ext::{ComputedValuesExt, DisplayInside}; use crate::{ContainingBlock, DefiniteContainingBlock}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use servo_arc::Arc; -use style::logical_geometry::WritingMode; use style::properties::ComputedValues; use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto}; use style::Zero; @@ -129,7 +128,7 @@ impl<'a> AbsolutelyPositionedFragment<'a> { fragments: &mut Vec, content_rect_size: &Vec2, padding: &Sides, - mode: WritingMode, + style: &ComputedValues, ) { if absolute.is_empty() { return; @@ -142,7 +141,7 @@ impl<'a> AbsolutelyPositionedFragment<'a> { .inflate(&padding); let containing_block = DefiniteContainingBlock { size: padding_rect.size.clone(), - mode, + style, }; fragments.push(Fragment::Anonymous(AnonymousFragment { children: absolute @@ -150,7 +149,7 @@ impl<'a> AbsolutelyPositionedFragment<'a> { .map(|a| a.layout(layout_context, &containing_block)) .collect(), rect: padding_rect, - mode, + mode: style.writing_mode, })) } @@ -325,11 +324,12 @@ impl<'a> AbsolutelyPositionedFragment<'a> { let containing_block_for_children = ContainingBlock { inline_size, block_size, - mode: style.writing_mode, + style, }; // https://drafts.csswg.org/css-writing-modes/#orthogonal-flows assert_eq!( - containing_block.mode, containing_block_for_children.mode, + containing_block.style.writing_mode, + containing_block_for_children.style.writing_mode, "Mixed writing modes are not supported yet" ); let dummy_tree_rank = 0; @@ -370,7 +370,7 @@ impl<'a> AbsolutelyPositionedFragment<'a> { &mut independent_layout.fragments, &content_rect.size, &padding, - style.writing_mode, + style, ); Fragment::Box(BoxFragment {