aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratbrakhi <atbrakhi@igalia.com>2024-01-15 15:31:21 +0100
committerGitHub <noreply@github.com>2024-01-15 14:31:21 +0000
commit1b847c3166d17a957f5ab5e4aae3a3fcb10d875c (patch)
tree6ff386ce681e3be3406eace72af574305dcd4b14
parentefa38c67fe6bdec751739bb3a0a6d159f2b695c8 (diff)
downloadservo-1b847c3166d17a957f5ab5e4aae3a3fcb10d875c.tar.gz
servo-1b847c3166d17a957f5ab5e4aae3a3fcb10d875c.zip
layout: Switch `IndependentLayout` to use `Au` instead of `Length` (#31083)
* use au in layout * fmt * review fix
-rw-r--r--components/layout_2020/flexbox/layout.rs4
-rw-r--r--components/layout_2020/flow/float.rs2
-rw-r--r--components/layout_2020/flow/inline.rs6
-rw-r--r--components/layout_2020/flow/mod.rs33
-rw-r--r--components/layout_2020/formatting_contexts.rs6
-rw-r--r--components/layout_2020/positioned.rs3
-rw-r--r--components/layout_2020/style_ext.rs14
-rw-r--r--components/layout_2020/table/mod.rs5
8 files changed, 52 insertions, 21 deletions
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 05c8b95ad97..55f792e3b07 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -410,7 +410,7 @@ impl FlexContainer {
IndependentLayout {
fragments,
- content_block_size,
+ content_block_size: content_block_size.into(),
last_inflow_baseline_offset: None,
}
}
@@ -1111,7 +1111,7 @@ impl<'a> FlexItem<'a> {
let hypothetical_cross_size = self
.content_box_size
.cross
- .auto_is(|| content_block_size)
+ .auto_is(|| content_block_size.into())
.clamp_between_extremums(
self.content_min_size.cross,
self.content_max_size.cross,
diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs
index a6f8f06ddf3..1de87a59eb2 100644
--- a/components/layout_2020/flow/float.rs
+++ b/components/layout_2020/flow/float.rs
@@ -930,7 +930,7 @@ impl FloatBox {
inline: inline_size,
block: box_size
.block
- .auto_is(|| independent_layout.content_block_size),
+ .auto_is(|| independent_layout.content_block_size.into()),
};
children = independent_layout.fragments;
},
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index e980983552a..c5b9bbd6c5c 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -1949,7 +1949,7 @@ impl IndependentFormattingContext {
// https://drafts.csswg.org/css2/visudet.html#block-root-margin
let tentative_block_size = box_size
.block
- .auto_is(|| independent_layout.content_block_size);
+ .auto_is(|| independent_layout.content_block_size.into());
// https://drafts.csswg.org/css2/visudet.html#min-max-heights
// In this case “applying the rules above again” with a non-auto block-size
@@ -1974,7 +1974,9 @@ impl IndependentFormattingContext {
pbm.border,
margin,
None,
- independent_layout.last_inflow_baseline_offset,
+ independent_layout
+ .last_inflow_baseline_offset
+ .map(|t| t.into()),
CollapsedBlockMargins::zero(),
)
},
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index 95c03655980..acdfa59ab26 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -30,7 +30,7 @@ use crate::geom::{LogicalRect, LogicalSides, LogicalVec2};
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext, PositioningContextLength};
use crate::replaced::ReplacedContent;
use crate::sizing::{self, ContentSizes};
-use crate::style_ext::{ComputedValuesExt, PaddingBorderMargin};
+use crate::style_ext::{Clamp, ComputedValuesExt, PaddingBorderMargin};
use crate::ContainingBlock;
mod construct;
@@ -240,10 +240,11 @@ impl BlockFormattingContext {
IndependentLayout {
fragments: flow_layout.fragments,
- content_block_size: flow_layout.content_block_size +
+ content_block_size: (flow_layout.content_block_size +
flow_layout.collapsible_margins_in_children.end.solve() +
- clearance.unwrap_or_else(Length::zero),
- last_inflow_baseline_offset: flow_layout.last_inflow_baseline_offset,
+ clearance.unwrap_or_else(Length::zero))
+ .into(),
+ last_inflow_baseline_offset: flow_layout.last_inflow_baseline_offset.map(|t| t.into()),
}
}
}
@@ -858,7 +859,11 @@ impl NonReplacedFormattingContext {
let block_size = containing_block_for_children.block_size.auto_is(|| {
layout
.content_block_size
- .clamp_between_extremums(min_box_size.block, max_box_size.block)
+ .clamp_between_extremums(
+ min_box_size.block.into(),
+ max_box_size.block.map(|t| t.into()),
+ )
+ .into()
});
let content_rect = LogicalRect {
@@ -882,7 +887,7 @@ impl NonReplacedFormattingContext {
pbm.border,
margin,
None, /* clearance */
- layout.last_inflow_baseline_offset,
+ layout.last_inflow_baseline_offset.map(|t| t.into()),
block_margins_collapsed_with_children,
)
}
@@ -939,12 +944,17 @@ impl NonReplacedFormattingContext {
style: &self.style,
},
);
+
content_size = LogicalVec2 {
inline: inline_size,
block: block_size.auto_is(|| {
layout
.content_block_size
- .clamp_between_extremums(min_box_size.block, max_box_size.block)
+ .clamp_between_extremums(
+ min_box_size.block.into(),
+ max_box_size.block.map(|t| t.into()),
+ )
+ .into()
}),
};
@@ -1002,13 +1012,16 @@ impl NonReplacedFormattingContext {
style: &self.style,
},
);
-
content_size = LogicalVec2 {
inline: proposed_inline_size,
block: block_size.auto_is(|| {
layout
.content_block_size
- .clamp_between_extremums(min_box_size.block, max_box_size.block)
+ .clamp_between_extremums(
+ min_box_size.block.into(),
+ max_box_size.block.map(|t| t.into()),
+ )
+ .into()
}),
};
@@ -1092,7 +1105,7 @@ impl NonReplacedFormattingContext {
pbm.border,
margin,
clearance,
- layout.last_inflow_baseline_offset,
+ layout.last_inflow_baseline_offset.map(|t| t.into()),
block_margins_collapsed_with_children,
)
}
diff --git a/components/layout_2020/formatting_contexts.rs b/components/layout_2020/formatting_contexts.rs
index 812ab22fbbc..8c441c98ea7 100644
--- a/components/layout_2020/formatting_contexts.rs
+++ b/components/layout_2020/formatting_contexts.rs
@@ -4,11 +4,11 @@
use std::convert::TryInto;
+use app_units::Au;
use serde::Serialize;
use servo_arc::Arc;
use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;
-use style::values::computed::Length;
use style::values::specified::text::TextDecorationLine;
use crate::context::LayoutContext;
@@ -63,12 +63,12 @@ pub(crate) struct IndependentLayout {
pub fragments: Vec<Fragment>,
/// https://drafts.csswg.org/css2/visudet.html#root-height
- pub content_block_size: Length,
+ pub content_block_size: Au,
/// The offset of the last inflow baseline of this layout in the content area, if
/// there was one. This is used to propagate baselines to the ancestors of `display:
/// inline-block`.
- pub last_inflow_baseline_offset: Option<Length>,
+ pub last_inflow_baseline_offset: Option<Au>,
}
impl IndependentFormattingContext {
diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs
index ce1621927b6..9b109a4fbb1 100644
--- a/components/layout_2020/positioned.rs
+++ b/components/layout_2020/positioned.rs
@@ -622,7 +622,8 @@ impl HoistedAbsolutelyPositionedBox {
&mut positioning_context,
&containing_block_for_children,
);
- let block_size = size.auto_is(|| independent_layout.content_block_size);
+ let block_size =
+ size.auto_is(|| independent_layout.content_block_size.into());
Result {
content_size: LogicalVec2 {
inline: inline_size,
diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs
index a2017e5d0d5..50c19b7d8b6 100644
--- a/components/layout_2020/style_ext.rs
+++ b/components/layout_2020/style_ext.rs
@@ -2,6 +2,7 @@
* 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/. */
+use app_units::Au;
use servo_config::pref;
use style::computed_values::mix_blend_mode::T as ComputedMixBlendMode;
use style::computed_values::position::T as ComputedPosition;
@@ -626,3 +627,16 @@ fn size_to_length(size: &Size) -> LengthPercentageOrAuto {
Size::Auto => LengthPercentageOrAuto::Auto,
}
}
+
+pub(crate) trait Clamp: Sized {
+ fn clamp_between_extremums(self, min: Self, max: Option<Self>) -> Self;
+}
+
+impl Clamp for Au {
+ fn clamp_between_extremums(self, min: Self, max: Option<Self>) -> Self {
+ match max {
+ Some(max_value) => self.min(max_value).max(min),
+ None => self.max(min),
+ }
+ }
+}
diff --git a/components/layout_2020/table/mod.rs b/components/layout_2020/table/mod.rs
index 918fa88ac5d..901943ad8e3 100644
--- a/components/layout_2020/table/mod.rs
+++ b/components/layout_2020/table/mod.rs
@@ -7,11 +7,12 @@
mod construct;
+use app_units::Au;
pub(crate) use construct::AnonymousTableContent;
pub use construct::TableBuilder;
+use euclid::num::Zero;
use euclid::{Point2D, UnknownUnit, Vector2D};
use serde::Serialize;
-use style::values::computed::Length;
use super::flow::BlockFormattingContext;
use crate::context::LayoutContext;
@@ -39,7 +40,7 @@ impl Table {
) -> IndependentLayout {
IndependentLayout {
fragments: Vec::new(),
- content_block_size: Length::new(0.),
+ content_block_size: Au::zero(),
last_inflow_baseline_offset: None,
}
}