mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement parsing/serialization for caret-color
This commit is contained in:
parent
d8a8e3e42e
commit
a2074f2653
5 changed files with 57 additions and 2 deletions
|
@ -29,11 +29,12 @@ use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use super::ComputedValues;
|
use super::ComputedValues;
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use values::Either;
|
use values::{Auto, Either};
|
||||||
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
||||||
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone};
|
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone};
|
||||||
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
|
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
|
||||||
use values::computed::{MaxLength, MinLength};
|
use values::computed::{MaxLength, MinLength};
|
||||||
|
use values::computed::ColorOrAuto;
|
||||||
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
|
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
|
||||||
use values::computed::ToComputedValue;
|
use values::computed::ToComputedValue;
|
||||||
use values::specified::Angle as SpecifiedAngle;
|
use values::specified::Angle as SpecifiedAngle;
|
||||||
|
@ -1796,3 +1797,21 @@ impl Interpolate for TransformList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-transitions-1/#animtype-color
|
||||||
|
impl Interpolate for ColorOrAuto {
|
||||||
|
#[inline]
|
||||||
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
|
match (*self, *other) {
|
||||||
|
(Either::First(ref this), Either::First(ref other)) => {
|
||||||
|
this.interpolate(&other, progress).map(Either::First)
|
||||||
|
},
|
||||||
|
(Either::Second(Auto), Either::Second(Auto)) => {
|
||||||
|
Ok(Either::Second(Auto))
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
let interpolated = if progress < 0.5 { *self } else { *other };
|
||||||
|
Ok(interpolated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,3 +30,10 @@ ${helpers.single_keyword("-moz-window-dragging", "default drag no-drag", product
|
||||||
gecko_enum_prefix="StyleWindowDragging",
|
gecko_enum_prefix="StyleWindowDragging",
|
||||||
animatable=False,
|
animatable=False,
|
||||||
spec="None (Nonstandard Firefox-only property)")}
|
spec="None (Nonstandard Firefox-only property)")}
|
||||||
|
|
||||||
|
${helpers.predefined_type("caret-color",
|
||||||
|
"ColorOrAuto",
|
||||||
|
"Either::Second(Auto)",
|
||||||
|
spec="https://drafts.csswg.org/css-ui/#caret-color",
|
||||||
|
animatable="True",
|
||||||
|
products="none")}
|
||||||
|
|
|
@ -363,3 +363,6 @@ impl ClipRectOrAuto {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <color> | auto
|
||||||
|
pub type ColorOrAuto = Either<CSSColor, Auto>;
|
||||||
|
|
|
@ -998,3 +998,6 @@ impl Parse for ClipRect {
|
||||||
|
|
||||||
/// rect(...) | auto
|
/// rect(...) | auto
|
||||||
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
|
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
|
||||||
|
|
||||||
|
/// <color> | auto
|
||||||
|
pub type ColorOrAuto = Either<CSSColor, Auto>;
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::{Color, Parser, RGBA};
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use style::parser::ParserContext;
|
use style::parser::ParserContext;
|
||||||
use style::stylesheets::Origin;
|
use style::stylesheets::Origin;
|
||||||
|
use style::values::{Auto, Either};
|
||||||
|
use style::values::specified::CSSColor;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -30,3 +32,24 @@ fn test_moz_user_select() {
|
||||||
let mut negative = Parser::new("potato");
|
let mut negative = Parser::new("potato");
|
||||||
assert!(_moz_user_select::parse(&context, &mut negative).is_err());
|
assert!(_moz_user_select::parse(&context, &mut negative).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_caret_color() {
|
||||||
|
use style::properties::longhands::caret_color;
|
||||||
|
|
||||||
|
let auto = parse_longhand!(caret_color, "auto");
|
||||||
|
assert_eq!(auto, Either::Second(Auto));
|
||||||
|
|
||||||
|
let blue_color = CSSColor {
|
||||||
|
parsed: Color::RGBA(RGBA {
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 255,
|
||||||
|
alpha: 255,
|
||||||
|
}),
|
||||||
|
authored: Some(String::from("blue").into_boxed_str()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let color = parse_longhand!(caret_color, "blue");
|
||||||
|
assert_eq!(color, Either::First(blue_color));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue