mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #19002 - emilio:kill-more-mako, r=jdm
style: Move background-repeat and mask-repeat outside of mako. <!-- 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/19002) <!-- Reviewable:end -->
This commit is contained in:
commit
347176df25
16 changed files with 173 additions and 147 deletions
|
@ -48,7 +48,7 @@ use std::default::Default;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::computed_values::{background_attachment, background_clip, background_origin};
|
use style::computed_values::{background_attachment, background_clip, background_origin};
|
||||||
use style::computed_values::{background_repeat, border_style, cursor};
|
use style::computed_values::{border_style, cursor};
|
||||||
use style::computed_values::{image_rendering, overflow_x, pointer_events, position, visibility};
|
use style::computed_values::{image_rendering, overflow_x, pointer_events, position, visibility};
|
||||||
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
|
use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode};
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
|
@ -66,6 +66,7 @@ use style::values::generics::image::{Circle, Ellipse, EndingShape as GenericEndi
|
||||||
use style::values::generics::image::{GradientItem as GenericGradientItem, GradientKind};
|
use style::values::generics::image::{GradientItem as GenericGradientItem, GradientKind};
|
||||||
use style::values::generics::image::{Image, ShapeExtent};
|
use style::values::generics::image::{Image, ShapeExtent};
|
||||||
use style::values::generics::image::PaintWorklet;
|
use style::values::generics::image::PaintWorklet;
|
||||||
|
use style::values::specified::background::RepeatKeyword as BackgroundRepeatKeyword;
|
||||||
use style::values::specified::position::{X, Y};
|
use style::values::specified::position::{X, Y};
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
@ -1186,17 +1187,17 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
// Adjust origin and size based on background-repeat
|
// Adjust origin and size based on background-repeat
|
||||||
let background_repeat = get_cyclic(&background.background_repeat.0, index);
|
let background_repeat = get_cyclic(&background.background_repeat.0, index);
|
||||||
match background_repeat.0 {
|
match background_repeat.0 {
|
||||||
background_repeat::single_value::RepeatKeyword::NoRepeat => {
|
BackgroundRepeatKeyword::NoRepeat => {
|
||||||
bounds.origin.x = anchor_origin_x;
|
bounds.origin.x = anchor_origin_x;
|
||||||
bounds.size.width = image_size.width;
|
bounds.size.width = image_size.width;
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Repeat => {
|
BackgroundRepeatKeyword::Repeat => {
|
||||||
ImageFragmentInfo::tile_image(&mut bounds.origin.x,
|
ImageFragmentInfo::tile_image(&mut bounds.origin.x,
|
||||||
&mut bounds.size.width,
|
&mut bounds.size.width,
|
||||||
anchor_origin_x,
|
anchor_origin_x,
|
||||||
image_size.width);
|
image_size.width);
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Space => {
|
BackgroundRepeatKeyword::Space => {
|
||||||
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.x,
|
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.x,
|
||||||
&mut bounds.size.width,
|
&mut bounds.size.width,
|
||||||
&mut tile_spacing.width,
|
&mut tile_spacing.width,
|
||||||
|
@ -1204,7 +1205,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
image_size.width);
|
image_size.width);
|
||||||
|
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Round => {
|
BackgroundRepeatKeyword::Round => {
|
||||||
ImageFragmentInfo::tile_image_round(&mut bounds.origin.x,
|
ImageFragmentInfo::tile_image_round(&mut bounds.origin.x,
|
||||||
&mut bounds.size.width,
|
&mut bounds.size.width,
|
||||||
anchor_origin_x,
|
anchor_origin_x,
|
||||||
|
@ -1212,17 +1213,17 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match background_repeat.1 {
|
match background_repeat.1 {
|
||||||
background_repeat::single_value::RepeatKeyword::NoRepeat => {
|
BackgroundRepeatKeyword::NoRepeat => {
|
||||||
bounds.origin.y = anchor_origin_y;
|
bounds.origin.y = anchor_origin_y;
|
||||||
bounds.size.height = image_size.height;
|
bounds.size.height = image_size.height;
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Repeat => {
|
BackgroundRepeatKeyword::Repeat => {
|
||||||
ImageFragmentInfo::tile_image(&mut bounds.origin.y,
|
ImageFragmentInfo::tile_image(&mut bounds.origin.y,
|
||||||
&mut bounds.size.height,
|
&mut bounds.size.height,
|
||||||
anchor_origin_y,
|
anchor_origin_y,
|
||||||
image_size.height);
|
image_size.height);
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Space => {
|
BackgroundRepeatKeyword::Space => {
|
||||||
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.y,
|
ImageFragmentInfo::tile_image_spaced(&mut bounds.origin.y,
|
||||||
&mut bounds.size.height,
|
&mut bounds.size.height,
|
||||||
&mut tile_spacing.height,
|
&mut tile_spacing.height,
|
||||||
|
@ -1230,7 +1231,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
image_size.height);
|
image_size.height);
|
||||||
|
|
||||||
}
|
}
|
||||||
background_repeat::single_value::RepeatKeyword::Round => {
|
BackgroundRepeatKeyword::Round => {
|
||||||
ImageFragmentInfo::tile_image_round(&mut bounds.origin.y,
|
ImageFragmentInfo::tile_image_round(&mut bounds.origin.y,
|
||||||
&mut bounds.size.height,
|
&mut bounds.size.height,
|
||||||
anchor_origin_y,
|
anchor_origin_y,
|
||||||
|
|
|
@ -3659,7 +3659,7 @@ fn static_assert() {
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%self:simple_image_array_property name="repeat" shorthand="${shorthand}" field_name="mRepeat">
|
<%self:simple_image_array_property name="repeat" shorthand="${shorthand}" field_name="mRepeat">
|
||||||
use properties::longhands::${shorthand}_repeat::single_value::computed_value::RepeatKeyword;
|
use values::specified::background::RepeatKeyword;
|
||||||
use gecko_bindings::structs::nsStyleImageLayers_Repeat;
|
use gecko_bindings::structs::nsStyleImageLayers_Repeat;
|
||||||
use gecko_bindings::structs::StyleImageLayerRepeat;
|
use gecko_bindings::structs::StyleImageLayerRepeat;
|
||||||
|
|
||||||
|
@ -3682,7 +3682,7 @@ fn static_assert() {
|
||||||
|
|
||||||
pub fn clone_${shorthand}_repeat(&self) -> longhands::${shorthand}_repeat::computed_value::T {
|
pub fn clone_${shorthand}_repeat(&self) -> longhands::${shorthand}_repeat::computed_value::T {
|
||||||
use properties::longhands::${shorthand}_repeat::single_value::computed_value::T;
|
use properties::longhands::${shorthand}_repeat::single_value::computed_value::T;
|
||||||
use properties::longhands::${shorthand}_repeat::single_value::computed_value::RepeatKeyword;
|
use values::specified::background::RepeatKeyword;
|
||||||
use gecko_bindings::structs::StyleImageLayerRepeat;
|
use gecko_bindings::structs::StyleImageLayerRepeat;
|
||||||
|
|
||||||
fn to_servo(repeat: StyleImageLayerRepeat) -> RepeatKeyword {
|
fn to_servo(repeat: StyleImageLayerRepeat) -> RepeatKeyword {
|
||||||
|
|
|
@ -439,7 +439,7 @@
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
|
|
||||||
use style_traits::{ToCss, ParseError};
|
use style_traits::ParseError;
|
||||||
define_css_keyword_enum! { T:
|
define_css_keyword_enum! { T:
|
||||||
% for value in keyword.values_for(product):
|
% for value in keyword.values_for(product):
|
||||||
"${value}" => ${to_rust_ident(value)},
|
"${value}" => ${to_rust_ident(value)},
|
||||||
|
@ -614,7 +614,6 @@
|
||||||
|
|
||||||
<%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)">
|
<%def name="inner_body(keyword, extra_specified=None, needs_conversion=False)">
|
||||||
% if extra_specified or keyword.aliases_for(product):
|
% if extra_specified or keyword.aliases_for(product):
|
||||||
use style_traits::ToCss;
|
|
||||||
define_css_keyword_enum! { SpecifiedValue:
|
define_css_keyword_enum! { SpecifiedValue:
|
||||||
values {
|
values {
|
||||||
% for value in keyword.values_for(product) + (extra_specified or "").split():
|
% for value in keyword.values_for(product) + (extra_specified or "").split():
|
||||||
|
@ -631,7 +630,6 @@
|
||||||
pub use self::computed_value::T as SpecifiedValue;
|
pub use self::computed_value::T as SpecifiedValue;
|
||||||
% endif
|
% endif
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use style_traits::ToCss;
|
|
||||||
define_css_keyword_enum! { T:
|
define_css_keyword_enum! { T:
|
||||||
% for value in data.longhands_by_name[name].keyword.values_for(product):
|
% for value in data.longhands_by_name[name].keyword.values_for(product):
|
||||||
"${value}" => ${to_rust_ident(value)},
|
"${value}" => ${to_rust_ident(value)},
|
||||||
|
|
|
@ -40,101 +40,16 @@ ${helpers.predefined_type("background-image", "ImageLayer",
|
||||||
)}
|
)}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
<%helpers:vector_longhand name="background-repeat" animation_value_type="discrete"
|
${helpers.predefined_type(
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat"
|
"background-repeat",
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER">
|
"BackgroundRepeat",
|
||||||
use std::fmt;
|
"computed::BackgroundRepeat::repeat()",
|
||||||
use style_traits::ToCss;
|
initial_specified_value="specified::BackgroundRepeat::repeat()",
|
||||||
|
animation_value_type="discrete",
|
||||||
define_css_keyword_enum!(RepeatKeyword:
|
vector=True,
|
||||||
"repeat" => Repeat,
|
spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat",
|
||||||
"space" => Space,
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
"round" => Round,
|
)}
|
||||||
"no-repeat" => NoRepeat);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
|
||||||
pub enum SpecifiedValue {
|
|
||||||
RepeatX,
|
|
||||||
RepeatY,
|
|
||||||
Other(RepeatKeyword, Option<RepeatKeyword>),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
pub use super::RepeatKeyword;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub struct T(pub RepeatKeyword, pub RepeatKeyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match (self.0, self.1) {
|
|
||||||
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"),
|
|
||||||
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"),
|
|
||||||
(horizontal, vertical) => {
|
|
||||||
horizontal.to_css(dest)?;
|
|
||||||
if horizontal != vertical {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
vertical.to_css(dest)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::Repeat)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
SpecifiedValue::Other(RepeatKeyword::Repeat, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
|
||||||
type ComputedValue = computed_value::T;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
|
||||||
match *self {
|
|
||||||
SpecifiedValue::RepeatX =>
|
|
||||||
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat),
|
|
||||||
SpecifiedValue::RepeatY =>
|
|
||||||
computed_value::T(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat),
|
|
||||||
SpecifiedValue::Other(horizontal, vertical) =>
|
|
||||||
computed_value::T(horizontal, vertical.unwrap_or(horizontal))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
|
||||||
match (computed.0, computed.1) {
|
|
||||||
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => SpecifiedValue::RepeatX,
|
|
||||||
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => SpecifiedValue::RepeatY,
|
|
||||||
(horizontal, vertical) => SpecifiedValue::Other(horizontal, Some(vertical)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
|
||||||
let ident = input.expect_ident_cloned()?;
|
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"repeat-x" => Ok(SpecifiedValue::RepeatX),
|
|
||||||
"repeat-y" => Ok(SpecifiedValue::RepeatY),
|
|
||||||
_ => Err(()),
|
|
||||||
}).or_else(|()| {
|
|
||||||
let horizontal: Result<_, ParseError> = RepeatKeyword::from_ident(&ident)
|
|
||||||
.map_err(|()| input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
|
|
||||||
let horizontal = horizontal?;
|
|
||||||
let vertical = input.try(RepeatKeyword::parse).ok();
|
|
||||||
Ok(SpecifiedValue::Other(horizontal, vertical))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
|
||||||
|
|
||||||
${helpers.single_keyword("background-attachment",
|
${helpers.single_keyword("background-attachment",
|
||||||
"scroll fixed" + (" local" if product == "gecko" else ""),
|
"scroll fixed" + (" local" if product == "gecko" else ""),
|
||||||
|
|
|
@ -222,9 +222,6 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
|
||||||
<%helpers:longhand name="border-image-repeat" animation_value_type="discrete"
|
<%helpers:longhand name="border-image-repeat" animation_value_type="discrete"
|
||||||
flags="APPLIES_TO_FIRST_LETTER"
|
flags="APPLIES_TO_FIRST_LETTER"
|
||||||
spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat">
|
spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat">
|
||||||
use style_traits::ToCss;
|
|
||||||
|
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
pub use super::RepeatKeyword;
|
pub use super::RepeatKeyword;
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ ${helpers.single_keyword("text-align-last",
|
||||||
flags="APPLIES_TO_PLACEHOLDER"
|
flags="APPLIES_TO_PLACEHOLDER"
|
||||||
spec="https://drafts.csswg.org/css-text/#propdef-text-align">
|
spec="https://drafts.csswg.org/css-text/#propdef-text-align">
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use style_traits::ToCss;
|
|
||||||
macro_rules! define_text_align {
|
macro_rules! define_text_align {
|
||||||
( $( $name: ident ( $string: expr ) => $discriminant: expr, )+ ) => {
|
( $( $name: ident ( $string: expr ) => $discriminant: expr, )+ ) => {
|
||||||
define_css_keyword_enum! { T:
|
define_css_keyword_enum! { T:
|
||||||
|
@ -584,8 +583,6 @@ ${helpers.predefined_type(
|
||||||
|
|
||||||
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
|
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
|
||||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
|
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
|
||||||
use style_traits::ToCss;
|
|
||||||
|
|
||||||
define_css_keyword_enum!(HorizontalWritingModeValue:
|
define_css_keyword_enum!(HorizontalWritingModeValue:
|
||||||
"over" => Over,
|
"over" => Over,
|
||||||
"under" => Under);
|
"under" => Under);
|
||||||
|
|
|
@ -81,23 +81,17 @@ ${helpers.single_keyword("mask-mode",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-mode")}
|
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-mode")}
|
||||||
|
|
||||||
<%helpers:vector_longhand name="mask-repeat" products="gecko" animation_value_type="discrete" extra_prefixes="webkit"
|
${helpers.predefined_type(
|
||||||
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat">
|
"mask-repeat",
|
||||||
pub use properties::longhands::background_repeat::single_value::parse;
|
"BackgroundRepeat",
|
||||||
pub use properties::longhands::background_repeat::single_value::SpecifiedValue;
|
"computed::BackgroundRepeat::repeat()",
|
||||||
pub use properties::longhands::background_repeat::single_value::computed_value;
|
initial_specified_value="specified::BackgroundRepeat::repeat()",
|
||||||
pub use properties::longhands::background_repeat::single_value::RepeatKeyword;
|
products="gecko",
|
||||||
|
extra_prefixes="webkit",
|
||||||
#[inline]
|
animation_value_type="discrete",
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-repeat",
|
||||||
computed_value::T(RepeatKeyword::Repeat, RepeatKeyword::Repeat)
|
vector=True,
|
||||||
}
|
)}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
SpecifiedValue::Other(RepeatKeyword::Repeat, None)
|
|
||||||
}
|
|
||||||
</%helpers:vector_longhand>
|
|
||||||
|
|
||||||
% for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]:
|
% for (axis, direction) in [("x", "Horizontal"), ("y", "Vertical")]:
|
||||||
${helpers.predefined_type(
|
${helpers.predefined_type(
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
|
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
|
||||||
use cssparser::{CowRcStr, ToCss as ParserToCss};
|
use cssparser::CowRcStr;
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||||
use euclid::TypedSize2D;
|
use euclid::TypedSize2D;
|
||||||
use font_metrics::get_metrics_provider_for_product;
|
use font_metrics::get_metrics_provider_for_product;
|
||||||
|
|
|
@ -6,9 +6,13 @@
|
||||||
|
|
||||||
use properties::animated_properties::RepeatableListAnimatable;
|
use properties::animated_properties::RepeatableListAnimatable;
|
||||||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||||
|
use std::fmt;
|
||||||
|
use style_traits::ToCss;
|
||||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||||
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::computed::length::LengthOrPercentageOrAuto;
|
use values::computed::length::LengthOrPercentageOrAuto;
|
||||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||||
|
use values::specified::background::{BackgroundRepeat as SpecifiedBackgroundRepeat, RepeatKeyword};
|
||||||
|
|
||||||
/// A computed value for the `background-size` property.
|
/// A computed value for the `background-size` property.
|
||||||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||||
|
@ -77,3 +81,72 @@ impl ToAnimatedValue for BackgroundSizeList {
|
||||||
BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0))
|
BackgroundSizeList(ToAnimatedValue::from_animated_value(animated.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The computed value of the `background-repeat` property:
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
|
pub struct BackgroundRepeat(pub RepeatKeyword, pub RepeatKeyword);
|
||||||
|
|
||||||
|
impl BackgroundRepeat {
|
||||||
|
/// Returns the `repeat repeat` value.
|
||||||
|
pub fn repeat() -> Self {
|
||||||
|
BackgroundRepeat(RepeatKeyword::Repeat, RepeatKeyword::Repeat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for BackgroundRepeat {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: fmt::Write,
|
||||||
|
{
|
||||||
|
match (self.0, self.1) {
|
||||||
|
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"),
|
||||||
|
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"),
|
||||||
|
(horizontal, vertical) => {
|
||||||
|
horizontal.to_css(dest)?;
|
||||||
|
if horizontal != vertical {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
vertical.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToComputedValue for SpecifiedBackgroundRepeat {
|
||||||
|
type ComputedValue = BackgroundRepeat;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
|
||||||
|
match *self {
|
||||||
|
SpecifiedBackgroundRepeat::RepeatX => {
|
||||||
|
BackgroundRepeat(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat)
|
||||||
|
}
|
||||||
|
SpecifiedBackgroundRepeat::RepeatY => {
|
||||||
|
BackgroundRepeat(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat)
|
||||||
|
}
|
||||||
|
SpecifiedBackgroundRepeat::Keywords(horizontal, vertical) => {
|
||||||
|
BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
|
// FIXME(emilio): Why can't this just be:
|
||||||
|
// SpecifiedBackgroundRepeat::Keywords(computed.0, computed.1)
|
||||||
|
match (computed.0, computed.1) {
|
||||||
|
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => {
|
||||||
|
SpecifiedBackgroundRepeat::RepeatX
|
||||||
|
}
|
||||||
|
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => {
|
||||||
|
SpecifiedBackgroundRepeat::RepeatY
|
||||||
|
}
|
||||||
|
(horizontal, vertical) => {
|
||||||
|
SpecifiedBackgroundRepeat::Keywords(horizontal, Some(vertical))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub use properties::animated_properties::TransitionProperty;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||||
pub use self::angle::Angle;
|
pub use self::angle::Angle;
|
||||||
pub use self::background::BackgroundSize;
|
pub use self::background::{BackgroundSize, BackgroundRepeat};
|
||||||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||||
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing};
|
||||||
pub use self::box_::VerticalAlign;
|
pub use self::box_::VerticalAlign;
|
||||||
|
|
|
@ -52,12 +52,6 @@ impl<L> Size<L> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L: Clone> From<L> for Size<L> {
|
|
||||||
fn from(size: L) -> Self {
|
|
||||||
Self::new(size.clone(), size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<L> ToCss for Size<L>
|
impl<L> ToCss for Size<L>
|
||||||
where L:
|
where L:
|
||||||
ToCss + PartialEq,
|
ToCss + PartialEq,
|
||||||
|
|
|
@ -15,7 +15,10 @@ use values::specified::length::LengthOrPercentageOrAuto;
|
||||||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||||
|
|
||||||
impl Parse for BackgroundSize {
|
impl Parse for BackgroundSize {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
|
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
|
||||||
let height = input
|
let height = input
|
||||||
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
||||||
|
@ -41,3 +44,59 @@ impl BackgroundSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One of the keywords for `background-repeat`.
|
||||||
|
define_css_keyword_enum! { RepeatKeyword:
|
||||||
|
"repeat" => Repeat,
|
||||||
|
"space" => Space,
|
||||||
|
"round" => Round,
|
||||||
|
"no-repeat" => NoRepeat
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The specified value for the `background-repeat` property.
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-backgrounds/#the-background-repeat
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
pub enum BackgroundRepeat {
|
||||||
|
/// `repeat-x`
|
||||||
|
RepeatX,
|
||||||
|
/// `repeat-y`
|
||||||
|
RepeatY,
|
||||||
|
/// `[repeat | space | round | no-repeat]{1,2}`
|
||||||
|
Keywords(RepeatKeyword, Option<RepeatKeyword>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BackgroundRepeat {
|
||||||
|
/// Returns the `repeat` value.
|
||||||
|
#[inline]
|
||||||
|
pub fn repeat() -> Self {
|
||||||
|
BackgroundRepeat::Keywords(RepeatKeyword::Repeat, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for BackgroundRepeat {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
_context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
let ident = input.expect_ident_cloned()?;
|
||||||
|
|
||||||
|
match_ignore_ascii_case! { &ident,
|
||||||
|
"repeat-x" => return Ok(BackgroundRepeat::RepeatX),
|
||||||
|
"repeat-y" => return Ok(BackgroundRepeat::RepeatY),
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
let horizontal = match RepeatKeyword::from_ident(&ident) {
|
||||||
|
Ok(h) => h,
|
||||||
|
Err(()) => {
|
||||||
|
return Err(input.new_custom_error(
|
||||||
|
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let vertical = input.try(RepeatKeyword::parse).ok();
|
||||||
|
Ok(BackgroundRepeat::Keywords(horizontal, vertical))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -46,8 +46,6 @@ pub enum Color {
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
mod gecko {
|
mod gecko {
|
||||||
use style_traits::ToCss;
|
|
||||||
|
|
||||||
define_css_keyword_enum! { SpecialColorKeyword:
|
define_css_keyword_enum! { SpecialColorKeyword:
|
||||||
"-moz-default-color" => MozDefaultColor,
|
"-moz-default-color" => MozDefaultColor,
|
||||||
"-moz-default-background-color" => MozDefaultBackgroundColor,
|
"-moz-default-background-color" => MozDefaultBackgroundColor,
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub use properties::animated_properties::TransitionProperty;
|
||||||
pub use self::angle::Angle;
|
pub use self::angle::Angle;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||||
pub use self::background::BackgroundSize;
|
pub use self::background::{BackgroundRepeat, BackgroundSize};
|
||||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing};
|
||||||
pub use self::box_::VerticalAlign;
|
pub use self::box_::VerticalAlign;
|
||||||
|
|
|
@ -472,7 +472,7 @@ macro_rules! __define_css_keyword_enum__actual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for $name {
|
impl $crate::ToCss for $name {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||||
where W: ::std::fmt::Write
|
where W: ::std::fmt::Write
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
//! Helper types for the `@viewport` rule.
|
//! Helper types for the `@viewport` rule.
|
||||||
|
|
||||||
use {CSSPixel, PinchZoomFactor, ParseError};
|
use {CSSPixel, PinchZoomFactor, ParseError, ToCss};
|
||||||
use cssparser::{Parser, ToCss};
|
use cssparser::Parser;
|
||||||
use euclid::TypedSize2D;
|
use euclid::TypedSize2D;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue