mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
layout: Add an indefinite containing block for intrinsic sizing (#33204)
When computing the min-content or max-content size of an element we need to ignore `inline-size`, `min-inline-size` and `max-inline-size`. However, we should take the block-axis sizing properties into account. That's because the contents could have percentages depending on them, which can then affect their inline size via an aspect ratio. Therefore, this patch adds `IndefiniteContainingBlock`, which is similar to `ContainingBlock`, but it allows an indefinite inline-size. This struct is then passed arround during intrinsic sizing. More refinement will be needed in follow-up patches in order to fully address the problem. Signed-off-by: Oriol Brufau <obrufau@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
46dbe4ce32
commit
93abdf7cb5
29 changed files with 600 additions and 332 deletions
|
@ -24,7 +24,7 @@ pub type AuOrAuto = AutoOr<Au>;
|
|||
pub type LengthOrAuto = AutoOr<Length>;
|
||||
pub type LengthPercentageOrAuto<'a> = AutoOr<&'a LengthPercentage>;
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
#[derive(Clone, Copy, PartialEq, Serialize)]
|
||||
pub struct LogicalVec2<T> {
|
||||
pub inline: T,
|
||||
pub block: T,
|
||||
|
@ -150,7 +150,7 @@ impl<T: Clone> LogicalVec2<AutoOr<T>> {
|
|||
}
|
||||
|
||||
impl LogicalVec2<LengthPercentageOrAuto<'_>> {
|
||||
pub fn percentages_relative_to(
|
||||
pub(crate) fn percentages_relative_to(
|
||||
&self,
|
||||
containing_block: &ContainingBlock,
|
||||
) -> LogicalVec2<LengthOrAuto> {
|
||||
|
@ -165,8 +165,32 @@ impl LogicalVec2<LengthPercentageOrAuto<'_>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl LogicalVec2<LengthPercentageOrAuto<'_>> {
|
||||
pub(crate) fn percentages_relative_to_basis(
|
||||
&self,
|
||||
basis: &LogicalVec2<Length>,
|
||||
) -> LogicalVec2<LengthOrAuto> {
|
||||
LogicalVec2 {
|
||||
inline: self.inline.percentage_relative_to(basis.inline),
|
||||
block: self.block.percentage_relative_to(basis.block),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LogicalVec2<LengthPercentageOrAuto<'_>> {
|
||||
pub(crate) fn maybe_percentages_relative_to_basis(
|
||||
&self,
|
||||
basis: &LogicalVec2<Option<Length>>,
|
||||
) -> LogicalVec2<LengthOrAuto> {
|
||||
LogicalVec2 {
|
||||
inline: self.inline.maybe_percentage_relative_to(basis.inline),
|
||||
block: self.block.maybe_percentage_relative_to(basis.block),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LogicalVec2<Option<&'_ LengthPercentage>> {
|
||||
pub fn percentages_relative_to(
|
||||
pub(crate) fn percentages_relative_to(
|
||||
&self,
|
||||
containing_block: &ContainingBlock,
|
||||
) -> LogicalVec2<Option<Length>> {
|
||||
|
@ -183,6 +207,22 @@ impl LogicalVec2<Option<&'_ LengthPercentage>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl LogicalVec2<Option<&'_ LengthPercentage>> {
|
||||
pub(crate) fn maybe_percentages_relative_to_basis(
|
||||
&self,
|
||||
basis: &LogicalVec2<Option<Length>>,
|
||||
) -> LogicalVec2<Option<Length>> {
|
||||
LogicalVec2 {
|
||||
inline: self
|
||||
.inline
|
||||
.and_then(|v| v.maybe_percentage_relative_to(basis.inline)),
|
||||
block: self
|
||||
.block
|
||||
.and_then(|v| v.maybe_percentage_relative_to(basis.block)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Zero> LogicalRect<T> {
|
||||
pub fn zero() -> Self {
|
||||
Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue