mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
layout: Change the IndefiniteContainingBlock
sizes to Option<Au>
(#35653)
Thus avoiding the need to convert to/from `AuOrAuto`. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
31b2f81bc6
commit
ebb19bcd60
6 changed files with 19 additions and 37 deletions
|
@ -2389,7 +2389,7 @@ impl FlexItemBox {
|
|||
layout_context,
|
||||
config
|
||||
.flex_axis
|
||||
.vec2_to_flex_relative(containing_block.size.map(|v| v.non_auto())),
|
||||
.vec2_to_flex_relative(containing_block.size),
|
||||
cross_axis_is_item_block_axis,
|
||||
content_box_size,
|
||||
content_min_size_no_auto,
|
||||
|
@ -2498,7 +2498,7 @@ impl FlexItemBox {
|
|||
fn automatic_min_size(
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
containing_block_size: FlexRelativeVec2<AuOrAuto>,
|
||||
containing_block_size: FlexRelativeVec2<Option<Au>>,
|
||||
cross_axis_is_item_block_axis: bool,
|
||||
content_box_size: FlexRelativeVec2<Size<Au>>,
|
||||
min_size: FlexRelativeVec2<GenericLengthPercentageOrAuto<Au>>,
|
||||
|
@ -2520,7 +2520,6 @@ impl FlexItemBox {
|
|||
let specified_size_suggestion = content_box_size.main.maybe_resolve_extrinsic(
|
||||
containing_block_size
|
||||
.main
|
||||
.non_auto()
|
||||
.map(|v| v - pbm_auto_is_zero.main),
|
||||
);
|
||||
|
||||
|
@ -2535,7 +2534,6 @@ impl FlexItemBox {
|
|||
if content_box_size.cross.is_initial() && auto_cross_size_stretches_to_container_size {
|
||||
containing_block_size
|
||||
.cross
|
||||
.non_auto()
|
||||
.map(|v| v - pbm_auto_is_zero.cross)
|
||||
} else {
|
||||
// TODO(#32853): handle size keywords.
|
||||
|
|
|
@ -898,19 +898,11 @@ impl SizeConstraint {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn to_auto_or(self) -> AutoOr<Au> {
|
||||
self.to_definite()
|
||||
.map_or(AutoOr::Auto, AutoOr::LengthPercentage)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AuOrAuto> for SizeConstraint {
|
||||
fn from(size: AuOrAuto) -> Self {
|
||||
size.non_auto()
|
||||
.map(SizeConstraint::Definite)
|
||||
.unwrap_or_default()
|
||||
impl From<Option<Au>> for SizeConstraint {
|
||||
fn from(size: Option<Au>) -> Self {
|
||||
size.map(SizeConstraint::Definite).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ pub mod traversal;
|
|||
use app_units::Au;
|
||||
pub use flow::BoxTree;
|
||||
pub use fragment_tree::FragmentTree;
|
||||
use geom::AuOrAuto;
|
||||
use style::logical_geometry::WritingMode;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::computed::TextDecorationLine;
|
||||
|
@ -75,7 +74,7 @@ impl ConstraintSpace {
|
|||
/// Useful for code that is shared for both layout (where we know the inline size
|
||||
/// of the containing block) and intrinsic sizing (where we don't know it).
|
||||
pub(crate) struct IndefiniteContainingBlock {
|
||||
pub size: LogicalVec2<AuOrAuto>,
|
||||
pub size: LogicalVec2<Option<Au>>,
|
||||
pub writing_mode: WritingMode,
|
||||
}
|
||||
|
||||
|
@ -83,8 +82,8 @@ impl From<&ConstraintSpace> for IndefiniteContainingBlock {
|
|||
fn from(constraint_space: &ConstraintSpace) -> Self {
|
||||
Self {
|
||||
size: LogicalVec2 {
|
||||
inline: AuOrAuto::Auto,
|
||||
block: constraint_space.block_size.to_auto_or(),
|
||||
inline: None,
|
||||
block: constraint_space.block_size.to_definite(),
|
||||
},
|
||||
writing_mode: constraint_space.writing_mode,
|
||||
}
|
||||
|
@ -95,8 +94,8 @@ impl<'a> From<&'_ ContainingBlock<'a>> for IndefiniteContainingBlock {
|
|||
fn from(containing_block: &ContainingBlock<'a>) -> Self {
|
||||
Self {
|
||||
size: LogicalVec2 {
|
||||
inline: AuOrAuto::LengthPercentage(containing_block.size.inline),
|
||||
block: containing_block.size.block.to_auto_or(),
|
||||
inline: Some(containing_block.size.inline),
|
||||
block: containing_block.size.block.to_definite(),
|
||||
},
|
||||
writing_mode: containing_block.style.writing_mode,
|
||||
}
|
||||
|
@ -106,9 +105,7 @@ impl<'a> From<&'_ ContainingBlock<'a>> for IndefiniteContainingBlock {
|
|||
impl<'a> From<&'_ DefiniteContainingBlock<'a>> for IndefiniteContainingBlock {
|
||||
fn from(containing_block: &DefiniteContainingBlock<'a>) -> Self {
|
||||
Self {
|
||||
size: containing_block
|
||||
.size
|
||||
.map(|v| AuOrAuto::LengthPercentage(*v)),
|
||||
size: containing_block.size.map(|v| Some(*v)),
|
||||
writing_mode: containing_block.style.writing_mode,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,6 @@ pub(crate) fn outer_inline(
|
|||
let available_block_size = containing_block
|
||||
.size
|
||||
.block
|
||||
.non_auto()
|
||||
.map(|v| Au::zero().max(v - pbm_sums.block));
|
||||
let automatic_size = if content_box_sizes.block.preferred.is_initial() &&
|
||||
auto_block_size_stretches_to_containing_block
|
||||
|
|
|
@ -840,13 +840,12 @@ impl LayoutStyle<'_> {
|
|||
// indefinite percentages, we treat the entire value as the initial value of the property.
|
||||
// However, for min size properties, as well as for margins and paddings,
|
||||
// we instead resolve indefinite percentages against zero.
|
||||
let containing_block_size = containing_block.size.map(|value| value.non_auto());
|
||||
let containing_block_size_auto_is_zero =
|
||||
containing_block_size.map(|value| value.unwrap_or_else(Au::zero));
|
||||
let containing_block_size_or_zero =
|
||||
containing_block.size.map(|value| value.unwrap_or_default());
|
||||
let writing_mode = containing_block.writing_mode;
|
||||
let pbm = self.padding_border_margin_with_writing_mode_and_containing_block_inline_size(
|
||||
writing_mode,
|
||||
containing_block.size.inline.auto_is(Au::zero),
|
||||
containing_block_size_or_zero.inline,
|
||||
);
|
||||
let style = self.style();
|
||||
let box_size = style.box_size(writing_mode);
|
||||
|
@ -872,15 +871,15 @@ impl LayoutStyle<'_> {
|
|||
depends_on_block_constraints(&max_size.block) ||
|
||||
style.depends_on_block_constraints_due_to_relative_positioning(writing_mode);
|
||||
|
||||
let box_size = box_size.maybe_percentages_relative_to_basis(&containing_block_size);
|
||||
let box_size = box_size.maybe_percentages_relative_to_basis(&containing_block.size);
|
||||
let content_box_size = style
|
||||
.content_box_size_for_box_size(box_size, &pbm)
|
||||
.map(|v| v.map(Au::from));
|
||||
let min_size = min_size.percentages_relative_to_basis(&containing_block_size_auto_is_zero);
|
||||
let min_size = min_size.percentages_relative_to_basis(&containing_block_size_or_zero);
|
||||
let content_min_box_size = style
|
||||
.content_min_box_size_for_min_size(min_size, &pbm)
|
||||
.map(|v| v.map(Au::from));
|
||||
let max_size = max_size.maybe_percentages_relative_to_basis(&containing_block_size);
|
||||
let max_size = max_size.maybe_percentages_relative_to_basis(&containing_block.size);
|
||||
let content_max_box_size = style
|
||||
.content_max_box_size_for_max_size(max_size, &pbm)
|
||||
.map(|v| v.map(Au::from));
|
||||
|
|
|
@ -35,7 +35,7 @@ use crate::fragment_tree::{
|
|||
PositioningFragment, SpecificLayoutInfo,
|
||||
};
|
||||
use crate::geom::{
|
||||
AuOrAuto, LogicalRect, LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides,
|
||||
LogicalRect, LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides,
|
||||
PhysicalVec, Size, SizeConstraint, ToLogical, ToLogicalWithContainingBlock,
|
||||
};
|
||||
use crate::positioned::{relative_adjustement, PositioningContext, PositioningContextLength};
|
||||
|
@ -704,10 +704,7 @@ impl<'a> TableLayout<'a> {
|
|||
/// Compute CAPMIN: <https://drafts.csswg.org/css-tables/#capmin>
|
||||
fn compute_caption_minimum_inline_size(&self, layout_context: &LayoutContext) -> Au {
|
||||
let containing_block = IndefiniteContainingBlock {
|
||||
size: LogicalVec2 {
|
||||
inline: AuOrAuto::Auto,
|
||||
block: AuOrAuto::Auto,
|
||||
},
|
||||
size: LogicalVec2::default(),
|
||||
writing_mode: self.table.style.writing_mode,
|
||||
};
|
||||
self.table
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue