mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Centralize specified url value handling, and refcount urls.
This commit is contained in:
parent
89c46369a2
commit
5f2e7af864
22 changed files with 267 additions and 187 deletions
|
@ -10,17 +10,16 @@
|
|||
use properties::shorthands::serialize_four_sides;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use url::Url;
|
||||
use values::computed::{BorderRadiusSize, LengthOrPercentage};
|
||||
use values::computed::UrlExtraData;
|
||||
use values::computed::position::Position;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
pub use values::specified::basic_shape::{FillRule, GeometryBox, ShapeBox};
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum ShapeSource<T> {
|
||||
Url(Url, UrlExtraData),
|
||||
Url(SpecifiedUrl),
|
||||
Shape(BasicShape, Option<T>),
|
||||
Box(T),
|
||||
None,
|
||||
|
@ -35,7 +34,7 @@ impl<T> Default for ShapeSource<T> {
|
|||
impl<T: ToCss> ToCss for ShapeSource<T> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
ShapeSource::Url(ref url, _) => url.to_css(dest),
|
||||
ShapeSource::Url(ref url) => url.to_css(dest),
|
||||
ShapeSource::Shape(ref shape, Some(ref reference)) => {
|
||||
try!(shape.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
use cssparser::Color as CSSColor;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use url::Url;
|
||||
use values::computed::{Context, Length, LengthOrPercentage, ToComputedValue};
|
||||
use values::computed::position::Position;
|
||||
use values::specified::{self, AngleOrCorner, SizeKeyword, UrlExtraData};
|
||||
use values::specified::{self, AngleOrCorner, SizeKeyword};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
|
||||
impl ToComputedValue for specified::Image {
|
||||
|
@ -22,8 +22,8 @@ impl ToComputedValue for specified::Image {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Image {
|
||||
match *self {
|
||||
specified::Image::Url(ref url, ref extra_data) => {
|
||||
Image::Url(url.clone(), extra_data.clone())
|
||||
specified::Image::Url(ref url_value) => {
|
||||
Image::Url(url_value.clone())
|
||||
},
|
||||
specified::Image::Gradient(ref gradient) => {
|
||||
Image::Gradient(gradient.to_computed_value(context))
|
||||
|
@ -34,8 +34,8 @@ impl ToComputedValue for specified::Image {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &Image) -> Self {
|
||||
match *computed {
|
||||
Image::Url(ref url, ref extra_data) => {
|
||||
specified::Image::Url(url.clone(), extra_data.clone())
|
||||
Image::Url(ref url_value) => {
|
||||
specified::Image::Url(url_value.clone())
|
||||
},
|
||||
Image::Gradient(ref linear_gradient) => {
|
||||
specified::Image::Gradient(
|
||||
|
@ -51,14 +51,14 @@ impl ToComputedValue for specified::Image {
|
|||
#[derive(Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum Image {
|
||||
Url(Url, UrlExtraData),
|
||||
Url(SpecifiedUrl),
|
||||
Gradient(Gradient),
|
||||
}
|
||||
|
||||
impl fmt::Debug for Image {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Image::Url(ref url, ref _extra_data) => write!(f, "url(\"{}\")", url),
|
||||
Image::Url(ref url) => url.to_css(f),
|
||||
Image::Gradient(ref grad) => {
|
||||
if grad.repeating {
|
||||
let _ = write!(f, "repeating-");
|
||||
|
@ -75,9 +75,7 @@ impl fmt::Debug for Image {
|
|||
impl ToCss for Image {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
Image::Url(ref url, _) => {
|
||||
url.to_css(dest)
|
||||
}
|
||||
Image::Url(ref url) => url.to_css(dest),
|
||||
Image::Gradient(ref gradient) => gradient.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use values::{CSSFloat, Either, None_, specified};
|
|||
pub use cssparser::Color as CSSColor;
|
||||
pub use super::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
||||
pub use super::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
pub use values::specified::{Angle, BorderStyle, Time, UrlExtraData, UrlOrNone};
|
||||
pub use values::specified::{Angle, BorderStyle, Time, UrlOrNone};
|
||||
|
||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
|
@ -13,7 +13,8 @@ pub use cssparser::Color as CSSColor;
|
|||
pub use self::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
pub use super::{Either, None_};
|
||||
pub use super::specified::{Angle, BorderStyle, Time, UrlExtraData, UrlOrNone};
|
||||
pub use super::specified::{Angle, BorderStyle, Time, UrlOrNone};
|
||||
pub use super::specified::url::UrlExtraData;
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
|
||||
|
||||
|
|
|
@ -12,12 +12,11 @@ use parser::{Parse, ParserContext};
|
|||
use properties::shorthands::{parse_four_sides, serialize_four_sides};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use url::Url;
|
||||
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
|
||||
use values::computed::basic_shape as computed_basic_shape;
|
||||
use values::specified::{BorderRadiusSize, LengthOrPercentage, Percentage};
|
||||
use values::specified::UrlExtraData;
|
||||
use values::specified::position::{Keyword, Position};
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A shape source, for some reference box
|
||||
///
|
||||
|
@ -26,7 +25,7 @@ use values::specified::position::{Keyword, Position};
|
|||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum ShapeSource<T> {
|
||||
Url(Url, UrlExtraData),
|
||||
Url(SpecifiedUrl),
|
||||
Shape(BasicShape, Option<T>),
|
||||
Box(T),
|
||||
None,
|
||||
|
@ -41,7 +40,7 @@ impl<T> Default for ShapeSource<T> {
|
|||
impl<T: ToCss> ToCss for ShapeSource<T> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
ShapeSource::Url(ref url, _) => url.to_css(dest),
|
||||
ShapeSource::Url(ref url) => url.to_css(dest),
|
||||
ShapeSource::Shape(ref shape, Some(ref reference)) => {
|
||||
try!(shape.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
|
@ -59,13 +58,8 @@ impl<T: Parse + PartialEq + Copy> ShapeSource<T> {
|
|||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(_) = input.try(|input| input.expect_ident_matching("none")) {
|
||||
Ok(ShapeSource::None)
|
||||
} else if let Ok(url) = input.try(|input| input.expect_url()) {
|
||||
match UrlExtraData::make_from(context) {
|
||||
Some(extra_data) => {
|
||||
Ok(ShapeSource::Url(context.parse_url(&url), extra_data))
|
||||
},
|
||||
None => Err(()),
|
||||
}
|
||||
} else if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||
Ok(ShapeSource::Url(url))
|
||||
} else {
|
||||
fn parse_component<U: Parse>(input: &mut Parser, component: &mut Option<U>) -> bool {
|
||||
if component.is_some() {
|
||||
|
@ -98,8 +92,8 @@ impl<T: ToComputedValue> ToComputedValue for ShapeSource<T> {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
ShapeSource::Url(ref url, ref data) => {
|
||||
computed_basic_shape::ShapeSource::Url(url.clone(), data.clone())
|
||||
ShapeSource::Url(ref url) => {
|
||||
computed_basic_shape::ShapeSource::Url(url.to_computed_value(cx))
|
||||
}
|
||||
ShapeSource::Shape(ref shape, ref reference) => {
|
||||
computed_basic_shape::ShapeSource::Shape(
|
||||
|
@ -116,8 +110,8 @@ impl<T: ToComputedValue> ToComputedValue for ShapeSource<T> {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
computed_basic_shape::ShapeSource::Url(ref url, ref data) => {
|
||||
ShapeSource::Url(url.clone(), data.clone())
|
||||
computed_basic_shape::ShapeSource::Url(ref url) => {
|
||||
ShapeSource::Url(SpecifiedUrl::from_computed_value(url))
|
||||
}
|
||||
computed_basic_shape::ShapeSource::Shape(ref shape, ref reference) => {
|
||||
ShapeSource::Shape(
|
||||
|
|
|
@ -11,49 +11,45 @@ use cssparser::Parser;
|
|||
use parser::{Parse, ParserContext};
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use style_traits::ToCss;
|
||||
use url::Url;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage, UrlExtraData};
|
||||
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage};
|
||||
use values::specified::position::Position;
|
||||
use values::specified::url::{SpecifiedUrl, UrlExtraData};
|
||||
|
||||
/// Specified values for an image according to CSS-IMAGES.
|
||||
/// https://drafts.csswg.org/css-images/#image-values
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum Image {
|
||||
Url(Url, UrlExtraData),
|
||||
Url(SpecifiedUrl),
|
||||
Gradient(Gradient),
|
||||
}
|
||||
|
||||
impl ToCss for Image {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
Image::Url(ref url, ref _extra_data) => {
|
||||
url.to_css(dest)
|
||||
}
|
||||
Image::Gradient(ref gradient) => gradient.to_css(dest)
|
||||
Image::Url(ref url_value) => url_value.to_css(dest),
|
||||
Image::Gradient(ref gradient) => gradient.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Image {
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> {
|
||||
if let Ok(url) = input.try(|input| input.expect_url()) {
|
||||
match UrlExtraData::make_from(context) {
|
||||
Some(extra_data) => {
|
||||
Ok(Image::Url(context.parse_url(&url), extra_data))
|
||||
},
|
||||
None => {
|
||||
// FIXME(heycam) should ensure we always have a principal, etc., when
|
||||
// parsing style attributes and re-parsing due to CSS Variables.
|
||||
println!("stylo: skipping declaration without ParserContextExtraData");
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Ok(Image::Gradient(try!(Gradient::parse_function(input))))
|
||||
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||
return Ok(Image::Url(url));
|
||||
}
|
||||
|
||||
Ok(Image::Gradient(try!(Gradient::parse_function(input))))
|
||||
}
|
||||
|
||||
/// Creates an already specified image value from an already resolved URL
|
||||
/// for insertion in the cascade.
|
||||
pub fn for_cascade(url: Option<Arc<Url>>, extra_data: UrlExtraData) -> Self {
|
||||
Image::Url(SpecifiedUrl::for_cascade(url, extra_data))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
use app_units::Au;
|
||||
use cssparser::{self, Parser, Token};
|
||||
use euclid::size::Size2D;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
||||
use parser::ParserContext;
|
||||
#[cfg(feature = "gecko")]
|
||||
use parser::ParserContextExtraData;
|
||||
use self::url::SpecifiedUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt;
|
||||
|
@ -17,7 +14,6 @@ use std::ops::Mul;
|
|||
use style_traits::ToCss;
|
||||
use super::{CSSFloat, HasViewportPercentage, NoViewportPercentage};
|
||||
use super::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
|
||||
use url::Url;
|
||||
|
||||
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
|
@ -30,6 +26,7 @@ pub mod basic_shape;
|
|||
pub mod image;
|
||||
pub mod length;
|
||||
pub mod position;
|
||||
pub mod url;
|
||||
|
||||
impl NoViewportPercentage for i32 {} // For PropertyDeclaration::Order
|
||||
|
||||
|
@ -263,42 +260,6 @@ impl Angle {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct UrlExtraData {
|
||||
#[cfg(feature = "gecko")]
|
||||
pub base: GeckoArcURI,
|
||||
#[cfg(feature = "gecko")]
|
||||
pub referrer: GeckoArcURI,
|
||||
#[cfg(feature = "gecko")]
|
||||
pub principal: GeckoArcPrincipal,
|
||||
}
|
||||
|
||||
impl UrlExtraData {
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn make_from(_: &ParserContext) -> Option<UrlExtraData> {
|
||||
Some(UrlExtraData { })
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn make_from(context: &ParserContext) -> Option<UrlExtraData> {
|
||||
match context.extra_data {
|
||||
ParserContextExtraData {
|
||||
base: Some(ref base),
|
||||
referrer: Some(ref referrer),
|
||||
principal: Some(ref principal),
|
||||
} => {
|
||||
Some(UrlExtraData {
|
||||
base: base.clone(),
|
||||
referrer: referrer.clone(),
|
||||
principal: principal.clone(),
|
||||
})
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_border_radius(input: &mut Parser) -> Result<BorderRadiusSize, ()> {
|
||||
input.try(BorderRadiusSize::parse).or_else(|()| {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
|
@ -546,7 +507,7 @@ impl ToCss for Opacity {
|
|||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum UrlOrNone {
|
||||
Url(Url, UrlExtraData),
|
||||
Url(SpecifiedUrl),
|
||||
None,
|
||||
}
|
||||
|
||||
|
@ -556,13 +517,8 @@ impl NoViewportPercentage for UrlOrNone {}
|
|||
impl ToCss for UrlOrNone {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
UrlOrNone::Url(ref url, _) => {
|
||||
url.to_css(dest)
|
||||
}
|
||||
UrlOrNone::None => {
|
||||
try!(dest.write_str("none"));
|
||||
Ok(())
|
||||
}
|
||||
UrlOrNone::Url(ref url) => url.to_css(dest),
|
||||
UrlOrNone::None => dest.write_str("none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -573,17 +529,6 @@ impl UrlOrNone {
|
|||
return Ok(UrlOrNone::None);
|
||||
}
|
||||
|
||||
let url = context.parse_url(&*try!(input.expect_url()));
|
||||
match UrlExtraData::make_from(context) {
|
||||
Some(extra_data) => {
|
||||
Ok(UrlOrNone::Url(url, extra_data))
|
||||
},
|
||||
_ => {
|
||||
// FIXME(heycam) should ensure we always have a principal, etc., when parsing
|
||||
// style attributes and re-parsing due to CSS Variables.
|
||||
println!("stylo: skipping UrlOrNone declaration without ParserContextExtraData");
|
||||
Err(())
|
||||
},
|
||||
}
|
||||
Ok(UrlOrNone::Url(try!(SpecifiedUrl::parse(context, input))))
|
||||
}
|
||||
}
|
||||
|
|
165
components/style/values/specified/url.rs
Normal file
165
components/style/values/specified/url.rs
Normal file
|
@ -0,0 +1,165 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
//! Common handling for the specified value CSS url() values.
|
||||
|
||||
use cssparser::{CssStringWriter, Parser};
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
||||
use parser::ParserContext;
|
||||
#[cfg(feature = "gecko")]
|
||||
use parser::ParserContextExtraData;
|
||||
use std::fmt::{self, Write};
|
||||
use std::ptr;
|
||||
use std::sync::Arc;
|
||||
use style_traits::ToCss;
|
||||
use url::Url;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct UrlExtraData {
|
||||
#[cfg(feature = "gecko")]
|
||||
pub base: GeckoArcURI,
|
||||
#[cfg(feature = "gecko")]
|
||||
pub referrer: GeckoArcURI,
|
||||
#[cfg(feature = "gecko")]
|
||||
pub principal: GeckoArcPrincipal,
|
||||
}
|
||||
|
||||
impl UrlExtraData {
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn make_from(_: &ParserContext) -> Option<UrlExtraData> {
|
||||
Some(UrlExtraData { })
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn make_from(context: &ParserContext) -> Option<UrlExtraData> {
|
||||
match context.extra_data {
|
||||
ParserContextExtraData {
|
||||
base: Some(ref base),
|
||||
referrer: Some(ref referrer),
|
||||
principal: Some(ref principal),
|
||||
} => {
|
||||
Some(UrlExtraData {
|
||||
base: base.clone(),
|
||||
referrer: referrer.clone(),
|
||||
principal: principal.clone(),
|
||||
})
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified url() value.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedUrl {
|
||||
/// The original URI. This might be optional since we may insert computed
|
||||
/// values of images into the cascade directly, and we don't bother to
|
||||
/// convert their serialization.
|
||||
///
|
||||
/// Refcounted since cloning this should be cheap and data: uris can be
|
||||
/// really large.
|
||||
original: Option<Arc<String>>,
|
||||
|
||||
/// The resolved value for the url, if valid.
|
||||
resolved: Option<Arc<Url>>,
|
||||
|
||||
/// Extra data used for Stylo.
|
||||
extra_data: UrlExtraData,
|
||||
}
|
||||
|
||||
impl SpecifiedUrl {
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
let url = try!(input.expect_url());
|
||||
|
||||
let extra_data = match UrlExtraData::make_from(context) {
|
||||
Some(extra_data) => extra_data,
|
||||
None => {
|
||||
// FIXME(heycam) should ensure we always have a principal, etc.,
|
||||
// when parsing style attributes and re-parsing due to CSS
|
||||
// Variables.
|
||||
println!("stylo: skipping declaration without ParserContextExtraData");
|
||||
return Err(())
|
||||
},
|
||||
};
|
||||
|
||||
let serialization = Arc::new(url.into_owned());
|
||||
let resolved = context.base_url.join(&serialization).ok().map(Arc::new);
|
||||
Ok(SpecifiedUrl {
|
||||
original: Some(serialization),
|
||||
resolved: resolved,
|
||||
extra_data: extra_data,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn extra_data(&self) -> &UrlExtraData {
|
||||
&self.extra_data
|
||||
}
|
||||
|
||||
pub fn url(&self) -> Option<&Arc<Url>> {
|
||||
self.resolved.as_ref()
|
||||
}
|
||||
|
||||
/// Little helper for Gecko's ffi.
|
||||
pub fn as_slice_components(&self) -> (*const u8, usize) {
|
||||
match self.resolved {
|
||||
Some(ref url) => (url.as_str().as_ptr(), url.as_str().len()),
|
||||
None => (ptr::null(), 0),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates an already specified url value from an already resolved URL
|
||||
/// for insertion in the cascade.
|
||||
pub fn for_cascade(url: Option<Arc<Url>>, extra_data: UrlExtraData) -> Self {
|
||||
SpecifiedUrl {
|
||||
original: None,
|
||||
resolved: url,
|
||||
extra_data: extra_data,
|
||||
}
|
||||
}
|
||||
|
||||
// Just for unit tests, don't use outside of them!
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn new_for_testing(url: &str) -> Self {
|
||||
SpecifiedUrl {
|
||||
original: Some(Arc::new(url.into())),
|
||||
resolved: Url::parse(url).ok().map(Arc::new),
|
||||
extra_data: UrlExtraData {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for SpecifiedUrl {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
// TODO(emilio): maybe we care about equality of the specified values if
|
||||
// present? Seems not.
|
||||
self.resolved == other.resolved &&
|
||||
self.extra_data == other.extra_data
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedUrl {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("url(\""));
|
||||
let string = match self.original {
|
||||
Some(ref original) => &**original,
|
||||
None => match self.resolved {
|
||||
Some(ref url) => url.as_str(),
|
||||
// This can only happen if the url wasn't specified by the
|
||||
// user *and* it's an invalid url that has been transformed
|
||||
// back to specified value via the "uncompute" functionality.
|
||||
None => "about:invalid",
|
||||
}
|
||||
};
|
||||
|
||||
try!(CssStringWriter::new(dest).write_str(string));
|
||||
dest.write_str("\")")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(emilio): Maybe consider ComputedUrl to save a word in style structs?
|
||||
impl ComputedValueAsSpecified for SpecifiedUrl {}
|
Loading…
Add table
Add a link
Reference in a new issue