mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Use Rust types for some misc properties.
-moz-tab-size, border-image-outset and border-image-slice. This is not a particularly interesting patch, just removes some code. We can remove way more code when a few related properties are also ported. Differential Revision: https://phabricator.services.mozilla.com/D19825
This commit is contained in:
parent
eefd440656
commit
6118e4d993
16 changed files with 149 additions and 184 deletions
|
@ -87,19 +87,22 @@ include = [
|
||||||
"FlexBasis",
|
"FlexBasis",
|
||||||
"Position",
|
"Position",
|
||||||
"BackgroundSize",
|
"BackgroundSize",
|
||||||
|
"BorderImageSlice",
|
||||||
|
"NonNegativeLengthOrNumberRect",
|
||||||
]
|
]
|
||||||
item_types = ["enums", "structs", "typedefs"]
|
item_types = ["enums", "structs", "typedefs"]
|
||||||
|
|
||||||
[export.body]
|
[export.body]
|
||||||
|
"CSSPixelLength" = """
|
||||||
|
inline nscoord ToAppUnits() const;
|
||||||
|
"""
|
||||||
|
|
||||||
"LengthPercentage" = """
|
"LengthPercentage" = """
|
||||||
// Defined in nsStyleCoord.h
|
// Defined in nsStyleCoord.h
|
||||||
static constexpr inline StyleLengthPercentage Zero();
|
static constexpr inline StyleLengthPercentage Zero();
|
||||||
static inline StyleLengthPercentage FromAppUnits(nscoord);
|
static inline StyleLengthPercentage FromAppUnits(nscoord);
|
||||||
static inline StyleLengthPercentage FromPercentage(float);
|
static inline StyleLengthPercentage FromPercentage(float);
|
||||||
inline CSSCoord LengthInCSSPixels() const;
|
inline CSSCoord LengthInCSSPixels() const;
|
||||||
private:
|
|
||||||
inline nscoord LengthComponent() const;
|
|
||||||
public:
|
|
||||||
inline float Percentage() const;
|
inline float Percentage() const;
|
||||||
inline bool HasPercent() const;
|
inline bool HasPercent() const;
|
||||||
inline bool ConvertsToLength() const;
|
inline bool ConvertsToLength() const;
|
||||||
|
|
|
@ -61,7 +61,6 @@ use crate::values::computed::font::FontSize;
|
||||||
use crate::values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
use crate::values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
use crate::values::generics::column::ColumnCount;
|
use crate::values::generics::column::ColumnCount;
|
||||||
use crate::values::generics::position::ZIndex;
|
use crate::values::generics::position::ZIndex;
|
||||||
use crate::values::generics::text::MozTabSize;
|
|
||||||
use crate::values::generics::transform::TransformStyle;
|
use crate::values::generics::transform::TransformStyle;
|
||||||
use crate::values::generics::url::UrlOrNone;
|
use crate::values::generics::url::UrlOrNone;
|
||||||
|
|
||||||
|
@ -1371,6 +1370,9 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
"MozScriptMinSize": impl_absolute_length,
|
"MozScriptMinSize": impl_absolute_length,
|
||||||
"MozScriptSizeMultiplier": impl_simple,
|
"MozScriptSizeMultiplier": impl_simple,
|
||||||
"NonNegativeLengthPercentage": impl_simple,
|
"NonNegativeLengthPercentage": impl_simple,
|
||||||
|
"NonNegativeLengthOrNumber": impl_simple,
|
||||||
|
"NonNegativeLengthOrNumberRect": impl_simple,
|
||||||
|
"BorderImageSlice": impl_simple,
|
||||||
"NonNegativeNumber": impl_simple,
|
"NonNegativeNumber": impl_simple,
|
||||||
"Number": impl_simple,
|
"Number": impl_simple,
|
||||||
"Opacity": impl_simple,
|
"Opacity": impl_simple,
|
||||||
|
@ -1476,8 +1478,8 @@ fn static_assert() {
|
||||||
for x in CORNERS]) %>
|
for x in CORNERS]) %>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Border"
|
<%self:impl_trait style_struct_name="Border"
|
||||||
skip_longhands="${skip_border_longhands} border-image-source border-image-outset
|
skip_longhands="${skip_border_longhands} border-image-source
|
||||||
border-image-repeat border-image-width border-image-slice">
|
border-image-repeat border-image-width">
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
pub fn set_border_${side.ident}_style(&mut self, v: BorderStyle) {
|
pub fn set_border_${side.ident}_style(&mut self, v: BorderStyle) {
|
||||||
self.gecko.mBorderStyle[${side.index}] = v;
|
self.gecko.mBorderStyle[${side.index}] = v;
|
||||||
|
@ -1578,8 +1580,6 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
<% impl_style_sides("border_image_outset") %>
|
|
||||||
|
|
||||||
<%
|
<%
|
||||||
border_image_repeat_keywords = ["Stretch", "Repeat", "Round", "Space"]
|
border_image_repeat_keywords = ["Stretch", "Repeat", "Round", "Space"]
|
||||||
%>
|
%>
|
||||||
|
@ -1621,36 +1621,6 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
<% impl_style_sides("border_image_width") %>
|
<% impl_style_sides("border_image_width") %>
|
||||||
|
|
||||||
pub fn set_border_image_slice(&mut self, v: longhands::border_image_slice::computed_value::T) {
|
|
||||||
use crate::gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_SLICE_NOFILL, NS_STYLE_BORDER_IMAGE_SLICE_FILL};
|
|
||||||
|
|
||||||
v.offsets.to_gecko_rect(&mut self.gecko.mBorderImageSlice);
|
|
||||||
|
|
||||||
let fill = if v.fill {
|
|
||||||
NS_STYLE_BORDER_IMAGE_SLICE_FILL
|
|
||||||
} else {
|
|
||||||
NS_STYLE_BORDER_IMAGE_SLICE_NOFILL
|
|
||||||
};
|
|
||||||
self.gecko.mBorderImageFill = fill as u8;
|
|
||||||
}
|
|
||||||
|
|
||||||
<%self:copy_sides_style_coord ident="border_image_slice">
|
|
||||||
self.gecko.mBorderImageFill = other.gecko.mBorderImageFill;
|
|
||||||
</%self:copy_sides_style_coord>
|
|
||||||
|
|
||||||
pub fn clone_border_image_slice(&self) -> longhands::border_image_slice::computed_value::T {
|
|
||||||
use crate::gecko_bindings::structs::NS_STYLE_BORDER_IMAGE_SLICE_FILL;
|
|
||||||
use crate::values::computed::{BorderImageSlice, NonNegativeNumberOrPercentage};
|
|
||||||
type NumberOrPercentageRect = crate::values::generics::rect::Rect<NonNegativeNumberOrPercentage>;
|
|
||||||
|
|
||||||
BorderImageSlice {
|
|
||||||
offsets:
|
|
||||||
NumberOrPercentageRect::from_gecko_rect(&self.gecko.mBorderImageSlice)
|
|
||||||
.expect("mBorderImageSlice[${side}] could not convert to NumberOrPercentageRect"),
|
|
||||||
fill: self.gecko.mBorderImageFill as u32 == NS_STYLE_BORDER_IMAGE_SLICE_FILL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<% skip_scroll_margin_longhands = " ".join(["scroll-margin-%s" % x.ident for x in SIDES]) %>
|
<% skip_scroll_margin_longhands = " ".join(["scroll-margin-%s" % x.ident for x in SIDES]) %>
|
||||||
|
@ -4377,7 +4347,7 @@ fn static_assert() {
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedText"
|
<%self:impl_trait style_struct_name="InheritedText"
|
||||||
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing
|
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing
|
||||||
-webkit-text-stroke-width text-emphasis-position -moz-tab-size">
|
-webkit-text-stroke-width text-emphasis-position">
|
||||||
|
|
||||||
<% text_align_keyword = Keyword("text-align",
|
<% text_align_keyword = Keyword("text-align",
|
||||||
"start end left right center justify -moz-center -moz-left -moz-right char",
|
"start end left right center justify -moz-center -moz-left -moz-right char",
|
||||||
|
@ -4566,28 +4536,6 @@ fn static_assert() {
|
||||||
${impl_non_negative_length('_webkit_text_stroke_width',
|
${impl_non_negative_length('_webkit_text_stroke_width',
|
||||||
'mWebkitTextStrokeWidth')}
|
'mWebkitTextStrokeWidth')}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub fn set__moz_tab_size(&mut self, v: longhands::_moz_tab_size::computed_value::T) {
|
|
||||||
match v {
|
|
||||||
MozTabSize::Number(non_negative_number) => {
|
|
||||||
self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0));
|
|
||||||
}
|
|
||||||
MozTabSize::Length(non_negative_length) => {
|
|
||||||
self.gecko.mTabSize.set(non_negative_length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub fn clone__moz_tab_size(&self) -> longhands::_moz_tab_size::computed_value::T {
|
|
||||||
match self.gecko.mTabSize.as_value() {
|
|
||||||
CoordDataValue::Coord(coord) => MozTabSize::Length(Au(coord).into()),
|
|
||||||
CoordDataValue::Factor(number) => MozTabSize::Number(From::from(number)),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<%call expr="impl_coord_copy('_moz_tab_size', 'mTabSize')"></%call>
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Text"
|
<%self:impl_trait style_struct_name="Text"
|
||||||
|
|
|
@ -119,10 +119,9 @@ ${helpers.predefined_type(
|
||||||
|
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"border-image-outset",
|
"border-image-outset",
|
||||||
"LengthOrNumberRect",
|
"NonNegativeLengthOrNumberRect",
|
||||||
parse_method="parse_non_negative",
|
initial_value="generics::rect::Rect::all(computed::NonNegativeLengthOrNumber::zero())",
|
||||||
initial_value="computed::LengthOrNumberRect::all(computed::LengthOrNumber::zero())",
|
initial_specified_value="generics::rect::Rect::all(specified::NonNegativeLengthOrNumber::zero())",
|
||||||
initial_specified_value="specified::LengthOrNumberRect::all(specified::LengthOrNumber::zero())",
|
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#border-image-outset",
|
spec="https://drafts.csswg.org/css-backgrounds/#border-image-outset",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
flags="APPLIES_TO_FIRST_LETTER",
|
flags="APPLIES_TO_FIRST_LETTER",
|
||||||
|
|
|
@ -257,10 +257,10 @@ ${helpers.predefined_type(
|
||||||
|
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
"-moz-tab-size",
|
"-moz-tab-size",
|
||||||
"MozTabSize",
|
"NonNegativeLengthOrNumber",
|
||||||
"generics::text::MozTabSize::Number(From::from(8.0))",
|
"generics::length::LengthOrNumber::Number(From::from(8.0))",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
animation_value_type="AnimatedMozTabSize",
|
animation_value_type="LengthOrNumber",
|
||||||
spec="https://drafts.csswg.org/css-text-3/#tab-size-property",
|
spec="https://drafts.csswg.org/css-text-3/#tab-size-property",
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -349,8 +349,8 @@ ${helpers.single_keyword(
|
||||||
"-moz-control-character-visibility",
|
"-moz-control-character-visibility",
|
||||||
"hidden visible",
|
"hidden visible",
|
||||||
gecko_constant_prefix="NS_STYLE_CONTROL_CHARACTER_VISIBILITY",
|
gecko_constant_prefix="NS_STYLE_CONTROL_CHARACTER_VISIBILITY",
|
||||||
gecko_ffi_name="mControlCharacterVisibility",
|
|
||||||
animation_value_type="none",
|
animation_value_type="none",
|
||||||
|
gecko_ffi_name="mControlCharacterVisibility",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
spec="Nonstandard",
|
spec="Nonstandard",
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
|
|
||||||
use super::{Context, Number, Percentage, ToComputedValue};
|
use super::{Context, Number, Percentage, ToComputedValue};
|
||||||
use crate::values::animated::ToAnimatedValue;
|
use crate::values::animated::ToAnimatedValue;
|
||||||
|
use crate::values::computed::NonNegativeNumber;
|
||||||
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
use crate::values::generics::length as generics;
|
use crate::values::generics::length as generics;
|
||||||
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize};
|
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize, GenericLengthOrNumber};
|
||||||
use crate::values::generics::transform::IsZeroLength;
|
use crate::values::generics::transform::IsZeroLength;
|
||||||
use crate::values::generics::NonNegative;
|
use crate::values::generics::NonNegative;
|
||||||
use crate::values::specified::length::ViewportPercentageLength;
|
use crate::values::specified::length::ViewportPercentageLength;
|
||||||
|
@ -678,6 +679,15 @@ impl ToCss for CSSPixelLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Add for CSSPixelLength {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn add(self, other: Self) -> Self {
|
||||||
|
Self::new(self.px() + other.px())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Neg for CSSPixelLength {
|
impl Neg for CSSPixelLength {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
|
@ -708,15 +718,7 @@ pub type Length = CSSPixelLength;
|
||||||
pub type LengthOrAuto = Either<Length, Auto>;
|
pub type LengthOrAuto = Either<Length, Auto>;
|
||||||
|
|
||||||
/// Either a computed `<length>` or a `<number>` value.
|
/// Either a computed `<length>` or a `<number>` value.
|
||||||
pub type LengthOrNumber = Either<Length, Number>;
|
pub type LengthOrNumber = GenericLengthOrNumber<Length, Number>;
|
||||||
|
|
||||||
impl LengthOrNumber {
|
|
||||||
/// Returns `0`.
|
|
||||||
#[inline]
|
|
||||||
pub fn zero() -> Self {
|
|
||||||
Either::Second(0.)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Either a computed `<length>` or the `normal` keyword.
|
/// Either a computed `<length>` or the `normal` keyword.
|
||||||
pub type LengthOrNormal = Either<Length, Normal>;
|
pub type LengthOrNormal = Either<Length, Normal>;
|
||||||
|
@ -776,13 +778,6 @@ impl NonNegativeLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<NonNegativeLength> for NonNegativeLength {
|
|
||||||
type Output = Self;
|
|
||||||
fn add(self, other: Self) -> Self {
|
|
||||||
NonNegativeLength::new(self.px() + other.px())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Length> for NonNegativeLength {
|
impl From<Length> for NonNegativeLength {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(len: Length) -> Self {
|
fn from(len: Length) -> Self {
|
||||||
|
@ -813,6 +808,9 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
||||||
/// Either a computed NonNegativeLengthPercentage or the `normal` keyword.
|
/// Either a computed NonNegativeLengthPercentage or the `normal` keyword.
|
||||||
pub type NonNegativeLengthPercentageOrNormal = Either<NonNegativeLengthPercentage, Normal>;
|
pub type NonNegativeLengthPercentageOrNormal = Either<NonNegativeLengthPercentage, Normal>;
|
||||||
|
|
||||||
|
/// Either a non-negative `<length>` or a `<number>`.
|
||||||
|
pub type NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
|
||||||
|
|
||||||
/// A type for possible values for min- and max- flavors of width, height,
|
/// A type for possible values for min- and max- flavors of width, height,
|
||||||
/// block-size, and inline-size.
|
/// block-size, and inline-size.
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
|
||||||
pub use self::gecko::ScrollSnapPoint;
|
pub use self::gecko::ScrollSnapPoint;
|
||||||
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
|
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
|
||||||
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength};
|
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength};
|
||||||
pub use self::length::{Length, LengthOrNumber, LengthPercentage};
|
pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber};
|
||||||
pub use self::length::{LengthPercentageOrAuto, MaxSize, Size};
|
pub use self::length::{LengthPercentageOrAuto, MaxSize, Size};
|
||||||
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
|
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -71,13 +71,13 @@ pub use self::motion::OffsetPath;
|
||||||
pub use self::outline::OutlineStyle;
|
pub use self::outline::OutlineStyle;
|
||||||
pub use self::percentage::{NonNegativePercentage, Percentage};
|
pub use self::percentage::{NonNegativePercentage, Percentage};
|
||||||
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position, ZIndex};
|
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position, ZIndex};
|
||||||
pub use self::rect::LengthOrNumberRect;
|
pub use self::rect::NonNegativeLengthOrNumberRect;
|
||||||
pub use self::resolution::Resolution;
|
pub use self::resolution::Resolution;
|
||||||
pub use self::svg::MozContextProperties;
|
pub use self::svg::MozContextProperties;
|
||||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||||
pub use self::table::XSpan;
|
pub use self::table::XSpan;
|
||||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize};
|
pub use self::text::{InitialLetter, LetterSpacing, LineHeight};
|
||||||
pub use self::text::{OverflowWrap, TextOverflow, WordSpacing};
|
pub use self::text::{OverflowWrap, TextOverflow, WordSpacing};
|
||||||
pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle};
|
pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle};
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
|
@ -536,6 +536,7 @@ impl From<GreaterThanOrEqualToOneNumber> for CSSFloat {
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
#[repr(C, u8)]
|
||||||
pub enum NumberOrPercentage {
|
pub enum NumberOrPercentage {
|
||||||
Percentage(Percentage),
|
Percentage(Percentage),
|
||||||
Number(Number),
|
Number(Number),
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
//! Computed types for CSS borders.
|
//! Computed types for CSS borders.
|
||||||
|
|
||||||
use crate::values::computed::length::LengthOrNumber;
|
use crate::values::computed::length::NonNegativeLengthOrNumber;
|
||||||
use crate::values::generics::rect::Rect;
|
use crate::values::generics::rect::Rect;
|
||||||
|
|
||||||
/// A specified rectangle made of four `<length-or-number>` values.
|
/// A specified rectangle made of four `<length-or-number>` values.
|
||||||
pub type LengthOrNumberRect = Rect<LengthOrNumber>;
|
pub type NonNegativeLengthOrNumberRect = Rect<NonNegativeLengthOrNumber>;
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::values::computed::length::{Length, LengthPercentage};
|
||||||
use crate::values::computed::{NonNegativeLength, NonNegativeNumber};
|
use crate::values::computed::{NonNegativeLength, NonNegativeNumber};
|
||||||
use crate::values::generics::text::InitialLetter as GenericInitialLetter;
|
use crate::values::generics::text::InitialLetter as GenericInitialLetter;
|
||||||
use crate::values::generics::text::LineHeight as GenericLineHeight;
|
use crate::values::generics::text::LineHeight as GenericLineHeight;
|
||||||
use crate::values::generics::text::MozTabSize as GenericMozTabSize;
|
|
||||||
use crate::values::generics::text::Spacing;
|
use crate::values::generics::text::Spacing;
|
||||||
use crate::values::specified::text::TextOverflowSide;
|
use crate::values::specified::text::TextOverflowSide;
|
||||||
use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
|
use crate::values::specified::text::{TextEmphasisFillMode, TextEmphasisShapeKeyword};
|
||||||
|
@ -124,9 +123,6 @@ impl TextDecorationsInEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified value for the `-moz-tab-size` property.
|
|
||||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
|
||||||
|
|
||||||
/// computed value for the text-emphasis-style property
|
/// computed value for the text-emphasis-style property
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
pub enum TextEmphasisStyle {
|
pub enum TextEmphasisStyle {
|
||||||
|
|
|
@ -26,7 +26,8 @@ pub enum BorderImageSideWidth<LengthPercentage, Number> {
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss,
|
Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss,
|
||||||
)]
|
)]
|
||||||
pub struct BorderImageSlice<NumberOrPercentage> {
|
#[repr(C)]
|
||||||
|
pub struct GenericBorderImageSlice<NumberOrPercentage> {
|
||||||
/// The offsets.
|
/// The offsets.
|
||||||
#[css(field_bound)]
|
#[css(field_bound)]
|
||||||
pub offsets: Rect<NumberOrPercentage>,
|
pub offsets: Rect<NumberOrPercentage>,
|
||||||
|
@ -35,6 +36,8 @@ pub struct BorderImageSlice<NumberOrPercentage> {
|
||||||
pub fill: bool,
|
pub fill: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::GenericBorderImageSlice as BorderImageSlice;
|
||||||
|
|
||||||
/// A generic value for the `border-*-radius` longhand properties.
|
/// A generic value for the `border-*-radius` longhand properties.
|
||||||
#[derive(
|
#[derive(
|
||||||
Animate,
|
Animate,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::parser::{Parse, ParserContext};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use crate::values::computed::ExtremumLength;
|
use crate::values::computed::ExtremumLength;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
use num_traits::Zero;
|
||||||
use style_traits::ParseError;
|
use style_traits::ParseError;
|
||||||
|
|
||||||
/// A `<length-percentage> | auto` value.
|
/// A `<length-percentage> | auto` value.
|
||||||
|
@ -155,3 +156,53 @@ impl<LengthPercentage> MaxSize<LengthPercentage> {
|
||||||
MaxSize::None
|
MaxSize::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A generic `<length>` | `<number>` value for the `-moz-tab-size` property.
|
||||||
|
#[derive(
|
||||||
|
Animate,
|
||||||
|
Clone,
|
||||||
|
ComputeSquaredDistance,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
SpecifiedValueInfo,
|
||||||
|
ToAnimatedValue,
|
||||||
|
ToAnimatedZero,
|
||||||
|
ToComputedValue,
|
||||||
|
ToCss,
|
||||||
|
)]
|
||||||
|
#[repr(C, u8)]
|
||||||
|
pub enum GenericLengthOrNumber<L, N> {
|
||||||
|
/// A length.
|
||||||
|
Length(L),
|
||||||
|
/// A number.
|
||||||
|
Number(N),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use self::GenericLengthOrNumber as LengthOrNumber;
|
||||||
|
|
||||||
|
impl<L: Parse, N: Parse> Parse for LengthOrNumber<L, N> {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
if let Ok(number) = input.try(|i| N::parse(context, i)) {
|
||||||
|
// Numbers need to be parsed first because `0` must be recognised
|
||||||
|
// as the number `0` and not the length `0px`.
|
||||||
|
return Ok(LengthOrNumber::Number(number));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(LengthOrNumber::Length(L::parse(context, input)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<L, N> LengthOrNumber<L, N> {
|
||||||
|
/// Returns `0`.
|
||||||
|
pub fn zero() -> Self
|
||||||
|
where
|
||||||
|
N: Zero,
|
||||||
|
{
|
||||||
|
LengthOrNumber::Number(num_traits::Zero::zero())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ use super::CustomIdent;
|
||||||
use crate::counter_style::{parse_counter_style_name, Symbols};
|
use crate::counter_style::{parse_counter_style_name, Symbols};
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
|
use num_traits::Zero;
|
||||||
|
use std::ops::Add;
|
||||||
use style_traits::{KeywordsCollectFn, ParseError};
|
use style_traits::{KeywordsCollectFn, ParseError};
|
||||||
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind};
|
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind};
|
||||||
|
|
||||||
|
@ -177,6 +179,24 @@ impl SpecifiedValueInfo for CounterStyleOrNone {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct NonNegative<T>(pub T);
|
pub struct NonNegative<T>(pub T);
|
||||||
|
|
||||||
|
impl <T: Add<Output = T>> Add<NonNegative<T>> for NonNegative<T> {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn add(self, other: Self) -> Self {
|
||||||
|
NonNegative(self.0 + other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <T: Zero> Zero for NonNegative<T> {
|
||||||
|
fn is_zero(&self) -> bool {
|
||||||
|
self.0.is_zero()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn zero() -> Self {
|
||||||
|
NonNegative(T::zero())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A wrapper of greater-than-or-equal-to-one values.
|
/// A wrapper of greater-than-or-equal-to-one values.
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
|
@ -149,25 +149,3 @@ impl<N, L> LineHeight<N, L> {
|
||||||
LineHeight::Normal
|
LineHeight::Normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic value for the `-moz-tab-size` property.
|
|
||||||
#[derive(
|
|
||||||
Animate,
|
|
||||||
Clone,
|
|
||||||
ComputeSquaredDistance,
|
|
||||||
Copy,
|
|
||||||
Debug,
|
|
||||||
MallocSizeOf,
|
|
||||||
PartialEq,
|
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToAnimatedValue,
|
|
||||||
ToAnimatedZero,
|
|
||||||
ToComputedValue,
|
|
||||||
ToCss,
|
|
||||||
)]
|
|
||||||
pub enum MozTabSize<Number, Length> {
|
|
||||||
/// A number.
|
|
||||||
Number(Number),
|
|
||||||
/// A length.
|
|
||||||
Length(Length),
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,9 +11,10 @@ use crate::font_metrics::FontMetricsQueryResult;
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::values::computed::{self, CSSPixelLength, Context};
|
use crate::values::computed::{self, CSSPixelLength, Context};
|
||||||
use crate::values::generics::length as generics;
|
use crate::values::generics::length as generics;
|
||||||
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize};
|
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize, GenericLengthOrNumber};
|
||||||
use crate::values::generics::transform::IsZeroLength;
|
use crate::values::generics::transform::IsZeroLength;
|
||||||
use crate::values::generics::NonNegative;
|
use crate::values::generics::NonNegative;
|
||||||
|
use crate::values::specified::NonNegativeNumber;
|
||||||
use crate::values::specified::calc::CalcNode;
|
use crate::values::specified::calc::CalcNode;
|
||||||
use crate::values::{Auto, CSSFloat, Either, Normal};
|
use crate::values::{Auto, CSSFloat, Either, Normal};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -1023,30 +1024,7 @@ pub type LengthOrNormal = Either<Length, Normal>;
|
||||||
pub type LengthOrAuto = Either<Length, Auto>;
|
pub type LengthOrAuto = Either<Length, Auto>;
|
||||||
|
|
||||||
/// Either a `<length>` or a `<number>`.
|
/// Either a `<length>` or a `<number>`.
|
||||||
pub type LengthOrNumber = Either<Length, Number>;
|
pub type LengthOrNumber = GenericLengthOrNumber<Length, Number>;
|
||||||
|
|
||||||
impl LengthOrNumber {
|
|
||||||
/// Parse a non-negative LengthOrNumber.
|
|
||||||
pub fn parse_non_negative<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
// We try to parse as a Number first because, for cases like
|
|
||||||
// LengthOrNumber, we want "0" to be parsed as a plain Number rather
|
|
||||||
// than a Length (0px); this matches the behaviour of all major browsers
|
|
||||||
if let Ok(v) = input.try(|i| Number::parse_non_negative(context, i)) {
|
|
||||||
return Ok(Either::Second(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
Length::parse_non_negative(context, input).map(Either::First)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `0`.
|
|
||||||
#[inline]
|
|
||||||
pub fn zero() -> Self {
|
|
||||||
Either::Second(Number::new(0.))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A specified value for `min-width`, `min-height`, `width` or `height` property.
|
/// A specified value for `min-width`, `min-height`, `width` or `height` property.
|
||||||
pub type Size = GenericSize<NonNegativeLengthPercentage>;
|
pub type Size = GenericSize<NonNegativeLengthPercentage>;
|
||||||
|
@ -1123,3 +1101,6 @@ impl MaxSize {
|
||||||
Ok(GenericMaxSize::LengthPercentage(length))
|
Ok(GenericMaxSize::LengthPercentage(length))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A specified non-negative `<length>` | `<number>`.
|
||||||
|
pub type NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
|
||||||
|
|
|
@ -19,8 +19,9 @@ use crate::values::serialize_atom_identifier;
|
||||||
use crate::values::specified::calc::CalcNode;
|
use crate::values::specified::calc::CalcNode;
|
||||||
use crate::{Atom, Namespace, Prefix};
|
use crate::{Atom, Namespace, Prefix};
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
use num_traits::One;
|
use num_traits::{Zero, One};
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
use std::ops::Add;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||||
|
@ -58,7 +59,7 @@ pub use self::gecko::ScrollSnapPoint;
|
||||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
||||||
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
||||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
pub use self::length::{FontRelativeLength, Length, LengthOrNumber, NonNegativeLengthOrNumber};
|
||||||
pub use self::length::{LengthPercentage, LengthPercentageOrAuto};
|
pub use self::length::{LengthPercentage, LengthPercentageOrAuto};
|
||||||
pub use self::length::{MaxSize, Size};
|
pub use self::length::{MaxSize, Size};
|
||||||
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
||||||
|
@ -71,14 +72,14 @@ pub use self::outline::OutlineStyle;
|
||||||
pub use self::percentage::Percentage;
|
pub use self::percentage::Percentage;
|
||||||
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position};
|
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position};
|
||||||
pub use self::position::{PositionComponent, ZIndex};
|
pub use self::position::{PositionComponent, ZIndex};
|
||||||
pub use self::rect::LengthOrNumberRect;
|
pub use self::rect::NonNegativeLengthOrNumberRect;
|
||||||
pub use self::resolution::Resolution;
|
pub use self::resolution::Resolution;
|
||||||
pub use self::svg::MozContextProperties;
|
pub use self::svg::MozContextProperties;
|
||||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||||
pub use self::svg_path::SVGPathData;
|
pub use self::svg_path::SVGPathData;
|
||||||
pub use self::table::XSpan;
|
pub use self::table::XSpan;
|
||||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign};
|
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextAlign};
|
||||||
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle};
|
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle};
|
||||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||||
pub use self::time::Time;
|
pub use self::time::Time;
|
||||||
|
@ -271,6 +272,26 @@ impl IsParallelTo for (Number, Number, Number) {
|
||||||
|
|
||||||
impl SpecifiedValueInfo for Number {}
|
impl SpecifiedValueInfo for Number {}
|
||||||
|
|
||||||
|
impl Add for Number {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn add(self, other: Self) -> Self {
|
||||||
|
Self::new(self.get() + other.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Zero for Number {
|
||||||
|
#[inline]
|
||||||
|
fn zero() -> Self {
|
||||||
|
Self::new(0.)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_zero(&self) -> bool {
|
||||||
|
self.get() == 0.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Number> for f32 {
|
impl From<Number> for f32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(n: Number) -> Self {
|
fn from(n: Number) -> Self {
|
||||||
|
|
|
@ -4,22 +4,8 @@
|
||||||
|
|
||||||
//! Specified types for CSS borders.
|
//! Specified types for CSS borders.
|
||||||
|
|
||||||
use crate::parser::ParserContext;
|
|
||||||
use crate::values::generics::rect::Rect;
|
use crate::values::generics::rect::Rect;
|
||||||
use crate::values::specified::length::LengthOrNumber;
|
use crate::values::specified::length::NonNegativeLengthOrNumber;
|
||||||
use cssparser::Parser;
|
|
||||||
use style_traits::ParseError;
|
|
||||||
|
|
||||||
/// A specified rectangle made of four `<length-or-number>` values.
|
/// A specified rectangle made of four `<length-or-number>` values.
|
||||||
pub type LengthOrNumberRect = Rect<LengthOrNumber>;
|
pub type NonNegativeLengthOrNumberRect = Rect<NonNegativeLengthOrNumber>;
|
||||||
|
|
||||||
impl LengthOrNumberRect {
|
|
||||||
/// Parses a `LengthOrNumberRect`, rejecting negative values.
|
|
||||||
#[inline]
|
|
||||||
pub fn parse_non_negative<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
Rect::parse_with(context, input, LengthOrNumber::parse_non_negative)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,11 +13,10 @@ use crate::values::computed::text::TextOverflow as ComputedTextOverflow;
|
||||||
use crate::values::computed::{Context, ToComputedValue};
|
use crate::values::computed::{Context, ToComputedValue};
|
||||||
use crate::values::generics::text::InitialLetter as GenericInitialLetter;
|
use crate::values::generics::text::InitialLetter as GenericInitialLetter;
|
||||||
use crate::values::generics::text::LineHeight as GenericLineHeight;
|
use crate::values::generics::text::LineHeight as GenericLineHeight;
|
||||||
use crate::values::generics::text::MozTabSize as GenericMozTabSize;
|
|
||||||
use crate::values::generics::text::Spacing;
|
use crate::values::generics::text::Spacing;
|
||||||
use crate::values::specified::length::{FontRelativeLength, Length};
|
use crate::values::specified::length::{FontRelativeLength, Length};
|
||||||
use crate::values::specified::length::{LengthPercentage, NoCalcLength};
|
use crate::values::specified::length::{LengthPercentage, NoCalcLength};
|
||||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
|
use crate::values::specified::length::{NonNegativeLengthPercentage};
|
||||||
use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number};
|
use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number};
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
|
@ -835,25 +834,6 @@ impl From<TextEmphasisPosition> for u8 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified value for the `-moz-tab-size` property.
|
|
||||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
|
||||||
|
|
||||||
impl Parse for MozTabSize {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) {
|
|
||||||
// Numbers need to be parsed first because `0` must be recognised
|
|
||||||
// as the number `0` and not the length `0px`.
|
|
||||||
return Ok(GenericMozTabSize::Number(number));
|
|
||||||
}
|
|
||||||
Ok(GenericMozTabSize::Length(NonNegativeLength::parse(
|
|
||||||
context, input,
|
|
||||||
)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Values for the `overflow-wrap` property.
|
/// Values for the `overflow-wrap` property.
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue