diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-01-07 16:43:10 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-01-08 12:00:42 +0100 |
commit | 4a31509215c70c8810019880b83025182a80b6e0 (patch) | |
tree | d8ebea49ee3ca7519739f3af63417c852aefcc4c | |
parent | ca503b4908cb45c20cc6777f9d01253057a86a97 (diff) | |
download | servo-4a31509215c70c8810019880b83025182a80b6e0.tar.gz servo-4a31509215c70c8810019880b83025182a80b6e0.zip |
style: Fix servo build.
This also fixes a bunch of calc handling issues and such.
Also remove tests that no longer compile and are covered by WPT.
-rw-r--r-- | components/layout/block.rs | 66 | ||||
-rw-r--r-- | components/layout/display_list/gradient.rs | 12 | ||||
-rw-r--r-- | components/layout/flex.rs | 36 | ||||
-rw-r--r-- | components/layout/floats.rs | 21 | ||||
-rw-r--r-- | components/layout/fragment.rs | 71 | ||||
-rw-r--r-- | components/layout/model.rs | 86 | ||||
-rw-r--r-- | components/layout/multicol.rs | 23 | ||||
-rw-r--r-- | components/layout/table.rs | 16 | ||||
-rw-r--r-- | components/layout/table_row.rs | 27 | ||||
-rw-r--r-- | components/script/dom/element.rs | 44 | ||||
-rw-r--r-- | components/style/properties/longhands/position.mako.rs | 2 | ||||
-rw-r--r-- | tests/unit/style/animated_properties.rs | 81 | ||||
-rw-r--r-- | tests/unit/style/attr.rs | 13 | ||||
-rw-r--r-- | tests/unit/style/properties/serialization.rs | 51 | ||||
-rw-r--r-- | tests/unit/style/stylesheets.rs | 68 | ||||
-rw-r--r-- | tests/unit/style/viewport.rs | 9 | ||||
-rw-r--r-- | tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini | 5 |
17 files changed, 197 insertions, 434 deletions
diff --git a/components/layout/block.rs b/components/layout/block.rs index 823d5226ea1..5cf6597654f 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::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; /// Information specific to floated blocks. #[derive(Clone, Serialize)] @@ -418,42 +417,23 @@ 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)) - }, - (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)) - }, - (LengthOrPercentageOrNone::Calc(calc), _) => { - calc.to_used_value(block_container_block_size) + let block_size = match fragment.style.content_block_size() { + LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_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) + + let max_block_size = match fragment.style.max_block_size() { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(block_container_block_size) }, - (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 +1395,9 @@ impl BlockFlow { pub fn explicit_block_size(&self, containing_block_size: Option<Au>) -> Option<Au> { 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 { + LengthOrPercentageOrAuto::Auto => { + let container_size = containing_block_size?; let (block_start, block_end) = { let position = self.fragment.style().logical_position(); ( @@ -1454,10 +1428,12 @@ impl BlockFlow { let sum = block_start + block_end + margin_block_start + margin_block_end; Some(available_block_size - sum) }, - (_, _) => None, } }, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(containing_block_size) + }, } } @@ -2177,8 +2153,8 @@ 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, + LengthOrPercentageOrAuto::Auto => true, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => lp.maybe_to_used_value(None).is_none(), }; self.bubble_inline_sizes_for_block(consult_children); self.fragment diff --git a/components/layout/display_list/gradient.rs b/components/layout/display_list/gradient.rs index 6cdee3d6df8..f7fc834e8d8 100644 --- a/components/layout/display_list/gradient.rs +++ b/components/layout/display_list/gradient.rs @@ -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(LengthOrPercentage::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(LengthOrPercentage::new_percent(Percentage(1.0))); } } @@ -214,13 +214,7 @@ fn position_to_offset(position: LengthOrPercentage, 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..fbd01c14dca 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}; @@ -52,18 +52,15 @@ impl AxisSize { max: LengthOrPercentageOrNone, ) -> 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 => { AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)) - }, + } + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + match lp.maybe_to_used_value(content_size) { + Some(length) => AxisSize::Definite(length), + None => AxisSize::Infinite, + } + } } } } @@ -461,10 +458,11 @@ 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 +486,10 @@ 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 { diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 5e9ee3ae886..9aa25f4e9b6 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -542,16 +542,21 @@ 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 { + LengthOrPercentageOrAuto::Auto => false, + LengthOrPercentageOrAuto::LengthOrPercentage(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/fragment.rs b/components/layout/fragment.rs index 3e84a36c595..5560941aaa8 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::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::transform; use webrender_api::{self, LayoutTransform}; @@ -1610,33 +1610,32 @@ 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() { + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(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 +2431,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 +2510,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_end != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthOrPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_end != - LengthOrPercentage::Length(Length::new(0.)) + LengthOrPercentage::zero() { return false; } @@ -2545,12 +2536,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_start != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthOrPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_start != - LengthOrPercentage::Length(Length::new(0.)) + LengthOrPercentage::zero() { return false; } diff --git a/components/layout/model.rs b/components/layout/model.rs index 4db60d05a4b..a54e3a9b76e 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -136,26 +136,19 @@ impl MarginCollapseInfo { 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() + LengthOrPercentageOrAuto::LengthOrPercentage(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 @@ -445,13 +438,9 @@ impl MaybeAuto { pub fn from_style(length: LengthOrPercentageOrAuto, containing_length: Au) -> MaybeAuto { match length { LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, - LengthOrPercentageOrAuto::Percentage(percent) => { - MaybeAuto::Specified(containing_length.scale_by(percent.0)) + LengthOrPercentageOrAuto::LengthOrPercentage(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)), } } @@ -485,6 +474,15 @@ impl MaybeAuto { } #[inline] + pub fn is_auto(&self) -> bool { + match *self { + MaybeAuto::Auto => true, + MaybeAuto::Specified(..) => false, + } + } + + + #[inline] pub fn map<F>(&self, mapper: F) -> MaybeAuto where F: FnOnce(Au) -> Au, @@ -503,15 +501,11 @@ pub fn style_length( style_length: LengthOrPercentageOrAuto, container_size: Option<Au>, ) -> 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 - } - }, + match style_length { + LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_to_used_value(container_size)) + } } } @@ -580,27 +574,16 @@ impl SizeConstraint { max_size: LengthOrPercentageOrNone, border: Option<Au>, ) -> 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 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 - } + let mut max_size = match max_size { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(container_size) }, }; + // Make sure max size is not smaller than min size. max_size = max_size.map(|x| max(x, min_size)); @@ -609,10 +592,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..e0234454b27 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -154,11 +154,22 @@ 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() { + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None) + } + }; + let size = size.or_else(|| { + match style.max_block_size() { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(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 +177,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..f492e9056ff 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -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), + LengthOrPercentageOrAuto::Auto => Au(0), + LengthOrPercentageOrAuto::LengthOrPercentage(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, + LengthOrPercentageOrAuto::Auto => 0.0, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.as_percentage().map_or(0.0, |p| p.0) + }, }, preferred: Au(0), constrained: false, diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 90c3c812f1c..52412d9a2d1 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -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 + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(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, + LengthOrPercentageOrAuto::Auto => 0.0, + LengthOrPercentageOrAuto::LengthOrPercentage(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, + LengthOrPercentageOrAuto::Auto => false, + LengthOrPercentageOrAuto::LengthOrPercentage(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/script/dom/element.rs b/components/script/dom/element.rs index 233d4a01bb3..6feb6381b77 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -718,7 +718,9 @@ impl LayoutElementHelpers for LayoutDom<Element> { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } @@ -743,8 +745,10 @@ impl LayoutElementHelpers for LayoutDom<Element> { match width { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let width_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let width_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Percentage( + computed::Percentage(percentage), + ), ); hints.push(from_declaration( shared_lock, @@ -753,9 +757,13 @@ impl LayoutElementHelpers for LayoutDom<Element> { }, LengthOrPercentageOrAuto::Length(length) => { let width_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( - specified::AbsoluteLength::Px(length.to_f32_px()), - )); + specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length( + specified::NoCalcLength::Absolute( + specified::AbsoluteLength::Px(length.to_f32_px()), + ), + ), + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Width(width_value), @@ -776,8 +784,10 @@ impl LayoutElementHelpers for LayoutDom<Element> { match height { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let height_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let height_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Percentage( + computed::Percentage(percentage), + ) ); hints.push(from_declaration( shared_lock, @@ -786,9 +796,13 @@ impl LayoutElementHelpers for LayoutDom<Element> { }, LengthOrPercentageOrAuto::Length(length) => { let height_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( - specified::AbsoluteLength::Px(length.to_f32_px()), - )); + specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length( + specified::NoCalcLength::Absolute( + specified::AbsoluteLength::Px(length.to_f32_px()), + ) + ) + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Height(height_value), @@ -815,7 +829,9 @@ impl LayoutElementHelpers for LayoutDom<Element> { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } @@ -837,7 +853,9 @@ impl LayoutElementHelpers for LayoutDom<Element> { )); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 53a3acf81ec..ddba7255008 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -297,7 +297,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "min-%s" % size, "LengthOrPercentage", - "computed::LengthOrPercentage::Length(computed::Length::new(0.))", + "computed::LengthOrPercentage::zero()", "parse_non_negative", spec=spec % ("min-%s" % size), logical_group="min-size", diff --git a/tests/unit/style/animated_properties.rs b/tests/unit/style/animated_properties.rs index 06102bc840e..8fa45a6305f 100644 --- a/tests/unit/style/animated_properties.rs +++ b/tests/unit/style/animated_properties.rs @@ -4,7 +4,6 @@ use cssparser::RGBA; use style::values::animated::{Animate, Procedure, ToAnimatedValue}; -use style::values::computed::Percentage; use style::values::generics::transform::{Transform, TransformOperation}; fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA { @@ -83,60 +82,6 @@ fn test_rgba_color_interepolation_out_of_range_clamped_2() { ); } -// Transform -#[test] -fn test_transform_interpolation_on_translate() { - use style::values::computed::{CalcLengthOrPercentage, Length, LengthOrPercentage}; - - let from = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(0.)), - LengthOrPercentage::Length(Length::new(100.)), - Length::new(25.), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(0.)), - Length::new(75.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(50.)), - LengthOrPercentage::Length(Length::new(50.)), - Length::new(50.), - )]) - ); - - let from = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(1.0)), - Length::new(25.), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(50.)), - Length::new(75.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::Translate3D( - // calc(50px + 25%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new( - Length::new(50.), - Some(Percentage(0.25)) - )), - // calc(25px + 50%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new( - Length::new(25.), - Some(Percentage(0.5)) - )), - Length::new(50.), - )]) - ); -} - #[test] fn test_transform_interpolation_on_scale() { let from = Transform(vec![TransformOperation::Scale3D(1.0, 2.0, 1.0)]); @@ -197,29 +142,3 @@ fn test_transform_interpolation_on_skew() { )]) ); } - -#[test] -fn test_transform_interpolation_on_mismatched_lists() { - use style::values::computed::{Angle, Length, LengthOrPercentage}; - - let from = Transform(vec![TransformOperation::Rotate3D( - 0.0, - 0.0, - 1.0, - Angle::from_radians(100.0), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(0.)), - Length::new(0.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::InterpolateMatrix { - from_list: from.clone(), - to_list: to.clone(), - progress: Percentage(0.5), - }]) - ); -} diff --git a/tests/unit/style/attr.rs b/tests/unit/style/attr.rs index 4521d83239a..261d6d8f98b 100644 --- a/tests/unit/style/attr.rs +++ b/tests/unit/style/attr.rs @@ -4,19 +4,6 @@ use app_units::Au; use style::attr::{parse_length, AttrValue, LengthOrPercentageOrAuto}; -use style::values::computed::{CalcLengthOrPercentage, Percentage}; - -#[test] -fn test_length_calc() { - let calc = CalcLengthOrPercentage::new(Au(10).into(), Some(Percentage(0.2))); - assert_eq!(calc.to_used_value(Some(Au(10))), Some(Au(12))); - assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10))); - assert_eq!(calc.to_used_value(None), None); - - let calc = CalcLengthOrPercentage::new(Au(10).into(), None); - assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10))); - assert_eq!(calc.to_used_value(None), Some(Au(10))); -} #[test] fn test_parse_double() { diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 035f9a9385c..8853ab010dd 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -4,13 +4,11 @@ use crate::properties::{parse, parse_input}; use crate::stylesheets::block_from; -use style::computed_values::display::T as Display; use style::properties::declaration_block::PropertyDeclarationBlock; use style::properties::parse_property_declaration_list; use style::properties::{Importance, PropertyDeclaration}; use style::values::specified::url::SpecifiedUrl; -use style::values::specified::NoCalcLength; -use style::values::specified::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::specified::Length; use style_traits::ToCss; trait ToCssString { @@ -25,53 +23,6 @@ impl ToCssString for PropertyDeclarationBlock { } } -#[test] -fn property_declaration_block_should_serialize_correctly() { - use style::properties::longhands::overflow_x::SpecifiedValue as OverflowValue; - - let declarations = vec![ - ( - PropertyDeclaration::Width(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( - 70f32, - ))), - Importance::Normal, - ), - ( - PropertyDeclaration::MinHeight(LengthOrPercentage::Length(NoCalcLength::from_px( - 20f32, - ))), - Importance::Normal, - ), - ( - PropertyDeclaration::Height(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( - 20f32, - ))), - Importance::Important, - ), - ( - PropertyDeclaration::Display(Display::InlineBlock), - Importance::Normal, - ), - ( - PropertyDeclaration::OverflowX(OverflowValue::Auto), - Importance::Normal, - ), - ( - PropertyDeclaration::OverflowY(OverflowValue::Auto), - Importance::Normal, - ), - ]; - - let block = block_from(declarations); - - let css_string = block.to_css_string(); - - assert_eq!( - css_string, - "width: 70px; min-height: 20px; height: 20px !important; display: inline-block; overflow: auto;" - ); -} - mod shorthand_serialization { pub use super::*; diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index a0557ad8795..68bbff46f9f 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -17,20 +17,16 @@ use std::sync::atomic::AtomicBool; use style::context::QuirksMode; use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::media_queries::MediaList; -use style::properties::longhands::{self, animation_timing_function}; +use style::properties::longhands; use style::properties::{CSSWideKeyword, CustomDeclaration}; use style::properties::{CustomDeclarationValue, Importance}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::shared_lock::SharedRwLock; -use style::stylesheets::keyframes_rule::{Keyframe, KeyframePercentage, KeyframeSelector}; use style::stylesheets::{ - CssRule, CssRules, KeyframesRule, NamespaceRule, StyleRule, Stylesheet, StylesheetContents, + CssRule, CssRules, NamespaceRule, StyleRule, Stylesheet, StylesheetContents, }; use style::stylesheets::{Namespaces, Origin}; -use style::values::computed::Percentage; -use style::values::specified::TimingFunction; -use style::values::specified::{LengthOrPercentageOrAuto, PositionComponent}; -use style::values::{CustomIdent, KeyframesName}; +use style::values::specified::PositionComponent; pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock where @@ -61,14 +57,6 @@ fn test_parse_stylesheet() { display: block; } #d1 > .ok { background: blue; } - @keyframes foo { - from { width: 0% } - to { - width: 100%; - width: 50% !important; /* !important not allowed here */ - animation-name: 'foo'; /* animation properties not allowed here */ - animation-timing-function: ease; /* … except animation-timing-function */ - } }"; let url = ServoUrl::parse("about::test").unwrap(); let lock = SharedRwLock::new(); @@ -278,56 +266,6 @@ fn test_parse_stylesheet() { column: 9, }, }))), - CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule { - name: KeyframesName::Ident(CustomIdent("foo".into())), - keyframes: vec![ - Arc::new(stylesheet.shared_lock.wrap(Keyframe { - selector: KeyframeSelector::new_for_unit_testing(vec![ - KeyframePercentage::new(0.), - ]), - block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![( - PropertyDeclaration::Width( - LengthOrPercentageOrAuto::Percentage(Percentage(0.)), - ), - Importance::Normal, - )]))), - source_location: SourceLocation { - line: 17, - column: 13, - }, - })), - Arc::new(stylesheet.shared_lock.wrap(Keyframe { - selector: KeyframeSelector::new_for_unit_testing(vec![ - KeyframePercentage::new(1.), - ]), - block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![ - ( - PropertyDeclaration::Width( - LengthOrPercentageOrAuto::Percentage(Percentage(1.)), - ), - Importance::Normal, - ), - ( - PropertyDeclaration::AnimationTimingFunction( - animation_timing_function::SpecifiedValue(vec![ - TimingFunction::ease(), - ]), - ), - Importance::Normal, - ), - ]))), - source_location: SourceLocation { - line: 18, - column: 13, - }, - })), - ], - vendor_prefix: None, - source_location: SourceLocation { - line: 16, - column: 19, - }, - }))), ], &stylesheet.shared_lock, ), diff --git a/tests/unit/style/viewport.rs b/tests/unit/style/viewport.rs index 5855b11e114..41fc2539f39 100644 --- a/tests/unit/style/viewport.rs +++ b/tests/unit/style/viewport.rs @@ -17,6 +17,7 @@ use style::stylesheets::{CssRuleType, Origin, Stylesheet, StylesheetInDocument}; use style::values::specified::LengthOrPercentageOrAuto::{self, Auto}; use style::values::specified::NoCalcLength::{self, ViewportPercentage}; use style::values::specified::ViewportPercentageLength::Vw; +use style::values::specified::LengthOrPercentage; use style_traits::viewport::*; use style_traits::{ParsingMode, PinchZoomFactor}; @@ -96,14 +97,14 @@ macro_rules! assert_decl_len { macro_rules! viewport_length { ($value:expr, px) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( + ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(NoCalcLength::from_px( $value, - ))) + )))) }; ($value:expr, vw) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length(ViewportPercentage(Vw( + ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(ViewportPercentage(Vw( $value, - )))) + ))))) }; } diff --git a/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini b/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini index d9922a6482f..07ba6517e69 100644 --- a/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini +++ b/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini @@ -1,6 +1,4 @@ [variable-substitution-replaced-size.html] - [height on IFRAME] - expected: FAIL [width on INPUT] expected: FAIL @@ -8,6 +6,3 @@ [height on INPUT] expected: FAIL - [height on CANVAS] - expected: FAIL - |