mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Refactor computation of preferred aspect ratios (#34416)
* Refactor computation of preferred aspect ratios Computing min/max-content sizes required a ContainingBlock in order to resolve the padding and border when determining the preferred aspect ratio. However, all callers already knew the padding and border, so they can compute the ratio themselves, and pass it directly instead of the ContainingBlock. Signed-off-by: Oriol Brufau <obrufau@igalia.com> * Put preferred aspect ratio into ConstraintSpace Signed-off-by: Oriol Brufau <obrufau@igalia.com> --------- Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
16da1c2721
commit
19a7e95a6a
11 changed files with 133 additions and 113 deletions
|
@ -35,24 +35,38 @@ use style::logical_geometry::WritingMode;
|
|||
use style::properties::ComputedValues;
|
||||
|
||||
use crate::geom::{LogicalVec2, SizeConstraint};
|
||||
use crate::style_ext::AspectRatio;
|
||||
|
||||
/// Represents the set of constraints that we use when computing the min-content
|
||||
/// and max-content inline sizes of an element.
|
||||
pub(crate) struct ConstraintSpace {
|
||||
pub block_size: SizeConstraint,
|
||||
pub writing_mode: WritingMode,
|
||||
pub preferred_aspect_ratio: Option<AspectRatio>,
|
||||
}
|
||||
|
||||
impl ConstraintSpace {
|
||||
fn new(block_size: SizeConstraint, writing_mode: WritingMode) -> Self {
|
||||
fn new(
|
||||
block_size: SizeConstraint,
|
||||
writing_mode: WritingMode,
|
||||
preferred_aspect_ratio: Option<AspectRatio>,
|
||||
) -> Self {
|
||||
Self {
|
||||
block_size,
|
||||
writing_mode,
|
||||
preferred_aspect_ratio,
|
||||
}
|
||||
}
|
||||
|
||||
fn new_for_style(style: &ComputedValues) -> Self {
|
||||
Self::new(SizeConstraint::default(), style.writing_mode)
|
||||
fn new_for_style_and_ratio(
|
||||
style: &ComputedValues,
|
||||
preferred_aspect_ratio: Option<AspectRatio>,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
SizeConstraint::default(),
|
||||
style.writing_mode,
|
||||
preferred_aspect_ratio,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue