mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Make outer_inline and outer_inline_and_percentages free functions
They now take a closure that will compute the content sizes on demand.
This commit is contained in:
parent
d0a1066d2d
commit
07d8c28d4a
3 changed files with 97 additions and 97 deletions
|
@ -14,7 +14,7 @@ use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
|
||||||
use crate::formatting_contexts::IndependentFormattingContext;
|
use crate::formatting_contexts::IndependentFormattingContext;
|
||||||
use crate::fragments::Tag;
|
use crate::fragments::Tag;
|
||||||
use crate::positioned::AbsolutelyPositionedBox;
|
use crate::positioned::AbsolutelyPositionedBox;
|
||||||
use crate::sizing::{BoxContentSizes, ContentSizes, ContentSizesRequest};
|
use crate::sizing::{self, BoxContentSizes, ContentSizes, ContentSizesRequest};
|
||||||
use crate::style_ext::{ComputedValuesExt, 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;
|
||||||
|
@ -701,10 +701,11 @@ where
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if let Some(to) = max_assign_in_flow_outer_content_sizes_to {
|
if let Some(to) = max_assign_in_flow_outer_content_sizes_to {
|
||||||
to.max_assign(
|
to.max_assign(&sizing::outer_inline(
|
||||||
&box_content_sizes
|
&info.style,
|
||||||
.outer_inline(&info.style, not_actually_containing_block_writing_mode),
|
not_actually_containing_block_writing_mode,
|
||||||
)
|
|| box_content_sizes.expect_inline().clone(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
let block_level_box = ArcRefCell::new(BlockLevelBox::SameFormattingContextBlock {
|
let block_level_box = ArcRefCell::new(BlockLevelBox::SameFormattingContextBlock {
|
||||||
tag: Tag::from_node_and_style_info(info),
|
tag: Tag::from_node_and_style_info(info),
|
||||||
|
@ -731,12 +732,11 @@ where
|
||||||
propagated_text_decoration_line,
|
propagated_text_decoration_line,
|
||||||
);
|
);
|
||||||
if let Some(to) = max_assign_in_flow_outer_content_sizes_to {
|
if let Some(to) = max_assign_in_flow_outer_content_sizes_to {
|
||||||
to.max_assign(
|
to.max_assign(&sizing::outer_inline(
|
||||||
&contents.content_sizes.outer_inline(
|
|
||||||
&contents.style,
|
&contents.style,
|
||||||
not_actually_containing_block_writing_mode,
|
not_actually_containing_block_writing_mode,
|
||||||
),
|
|| contents.content_sizes.expect_inline().clone(),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
ArcRefCell::new(BlockLevelBox::Independent(contents)),
|
ArcRefCell::new(BlockLevelBox::Independent(contents)),
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::positioned::{
|
||||||
relative_adjustement, AbsolutelyPositionedBox, HoistedAbsolutelyPositionedBox,
|
relative_adjustement, AbsolutelyPositionedBox, HoistedAbsolutelyPositionedBox,
|
||||||
PositioningContext,
|
PositioningContext,
|
||||||
};
|
};
|
||||||
use crate::sizing::ContentSizes;
|
use crate::sizing::{self, ContentSizes};
|
||||||
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
|
use crate::style_ext::{ComputedValuesExt, Display, DisplayGeneratingBox, DisplayOutside};
|
||||||
use crate::ContainingBlock;
|
use crate::ContainingBlock;
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -200,9 +200,10 @@ impl InlineFormattingContext {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
InlineLevelBox::Atomic(atomic) => {
|
InlineLevelBox::Atomic(atomic) => {
|
||||||
let (outer, pc) = atomic.content_sizes.outer_inline_and_percentages(
|
let (outer, pc) = sizing::outer_inline_and_percentages(
|
||||||
&atomic.style,
|
&atomic.style,
|
||||||
self.containing_block_writing_mode,
|
self.containing_block_writing_mode,
|
||||||
|
|| atomic.content_sizes.expect_inline().clone(),
|
||||||
);
|
);
|
||||||
self.current_line.min_content += outer.min_content;
|
self.current_line.min_content += outer.min_content;
|
||||||
self.current_line.max_content += outer.max_content;
|
self.current_line.max_content += outer.max_content;
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl ContentSizes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map(&self, f: impl Fn(Length) -> Length) -> Self {
|
pub fn map(&self, f: impl Fn(Length) -> Length) -> Self {
|
||||||
Self {
|
Self {
|
||||||
min_content: f(self.min_content),
|
min_content: f(self.min_content),
|
||||||
max_content: f(self.max_content),
|
max_content: f(self.max_content),
|
||||||
|
@ -98,29 +98,37 @@ pub(crate) enum BoxContentSizes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BoxContentSizes {
|
impl BoxContentSizes {
|
||||||
fn expect_inline(&self) -> &ContentSizes {
|
pub fn expect_inline(&self) -> &ContentSizes {
|
||||||
match self {
|
match self {
|
||||||
Self::NoneWereRequested => panic!("Accessing content size that was not requested"),
|
Self::NoneWereRequested => panic!("Accessing content size that was not requested"),
|
||||||
Self::Inline(s) => s,
|
Self::Inline(s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://dbaron.org/css/intrinsic/#outer-intrinsic
|
/// https://drafts.csswg.org/css2/visudet.html#shrink-to-fit-float
|
||||||
pub fn outer_inline(
|
pub(crate) fn shrink_to_fit(&self, available_size: Length) -> Length {
|
||||||
&self,
|
let inline = self.expect_inline();
|
||||||
|
available_size
|
||||||
|
.max(inline.min_content)
|
||||||
|
.min(inline.max_content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn outer_inline(
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
containing_block_writing_mode: WritingMode,
|
containing_block_writing_mode: WritingMode,
|
||||||
|
get_content_size: impl FnOnce() -> ContentSizes,
|
||||||
) -> ContentSizes {
|
) -> ContentSizes {
|
||||||
let (mut outer, percentages) =
|
let (mut outer, percentages) =
|
||||||
self.outer_inline_and_percentages(style, containing_block_writing_mode);
|
outer_inline_and_percentages(style, containing_block_writing_mode, get_content_size);
|
||||||
outer.adjust_for_pbm_percentages(percentages);
|
outer.adjust_for_pbm_percentages(percentages);
|
||||||
outer
|
outer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn outer_inline_and_percentages(
|
pub(crate) fn outer_inline_and_percentages(
|
||||||
&self,
|
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
containing_block_writing_mode: WritingMode,
|
containing_block_writing_mode: WritingMode,
|
||||||
|
get_content_size: impl FnOnce() -> ContentSizes,
|
||||||
) -> (ContentSizes, Percentage) {
|
) -> (ContentSizes, Percentage) {
|
||||||
let padding = style.padding(containing_block_writing_mode);
|
let padding = style.padding(containing_block_writing_mode);
|
||||||
let border = style.border_width(containing_block_writing_mode);
|
let border = style.border_width(containing_block_writing_mode);
|
||||||
|
@ -174,7 +182,7 @@ impl BoxContentSizes {
|
||||||
max_content: border_box_size,
|
max_content: border_box_size,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => self.expect_inline().map(|content_box_size| {
|
None => get_content_size().map(|content_box_size| {
|
||||||
match box_sizing {
|
match box_sizing {
|
||||||
// Clamp to 'min-width' and 'max-width', which are sizing the…
|
// Clamp to 'min-width' and 'max-width', which are sizing the…
|
||||||
BoxSizing::ContentBox => clamp(content_box_size) + pb_lengths,
|
BoxSizing::ContentBox => clamp(content_box_size) + pb_lengths,
|
||||||
|
@ -186,12 +194,3 @@ impl BoxContentSizes {
|
||||||
let outer = border_box_sizes.map(|s| s + m_lengths);
|
let outer = border_box_sizes.map(|s| s + m_lengths);
|
||||||
(outer, pbm_percentages)
|
(outer, pbm_percentages)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css2/visudet.html#shrink-to-fit-float
|
|
||||||
pub(crate) fn shrink_to_fit(&self, available_size: Length) -> Length {
|
|
||||||
let inline = self.expect_inline();
|
|
||||||
available_size
|
|
||||||
.max(inline.min_content)
|
|
||||||
.min(inline.max_content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue