From 1fe45bc2050f3bf34e712d70327c5ca55f864671 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Wed, 13 Dec 2017 19:30:26 -0600 Subject: [PATCH] servo: Merge #19548 - style: Move outline-style outside of mako (from CYBAI:move-outline-style-out-of-mako); r=emilio 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 Source-Repo: https://github.com/servo/servo Source-Revision: 714c1b2455bc6f651e982b5efec85e3bf711f708 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : c435362b7e4d8abcae2548a7bfd07e7e77328e8a --- .../components/layout/display_list_builder.rs | 8 +-- .../components/style/properties/gecko.mako.rs | 9 +-- .../style/properties/longhand/outline.mako.rs | 53 +++--------------- servo/components/style/values/computed/mod.rs | 2 + .../style/values/computed/outline.rs | 7 +++ .../components/style/values/specified/mod.rs | 2 + .../style/values/specified/outline.rs | 56 +++++++++++++++++++ .../unit/style/properties/serialization.rs | 6 +- 8 files changed, 87 insertions(+), 56 deletions(-) create mode 100644 servo/components/style/values/computed/outline.rs create mode 100644 servo/components/style/values/specified/outline.rs diff --git a/servo/components/layout/display_list_builder.rs b/servo/components/layout/display_list_builder.rs index 1bcd251b886e..efe07fd5758f 100644 --- a/servo/components/layout/display_list_builder.rs +++ b/servo/components/layout/display_list_builder.rs @@ -1700,7 +1700,7 @@ impl FragmentDisplayListBuilding for Fragment { style: &ComputedValues, bounds: &Rect, clip: &Rect) { - 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/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 08516ed928b2..fcf045e1de88 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/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/servo/components/style/properties/longhand/outline.mako.rs b/servo/components/style/properties/longhand/outline.mako.rs index c35f42176f77..9446745ec3eb 100644 --- a/servo/components/style/properties/longhand/outline.mako.rs +++ b/servo/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; - - 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::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.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/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index a79f9990cd86..3f2388698fec 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/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/servo/components/style/values/computed/outline.rs b/servo/components/style/values/computed/outline.rs new file mode 100644 index 000000000000..b3fcaee40e62 --- /dev/null +++ b/servo/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/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index cc53fc480708..d9863620ae46 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/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/servo/components/style/values/specified/outline.rs b/servo/components/style/values/specified/outline.rs new file mode 100644 index 000000000000..483852422753 --- /dev/null +++ b/servo/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)] +/// +pub enum OutlineStyle { + /// auto + Auto, + /// + 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> { + 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/servo/tests/unit/style/properties/serialization.rs b/servo/tests/unit/style/properties/serialization.rs index 7ec045feb81d..caef14d6fbe6 100644 --- a/servo/tests/unit/style/properties/serialization.rs +++ b/servo/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));