mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Add a request_content_sizes
parameter to IndependentFormattingContext::construct
This commit is contained in:
parent
2c124b9d0b
commit
cfdd23ac16
8 changed files with 101 additions and 52 deletions
|
@ -10,7 +10,7 @@ use crate::flow::inline::{InlineBox, InlineFormattingContext, InlineLevelBox, Te
|
||||||
use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
|
use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
|
||||||
use crate::formatting_contexts::IndependentFormattingContext;
|
use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
use crate::positioned::AbsolutelyPositionedBox;
|
use crate::positioned::AbsolutelyPositionedBox;
|
||||||
use crate::style_ext::{DisplayGeneratingBox, DisplayInside, DisplayOutside};
|
use crate::style_ext::{ComputedValuesExt, DisplayGeneratingBox, DisplayInside, DisplayOutside};
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
use rayon_croissant::ParallelIteratorExt;
|
use rayon_croissant::ParallelIteratorExt;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
|
@ -158,6 +158,7 @@ impl BlockContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut contains_floats = builder.contains_floats;
|
let mut contains_floats = builder.contains_floats;
|
||||||
|
let request_content_sizes = false; // FIXME
|
||||||
let container = BlockContainer::BlockLevelBoxes(
|
let container = BlockContainer::BlockLevelBoxes(
|
||||||
builder
|
builder
|
||||||
.block_level_boxes
|
.block_level_boxes
|
||||||
|
@ -165,7 +166,7 @@ impl BlockContainer {
|
||||||
.mapfold_reduce_into(
|
.mapfold_reduce_into(
|
||||||
&mut contains_floats,
|
&mut contains_floats,
|
||||||
|contains_floats, (intermediate, box_slot): (IntermediateBlockLevelBox<_>, BoxSlot<'_>)| {
|
|contains_floats, (intermediate, box_slot): (IntermediateBlockLevelBox<_>, BoxSlot<'_>)| {
|
||||||
let (block_level_box, box_contains_floats) = intermediate.finish(context);
|
let (block_level_box, box_contains_floats) = intermediate.finish(context, request_content_sizes);
|
||||||
*contains_floats |= box_contains_floats;
|
*contains_floats |= box_contains_floats;
|
||||||
box_slot.set(LayoutBox::BlockLevel(block_level_box.clone()));
|
box_slot.set(LayoutBox::BlockLevel(block_level_box.clone()));
|
||||||
block_level_box
|
block_level_box
|
||||||
|
@ -332,6 +333,7 @@ where
|
||||||
style.clone(),
|
style.clone(),
|
||||||
display_inside,
|
display_inside,
|
||||||
<Contents<Node>>::Replaced(replaced),
|
<Contents<Node>>::Replaced(replaced),
|
||||||
|
false, // ignored
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
Ok(non_replaced) => match display_inside {
|
Ok(non_replaced) => match display_inside {
|
||||||
|
@ -452,14 +454,7 @@ where
|
||||||
self.block_level_boxes.push((box_, box_slot));
|
self.block_level_boxes.push((box_, box_slot));
|
||||||
} else {
|
} else {
|
||||||
let box_ = Arc::new(InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
let box_ = Arc::new(InlineLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
||||||
AbsolutelyPositionedBox {
|
AbsolutelyPositionedBox::construct(self.context, style, display_inside, contents),
|
||||||
contents: IndependentFormattingContext::construct(
|
|
||||||
self.context,
|
|
||||||
style,
|
|
||||||
display_inside,
|
|
||||||
contents,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
self.current_inline_level_boxes().push(box_.clone());
|
self.current_inline_level_boxes().push(box_.clone());
|
||||||
box_slot.set(LayoutBox::InlineLevel(box_))
|
box_slot.set(LayoutBox::InlineLevel(box_))
|
||||||
|
@ -483,14 +478,12 @@ where
|
||||||
};
|
};
|
||||||
self.block_level_boxes.push((box_, box_slot));
|
self.block_level_boxes.push((box_, box_slot));
|
||||||
} else {
|
} else {
|
||||||
let box_ = Arc::new(InlineLevelBox::OutOfFlowFloatBox(FloatBox {
|
let box_ = Arc::new(InlineLevelBox::OutOfFlowFloatBox(FloatBox::construct(
|
||||||
contents: IndependentFormattingContext::construct(
|
self.context,
|
||||||
self.context,
|
style,
|
||||||
style,
|
display_inside,
|
||||||
display_inside,
|
contents,
|
||||||
contents,
|
)));
|
||||||
),
|
|
||||||
}));
|
|
||||||
self.current_inline_level_boxes().push(box_.clone());
|
self.current_inline_level_boxes().push(box_.clone());
|
||||||
box_slot.set(LayoutBox::InlineLevel(box_))
|
box_slot.set(LayoutBox::InlineLevel(box_))
|
||||||
}
|
}
|
||||||
|
@ -551,6 +544,7 @@ where
|
||||||
fn finish(
|
fn finish(
|
||||||
self,
|
self,
|
||||||
context: &LayoutContext,
|
context: &LayoutContext,
|
||||||
|
parent_requests_outer_content_sizes: bool,
|
||||||
) -> (Arc<BlockLevelBox>, ContainsFloats) {
|
) -> (Arc<BlockLevelBox>, ContainsFloats) {
|
||||||
match self {
|
match self {
|
||||||
IntermediateBlockLevelBox::SameFormattingContextBlock { style, contents } => {
|
IntermediateBlockLevelBox::SameFormattingContextBlock { style, contents } => {
|
||||||
|
@ -564,11 +558,14 @@ where
|
||||||
display_inside,
|
display_inside,
|
||||||
contents,
|
contents,
|
||||||
} => {
|
} => {
|
||||||
|
let request_content_sizes =
|
||||||
|
parent_requests_outer_content_sizes && style.inline_size_is_auto();
|
||||||
let contents = IndependentFormattingContext::construct(
|
let contents = IndependentFormattingContext::construct(
|
||||||
context,
|
context,
|
||||||
style,
|
style,
|
||||||
display_inside,
|
display_inside,
|
||||||
contents,
|
contents,
|
||||||
|
request_content_sizes,
|
||||||
);
|
);
|
||||||
(
|
(
|
||||||
Arc::new(BlockLevelBox::Independent(contents)),
|
Arc::new(BlockLevelBox::Independent(contents)),
|
||||||
|
@ -581,14 +578,7 @@ where
|
||||||
contents,
|
contents,
|
||||||
} => {
|
} => {
|
||||||
let block_level_box = Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
let block_level_box = Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
||||||
AbsolutelyPositionedBox {
|
AbsolutelyPositionedBox::construct(context, style, display_inside, contents),
|
||||||
contents: IndependentFormattingContext::construct(
|
|
||||||
context,
|
|
||||||
style,
|
|
||||||
display_inside,
|
|
||||||
contents,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
(block_level_box, ContainsFloats::No)
|
(block_level_box, ContainsFloats::No)
|
||||||
},
|
},
|
||||||
|
@ -597,14 +587,9 @@ where
|
||||||
display_inside,
|
display_inside,
|
||||||
contents,
|
contents,
|
||||||
} => {
|
} => {
|
||||||
let contents = IndependentFormattingContext::construct(
|
let block_level_box = Arc::new(BlockLevelBox::OutOfFlowFloatBox(
|
||||||
context,
|
FloatBox::construct(context, style, display_inside, contents),
|
||||||
style,
|
));
|
||||||
display_inside,
|
|
||||||
contents,
|
|
||||||
);
|
|
||||||
let block_level_box =
|
|
||||||
Arc::new(BlockLevelBox::OutOfFlowFloatBox(FloatBox { contents }));
|
|
||||||
(block_level_box, ContainsFloats::Yes)
|
(block_level_box, ContainsFloats::Yes)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::context::LayoutContext;
|
||||||
|
use crate::dom_traversal::{Contents, NodeExt};
|
||||||
use crate::formatting_contexts::IndependentFormattingContext;
|
use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
|
use crate::style_ext::{ComputedValuesExt, DisplayInside};
|
||||||
|
use servo_arc::Arc;
|
||||||
|
use style::properties::ComputedValues;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct FloatBox {
|
pub(crate) struct FloatBox {
|
||||||
|
@ -19,3 +24,23 @@ impl FloatContext {
|
||||||
FloatContext {}
|
FloatContext {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FloatBox {
|
||||||
|
pub fn construct<'dom>(
|
||||||
|
context: &LayoutContext,
|
||||||
|
style: Arc<ComputedValues>,
|
||||||
|
display_inside: DisplayInside,
|
||||||
|
contents: Contents<impl NodeExt<'dom>>,
|
||||||
|
) -> Self {
|
||||||
|
let request_content_sizes = style.inline_size_is_auto();
|
||||||
|
Self {
|
||||||
|
contents: IndependentFormattingContext::construct(
|
||||||
|
context,
|
||||||
|
style,
|
||||||
|
display_inside,
|
||||||
|
contents,
|
||||||
|
request_content_sizes,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
use crate::fragments::CollapsedBlockMargins;
|
use crate::fragments::CollapsedBlockMargins;
|
||||||
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment, TextFragment};
|
use crate::fragments::{AnonymousFragment, BoxFragment, Fragment, TextFragment};
|
||||||
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
||||||
use crate::sizing::{outer_inline_content_sizes, ContentSizes};
|
|
||||||
use crate::positioned::{AbsolutelyPositionedBox, AbsolutelyPositionedFragment};
|
use crate::positioned::{AbsolutelyPositionedBox, AbsolutelyPositionedFragment};
|
||||||
|
use crate::sizing::{outer_inline_content_sizes, ContentSizes};
|
||||||
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
|
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
|
||||||
use crate::{relative_adjustement, ContainingBlock};
|
use crate::{relative_adjustement, ContainingBlock};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
|
|
@ -59,32 +59,33 @@ fn construct_for_root_element<'dom>(
|
||||||
Display::GeneratingBox(DisplayGeneratingBox::OutsideInside { inside, .. }) => inside,
|
Display::GeneratingBox(DisplayGeneratingBox::OutsideInside { inside, .. }) => inside,
|
||||||
};
|
};
|
||||||
|
|
||||||
let position = box_style.position;
|
let contents = replaced.map_or(Contents::OfElement(root_element), Contents::Replaced);
|
||||||
let float = box_style.float;
|
if box_style.position.is_absolutely_positioned() {
|
||||||
let contents = IndependentFormattingContext::construct(
|
|
||||||
context,
|
|
||||||
style,
|
|
||||||
display_inside,
|
|
||||||
replaced.map_or(Contents::OfElement(root_element), Contents::Replaced),
|
|
||||||
);
|
|
||||||
if position.is_absolutely_positioned() {
|
|
||||||
(
|
(
|
||||||
ContainsFloats::No,
|
ContainsFloats::No,
|
||||||
vec![Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
vec![Arc::new(BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(
|
||||||
AbsolutelyPositionedBox { contents },
|
AbsolutelyPositionedBox::construct(context, style, display_inside, contents),
|
||||||
))],
|
))],
|
||||||
)
|
)
|
||||||
} else if float.is_floating() {
|
} else if box_style.float.is_floating() {
|
||||||
(
|
(
|
||||||
ContainsFloats::Yes,
|
ContainsFloats::Yes,
|
||||||
vec![Arc::new(BlockLevelBox::OutOfFlowFloatBox(FloatBox {
|
vec![Arc::new(BlockLevelBox::OutOfFlowFloatBox(
|
||||||
contents,
|
FloatBox::construct(context, style, display_inside, contents),
|
||||||
}))],
|
))],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
ContainsFloats::No,
|
ContainsFloats::No,
|
||||||
vec![Arc::new(BlockLevelBox::Independent(contents))],
|
vec![Arc::new(BlockLevelBox::Independent(
|
||||||
|
IndependentFormattingContext::construct(
|
||||||
|
context,
|
||||||
|
style,
|
||||||
|
display_inside,
|
||||||
|
contents,
|
||||||
|
/* request_content_sizes */ false,
|
||||||
|
),
|
||||||
|
))],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ impl IndependentFormattingContext {
|
||||||
style: Arc<ComputedValues>,
|
style: Arc<ComputedValues>,
|
||||||
display_inside: DisplayInside,
|
display_inside: DisplayInside,
|
||||||
contents: Contents<impl NodeExt<'dom>>,
|
contents: Contents<impl NodeExt<'dom>>,
|
||||||
|
_request_content_sizes: bool, // Ignored for replaced content
|
||||||
) -> Self {
|
) -> Self {
|
||||||
use self::IndependentFormattingContextContents as Contents;
|
use self::IndependentFormattingContextContents as Contents;
|
||||||
let contents = match contents.try_into() {
|
let contents = match contents.try_into() {
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::context::LayoutContext;
|
use crate::context::LayoutContext;
|
||||||
|
use crate::dom_traversal::{Contents, NodeExt};
|
||||||
use crate::formatting_contexts::IndependentFormattingContext;
|
use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
use crate::fragments::{AnonymousFragment, BoxFragment, CollapsedBlockMargins, Fragment};
|
use crate::fragments::{AnonymousFragment, BoxFragment, CollapsedBlockMargins, Fragment};
|
||||||
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
use crate::geom::flow_relative::{Rect, Sides, Vec2};
|
||||||
use crate::style_ext::{ComputedValuesExt, Direction, WritingMode};
|
use crate::style_ext::{ComputedValuesExt, Direction, DisplayInside, WritingMode};
|
||||||
use crate::{ContainingBlock, DefiniteContainingBlock};
|
use crate::{ContainingBlock, DefiniteContainingBlock};
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||||
|
use servo_arc::Arc;
|
||||||
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
|
||||||
|
@ -42,6 +45,25 @@ pub(crate) enum AbsoluteBoxOffsets<NonStatic> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AbsolutelyPositionedBox {
|
impl AbsolutelyPositionedBox {
|
||||||
|
pub fn construct<'dom>(
|
||||||
|
context: &LayoutContext,
|
||||||
|
style: Arc<ComputedValues>,
|
||||||
|
display_inside: DisplayInside,
|
||||||
|
contents: Contents<impl NodeExt<'dom>>,
|
||||||
|
) -> Self {
|
||||||
|
let request_content_sizes =
|
||||||
|
style.inline_size_is_auto() && !style.inline_box_offsets_are_both_auto();
|
||||||
|
Self {
|
||||||
|
contents: IndependentFormattingContext::construct(
|
||||||
|
context,
|
||||||
|
style,
|
||||||
|
display_inside,
|
||||||
|
contents,
|
||||||
|
request_content_sizes,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn layout<'a>(
|
pub(crate) fn layout<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
initial_start_corner: Vec2<Length>,
|
initial_start_corner: Vec2<Length>,
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub(crate) trait ComputedValuesExt {
|
||||||
fn writing_mode(&self) -> (WritingMode, Direction);
|
fn writing_mode(&self) -> (WritingMode, Direction);
|
||||||
fn writing_mode_is_horizontal(&self) -> bool;
|
fn writing_mode_is_horizontal(&self) -> bool;
|
||||||
fn inline_size_is_auto(&self) -> bool;
|
fn inline_size_is_auto(&self) -> bool;
|
||||||
|
fn inline_box_offsets_are_both_auto(&self) -> bool;
|
||||||
fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto>;
|
fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto>;
|
||||||
fn box_size(&self) -> flow_relative::Vec2<LengthPercentageOrAuto>;
|
fn box_size(&self) -> flow_relative::Vec2<LengthPercentageOrAuto>;
|
||||||
fn padding(&self) -> flow_relative::Sides<LengthPercentage>;
|
fn padding(&self) -> flow_relative::Sides<LengthPercentage>;
|
||||||
|
@ -77,6 +78,19 @@ impl ComputedValuesExt for ComputedValues {
|
||||||
matches!(size, Size::Auto)
|
matches!(size, Size::Auto)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inline_box_offsets_are_both_auto(&self) -> bool {
|
||||||
|
let position = self.get_position();
|
||||||
|
let offsets = if self.writing_mode_is_horizontal() {
|
||||||
|
(position.left, position.right)
|
||||||
|
} else {
|
||||||
|
(position.top, position.bottom)
|
||||||
|
};
|
||||||
|
matches!(
|
||||||
|
offsets,
|
||||||
|
(LengthPercentageOrAuto::Auto, LengthPercentageOrAuto::Auto)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto> {
|
fn box_offsets(&self) -> flow_relative::Sides<LengthPercentageOrAuto> {
|
||||||
let position = self.get_position();
|
let position = self.get_position();
|
||||||
|
|
|
@ -1082,7 +1082,8 @@ impl LayoutThread {
|
||||||
driver::traverse_dom(&traversal, token, Some(rayon_pool));
|
driver::traverse_dom(&traversal, token, Some(rayon_pool));
|
||||||
|
|
||||||
let root_node = document.root_element().unwrap().as_node();
|
let root_node = document.root_element().unwrap().as_node();
|
||||||
let box_tree = rayon_pool.install(|| BoxTreeRoot::construct(traversal.context(), root_node));
|
let box_tree =
|
||||||
|
rayon_pool.install(|| BoxTreeRoot::construct(traversal.context(), root_node));
|
||||||
Some(box_tree)
|
Some(box_tree)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue