Add SpecifiedImageUrl for <url> used as images.

This commit is contained in:
Xidorn Quan 2018-03-08 21:31:05 +11:00
parent 14b708311b
commit a99ca543cd
18 changed files with 151 additions and 136 deletions

View file

@ -18,7 +18,7 @@ use values::generics::counters::CounterReset as GenericCounterReset;
#[cfg(feature = "gecko")]
use values::specified::Attr;
#[cfg(feature = "gecko")]
use values::specified::url::SpecifiedUrl;
use values::specified::url::SpecifiedImageUrl;
pub use values::specified::{Content, ContentItem};
/// A computed value for the `counter-increment` property.
@ -79,8 +79,7 @@ impl Parse for Content {
let mut content = vec![];
loop {
#[cfg(feature = "gecko")] {
if let Ok(mut url) = input.try(|i| SpecifiedUrl::parse(_context, i)) {
url.build_image_value();
if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(_context, i)) {
content.push(ContentItem::Url(url));
continue;
}

View file

@ -12,7 +12,8 @@ use std::f32::consts::PI;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
use values::{Either, None_};
use values::computed::{Angle, ComputedUrl, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
use values::computed::{Angle, ComputedImageUrl, Context};
use values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
#[cfg(feature = "gecko")]
use values::computed::Percentage;
use values::computed::position::Position;
@ -28,7 +29,7 @@ pub type ImageLayer = Either<None_, Image>;
/// Computed values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = GenericImage<Gradient, MozImageRect, ComputedUrl>;
pub type Image = GenericImage<Gradient, MozImageRect, ComputedImageUrl>;
/// Computed values for a CSS gradient.
/// <https://drafts.csswg.org/css-images/#gradients>
@ -76,7 +77,7 @@ pub type GradientItem = GenericGradientItem<RGBA, LengthOrPercentage>;
pub type ColorStop = GenericColorStop<RGBA, LengthOrPercentage>;
/// Computed values for `-moz-image-rect(...)`.
pub type MozImageRect = GenericMozImageRect<NumberOrPercentage, ComputedUrl>;
pub type MozImageRect = GenericMozImageRect<NumberOrPercentage, ComputedImageUrl>;
impl GenericLineDirection for LineDirection {
fn points_downwards(&self, compat_mode: CompatMode) -> bool {

View file

@ -646,9 +646,17 @@ pub enum ComputedUrl {
Valid(ServoUrl),
}
/// TODO: Properly build ComputedUrl for gecko
/// The computed value of a CSS `url()` for image.
#[cfg(feature = "servo")]
pub type ComputedImageUrl = ComputedUrl;
// TODO: Properly build ComputedUrl for gecko
/// The computed value of a CSS `url()`.
#[cfg(feature = "gecko")]
pub type ComputedUrl = specified::url::SpecifiedUrl;
/// The computed value of a CSS `url()` for image.
#[cfg(feature = "gecko")]
pub type ComputedImageUrl = specified::url::SpecifiedImageUrl;
#[cfg(feature = "servo")]
impl ComputedUrl {
@ -680,3 +688,6 @@ impl ToCss for ComputedUrl {
/// <url> | <none>
pub type UrlOrNone = Either<ComputedUrl, None_>;
/// <url> | <none> for image
pub type ImageUrlOrNone = Either<ComputedImageUrl, None_>;

View file

@ -18,7 +18,7 @@ use style_traits::cursor::CursorKind;
use values::computed::color::Color;
use values::generics::pointing::CaretColor as GenericCaretColor;
#[cfg(feature = "gecko")]
use values::specified::url::SpecifiedUrl;
use values::specified::url::SpecifiedImageUrl;
/// The computed value for the `cursor` property.
///
@ -65,10 +65,7 @@ impl Parse for Cursor {
let mut images = vec![];
loop {
match input.try(|input| CursorImage::parse_image(context, input)) {
Ok(mut image) => {
image.url.build_image_value();
images.push(image)
}
Ok(image) => images.push(image),
Err(_) => break,
}
input.expect_comma()?;
@ -114,7 +111,7 @@ impl CursorImage {
input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i>> {
Ok(Self {
url: SpecifiedUrl::parse(context, input)?,
url: SpecifiedImageUrl::parse(context, input)?,
// FIXME(emilio): Should use Number::parse to handle calc() correctly.
hotspot: match input.try(|input| input.expect_number()) {
Ok(number) => Some((number, input.expect_number()?)),