diff --git a/components/layout/block.rs b/components/layout/block.rs index 823d5226ea1..8c4a8a771aa 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -66,8 +66,7 @@ use style::context::SharedStyleContext; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::ComputedValues; use style::servo::restyle_damage::ServoRestyleDamage; -use style::values::computed::LengthOrPercentageOrAuto; -use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone}; +use style::values::computed::{LengthPercentageOrAuto, LengthPercentageOrNone}; /// Information specific to floated blocks. #[derive(Clone, Serialize)] @@ -418,42 +417,26 @@ impl CandidateBSizeIterator { // If that is not determined yet by the time we need to resolve // `min-height` and `max-height`, percentage values are ignored. - let block_size = match ( - fragment.style.content_block_size(), - block_container_block_size, - ) { - (LengthOrPercentageOrAuto::Percentage(percent), Some(block_container_block_size)) => { - MaybeAuto::Specified(block_container_block_size.scale_by(percent.0)) + let block_size = match fragment.style.content_block_size() { + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size)) }, - (LengthOrPercentageOrAuto::Calc(calc), _) => { - MaybeAuto::from_option(calc.to_used_value(block_container_block_size)) - }, - (LengthOrPercentageOrAuto::Percentage(_), None) | - (LengthOrPercentageOrAuto::Auto, _) => MaybeAuto::Auto, - (LengthOrPercentageOrAuto::Length(length), _) => MaybeAuto::Specified(Au::from(length)), }; - let max_block_size = match (fragment.style.max_block_size(), block_container_block_size) { - (LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) => { - Some(block_container_block_size.scale_by(percent.0)) + + let max_block_size = match fragment.style.max_block_size() { + LengthPercentageOrNone::None => None, + LengthPercentageOrNone::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(block_container_block_size) }, - (LengthOrPercentageOrNone::Calc(calc), _) => { - calc.to_used_value(block_container_block_size) - }, - (LengthOrPercentageOrNone::Percentage(_), None) | - (LengthOrPercentageOrNone::None, _) => None, - (LengthOrPercentageOrNone::Length(length), _) => Some(Au::from(length)), - }; - let min_block_size = match (fragment.style.min_block_size(), block_container_block_size) { - (LengthOrPercentage::Percentage(percent), Some(block_container_block_size)) => { - block_container_block_size.scale_by(percent.0) - }, - (LengthOrPercentage::Calc(calc), _) => calc - .to_used_value(block_container_block_size) - .unwrap_or(Au(0)), - (LengthOrPercentage::Percentage(_), None) => Au(0), - (LengthOrPercentage::Length(length), _) => Au::from(length), }; + let min_block_size = fragment + .style + .min_block_size() + .maybe_to_used_value(block_container_block_size) + .unwrap_or(Au(0)); + // 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 { BoxSizing::BorderBox => fragment.border_padding.block_start_end(), @@ -1415,15 +1398,9 @@ impl BlockFlow { pub fn explicit_block_size(&self, containing_block_size: Option) -> Option { let content_block_size = self.fragment.style().content_block_size(); - match (content_block_size, containing_block_size) { - (LengthOrPercentageOrAuto::Calc(calc), _) => calc.to_used_value(containing_block_size), - (LengthOrPercentageOrAuto::Length(length), _) => Some(Au::from(length)), - (LengthOrPercentageOrAuto::Percentage(percent), Some(container_size)) => { - Some(container_size.scale_by(percent.0)) - }, - (LengthOrPercentageOrAuto::Percentage(_), None) | - (LengthOrPercentageOrAuto::Auto, None) => None, - (LengthOrPercentageOrAuto::Auto, Some(container_size)) => { + match content_block_size { + LengthPercentageOrAuto::Auto => { + let container_size = containing_block_size?; let (block_start, block_end) = { let position = self.fragment.style().logical_position(); ( @@ -1441,11 +1418,11 @@ impl BlockFlow { // calculated during assign-inline-size. let margin = self.fragment.style().logical_margin(); let margin_block_start = match margin.block_start { - LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, _ => MaybeAuto::Specified(self.fragment.margin.block_start), }; let margin_block_end = match margin.block_end { - LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, _ => MaybeAuto::Specified(self.fragment.margin.block_end), }; @@ -1454,10 +1431,12 @@ impl BlockFlow { let sum = block_start + block_end + margin_block_start + margin_block_end; Some(available_block_size - sum) }, - (_, _) => None, } }, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(containing_block_size) + }, } } @@ -1476,11 +1455,11 @@ impl BlockFlow { // calculated during assign-inline-size. let margin = self.fragment.style().logical_margin(); let margin_block_start = match margin.block_start { - LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, _ => MaybeAuto::Specified(self.fragment.margin.block_start), }; let margin_block_end = match margin.block_end { - LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, _ => MaybeAuto::Specified(self.fragment.margin.block_end), }; @@ -2046,7 +2025,7 @@ impl BlockFlow { // 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 // SERPs falls into this category. - if self.fragment.style.max_inline_size() != LengthOrPercentageOrNone::None { + if self.fragment.style.max_inline_size() != LengthPercentageOrNone::None { return; } @@ -2177,8 +2156,10 @@ impl Flow for BlockFlow { // If this block has a fixed width, just use that for the minimum and preferred width, // rather than bubbling up children inline width. let consult_children = match self.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => false, - _ => true, + LengthPercentageOrAuto::Auto => true, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None).is_none() + }, }; self.bubble_inline_sizes_for_block(consult_children); self.fragment @@ -2564,9 +2545,8 @@ impl Flow for BlockFlow { .base .flags .contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && - self.fragment.style().logical_position().inline_start == - LengthOrPercentageOrAuto::Auto && - self.fragment.style().logical_position().inline_end == LengthOrPercentageOrAuto::Auto + self.fragment.style().logical_position().inline_start == LengthPercentageOrAuto::Auto && + self.fragment.style().logical_position().inline_end == LengthPercentageOrAuto::Auto { self.base.position.start.i = inline_position } @@ -2577,9 +2557,8 @@ impl Flow for BlockFlow { .base .flags .contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && - self.fragment.style().logical_position().block_start == - LengthOrPercentageOrAuto::Auto && - self.fragment.style().logical_position().block_end == LengthOrPercentageOrAuto::Auto + self.fragment.style().logical_position().block_start == LengthPercentageOrAuto::Auto && + self.fragment.style().logical_position().block_end == LengthPercentageOrAuto::Auto { self.base.position.start.b = block_position } diff --git a/components/layout/display_list/background.rs b/components/layout/display_list/background.rs index 89d6aebb0db..d914a97e1bf 100644 --- a/components/layout/display_list/background.rs +++ b/components/layout/display_list/background.rs @@ -12,7 +12,7 @@ use style::computed_values::background_attachment::single_value::T as Background use style::computed_values::background_clip::single_value::T as BackgroundClip; use style::computed_values::background_origin::single_value::T as BackgroundOrigin; use style::properties::style_structs::Background; -use style::values::computed::{BackgroundSize, LengthOrPercentageOrAuto}; +use style::values::computed::{BackgroundSize, LengthPercentageOrAuto}; use style::values::generics::background::BackgroundSize as GenericBackgroundSize; use style::values::generics::NonNegative; use style::values::specified::background::BackgroundRepeatKeyword; @@ -88,7 +88,7 @@ fn compute_background_image_size( ( GenericBackgroundSize::Explicit { width, - height: NonNegative(LengthOrPercentageOrAuto::Auto), + height: NonNegative(LengthPercentageOrAuto::Auto), }, _, ) => { @@ -98,7 +98,7 @@ fn compute_background_image_size( }, ( GenericBackgroundSize::Explicit { - width: NonNegative(LengthOrPercentageOrAuto::Auto), + width: NonNegative(LengthPercentageOrAuto::Auto), height, }, _, diff --git a/components/layout/display_list/gradient.rs b/components/layout/display_list/gradient.rs index 6cdee3d6df8..db5208eadac 100644 --- a/components/layout/display_list/gradient.rs +++ b/components/layout/display_list/gradient.rs @@ -9,7 +9,7 @@ use app_units::Au; use euclid::{Point2D, Size2D, Vector2D}; use style::properties::ComputedValues; use style::values::computed::image::{EndingShape, LineDirection}; -use style::values::computed::{Angle, GradientItem, LengthOrPercentage, Percentage, Position}; +use style::values::computed::{Angle, GradientItem, LengthPercentage, Percentage, Position}; use style::values::generics::image::EndingShape as GenericEndingShape; use style::values::generics::image::GradientItem as GenericGradientItem; use style::values::generics::image::{Circle, Ellipse, ShapeExtent}; @@ -107,14 +107,14 @@ fn convert_gradient_stops( { let first = stop_items.first_mut().unwrap(); if first.position.is_none() { - first.position = Some(LengthOrPercentage::Percentage(Percentage(0.0))); + first.position = Some(LengthPercentage::new_percent(Percentage(0.))); } } // If the last color stop does not have a position, set its position to 100%. { let last = stop_items.last_mut().unwrap(); if last.position.is_none() { - last.position = Some(LengthOrPercentage::Percentage(Percentage(1.0))); + last.position = Some(LengthPercentage::new_percent(Percentage(1.0))); } } @@ -210,17 +210,11 @@ where Size2D::new(cmp(left_side, right_side), cmp(top_side, bottom_side)) } -fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 { +fn position_to_offset(position: LengthPercentage, total_length: Au) -> f32 { if total_length == Au(0) { return 0.0; } - match position { - LengthOrPercentage::Length(l) => l.to_i32_au() as f32 / total_length.0 as f32, - LengthOrPercentage::Percentage(percentage) => percentage.0 as f32, - LengthOrPercentage::Calc(calc) => { - calc.to_used_value(Some(total_length)).unwrap().0 as f32 / total_length.0 as f32 - }, - } + position.to_used_value(total_length).0 as f32 / total_length.0 as f32 } pub fn linear( diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 1848cdf2e81..44055ae7d18 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -12,7 +12,7 @@ use crate::floats::FloatKind; use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, ImmutableFlowUtils, OpaqueFlow}; use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use crate::layout_debug; -use crate::model::{AdjoiningMargins, CollapsibleMargins}; +use crate::model::{self, AdjoiningMargins, CollapsibleMargins}; use crate::model::{IntrinsicISizes, MaybeAuto, SizeConstraint}; use crate::traversal::PreorderFlowTraversal; use app_units::{Au, MAX_AU}; @@ -28,9 +28,7 @@ use style::logical_geometry::{Direction, LogicalSize}; use style::properties::ComputedValues; use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::flex::FlexBasis; -use style::values::computed::{ - LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone, -}; +use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, LengthPercentageOrNone}; use style::values::generics::flex::FlexBasis as GenericFlexBasis; /// The size of an axis. May be a specified size, a min/max @@ -46,24 +44,21 @@ impl AxisSize { /// Generate a new available cross or main axis size from the specified size of the container, /// containing block size, min constraint, and max constraint pub fn new( - size: LengthOrPercentageOrAuto, + size: LengthPercentageOrAuto, content_size: Option, - min: LengthOrPercentage, - max: LengthOrPercentageOrNone, + min: LengthPercentage, + max: LengthPercentageOrNone, ) -> AxisSize { match size { - LengthOrPercentageOrAuto::Length(length) => AxisSize::Definite(Au::from(length)), - LengthOrPercentageOrAuto::Percentage(percent) => match content_size { - Some(size) => AxisSize::Definite(size.scale_by(percent.0)), - None => AxisSize::Infinite, - }, - LengthOrPercentageOrAuto::Calc(calc) => match calc.to_used_value(content_size) { - Some(length) => AxisSize::Definite(length), - None => AxisSize::Infinite, - }, - LengthOrPercentageOrAuto::Auto => { + LengthPercentageOrAuto::Auto => { AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)) }, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + match lp.maybe_to_used_value(content_size) { + Some(length) => AxisSize::Definite(length), + None => AxisSize::Infinite, + } + }, } } } @@ -74,7 +69,7 @@ impl AxisSize { /// is definite after flex size resolving. fn from_flex_basis( flex_basis: FlexBasis, - main_length: LengthOrPercentageOrAuto, + main_length: LengthPercentageOrAuto, containing_length: Au, ) -> MaybeAuto { let width = match flex_basis { @@ -83,7 +78,7 @@ fn from_flex_basis( }; match width.0 { - LengthOrPercentageOrAuto::Auto => MaybeAuto::from_style(main_length, containing_length), + LengthPercentageOrAuto::Auto => MaybeAuto::from_style(main_length, containing_length), other => MaybeAuto::from_style(other, containing_length), } } @@ -144,7 +139,7 @@ impl FlexItem { let block = flow.as_mut_block(); match direction { // TODO(stshine): the definition of min-{width, height} in style component - // should change to LengthOrPercentageOrAuto for automatic implied minimal size. + // should change to LengthPercentageOrAuto for automatic implied minimal size. // https://drafts.csswg.org/css-flexbox-1/#min-size-auto Direction::Inline => { let basis = from_flex_basis( @@ -228,18 +223,18 @@ impl FlexItem { let mut margin_count = 0; match direction { Direction::Inline => { - if margin.inline_start == LengthOrPercentageOrAuto::Auto { + if margin.inline_start == LengthPercentageOrAuto::Auto { margin_count += 1; } - if margin.inline_end == LengthOrPercentageOrAuto::Auto { + if margin.inline_end == LengthPercentageOrAuto::Auto { margin_count += 1; } }, Direction::Block => { - if margin.block_start == LengthOrPercentageOrAuto::Auto { + if margin.block_start == LengthPercentageOrAuto::Auto { margin_count += 1; } - if margin.block_end == LengthOrPercentageOrAuto::Auto { + if margin.block_end == LengthPercentageOrAuto::Auto { margin_count += 1; } }, @@ -461,10 +456,10 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out, and max replaced with union_nonbreaking_inline. fn inline_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => true, - _ => false, - }; + // FIXME(emilio): This doesn't handle at all writing-modes. + let fixed_width = + !model::style_length(self.block_flow.fragment.style().get_position().width, None) + .is_auto(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { @@ -488,10 +483,9 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out. fn block_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => true, - _ => false, - }; + let fixed_width = + !model::style_length(self.block_flow.fragment.style().get_position().width, None) + .is_auto(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { @@ -821,7 +815,7 @@ impl FlexFlow { // cross size of item should equal to the line size if any auto margin exists. // https://drafts.csswg.org/css-flexbox/#algo-cross-margins if auto_margin_count > 0 { - if margin.block_start == LengthOrPercentageOrAuto::Auto { + if margin.block_start == LengthPercentageOrAuto::Auto { margin_block_start = if free_space < Au(0) { Au(0) } else { @@ -835,7 +829,7 @@ impl FlexFlow { let self_align = block.fragment.style().get_position().align_self; if self_align == AlignSelf::Stretch && - block.fragment.style().content_block_size() == LengthOrPercentageOrAuto::Auto + block.fragment.style().content_block_size() == LengthPercentageOrAuto::Auto { free_space = Au(0); block.base.block_container_explicit_block_size = Some(line.cross_size); diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 5e9ee3ae886..5a58e27f9d1 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -10,7 +10,7 @@ use std::cmp::{max, min}; use std::fmt; use style::computed_values::float::T as StyleFloat; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; -use style::values::computed::LengthOrPercentageOrAuto; +use style::values::computed::LengthPercentageOrAuto; /// The kind of float: left or right. #[derive(Clone, Copy, Debug, Serialize)] @@ -542,16 +542,20 @@ impl SpeculatedFloatPlacement { let mut float_inline_size = base_flow.intrinsic_inline_sizes.preferred_inline_size; if float_inline_size == Au(0) { if flow.is_block_like() { - // Hack: If the size of the float is a percentage, then there's no way we can guess - // at its size now. So just pick an arbitrary nonzero value (in this case, 1px) so - // that the layout traversal logic will know that objects later in the document + // Hack: If the size of the float is not fixed, then there's no + // way we can guess at its size now. So just pick an arbitrary + // nonzero value (in this case, 1px) so that the layout + // traversal logic will know that objects later in the document // might flow around this float. - if let LengthOrPercentageOrAuto::Percentage(percentage) = - flow.as_block().fragment.style.content_inline_size() - { - if percentage.0 > 0.0 { - float_inline_size = Au::from_px(1) - } + let inline_size = flow.as_block().fragment.style.content_inline_size(); + let fixed = match inline_size { + LengthPercentageOrAuto::Auto => false, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.is_definitely_zero() || lp.maybe_to_used_value(None).is_some() + }, + }; + if !fixed { + float_inline_size = Au::from_px(1) } } } diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 2059fe35525..86bd6b74edf 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -67,7 +67,7 @@ use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::properties::ComputedValues; use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; -use style::values::computed::LengthOrPercentageOrAuto; +use style::values::computed::LengthPercentageOrAuto; use webrender_api::LayoutTransform; /// This marker trait indicates that a type is a struct with `#[repr(C)]` whose first field @@ -1068,13 +1068,13 @@ impl BaseFlow { flags.insert(FlowFlags::IS_ABSOLUTELY_POSITIONED); let logical_position = style.logical_position(); - if logical_position.inline_start == LengthOrPercentageOrAuto::Auto && - logical_position.inline_end == LengthOrPercentageOrAuto::Auto + if logical_position.inline_start == LengthPercentageOrAuto::Auto && + logical_position.inline_end == LengthPercentageOrAuto::Auto { flags.insert(FlowFlags::INLINE_POSITION_IS_STATIC); } - if logical_position.block_start == LengthOrPercentageOrAuto::Auto && - logical_position.block_end == LengthOrPercentageOrAuto::Auto + if logical_position.block_start == LengthPercentageOrAuto::Auto && + logical_position.block_end == LengthPercentageOrAuto::Auto { flags.insert(FlowFlags::BLOCK_POSITION_IS_STATIC); } @@ -1161,13 +1161,13 @@ impl BaseFlow { let logical_position = style.logical_position(); self.flags.set( FlowFlags::INLINE_POSITION_IS_STATIC, - logical_position.inline_start == LengthOrPercentageOrAuto::Auto && - logical_position.inline_end == LengthOrPercentageOrAuto::Auto, + logical_position.inline_start == LengthPercentageOrAuto::Auto && + logical_position.inline_end == LengthPercentageOrAuto::Auto, ); self.flags.set( FlowFlags::BLOCK_POSITION_IS_STATIC, - logical_position.block_start == LengthOrPercentageOrAuto::Auto && - logical_position.block_end == LengthOrPercentageOrAuto::Auto, + logical_position.block_start == LengthPercentageOrAuto::Auto && + logical_position.block_end == LengthPercentageOrAuto::Auto, ); } } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 3e84a36c595..db4fd8f4625 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -61,7 +61,7 @@ use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; use style::str::char_is_whitespace; use style::values::computed::counters::ContentItem; -use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::computed::{LengthPercentage, LengthPercentageOrAuto}; use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::transform; use webrender_api::{self, LayoutTransform}; @@ -1448,14 +1448,14 @@ impl Fragment { pub fn relative_position(&self, containing_block_size: &LogicalSize) -> LogicalSize { fn from_style(style: &ComputedValues, container_size: &LogicalSize) -> LogicalSize { let offsets = style.logical_position(); - let offset_i = if offsets.inline_start != LengthOrPercentageOrAuto::Auto { + let offset_i = if offsets.inline_start != LengthPercentageOrAuto::Auto { MaybeAuto::from_style(offsets.inline_start, container_size.inline) .specified_or_zero() } else { -MaybeAuto::from_style(offsets.inline_end, container_size.inline) .specified_or_zero() }; - let offset_b = if offsets.block_start != LengthOrPercentageOrAuto::Auto { + let offset_b = if offsets.block_start != LengthPercentageOrAuto::Auto { MaybeAuto::from_style(offsets.block_start, container_size.block).specified_or_zero() } else { -MaybeAuto::from_style(offsets.block_end, container_size.block).specified_or_zero() @@ -1610,33 +1610,31 @@ impl Fragment { SpecificFragmentInfo::Canvas(_) | SpecificFragmentInfo::Iframe(_) | SpecificFragmentInfo::Svg(_) => { - let mut inline_size = match self.style.content_inline_size() { - LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Percentage(_) => { - // We have to initialize the `border_padding` field first to make - // the size constraints work properly. - // TODO(stshine): Find a cleaner way to do this. - let padding = self.style.logical_padding(); - self.border_padding.inline_start = - padding.inline_start.to_used_value(Au(0)); - self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0)); - self.border_padding.block_start = padding.block_start.to_used_value(Au(0)); - self.border_padding.block_end = padding.block_end.to_used_value(Au(0)); - let border = self.border_width(); - self.border_padding.inline_start += border.inline_start; - self.border_padding.inline_end += border.inline_end; - self.border_padding.block_start += border.block_start; - self.border_padding.block_end += border.block_end; - let (result_inline, _) = self.calculate_replaced_sizes(None, None); - result_inline - }, - LengthOrPercentageOrAuto::Length(length) => Au::from(length), - LengthOrPercentageOrAuto::Calc(calc) => { - // TODO(nox): This is probably wrong, because it accounts neither for - // clamping (not sure if necessary here) nor percentage. - Au::from(calc.unclamped_length()) + let inline_size = match self.style.content_inline_size() { + LengthPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None) }, }; + let mut inline_size = inline_size.unwrap_or_else(|| { + // We have to initialize the `border_padding` field first to make + // the size constraints work properly. + // TODO(stshine): Find a cleaner way to do this. + let padding = self.style.logical_padding(); + self.border_padding.inline_start = padding.inline_start.to_used_value(Au(0)); + self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0)); + self.border_padding.block_start = padding.block_start.to_used_value(Au(0)); + self.border_padding.block_end = padding.block_end.to_used_value(Au(0)); + let border = self.border_width(); + self.border_padding.inline_start += border.inline_start; + self.border_padding.inline_end += border.inline_end; + self.border_padding.block_start += border.block_start; + self.border_padding.block_end += border.block_end; + let (result_inline, _) = self.calculate_replaced_sizes(None, None); + result_inline + }); + let size_constraint = self.size_constraint(None, Direction::Inline); inline_size = size_constraint.clamp(inline_size); @@ -2432,16 +2430,8 @@ impl Fragment { content_inline_metrics.space_below_baseline } }, - VerticalAlign::Length(LengthOrPercentage::Length(length)) => { - offset -= Au::from(length) - }, - VerticalAlign::Length(LengthOrPercentage::Percentage(percentage)) => { - offset -= minimum_line_metrics.space_needed().scale_by(percentage.0) - }, - VerticalAlign::Length(LengthOrPercentage::Calc(formula)) => { - offset -= formula - .to_used_value(Some(minimum_line_metrics.space_needed())) - .unwrap() + VerticalAlign::Length(ref lp) => { + offset -= lp.to_used_value(minimum_line_metrics.space_needed()); }, } } @@ -2519,12 +2509,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_end != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_end != - LengthOrPercentage::Length(Length::new(0.)) + LengthPercentage::zero() { return false; } @@ -2545,12 +2535,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_start != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_start != - LengthOrPercentage::Length(Length::new(0.)) + LengthPercentage::zero() { return false; } diff --git a/components/layout/model.rs b/components/layout/model.rs index 4db60d05a4b..0650c8887a1 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -11,8 +11,8 @@ use std::cmp::{max, min}; use std::fmt; use style::logical_geometry::{LogicalMargin, WritingMode}; use style::properties::ComputedValues; -use style::values::computed::LengthOrPercentageOrNone; -use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::computed::LengthPercentageOrNone; +use style::values::computed::{LengthPercentage, LengthPercentageOrAuto}; /// A collapsible margin. See CSS 2.1 § 8.3.1. #[derive(Clone, Copy, Debug)] @@ -135,27 +135,20 @@ impl MarginCollapseInfo { MarginCollapseState::AccumulatingCollapsibleTopMargin => { may_collapse_through = may_collapse_through && match fragment.style().content_block_size() { - LengthOrPercentageOrAuto::Auto => true, - LengthOrPercentageOrAuto::Length(l) => l.px() == 0., - LengthOrPercentageOrAuto::Percentage(v) => { - v.0 == 0. || containing_block_size.is_none() + LengthPercentageOrAuto::Auto => true, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.is_definitely_zero() || + lp.maybe_to_used_value(containing_block_size).is_none() }, - LengthOrPercentageOrAuto::Calc(_) => false, }; if may_collapse_through { - match fragment.style().min_block_size() { - LengthOrPercentage::Length(l) if l.px() == 0. => { - FinalMarginState::MarginsCollapseThrough - }, - LengthOrPercentage::Percentage(v) if v.0 == 0. => { - FinalMarginState::MarginsCollapseThrough - }, - _ => { - // If the fragment has non-zero min-block-size, margins may not - // collapse through it. - FinalMarginState::BottomMarginCollapses - }, + if fragment.style().min_block_size().is_definitely_zero() { + FinalMarginState::MarginsCollapseThrough + } else { + // If the fragment has non-zero min-block-size, margins may not + // collapse through it. + FinalMarginState::BottomMarginCollapses } } else { // If the fragment has an explicitly specified block-size, margins may not @@ -442,16 +435,12 @@ pub enum MaybeAuto { impl MaybeAuto { #[inline] - pub fn from_style(length: LengthOrPercentageOrAuto, containing_length: Au) -> MaybeAuto { + pub fn from_style(length: LengthPercentageOrAuto, containing_length: Au) -> MaybeAuto { match length { - LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, - LengthOrPercentageOrAuto::Percentage(percent) => { - MaybeAuto::Specified(containing_length.scale_by(percent.0)) + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + MaybeAuto::Specified(lp.to_used_value(containing_length)) }, - LengthOrPercentageOrAuto::Calc(calc) => { - MaybeAuto::from_option(calc.to_used_value(Some(containing_length))) - }, - LengthOrPercentageOrAuto::Length(length) => MaybeAuto::Specified(Au::from(length)), } } @@ -484,6 +473,14 @@ impl MaybeAuto { self.specified_or_default(Au::new(0)) } + #[inline] + pub fn is_auto(&self) -> bool { + match *self { + MaybeAuto::Auto => true, + MaybeAuto::Specified(..) => false, + } + } + #[inline] pub fn map(&self, mapper: F) -> MaybeAuto where @@ -499,18 +496,11 @@ impl MaybeAuto { /// Receive an optional container size and return used value for width or height. /// /// `style_length`: content size as given in the CSS. -pub fn style_length( - style_length: LengthOrPercentageOrAuto, - container_size: Option, -) -> MaybeAuto { - match container_size { - Some(length) => MaybeAuto::from_style(style_length, length), - None => { - if let LengthOrPercentageOrAuto::Length(length) = style_length { - MaybeAuto::Specified(Au::from(length)) - } else { - MaybeAuto::Auto - } +pub fn style_length(style_length: LengthPercentageOrAuto, container_size: Option) -> MaybeAuto { + match style_length { + LengthPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_to_used_value(container_size)) }, } } @@ -576,31 +566,21 @@ impl SizeConstraint { /// Create a `SizeConstraint` for an axis. pub fn new( container_size: Option, - min_size: LengthOrPercentage, - max_size: LengthOrPercentageOrNone, + min_size: LengthPercentage, + max_size: LengthPercentageOrNone, border: Option, ) -> SizeConstraint { - let mut min_size = match container_size { - Some(container_size) => min_size.to_used_value(container_size), - None => { - if let LengthOrPercentage::Length(length) = min_size { - Au::from(length) - } else { - Au(0) - } + let mut min_size = min_size + .maybe_to_used_value(container_size) + .unwrap_or(Au(0)); + + let mut max_size = match max_size { + LengthPercentageOrNone::None => None, + LengthPercentageOrNone::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(container_size) }, }; - let mut max_size = match container_size { - Some(container_size) => max_size.to_used_value(container_size), - None => { - if let LengthOrPercentageOrNone::Length(length) = max_size { - Some(Au::from(length)) - } else { - None - } - }, - }; // Make sure max size is not smaller than min size. max_size = max_size.map(|x| max(x, min_size)); @@ -609,10 +589,7 @@ impl SizeConstraint { max_size = max_size.map(|x| max(x - border, Au(0))); } - SizeConstraint { - min_size: min_size, - max_size: max_size, - } + SizeConstraint { min_size, max_size } } /// Clamp the given size by the given min size and max size constraint. diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 294670f0a1e..14ea36626f9 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -19,7 +19,7 @@ use std::fmt; use std::sync::Arc; use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; -use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +use style::values::computed::{LengthPercentageOrAuto, LengthPercentageOrNone}; use style::values::generics::column::ColumnCount; use style::values::Either; @@ -154,11 +154,20 @@ impl Flow for MulticolFlow { this_fragment_is_empty: true, available_block_size: { let style = &self.block_flow.fragment.style; - if let LengthOrPercentageOrAuto::Length(length) = style.content_block_size() { - Au::from(length) - } else if let LengthOrPercentageOrNone::Length(length) = style.max_block_size() { - Au::from(length) - } else { + let size = match style.content_block_size() { + LengthPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None) + }, + }; + let size = size.or_else(|| match style.max_block_size() { + LengthPercentageOrNone::None => None, + LengthPercentageOrNone::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None) + }, + }); + + size.unwrap_or_else(|| { // FIXME: do column balancing instead // FIXME: (until column balancing) substract margins/borders/padding LogicalSize::from_physical( @@ -166,7 +175,7 @@ impl Flow for MulticolFlow { ctx.shared_context().viewport_size(), ) .block - } + }) }, }); diff --git a/components/layout/table.rs b/components/layout/table.rs index 5f08b107b31..83d3552a988 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -33,7 +33,7 @@ use style::logical_geometry::LogicalSize; use style::properties::style_structs::Background; use style::properties::ComputedValues; use style::servo::restyle_damage::ServoRestyleDamage; -use style::values::computed::LengthOrPercentageOrAuto; +use style::values::computed::LengthPercentageOrAuto; use style::values::CSSFloat; #[allow(unsafe_code)] @@ -301,16 +301,16 @@ impl Flow for TableFlow { self.column_intrinsic_inline_sizes .push(ColumnIntrinsicInlineSize { minimum_length: match *specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => Au(0), - LengthOrPercentageOrAuto::Length(length) => Au::from(length), + LengthPercentageOrAuto::Auto => Au(0), + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None).unwrap_or(Au(0)) + }, }, percentage: match *specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Length(_) => 0.0, - LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, + LengthPercentageOrAuto::Auto => 0.0, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.as_percentage().map_or(0.0, |p| p.0) + }, }, preferred: Au(0), constrained: false, diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 28cdafea7ec..6bb5cbe620b 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -14,7 +14,7 @@ use euclid::Point2D; use std::fmt; use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; -use style::values::computed::LengthOrPercentageOrAuto; +use style::values::computed::LengthPercentageOrAuto; #[allow(unsafe_code)] unsafe impl crate::flow::HasBaseFlow for TableColGroupFlow {} @@ -31,10 +31,10 @@ pub struct TableColGroupFlow { /// The table column fragments pub cols: Vec, - /// The specified inline-sizes of table columns. (We use `LengthOrPercentageOrAuto` 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 /// inline sizes.) - pub inline_sizes: Vec, + pub inline_sizes: Vec, } impl TableColGroupFlow { diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 90c3c812f1c..ca33eb2584e 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -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::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; use style::properties::ComputedValues; -use style::values::computed::{Color, LengthOrPercentageOrAuto}; +use style::values::computed::{Color, LengthPercentageOrAuto}; #[allow(unsafe_code)] unsafe impl crate::flow::HasBaseFlow for TableRowFlow {} @@ -430,25 +430,24 @@ impl Flow for TableRowFlow { let child_base = kid.mut_base(); let child_column_inline_size = ColumnIntrinsicInlineSize { minimum_length: match child_specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => { - child_base.intrinsic_inline_sizes.minimum_inline_size + LengthPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None) }, - LengthOrPercentageOrAuto::Length(length) => Au::from(length), - }, + } + .unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size), percentage: match child_specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Length(_) => 0.0, - LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, + LengthPercentageOrAuto::Auto => 0.0, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.as_percentage().map_or(0.0, |p| p.0) + }, }, preferred: child_base.intrinsic_inline_sizes.preferred_inline_size, constrained: match child_specified_inline_size { - LengthOrPercentageOrAuto::Length(_) => true, - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => false, + LengthPercentageOrAuto::Auto => false, + LengthPercentageOrAuto::LengthPercentage(ref lp) => { + lp.maybe_to_used_value(None).is_some() + }, }, }; min_inline_size = min_inline_size + child_column_inline_size.minimum_length; diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 94d7d2d32a0..f63cf3f28f0 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -35,7 +35,7 @@ use style::computed_values::{position, table_layout}; use style::context::SharedStyleContext; use style::logical_geometry::{LogicalRect, LogicalSize}; use style::properties::ComputedValues; -use style::values::computed::LengthOrPercentageOrAuto; +use style::values::computed::LengthPercentageOrAuto; use style::values::CSSFloat; #[derive(Clone, Copy, Debug, Serialize)] @@ -203,7 +203,7 @@ impl TableWrapperFlow { // 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. let available_inline_size = match self.block_flow.fragment.style().content_inline_size() { - LengthOrPercentageOrAuto::Auto => { + LengthPercentageOrAuto::Auto => { self.block_flow .get_shrink_to_fit_inline_size(available_inline_size) - table_border_padding diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 233d4a01bb3..d461cd11527 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -718,7 +718,9 @@ impl LayoutElementHelpers for LayoutDom { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length(value), + )), )); } @@ -743,8 +745,8 @@ impl LayoutElementHelpers for LayoutDom { match width { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let width_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let width_value = specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Percentage(computed::Percentage(percentage)), ); hints.push(from_declaration( shared_lock, @@ -752,10 +754,11 @@ impl LayoutElementHelpers for LayoutDom { )); }, LengthOrPercentageOrAuto::Length(length) => { - let width_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( + let width_value = specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length(specified::NoCalcLength::Absolute( specified::AbsoluteLength::Px(length.to_f32_px()), - )); + )), + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Width(width_value), @@ -776,8 +779,8 @@ impl LayoutElementHelpers for LayoutDom { match height { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let height_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let height_value = specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Percentage(computed::Percentage(percentage)), ); hints.push(from_declaration( shared_lock, @@ -785,10 +788,11 @@ impl LayoutElementHelpers for LayoutDom { )); }, LengthOrPercentageOrAuto::Length(length) => { - let height_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( + let height_value = specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length(specified::NoCalcLength::Absolute( specified::AbsoluteLength::Px(length.to_f32_px()), - )); + )), + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Height(height_value), @@ -815,7 +819,9 @@ impl LayoutElementHelpers for LayoutDom { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length(value), + )), )); } @@ -837,7 +843,9 @@ impl LayoutElementHelpers for LayoutDom { )); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Height(specified::LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length(value), + )), )); } diff --git a/components/style/attr.rs b/components/style/attr.rs index 16173d64057..926d52cd5f8 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -543,7 +543,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result { /// Parses a [dimension value][dim]. If unparseable, `Auto` is returned. /// /// [dim]: https://html.spec.whatwg.org/multipage/#rules-for-parsing-dimension-values -// TODO: this function can be rewritten to return Result +// TODO: this function can be rewritten to return Result pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto { // Steps 1 & 2 are not relevant diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 266ebbd750a..89cce99beb0 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -20,9 +20,9 @@ use crate::stylesheets::{Origin, RulesMutateError}; use crate::values::computed::image::LineDirection; use crate::values::computed::transform::Matrix3D; use crate::values::computed::url::ComputedImageUrl; -use crate::values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; -use crate::values::computed::{Integer, LengthOrPercentage}; -use crate::values::computed::{LengthOrPercentageOrAuto, NonNegativeLengthOrPercentageOrAuto}; +use crate::values::computed::{Angle, Gradient, Image}; +use crate::values::computed::{Integer, LengthPercentage}; +use crate::values::computed::{LengthPercentageOrAuto, NonNegativeLengthPercentageOrAuto}; use crate::values::computed::{Percentage, TextAlign}; use crate::values::generics::box_::VerticalAlign; use crate::values::generics::grid::{TrackListValue, TrackSize}; @@ -31,9 +31,10 @@ use crate::values::generics::rect::Rect; use crate::values::generics::NonNegative; use app_units::Au; use std::f32::consts::PI; +use style_traits::values::specified::AllowedNumericType; -impl From for nsStyleCoord_CalcValue { - fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { +impl From for nsStyleCoord_CalcValue { + fn from(other: LengthPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { mLength: other.unclamped_length().to_i32_au(), @@ -43,82 +44,44 @@ impl From for nsStyleCoord_CalcValue { } } -impl From for CalcLengthOrPercentage { - fn from(other: nsStyleCoord_CalcValue) -> CalcLengthOrPercentage { +impl From for LengthPercentage { + fn from(other: nsStyleCoord_CalcValue) -> LengthPercentage { let percentage = if other.mHasPercent { Some(Percentage(other.mPercent)) } else { None }; - Self::new(Au(other.mLength).into(), percentage) + Self::with_clamping_mode( + Au(other.mLength).into(), + percentage, + AllowedNumericType::All, + /* was_calc = */ true, + ) } } -impl From for nsStyleCoord_CalcValue { - fn from(other: LengthOrPercentage) -> nsStyleCoord_CalcValue { - match other { - LengthOrPercentage::Length(px) => nsStyleCoord_CalcValue { - mLength: px.to_i32_au(), - mPercent: 0.0, - mHasPercent: false, - }, - LengthOrPercentage::Percentage(pc) => nsStyleCoord_CalcValue { - mLength: 0, - mPercent: pc.0, - mHasPercent: true, - }, - LengthOrPercentage::Calc(calc) => calc.into(), - } - } -} - -impl LengthOrPercentageOrAuto { +impl LengthPercentageOrAuto { /// Convert this value in an appropriate `nsStyleCoord::CalcValue`. pub fn to_calc_value(&self) -> Option { match *self { - LengthOrPercentageOrAuto::Length(px) => Some(nsStyleCoord_CalcValue { - mLength: px.to_i32_au(), - mPercent: 0.0, - mHasPercent: false, - }), - LengthOrPercentageOrAuto::Percentage(pc) => Some(nsStyleCoord_CalcValue { - mLength: 0, - mPercent: pc.0, - mHasPercent: true, - }), - LengthOrPercentageOrAuto::Calc(calc) => Some(calc.into()), - LengthOrPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(len) => Some(From::from(len)), + LengthPercentageOrAuto::Auto => None, } } } -impl From for LengthOrPercentage { - fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentage { - match (other.mHasPercent, other.mLength) { - (false, _) => LengthOrPercentage::Length(Au(other.mLength).into()), - (true, 0) => LengthOrPercentage::Percentage(Percentage(other.mPercent)), - _ => LengthOrPercentage::Calc(other.into()), - } - } -} - -impl From for LengthOrPercentageOrAuto { - fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentageOrAuto { - match (other.mHasPercent, other.mLength) { - (false, _) => LengthOrPercentageOrAuto::Length(Au(other.mLength).into()), - (true, 0) => LengthOrPercentageOrAuto::Percentage(Percentage(other.mPercent)), - _ => LengthOrPercentageOrAuto::Calc(other.into()), - } +impl From for LengthPercentageOrAuto { + fn from(other: nsStyleCoord_CalcValue) -> LengthPercentageOrAuto { + LengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other)) } } // FIXME(emilio): A lot of these impl From should probably become explicit or // disappear as we move more stuff to cbindgen. -impl From for NonNegativeLengthOrPercentageOrAuto { +impl From for NonNegativeLengthPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> Self { - use style_traits::values::specified::AllowedNumericType; - NonNegative(if other.mLength < 0 || other.mPercent < 0. { - LengthOrPercentageOrAuto::Calc(CalcLengthOrPercentage::with_clamping_mode( + NonNegative(LengthPercentageOrAuto::LengthPercentage( + LengthPercentage::with_clamping_mode( Au(other.mLength).into(), if other.mHasPercent { Some(Percentage(other.mPercent)) @@ -126,10 +89,9 @@ impl From for NonNegativeLengthOrPercentageOrAuto { None }, AllowedNumericType::NonNegative, - )) - } else { - other.into() - }) + /* was_calc = */ true, + ), + )) } } @@ -139,24 +101,17 @@ impl From for CoordDataValue { } } -fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) -> LineDirection { +fn line_direction(horizontal: LengthPercentage, vertical: LengthPercentage) -> LineDirection { use crate::values::computed::position::Position; use crate::values::specified::position::{X, Y}; - let horizontal_percentage = match horizontal { - LengthOrPercentage::Percentage(percentage) => Some(percentage.0), - _ => None, - }; - - let vertical_percentage = match vertical { - LengthOrPercentage::Percentage(percentage) => Some(percentage.0), - _ => None, - }; + let horizontal_percentage = horizontal.as_percentage(); + let vertical_percentage = vertical.as_percentage(); let horizontal_as_corner = horizontal_percentage.and_then(|percentage| { - if percentage == 0.0 { + if percentage.0 == 0.0 { Some(X::Left) - } else if percentage == 1.0 { + } else if percentage.0 == 1.0 { Some(X::Right) } else { None @@ -164,9 +119,9 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) }); let vertical_as_corner = vertical_percentage.and_then(|percentage| { - if percentage == 0.0 { + if percentage.0 == 0.0 { Some(Y::Top) - } else if percentage == 1.0 { + } else if percentage.0 == 1.0 { Some(Y::Bottom) } else { None @@ -178,13 +133,13 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) } if let Some(hc) = horizontal_as_corner { - if vertical_percentage == Some(0.5) { + if vertical_percentage == Some(Percentage(0.5)) { return LineDirection::Horizontal(hc); } } if let Some(vc) = vertical_as_corner { - if horizontal_percentage == Some(0.5) { + if horizontal_percentage == Some(Percentage(0.5)) { return LineDirection::Vertical(vc); } } @@ -512,8 +467,8 @@ impl nsStyleImage { .as_ref() .unwrap(); let angle = Angle::from_gecko_style_coord(&gecko_gradient.mAngle); - let horizontal_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosX); - let vertical_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosY); + let horizontal_style = LengthPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosX); + let vertical_style = LengthPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosY); let kind = match gecko_gradient.mShape as u32 { structs::NS_STYLE_GRADIENT_SHAPE_LINEAR => { @@ -574,20 +529,18 @@ impl nsStyleImage { structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => { let length_percentage_keyword = match gecko_gradient.mSize as u32 { structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => match ( - LengthOrPercentage::from_gecko_style_coord( - &gecko_gradient.mRadiusX, - ), - LengthOrPercentage::from_gecko_style_coord( - &gecko_gradient.mRadiusY, - ), + LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusX), + LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusY), ) { (Some(x), Some(y)) => Ellipse::Radii(x, y), _ => { - debug_assert!(false, - "mRadiusX, mRadiusY could not convert to LengthOrPercentage"); + debug_assert!( + false, + "mRadiusX, mRadiusY could not convert to LengthPercentage" + ); Ellipse::Radii( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), ) }, }, @@ -606,11 +559,11 @@ impl nsStyleImage { _ => { debug_assert!( false, - "mRadiusX, mRadiusY could not convert to LengthOrPercentage" + "mRadiusX, mRadiusY could not convert to LengthPercentage" ); Position { - horizontal: LengthOrPercentage::zero(), - vertical: LengthOrPercentage::zero(), + horizontal: LengthPercentage::zero(), + vertical: LengthPercentage::zero(), } }, }; @@ -625,13 +578,13 @@ impl nsStyleImage { .map(|ref stop| { if stop.mIsInterpolationHint { GradientItem::InterpolationHint( - LengthOrPercentage::from_gecko_style_coord(&stop.mLocation) - .expect("mLocation could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(&stop.mLocation) + .expect("mLocation could not convert to LengthPercentage"), ) } else { GradientItem::ColorStop(ColorStop { color: stop.mColor.into(), - position: LengthOrPercentage::from_gecko_style_coord(&stop.mLocation), + position: LengthPercentage::from_gecko_style_coord(&stop.mLocation), }) } }) @@ -670,7 +623,7 @@ pub mod basic_shape { BasicShape, ClippingShape, FloatAreaShape, ShapeRadius, }; use crate::values::computed::border::{BorderCornerRadius, BorderRadius}; - use crate::values::computed::length::LengthOrPercentage; + use crate::values::computed::length::LengthPercentage; use crate::values::computed::motion::OffsetPath; use crate::values::computed::position; use crate::values::computed::url::ComputedUrl; @@ -787,10 +740,10 @@ pub mod basic_shape { fn from(other: &'a StyleBasicShape) -> Self { match other.mType { StyleBasicShapeType::Inset => { - let t = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[0]); - let r = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[1]); - let b = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[2]); - let l = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[3]); + let t = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[0]); + let r = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[1]); + let b = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[2]); + let l = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[3]); let round: BorderRadius = (&other.mRadius).into(); let round = if round.all_zero() { None } else { Some(round) }; let rect = Rect::new( @@ -816,12 +769,12 @@ pub mod basic_shape { let x = 2 * i; let y = x + 1; coords.push(PolygonCoord( - LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[x]) + LengthPercentage::from_gecko_style_coord(&other.mCoordinates[x]) .expect( "polygon() coordinate should be a length, percentage, \ or calc value", ), - LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[y]) + LengthPercentage::from_gecko_style_coord(&other.mCoordinates[y]) .expect( "polygon() coordinate should be a length, percentage, \ or calc value", @@ -842,15 +795,14 @@ pub mod basic_shape { let get_corner = |index| { BorderCornerRadius::new( NonNegative( - LengthOrPercentage::from_gecko_style_coord(&other.data_at(index)).expect( + LengthPercentage::from_gecko_style_coord(&other.data_at(index)).expect( " should be a length, percentage, or calc value", ), ), NonNegative( - LengthOrPercentage::from_gecko_style_coord(&other.data_at(index + 1)) - .expect( - " should be a length, percentage, or calc value", - ), + LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1)).expect( + " should be a length, percentage, or calc value", + ), ), ) }; @@ -1003,11 +955,11 @@ impl From for SheetType { } } -impl TrackSize { +impl TrackSize { /// Return TrackSize from given two nsStyleCoord pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { use crate::gecko_bindings::structs::root::nsStyleUnit; - use crate::values::computed::length::LengthOrPercentage; + use crate::values::computed::length::LengthPercentage; use crate::values::generics::grid::{TrackBreadth, TrackSize}; if gecko_min.unit() == nsStyleUnit::eStyleUnit_None { @@ -1017,8 +969,8 @@ impl TrackSize { gecko_max.unit() == nsStyleUnit::eStyleUnit_Calc ); return TrackSize::FitContent( - LengthOrPercentage::from_gecko_style_coord(gecko_max) - .expect("gecko_max could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(gecko_max) + .expect("gecko_max could not convert to LengthPercentage"), ); } @@ -1058,7 +1010,7 @@ impl TrackSize { } } -impl TrackListValue { +impl TrackListValue { /// Return TrackSize from given two nsStyleCoord pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { TrackListValue::TrackSize(TrackSize::from_gecko_style_coords(gecko_min, gecko_max)) diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 39a5ac2de89..2288db104a4 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -13,9 +13,9 @@ use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, Coor use crate::media_queries::Device; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use crate::values::computed::FlexBasis as ComputedFlexBasis; -use crate::values::computed::{Angle, ExtremumLength, Length, LengthOrPercentage}; -use crate::values::computed::{LengthOrPercentageOrAuto, Percentage}; -use crate::values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage}; +use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage}; +use crate::values::computed::{LengthPercentageOrAuto, Percentage}; +use crate::values::computed::{LengthPercentageOrNone, Number, NumberOrPercentage}; use crate::values::computed::{MaxLength as ComputedMaxLength, MozLength as ComputedMozLength}; use crate::values::generics::basic_shape::ShapeRadius; use crate::values::generics::box_::Perspective; @@ -146,21 +146,25 @@ impl GeckoStyleCoordConvertible for NumberOrPercentage { } } -impl GeckoStyleCoordConvertible for LengthOrPercentage { +impl GeckoStyleCoordConvertible for LengthPercentage { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentage::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentage::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentage::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + if self.was_calc { + return coord.set_value(CoordDataValue::Calc((*self).into())); + } + debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); + if let Some(p) = self.percentage { + return coord.set_value(CoordDataValue::Percent(p.0)); + } + coord.set_value(CoordDataValue::Coord(self.unclamped_length().to_i32_au())) } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => Some(LengthOrPercentage::Length(Au(coord).into())), - CoordDataValue::Percent(p) => Some(LengthOrPercentage::Percentage(Percentage(p))), - CoordDataValue::Calc(calc) => Some(LengthOrPercentage::Calc(calc.into())), + CoordDataValue::Coord(coord) => Some(LengthPercentage::new(Au(coord).into(), None)), + CoordDataValue::Percent(p) => { + Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p)))) + }, + CoordDataValue::Calc(calc) => Some(calc.into()), _ => None, } } @@ -179,50 +183,36 @@ impl GeckoStyleCoordConvertible for Length { } } -impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { +impl GeckoStyleCoordConvertible for LengthPercentageOrAuto { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentageOrAuto::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentageOrAuto::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentageOrAuto::Auto => CoordDataValue::Auto, - LengthOrPercentageOrAuto::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + match *self { + LengthPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto), + LengthPercentageOrAuto::LengthPercentage(ref lp) => lp.to_gecko_style_coord(coord), + } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => { - Some(LengthOrPercentageOrAuto::Length(Au(coord).into())) - }, - CoordDataValue::Percent(p) => Some(LengthOrPercentageOrAuto::Percentage(Percentage(p))), - CoordDataValue::Auto => Some(LengthOrPercentageOrAuto::Auto), - CoordDataValue::Calc(calc) => Some(LengthOrPercentageOrAuto::Calc(calc.into())), - _ => None, + CoordDataValue::Auto => Some(LengthPercentageOrAuto::Auto), + _ => LengthPercentage::from_gecko_style_coord(coord) + .map(LengthPercentageOrAuto::LengthPercentage), } } } -impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { +impl GeckoStyleCoordConvertible for LengthPercentageOrNone { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentageOrNone::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentageOrNone::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentageOrNone::None => CoordDataValue::None, - LengthOrPercentageOrNone::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + match *self { + LengthPercentageOrNone::None => coord.set_value(CoordDataValue::None), + LengthPercentageOrNone::LengthPercentage(ref lp) => lp.to_gecko_style_coord(coord), + } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => { - Some(LengthOrPercentageOrNone::Length(Au(coord).into())) - }, - CoordDataValue::Percent(p) => Some(LengthOrPercentageOrNone::Percentage(Percentage(p))), - CoordDataValue::None => Some(LengthOrPercentageOrNone::None), - CoordDataValue::Calc(calc) => Some(LengthOrPercentageOrNone::Calc(calc.into())), - _ => None, + CoordDataValue::None => Some(LengthPercentageOrNone::None), + _ => LengthPercentage::from_gecko_style_coord(coord) + .map(LengthPercentageOrNone::LengthPercentage), } } } @@ -230,7 +220,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { impl GeckoStyleCoordConvertible for TrackBreadth { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - TrackBreadth::Breadth(ref lop) => lop.to_gecko_style_coord(coord), + TrackBreadth::Breadth(ref lp) => lp.to_gecko_style_coord(coord), TrackBreadth::Fr(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)), TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto), TrackBreadth::Keyword(TrackKeyword::MinContent) => coord.set_value( @@ -271,7 +261,7 @@ impl GeckoStyleCoordConvertible for ComputedShapeRadius { ShapeRadius::FarthestSide => coord.set_value(CoordDataValue::Enumerated( StyleShapeRadius::FarthestSide as u32, )), - ShapeRadius::Length(lop) => lop.to_gecko_style_coord(coord), + ShapeRadius::Length(lp) => lp.to_gecko_style_coord(coord), } } @@ -377,14 +367,14 @@ impl GeckoStyleCoordConvertible for ExtremumLength { impl GeckoStyleCoordConvertible for ComputedMozLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MozLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord), + MozLength::LengthPercentageOrAuto(ref lpoa) => lpoa.to_gecko_style_coord(coord), MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthOrPercentageOrAuto::from_gecko_style_coord(coord) - .map(MozLength::LengthOrPercentageOrAuto) + LengthPercentageOrAuto::from_gecko_style_coord(coord) + .map(MozLength::LengthPercentageOrAuto) .or_else(|| { ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength) }) @@ -394,21 +384,21 @@ impl GeckoStyleCoordConvertible for ComputedMozLength { impl GeckoStyleCoordConvertible for ComputedMaxLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord), + MaxLength::LengthPercentageOrNone(ref lpon) => lpon.to_gecko_style_coord(coord), MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthOrPercentageOrNone::from_gecko_style_coord(coord) - .map(MaxLength::LengthOrPercentageOrNone) + LengthPercentageOrNone::from_gecko_style_coord(coord) + .map(MaxLength::LengthPercentageOrNone) .or_else(|| { ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength) }) } } -impl GeckoStyleCoordConvertible for ScrollSnapPoint { +impl GeckoStyleCoordConvertible for ScrollSnapPoint { fn to_gecko_style_coord(&self, coord: &mut T) { match self.repeated() { None => coord.set_value(CoordDataValue::None), @@ -423,8 +413,8 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint { Some(match coord.unit() { nsStyleUnit::eStyleUnit_None => ScrollSnapPoint::None, _ => ScrollSnapPoint::Repeat( - LengthOrPercentage::from_gecko_style_coord(coord) - .expect("coord could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(coord) + .expect("coord could not convert to LengthPercentage"), ), }) } diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index aa4f9947cd2..73657af3e35 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -9,7 +9,7 @@ use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::{nsCSSUnit, nsCSSValue}; use crate::gecko_bindings::structs::{nsCSSValueList, nsCSSValue_Array}; use crate::gecko_string_cache::Atom; -use crate::values::computed::{Angle, Length, LengthOrPercentage, Percentage}; +use crate::values::computed::{Angle, Length, LengthPercentage, Percentage}; use std::marker::PhantomData; use std::mem; use std::ops::{Index, IndexMut}; @@ -67,13 +67,16 @@ impl nsCSSValue { &*array } - /// Sets LengthOrPercentage value to this nsCSSValue. - pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) { - match lop { - LengthOrPercentage::Length(px) => self.set_px(px.px()), - LengthOrPercentage::Percentage(pc) => self.set_percentage(pc.0), - LengthOrPercentage::Calc(calc) => bindings::Gecko_CSSValue_SetCalc(self, calc.into()), + /// Sets LengthPercentage value to this nsCSSValue. + pub unsafe fn set_length_percentage(&mut self, lp: LengthPercentage) { + if lp.was_calc { + return bindings::Gecko_CSSValue_SetCalc(self, lp.into()); } + debug_assert!(lp.percentage.is_none() || lp.unclamped_length() == Length::zero()); + if let Some(p) = lp.percentage { + return self.set_percentage(p.0); + } + self.set_px(lp.unclamped_length().px()); } /// Sets a px value to this nsCSSValue. @@ -86,18 +89,16 @@ impl nsCSSValue { bindings::Gecko_CSSValue_SetPercentage(self, unit_value) } - /// Returns LengthOrPercentage value. - pub unsafe fn get_lop(&self) -> LengthOrPercentage { + /// Returns LengthPercentage value. + pub unsafe fn get_length_percentage(&self) -> LengthPercentage { match self.mUnit { nsCSSUnit::eCSSUnit_Pixel => { - LengthOrPercentage::Length(Length::new(bindings::Gecko_CSSValue_GetNumber(self))) + LengthPercentage::new(Length::new(bindings::Gecko_CSSValue_GetNumber(self)), None) }, - nsCSSUnit::eCSSUnit_Percent => LengthOrPercentage::Percentage(Percentage( + nsCSSUnit::eCSSUnit_Percent => LengthPercentage::new_percent(Percentage( bindings::Gecko_CSSValue_GetPercentage(self), )), - nsCSSUnit::eCSSUnit_Calc => { - LengthOrPercentage::Calc(bindings::Gecko_CSSValue_GetCalc(self).into()) - }, + nsCSSUnit::eCSSUnit_Calc => bindings::Gecko_CSSValue_GetCalc(self).into(), _ => panic!("Unexpected unit"), } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index d969f14f54a..40691d75e04 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -510,7 +510,7 @@ def set_gecko_property(ffi_name, expr): // set on mContextFlags, and the length field is set to the initial value. pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - use crate::values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber}; + use crate::values::generics::svg::{SVGLength, SvgLengthPercentageOrNumber}; use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; let length = match v { SVGLength::Length(length) => { @@ -526,9 +526,9 @@ def set_gecko_property(ffi_name, expr): } }; match length { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => - self.gecko.${gecko_ffi_name}.set(lop), - SvgLengthOrPercentageOrNumber::Number(num) => + SvgLengthPercentageOrNumber::LengthPercentage(lp) => + self.gecko.${gecko_ffi_name}.set(lp), + SvgLengthPercentageOrNumber::Number(num) => self.gecko.${gecko_ffi_name}.set_value(CoordDataValue::Factor(num.into())), } } @@ -546,30 +546,28 @@ def set_gecko_property(ffi_name, expr): } pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use crate::values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber}; - use crate::values::computed::LengthOrPercentage; + use crate::values::generics::svg::{SVGLength, SvgLengthPercentageOrNumber}; + use crate::values::computed::LengthPercentage; use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; if (self.gecko.mContextFlags & CONTEXT_VALUE) != 0 { return SVGLength::ContextValue; } let length = match self.gecko.${gecko_ffi_name}.as_value() { CoordDataValue::Factor(number) => { - SvgLengthOrPercentageOrNumber::Number(number) + SvgLengthPercentageOrNumber::Number(number) }, CoordDataValue::Coord(coord) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Length(Au(coord).into()) + SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new(Au(coord).into(), None) ) }, CoordDataValue::Percent(p) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(Percentage(p)) + SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new(Au(0).into(), Some(Percentage(p))) ) }, CoordDataValue::Calc(calc) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Calc(calc.into()) - ) + SvgLengthPercentageOrNumber::LengthPercentage(calc.into()) }, _ => unreachable!("Unexpected coordinate in ${ident}"), }; @@ -941,10 +939,10 @@ def set_gecko_property(ffi_name, expr): transform_functions = [ ("Matrix3D", "matrix3d", ["number"] * 16), ("Matrix", "matrix", ["number"] * 6), - ("Translate", "translate", ["lop", "optional_lop"]), - ("Translate3D", "translate3d", ["lop", "lop", "length"]), - ("TranslateX", "translatex", ["lop"]), - ("TranslateY", "translatey", ["lop"]), + ("Translate", "translate", ["lp", "optional_lp"]), + ("Translate3D", "translate3d", ["lp", "lp", "length"]), + ("TranslateX", "translatex", ["lp"]), + ("TranslateY", "translatey", ["lp"]), ("TranslateZ", "translatez", ["length"]), ("Scale3D", "scale3d", ["number"] * 3), ("Scale", "scale", ["number", "optional_number"]), @@ -995,7 +993,7 @@ transform_functions = [ # Note: This is an integer type, but we use it as a percentage value in Gecko, so # need to cast it to f32. "integer_to_percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s as f32)", - "lop" : "%s.set_lop(%s)", + "lp" : "%s.set_length_percentage(%s)", "angle" : "%s.set_angle(%s)", "number" : "bindings::Gecko_CSSValue_SetNumber(%s, %s)", # Note: We use nsCSSValueSharedList here, instead of nsCSSValueList_heap @@ -1044,8 +1042,8 @@ transform_functions = [ # %s is substituted with the call to GetArrayItem. css_value_getters = { "length" : "Length::new(bindings::Gecko_CSSValue_GetNumber(%s))", - "lop" : "%s.get_lop()", - "lopon" : "Either::Second(%s.get_lop())", + "lp" : "%s.get_length_percentage()", + "lpon" : "Either::Second(%s.get_length_percentage())", "lon" : "Either::First(%s.get_length())", "angle" : "%s.get_angle()", "number" : "bindings::Gecko_CSSValue_GetNumber(%s)", @@ -1271,12 +1269,12 @@ pub fn clone_transform_from_list( #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> values::computed::TransformOrigin { - use crate::values::computed::{Length, LengthOrPercentage, TransformOrigin}; + use crate::values::computed::{Length, LengthPercentage, TransformOrigin}; TransformOrigin { - horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0]) - .expect("clone for LengthOrPercentage failed"), - vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) - .expect("clone for LengthOrPercentage failed"), + horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0]) + .expect("clone for LengthPercentage failed"), + vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) + .expect("clone for LengthPercentage failed"), depth: if let Some(third) = self.gecko.${gecko_ffi_name}.get(2) { Length::from_gecko_style_coord(third) .expect("clone for Length failed") @@ -1404,19 +1402,19 @@ impl Clone for ${style_struct.gecko_struct_name} { "length::LengthOrAuto": impl_style_coord, "length::LengthOrNormal": impl_style_coord, "length::NonNegativeLengthOrAuto": impl_style_coord, - "length::NonNegativeLengthOrPercentageOrNormal": impl_style_coord, + "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "FillRule": impl_simple, "FlexBasis": impl_style_coord, "Length": impl_absolute_length, "LengthOrNormal": impl_style_coord, - "LengthOrPercentage": impl_style_coord, - "LengthOrPercentageOrAuto": impl_style_coord, - "LengthOrPercentageOrNone": impl_style_coord, + "LengthPercentage": impl_style_coord, + "LengthPercentageOrAuto": impl_style_coord, + "LengthPercentageOrNone": impl_style_coord, "MaxLength": impl_style_coord, "MozLength": impl_style_coord, "MozScriptMinSize": impl_absolute_length, "MozScriptSizeMultiplier": impl_simple, - "NonNegativeLengthOrPercentage": impl_style_coord, + "NonNegativeLengthPercentage": impl_style_coord, "NonNegativeNumber": impl_simple, "Number": impl_simple, "Opacity": impl_simple, @@ -3086,7 +3084,7 @@ fn static_assert() { } pub fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T { - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; use crate::values::generics::box_::VerticalAlign; let gecko = &self.gecko.mVerticalAlign; @@ -3094,7 +3092,7 @@ fn static_assert() { CoordDataValue::Enumerated(value) => VerticalAlign::from_gecko_keyword(value), _ => { VerticalAlign::Length( - LengthOrPercentage::from_gecko_style_coord(gecko).expect( + LengthPercentage::from_gecko_style_coord(gecko).expect( "expected for vertical-align", ), ) @@ -3388,11 +3386,11 @@ fn static_assert() { pub fn clone_perspective_origin(&self) -> longhands::perspective_origin::computed_value::T { use crate::properties::longhands::perspective_origin::computed_value::T; - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; T { - horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0]) + horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0]) .expect("Expected length or percentage for horizontal value of perspective-origin"), - vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1]) + vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1]) .expect("Expected length or percentage for vertical value of perspective-origin"), } } @@ -3881,12 +3879,12 @@ fn static_assert() { pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T { use crate::gecko_bindings::structs::nsStyleCoord_CalcValue as CalcValue; use crate::gecko_bindings::structs::nsStyleImageLayers_Size_DimensionType as DimensionType; - use crate::values::computed::NonNegativeLengthOrPercentageOrAuto; + use crate::values::computed::NonNegativeLengthPercentageOrAuto; use crate::values::generics::background::BackgroundSize; - fn to_servo(value: CalcValue, ty: u8) -> NonNegativeLengthOrPercentageOrAuto { + fn to_servo(value: CalcValue, ty: u8) -> NonNegativeLengthPercentageOrAuto { if ty == DimensionType::eAuto as u8 { - NonNegativeLengthOrPercentageOrAuto::auto() + NonNegativeLengthPercentageOrAuto::auto() } else { debug_assert_eq!(ty, DimensionType::eLengthPercentage as u8); value.into() @@ -4570,14 +4568,14 @@ fn static_assert() { pub fn set_word_spacing(&mut self, v: longhands::word_spacing::computed_value::T) { use crate::values::generics::text::Spacing; match v { - Spacing::Value(lop) => self.gecko.mWordSpacing.set(lop), + Spacing::Value(lp) => self.gecko.mWordSpacing.set(lp), // https://drafts.csswg.org/css-text-3/#valdef-word-spacing-normal Spacing::Normal => self.gecko.mWordSpacing.set_value(CoordDataValue::Coord(0)), } } pub fn clone_word_spacing(&self) -> longhands::word_spacing::computed_value::T { - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; use crate::values::generics::text::Spacing; debug_assert!( matches!(self.gecko.mWordSpacing.as_value(), @@ -4586,7 +4584,7 @@ fn static_assert() { CoordDataValue::Percent(_) | CoordDataValue::Calc(_)), "Unexpected computed value for word-spacing"); - LengthOrPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing).map_or(Spacing::Normal, Spacing::Value) + LengthPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing).map_or(Spacing::Normal, Spacing::Value) } <%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"> @@ -5018,7 +5016,7 @@ clip-path pub fn set_stroke_dasharray(&mut self, v: longhands::stroke_dasharray::computed_value::T) { use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE; - use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthOrPercentageOrNumber}; + use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthPercentageOrNumber}; match v { SVGStrokeDashArray::Values(v) => { @@ -5029,9 +5027,9 @@ clip-path } for (gecko, servo) in self.gecko.mStrokeDasharray.iter_mut().zip(v) { match servo { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => - gecko.set(lop), - SvgLengthOrPercentageOrNumber::Number(num) => + SvgLengthPercentageOrNumber::LengthPercentage(lp) => + gecko.set(lp), + SvgLengthPercentageOrNumber::Number(num) => gecko.set_value(CoordDataValue::Factor(num.into())), } } @@ -5061,8 +5059,9 @@ clip-path pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T { use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE; - use crate::values::computed::LengthOrPercentage; - use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthOrPercentageOrNumber}; + use crate::values::computed::LengthPercentage; + use crate::values::generics::NonNegative; + use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthPercentageOrNumber}; if self.gecko.mContextFlags & CONTEXT_VALUE != 0 { debug_assert_eq!(self.gecko.mStrokeDasharray.len(), 0); @@ -5072,16 +5071,16 @@ clip-path for gecko in self.gecko.mStrokeDasharray.iter() { match gecko.as_value() { CoordDataValue::Factor(number) => - vec.push(SvgLengthOrPercentageOrNumber::Number(number.into())), + vec.push(SvgLengthPercentageOrNumber::Number(number.into())), CoordDataValue::Coord(coord) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Length(Au(coord).into()).into())), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::new(Au(coord).into(), None).into()))), CoordDataValue::Percent(p) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(Percentage(p)).into())), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::new_percent(Percentage(p)).into()))), CoordDataValue::Calc(calc) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Calc(calc.into()).into())), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::from(calc).clamp_to_non_negative()))), _ => unreachable!(), } } diff --git a/components/style/properties/longhands/background.mako.rs b/components/style/properties/longhands/background.mako.rs index b97545898c2..c6a25be53c1 100644 --- a/components/style/properties/longhands/background.mako.rs +++ b/components/style/properties/longhands/background.mako.rs @@ -35,7 +35,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "background-position-" + axis, "position::" + direction + "Position", - initial_value="computed::LengthOrPercentage::zero()", + initial_value="computed::LengthPercentage::zero()", initial_specified_value="SpecifiedValue::initial_specified_value()", spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis, animation_value_type="ComputedValue", diff --git a/components/style/properties/longhands/border.mako.rs b/components/style/properties/longhands/border.mako.rs index 3fcf73bf2f4..79df20d7812 100644 --- a/components/style/properties/longhands/border.mako.rs +++ b/components/style/properties/longhands/border.mako.rs @@ -69,7 +69,7 @@ ${helpers.gecko_keyword_conversion( type="crate::values::specified::BorderStyle", )} -// FIXME(#4126): when gfx supports painting it, make this Size2D +// FIXME(#4126): when gfx supports painting it, make this Size2D % for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]: ${helpers.predefined_type( "border-" + corner + "-radius", @@ -189,7 +189,7 @@ impl crate::values::computed::BorderImageWidth { use crate::gecko_bindings::structs::nsStyleUnit::{eStyleUnit_Factor, eStyleUnit_Auto}; use crate::gecko_bindings::sugar::ns_style_coord::CoordData; use crate::gecko::values::GeckoStyleCoordConvertible; - use crate::values::computed::{LengthOrPercentage, Number}; + use crate::values::computed::{LengthPercentage, Number}; use crate::values::generics::border::BorderImageSideWidth; use crate::values::generics::NonNegative; @@ -207,8 +207,8 @@ impl crate::values::computed::BorderImageWidth { }, _ => { BorderImageSideWidth::Length( - NonNegative(LengthOrPercentage::from_gecko_style_coord(&sides.data_at(${i})) - .expect("sides[${i}] could not convert to LengthOrPercentage"))) + NonNegative(LengthPercentage::from_gecko_style_coord(&sides.data_at(${i})) + .expect("sides[${i}] could not convert to LengthPercentage"))) }, }, % endfor diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index 48b83271d9b..1818179a442 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -611,10 +611,10 @@ ${helpers.predefined_type( ${helpers.predefined_type( "shape-margin", - "NonNegativeLengthOrPercentage", - "computed::NonNegativeLengthOrPercentage::zero()", + "NonNegativeLengthPercentage", + "computed::NonNegativeLengthPercentage::zero()", products="gecko", - animation_value_type="NonNegativeLengthOrPercentage", + animation_value_type="NonNegativeLengthPercentage", flags="APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-shapes/#shape-margin-property", )} diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 5a7b88e3823..b1ed79379ca 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -53,8 +53,8 @@ ${helpers.single_keyword( ${helpers.predefined_type( "text-indent", - "LengthOrPercentage", - "computed::LengthOrPercentage::Length(computed::Length::new(0.))", + "LengthPercentage", + "computed::LengthPercentage::zero()", animation_value_type="ComputedValue", spec="https://drafts.csswg.org/css-text/#propdef-text-indent", allow_quirks=True, diff --git a/components/style/properties/longhands/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs index 822fbf798a7..e5eac633c96 100644 --- a/components/style/properties/longhands/margin.mako.rs +++ b/components/style/properties/longhands/margin.mako.rs @@ -14,8 +14,8 @@ %> ${helpers.predefined_type( "margin-%s" % side[0], - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Length(computed::Length::new(0.))", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::zero()", alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), allow_quirks=not side[1], animation_value_type="ComputedValue", diff --git a/components/style/properties/longhands/padding.mako.rs b/components/style/properties/longhands/padding.mako.rs index edfc37d31e6..5fa51863629 100644 --- a/components/style/properties/longhands/padding.mako.rs +++ b/components/style/properties/longhands/padding.mako.rs @@ -16,10 +16,10 @@ %> ${helpers.predefined_type( "padding-%s" % side[0], - "NonNegativeLengthOrPercentage", - "computed::NonNegativeLengthOrPercentage::zero()", + "NonNegativeLengthPercentage", + "computed::NonNegativeLengthPercentage::zero()", alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"), - animation_value_type="NonNegativeLengthOrPercentage", + animation_value_type="NonNegativeLengthPercentage", logical=side[1], logical_group="padding", spec=spec, diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 53a3acf81ec..a7a6910f954 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -12,8 +12,8 @@ % for side in PHYSICAL_SIDES: ${helpers.predefined_type( side, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", animation_value_type="ComputedValue", @@ -26,8 +26,8 @@ % for side in LOGICAL_SIDES: ${helpers.predefined_type( "inset-%s" % side, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", spec="https://drafts.csswg.org/css-logical-props/#propdef-inset-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", alias="offset-%s:layout.css.offset-logical-properties.enabled" % side, @@ -285,8 +285,8 @@ ${helpers.predefined_type( // servo versions (no keyword support) ${helpers.predefined_type( size, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", "parse_non_negative", spec=spec % size, logical_group="size", @@ -296,8 +296,8 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( "min-%s" % size, - "LengthOrPercentage", - "computed::LengthOrPercentage::Length(computed::Length::new(0.))", + "LengthPercentage", + "computed::LengthPercentage::zero()", "parse_non_negative", spec=spec % ("min-%s" % size), logical_group="min-size", @@ -308,8 +308,8 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( "max-%s" % size, - "LengthOrPercentageOrNone", - "computed::LengthOrPercentageOrNone::None", + "LengthPercentageOrNone", + "computed::LengthPercentageOrNone::None", "parse_non_negative", spec=spec % ("max-%s" % size), logical_group="max-size", @@ -408,24 +408,24 @@ ${helpers.predefined_type( ${helpers.predefined_type( "column-gap", - "length::NonNegativeLengthOrPercentageOrNormal", + "length::NonNegativeLengthPercentageOrNormal", "Either::Second(Normal)", alias="grid-column-gap" if product == "gecko" else "", extra_prefixes="moz", servo_pref="layout.columns.enabled", spec="https://drafts.csswg.org/css-align-3/#propdef-column-gap", - animation_value_type="NonNegativeLengthOrPercentageOrNormal", + animation_value_type="NonNegativeLengthPercentageOrNormal", servo_restyle_damage="reflow", )} // no need for -moz- prefixed alias for this property ${helpers.predefined_type( "row-gap", - "length::NonNegativeLengthOrPercentageOrNormal", + "length::NonNegativeLengthPercentageOrNormal", "Either::Second(Normal)", alias="grid-row-gap", products="gecko", spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap", - animation_value_type="NonNegativeLengthOrPercentageOrNormal", + animation_value_type="NonNegativeLengthPercentageOrNormal", servo_restyle_damage="reflow", )} diff --git a/components/style/properties/longhands/svg.mako.rs b/components/style/properties/longhands/svg.mako.rs index 43a8952d86e..f003fa5222e 100644 --- a/components/style/properties/longhands/svg.mako.rs +++ b/components/style/properties/longhands/svg.mako.rs @@ -118,7 +118,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "mask-position-" + axis, "position::" + direction + "Position", - "computed::LengthOrPercentage::zero()", + "computed::LengthPercentage::zero()", products="gecko", extra_prefixes="webkit", initial_specified_value="specified::PositionComponent::Center", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 494bdc7706d..2d91273be15 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3017,7 +3017,7 @@ impl ComputedValuesInner { /// Get the logical computed inline size. #[inline] - pub fn content_inline_size(&self) -> computed::LengthOrPercentageOrAuto { + pub fn content_inline_size(&self) -> computed::LengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.height @@ -3028,42 +3028,42 @@ impl ComputedValuesInner { /// Get the logical computed block size. #[inline] - pub fn content_block_size(&self) -> computed::LengthOrPercentageOrAuto { + pub fn content_block_size(&self) -> computed::LengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } } /// Get the logical computed min inline size. #[inline] - pub fn min_inline_size(&self) -> computed::LengthOrPercentage { + pub fn min_inline_size(&self) -> computed::LengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width } } /// Get the logical computed min block size. #[inline] - pub fn min_block_size(&self) -> computed::LengthOrPercentage { + pub fn min_block_size(&self) -> computed::LengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height } } /// Get the logical computed max inline size. #[inline] - pub fn max_inline_size(&self) -> computed::LengthOrPercentageOrNone { + pub fn max_inline_size(&self) -> computed::LengthPercentageOrNone { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width } } /// Get the logical computed max block size. #[inline] - pub fn max_block_size(&self) -> computed::LengthOrPercentageOrNone { + pub fn max_block_size(&self) -> computed::LengthPercentageOrNone { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height } } /// Get the logical computed padding for this writing mode. #[inline] - pub fn logical_padding(&self) -> LogicalMargin { + pub fn logical_padding(&self) -> LogicalMargin { let padding_style = self.get_padding(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( padding_style.padding_top.0, @@ -3093,7 +3093,7 @@ impl ComputedValuesInner { /// Gets the logical computed margin from this style. #[inline] - pub fn logical_margin(&self) -> LogicalMargin { + pub fn logical_margin(&self) -> LogicalMargin { let margin_style = self.get_margin(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( margin_style.margin_top, @@ -3105,7 +3105,7 @@ impl ComputedValuesInner { /// Gets the logical position from this style. #[inline] - pub fn logical_position(&self) -> LogicalMargin { + pub fn logical_position(&self) -> LogicalMargin { // FIXME(SimonSapin): should be the writing mode of the containing block, maybe? let position_style = self.get_position(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( diff --git a/components/style/properties/shorthands/margin.mako.rs b/components/style/properties/shorthands/margin.mako.rs index 944d4a3e6a1..86e3b56a226 100644 --- a/components/style/properties/shorthands/margin.mako.rs +++ b/components/style/properties/shorthands/margin.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthOrPercentageOrAuto::parse", +${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthPercentageOrAuto::parse", spec="https://drafts.csswg.org/css-box/#propdef-margin", allowed_in_page_rule=True, allow_quirks=True)} diff --git a/components/style/properties/shorthands/padding.mako.rs b/components/style/properties/shorthands/padding.mako.rs index 41db5d3a0fe..0314a46938d 100644 --- a/components/style/properties/shorthands/padding.mako.rs +++ b/components/style/properties/shorthands/padding.mako.rs @@ -4,6 +4,6 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthOrPercentage::parse", +${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthPercentage::parse", spec="https://drafts.csswg.org/css-box-3/#propdef-padding", allow_quirks=True)} diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index 4df576a15ab..862399e065c 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -18,7 +18,9 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard use crate::str::CssStringWriter; use crate::stylesheets::{Origin, StylesheetInDocument}; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::specified::{LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; +use crate::values::specified::{ + self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength, +}; use app_units::Au; use cssparser::CowRcStr; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; @@ -149,7 +151,7 @@ trait FromMeta: Sized { #[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive(Clone, Debug, PartialEq, ToCss)] pub enum ViewportLength { - Specified(LengthOrPercentageOrAuto), + Specified(LengthPercentageOrAuto), ExtendToZoom, } @@ -157,7 +159,9 @@ impl FromMeta for ViewportLength { fn from_meta(value: &str) -> Option { macro_rules! specified { ($value:expr) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length($value)) + ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length($value), + )) }; } @@ -184,7 +188,7 @@ impl ViewportLength { ) -> Result> { // we explicitly do not accept 'extend-to-zoom', since it is a UA // internal value for viewport translation - LengthOrPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) + LengthPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) } } @@ -466,10 +470,10 @@ impl ViewportRule { if !has_width && has_zoom { if has_height { push_descriptor!(MinWidth(ViewportLength::Specified( - LengthOrPercentageOrAuto::Auto + LengthPercentageOrAuto::Auto ))); push_descriptor!(MaxWidth(ViewportLength::Specified( - LengthOrPercentageOrAuto::Auto + LengthPercentageOrAuto::Auto ))); } else { push_descriptor!(MinWidth(ViewportLength::ExtendToZoom)); @@ -752,16 +756,11 @@ impl MaybeNew for ViewportConstraints { if let Some($value) = $value { match *$value { ViewportLength::Specified(ref length) => match *length { - LengthOrPercentageOrAuto::Length(ref value) => { - Some(Au::from(value.to_computed_value(&context))) - }, - LengthOrPercentageOrAuto::Percentage(value) => { - Some(initial_viewport.$dimension.scale_by(value.0)) - }, - LengthOrPercentageOrAuto::Auto => None, - LengthOrPercentageOrAuto::Calc(ref calc) => calc - .to_computed_value(&context) - .to_used_value(Some(initial_viewport.$dimension)), + LengthPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(ref lop) => Some( + lop.to_computed_value(&context) + .to_used_value(initial_viewport.$dimension), + ), }, ViewportLength::ExtendToZoom => { // $extend_to will be 'None' if 'extend-to-zoom' is 'auto' diff --git a/components/style/values/animated/length.rs b/components/style/values/animated/length.rs index e303d2fcfce..672c4117b00 100644 --- a/components/style/values/animated/length.rs +++ b/components/style/values/animated/length.rs @@ -4,15 +4,14 @@ //! Animation implementation for various length-related types. -use super::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; -use crate::values::computed::length::{CalcLengthOrPercentage, Length}; -use crate::values::computed::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +use super::{Animate, Procedure, ToAnimatedValue}; +use crate::values::computed::length::LengthPercentage; use crate::values::computed::MaxLength as ComputedMaxLength; use crate::values::computed::MozLength as ComputedMozLength; use crate::values::computed::Percentage; /// -impl Animate for CalcLengthOrPercentage { +impl Animate for LengthPercentage { #[inline] fn animate(&self, other: &Self, procedure: Procedure) -> Result { let animate_percentage_half = |this: Option, other: Option| { @@ -28,42 +27,19 @@ impl Animate for CalcLengthOrPercentage { .unclamped_length() .animate(&other.unclamped_length(), procedure)?; let percentage = animate_percentage_half(self.percentage, other.percentage)?; - Ok(CalcLengthOrPercentage::with_clamping_mode( + let is_calc = self.was_calc || + other.was_calc || + self.percentage.is_some() != other.percentage.is_some(); + Ok(Self::with_clamping_mode( length, percentage, self.clamping_mode, + is_calc, )) } } -impl ToAnimatedZero for LengthOrPercentageOrAuto { - #[inline] - fn to_animated_zero(&self) -> Result { - match *self { - LengthOrPercentageOrAuto::Length(_) | - LengthOrPercentageOrAuto::Percentage(_) | - LengthOrPercentageOrAuto::Calc(_) => { - Ok(LengthOrPercentageOrAuto::Length(Length::new(0.))) - }, - LengthOrPercentageOrAuto::Auto => Err(()), - } - } -} - -impl ToAnimatedZero for LengthOrPercentageOrNone { - #[inline] - fn to_animated_zero(&self) -> Result { - match *self { - LengthOrPercentageOrNone::Length(_) | - LengthOrPercentageOrNone::Percentage(_) | - LengthOrPercentageOrNone::Calc(_) => { - Ok(LengthOrPercentageOrNone::Length(Length::new(0.))) - }, - LengthOrPercentageOrNone::None => Err(()), - } - } -} - +// FIXME(emilio): These should use NonNegative<> instead. impl ToAnimatedValue for ComputedMaxLength { type AnimatedValue = Self; @@ -74,20 +50,17 @@ impl ToAnimatedValue for ComputedMaxLength { #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::{Length, LengthOrPercentageOrNone, Percentage}; + use crate::values::computed::LengthPercentageOrNone; use crate::values::generics::length::MaxLength as GenericMaxLength; match animated { - GenericMaxLength::LengthOrPercentageOrNone(lopn) => { - let result = match lopn { - LengthOrPercentageOrNone::Length(px) => { - LengthOrPercentageOrNone::Length(Length::new(px.px().max(0.))) + GenericMaxLength::LengthPercentageOrNone(lpn) => { + let result = match lpn { + LengthPercentageOrNone::LengthPercentage(len) => { + LengthPercentageOrNone::LengthPercentage(len.clamp_to_non_negative()) }, - LengthOrPercentageOrNone::Percentage(percentage) => { - LengthOrPercentageOrNone::Percentage(Percentage(percentage.0.max(0.))) - }, - _ => lopn, + LengthPercentageOrNone::None => lpn, }; - GenericMaxLength::LengthOrPercentageOrNone(result) + GenericMaxLength::LengthPercentageOrNone(result) }, _ => animated, } @@ -104,20 +77,10 @@ impl ToAnimatedValue for ComputedMozLength { #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::{Length, LengthOrPercentageOrAuto, Percentage}; use crate::values::generics::length::MozLength as GenericMozLength; match animated { - GenericMozLength::LengthOrPercentageOrAuto(lopa) => { - let result = match lopa { - LengthOrPercentageOrAuto::Length(px) => { - LengthOrPercentageOrAuto::Length(Length::new(px.px().max(0.))) - }, - LengthOrPercentageOrAuto::Percentage(percentage) => { - LengthOrPercentageOrAuto::Percentage(Percentage(percentage.0.max(0.))) - }, - _ => lopa, - }; - GenericMozLength::LengthOrPercentageOrAuto(result) + GenericMozLength::LengthPercentageOrAuto(lpa) => { + GenericMozLength::LengthPercentageOrAuto(lpa.clamp_to_non_negative()) }, _ => animated, } diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index a7c947f810a..a4e79074ef6 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -9,7 +9,7 @@ //! module's raison d'être is to ultimately contain all these types. use crate::properties::PropertyId; -use crate::values::computed::length::CalcLengthOrPercentage; +use crate::values::computed::length::LengthPercentage; use crate::values::computed::url::ComputedUrl; use crate::values::computed::Angle as ComputedAngle; use crate::values::computed::Image; @@ -335,7 +335,7 @@ macro_rules! trivial_to_animated_value { } trivial_to_animated_value!(Au); -trivial_to_animated_value!(CalcLengthOrPercentage); +trivial_to_animated_value!(LengthPercentage); trivial_to_animated_value!(ComputedAngle); trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); diff --git a/components/style/values/animated/svg.rs b/components/style/values/animated/svg.rs index 1d8be90fb6e..af627bba784 100644 --- a/components/style/values/animated/svg.rs +++ b/components/style/values/animated/svg.rs @@ -8,9 +8,9 @@ use super::{Animate, Procedure, ToAnimatedZero}; use crate::properties::animated_properties::ListAnimation; use crate::values::animated::color::Color as AnimatedColor; use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{LengthOrPercentage, Number, NumberOrPercentage}; +use crate::values::computed::{LengthPercentage, Number, NumberOrPercentage}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; -use crate::values::generics::svg::{SVGLength, SVGPaint, SvgLengthOrPercentageOrNumber}; +use crate::values::generics::svg::{SVGLength, SVGPaint, SvgLengthPercentageOrNumber}; use crate::values::generics::svg::{SVGOpacity, SVGStrokeDashArray}; /// Animated SVGPaint. @@ -29,19 +29,23 @@ impl ToAnimatedZero for IntermediateSVGPaint { // FIXME: We need to handle calc here properly, see // https://bugzilla.mozilla.org/show_bug.cgi?id=1386967 fn to_number_or_percentage( - value: &SvgLengthOrPercentageOrNumber, + value: &SvgLengthPercentageOrNumber, ) -> Result { Ok(match *value { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref l) => match *l { - LengthOrPercentage::Length(ref l) => NumberOrPercentage::Number(l.px()), - LengthOrPercentage::Percentage(ref p) => NumberOrPercentage::Percentage(*p), - LengthOrPercentage::Calc(..) => return Err(()), + SvgLengthPercentageOrNumber::LengthPercentage(ref l) => match l.percentage { + Some(p) => { + if l.unclamped_length().px() != 0. { + return Err(()); + } + NumberOrPercentage::Percentage(p) + }, + None => NumberOrPercentage::Number(l.length().px()), }, - SvgLengthOrPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), + SvgLengthPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), }) } -impl Animate for SvgLengthOrPercentageOrNumber { +impl Animate for SvgLengthPercentageOrNumber { #[inline] fn animate(&self, other: &Self, procedure: Procedure) -> Result { let this = to_number_or_percentage(self)?; @@ -49,20 +53,20 @@ impl Animate for SvgLengthOrPercentageOrNumber { match (this, other) { (NumberOrPercentage::Number(ref this), NumberOrPercentage::Number(ref other)) => Ok( - SvgLengthOrPercentageOrNumber::Number(this.animate(other, procedure)?), + SvgLengthPercentageOrNumber::Number(this.animate(other, procedure)?), ), ( NumberOrPercentage::Percentage(ref this), NumberOrPercentage::Percentage(ref other), - ) => Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(this.animate(other, procedure)?), + ) => Ok(SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new_percent(this.animate(other, procedure)?), )), _ => Err(()), } } } -impl ComputeSquaredDistance for SvgLengthOrPercentageOrNumber { +impl ComputeSquaredDistance for SvgLengthPercentageOrNumber { fn compute_squared_distance(&self, other: &Self) -> Result { to_number_or_percentage(self)?.compute_squared_distance(&to_number_or_percentage(other)?) } diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index 5223a195075..c341ca770ed 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -16,7 +16,7 @@ use crate::values::computed::transform::TransformOperation as ComputedTransformO use crate::values::computed::transform::Translate as ComputedTranslate; use crate::values::computed::transform::{DirectionVector, Matrix, Matrix3D}; use crate::values::computed::Angle; -use crate::values::computed::{Length, LengthOrPercentage}; +use crate::values::computed::{Length, LengthPercentage}; use crate::values::computed::{Number, Percentage}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::transform::{self, Transform, TransformOperation}; @@ -1043,8 +1043,8 @@ impl Animate for ComputedTransformOperation { ) => Ok(TransformOperation::Translate( fx.animate(tx, procedure)?, Some( - fy.unwrap_or(LengthOrPercentage::zero()) - .animate(&ty.unwrap_or(LengthOrPercentage::zero()), procedure)?, + fy.unwrap_or(LengthPercentage::zero()) + .animate(&ty.unwrap_or(LengthPercentage::zero()), procedure)?, ), )), (&TransformOperation::TranslateX(ref f), &TransformOperation::TranslateX(ref t)) => { @@ -1167,17 +1167,6 @@ impl Animate for ComputedTransformOperation { // See https://bugzilla.mozilla.org/show_bug.cgi?id=1318591#c0. impl ComputeSquaredDistance for ComputedTransformOperation { fn compute_squared_distance(&self, other: &Self) -> Result { - // For translate, We don't want to require doing layout in order to calculate the result, so - // drop the percentage part. However, dropping percentage makes us impossible to - // compute the distance for the percentage-percentage case, but Gecko uses the - // same formula, so it's fine for now. - // Note: We use pixel value to compute the distance for translate, so we have to - // convert Au into px. - let extract_pixel_length = |lop: &LengthOrPercentage| match *lop { - LengthOrPercentage::Length(px) => px.px(), - LengthOrPercentage::Percentage(_) => 0., - LengthOrPercentage::Calc(calc) => calc.length().px(), - }; match (self, other) { (&TransformOperation::Matrix3D(ref this), &TransformOperation::Matrix3D(ref other)) => { this.compute_squared_distance(other) @@ -1199,10 +1188,16 @@ impl ComputeSquaredDistance for ComputedTransformOperation { &TransformOperation::Translate3D(ref fx, ref fy, ref fz), &TransformOperation::Translate3D(ref tx, ref ty, ref tz), ) => { - let fx = extract_pixel_length(&fx); - let fy = extract_pixel_length(&fy); - let tx = extract_pixel_length(&tx); - let ty = extract_pixel_length(&ty); + // For translate, We don't want to require doing layout in order + // to calculate the result, so drop the percentage part. + // + // However, dropping percentage makes us impossible to compute + // the distance for the percentage-percentage case, but Gecko + // uses the same formula, so it's fine for now. + let fx = fx.length_component().px(); + let fy = fy.length_component().px(); + let tx = tx.length_component().px(); + let ty = ty.length_component().px(); Ok(fx.compute_squared_distance(&tx)? + fy.compute_squared_distance(&ty)? + @@ -1388,15 +1383,15 @@ impl ComputeSquaredDistance for ComputedRotate { /// impl ComputedTranslate { - fn resolve(&self) -> (LengthOrPercentage, LengthOrPercentage, Length) { + fn resolve(&self) -> (LengthPercentage, LengthPercentage, Length) { // According to the spec: // https://drafts.csswg.org/css-transforms-2/#individual-transforms // // Unspecified translations default to 0px match *self { Translate::None => ( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), Length::zero(), ), Translate::Translate3D(tx, ty, tz) => (tx, ty, tz), diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index 82db7e0fdeb..08f10c9c1ec 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -4,20 +4,20 @@ //! Computed types for CSS values related to backgrounds. -use crate::values::computed::length::NonNegativeLengthOrPercentageOrAuto; +use crate::values::computed::length::NonNegativeLengthPercentageOrAuto; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; pub use crate::values::specified::background::BackgroundRepeat; /// A computed value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl BackgroundSize { /// Returns `auto auto`. pub fn auto() -> Self { GenericBackgroundSize::Explicit { - width: NonNegativeLengthOrPercentageOrAuto::auto(), - height: NonNegativeLengthOrPercentageOrAuto::auto(), + width: NonNegativeLengthPercentageOrAuto::auto(), + height: NonNegativeLengthPercentageOrAuto::auto(), } } } diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index f808e0bf9f5..28067fb0c81 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -8,7 +8,7 @@ //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{Image, LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage}; use crate::values::generics::basic_shape as generic; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; @@ -24,25 +24,24 @@ pub type FloatAreaShape = generic::FloatAreaShape; /// A computed basic shape. pub type BasicShape = generic::BasicShape< - LengthOrPercentage, - LengthOrPercentage, - LengthOrPercentage, - NonNegativeLengthOrPercentage, + LengthPercentage, + LengthPercentage, + LengthPercentage, + NonNegativeLengthPercentage, >; /// The computed value of `inset()` -pub type InsetRect = generic::InsetRect; +pub type InsetRect = generic::InsetRect; /// A computed circle. -pub type Circle = - generic::Circle; +pub type Circle = generic::Circle; /// A computed ellipse. pub type Ellipse = - generic::Ellipse; + generic::Ellipse; /// The computed value of `ShapeRadius` -pub type ShapeRadius = generic::ShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; impl ToCss for Circle { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result diff --git a/components/style/values/computed/border.rs b/components/style/values/computed/border.rs index c6ab4abc5a5..e85b5a3e5d6 100644 --- a/components/style/values/computed/border.rs +++ b/components/style/values/computed/border.rs @@ -4,7 +4,7 @@ //! Computed types for CSS values related to borders. -use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; +use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthPercentage}; use crate::values::computed::{NonNegativeNumber, NonNegativeNumberOrPercentage}; use crate::values::generics::border::BorderCornerRadius as GenericBorderCornerRadius; use crate::values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth; @@ -23,16 +23,16 @@ pub type BorderImageWidth = Rect; /// A computed value for a single side of a `border-image-width` property. pub type BorderImageSideWidth = - GenericBorderImageSideWidth; + GenericBorderImageSideWidth; /// A computed value for the `border-image-slice` property. pub type BorderImageSlice = GenericBorderImageSlice; /// A computed value for the `border-radius` property. -pub type BorderRadius = GenericBorderRadius; +pub type BorderRadius = GenericBorderRadius; /// A computed value for the `border-*-radius` longhand properties. -pub type BorderCornerRadius = GenericBorderCornerRadius; +pub type BorderCornerRadius = GenericBorderCornerRadius; /// A computed value for the `border-spacing` longhand property. pub type BorderSpacing = GenericBorderSpacing; @@ -80,8 +80,8 @@ impl BorderCornerRadius { /// Returns `0 0`. pub fn zero() -> Self { GenericBorderCornerRadius(Size::new( - NonNegativeLengthOrPercentage::zero(), - NonNegativeLengthOrPercentage::zero(), + NonNegativeLengthPercentage::zero(), + NonNegativeLengthPercentage::zero(), )) } } @@ -90,8 +90,8 @@ impl BorderRadius { /// Returns whether all the values are `0px`. pub fn all_zero(&self) -> bool { fn all(corner: &BorderCornerRadius) -> bool { - fn is_zero(l: &NonNegativeLengthOrPercentage) -> bool { - *l == NonNegativeLengthOrPercentage::zero() + fn is_zero(l: &NonNegativeLengthPercentage) -> bool { + *l == NonNegativeLengthPercentage::zero() } is_zero(corner.0.width()) && is_zero(corner.0.height()) } diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index 32ac16fb574..381ae7b364e 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -4,7 +4,7 @@ //! Computed types for box properties. -use crate::values::computed::length::{LengthOrPercentage, NonNegativeLength}; +use crate::values::computed::length::{LengthPercentage, NonNegativeLength}; use crate::values::computed::{Context, Number, ToComputedValue}; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::Perspective as GenericPerspective; @@ -18,7 +18,7 @@ pub use crate::values::specified::box_::{OverscrollBehavior, ScrollSnapType}; pub use crate::values::specified::box_::{TouchAction, TransitionProperty, WillChange}; /// A computed value for the `vertical-align` property. -pub type VerticalAlign = GenericVerticalAlign; +pub type VerticalAlign = GenericVerticalAlign; /// A computed value for the `animation-iteration-count` property. pub type AnimationIterationCount = GenericAnimationIterationCount; diff --git a/components/style/values/computed/flex.rs b/components/style/values/computed/flex.rs index fb65aaeae87..a48d7800752 100644 --- a/components/style/values/computed/flex.rs +++ b/components/style/values/computed/flex.rs @@ -8,7 +8,7 @@ use crate::values::generics::flex::FlexBasis as GenericFlexBasis; /// The `width` value type. #[cfg(feature = "servo")] -pub type Width = crate::values::computed::NonNegativeLengthOrPercentageOrAuto; +pub type Width = crate::values::computed::NonNegativeLengthPercentageOrAuto; /// The `width` value type. #[cfg(feature = "gecko")] diff --git a/components/style/values/computed/gecko.rs b/components/style/values/computed/gecko.rs index bf0e24f67ae..cbe0802eab8 100644 --- a/components/style/values/computed/gecko.rs +++ b/components/style/values/computed/gecko.rs @@ -4,8 +4,8 @@ //! Computed types for legacy Gecko-only properties. -use crate::values::computed::length::LengthOrPercentage; +use crate::values::computed::length::LengthPercentage; use crate::values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; /// A computed type for scroll snap points. -pub type ScrollSnapPoint = GenericScrollSnapPoint; +pub type ScrollSnapPoint = GenericScrollSnapPoint; diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index ba18e4b30c8..a77da59dda3 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -9,10 +9,8 @@ use crate::values::computed::position::Position; use crate::values::computed::url::ComputedImageUrl; -#[cfg(feature = "gecko")] -use crate::values::computed::Percentage; use crate::values::computed::{Angle, Color, Context}; -use crate::values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue}; +use crate::values::computed::{Length, LengthPercentage, NumberOrPercentage, ToComputedValue}; use crate::values::generics::image::{self as generic, CompatMode}; use crate::values::specified::image::LineDirection as SpecifiedLineDirection; use crate::values::specified::position::{X, Y}; @@ -31,11 +29,11 @@ pub type Image = generic::Image; /// Computed values for a CSS gradient. /// pub type Gradient = - generic::Gradient; + generic::Gradient; /// A computed gradient kind. pub type GradientKind = - generic::GradientKind; + generic::GradientKind; /// A computed gradient line direction. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)] @@ -54,13 +52,13 @@ pub enum LineDirection { } /// A computed radial gradient ending shape. -pub type EndingShape = generic::EndingShape; +pub type EndingShape = generic::EndingShape; /// A computed gradient item. -pub type GradientItem = generic::GradientItem; +pub type GradientItem = generic::GradientItem; /// A computed color stop. -pub type ColorStop = generic::ColorStop; +pub type ColorStop = generic::ColorStop; /// Computed values for `-moz-image-rect(...)`. pub type MozImageRect = generic::MozImageRect; @@ -75,13 +73,14 @@ impl generic::LineDirection for LineDirection { #[cfg(feature = "gecko")] LineDirection::MozPosition( Some(Position { - horizontal: LengthOrPercentage::Percentage(Percentage(x)), - vertical: LengthOrPercentage::Percentage(Percentage(y)), + ref vertical, + ref horizontal, }), None, ) => { // `50% 0%` is the default value for line direction. - x == 0.5 && y == 0.0 + horizontal.as_percentage().map_or(false, |p| p.0 == 0.5) && + vertical.as_percentage().map_or(false, |p| p.0 == 0.0) }, _ => false, } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 240b5ceb1ee..daf14ea19e3 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -5,7 +5,7 @@ //! `` computed values, and related ones. use super::{Context, Number, Percentage, ToComputedValue}; -use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; +use crate::values::animated::ToAnimatedValue; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::length::MaxLength as GenericMaxLength; use crate::values::generics::length::MozLength as GenericMozLength; @@ -67,16 +67,43 @@ impl ToComputedValue for specified::Length { } } +/// A `` value. This can be either a ``, a +/// ``, or a combination of both via `calc()`. +/// +/// https://drafts.csswg.org/css-values-4/#typedef-length-percentage #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToAnimatedZero)] -pub struct CalcLengthOrPercentage { +#[derive(Clone, Copy, Debug, MallocSizeOf, ToAnimatedZero)] +pub struct LengthPercentage { #[animation(constant)] pub clamping_mode: AllowedNumericType, length: Length, pub percentage: Option, + /// Whether this was from a calc() expression. This is needed because right + /// now we don't treat calc() the same way as non-calc everywhere, but + /// that's a bug in most cases. + /// + /// Please don't add new uses of this that aren't for converting to Gecko's + /// representation, or to interpolate values. + /// + /// See https://github.com/w3c/csswg-drafts/issues/3482. + #[animation(constant)] + pub was_calc: bool, } -impl ComputeSquaredDistance for CalcLengthOrPercentage { +// FIXME(emilio): This is a bit of a hack that can disappear as soon as we share +// representation of LengthPercentage with Gecko. The issue here is that Gecko +// uses CalcValue to represent position components, so they always come back as +// was_calc == true, and we mess up in the transitions code. +// +// This was a pre-existing bug, though arguably so only in pretty obscure cases +// like calc(0px + 5%) and such. +impl PartialEq for LengthPercentage { + fn eq(&self, other: &Self) -> bool { + self.length == other.length && self.percentage == other.percentage + } +} + +impl ComputeSquaredDistance for LengthPercentage { #[inline] fn compute_squared_distance(&self, other: &Self) -> Result { // FIXME(nox): This looks incorrect to me, to add a distance between lengths @@ -89,24 +116,36 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage { } } -impl CalcLengthOrPercentage { - /// Returns a new `CalcLengthOrPercentage`. +impl LengthPercentage { + /// Returns a new `LengthPercentage`. #[inline] pub fn new(length: Length, percentage: Option) -> Self { - Self::with_clamping_mode(length, percentage, AllowedNumericType::All) + Self::with_clamping_mode( + length, + percentage, + AllowedNumericType::All, + /* was_calc = */ false, + ) } - /// Returns a new `CalcLengthOrPercentage` with a specific clamping mode. + /// Returns a new `LengthPercentage` with zero length and some percentage. + pub fn new_percent(percentage: Percentage) -> Self { + Self::new(Length::zero(), Some(percentage)) + } + + /// Returns a new `LengthPercentage` with a specific clamping mode. #[inline] pub fn with_clamping_mode( length: Length, percentage: Option, clamping_mode: AllowedNumericType, + was_calc: bool, ) -> Self { Self { clamping_mode, length, percentage, + was_calc, } } @@ -137,16 +176,31 @@ impl CalcLengthOrPercentage { self.percentage.map_or(0., |p| p.0) } + /// Returns the percentage component if this could be represented as a + /// non-calc percentage. + pub fn as_percentage(&self) -> Option { + if self.length.px() != 0. { + return None; + } + + let p = self.percentage?; + if self.clamping_mode.clamp(p.0) != p.0 { + return None; + } + + Some(p) + } + /// Convert the computed value into used value. #[inline] - pub fn to_used_value(&self, container_len: Option) -> Option { - self.to_pixel_length(container_len).map(Au::from) + pub fn maybe_to_used_value(&self, container_len: Option) -> Option { + self.maybe_to_pixel_length(container_len).map(Au::from) } /// If there are special rules for computing percentages in a value (e.g. /// the height property), they apply whenever a calc() expression contains /// percentages. - pub fn to_pixel_length(&self, container_len: Option) -> Option { + pub fn maybe_to_pixel_length(&self, container_len: Option) -> Option { match (container_len, self.percentage) { (Some(len), Some(percent)) => { let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px(); @@ -158,92 +212,23 @@ impl CalcLengthOrPercentage { } } -impl From for CalcLengthOrPercentage { - fn from(len: LengthOrPercentage) -> CalcLengthOrPercentage { - match len { - LengthOrPercentage::Percentage(this) => { - CalcLengthOrPercentage::new(Length::new(0.), Some(this)) - }, - LengthOrPercentage::Length(this) => CalcLengthOrPercentage::new(this, None), - LengthOrPercentage::Calc(this) => this, - } - } -} - -impl From for Option { - fn from(len: LengthOrPercentageOrAuto) -> Option { - match len { - LengthOrPercentageOrAuto::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) - }, - LengthOrPercentageOrAuto::Length(this) => Some(CalcLengthOrPercentage::new(this, None)), - LengthOrPercentageOrAuto::Calc(this) => Some(this), - LengthOrPercentageOrAuto::Auto => None, - } - } -} - -impl From for Option { - fn from(len: LengthOrPercentageOrNone) -> Option { - match len { - LengthOrPercentageOrNone::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) - }, - LengthOrPercentageOrNone::Length(this) => Some(CalcLengthOrPercentage::new(this, None)), - LengthOrPercentageOrNone::Calc(this) => Some(this), - LengthOrPercentageOrNone::None => None, - } - } -} - -impl ToCss for CalcLengthOrPercentage { +impl ToCss for LengthPercentage { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, { - use num_traits::Zero; - - let length = self.unclamped_length(); - match self.percentage { - Some(p) => { - if length.px() == 0. && self.clamping_mode.clamp(p.0) == p.0 { - return p.to_css(dest); - } - }, - None => { - if self.clamping_mode.clamp(length.px()) == length.px() { - return length.to_css(dest); - } - }, - } - - dest.write_str("calc(")?; - if let Some(percentage) = self.percentage { - percentage.to_css(dest)?; - if length.px() != 0. { - dest.write_str(if length.px() < Zero::zero() { - " - " - } else { - " + " - })?; - length.abs().to_css(dest)?; - } - } else { - length.to_css(dest)?; - } - - dest.write_str(")") + specified::LengthPercentage::from_computed_value(self).to_css(dest) } } -impl specified::CalcLengthOrPercentage { +impl specified::CalcLengthPercentage { /// Compute the value, zooming any absolute units by the zoom function. fn to_computed_value_with_zoom( &self, context: &Context, zoom_fn: F, base_size: FontBaseSize, - ) -> CalcLengthOrPercentage + ) -> LengthPercentage where F: Fn(Length) -> Length, { @@ -277,10 +262,11 @@ impl specified::CalcLengthOrPercentage { } } - CalcLengthOrPercentage { + LengthPercentage { clamping_mode: self.clamping_mode, length: Length::new(length.min(f32::MAX).max(f32::MIN)), percentage: self.percentage, + was_calc: true, } } @@ -289,7 +275,7 @@ impl specified::CalcLengthOrPercentage { &self, context: &Context, base_size: FontBaseSize, - ) -> CalcLengthOrPercentage { + ) -> LengthPercentage { self.to_computed_value_with_zoom( context, |abs| context.maybe_zoom_text(abs.into()).0, @@ -323,17 +309,17 @@ impl specified::CalcLengthOrPercentage { } } -impl ToComputedValue for specified::CalcLengthOrPercentage { - type ComputedValue = CalcLengthOrPercentage; +impl ToComputedValue for specified::CalcLengthPercentage { + type ComputedValue = LengthPercentage; - fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage { + fn to_computed_value(&self, context: &Context) -> LengthPercentage { // normal properties don't zoom, and compute em units against the current style's font-size self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle) } #[inline] - fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self { - specified::CalcLengthOrPercentage { + fn from_computed_value(computed: &LengthPercentage) -> Self { + specified::CalcLengthPercentage { clamping_mode: computed.clamping_mode, absolute: Some(AbsoluteLength::from_computed_value(&computed.length)), percentage: computed.percentage, @@ -342,95 +328,33 @@ impl ToComputedValue for specified::CalcLengthOrPercentage { } } -#[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] -#[css(derive_debug)] -#[derive( - Animate, - Clone, - ComputeSquaredDistance, - Copy, - MallocSizeOf, - PartialEq, - ToAnimatedValue, - ToAnimatedZero, - ToCss, -)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] -pub enum LengthOrPercentage { - Length(Length), - Percentage(Percentage), - Calc(CalcLengthOrPercentage), -} - -impl LengthOrPercentage { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - // Special handling for zero values since these should not require calc(). - if self.is_definitely_zero() { - return other.to_animated_zero()?.animate(other, procedure); - } - if other.is_definitely_zero() { - return self.animate(&self.to_animated_zero()?, procedure); - } - - let this = CalcLengthOrPercentage::from(*self); - let other = CalcLengthOrPercentage::from(*other); - Ok(LengthOrPercentage::Calc(this.animate(&other, procedure)?)) - } - - #[inline] - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - CalcLengthOrPercentage::compute_squared_distance(&(*self).into(), &(*other).into()) - } -} - -impl From for LengthOrPercentage { - #[inline] - fn from(length: Au) -> Self { - LengthOrPercentage::Length(length.into()) - } -} - -impl LengthOrPercentage { +impl LengthPercentage { #[inline] #[allow(missing_docs)] - pub fn zero() -> LengthOrPercentage { - LengthOrPercentage::Length(Length::new(0.)) + pub fn zero() -> LengthPercentage { + LengthPercentage::new(Length::new(0.), None) } - #[inline] /// 1px length value for SVG defaults - pub fn one() -> LengthOrPercentage { - LengthOrPercentage::Length(Length::new(1.)) + #[inline] + pub fn one() -> LengthPercentage { + LengthPercentage::new(Length::new(1.), None) } /// Returns true if the computed value is absolute 0 or 0%. - /// - /// (Returns false for calc() values, even if ones that may resolve to zero.) #[inline] pub fn is_definitely_zero(&self) -> bool { - use self::LengthOrPercentage::*; - match *self { - Length(l) => l.px() == 0.0, - Percentage(p) => p.0 == 0.0, - Calc(_) => false, - } + self.unclamped_length().px() == 0.0 && self.percentage.map_or(true, |p| p.0 == 0.0) } // CSSFloat doesn't implement Hash, so does CSSPixelLength. Therefore, we still use Au as the // hash key. #[allow(missing_docs)] pub fn to_hash_key(&self) -> (Au, NotNan) { - use self::LengthOrPercentage::*; - match *self { - Length(l) => (Au::from(l), NotNan::new(0.0).unwrap()), - Percentage(p) => (Au(0), NotNan::new(p.0).unwrap()), - Calc(c) => ( - Au::from(c.unclamped_length()), - NotNan::new(c.percentage()).unwrap(), - ), - } + ( + Au::from(self.unclamped_length()), + NotNan::new(self.percentage()).unwrap(), + ) } /// Returns the used value. @@ -440,124 +364,118 @@ impl LengthOrPercentage { /// Returns the used value as CSSPixelLength. pub fn to_pixel_length(&self, containing_length: Au) -> Length { - match *self { - LengthOrPercentage::Length(length) => length, - LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0).into(), - LengthOrPercentage::Calc(ref calc) => { - calc.to_pixel_length(Some(containing_length)).unwrap() - }, - } + self.maybe_to_pixel_length(Some(containing_length)).unwrap() } /// Returns the clamped non-negative values. + /// + /// TODO(emilio): It's a bit unfortunate that this depends on whether the + /// value was a `calc()` value or not. Should it? #[inline] pub fn clamp_to_non_negative(self) -> Self { - match self { - LengthOrPercentage::Length(length) => { - LengthOrPercentage::Length(length.clamp_to_non_negative()) - }, - LengthOrPercentage::Percentage(percentage) => { - LengthOrPercentage::Percentage(percentage.clamp_to_non_negative()) - }, - _ => self, + if self.was_calc { + return Self::with_clamping_mode( + self.length, + self.percentage, + AllowedNumericType::NonNegative, + self.was_calc, + ); } - } -} -impl ToComputedValue for specified::LengthOrPercentage { - type ComputedValue = LengthOrPercentage; - - fn to_computed_value(&self, context: &Context) -> LengthOrPercentage { - match *self { - specified::LengthOrPercentage::Length(ref value) => { - LengthOrPercentage::Length(value.to_computed_value(context)) - }, - specified::LengthOrPercentage::Percentage(value) => { - LengthOrPercentage::Percentage(value) - }, - specified::LengthOrPercentage::Calc(ref calc) => { - LengthOrPercentage::Calc((**calc).to_computed_value(context)) - }, + debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); + if let Some(p) = self.percentage { + return Self::with_clamping_mode( + Length::zero(), + Some(p.clamp_to_non_negative()), + AllowedNumericType::NonNegative, + self.was_calc, + ); } - } - fn from_computed_value(computed: &LengthOrPercentage) -> Self { - match *computed { - LengthOrPercentage::Length(value) => { - specified::LengthOrPercentage::Length(ToComputedValue::from_computed_value(&value)) - }, - LengthOrPercentage::Percentage(value) => { - specified::LengthOrPercentage::Percentage(value) - }, - LengthOrPercentage::Calc(ref calc) => specified::LengthOrPercentage::Calc(Box::new( - ToComputedValue::from_computed_value(calc), - )), - } - } -} - -impl IsZeroLength for LengthOrPercentage { - #[inline] - fn is_zero_length(&self) -> bool { - match *self { - LengthOrPercentage::Length(l) => l.0 == 0.0, - LengthOrPercentage::Percentage(p) => p.0 == 0.0, - LengthOrPercentage::Calc(c) => c.unclamped_length().0 == 0.0 && c.percentage() == 0.0, - } - } -} - -#[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] -#[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToCss)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] -pub enum LengthOrPercentageOrAuto { - Length(Length), - Percentage(Percentage), - Auto, - Calc(CalcLengthOrPercentage), -} - -impl LengthOrPercentageOrAuto { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - let this = >::from(*self); - let other = >::from(*other); - Ok(LengthOrPercentageOrAuto::Calc( - this.animate(&other, procedure)?.ok_or(())?, - )) - } - - #[inline] - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - >::compute_squared_distance( - &(*self).into(), - &(*other).into(), + Self::with_clamping_mode( + self.length.clamp_to_non_negative(), + None, + AllowedNumericType::NonNegative, + self.was_calc, ) } } -/// A wrapper of LengthOrPercentageOrAuto, whose value must be >= 0. -pub type NonNegativeLengthOrPercentageOrAuto = NonNegative; +impl ToComputedValue for specified::LengthPercentage { + type ComputedValue = LengthPercentage; -impl IsAuto for NonNegativeLengthOrPercentageOrAuto { + fn to_computed_value(&self, context: &Context) -> LengthPercentage { + match *self { + specified::LengthPercentage::Length(ref value) => { + LengthPercentage::new(value.to_computed_value(context), None) + }, + specified::LengthPercentage::Percentage(value) => LengthPercentage::new_percent(value), + specified::LengthPercentage::Calc(ref calc) => (**calc).to_computed_value(context), + } + } + + fn from_computed_value(computed: &LengthPercentage) -> Self { + let length = computed.unclamped_length(); + if let Some(p) = computed.as_percentage() { + return specified::LengthPercentage::Percentage(p); + } + + let percentage = computed.percentage; + if percentage.is_none() && computed.clamping_mode.clamp(length.px()) == length.px() { + return specified::LengthPercentage::Length(ToComputedValue::from_computed_value( + &length, + )); + } + + specified::LengthPercentage::Calc(Box::new(ToComputedValue::from_computed_value(computed))) + } +} + +impl IsZeroLength for LengthPercentage { + #[inline] + fn is_zero_length(&self) -> bool { + self.is_definitely_zero() + } +} + +#[allow(missing_docs)] +#[css(derive_debug)] +#[derive( + Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, +)] +pub enum LengthPercentageOrAuto { + LengthPercentage(LengthPercentage), + Auto, +} + +impl LengthPercentageOrAuto { + /// Returns the `0` value. + #[inline] + pub fn zero() -> Self { + LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero()) + } +} + +/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. +pub type NonNegativeLengthPercentageOrAuto = NonNegative; + +impl IsAuto for NonNegativeLengthPercentageOrAuto { #[inline] fn is_auto(&self) -> bool { *self == Self::auto() } } -impl NonNegativeLengthOrPercentageOrAuto { +impl NonNegativeLengthPercentageOrAuto { /// `auto` #[inline] pub fn auto() -> Self { - NonNegative(LengthOrPercentageOrAuto::Auto) + NonNegative(LengthPercentageOrAuto::Auto) } } -impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto { - type AnimatedValue = LengthOrPercentageOrAuto; +impl ToAnimatedValue for NonNegativeLengthPercentageOrAuto { + type AnimatedValue = LengthPercentageOrAuto; #[inline] fn to_animated_value(self) -> Self::AnimatedValue { @@ -570,190 +488,154 @@ impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto { } } -impl LengthOrPercentageOrAuto { +impl LengthPercentageOrAuto { /// Returns true if the computed value is absolute 0 or 0%. - /// - /// (Returns false for calc() values, even if ones that may resolve to zero.) #[inline] pub fn is_definitely_zero(&self) -> bool { - use self::LengthOrPercentageOrAuto::*; + use self::LengthPercentageOrAuto::*; match *self { - Length(l) => l.px() == 0.0, - Percentage(p) => p.0 == 0.0, - Calc(_) | Auto => false, + LengthPercentage(ref l) => l.is_definitely_zero(), + Auto => false, } } - fn clamp_to_non_negative(self) -> Self { - use self::LengthOrPercentageOrAuto::*; + /// Clamps the value to a non-negative value. + pub fn clamp_to_non_negative(self) -> Self { + use self::LengthPercentageOrAuto::*; match self { - Length(l) => Length(l.clamp_to_non_negative()), - Percentage(p) => Percentage(p.clamp_to_non_negative()), - _ => self, + LengthPercentage(l) => LengthPercentage(l.clamp_to_non_negative()), + Auto => Auto, } } } -impl ToComputedValue for specified::LengthOrPercentageOrAuto { - type ComputedValue = LengthOrPercentageOrAuto; +impl ToComputedValue for specified::LengthPercentageOrAuto { + type ComputedValue = LengthPercentageOrAuto; #[inline] - fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrAuto { + fn to_computed_value(&self, context: &Context) -> LengthPercentageOrAuto { match *self { - specified::LengthOrPercentageOrAuto::Length(ref value) => { - LengthOrPercentageOrAuto::Length(value.to_computed_value(context)) - }, - specified::LengthOrPercentageOrAuto::Percentage(value) => { - LengthOrPercentageOrAuto::Percentage(value) - }, - specified::LengthOrPercentageOrAuto::Auto => LengthOrPercentageOrAuto::Auto, - specified::LengthOrPercentageOrAuto::Calc(ref calc) => { - LengthOrPercentageOrAuto::Calc((**calc).to_computed_value(context)) + specified::LengthPercentageOrAuto::LengthPercentage(ref value) => { + LengthPercentageOrAuto::LengthPercentage(value.to_computed_value(context)) }, + specified::LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto, } } #[inline] - fn from_computed_value(computed: &LengthOrPercentageOrAuto) -> Self { + fn from_computed_value(computed: &LengthPercentageOrAuto) -> Self { match *computed { - LengthOrPercentageOrAuto::Auto => specified::LengthOrPercentageOrAuto::Auto, - LengthOrPercentageOrAuto::Length(value) => specified::LengthOrPercentageOrAuto::Length( - ToComputedValue::from_computed_value(&value), - ), - LengthOrPercentageOrAuto::Percentage(value) => { - specified::LengthOrPercentageOrAuto::Percentage(value) + LengthPercentageOrAuto::Auto => specified::LengthPercentageOrAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(ref value) => { + specified::LengthPercentageOrAuto::LengthPercentage( + ToComputedValue::from_computed_value(value), + ) }, - LengthOrPercentageOrAuto::Calc(calc) => specified::LengthOrPercentageOrAuto::Calc( - Box::new(ToComputedValue::from_computed_value(&calc)), - ), } } } #[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, PartialEq, ToCss)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] -pub enum LengthOrPercentageOrNone { - Length(Length), - Percentage(Percentage), - Calc(CalcLengthOrPercentage), +#[derive( + Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss, +)] +pub enum LengthPercentageOrNone { + LengthPercentage(LengthPercentage), None, } -impl LengthOrPercentageOrNone { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - let this = >::from(*self); - let other = >::from(*other); - Ok(LengthOrPercentageOrNone::Calc( - this.animate(&other, procedure)?.ok_or(())?, - )) - } - - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - >::compute_squared_distance( - &(*self).into(), - &(*other).into(), - ) - } -} - -impl LengthOrPercentageOrNone { +impl LengthPercentageOrNone { /// Returns the used value. pub fn to_used_value(&self, containing_length: Au) -> Option { match *self { - LengthOrPercentageOrNone::None => None, - LengthOrPercentageOrNone::Length(length) => Some(Au::from(length)), - LengthOrPercentageOrNone::Percentage(percent) => { - Some(containing_length.scale_by(percent.0)) + LengthPercentageOrNone::None => None, + LengthPercentageOrNone::LengthPercentage(ref lp) => { + Some(lp.to_used_value(containing_length)) }, - LengthOrPercentageOrNone::Calc(ref calc) => calc.to_used_value(Some(containing_length)), } } } -impl ToComputedValue for specified::LengthOrPercentageOrNone { - type ComputedValue = LengthOrPercentageOrNone; +// FIXME(emilio): Derive this. +impl ToComputedValue for specified::LengthPercentageOrNone { + type ComputedValue = LengthPercentageOrNone; #[inline] - fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrNone { + fn to_computed_value(&self, context: &Context) -> LengthPercentageOrNone { match *self { - specified::LengthOrPercentageOrNone::Length(ref value) => { - LengthOrPercentageOrNone::Length(value.to_computed_value(context)) + specified::LengthPercentageOrNone::LengthPercentage(ref value) => { + LengthPercentageOrNone::LengthPercentage(value.to_computed_value(context)) }, - specified::LengthOrPercentageOrNone::Percentage(value) => { - LengthOrPercentageOrNone::Percentage(value) - }, - specified::LengthOrPercentageOrNone::Calc(ref calc) => { - LengthOrPercentageOrNone::Calc((**calc).to_computed_value(context)) - }, - specified::LengthOrPercentageOrNone::None => LengthOrPercentageOrNone::None, + specified::LengthPercentageOrNone::None => LengthPercentageOrNone::None, } } #[inline] - fn from_computed_value(computed: &LengthOrPercentageOrNone) -> Self { + fn from_computed_value(computed: &LengthPercentageOrNone) -> Self { match *computed { - LengthOrPercentageOrNone::None => specified::LengthOrPercentageOrNone::None, - LengthOrPercentageOrNone::Length(value) => specified::LengthOrPercentageOrNone::Length( - ToComputedValue::from_computed_value(&value), - ), - LengthOrPercentageOrNone::Percentage(value) => { - specified::LengthOrPercentageOrNone::Percentage(value) + LengthPercentageOrNone::None => specified::LengthPercentageOrNone::None, + LengthPercentageOrNone::LengthPercentage(value) => { + specified::LengthPercentageOrNone::LengthPercentage( + ToComputedValue::from_computed_value(&value), + ) }, - LengthOrPercentageOrNone::Calc(calc) => specified::LengthOrPercentageOrNone::Calc( - Box::new(ToComputedValue::from_computed_value(&calc)), - ), } } } -/// A wrapper of LengthOrPercentage, whose value must be >= 0. -pub type NonNegativeLengthOrPercentage = NonNegative; +/// A wrapper of LengthPercentage, whose value must be >= 0. +pub type NonNegativeLengthPercentage = NonNegative; -impl ToAnimatedValue for NonNegativeLengthOrPercentage { - type AnimatedValue = LengthOrPercentage; +impl ToAnimatedValue for NonNegativeLengthPercentage { + type AnimatedValue = LengthPercentage; #[inline] fn to_animated_value(self) -> Self::AnimatedValue { - self.into() + self.0 } #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated.clamp_to_non_negative().into() + NonNegative(animated.clamp_to_non_negative()) } } -impl From for NonNegativeLengthOrPercentage { +impl From for NonNegativeLengthPercentage { #[inline] fn from(length: NonNegativeLength) -> Self { - LengthOrPercentage::Length(length.0).into() + LengthPercentage::new(length.0, None).into() } } -impl From for NonNegativeLengthOrPercentage { +impl From for NonNegativeLengthPercentage { #[inline] - fn from(lop: LengthOrPercentage) -> Self { - NonNegative::(lop) + fn from(lp: LengthPercentage) -> Self { + NonNegative::(lp) } } -impl From for LengthOrPercentage { +impl From for LengthPercentage { #[inline] - fn from(lop: NonNegativeLengthOrPercentage) -> LengthOrPercentage { - lop.0 + fn from(lp: NonNegativeLengthPercentage) -> LengthPercentage { + lp.0 } } -impl NonNegativeLengthOrPercentage { +// TODO(emilio): This is a really generic impl which is only needed to implement +// Animated and co for Spacing<>. Get rid of this, probably? +impl From for LengthPercentage { + #[inline] + fn from(length: Au) -> Self { + LengthPercentage::new(length.into(), None) + } +} + +impl NonNegativeLengthPercentage { /// Get zero value. #[inline] pub fn zero() -> Self { - NonNegative::(LengthOrPercentage::zero()) + NonNegative::(LengthPercentage::zero()) } /// Returns true if the computed value is absolute 0 or 0%. @@ -798,11 +680,6 @@ impl CSSPixelLength { self.0 } - #[inline] - fn clamp_to_non_negative(self) -> Self { - Self::new(self.px().max(0.)) - } - /// Return the length with app_unit i32 type. #[inline] pub fn to_i32_au(&self) -> i32 { @@ -810,11 +687,19 @@ impl CSSPixelLength { } /// Return the absolute value of this length. + #[inline] pub fn abs(self) -> Self { CSSPixelLength::new(self.0.abs()) } + /// Return the clamped value of this length. + #[inline] + pub fn clamp_to_non_negative(self) -> Self { + CSSPixelLength::new(self.0.max(0.)) + } + /// Zero value + #[inline] pub fn zero() -> Self { CSSPixelLength::new(0.) } @@ -963,8 +848,8 @@ pub type NonNegativeLengthOrAuto = Either; /// Either a computed NonNegativeLength or the `normal` keyword. pub type NonNegativeLengthOrNormal = Either; -/// Either a computed NonNegativeLengthOrPercentage or the `normal` keyword. -pub type NonNegativeLengthOrPercentageOrNormal = Either; +/// Either a computed NonNegativeLengthPercentage or the `normal` keyword. +pub type NonNegativeLengthPercentageOrNormal = Either; /// A type for possible values for min- and max- flavors of width, height, /// block-size, and inline-size. @@ -994,23 +879,23 @@ pub enum ExtremumLength { } /// A computed value for `min-width`, `min-height`, `width` or `height` property. -pub type MozLength = GenericMozLength; +pub type MozLength = GenericMozLength; impl MozLength { /// Returns the `auto` value. #[inline] pub fn auto() -> Self { - GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) + GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::Auto) } } /// A computed value for `max-width` or `min-height` property. -pub type MaxLength = GenericMaxLength; +pub type MaxLength = GenericMaxLength; impl MaxLength { /// Returns the `none` value. #[inline] pub fn none() -> Self { - GenericMaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None) + GenericMaxLength::LengthPercentageOrNone(LengthPercentageOrNone::None) } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 4051511e28e..c389e1d1267 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -62,9 +62,9 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, pub use self::gecko::ScrollSnapPoint; pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; -pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage}; -pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; -pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto}; +pub use self::length::{Length, LengthOrNumber, LengthPercentage}; +pub use self::length::{LengthPercentageOrAuto, LengthPercentageOrNone, MaxLength, MozLength}; +pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::list::{QuotePair, Quotes}; @@ -689,20 +689,20 @@ impl ToCss for ClipRect { pub type ClipRectOrAuto = Either; /// The computed value of a grid `` -pub type TrackBreadth = GenericTrackBreadth; +pub type TrackBreadth = GenericTrackBreadth; /// The computed value of a grid `` -pub type TrackSize = GenericTrackSize; +pub type TrackSize = GenericTrackSize; /// The computed value of a grid `` /// (could also be `` or ``) -pub type TrackList = GenericTrackList; +pub type TrackList = GenericTrackList; /// The computed value of a ``. pub type GridLine = GenericGridLine; /// ` | ` -pub type GridTemplateComponent = GenericGridTemplateComponent; +pub type GridTemplateComponent = GenericGridTemplateComponent; impl ClipRectOrAuto { /// Return an auto (default for clip-rect and image-region) value diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index 8c7976886d8..d6f9161903b 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -7,7 +7,7 @@ //! //! [position]: https://drafts.csswg.org/css-backgrounds-3/#position -use crate::values::computed::{Integer, LengthOrPercentage, Percentage}; +use crate::values::computed::{Integer, LengthPercentage, Percentage}; use crate::values::generics::position::Position as GenericPosition; use crate::values::generics::position::ZIndex as GenericZIndex; pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas}; @@ -18,25 +18,25 @@ use style_traits::{CssWriter, ToCss}; pub type Position = GenericPosition; /// The computed value of a CSS horizontal position. -pub type HorizontalPosition = LengthOrPercentage; +pub type HorizontalPosition = LengthPercentage; /// The computed value of a CSS vertical position. -pub type VerticalPosition = LengthOrPercentage; +pub type VerticalPosition = LengthPercentage; impl Position { /// `50% 50%` #[inline] pub fn center() -> Self { Self::new( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), ) } /// `0% 0%` #[inline] pub fn zero() -> Self { - Self::new(LengthOrPercentage::zero(), LengthOrPercentage::zero()) + Self::new(LengthPercentage::zero(), LengthPercentage::zero()) } } diff --git a/components/style/values/computed/svg.rs b/components/style/values/computed/svg.rs index 02583189e4f..f3ca86aa5b0 100644 --- a/components/style/values/computed/svg.rs +++ b/components/style/values/computed/svg.rs @@ -6,7 +6,7 @@ use crate::values::computed::color::Color; use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::computed::{LengthPercentage, NonNegativeLengthPercentage}; use crate::values::computed::{NonNegativeNumber, Number, Opacity}; use crate::values::generics::svg as generic; use crate::values::RGBA; @@ -42,56 +42,56 @@ impl SVGPaint { /// A value of | | for stroke-dashoffset. /// -pub type SvgLengthOrPercentageOrNumber = - generic::SvgLengthOrPercentageOrNumber; +pub type SvgLengthPercentageOrNumber = + generic::SvgLengthPercentageOrNumber; /// | | | context-value -pub type SVGLength = generic::SVGLength; +pub type SVGLength = generic::SVGLength; impl SVGLength { /// `0px` pub fn zero() -> Self { - generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::zero(), + generic::SVGLength::Length(generic::SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::zero(), )) } } /// A value of | | for stroke-width/stroke-dasharray. /// -pub type NonNegativeSvgLengthOrPercentageOrNumber = - generic::SvgLengthOrPercentageOrNumber; +pub type NonNegativeSvgLengthPercentageOrNumber = + generic::SvgLengthPercentageOrNumber; // FIXME(emilio): This is really hacky, and can go away with a bit of work on // the clone_stroke_width code in gecko.mako.rs. -impl Into for SvgLengthOrPercentageOrNumber { - fn into(self) -> NonNegativeSvgLengthOrPercentageOrNumber { +impl Into for SvgLengthPercentageOrNumber { + fn into(self) -> NonNegativeSvgLengthPercentageOrNumber { match self { - generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => { - generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop.into()) + generic::SvgLengthPercentageOrNumber::LengthPercentage(lop) => { + generic::SvgLengthPercentageOrNumber::LengthPercentage(lop.into()) }, - generic::SvgLengthOrPercentageOrNumber::Number(num) => { - generic::SvgLengthOrPercentageOrNumber::Number(num.into()) + generic::SvgLengthPercentageOrNumber::Number(num) => { + generic::SvgLengthPercentageOrNumber::Number(num.into()) }, } } } /// An non-negative wrapper of SVGLength. -pub type SVGWidth = generic::SVGLength; +pub type SVGWidth = generic::SVGLength; impl SVGWidth { /// `1px`. pub fn one() -> Self { use crate::values::generics::NonNegative; - generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( - NonNegative(LengthOrPercentage::one()), + generic::SVGLength::Length(generic::SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::one()), )) } } /// [ | | ]# | context-value -pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; +pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; impl Default for SVGStrokeDashArray { fn default() -> Self { diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index ce5545308b0..030a6df6cff 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -6,7 +6,7 @@ #[cfg(feature = "servo")] use crate::properties::StyleBuilder; -use crate::values::computed::length::{Length, LengthOrPercentage}; +use crate::values::computed::length::{Length, LengthPercentage}; use crate::values::computed::{NonNegativeLength, NonNegativeNumber}; use crate::values::generics::text::InitialLetter as GenericInitialLetter; use crate::values::generics::text::LineHeight as GenericLineHeight; @@ -29,7 +29,7 @@ pub type InitialLetter = GenericInitialLetter; pub type LetterSpacing = Spacing; /// A computed value for the `word-spacing` property. -pub type WordSpacing = Spacing; +pub type WordSpacing = Spacing; /// A computed value for the `line-height` property. pub type LineHeight = GenericLineHeight; diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index e3493131544..979886aa996 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -7,7 +7,7 @@ use super::CSSFloat; use crate::values::animated::transform::{Perspective, Scale3D, Translate3D}; use crate::values::animated::ToAnimatedZero; -use crate::values::computed::{Angle, Integer, Length, LengthOrPercentage, Number, Percentage}; +use crate::values::computed::{Angle, Integer, Length, LengthPercentage, Number, Percentage}; use crate::values::generics::transform as generic; use euclid::{Transform3D, Vector3D}; use num_traits::Zero; @@ -16,12 +16,12 @@ pub use crate::values::generics::transform::TransformStyle; /// A single operation in a computed CSS `transform` pub type TransformOperation = - generic::TransformOperation; + generic::TransformOperation; /// A computed CSS `transform` pub type Transform = generic::Transform; /// The computed value of a CSS `` -pub type TransformOrigin = generic::TransformOrigin; +pub type TransformOrigin = generic::TransformOrigin; /// A vector to represent the direction vector (rotate axis) for Rotate3D. pub type DirectionVector = Vector3D; @@ -31,8 +31,8 @@ impl TransformOrigin { #[inline] pub fn initial_value() -> Self { Self::new( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), Length::new(0.), ) } @@ -374,7 +374,7 @@ impl TransformOperation { generic::TransformOperation::Translate(ref x, None) => { generic::TransformOperation::Translate3D( x.clone(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), Length::zero(), ) }, @@ -383,15 +383,15 @@ impl TransformOperation { }, generic::TransformOperation::TranslateY(ref y) => { generic::TransformOperation::Translate3D( - LengthOrPercentage::zero(), + LengthPercentage::zero(), y.clone(), Length::zero(), ) }, generic::TransformOperation::TranslateZ(ref z) => { generic::TransformOperation::Translate3D( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), z.clone(), ) }, @@ -576,7 +576,7 @@ impl Rotate { } /// A computed CSS `translate` -pub type Translate = generic::Translate; +pub type Translate = generic::Translate; impl Translate { /// Convert TransformOperation to Translate. diff --git a/components/style/values/generics/background.rs b/components/style/values/generics/background.rs index 68bd08b29dd..4a7ee4b9b95 100644 --- a/components/style/values/generics/background.rs +++ b/components/style/values/generics/background.rs @@ -22,13 +22,13 @@ use style_traits::{CssWriter, ToCss}; ToAnimatedZero, ToComputedValue, )] -pub enum BackgroundSize { +pub enum BackgroundSize { /// ` ` Explicit { /// Explicit width. - width: LengthOrPercentageOrAuto, + width: LengthPercentageOrAuto, /// Explicit height. - height: LengthOrPercentageOrAuto, + height: LengthPercentageOrAuto, }, /// `cover` #[animation(error)] @@ -38,9 +38,9 @@ pub enum BackgroundSize { Contain, } -impl ToCss for BackgroundSize +impl ToCss for BackgroundSize where - LengthOrPercentageOrAuto: ToCss + IsAuto, + LengthPercentageOrAuto: ToCss + IsAuto, { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index bfe709ceb4b..f224f936ccb 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -104,11 +104,11 @@ pub enum ShapeSource { ToComputedValue, ToCss, )] -pub enum BasicShape { - Inset(#[css(field_bound)] InsetRect), - Circle(#[css(field_bound)] Circle), - Ellipse(#[css(field_bound)] Ellipse), - Polygon(Polygon), +pub enum BasicShape { + Inset(#[css(field_bound)] InsetRect), + Circle(#[css(field_bound)] Circle), + Ellipse(#[css(field_bound)] Ellipse), + Polygon(Polygon), } /// @@ -125,9 +125,9 @@ pub enum BasicShape { ToAnimatedValue, ToComputedValue, )] -pub struct InsetRect { - pub rect: Rect, - pub round: Option>, +pub struct InsetRect { + pub rect: Rect, + pub round: Option>, } /// @@ -145,9 +145,9 @@ pub struct InsetRect { ToAnimatedValue, ToComputedValue, )] -pub struct Circle { +pub struct Circle { pub position: Position, - pub radius: ShapeRadius, + pub radius: ShapeRadius, } /// @@ -165,10 +165,10 @@ pub struct Circle { ToAnimatedValue, ToComputedValue, )] -pub struct Ellipse { +pub struct Ellipse { pub position: Position, - pub semiaxis_x: ShapeRadius, - pub semiaxis_y: ShapeRadius, + pub semiaxis_x: ShapeRadius, + pub semiaxis_y: ShapeRadius, } /// @@ -186,8 +186,8 @@ pub struct Ellipse { ToComputedValue, ToCss, )] -pub enum ShapeRadius { - Length(NonNegativeLengthOrPercentage), +pub enum ShapeRadius { + Length(NonNegativeLengthPercentage), #[animation(error)] ClosestSide, #[animation(error)] @@ -208,13 +208,13 @@ pub enum ShapeRadius { ToComputedValue, ToCss, )] -pub struct Polygon { +pub struct Polygon { /// The filling rule for a polygon. #[css(skip_if = "fill_is_default")] pub fill: FillRule, /// A collection of (x, y) coordinates to draw the polygon. #[css(iterable)] - pub coordinates: Vec>, + pub coordinates: Vec>, } /// Coordinates for Polygon. @@ -228,7 +228,7 @@ pub struct Polygon { ToComputedValue, ToCss, )] -pub struct PolygonCoord(pub LengthOrPercentage, pub LengthOrPercentage); +pub struct PolygonCoord(pub LengthPercentage, pub LengthPercentage); // https://drafts.csswg.org/css-shapes/#typedef-fill-rule // NOTE: Basic shapes spec says that these are the only two values, however diff --git a/components/style/values/generics/border.rs b/components/style/values/generics/border.rs index 20274816615..0a1cef3b4bb 100644 --- a/components/style/values/generics/border.rs +++ b/components/style/values/generics/border.rs @@ -13,9 +13,9 @@ use style_traits::{CssWriter, ToCss}; #[derive( Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, )] -pub enum BorderImageSideWidth { +pub enum BorderImageSideWidth { /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), /// `` Number(Number), /// `auto` @@ -98,15 +98,15 @@ impl BorderSpacing { ToAnimatedValue, ToComputedValue, )] -pub struct BorderRadius { +pub struct BorderRadius { /// The top left radius. - pub top_left: BorderCornerRadius, + pub top_left: BorderCornerRadius, /// The top right radius. - pub top_right: BorderCornerRadius, + pub top_right: BorderCornerRadius, /// The bottom right radius. - pub bottom_right: BorderCornerRadius, + pub bottom_right: BorderCornerRadius, /// The bottom left radius. - pub bottom_left: BorderCornerRadius, + pub bottom_left: BorderCornerRadius, } impl BorderRadius { diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs index 1c40702dd6c..8a8dc58fd92 100644 --- a/components/style/values/generics/box.rs +++ b/components/style/values/generics/box.rs @@ -19,7 +19,7 @@ use crate::values::animated::ToAnimatedZero; ToComputedValue, ToCss, )] -pub enum VerticalAlign { +pub enum VerticalAlign { /// `baseline` Baseline, /// `sub` @@ -40,7 +40,7 @@ pub enum VerticalAlign { #[cfg(feature = "gecko")] MozMiddleWithBaseline, /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), } impl VerticalAlign { diff --git a/components/style/values/generics/gecko.rs b/components/style/values/generics/gecko.rs index e8bddc871f9..fb84fdf4acc 100644 --- a/components/style/values/generics/gecko.rs +++ b/components/style/values/generics/gecko.rs @@ -8,12 +8,12 @@ /// A generic value for scroll snap points. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] -pub enum ScrollSnapPoint { +pub enum ScrollSnapPoint { /// `none` None, /// `repeat()` #[css(function)] - Repeat(LengthOrPercentage), + Repeat(LengthPercentage), } impl ScrollSnapPoint { diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index 9944ef6a212..3e978e9c449 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -190,7 +190,7 @@ impl TrackBreadth { #[inline] pub fn is_fixed(&self) -> bool { match *self { - TrackBreadth::Breadth(ref _lop) => true, + TrackBreadth::Breadth(ref _lp) => true, _ => false, } } @@ -278,9 +278,9 @@ impl ToCss for TrackSize { max.to_css(dest)?; dest.write_str(")") }, - TrackSize::FitContent(ref lop) => { + TrackSize::FitContent(ref lp) => { dest.write_str("fit-content(")?; - lop.to_css(dest)?; + lp.to_css(dest)?; dest.write_str(")") }, } @@ -308,7 +308,7 @@ impl ToComputedValue for TrackSize { TrackSize::Minmax(ref b1, ref b2) => { TrackSize::Minmax(b1.to_computed_value(context), b2.to_computed_value(context)) }, - TrackSize::FitContent(ref lop) => TrackSize::FitContent(lop.to_computed_value(context)), + TrackSize::FitContent(ref lp) => TrackSize::FitContent(lp.to_computed_value(context)), } } @@ -322,8 +322,8 @@ impl ToComputedValue for TrackSize { ToComputedValue::from_computed_value(b1), ToComputedValue::from_computed_value(b2), ), - TrackSize::FitContent(ref lop) => { - TrackSize::FitContent(ToComputedValue::from_computed_value(lop)) + TrackSize::FitContent(ref lp) => { + TrackSize::FitContent(ToComputedValue::from_computed_value(lp)) }, } } @@ -482,11 +482,11 @@ impl TrackRepeat { /// Track list values. Can be or #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] -pub enum TrackListValue { +pub enum TrackListValue { /// A value. - TrackSize(TrackSize), + TrackSize(TrackSize), /// A value. - TrackRepeat(TrackRepeat), + TrackRepeat(TrackRepeat), } /// The type of a `` as determined during parsing. @@ -515,7 +515,7 @@ pub enum TrackListType { /// /// #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)] -pub struct TrackList { +pub struct TrackList { /// The type of this `` (auto, explicit or general). /// /// In order to avoid parsing the same value multiple times, this does a single traversal @@ -523,7 +523,7 @@ pub struct TrackList { #[css(skip)] pub list_type: TrackListType, /// A vector of ` | ` values. - pub values: Vec>, + pub values: Vec>, /// `` accompanying ` | ` values. /// /// If there's no ``, then it's represented by an empty vector. @@ -531,7 +531,7 @@ pub struct TrackList { /// length is always one value more than that of the ``. pub line_names: Box<[Box<[CustomIdent]>]>, /// `` value. There can only be one `` in a TrackList. - pub auto_repeat: Option>, + pub auto_repeat: Option>, } impl ToCss for TrackList { diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index a4bbc2b44d2..44ff903b4f4 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -37,11 +37,11 @@ pub enum Image { /// A CSS gradient. /// #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)] -pub struct Gradient { +pub struct Gradient { /// Gradients can be linear or radial. - pub kind: GradientKind, + pub kind: GradientKind, /// The color stops and interpolation hints. - pub items: Vec>, + pub items: Vec>, /// True if this is a repeating gradient. pub repeating: bool, /// Compatibility mode. @@ -61,12 +61,12 @@ pub enum CompatMode { /// A gradient kind. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)] -pub enum GradientKind { +pub enum GradientKind { /// A linear gradient. Linear(LineDirection), /// A radial gradient. Radial( - EndingShape, + EndingShape, Position, Option, ), @@ -74,11 +74,11 @@ pub enum GradientKind { +pub enum EndingShape { /// A circular gradient. Circle(Circle), /// An elliptic gradient. - Ellipse(Ellipse), + Ellipse(Ellipse), } /// A circle shape. @@ -92,9 +92,9 @@ pub enum Circle { /// An ellipse shape. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub enum Ellipse { +pub enum Ellipse { /// An ellipse pair of radii. - Radii(LengthOrPercentage, LengthOrPercentage), + Radii(LengthPercentage, LengthPercentage), /// An ellipse extent. Extent(ShapeExtent), } @@ -115,21 +115,21 @@ pub enum ShapeExtent { /// A gradient item. /// #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub enum GradientItem { +pub enum GradientItem { /// A color stop. - ColorStop(ColorStop), + ColorStop(ColorStop), /// An interpolation hint. - InterpolationHint(LengthOrPercentage), + InterpolationHint(LengthPercentage), } /// A color stop. /// #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub struct ColorStop { +pub struct ColorStop { /// The color of this stop. pub color: Color, /// The position of this stop. - pub position: Option, + pub position: Option, } /// Specified values for a paint worklet. diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index ade1e4bb3a9..006739462aa 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -26,8 +26,8 @@ use crate::values::computed::ExtremumLength; ToComputedValue, ToCss, )] -pub enum MozLength { - LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), +pub enum MozLength { + LengthPercentageOrAuto(LengthPercentageOrAuto), #[animation(error)] ExtremumLength(ExtremumLength), } @@ -47,8 +47,8 @@ pub enum MozLength { ToComputedValue, ToCss, )] -pub enum MaxLength { - LengthOrPercentageOrNone(LengthOrPercentageOrNone), +pub enum MaxLength { + LengthPercentageOrNone(LengthPercentageOrNone), #[animation(error)] ExtremumLength(ExtremumLength), } diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 0559f8f1514..914de88999c 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -142,28 +142,28 @@ impl Parse for SVGPaint { +pub enum SvgLengthPercentageOrNumber { /// | - LengthOrPercentage(LengthOrPercentage), + LengthPercentage(LengthPercentage), /// Number(Number), } -/// Parsing the SvgLengthOrPercentageOrNumber. At first, we need to parse number +/// Parsing the SvgLengthPercentageOrNumber. At first, we need to parse number /// since prevent converting to the length. -impl Parse - for SvgLengthOrPercentageOrNumber +impl Parse + for SvgLengthPercentageOrNumber { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(num) = input.try(|i| NumberType::parse(context, i)) { - return Ok(SvgLengthOrPercentageOrNumber::Number(num)); + return Ok(SvgLengthPercentageOrNumber::Number(num)); } - let lop = LengthOrPercentageType::parse(context, input)?; - Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop)) + let lp = LengthPercentageType::parse(context, input)?; + Ok(SvgLengthPercentageOrNumber::LengthPercentage(lp)) } } diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 090c3c1f687..5a4f9213908 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -103,10 +103,7 @@ where } } -impl ToAnimatedZero for Spacing -where - V: From, -{ +impl ToAnimatedZero for Spacing { #[inline] fn to_animated_zero(&self) -> Result { Err(()) @@ -126,7 +123,7 @@ where ToAnimatedValue, ToCss, )] -pub enum LineHeight { +pub enum LineHeight { /// `normal` Normal, /// `-moz-block-height` @@ -135,7 +132,7 @@ pub enum LineHeight { /// `` Number(Number), /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), } impl ToAnimatedZero for LineHeight { diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 158b7456c76..4591f3addd2 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -5,10 +5,10 @@ //! Generic types for CSS values that are related to transformations. use crate::values::computed::length::Length as ComputedLength; -use crate::values::computed::length::LengthOrPercentage as ComputedLengthOrPercentage; +use crate::values::computed::length::LengthPercentage as ComputedLengthPercentage; use crate::values::specified::angle::Angle as SpecifiedAngle; use crate::values::specified::length::Length as SpecifiedLength; -use crate::values::specified::length::LengthOrPercentage as SpecifiedLengthOrPercentage; +use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage; use crate::values::{computed, CSSFloat}; use app_units::Au; use euclid::{self, Rect, Transform3D}; @@ -105,7 +105,7 @@ impl TransformOrigin { #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] /// A single operation in the list of a `transform` value -pub enum TransformOperation { +pub enum TransformOperation { /// Represents a 2D 2x3 matrix. Matrix(Matrix), /// Represents a 3D 4x4 matrix. @@ -125,19 +125,19 @@ pub enum TransformOperation SkewY(Angle), /// translate(x, y) or translate(x) #[css(comma, function)] - Translate(LengthOrPercentage, Option), + Translate(LengthPercentage, Option), /// translateX(x) #[css(function = "translateX")] - TranslateX(LengthOrPercentage), + TranslateX(LengthPercentage), /// translateY(y) #[css(function = "translateY")] - TranslateY(LengthOrPercentage), + TranslateY(LengthPercentage), /// translateZ(z) #[css(function = "translateZ")] TranslateZ(Length), /// translate3d(x, y, z) #[css(comma, function = "translate3d")] - Translate3D(LengthOrPercentage, LengthOrPercentage, Length), + Translate3D(LengthPercentage, LengthPercentage, Length), /// A 2D scaling factor. /// /// `scale(2)` is parsed as `Scale(Number::new(2.0), None)` and is equivalent to @@ -191,18 +191,16 @@ pub enum TransformOperation #[allow(missing_docs)] #[css(comma, function = "interpolatematrix")] InterpolateMatrix { - from_list: - Transform>, - to_list: Transform>, + from_list: Transform>, + to_list: Transform>, progress: computed::Percentage, }, /// A intermediate type for accumulation of mismatched transform lists. #[allow(missing_docs)] #[css(comma, function = "accumulatematrix")] AccumulateMatrix { - from_list: - Transform>, - to_list: Transform>, + from_list: Transform>, + to_list: Transform>, count: Integer, }, } @@ -211,8 +209,8 @@ pub enum TransformOperation /// A value of the `transform` property pub struct Transform(#[css(if_empty = "none", iterable)] pub Vec); -impl - TransformOperation +impl + TransformOperation { /// Check if it is any rotate function. pub fn is_rotate(&self) -> bool { @@ -263,13 +261,13 @@ impl ToAbsoluteLength for SpecifiedLength { } } -impl ToAbsoluteLength for SpecifiedLengthOrPercentage { +impl ToAbsoluteLength for SpecifiedLengthPercentage { // This returns Err(()) if there is any relative length or percentage. We use this when // parsing a transform list of DOMMatrix because we want to return a DOM Exception // if there is relative length. #[inline] fn to_pixel_length(&self, _containing_len: Option) -> Result { - use self::SpecifiedLengthOrPercentage::*; + use self::SpecifiedLengthPercentage::*; match *self { Length(len) => len.to_computed_pixel_length_without_context(), Calc(ref calc) => calc.to_computed_pixel_length_without_context(), @@ -285,21 +283,17 @@ impl ToAbsoluteLength for ComputedLength { } } -impl ToAbsoluteLength for ComputedLengthOrPercentage { +impl ToAbsoluteLength for ComputedLengthPercentage { #[inline] fn to_pixel_length(&self, containing_len: Option) -> Result { - let extract_pixel_length = |lop: &ComputedLengthOrPercentage| match *lop { - ComputedLengthOrPercentage::Length(px) => px.px(), - ComputedLengthOrPercentage::Percentage(_) => 0., - ComputedLengthOrPercentage::Calc(calc) => calc.length().px(), - }; - match containing_len { Some(relative_len) => Ok(self.to_pixel_length(relative_len).px()), // If we don't have reference box, we cannot resolve the used value, // so only retrieve the length part. This will be used for computing // distance without any layout info. - None => Ok(extract_pixel_length(self)), + // + // FIXME(emilio): This looks wrong. + None => Ok(self.length_component().px()), } } } @@ -637,18 +631,18 @@ impl ToCss for Scale { /// A value of the `Translate` property /// /// -pub enum Translate { +pub enum Translate { /// 'none' None, /// '' or ' ' - Translate(LengthOrPercentage, LengthOrPercentage), + Translate(LengthPercentage, LengthPercentage), /// ' ' - Translate3D(LengthOrPercentage, LengthOrPercentage, Length), + Translate3D(LengthPercentage, LengthPercentage, Length), } /// A trait to check if this is a zero length. /// An alternative way is use num_traits::Zero. However, in order to implement num_traits::Zero, -/// we also have to implement Add, which may be complicated for LengthOrPercentage::Calc. +/// we also have to implement Add, which may be complicated for LengthPercentage::Calc. /// We could do this if other types also need it. If so, we could drop this trait. pub trait IsZeroLength { /// Returns true if this is a zero length. diff --git a/components/style/values/specified/background.rs b/components/style/values/specified/background.rs index d3c1b2c0d14..47c66feaef6 100644 --- a/components/style/values/specified/background.rs +++ b/components/style/values/specified/background.rs @@ -6,24 +6,24 @@ use crate::parser::{Parse, ParserContext}; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; -use crate::values::specified::length::NonNegativeLengthOrPercentageOrAuto; +use crate::values::specified::length::NonNegativeLengthPercentageOrAuto; use cssparser::Parser; use selectors::parser::SelectorParseErrorKind; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, ToCss}; /// A specified value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl Parse for BackgroundSize { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(width) = input.try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) { + if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) { let height = input - .try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) - .unwrap_or(NonNegativeLengthOrPercentageOrAuto::auto()); + .try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + .unwrap_or(NonNegativeLengthPercentageOrAuto::auto()); return Ok(GenericBackgroundSize::Explicit { width, height }); } Ok(try_match_ident_ignore_ascii_case! { input, @@ -37,8 +37,8 @@ impl BackgroundSize { /// Returns `auto auto`. pub fn auto() -> Self { GenericBackgroundSize::Explicit { - width: NonNegativeLengthOrPercentageOrAuto::auto(), - height: NonNegativeLengthOrPercentageOrAuto::auto(), + width: NonNegativeLengthPercentageOrAuto::auto(), + height: NonNegativeLengthPercentageOrAuto::auto(), } } } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 84624671ffe..b757c8eec48 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -17,7 +17,7 @@ use crate::values::specified::image::Image; use crate::values::specified::position::{HorizontalPosition, Position, VerticalPosition}; use crate::values::specified::url::SpecifiedUrl; use crate::values::specified::SVGPathData; -use crate::values::specified::{LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage}; use cssparser::Parser; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; @@ -35,26 +35,26 @@ pub type FloatAreaShape = generic::FloatAreaShape; pub type BasicShape = generic::BasicShape< HorizontalPosition, VerticalPosition, - LengthOrPercentage, - NonNegativeLengthOrPercentage, + LengthPercentage, + NonNegativeLengthPercentage, >; /// The specified value of `inset()` -pub type InsetRect = generic::InsetRect; +pub type InsetRect = generic::InsetRect; /// A specified circle. pub type Circle = - generic::Circle; + generic::Circle; /// A specified ellipse. pub type Ellipse = - generic::Ellipse; + generic::Ellipse; /// The specified value of `ShapeRadius` -pub type ShapeRadius = generic::ShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; /// The specified value of `Polygon` -pub type Polygon = generic::Polygon; +pub type Polygon = generic::Polygon; #[cfg(feature = "gecko")] fn is_clip_path_path_enabled(context: &ParserContext) -> bool { @@ -200,7 +200,7 @@ impl InsetRect { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let rect = Rect::parse_with(context, input, LengthOrPercentage::parse)?; + let rect = Rect::parse_with(context, input, LengthPercentage::parse)?; let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() { Some(BorderRadius::parse(context, input)?) } else { @@ -316,8 +316,8 @@ impl Parse for ShapeRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { - return Ok(generic::ShapeRadius::Length(lop)); + if let Ok(lp) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { + return Ok(generic::ShapeRadius::Length(lp)); } try_match_ident_ignore_ascii_case! { input, @@ -353,8 +353,8 @@ impl Polygon { let buf = input.parse_comma_separated(|i| { Ok(PolygonCoord( - LengthOrPercentage::parse(context, i)?, - LengthOrPercentage::parse(context, i)?, + LengthPercentage::parse(context, i)?, + LengthPercentage::parse(context, i)?, )) })?; diff --git a/components/style/values/specified/border.rs b/components/style/values/specified/border.rs index acd38ea5ba4..c3f1dd6f4af 100644 --- a/components/style/values/specified/border.rs +++ b/components/style/values/specified/border.rs @@ -13,7 +13,7 @@ use crate::values::generics::border::BorderRadius as GenericBorderRadius; use crate::values::generics::border::BorderSpacing as GenericBorderSpacing; use crate::values::generics::rect::Rect; use crate::values::generics::size::Size; -use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; +use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage}; use crate::values::specified::{AllowQuirks, NonNegativeNumber, NonNegativeNumberOrPercentage}; use cssparser::Parser; use std::fmt::{self, Write}; @@ -79,16 +79,16 @@ pub type BorderImageWidth = Rect; /// A specified value for a single side of a `border-image-width` property. pub type BorderImageSideWidth = - GenericBorderImageSideWidth; + GenericBorderImageSideWidth; /// A specified value for the `border-image-slice` property. pub type BorderImageSlice = GenericBorderImageSlice; /// A specified value for the `border-radius` property. -pub type BorderRadius = GenericBorderRadius; +pub type BorderRadius = GenericBorderRadius; /// A specified value for the `border-*-radius` longhand properties. -pub type BorderCornerRadius = GenericBorderCornerRadius; +pub type BorderCornerRadius = GenericBorderCornerRadius; /// A specified value for the `border-spacing` longhand properties. pub type BorderSpacing = GenericBorderSpacing; @@ -178,7 +178,7 @@ impl Parse for BorderImageSideWidth { return Ok(GenericBorderImageSideWidth::Auto); } - if let Ok(len) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { + if let Ok(len) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { return Ok(GenericBorderImageSideWidth::Length(len)); } @@ -206,9 +206,9 @@ impl Parse for BorderRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let widths = Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)?; + let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?; let heights = if input.try(|i| i.expect_delim('/')).is_ok() { - Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)? + Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)? } else { widths.clone() }; @@ -227,7 +227,7 @@ impl Parse for BorderCornerRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Size::parse_with(context, input, NonNegativeLengthOrPercentage::parse) + Size::parse_with(context, input, NonNegativeLengthPercentage::parse) .map(GenericBorderCornerRadius) } } diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index c785fb0c0db..30111170bc0 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -11,7 +11,7 @@ use crate::properties::{PropertyId, ShorthandId}; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::Perspective as GenericPerspective; use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign; -use crate::values::specified::length::{LengthOrPercentage, NonNegativeLength}; +use crate::values::specified::length::{LengthPercentage, NonNegativeLength}; use crate::values::specified::{AllowQuirks, Number}; use crate::values::{CustomIdent, KeyframesName}; use crate::Atom; @@ -271,17 +271,16 @@ impl Display { } /// A specified value for the `vertical-align` property. -pub type VerticalAlign = GenericVerticalAlign; +pub type VerticalAlign = GenericVerticalAlign; impl Parse for VerticalAlign { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lop) = - input.try(|i| LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes)) + if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) { - return Ok(GenericVerticalAlign::Length(lop)); + return Ok(GenericVerticalAlign::Length(lp)); } try_match_ident_ignore_ascii_case! { input, diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index 2fe00ff8799..9e66edd9a9e 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -52,7 +52,7 @@ pub enum CalcUnit { /// `` Percentage, /// ` | ` - LengthOrPercentage, + LengthPercentage, /// `` Angle, /// `