mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Simplify border-image-repeat serialization.
We're the only ones to preserve explicitly the second keyword, as noticed in: https://github.com/w3c/web-platform-tests/pull/10170
This commit is contained in:
parent
cba8b083d3
commit
68ce13aae4
2 changed files with 28 additions and 53 deletions
|
@ -6,7 +6,8 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use style_traits::ParseError;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
use values::computed::{self, Context, ToComputedValue};
|
||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
|
||||
|
@ -54,9 +55,8 @@ impl BorderSideWidth {
|
|||
pub fn parse_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>>
|
||||
{
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(length) = input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
|
||||
return Ok(BorderSideWidth::Length(length));
|
||||
}
|
||||
|
@ -186,14 +186,31 @@ pub enum BorderImageRepeatKeyword {
|
|||
/// The specified value for the `border-image-repeat` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-backgrounds/#the-border-image-repeat
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
pub struct BorderImageRepeat(pub BorderImageRepeatKeyword, pub Option<BorderImageRepeatKeyword>);
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct BorderImageRepeat(pub BorderImageRepeatKeyword, pub BorderImageRepeatKeyword);
|
||||
|
||||
impl ToCss for BorderImageRepeat {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
self.0.to_css(dest)?;
|
||||
if self.0 != self.1 {
|
||||
dest.write_str(" ")?;
|
||||
self.1.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl BorderImageRepeat {
|
||||
/// Returns the `stretch` value.
|
||||
#[inline]
|
||||
pub fn stretch() -> Self {
|
||||
BorderImageRepeat(BorderImageRepeatKeyword::Stretch, None)
|
||||
BorderImageRepeat(
|
||||
BorderImageRepeatKeyword::Stretch,
|
||||
BorderImageRepeatKeyword::Stretch,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +221,6 @@ impl Parse for BorderImageRepeat {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let horizontal = BorderImageRepeatKeyword::parse(input)?;
|
||||
let vertical = input.try(BorderImageRepeatKeyword::parse).ok();
|
||||
Ok(BorderImageRepeat(horizontal, vertical))
|
||||
Ok(BorderImageRepeat(horizontal, vertical.unwrap_or(horizontal)))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue