mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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 -->
This commit is contained in:
commit
714c1b2455
8 changed files with 87 additions and 56 deletions
|
@ -1700,7 +1700,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
clip: &Rect<Au>) {
|
clip: &Rect<Au>) {
|
||||||
use style::values::Either;
|
use style::values::specified::outline::OutlineStyle;
|
||||||
|
|
||||||
let width = Au::from(style.get_outline().outline_width);
|
let width = Au::from(style.get_outline().outline_width);
|
||||||
if width == Au(0) {
|
if width == Au(0) {
|
||||||
|
@ -1708,9 +1708,9 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
let outline_style = match style.get_outline().outline_style {
|
let outline_style = match style.get_outline().outline_style {
|
||||||
Either::First(_auto) => BorderStyle::Solid,
|
OutlineStyle::Auto => BorderStyle::Solid,
|
||||||
Either::Second(BorderStyle::None) => return,
|
OutlineStyle::Other(BorderStyle::None) => return,
|
||||||
Either::Second(border_style) => border_style
|
OutlineStyle::Other(border_style) => border_style
|
||||||
};
|
};
|
||||||
|
|
||||||
// Outlines are not accounted for in the dimensions of the border box, so adjust the
|
// Outlines are not accounted for in the dimensions of the border box, so adjust the
|
||||||
|
|
|
@ -61,6 +61,7 @@ use values::{self, Auto, CustomIdent, Either, KeyframesName, None_};
|
||||||
use values::computed::{NonNegativeLength, ToComputedValue, Percentage};
|
use values::computed::{NonNegativeLength, ToComputedValue, Percentage};
|
||||||
use values::computed::font::{FontSize, SingleFontFamily};
|
use values::computed::font::{FontSize, SingleFontFamily};
|
||||||
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
|
use values::computed::outline::OutlineStyle;
|
||||||
use computed_values::border_style;
|
use computed_values::border_style;
|
||||||
|
|
||||||
pub mod style_structs {
|
pub mod style_structs {
|
||||||
|
@ -2348,10 +2349,10 @@ fn static_assert() {
|
||||||
// cast + static_asserts
|
// cast + static_asserts
|
||||||
let result = match v {
|
let result = match v {
|
||||||
% for value in border_style_keyword.values_for('gecko'):
|
% 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")},
|
structs::${border_style_keyword.gecko_constant(value)} ${border_style_keyword.maybe_cast("u8")},
|
||||||
% endfor
|
% endfor
|
||||||
Either::First(Auto) =>
|
OutlineStyle::Auto =>
|
||||||
structs::${border_style_keyword.gecko_constant('auto')} ${border_style_keyword.maybe_cast("u8")},
|
structs::${border_style_keyword.gecko_constant('auto')} ${border_style_keyword.maybe_cast("u8")},
|
||||||
};
|
};
|
||||||
${set_gecko_property("mOutlineStyle", "result")}
|
${set_gecko_property("mOutlineStyle", "result")}
|
||||||
|
@ -2378,10 +2379,10 @@ fn static_assert() {
|
||||||
match ${get_gecko_property("mOutlineStyle")} ${border_style_keyword.maybe_cast("u32")} {
|
match ${get_gecko_property("mOutlineStyle")} ${border_style_keyword.maybe_cast("u32")} {
|
||||||
% for value in border_style_keyword.values_for('gecko'):
|
% for value in border_style_keyword.values_for('gecko'):
|
||||||
structs::${border_style_keyword.gecko_constant(value)} => {
|
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
|
% 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:
|
% if border_style_keyword.gecko_inexhaustive:
|
||||||
x => panic!("Found unexpected value in style struct for outline_style property: {:?}", x),
|
x => panic!("Found unexpected value in style struct for outline_style property: {:?}", x),
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -20,51 +20,14 @@ ${helpers.predefined_type(
|
||||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color",
|
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color",
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<%helpers:longhand name="outline-style" animation_value_type="discrete"
|
${helpers.predefined_type(
|
||||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-style">
|
"outline-style",
|
||||||
use values::specified::BorderStyle;
|
"OutlineStyle",
|
||||||
|
"computed::OutlineStyle::none()",
|
||||||
pub type SpecifiedValue = Either<Auto, BorderStyle>;
|
initial_specified_value="specified::OutlineStyle::none()",
|
||||||
|
animation_value_type="discrete",
|
||||||
impl SpecifiedValue {
|
spec="https://drafts.csswg.org/css-ui/#propdef-outline-style",
|
||||||
#[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-width",
|
${helpers.predefined_type("outline-width",
|
||||||
"BorderSideWidth",
|
"BorderSideWidth",
|
||||||
|
|
|
@ -54,6 +54,7 @@ pub use super::specified::{BorderStyle, TextDecorationLine};
|
||||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
|
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
|
||||||
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
|
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||||
pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
|
pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||||
|
pub use self::outline::OutlineStyle;
|
||||||
pub use self::percentage::Percentage;
|
pub use self::percentage::Percentage;
|
||||||
pub use self::position::{Position, GridAutoFlow, GridTemplateAreas};
|
pub use self::position::{Position, GridAutoFlow, GridTemplateAreas};
|
||||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
|
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
|
||||||
|
@ -79,6 +80,7 @@ pub mod image;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub mod gecko;
|
pub mod gecko;
|
||||||
pub mod length;
|
pub mod length;
|
||||||
|
pub mod outline;
|
||||||
pub mod percentage;
|
pub mod percentage;
|
||||||
pub mod position;
|
pub mod position;
|
||||||
pub mod rect;
|
pub mod rect;
|
||||||
|
|
7
components/style/values/computed/outline.rs
Normal file
7
components/style/values/computed/outline.rs
Normal file
|
@ -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;
|
|
@ -49,6 +49,7 @@ pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
|
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||||
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
||||||
pub use self::length::NonNegativeLengthOrPercentage;
|
pub use self::length::NonNegativeLengthOrPercentage;
|
||||||
|
pub use self::outline::OutlineStyle;
|
||||||
pub use self::rect::LengthOrNumberRect;
|
pub use self::rect::LengthOrNumberRect;
|
||||||
pub use self::percentage::Percentage;
|
pub use self::percentage::Percentage;
|
||||||
pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
|
pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
|
||||||
|
@ -78,6 +79,7 @@ pub mod gecko;
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod length;
|
pub mod length;
|
||||||
|
pub mod outline;
|
||||||
pub mod percentage;
|
pub mod percentage;
|
||||||
pub mod position;
|
pub mod position;
|
||||||
pub mod rect;
|
pub mod rect;
|
||||||
|
|
56
components/style/values/specified/outline.rs
Normal file
56
components/style/values/specified/outline.rs
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -511,7 +511,7 @@ mod shorthand_serialization {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod outline {
|
mod outline {
|
||||||
use style::values::Either;
|
use style::values::specified::outline::OutlineStyle;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -519,7 +519,7 @@ mod shorthand_serialization {
|
||||||
let mut properties = Vec::new();
|
let mut properties = Vec::new();
|
||||||
|
|
||||||
let width = BorderSideWidth::Length(Length::from_px(4f32));
|
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();
|
let color = RGBA::new(255, 0, 0, 255).into();
|
||||||
|
|
||||||
properties.push(PropertyDeclaration::OutlineWidth(width));
|
properties.push(PropertyDeclaration::OutlineWidth(width));
|
||||||
|
@ -535,7 +535,7 @@ mod shorthand_serialization {
|
||||||
let mut properties = Vec::new();
|
let mut properties = Vec::new();
|
||||||
|
|
||||||
let width = BorderSideWidth::Length(Length::from_px(4f32));
|
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();
|
let color = RGBA::new(255, 0, 0, 255).into();
|
||||||
properties.push(PropertyDeclaration::OutlineWidth(width));
|
properties.push(PropertyDeclaration::OutlineWidth(width));
|
||||||
properties.push(PropertyDeclaration::OutlineStyle(style));
|
properties.push(PropertyDeclaration::OutlineStyle(style));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue