Auto merge of #22864 - emilio:gecko-sync, r=emilio

style: Rename MozLength to Size, and MaxLength to MaxSize.

MozLength is not a very descriptive name. If we're going to use it in both Gecko
and Servo we may as well name it something more accurate.

I would've chosen `ContentSize` per CSS2[1][2] if it wasn't a lie in presence
of box-sizing. I don't have better ideas than `Size`, given that.

[1]: https://drafts.csswg.org/css2/visudet.html#propdef-width
[2]: https://drafts.csswg.org/css2/box.html#content-width

Differential Revision: https://phabricator.services.mozilla.com/D19280

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22864)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-02-11 20:28:35 -05:00 committed by GitHub
commit 92369cca21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 280 additions and 333 deletions

View file

@ -67,9 +67,7 @@ use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::{ use style::values::computed::{LengthPercentageOrAuto, MaxSize, Size};
LengthPercentageOrAuto, MaxLength, NonNegativeLengthPercentageOrAuto,
};
/// Information specific to floated blocks. /// Information specific to floated blocks.
#[derive(Clone, Serialize)] #[derive(Clone, Serialize)]
@ -421,24 +419,24 @@ impl CandidateBSizeIterator {
// `min-height` and `max-height`, percentage values are ignored. // `min-height` and `max-height`, percentage values are ignored.
let block_size = match fragment.style.content_block_size() { let block_size = match fragment.style.content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto, Size::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size)) MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size))
}, },
}; };
let max_block_size = match fragment.style.max_block_size() { let max_block_size = match fragment.style.max_block_size() {
MaxLength::None => None, MaxSize::None => None,
MaxLength::LengthPercentage(ref lp) => { MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(block_container_block_size),
lp.maybe_to_used_value(block_container_block_size)
},
}; };
let min_block_size = fragment let min_block_size = match fragment.style.min_block_size() {
.style Size::Auto => MaybeAuto::Auto,
.min_block_size() Size::LengthPercentage(ref lp) => {
.maybe_to_used_value(block_container_block_size) MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size))
.unwrap_or(Au(0)); },
}
.specified_or_zero();
// If the style includes `box-sizing: border-box`, subtract the border and padding. // If the style includes `box-sizing: border-box`, subtract the border and padding.
let adjustment_for_box_sizing = match fragment.style.get_position().box_sizing { let adjustment_for_box_sizing = match fragment.style.get_position().box_sizing {
@ -1402,7 +1400,7 @@ impl BlockFlow {
let content_block_size = self.fragment.style().content_block_size(); let content_block_size = self.fragment.style().content_block_size();
match content_block_size { match content_block_size {
NonNegativeLengthPercentageOrAuto::Auto => { Size::Auto => {
let container_size = containing_block_size?; let container_size = containing_block_size?;
let (block_start, block_end) = { let (block_start, block_end) = {
let position = self.fragment.style().logical_position(); let position = self.fragment.style().logical_position();
@ -1437,9 +1435,7 @@ impl BlockFlow {
(_, _) => None, (_, _) => None,
} }
}, },
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(containing_block_size),
lp.maybe_to_used_value(containing_block_size)
},
} }
} }
@ -1796,7 +1792,8 @@ impl BlockFlow {
.fragment .fragment
.style() .style()
.min_inline_size() .min_inline_size()
.to_used_value(self.base.block_container_inline_size); .to_used_value(self.base.block_container_inline_size)
.unwrap_or(Au(0));
let specified_inline_size = self.fragment.style().content_inline_size(); let specified_inline_size = self.fragment.style().content_inline_size();
let container_size = self.base.block_container_inline_size; let container_size = self.base.block_container_inline_size;
let inline_size = match specified_inline_size.to_used_value(container_size) { let inline_size = match specified_inline_size.to_used_value(container_size) {
@ -2025,7 +2022,7 @@ impl BlockFlow {
// If `max-width` is set, then don't perform this speculation. We guess that the // If `max-width` is set, then don't perform this speculation. We guess that the
// page set `max-width` in order to avoid hitting floats. The search box on Google // page set `max-width` in order to avoid hitting floats. The search box on Google
// SERPs falls into this category. // SERPs falls into this category.
if self.fragment.style.max_inline_size() != MaxLength::None { if self.fragment.style.max_inline_size() != MaxSize::None {
return; return;
} }
@ -2157,10 +2154,8 @@ impl Flow for BlockFlow {
// rather than bubbling up children inline width. // rather than bubbling up children inline width.
// FIXME(emilio): This should probably be writing-mode-aware. // FIXME(emilio): This should probably be writing-mode-aware.
let consult_children = match self.fragment.style().get_position().width { let consult_children = match self.fragment.style().get_position().width {
NonNegativeLengthPercentageOrAuto::Auto => true, Size::Auto => true,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None).is_none(),
lp.maybe_to_used_value(None).is_none()
},
}; };
self.bubble_inline_sizes_for_block(consult_children); self.bubble_inline_sizes_for_block(consult_children);
self.fragment self.fragment
@ -2911,7 +2906,8 @@ pub trait ISizeAndMarginsComputer {
.fragment() .fragment()
.style() .style()
.min_inline_size() .min_inline_size()
.to_used_value(containing_block_inline_size); .to_used_value(containing_block_inline_size)
.unwrap_or(Au(0));
if computed_min_inline_size > solution.inline_size { if computed_min_inline_size > solution.inline_size {
input.computed_inline_size = MaybeAuto::Specified(computed_min_inline_size); input.computed_inline_size = MaybeAuto::Specified(computed_min_inline_size);
solution = self.solve_inline_size_constraints(block, &input); solution = self.solve_inline_size_constraints(block, &input);

View file

@ -29,9 +29,7 @@ use style::logical_geometry::{Direction, LogicalSize};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::flex::FlexBasis; use style::values::computed::flex::FlexBasis;
use style::values::computed::{ use style::values::computed::{MaxSize, Size};
MaxLength, NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto,
};
use style::values::generics::flex::FlexBasis as GenericFlexBasis; use style::values::generics::flex::FlexBasis as GenericFlexBasis;
/// The size of an axis. May be a specified size, a min/max /// The size of an axis. May be a specified size, a min/max
@ -46,21 +44,12 @@ enum AxisSize {
impl AxisSize { impl AxisSize {
/// Generate a new available cross or main axis size from the specified size of the container, /// Generate a new available cross or main axis size from the specified size of the container,
/// containing block size, min constraint, and max constraint /// containing block size, min constraint, and max constraint
pub fn new( pub fn new(size: Size, content_size: Option<Au>, min: Size, max: MaxSize) -> AxisSize {
size: NonNegativeLengthPercentageOrAuto,
content_size: Option<Au>,
min: NonNegativeLengthPercentage,
max: MaxLength,
) -> AxisSize {
match size { match size {
NonNegativeLengthPercentageOrAuto::Auto => { Size::Auto => AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)),
AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)) Size::LengthPercentage(ref lp) => match lp.maybe_to_used_value(content_size) {
}, Some(length) => AxisSize::Definite(length),
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { None => AxisSize::Infinite,
match lp.maybe_to_used_value(content_size) {
Some(length) => AxisSize::Definite(length),
None => AxisSize::Infinite,
}
}, },
} }
} }
@ -70,26 +59,20 @@ impl AxisSize {
/// and the container size, then return the used value of flex basis. it can be used to help /// and the container size, then return the used value of flex basis. it can be used to help
/// determining the flex base size and to indicate whether the main size of the item /// determining the flex base size and to indicate whether the main size of the item
/// is definite after flex size resolving. /// is definite after flex size resolving.
fn from_flex_basis( fn from_flex_basis(flex_basis: FlexBasis, main_length: Size, containing_length: Au) -> MaybeAuto {
flex_basis: FlexBasis,
main_length: NonNegativeLengthPercentageOrAuto,
containing_length: Au,
) -> MaybeAuto {
let width = match flex_basis { let width = match flex_basis {
GenericFlexBasis::Content => return MaybeAuto::Auto, GenericFlexBasis::Content => return MaybeAuto::Auto,
GenericFlexBasis::Width(width) => width, GenericFlexBasis::Width(width) => width,
}; };
let width = match width { let width = match width {
NonNegativeLengthPercentageOrAuto::Auto => main_length, Size::Auto => main_length,
_ => width, _ => width,
}; };
match width { match width {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto, Size::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => MaybeAuto::Specified(lp.to_used_value(containing_length)),
MaybeAuto::Specified(lp.to_used_value(containing_length))
},
} }
} }
@ -183,7 +166,8 @@ impl FlexItem {
.fragment .fragment
.style .style
.min_inline_size() .min_inline_size()
.to_used_value(containing_length); .to_used_value(containing_length)
.unwrap_or(Au(0));
}, },
Direction::Block => { Direction::Block => {
let basis = from_flex_basis( let basis = from_flex_basis(
@ -205,7 +189,8 @@ impl FlexItem {
.fragment .fragment
.style .style
.min_block_size() .min_block_size()
.to_used_value(containing_length); .to_used_value(containing_length)
.unwrap_or(Au(0));
}, },
} }
} }

View file

@ -10,7 +10,7 @@ use std::cmp::{max, min};
use std::fmt; use std::fmt;
use style::computed_values::float::T as StyleFloat; use style::computed_values::float::T as StyleFloat;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::values::computed::NonNegativeLengthPercentageOrAuto; use style::values::computed::Size;
/// The kind of float: left or right. /// The kind of float: left or right.
#[derive(Clone, Copy, Debug, Serialize)] #[derive(Clone, Copy, Debug, Serialize)]
@ -549,8 +549,8 @@ impl SpeculatedFloatPlacement {
// might flow around this float. // might flow around this float.
let inline_size = flow.as_block().fragment.style.content_inline_size(); let inline_size = flow.as_block().fragment.style.content_inline_size();
let fixed = match inline_size { let fixed = match inline_size {
NonNegativeLengthPercentageOrAuto::Auto => false, Size::Auto => false,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
lp.0.is_definitely_zero() || lp.0.maybe_to_used_value(None).is_some() lp.0.is_definitely_zero() || lp.0.maybe_to_used_value(None).is_some()
}, },
}; };

View file

@ -61,9 +61,7 @@ use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace; use style::str::char_is_whitespace;
use style::values::computed::counters::ContentItem; use style::values::computed::counters::ContentItem;
use style::values::computed::{ use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, Size};
LengthPercentage, LengthPercentageOrAuto, NonNegativeLengthPercentageOrAuto,
};
use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::box_::{Perspective, VerticalAlign};
use style::values::generics::transform; use style::values::generics::transform;
use webrender_api::{self, LayoutTransform}; use webrender_api::{self, LayoutTransform};
@ -991,7 +989,13 @@ impl Fragment {
.content_inline_size() .content_inline_size()
.to_used_value(Au(0)) .to_used_value(Au(0))
.unwrap_or(Au(0)); .unwrap_or(Au(0));
specified = max(style.min_inline_size().to_used_value(Au(0)), specified); specified = max(
style
.min_inline_size()
.to_used_value(Au(0))
.unwrap_or(Au(0)),
specified,
);
if let Some(max) = style.max_inline_size().to_used_value(Au(0)) { if let Some(max) = style.max_inline_size().to_used_value(Au(0)) {
specified = min(specified, max) specified = min(specified, max)
} }
@ -1615,10 +1619,8 @@ impl Fragment {
SpecificFragmentInfo::Iframe(_) | SpecificFragmentInfo::Iframe(_) |
SpecificFragmentInfo::Svg(_) => { SpecificFragmentInfo::Svg(_) => {
let inline_size = match self.style.content_inline_size() { let inline_size = match self.style.content_inline_size() {
NonNegativeLengthPercentageOrAuto::Auto => None, Size::Auto => None,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
lp.maybe_to_used_value(None)
},
}; };
let mut inline_size = inline_size.unwrap_or_else(|| { let mut inline_size = inline_size.unwrap_or_else(|| {

View file

@ -11,10 +11,8 @@ use std::cmp::{max, min};
use std::fmt; use std::fmt;
use style::logical_geometry::{LogicalMargin, WritingMode}; use style::logical_geometry::{LogicalMargin, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::MaxLength; use style::values::computed::MaxSize;
use style::values::computed::{ use style::values::computed::{LengthPercentageOrAuto, Size};
LengthPercentageOrAuto, NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto,
};
/// A collapsible margin. See CSS 2.1 § 8.3.1. /// A collapsible margin. See CSS 2.1 § 8.3.1.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@ -137,15 +135,17 @@ impl MarginCollapseInfo {
MarginCollapseState::AccumulatingCollapsibleTopMargin => { MarginCollapseState::AccumulatingCollapsibleTopMargin => {
may_collapse_through = may_collapse_through && may_collapse_through = may_collapse_through &&
match fragment.style().content_block_size() { match fragment.style().content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => true, Size::Auto => true,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
lp.is_definitely_zero() || lp.is_definitely_zero() ||
lp.maybe_to_used_value(containing_block_size).is_none() lp.maybe_to_used_value(containing_block_size).is_none()
}, },
}; };
if may_collapse_through { if may_collapse_through {
if fragment.style().min_block_size().is_definitely_zero() { if fragment.style.min_block_size().is_auto() ||
fragment.style().min_block_size().is_definitely_zero()
{
FinalMarginState::MarginsCollapseThrough FinalMarginState::MarginsCollapseThrough
} else { } else {
// If the fragment has non-zero min-block-size, margins may not // If the fragment has non-zero min-block-size, margins may not
@ -498,13 +498,10 @@ impl MaybeAuto {
/// Receive an optional container size and return used value for width or height. /// Receive an optional container size and return used value for width or height.
/// ///
/// `style_length`: content size as given in the CSS. /// `style_length`: content size as given in the CSS.
pub fn style_length( pub fn style_length(style_length: Size, container_size: Option<Au>) -> MaybeAuto {
style_length: NonNegativeLengthPercentageOrAuto,
container_size: Option<Au>,
) -> MaybeAuto {
match style_length { match style_length {
NonNegativeLengthPercentageOrAuto::Auto => MaybeAuto::Auto, Size::Auto => MaybeAuto::Auto,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
MaybeAuto::from_option(lp.0.maybe_to_used_value(container_size)) MaybeAuto::from_option(lp.0.maybe_to_used_value(container_size))
}, },
} }
@ -571,17 +568,20 @@ impl SizeConstraint {
/// Create a `SizeConstraint` for an axis. /// Create a `SizeConstraint` for an axis.
pub fn new( pub fn new(
container_size: Option<Au>, container_size: Option<Au>,
min_size: NonNegativeLengthPercentage, min_size: Size,
max_size: MaxLength, max_size: MaxSize,
border: Option<Au>, border: Option<Au>,
) -> SizeConstraint { ) -> SizeConstraint {
let mut min_size = min_size let mut min_size = match min_size {
.maybe_to_used_value(container_size) Size::Auto => Au(0),
.unwrap_or(Au(0)); Size::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(container_size).unwrap_or(Au(0))
},
};
let mut max_size = match max_size { let mut max_size = match max_size {
MaxLength::None => None, MaxSize::None => None,
MaxLength::LengthPercentage(ref lp) => lp.maybe_to_used_value(container_size), MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(container_size),
}; };
// Make sure max size is not smaller than min size. // Make sure max size is not smaller than min size.

View file

@ -19,7 +19,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::{MaxLength, NonNegativeLengthPercentageOrAuto}; use style::values::computed::{MaxSize, Size};
use style::values::generics::column::ColumnCount; use style::values::generics::column::ColumnCount;
use style::values::Either; use style::values::Either;
@ -155,14 +155,12 @@ impl Flow for MulticolFlow {
available_block_size: { available_block_size: {
let style = &self.block_flow.fragment.style; let style = &self.block_flow.fragment.style;
let size = match style.content_block_size() { let size = match style.content_block_size() {
NonNegativeLengthPercentageOrAuto::Auto => None, Size::Auto => None,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
lp.maybe_to_used_value(None)
},
}; };
let size = size.or_else(|| match style.max_block_size() { let size = size.or_else(|| match style.max_block_size() {
MaxLength::None => None, MaxSize::None => None,
MaxLength::LengthPercentage(ref lp) => lp.maybe_to_used_value(None), MaxSize::LengthPercentage(ref lp) => lp.maybe_to_used_value(None),
}); });
size.unwrap_or_else(|| { size.unwrap_or_else(|| {

View file

@ -33,7 +33,7 @@ use style::logical_geometry::LogicalSize;
use style::properties::style_structs::Background; use style::properties::style_structs::Background;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::NonNegativeLengthPercentageOrAuto; use style::values::computed::Size;
use style::values::CSSFloat; use style::values::CSSFloat;
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -301,14 +301,14 @@ impl Flow for TableFlow {
self.column_intrinsic_inline_sizes self.column_intrinsic_inline_sizes
.push(ColumnIntrinsicInlineSize { .push(ColumnIntrinsicInlineSize {
minimum_length: match *specified_inline_size { minimum_length: match *specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => Au(0), Size::Auto => Au(0),
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
lp.maybe_to_used_value(None).unwrap_or(Au(0)) lp.maybe_to_used_value(None).unwrap_or(Au(0))
}, },
}, },
percentage: match *specified_inline_size { percentage: match *specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => 0.0, Size::Auto => 0.0,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
lp.0.as_percentage().map_or(0.0, |p| p.0) lp.0.as_percentage().map_or(0.0, |p| p.0)
}, },
}, },

View file

@ -21,7 +21,7 @@ use script_layout_interface::wrapper_traits::ThreadSafeLayoutNode;
use std::fmt; use std::fmt;
use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::length::NonNegativeLengthPercentageOrAuto; use style::values::computed::length::Size;
use style::values::computed::Color; use style::values::computed::Color;
use style::values::generics::box_::VerticalAlign; use style::values::generics::box_::VerticalAlign;
use style::values::specified::BorderStyle; use style::values::specified::BorderStyle;
@ -203,8 +203,8 @@ impl Flow for TableCellFlow {
self.block_flow.bubble_inline_sizes_for_block(true); self.block_flow.bubble_inline_sizes_for_block(true);
let specified_inline_size = match self.block_flow.fragment.style().content_inline_size() { let specified_inline_size = match self.block_flow.fragment.style().content_inline_size() {
NonNegativeLengthPercentageOrAuto::Auto => Au(0), Size::Auto => Au(0),
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => lp.to_used_value(Au(0)), Size::LengthPercentage(ref lp) => lp.to_used_value(Au(0)),
}; };
if self if self

View file

@ -14,7 +14,7 @@ use euclid::Point2D;
use std::fmt; use std::fmt;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::NonNegativeLengthPercentageOrAuto; use style::values::computed::Size;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe impl crate::flow::HasBaseFlow for TableColGroupFlow {} unsafe impl crate::flow::HasBaseFlow for TableColGroupFlow {}
@ -34,7 +34,7 @@ pub struct TableColGroupFlow {
/// The specified inline-sizes of table columns. (We use `LengthPercentageOrAuto` here in /// The specified inline-sizes of table columns. (We use `LengthPercentageOrAuto` here in
/// lieu of `ColumnInlineSize` because column groups do not establish minimum or preferred /// lieu of `ColumnInlineSize` because column groups do not establish minimum or preferred
/// inline sizes.) /// inline sizes.)
pub inline_sizes: Vec<NonNegativeLengthPercentageOrAuto>, pub inline_sizes: Vec<Size>,
} }
impl TableColGroupFlow { impl TableColGroupFlow {

View file

@ -29,7 +29,7 @@ use style::computed_values::border_spacing::T as BorderSpacing;
use style::computed_values::border_top_style::T as BorderStyle; use style::computed_values::border_top_style::T as BorderStyle;
use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::{Color, NonNegativeLengthPercentageOrAuto}; use style::values::computed::{Color, Size};
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe impl crate::flow::HasBaseFlow for TableRowFlow {} unsafe impl crate::flow::HasBaseFlow for TableRowFlow {}
@ -429,24 +429,18 @@ impl Flow for TableRowFlow {
let child_base = kid.mut_base(); let child_base = kid.mut_base();
let child_column_inline_size = ColumnIntrinsicInlineSize { let child_column_inline_size = ColumnIntrinsicInlineSize {
minimum_length: match child_specified_inline_size { minimum_length: match child_specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => None, Size::Auto => None,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.0.maybe_to_used_value(None),
lp.0.maybe_to_used_value(None)
},
} }
.unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size), .unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size),
percentage: match child_specified_inline_size { percentage: match child_specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => 0.0, Size::Auto => 0.0,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.0.as_percentage().map_or(0.0, |p| p.0),
lp.0.as_percentage().map_or(0.0, |p| p.0)
},
}, },
preferred: child_base.intrinsic_inline_sizes.preferred_inline_size, preferred: child_base.intrinsic_inline_sizes.preferred_inline_size,
constrained: match child_specified_inline_size { constrained: match child_specified_inline_size {
NonNegativeLengthPercentageOrAuto::Auto => false, Size::Auto => false,
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => lp.0.maybe_to_used_value(None).is_some(),
lp.0.maybe_to_used_value(None).is_some()
},
}, },
}; };
min_inline_size = min_inline_size + child_column_inline_size.minimum_length; min_inline_size = min_inline_size + child_column_inline_size.minimum_length;

View file

@ -33,7 +33,7 @@ use style::computed_values::{position, table_layout};
use style::context::SharedStyleContext; use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalRect, LogicalSize}; use style::logical_geometry::{LogicalRect, LogicalSize};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::NonNegativeLengthPercentageOrAuto; use style::values::computed::Size;
use style::values::CSSFloat; use style::values::CSSFloat;
#[derive(Clone, Copy, Debug, Serialize)] #[derive(Clone, Copy, Debug, Serialize)]
@ -201,7 +201,7 @@ impl TableWrapperFlow {
// says "the basic idea is the same as the shrink-to-fit width that CSS2.1 defines". So we // says "the basic idea is the same as the shrink-to-fit width that CSS2.1 defines". So we
// just use the shrink-to-fit inline size. // just use the shrink-to-fit inline size.
let available_inline_size = match self.block_flow.fragment.style().content_inline_size() { let available_inline_size = match self.block_flow.fragment.style().content_inline_size() {
NonNegativeLengthPercentageOrAuto::Auto => { Size::Auto => {
self.block_flow self.block_flow
.get_shrink_to_fit_inline_size(available_inline_size) - .get_shrink_to_fit_inline_size(available_inline_size) -
table_border_padding table_border_padding
@ -841,7 +841,7 @@ fn initial_computed_inline_size(
table_border_padding: Au, table_border_padding: Au,
) -> MaybeAuto { ) -> MaybeAuto {
match block.fragment.style.content_inline_size() { match block.fragment.style.content_inline_size() {
NonNegativeLengthPercentageOrAuto::Auto => { Size::Auto => {
if preferred_width_of_all_columns + table_border_padding <= containing_block_inline_size if preferred_width_of_all_columns + table_border_padding <= containing_block_inline_size
{ {
MaybeAuto::Specified(preferred_width_of_all_columns + table_border_padding) MaybeAuto::Specified(preferred_width_of_all_columns + table_border_padding)
@ -851,7 +851,7 @@ fn initial_computed_inline_size(
MaybeAuto::Auto MaybeAuto::Auto
} }
}, },
NonNegativeLengthPercentageOrAuto::LengthPercentage(ref lp) => { Size::LengthPercentage(ref lp) => {
let used = lp.to_used_value(containing_block_inline_size); let used = lp.to_used_value(containing_block_inline_size);
MaybeAuto::Specified(max( MaybeAuto::Specified(max(
used - table_border_padding, used - table_border_padding,

View file

@ -718,11 +718,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)); specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width( PropertyDeclaration::Width(specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length(value),
specified::LengthPercentage::Length(value), ))),
)),
),
)); ));
} }
@ -747,22 +745,20 @@ impl LayoutElementHelpers for LayoutDom<Element> {
match width { match width {
LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Auto => {},
LengthOrPercentageOrAuto::Percentage(percentage) => { LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = let width_value = specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Percentage(computed::Percentage(percentage)),
specified::LengthPercentage::Percentage(computed::Percentage(percentage)), ));
));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width(width_value), PropertyDeclaration::Width(width_value),
)); ));
}, },
LengthOrPercentageOrAuto::Length(length) => { LengthOrPercentageOrAuto::Length(length) => {
let width_value = let width_value = specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length(specified::NoCalcLength::Absolute(
specified::LengthPercentage::Length(specified::NoCalcLength::Absolute( specified::AbsoluteLength::Px(length.to_f32_px()),
specified::AbsoluteLength::Px(length.to_f32_px()), )),
)), ));
));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width(width_value), PropertyDeclaration::Width(width_value),
@ -783,22 +779,20 @@ impl LayoutElementHelpers for LayoutDom<Element> {
match height { match height {
LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Auto => {},
LengthOrPercentageOrAuto::Percentage(percentage) => { LengthOrPercentageOrAuto::Percentage(percentage) => {
let height_value = let height_value = specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Percentage(computed::Percentage(percentage)),
specified::LengthPercentage::Percentage(computed::Percentage(percentage)), ));
));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Height(height_value), PropertyDeclaration::Height(height_value),
)); ));
}, },
LengthOrPercentageOrAuto::Length(length) => { LengthOrPercentageOrAuto::Length(length) => {
let height_value = let height_value = specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length(specified::NoCalcLength::Absolute(
specified::LengthPercentage::Length(specified::NoCalcLength::Absolute( specified::AbsoluteLength::Px(length.to_f32_px()),
specified::AbsoluteLength::Px(length.to_f32_px()), )),
)), ));
));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Height(height_value), PropertyDeclaration::Height(height_value),
@ -825,11 +819,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)); specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Width( PropertyDeclaration::Width(specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length(value),
specified::LengthPercentage::Length(value), ))),
)),
),
)); ));
} }
@ -851,11 +843,9 @@ impl LayoutElementHelpers for LayoutDom<Element> {
)); ));
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, shared_lock,
PropertyDeclaration::Height( PropertyDeclaration::Height(specified::Size::LengthPercentage(NonNegative(
specified::NonNegativeLengthPercentageOrAuto::LengthPercentage(NonNegative( specified::LengthPercentage::Length(value),
specified::LengthPercentage::Length(value), ))),
)),
),
)); ));
} }

View file

@ -14,7 +14,7 @@ use crate::media_queries::Device;
use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use crate::values::computed::FlexBasis as ComputedFlexBasis; use crate::values::computed::FlexBasis as ComputedFlexBasis;
use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage}; use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage};
use crate::values::computed::{MaxLength as ComputedMaxLength, MozLength as ComputedMozLength}; use crate::values::computed::{MaxSize as ComputedMaxSize, Size as ComputedSize};
use crate::values::computed::{NonNegativeLengthPercentage, Percentage}; use crate::values::computed::{NonNegativeLengthPercentage, Percentage};
use crate::values::computed::{Number, NumberOrPercentage}; use crate::values::computed::{Number, NumberOrPercentage};
use crate::values::generics::basic_shape::ShapeRadius; use crate::values::generics::basic_shape::ShapeRadius;
@ -22,7 +22,7 @@ use crate::values::generics::box_::Perspective;
use crate::values::generics::flex::FlexBasis; use crate::values::generics::flex::FlexBasis;
use crate::values::generics::gecko::ScrollSnapPoint; use crate::values::generics::gecko::ScrollSnapPoint;
use crate::values::generics::grid::{TrackBreadth, TrackKeyword}; use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
use crate::values::generics::length::{LengthPercentageOrAuto, MaxLength, MozLength}; use crate::values::generics::length::{LengthPercentageOrAuto, MaxSize, Size};
use crate::values::generics::{CounterStyleOrNone, NonNegative}; use crate::values::generics::{CounterStyleOrNone, NonNegative};
use crate::values::{Auto, Either, None_, Normal}; use crate::values::{Auto, Either, None_, Normal};
use crate::Atom; use crate::Atom;
@ -91,7 +91,7 @@ impl GeckoStyleCoordConvertible for ComputedFlexBasis {
} }
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
if let Some(width) = ComputedMozLength::from_gecko_style_coord(coord) { if let Some(width) = ComputedSize::from_gecko_style_coord(coord) {
return Some(FlexBasis::Width(width)); return Some(FlexBasis::Width(width));
} }
@ -350,43 +350,43 @@ impl GeckoStyleCoordConvertible for ExtremumLength {
} }
} }
impl GeckoStyleCoordConvertible for ComputedMozLength { impl GeckoStyleCoordConvertible for ComputedSize {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) { fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self { match *self {
MozLength::LengthPercentage(ref lpoa) => lpoa.to_gecko_style_coord(coord), Size::LengthPercentage(ref lpoa) => lpoa.to_gecko_style_coord(coord),
MozLength::Auto => coord.set_value(CoordDataValue::Auto), Size::Auto => coord.set_value(CoordDataValue::Auto),
MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), Size::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
} }
} }
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
if let CoordDataValue::Auto = coord.as_value() { if let CoordDataValue::Auto = coord.as_value() {
return Some(MozLength::Auto); return Some(Size::Auto);
} }
if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) {
return Some(MozLength::LengthPercentage(lp)); return Some(Size::LengthPercentage(lp));
} }
ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength) ExtremumLength::from_gecko_style_coord(coord).map(Size::ExtremumLength)
} }
} }
impl GeckoStyleCoordConvertible for ComputedMaxLength { impl GeckoStyleCoordConvertible for ComputedMaxSize {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) { fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self { match *self {
MaxLength::LengthPercentage(ref lpon) => lpon.to_gecko_style_coord(coord), MaxSize::LengthPercentage(ref lpon) => lpon.to_gecko_style_coord(coord),
MaxLength::None => coord.set_value(CoordDataValue::None), MaxSize::None => coord.set_value(CoordDataValue::None),
MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), MaxSize::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
} }
} }
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
if let CoordDataValue::None = coord.as_value() { if let CoordDataValue::None = coord.as_value() {
return Some(MaxLength::None); return Some(MaxSize::None);
} }
if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) { if let Some(lp) = NonNegativeLengthPercentage::from_gecko_style_coord(coord) {
return Some(MaxLength::LengthPercentage(lp)); return Some(MaxSize::LengthPercentage(lp));
} }
ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength) ExtremumLength::from_gecko_style_coord(coord).map(MaxSize::ExtremumLength)
} }
} }

View file

@ -1390,8 +1390,8 @@ impl Clone for ${style_struct.gecko_struct_name} {
"LengthOrNormal": impl_style_coord, "LengthOrNormal": impl_style_coord,
"LengthPercentage": impl_simple, "LengthPercentage": impl_simple,
"LengthPercentageOrAuto": impl_style_coord, "LengthPercentageOrAuto": impl_style_coord,
"MaxLength": impl_style_coord, "MaxSize": impl_style_coord,
"MozLength": impl_style_coord, "Size": impl_style_coord,
"MozScriptMinSize": impl_absolute_length, "MozScriptMinSize": impl_absolute_length,
"MozScriptSizeMultiplier": impl_simple, "MozScriptSizeMultiplier": impl_simple,
"NonNegativeLengthPercentage": impl_simple, "NonNegativeLengthPercentage": impl_simple,

View file

@ -244,65 +244,40 @@ ${helpers.predefined_type(
if logical: if logical:
spec = "https://drafts.csswg.org/css-logical-props/#propdef-%s" spec = "https://drafts.csswg.org/css-logical-props/#propdef-%s"
%> %>
% if product == "gecko": // width, height, block-size, inline-size
// width, height, block-size, inline-size ${helpers.predefined_type(
${helpers.predefined_type( size,
size, "Size",
"MozLength", "computed::Size::auto()",
"computed::MozLength::auto()", logical=logical,
logical=logical, logical_group="size",
logical_group="size", allow_quirks=not logical,
allow_quirks=not logical, spec=spec % size,
spec=spec % size, animation_value_type="Size",
animation_value_type="MozLength", flags="GETCS_NEEDS_LAYOUT_FLUSH",
flags="GETCS_NEEDS_LAYOUT_FLUSH", servo_restyle_damage="reflow",
servo_restyle_damage="reflow", )}
)} // min-width, min-height, min-block-size, min-inline-size
// min-width, min-height, min-block-size, min-inline-size, ${helpers.predefined_type(
${helpers.predefined_type( "min-%s" % size,
"min-%s" % size, "Size",
"MozLength", "computed::Size::auto()",
"computed::MozLength::auto()", logical=logical,
logical=logical, logical_group="min-size",
logical_group="min-size", allow_quirks=not logical,
allow_quirks=not logical, spec=spec % size,
spec=spec % size, animation_value_type="Size",
animation_value_type="MozLength", servo_restyle_damage="reflow",
servo_restyle_damage="reflow", )}
)}
% else:
// servo versions (no keyword support)
${helpers.predefined_type(
size,
"NonNegativeLengthPercentageOrAuto",
"computed::NonNegativeLengthPercentageOrAuto::auto()",
spec=spec % size,
logical_group="size",
allow_quirks=not logical,
animation_value_type="ComputedValue", logical = logical,
servo_restyle_damage="reflow",
)}
${helpers.predefined_type(
"min-%s" % size,
"NonNegativeLengthPercentage",
"computed::NonNegativeLengthPercentage::zero()",
spec=spec % ("min-%s" % size),
logical_group="min-size",
animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical,
servo_restyle_damage="reflow",
)}
% endif
${helpers.predefined_type( ${helpers.predefined_type(
"max-%s" % size, "max-%s" % size,
"MaxLength", "MaxSize",
"computed::MaxLength::none()", "computed::MaxSize::none()",
logical=logical, logical=logical,
logical_group="max-size", logical_group="max-size",
allow_quirks=not logical, allow_quirks=not logical,
spec=spec % size, spec=spec % size,
animation_value_type="MaxLength", animation_value_type="MaxSize",
servo_restyle_damage="reflow", servo_restyle_damage="reflow",
)} )}
% endfor % endfor

View file

@ -3016,7 +3016,7 @@ impl ComputedValuesInner {
/// Get the logical computed inline size. /// Get the logical computed inline size.
#[inline] #[inline]
pub fn content_inline_size(&self) -> computed::NonNegativeLengthPercentageOrAuto { pub fn content_inline_size(&self) -> computed::Size {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { if self.writing_mode.is_vertical() {
position_style.height position_style.height
@ -3027,35 +3027,35 @@ impl ComputedValuesInner {
/// Get the logical computed block size. /// Get the logical computed block size.
#[inline] #[inline]
pub fn content_block_size(&self) -> computed::NonNegativeLengthPercentageOrAuto { pub fn content_block_size(&self) -> computed::Size {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } if self.writing_mode.is_vertical() { position_style.width } else { position_style.height }
} }
/// Get the logical computed min inline size. /// Get the logical computed min inline size.
#[inline] #[inline]
pub fn min_inline_size(&self) -> computed::NonNegativeLengthPercentage { pub fn min_inline_size(&self) -> computed::Size {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width } if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width }
} }
/// Get the logical computed min block size. /// Get the logical computed min block size.
#[inline] #[inline]
pub fn min_block_size(&self) -> computed::NonNegativeLengthPercentage { pub fn min_block_size(&self) -> computed::Size {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height } if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height }
} }
/// Get the logical computed max inline size. /// Get the logical computed max inline size.
#[inline] #[inline]
pub fn max_inline_size(&self) -> computed::MaxLength { pub fn max_inline_size(&self) -> computed::MaxSize {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width } if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width }
} }
/// Get the logical computed max block size. /// Get the logical computed max block size.
#[inline] #[inline]
pub fn max_block_size(&self) -> computed::MaxLength { pub fn max_block_size(&self) -> computed::MaxSize {
let position_style = self.get_position(); let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height } if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height }
} }

View file

@ -4,23 +4,16 @@
//! Computed types for CSS values related to flexbox. //! Computed types for CSS values related to flexbox.
use crate::values::computed::Size;
use crate::values::generics::flex::FlexBasis as GenericFlexBasis; use crate::values::generics::flex::FlexBasis as GenericFlexBasis;
/// The `width` value type.
#[cfg(feature = "servo")]
pub type Width = crate::values::computed::NonNegativeLengthPercentageOrAuto;
/// The `width` value type.
#[cfg(feature = "gecko")]
pub type Width = crate::values::computed::MozLength;
/// A computed value for the `flex-basis` property. /// A computed value for the `flex-basis` property.
pub type FlexBasis = GenericFlexBasis<Width>; pub type FlexBasis = GenericFlexBasis<Size>;
impl FlexBasis { impl FlexBasis {
/// `auto` /// `auto`
#[inline] #[inline]
pub fn auto() -> Self { pub fn auto() -> Self {
GenericFlexBasis::Width(Width::auto()) GenericFlexBasis::Width(Size::auto())
} }
} }

View file

@ -8,9 +8,7 @@ use super::{Context, Number, Percentage, ToComputedValue};
use crate::values::animated::ToAnimatedValue; use crate::values::animated::ToAnimatedValue;
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
use crate::values::generics::length as generics; use crate::values::generics::length as generics;
use crate::values::generics::length::{ use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize};
MaxLength as GenericMaxLength, MozLength as GenericMozLength,
};
use crate::values::generics::transform::IsZeroLength; use crate::values::generics::transform::IsZeroLength;
use crate::values::generics::NonNegative; use crate::values::generics::NonNegative;
use crate::values::specified::length::ViewportPercentageLength; use crate::values::specified::length::ViewportPercentageLength;
@ -580,12 +578,36 @@ impl NonNegativeLengthPercentage {
} }
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
impl MaxLength { impl MaxSize {
/// Convert the computed value into used value. /// Convert the computed value into used value.
#[inline]
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> { pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
match *self { match *self {
GenericMaxLength::None => None, GenericMaxSize::None => None,
GenericMaxLength::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)), GenericMaxSize::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
}
}
}
impl Size {
/// Convert the computed value into used value.
#[inline]
#[cfg(feature = "servo")]
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
match *self {
GenericSize::Auto => None,
GenericSize::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
}
}
/// Returns true if the computed value is absolute 0 or 0%.
#[inline]
pub fn is_definitely_zero(&self) -> bool {
match *self {
GenericSize::Auto => false,
GenericSize::LengthPercentage(ref lp) => lp.is_definitely_zero(),
#[cfg(feature = "gecko")]
GenericSize::ExtremumLength(..) => false,
} }
} }
} }
@ -821,7 +843,7 @@ pub enum ExtremumLength {
} }
/// A computed value for `min-width`, `min-height`, `width` or `height` property. /// A computed value for `min-width`, `min-height`, `width` or `height` property.
pub type MozLength = GenericMozLength<NonNegativeLengthPercentage>; pub type Size = GenericSize<NonNegativeLengthPercentage>;
/// A computed value for `max-width` or `min-height` property. /// A computed value for `max-width` or `min-height` property.
pub type MaxLength = GenericMaxLength<NonNegativeLengthPercentage>; pub type MaxSize = GenericMaxSize<NonNegativeLengthPercentage>;

View file

@ -62,7 +62,7 @@ pub use self::gecko::ScrollSnapPoint;
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect}; pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength};
pub use self::length::{Length, LengthOrNumber, LengthPercentage}; pub use self::length::{Length, LengthOrNumber, LengthPercentage};
pub use self::length::{LengthPercentageOrAuto, MaxLength, MozLength}; pub use self::length::{LengthPercentageOrAuto, MaxSize, Size};
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use self::list::ListStyleType; pub use self::list::ListStyleType;

View file

@ -5,6 +5,7 @@
//! Generic types for CSS values related to length. //! Generic types for CSS values related to length.
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
#[cfg(feature = "gecko")]
use crate::values::computed::ExtremumLength; use crate::values::computed::ExtremumLength;
use cssparser::Parser; use cssparser::Parser;
use style_traits::ParseError; use style_traits::ParseError;
@ -76,7 +77,7 @@ impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage>
/// A generic value for the `width`, `height`, `min-width`, or `min-height` property. /// A generic value for the `width`, `height`, `min-width`, or `min-height` property.
/// ///
/// Unlike `max-width` or `max-height` properties, a MozLength can be `auto`, /// Unlike `max-width` or `max-height` properties, a Size can be `auto`,
/// and cannot be `none`. /// and cannot be `none`.
/// ///
/// Note that it only accepts non-negative values. /// Note that it only accepts non-negative values.
@ -95,18 +96,25 @@ impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage>
ToComputedValue, ToComputedValue,
ToCss, ToCss,
)] )]
pub enum MozLength<LengthPercentage> { pub enum Size<LengthPercentage> {
LengthPercentage(LengthPercentage), LengthPercentage(LengthPercentage),
Auto, Auto,
#[cfg(feature = "gecko")]
#[animation(error)] #[animation(error)]
ExtremumLength(ExtremumLength), ExtremumLength(ExtremumLength),
} }
impl<LengthPercentage> MozLength<LengthPercentage> { impl<LengthPercentage> Size<LengthPercentage> {
/// `auto` value. /// `auto` value.
#[inline] #[inline]
pub fn auto() -> Self { pub fn auto() -> Self {
MozLength::Auto Size::Auto
}
/// Returns whether we're the auto value.
#[inline]
pub fn is_auto(&self) -> bool {
matches!(*self, Size::Auto)
} }
} }
@ -126,7 +134,7 @@ impl<LengthPercentage> MozLength<LengthPercentage> {
ToComputedValue, ToComputedValue,
ToCss, ToCss,
)] )]
pub enum MaxLength<LengthPercentage> { pub enum MaxSize<LengthPercentage> {
LengthPercentage(LengthPercentage), LengthPercentage(LengthPercentage),
None, None,
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -134,10 +142,10 @@ pub enum MaxLength<LengthPercentage> {
ExtremumLength(ExtremumLength), ExtremumLength(ExtremumLength),
} }
impl<LengthPercentage> MaxLength<LengthPercentage> { impl<LengthPercentage> MaxSize<LengthPercentage> {
/// `none` value. /// `none` value.
#[inline] #[inline]
pub fn none() -> Self { pub fn none() -> Self {
MaxLength::None MaxSize::None
} }
} }

View file

@ -6,26 +6,19 @@
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
use crate::values::generics::flex::FlexBasis as GenericFlexBasis; use crate::values::generics::flex::FlexBasis as GenericFlexBasis;
use crate::values::specified::Size;
use cssparser::Parser; use cssparser::Parser;
use style_traits::ParseError; use style_traits::ParseError;
/// The `width` value type.
#[cfg(feature = "servo")]
pub type Width = crate::values::specified::NonNegativeLengthPercentageOrAuto;
/// The `width` value type.
#[cfg(feature = "gecko")]
pub type Width = crate::values::specified::MozLength;
/// A specified value for the `flex-basis` property. /// A specified value for the `flex-basis` property.
pub type FlexBasis = GenericFlexBasis<Width>; pub type FlexBasis = GenericFlexBasis<Size>;
impl Parse for FlexBasis { impl Parse for FlexBasis {
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(width) = input.try(|i| Width::parse(context, i)) { if let Ok(width) = input.try(|i| Size::parse(context, i)) {
return Ok(GenericFlexBasis::Width(width)); return Ok(GenericFlexBasis::Width(width));
} }
try_match_ident_ignore_ascii_case! { input, try_match_ident_ignore_ascii_case! { input,
@ -38,12 +31,12 @@ impl FlexBasis {
/// `auto` /// `auto`
#[inline] #[inline]
pub fn auto() -> Self { pub fn auto() -> Self {
GenericFlexBasis::Width(Width::auto()) GenericFlexBasis::Width(Size::auto())
} }
/// `0%` /// `0%`
#[inline] #[inline]
pub fn zero_percent() -> Self { pub fn zero_percent() -> Self {
GenericFlexBasis::Width(Width::zero_percent()) GenericFlexBasis::Width(Size::zero_percent())
} }
} }

View file

@ -9,11 +9,9 @@
use super::{AllowQuirks, Number, Percentage, ToComputedValue}; use super::{AllowQuirks, Number, Percentage, ToComputedValue};
use crate::font_metrics::FontMetricsQueryResult; use crate::font_metrics::FontMetricsQueryResult;
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
use crate::values::computed::{self, CSSPixelLength, Context, ExtremumLength}; use crate::values::computed::{self, CSSPixelLength, Context};
use crate::values::generics::length as generics; use crate::values::generics::length as generics;
use crate::values::generics::length::{ use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize};
MaxLength as GenericMaxLength, MozLength as GenericMozLength,
};
use crate::values::generics::transform::IsZeroLength; use crate::values::generics::transform::IsZeroLength;
use crate::values::generics::NonNegative; use crate::values::generics::NonNegative;
use crate::values::specified::calc::CalcNode; use crate::values::specified::calc::CalcNode;
@ -1051,56 +1049,18 @@ impl LengthOrNumber {
} }
/// A specified value for `min-width`, `min-height`, `width` or `height` property. /// A specified value for `min-width`, `min-height`, `width` or `height` property.
pub type MozLength = GenericMozLength<NonNegativeLengthPercentage>; pub type Size = GenericSize<NonNegativeLengthPercentage>;
impl Parse for MozLength { impl Parse for Size {
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
MozLength::parse_quirky(context, input, AllowQuirks::No) Size::parse_quirky(context, input, AllowQuirks::No)
} }
} }
impl MozLength { impl Size {
/// Parses, with quirks.
pub fn parse_quirky<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.try(ExtremumLength::parse) {
return Ok(GenericMozLength::ExtremumLength(l));
}
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericMozLength::Auto);
}
let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?;
Ok(GenericMozLength::LengthPercentage(length))
}
/// Returns `0%`.
#[inline]
pub fn zero_percent() -> Self {
GenericMozLength::LengthPercentage(NonNegativeLengthPercentage::zero_percent())
}
}
/// A specified value for `max-width` or `max-height` property.
pub type MaxLength = GenericMaxLength<NonNegativeLengthPercentage>;
impl Parse for MaxLength {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
MaxLength::parse_quirky(context, input, AllowQuirks::No)
}
}
impl MaxLength {
/// Parses, with quirks. /// Parses, with quirks.
pub fn parse_quirky<'i, 't>( pub fn parse_quirky<'i, 't>(
context: &ParserContext, context: &ParserContext,
@ -1109,16 +1069,57 @@ impl MaxLength {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if let Ok(l) = input.try(ExtremumLength::parse) { if let Ok(l) = input.try(computed::ExtremumLength::parse) {
return Ok(GenericMaxLength::ExtremumLength(l)); return Ok(GenericSize::ExtremumLength(l));
}
}
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericSize::Auto);
}
let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?;
Ok(GenericSize::LengthPercentage(length))
}
/// Returns `0%`.
#[inline]
pub fn zero_percent() -> Self {
GenericSize::LengthPercentage(NonNegativeLengthPercentage::zero_percent())
}
}
/// A specified value for `max-width` or `max-height` property.
pub type MaxSize = GenericMaxSize<NonNegativeLengthPercentage>;
impl Parse for MaxSize {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
MaxSize::parse_quirky(context, input, AllowQuirks::No)
}
}
impl MaxSize {
/// Parses, with quirks.
pub fn parse_quirky<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
#[cfg(feature = "gecko")]
{
if let Ok(l) = input.try(computed::ExtremumLength::parse) {
return Ok(GenericMaxSize::ExtremumLength(l));
} }
} }
if input.try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(GenericMaxLength::None); return Ok(GenericMaxSize::None);
} }
let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?; let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?;
Ok(GenericMaxLength::LengthPercentage(length)) Ok(GenericMaxSize::LengthPercentage(length))
} }
} }

View file

@ -59,7 +59,7 @@ pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRec
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth}; pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
pub use self::length::{FontRelativeLength, Length, LengthOrNumber}; pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
pub use self::length::{LengthPercentage, LengthPercentageOrAuto}; pub use self::length::{LengthPercentage, LengthPercentageOrAuto};
pub use self::length::{MaxLength, MozLength}; pub use self::length::{MaxSize, Size};
pub use self::length::{NoCalcLength, ViewportPercentageLength}; pub use self::length::{NoCalcLength, ViewportPercentageLength};
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]

View file

@ -1,7 +1,7 @@
[flexbox_computedstyle_min-auto-size.html] [flexbox_computedstyle_min-auto-size.html]
[Computed min-width/min-height of specified auto for flex item.] [Computed min-width/min-height of specified auto inside display:none which would otherwise have been a flex item.]
expected: FAIL expected: FAIL
[Computed min-width/min-height of specified auto for flex item inside display:contents.] [Computed min-width/min-height of specified auto with display:none which would otherwise have been a flex item.]
expected: FAIL expected: FAIL

View file

@ -1,5 +0,0 @@
[flexbox_computedstyle_min-height-auto.html]
type: testharness
[flexbox | computed style | min-height: auto]
expected: FAIL

View file

@ -1,5 +0,0 @@
[flexbox_computedstyle_min-width-auto.html]
type: testharness
[flexbox | computed style | min-width: auto]
expected: FAIL