From 2d9d31ee04553446546763e88ff8fedd01aba63e Mon Sep 17 00:00:00 2001 From: Daniel Robertson Date: Sun, 17 Apr 2016 22:07:36 -0400 Subject: [PATCH] Add style property for flex-basis Add the style property for flex-basis. The property should allow all values acceptable for `width`|`height` with the addition of `content`. --- components/layout/incremental.rs | 4 +- .../dom/webidls/CSSStyleDeclaration.webidl | 2 + .../style/properties/properties.mako.rs | 3 + components/style/values.rs | 102 ++++++++++++++++++ ...exbox_computedstyle_flex-basis-percent.htm | 15 ++- ...flexbox_computedstyle_flex-basis-0.htm.ini | 3 - ...xbox_computedstyle_flex-basis-auto.htm.ini | 3 - ...x_computedstyle_flex-basis-percent.htm.ini | 3 - 8 files changed, 117 insertions(+), 18 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-0.htm.ini delete mode 100644 tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-auto.htm.ini delete mode 100644 tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm.ini diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index affb4f42c70..fb73e8b6d87 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -218,7 +218,9 @@ pub fn compute_damage(old: Option<&Arc>, new: &ServoCompute get_inheritedtable.border_collapse, get_inheritedtable.border_spacing, get_column.column_gap, - get_position.flex_direction + get_position.flex_direction, + get_position.flex_basis, + get_position.order ]) || add_if_not_equal!(old, new, damage, [ REPAINT, STORE_OVERFLOW, REFLOW_OUT_OF_FLOW ], [ get_position.top, get_position.left, diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 10cf77ccc83..567167024ee 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -310,5 +310,7 @@ partial interface CSSStyleDeclaration { [SetterThrows, TreatNullAs=EmptyString] attribute DOMString flexDirection; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString flex-direction; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString flexBasis; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString flex-basis; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString order; }; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 9fb8e132184..5b000c20642 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -4360,6 +4360,9 @@ pub mod longhands { } + ${helpers.predefined_type("flex-basis", "LengthOrPercentageOrAutoOrContent", + "computed::LengthOrPercentageOrAutoOrContent::Auto")} + ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", products="gecko")} // SVG 1.1 (Second Edition) diff --git a/components/style/values.rs b/components/style/values.rs index 79239788704..23c933bc394 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -1050,6 +1050,50 @@ pub mod specified { } } + #[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)] + pub enum LengthOrPercentageOrAutoOrContent { + Length(Length), + Percentage(Percentage), + Calc(CalcLengthOrPercentage), + Auto, + Content + } + + impl ToCss for LengthOrPercentageOrAutoOrContent { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + LengthOrPercentageOrAutoOrContent::Length(len) => len.to_css(dest), + LengthOrPercentageOrAutoOrContent::Percentage(perc) => perc.to_css(dest), + LengthOrPercentageOrAutoOrContent::Auto => dest.write_str("auto"), + LengthOrPercentageOrAutoOrContent::Content => dest.write_str("content"), + LengthOrPercentageOrAutoOrContent::Calc(calc) => calc.to_css(dest), + } + } + } + + impl LengthOrPercentageOrAutoOrContent { + pub fn parse(input: &mut Parser) -> Result { + let context = AllowedNumericType::NonNegative; + match try!(input.next()) { + Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => + Length::parse_dimension(value.value, unit).map(LengthOrPercentageOrAutoOrContent::Length), + Token::Percentage(ref value) if context.is_ok(value.unit_value) => + Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(value.unit_value))), + Token::Number(ref value) if value.value == 0. => + Ok(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0)))), + Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => + Ok(LengthOrPercentageOrAutoOrContent::Auto), + Token::Ident(ref value) if value.eq_ignore_ascii_case("content") => + Ok(LengthOrPercentageOrAutoOrContent::Content), + Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { + let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); + Ok(LengthOrPercentageOrAutoOrContent::Calc(calc)) + }, + _ => Err(()) + } + } + } + #[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)] pub struct BorderRadiusSize(pub Size2D); @@ -1771,6 +1815,64 @@ pub mod computed { } } + #[derive(PartialEq, Clone, Copy, HeapSizeOf)] + pub enum LengthOrPercentageOrAutoOrContent { + Length(Au), + Percentage(CSSFloat), + Calc(CalcLengthOrPercentage), + Auto, + Content + } + impl fmt::Debug for LengthOrPercentageOrAutoOrContent { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + LengthOrPercentageOrAutoOrContent::Length(length) => write!(f, "{:?}", length), + LengthOrPercentageOrAutoOrContent::Percentage(percentage) => write!(f, "{}%", percentage * 100.), + LengthOrPercentageOrAutoOrContent::Calc(calc) => write!(f, "{:?}", calc), + LengthOrPercentageOrAutoOrContent::Auto => write!(f, "auto"), + LengthOrPercentageOrAutoOrContent::Content => write!(f, "content") + } + } + } + + impl ToComputedValue for specified::LengthOrPercentageOrAutoOrContent { + type ComputedValue = LengthOrPercentageOrAutoOrContent; + + #[inline] + fn to_computed_value(&self, context: &Cx) -> LengthOrPercentageOrAutoOrContent { + match *self { + specified::LengthOrPercentageOrAutoOrContent::Length(value) => { + LengthOrPercentageOrAutoOrContent::Length(value.to_computed_value(context)) + }, + specified::LengthOrPercentageOrAutoOrContent::Percentage(value) => { + LengthOrPercentageOrAutoOrContent::Percentage(value.0) + }, + specified::LengthOrPercentageOrAutoOrContent::Calc(calc) => { + LengthOrPercentageOrAutoOrContent::Calc(calc.to_computed_value(context)) + }, + specified::LengthOrPercentageOrAutoOrContent::Auto => { + LengthOrPercentageOrAutoOrContent::Auto + }, + specified::LengthOrPercentageOrAutoOrContent::Content => { + LengthOrPercentageOrAutoOrContent::Content + } + } + } + } + + impl ::cssparser::ToCss for LengthOrPercentageOrAutoOrContent { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + LengthOrPercentageOrAutoOrContent::Length(length) => length.to_css(dest), + LengthOrPercentageOrAutoOrContent::Percentage(percentage) + => write!(dest, "{}%", percentage * 100.), + LengthOrPercentageOrAutoOrContent::Calc(calc) => calc.to_css(dest), + LengthOrPercentageOrAutoOrContent::Auto => dest.write_str("auto"), + LengthOrPercentageOrAutoOrContent::Content => dest.write_str("content") + } + } + } + #[derive(PartialEq, Clone, Copy, HeapSizeOf)] pub enum LengthOrPercentageOrNone { Length(Au), diff --git a/tests/wpt/css-tests/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm b/tests/wpt/css-tests/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm index 4b95fae9b5b..a87d086874d 100644 --- a/tests/wpt/css-tests/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm +++ b/tests/wpt/css-tests/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm @@ -5,24 +5,23 @@ -

FAIL, enable javascript

+

FAIL, enable javascript

- \ No newline at end of file + diff --git a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-0.htm.ini b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-0.htm.ini deleted file mode 100644 index 5e4c10a6cf7..00000000000 --- a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-0.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flexbox_computedstyle_flex-basis-0.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-auto.htm.ini b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-auto.htm.ini deleted file mode 100644 index 01333e3feae..00000000000 --- a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-auto.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flexbox_computedstyle_flex-basis-auto.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm.ini b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm.ini deleted file mode 100644 index 6aa92c48f90..00000000000 --- a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-basis-percent.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flexbox_computedstyle_flex-basis-percent.htm] - type: reftest - expected: FAIL