mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add SpecifiedImageUrl for <url> used as images.
This commit is contained in:
parent
14b708311b
commit
a99ca543cd
18 changed files with 151 additions and 136 deletions
|
@ -18,7 +18,7 @@ use values::generics::counters::CounterReset as GenericCounterReset;
|
|||
use values::specified::Attr;
|
||||
use values::specified::Integer;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
use values::specified::url::SpecifiedImageUrl;
|
||||
|
||||
/// A specified value for the `counter-increment` property.
|
||||
pub type CounterIncrement = GenericCounterIncrement<Integer>;
|
||||
|
@ -119,5 +119,5 @@ pub enum ContentItem {
|
|||
Attr(Attr),
|
||||
/// `url(url)`
|
||||
#[cfg(feature = "gecko")]
|
||||
Url(SpecifiedUrl),
|
||||
Url(SpecifiedImageUrl),
|
||||
}
|
||||
|
|
|
@ -31,14 +31,14 @@ use values::generics::position::Position as GenericPosition;
|
|||
use values::specified::{Angle, Color, Length, LengthOrPercentage};
|
||||
use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor};
|
||||
use values::specified::position::{LegacyPosition, Position, PositionComponent, Side, X, Y};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
use values::specified::url::SpecifiedImageUrl;
|
||||
|
||||
/// A specified image layer.
|
||||
pub type ImageLayer = Either<None_, Image>;
|
||||
|
||||
/// Specified values for an image according to CSS-IMAGES.
|
||||
/// <https://drafts.csswg.org/css-images/#image-values>
|
||||
pub type Image = GenericImage<Gradient, MozImageRect, SpecifiedUrl>;
|
||||
pub type Image = GenericImage<Gradient, MozImageRect, SpecifiedImageUrl>;
|
||||
|
||||
/// Specified values for a CSS gradient.
|
||||
/// <https://drafts.csswg.org/css-images/#gradients>
|
||||
|
@ -124,16 +124,11 @@ pub type ColorStop = GenericColorStop<RGBAColor, LengthOrPercentage>;
|
|||
|
||||
/// Specified values for `moz-image-rect`
|
||||
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
||||
pub type MozImageRect = GenericMozImageRect<NumberOrPercentage, SpecifiedUrl>;
|
||||
pub type MozImageRect = GenericMozImageRect<NumberOrPercentage, SpecifiedImageUrl>;
|
||||
|
||||
impl Parse for Image {
|
||||
#[cfg_attr(not(feature = "gecko"), allow(unused_mut))]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Image, ParseError<'i>> {
|
||||
if let Ok(mut url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
url.build_image_value();
|
||||
}
|
||||
if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) {
|
||||
return Ok(GenericImage::Url(url));
|
||||
}
|
||||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||
|
@ -145,11 +140,7 @@ impl Parse for Image {
|
|||
return Ok(GenericImage::PaintWorklet(paint_worklet));
|
||||
}
|
||||
}
|
||||
if let Ok(mut image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
image_rect.url.build_image_value();
|
||||
}
|
||||
if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
||||
return Ok(GenericImage::Rect(Box::new(image_rect)));
|
||||
}
|
||||
Ok(GenericImage::Element(Image::parse_element(input)?))
|
||||
|
@ -944,7 +935,7 @@ impl Parse for MozImageRect {
|
|||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
input.parse_nested_block(|i| {
|
||||
let string = i.expect_url_or_string()?;
|
||||
let url = SpecifiedUrl::parse_from_string(string.as_ref().to_owned(), context)?;
|
||||
let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context)?;
|
||||
i.expect_comma()?;
|
||||
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||
i.expect_comma()?;
|
||||
|
@ -953,14 +944,7 @@ impl Parse for MozImageRect {
|
|||
let bottom = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||
i.expect_comma()?;
|
||||
let left = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||
|
||||
Ok(MozImageRect {
|
||||
url: url,
|
||||
top: top,
|
||||
right: right,
|
||||
bottom: bottom,
|
||||
left: left,
|
||||
})
|
||||
Ok(MozImageRect { url, top, right, bottom, left })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use values::{Either, None_};
|
|||
use values::CustomIdent;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use values::specified::UrlOrNone;
|
||||
use values::specified::ImageUrlOrNone;
|
||||
|
||||
/// Specified and computed `list-style-type` property.
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -75,7 +75,7 @@ impl Parse for ListStyleType {
|
|||
|
||||
/// Specified and computed `list-style-image` property.
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||
pub struct ListStyleImage(pub UrlOrNone);
|
||||
pub struct ListStyleImage(pub ImageUrlOrNone);
|
||||
|
||||
// FIXME(nox): This is wrong, there are different types for specified
|
||||
// and computed URLs in Servo.
|
||||
|
@ -90,19 +90,11 @@ impl ListStyleImage {
|
|||
}
|
||||
|
||||
impl Parse for ListStyleImage {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<ListStyleImage, ParseError<'i>> {
|
||||
#[allow(unused_mut)]
|
||||
let mut value = input.try(|input| UrlOrNone::parse(context, input))?;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Either::First(ref mut url) = value {
|
||||
url.build_image_value();
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(ListStyleImage(value));
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<ListStyleImage, ParseError<'i>> {
|
||||
ImageUrlOrNone::parse(context, input).map(ListStyleImage)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use context::QuirksMode;
|
|||
use cssparser::{Parser, Token, serialize_identifier};
|
||||
use num_traits::One;
|
||||
use parser::{ParserContext, Parse};
|
||||
use self::url::SpecifiedUrl;
|
||||
use self::url::{SpecifiedImageUrl, SpecifiedUrl};
|
||||
use std::f32;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
|
@ -534,6 +534,9 @@ impl Parse for PositiveInteger {
|
|||
#[allow(missing_docs)]
|
||||
pub type UrlOrNone = Either<SpecifiedUrl, None_>;
|
||||
|
||||
/// The specified value of a `<url>` for image or `none`.
|
||||
pub type ImageUrlOrNone = Either<SpecifiedImageUrl, None_>;
|
||||
|
||||
/// The specified value of a grid `<track-breadth>`
|
||||
pub type TrackBreadth = GenericTrackBreadth<LengthOrPercentage>;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use style_traits::cursor::CursorKind;
|
|||
use values::generics::pointing::CaretColor as GenericCaretColor;
|
||||
use values::specified::color::Color;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
use values::specified::url::SpecifiedImageUrl;
|
||||
|
||||
/// The specified value for the `cursor` property.
|
||||
///
|
||||
|
@ -39,7 +39,7 @@ pub struct Cursor {
|
|||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct CursorImage {
|
||||
/// The url to parse images from.
|
||||
pub url: SpecifiedUrl,
|
||||
pub url: SpecifiedImageUrl,
|
||||
/// The <x> and <y> coordinates.
|
||||
pub hotspot: Option<(f32, f32)>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue