mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Move clamp_*
functions to methods of Length
This commit is contained in:
parent
8a7de32d5b
commit
a2c2b294d5
2 changed files with 34 additions and 24 deletions
|
@ -411,7 +411,7 @@ fn layout_in_flow_non_replaced_block_level<'a>(
|
||||||
// https://drafts.csswg.org/css2/visudet.html#min-max-heights
|
// https://drafts.csswg.org/css2/visudet.html#min-max-heights
|
||||||
let mut block_size = box_size.block;
|
let mut block_size = box_size.block;
|
||||||
if let LengthOrAuto::LengthPercentage(ref mut block_size) = block_size {
|
if let LengthOrAuto::LengthPercentage(ref mut block_size) = block_size {
|
||||||
*block_size = clamp_between_extremums(*block_size, min_box_size.block, max_box_size.block);
|
*block_size = block_size.clamp_between_extremums(min_box_size.block, max_box_size.block);
|
||||||
}
|
}
|
||||||
|
|
||||||
let containing_block_for_children = ContainingBlock {
|
let containing_block_for_children = ContainingBlock {
|
||||||
|
@ -475,11 +475,9 @@ fn layout_in_flow_non_replaced_block_level<'a>(
|
||||||
.collapsed_through;
|
.collapsed_through;
|
||||||
let relative_adjustement = relative_adjustement(style, inline_size, block_size);
|
let relative_adjustement = relative_adjustement(style, inline_size, block_size);
|
||||||
let block_size = block_size.auto_is(|| {
|
let block_size = block_size.auto_is(|| {
|
||||||
clamp_between_extremums(
|
flow_layout
|
||||||
flow_layout.content_block_size,
|
.content_block_size
|
||||||
min_box_size.block,
|
.clamp_between_extremums(min_box_size.block, max_box_size.block)
|
||||||
max_box_size.block,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
let content_rect = Rect {
|
let content_rect = Rect {
|
||||||
start_corner: Vec2 {
|
start_corner: Vec2 {
|
||||||
|
@ -536,10 +534,10 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
|
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
|
||||||
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
|
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
|
||||||
|
|
||||||
let clamp = |inline_size, block_size| {
|
let clamp = |inline_size: Length, block_size: Length| {
|
||||||
(
|
(
|
||||||
clamp_between_extremums(inline_size, min_box_size.inline, max_box_size.inline),
|
inline_size.clamp_between_extremums(min_box_size.inline, max_box_size.inline),
|
||||||
clamp_between_extremums(block_size, min_box_size.block, max_box_size.block),
|
block_size.clamp_between_extremums(min_box_size.block, max_box_size.block),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
// https://drafts.csswg.org/css2/visudet.html#min-max-widths
|
// https://drafts.csswg.org/css2/visudet.html#min-max-widths
|
||||||
|
@ -590,7 +588,7 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
// Row 3.
|
// Row 3.
|
||||||
(Violation::Below(min_inline_size), Violation::None) => {
|
(Violation::Below(min_inline_size), Violation::None) => {
|
||||||
let block_size =
|
let block_size =
|
||||||
clamp_below_max(min_inline_size / intrinsic_ratio, max_box_size.block);
|
(min_inline_size / intrinsic_ratio).clamp_below_max(max_box_size.block);
|
||||||
(min_inline_size, block_size)
|
(min_inline_size, block_size)
|
||||||
},
|
},
|
||||||
// Row 4.
|
// Row 4.
|
||||||
|
@ -601,7 +599,7 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
// Row 5.
|
// Row 5.
|
||||||
(Violation::None, Violation::Below(min_block_size)) => {
|
(Violation::None, Violation::Below(min_block_size)) => {
|
||||||
let inline_size =
|
let inline_size =
|
||||||
clamp_below_max(min_block_size * intrinsic_ratio, max_box_size.inline);
|
(min_block_size * intrinsic_ratio).clamp_below_max(max_box_size.inline);
|
||||||
(inline_size, min_block_size)
|
(inline_size, min_block_size)
|
||||||
},
|
},
|
||||||
// Rows 6-7.
|
// Rows 6-7.
|
||||||
|
@ -627,12 +625,12 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
{
|
{
|
||||||
// Row 8.
|
// Row 8.
|
||||||
let inline_size =
|
let inline_size =
|
||||||
clamp_below_max(min_block_size * intrinsic_ratio, max_box_size.inline);
|
(min_block_size * intrinsic_ratio).clamp_below_max(max_box_size.inline);
|
||||||
(inline_size, min_block_size)
|
(inline_size, min_block_size)
|
||||||
} else {
|
} else {
|
||||||
// Row 9.
|
// Row 9.
|
||||||
let block_size =
|
let block_size =
|
||||||
clamp_below_max(min_inline_size / intrinsic_ratio, max_box_size.block);
|
(min_inline_size / intrinsic_ratio).clamp_below_max(max_box_size.block);
|
||||||
(min_inline_size, block_size)
|
(min_inline_size, block_size)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -704,14 +702,6 @@ fn solve_inline_margins_for_in_flow_block_level(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clamp_between_extremums(size: Length, min_size: Length, max_size: Option<Length>) -> Length {
|
|
||||||
clamp_below_max(size, max_size).max(min_size)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clamp_below_max(size: Length, max_size: Option<Length>) -> Length {
|
|
||||||
max_size.map_or(size, |max_size| size.min(max_size))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn percent_resolved_box_size(
|
fn percent_resolved_box_size(
|
||||||
box_size: Vec2<LengthPercentageOrAuto>,
|
box_size: Vec2<LengthPercentageOrAuto>,
|
||||||
containing_block: &ContainingBlock,
|
containing_block: &ContainingBlock,
|
||||||
|
|
|
@ -657,14 +657,14 @@ impl CSSPixelLength {
|
||||||
|
|
||||||
/// Return the containing pixel value.
|
/// Return the containing pixel value.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn px(&self) -> CSSFloat {
|
pub fn px(self) -> CSSFloat {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the length with app_unit i32 type.
|
/// Return the length with app_unit i32 type.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_i32_au(&self) -> i32 {
|
pub fn to_i32_au(self) -> i32 {
|
||||||
Au::from(*self).0
|
Au::from(self).0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the absolute value of this length.
|
/// Return the absolute value of this length.
|
||||||
|
@ -692,9 +692,29 @@ impl CSSPixelLength {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets `self` to the maximum between `self` and `other`.
|
/// Sets `self` to the maximum between `self` and `other`.
|
||||||
|
#[inline]
|
||||||
pub fn max_assign(&mut self, other: Self) {
|
pub fn max_assign(&mut self, other: Self) {
|
||||||
*self = self.max(other);
|
*self = self.max(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clamp the value to a lower bound and an optional upper bound.
|
||||||
|
///
|
||||||
|
/// Can be used for example with `min-width` and `max-width`.
|
||||||
|
#[inline]
|
||||||
|
pub fn clamp_between_extremums(self, min_size: Self, max_size: Option<Self>) -> Self {
|
||||||
|
self.clamp_below_max(max_size).max(min_size)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clamp the value to an optional upper bound.
|
||||||
|
///
|
||||||
|
/// Can be used for example with `max-width`.
|
||||||
|
#[inline]
|
||||||
|
pub fn clamp_below_max(self, max_size: Option<Self>) -> Self {
|
||||||
|
match max_size {
|
||||||
|
None => self,
|
||||||
|
Some(max_size) => self.min(max_size),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Zero for CSSPixelLength {
|
impl Zero for CSSPixelLength {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue