diff options
author | Anthony Ramine <nox@nox.paris> | 2020-06-18 14:11:02 +0200 |
---|---|---|
committer | Anthony Ramine <nox@nox.paris> | 2020-06-18 14:11:02 +0200 |
commit | 235df94f2eb9227fb35a51a5bc486aa9d29b5036 (patch) | |
tree | f1d87a305d07d5e484ca0fbd2cbc269a5f6f4ca9 /components/layout_2020/sizing.rs | |
parent | ba5568a0a60cbd4bbedd3b766b7182824d75b131 (diff) | |
download | servo-235df94f2eb9227fb35a51a5bc486aa9d29b5036.tar.gz servo-235df94f2eb9227fb35a51a5bc486aa9d29b5036.zip |
Compute content sizes lazily in layout 2020
Diffstat (limited to 'components/layout_2020/sizing.rs')
-rw-r--r-- | components/layout_2020/sizing.rs | 61 |
1 files changed, 3 insertions, 58 deletions
diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs index dd9574d4f85..ec07861c374 100644 --- a/components/layout_2020/sizing.rs +++ b/components/layout_2020/sizing.rs @@ -11,44 +11,6 @@ use style::properties::ComputedValues; use style::values::computed::{Length, LengthPercentage, Percentage}; use style::Zero; -/// Which min/max-content values should be computed during box construction -#[derive(Clone, Copy, Debug)] -pub(crate) enum ContentSizesRequest { - Inline, - None, -} - -impl ContentSizesRequest { - pub fn inline_if(condition: bool) -> Self { - if condition { - Self::Inline - } else { - Self::None - } - } - - pub fn requests_inline(self) -> bool { - match self { - Self::Inline => true, - Self::None => false, - } - } - - pub fn if_requests_inline<T>(self, f: impl FnOnce() -> T) -> Option<T> { - match self { - Self::Inline => Some(f()), - Self::None => None, - } - } - - pub fn compute(self, compute_inline: impl FnOnce() -> ContentSizes) -> BoxContentSizes { - match self { - Self::Inline => BoxContentSizes::Inline(compute_inline()), - Self::None => BoxContentSizes::NoneWereRequested, - } - } -} - #[derive(Clone, Debug, Serialize)] pub(crate) struct ContentSizes { pub min_content: Length, @@ -90,27 +52,10 @@ impl ContentSizes { } } -/// Optional min/max-content for storage in the box tree -#[derive(Debug, Serialize)] -pub(crate) enum BoxContentSizes { - NoneWereRequested, // … during box construction - Inline(ContentSizes), -} - -impl BoxContentSizes { - pub fn expect_inline(&self) -> &ContentSizes { - match self { - Self::NoneWereRequested => panic!("Accessing content size that was not requested"), - Self::Inline(s) => s, - } - } - +impl ContentSizes { /// 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) + pub fn shrink_to_fit(&self, available_size: Length) -> Length { + available_size.max(self.min_content).min(self.max_content) } } |