diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-12-13 19:30:26 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 19:30:26 -0600 |
commit | 714c1b2455bc6f651e982b5efec85e3bf711f708 (patch) | |
tree | 9db5128d669c7b264f73224c10802552ea5061e0 | |
parent | 8ca43e41efca61b015c47f4d109c4d49b2a4ea0b (diff) | |
parent | b9b91b33be2365d40d2f7c101da82171ef6a8761 (diff) | |
download | servo-714c1b2455bc6f651e982b5efec85e3bf711f708.tar.gz servo-714c1b2455bc6f651e982b5efec85e3bf711f708.zip |
Auto merge of #19548 - CYBAI:move-outline-style-out-of-mako, r=emilio
style: Move outline-style outside of mako
This is a sub-PR of #19015
r? emilio
---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #19546
- [x] These changes do not require tests
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19548)
<!-- Reviewable:end -->
-rw-r--r-- | components/layout/display_list_builder.rs | 8 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 9 | ||||
-rw-r--r-- | components/style/properties/longhand/outline.mako.rs | 53 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 2 | ||||
-rw-r--r-- | components/style/values/computed/outline.rs | 7 | ||||
-rw-r--r-- | components/style/values/specified/mod.rs | 2 | ||||
-rw-r--r-- | components/style/values/specified/outline.rs | 56 | ||||
-rw-r--r-- | tests/unit/style/properties/serialization.rs | 6 |
8 files changed, 87 insertions, 56 deletions
diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 1bcd251b886..efe07fd5758 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -1700,7 +1700,7 @@ impl FragmentDisplayListBuilding for Fragment { style: &ComputedValues, bounds: &Rect<Au>, clip: &Rect<Au>) { - use style::values::Either; + use style::values::specified::outline::OutlineStyle; let width = Au::from(style.get_outline().outline_width); if width == Au(0) { @@ -1708,9 +1708,9 @@ impl FragmentDisplayListBuilding for Fragment { } let outline_style = match style.get_outline().outline_style { - Either::First(_auto) => BorderStyle::Solid, - Either::Second(BorderStyle::None) => return, - Either::Second(border_style) => border_style + OutlineStyle::Auto => BorderStyle::Solid, + OutlineStyle::Other(BorderStyle::None) => return, + OutlineStyle::Other(border_style) => border_style }; // Outlines are not accounted for in the dimensions of the border box, so adjust the diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 08516ed928b..fcf045e1de8 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -61,6 +61,7 @@ use values::{self, Auto, CustomIdent, Either, KeyframesName, None_}; use values::computed::{NonNegativeLength, ToComputedValue, Percentage}; use values::computed::font::{FontSize, SingleFontFamily}; use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; +use values::computed::outline::OutlineStyle; use computed_values::border_style; pub mod style_structs { @@ -2348,10 +2349,10 @@ fn static_assert() { // cast + static_asserts let result = match v { % for value in border_style_keyword.values_for('gecko'): - Either::Second(border_style::T::${to_camel_case(value)}) => + OutlineStyle::Other(border_style::T::${to_camel_case(value)}) => structs::${border_style_keyword.gecko_constant(value)} ${border_style_keyword.maybe_cast("u8")}, % endfor - Either::First(Auto) => + OutlineStyle::Auto => structs::${border_style_keyword.gecko_constant('auto')} ${border_style_keyword.maybe_cast("u8")}, }; ${set_gecko_property("mOutlineStyle", "result")} @@ -2378,10 +2379,10 @@ fn static_assert() { match ${get_gecko_property("mOutlineStyle")} ${border_style_keyword.maybe_cast("u32")} { % for value in border_style_keyword.values_for('gecko'): structs::${border_style_keyword.gecko_constant(value)} => { - Either::Second(border_style::T::${to_camel_case(value)}) + OutlineStyle::Other(border_style::T::${to_camel_case(value)}) }, % endfor - structs::${border_style_keyword.gecko_constant('auto')} => Either::First(Auto), + structs::${border_style_keyword.gecko_constant('auto')} => OutlineStyle::Auto, % if border_style_keyword.gecko_inexhaustive: x => panic!("Found unexpected value in style struct for outline_style property: {:?}", x), % endif diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index c35f42176f7..9446745ec3e 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -20,51 +20,14 @@ ${helpers.predefined_type( spec="https://drafts.csswg.org/css-ui/#propdef-outline-color", )} -<%helpers:longhand name="outline-style" animation_value_type="discrete" - spec="https://drafts.csswg.org/css-ui/#propdef-outline-style"> - use values::specified::BorderStyle; - - pub type SpecifiedValue = Either<Auto, BorderStyle>; - - impl SpecifiedValue { - #[inline] - pub fn none_or_hidden(&self) -> bool { - match *self { - Either::First(ref _auto) => false, - Either::Second(ref border_style) => border_style.none_or_hidden() - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - Either::Second(BorderStyle::None) - } - - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - Either::Second(BorderStyle::None) - } - - pub mod computed_value { - pub type T = super::SpecifiedValue; - } - - pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result<SpecifiedValue, ParseError<'i>> { - SpecifiedValue::parse(context, input) - .and_then(|result| { - if let Either::Second(BorderStyle::Hidden) = result { - // The outline-style property accepts the same values as - // border-style, except that 'hidden' is not a legal outline - // style. - Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))) - } else { - Ok(result) - } - }) - } -</%helpers:longhand> +${helpers.predefined_type( + "outline-style", + "OutlineStyle", + "computed::OutlineStyle::none()", + initial_specified_value="specified::OutlineStyle::none()", + animation_value_type="discrete", + spec="https://drafts.csswg.org/css-ui/#propdef-outline-style", +)} ${helpers.predefined_type("outline-width", "BorderSideWidth", diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index a79f9990cd8..3f2388698fe 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -54,6 +54,7 @@ pub use super::specified::{BorderStyle, TextDecorationLine}; pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage}; pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage}; +pub use self::outline::OutlineStyle; pub use self::percentage::Percentage; pub use self::position::{Position, GridAutoFlow, GridTemplateAreas}; pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth}; @@ -79,6 +80,7 @@ pub mod image; #[cfg(feature = "gecko")] pub mod gecko; pub mod length; +pub mod outline; pub mod percentage; pub mod position; pub mod rect; diff --git a/components/style/values/computed/outline.rs b/components/style/values/computed/outline.rs new file mode 100644 index 00000000000..b3fcaee40e6 --- /dev/null +++ b/components/style/values/computed/outline.rs @@ -0,0 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Computed values for outline properties + +pub use values::specified::OutlineStyle; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index cc53fc48070..d9863620ae4 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -49,6 +49,7 @@ pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength}; pub use self::length::{NoCalcLength, ViewportPercentageLength}; pub use self::length::NonNegativeLengthOrPercentage; +pub use self::outline::OutlineStyle; pub use self::rect::LengthOrNumberRect; pub use self::percentage::Percentage; pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas}; @@ -78,6 +79,7 @@ pub mod gecko; pub mod grid; pub mod image; pub mod length; +pub mod outline; pub mod percentage; pub mod position; pub mod rect; diff --git a/components/style/values/specified/outline.rs b/components/style/values/specified/outline.rs new file mode 100644 index 00000000000..48385242275 --- /dev/null +++ b/components/style/values/specified/outline.rs @@ -0,0 +1,56 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Specified values for outline properties + +use cssparser::Parser; +use parser::{Parse, ParserContext}; +use selectors::parser::SelectorParseErrorKind; +use style_traits::ParseError; +use values::specified::BorderStyle; + +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Ord)] +#[derive(PartialEq, PartialOrd, ToComputedValue, ToCss)] +/// <https://drafts.csswg.org/css-ui/#propdef-outline-style> +pub enum OutlineStyle { + /// auto + Auto, + /// <border-style> + Other(BorderStyle), +} + +impl OutlineStyle { + #[inline] + /// Get default value as None + pub fn none() -> OutlineStyle { + OutlineStyle::Other(BorderStyle::None) + } + + #[inline] + /// Get value for None or Hidden + pub fn none_or_hidden(&self) -> bool { + match *self { + OutlineStyle::Auto => false, + OutlineStyle::Other(ref border_style) => border_style.none_or_hidden() + } + } +} + +impl Parse for OutlineStyle { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result<OutlineStyle, ParseError<'i>> { + if let Ok(border_style) = input.try(|i| BorderStyle::parse(context, i)) { + if let BorderStyle::Hidden = border_style { + return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))); + } + + return Ok(OutlineStyle::Other(border_style)); + } + + input.expect_ident_matching("auto")?; + Ok(OutlineStyle::Auto) + } +} diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 7ec045feb81..caef14d6fbe 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -511,7 +511,7 @@ mod shorthand_serialization { } mod outline { - use style::values::Either; + use style::values::specified::outline::OutlineStyle; use super::*; #[test] @@ -519,7 +519,7 @@ mod shorthand_serialization { let mut properties = Vec::new(); let width = BorderSideWidth::Length(Length::from_px(4f32)); - let style = Either::Second(BorderStyle::Solid); + let style = OutlineStyle::Other(BorderStyle::Solid); let color = RGBA::new(255, 0, 0, 255).into(); properties.push(PropertyDeclaration::OutlineWidth(width)); @@ -535,7 +535,7 @@ mod shorthand_serialization { let mut properties = Vec::new(); let width = BorderSideWidth::Length(Length::from_px(4f32)); - let style = Either::First(Auto); + let style = OutlineStyle::Auto; let color = RGBA::new(255, 0, 0, 255).into(); properties.push(PropertyDeclaration::OutlineWidth(width)); properties.push(PropertyDeclaration::OutlineStyle(style)); |