Skip to content
Permalink
Browse files

style: Centralize specified url value handling, and refcount urls.

  • Loading branch information
emilio committed Nov 10, 2016
1 parent 89c4636 commit 5f2e7af864e3d190957f58b317bf56cce8a84795
@@ -1205,9 +1205,9 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
-> ConstructionResult {
let flotation = FloatKind::from_property(flotation);
let marker_fragments = match node.style(self.style_context()).get_list().list_style_image {
list_style_image::T::Url(ref url, ref _extra_data) => {
list_style_image::T::Url(ref url_value) => {
let image_info = box ImageFragmentInfo::new(node,
Some((*url).clone()),
url_value.url().map(|u| (**u).clone()),
&self.layout_context.shared);
vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)]
}
@@ -612,14 +612,16 @@ impl FragmentDisplayListBuilding for Fragment {
style);
}
}
Some(computed::Image::Url(ref image_url, ref _extra_data)) => {
self.build_display_list_for_background_image(state,
style,
display_list_section,
&bounds,
&clip,
image_url,
i);
Some(computed::Image::Url(ref image_url)) => {
if let Some(url) = image_url.url() {
self.build_display_list_for_background_image(state,
style,
display_list_section,
&bounds,
&clip,
url,
i);
}
}
}
}
@@ -368,7 +368,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
PropertyDeclaration::BackgroundImage(DeclaredValue::Value(
background_image::SpecifiedValue(vec![
background_image::single_value::SpecifiedValue(Some(
specified::Image::Url(url, specified::UrlExtraData { })
specified::Image::for_cascade(Some(Arc::new(url)), specified::url::UrlExtraData { })
))
])))));
}

Some generated files are not rendered by default. Learn more.

@@ -120,11 +120,13 @@ impl nsStyleImage {
Image::Gradient(gradient) => {
self.set_gradient(gradient)
},
Image::Url(ref url, ref extra_data) if with_url => {
Image::Url(ref url) if with_url => {
let (ptr, len) = url.as_slice_components();
let extra_data = url.extra_data();
unsafe {
Gecko_SetUrlImageValue(self,
url.as_str().as_ptr(),
url.as_str().len() as u32,
ptr,
len as u32,
extra_data.base.get(),
extra_data.referrer.get(),
extra_data.principal.get());
@@ -66,15 +66,6 @@ impl<'a> ParserContext<'a> {
}
}


impl<'a> ParserContext<'a> {
pub fn parse_url(&self, input: &str) -> Url {
self.base_url.join(input)
.unwrap_or_else(|_| Url::parse("about:invalid").unwrap())
}
}


/// Defaults to a no-op.
/// Set a `RUST_LOG=style::errors` environment variable
/// to log CSS parse errors to stderr.
@@ -1036,11 +1036,13 @@ fn static_assert() {
use properties::longhands::_moz_binding::computed_value::T as BindingValue;
match v {
BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
BindingValue::Url(ref url, ref extra_data) => {
BindingValue::Url(ref url) => {
let extra_data = url.extra_data();
let (ptr, len) = url.as_slice_components();
unsafe {
Gecko_SetMozBinding(&mut self.gecko,
url.as_str().as_ptr(),
url.as_str().len() as u32,
ptr,
len as u32,
extra_data.base.get(),
extra_data.referrer.get(),
extra_data.principal.get());
@@ -1441,11 +1443,13 @@ fn static_assert() {
Gecko_SetListStyleImageNone(&mut self.gecko);
}
}
UrlOrNone::Url(ref url, ref extra_data) => {
UrlOrNone::Url(ref url) => {
let (ptr, len) = url.as_slice_components();
let extra_data = url.extra_data();
unsafe {
Gecko_SetListStyleImage(&mut self.gecko,
url.as_str().as_ptr(),
url.as_str().len() as u32,
ptr,
len as u32,
extra_data.base.get(),
extra_data.referrer.get(),
extra_data.principal.get());
@@ -149,20 +149,21 @@ ${helpers.single_keyword("mask-composite",
has_uncacheable_values="${product == 'gecko'}">
use std::fmt;
use style_traits::ToCss;
use url::Url;
use values::specified::{Image, UrlExtraData};
use std::sync::Arc;
use values::specified::Image;
use values::specified::url::SpecifiedUrl;
use values::NoViewportPercentage;

pub mod computed_value {
use std::fmt;
use style_traits::ToCss;
use url::Url;
use values::computed;
use values::specified::url::SpecifiedUrl;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
Image(computed::Image),
Url(Url, computed::UrlExtraData),
Url(SpecifiedUrl),
None
}

@@ -171,7 +172,7 @@ ${helpers.single_keyword("mask-composite",
match *self {
T::None => dest.write_str("none"),
T::Image(ref image) => image.to_css(dest),
T::Url(ref url, _) => url.to_css(dest),
T::Url(ref url) => url.to_css(dest),
}
}
}
@@ -183,15 +184,15 @@ ${helpers.single_keyword("mask-composite",
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
Image(Image),
Url(Url, UrlExtraData),
Url(SpecifiedUrl),
None
}

impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::Image(ref image) => image.to_css(dest),
SpecifiedValue::Url(ref url, _) => url.to_css(dest),
SpecifiedValue::Url(ref url) => url.to_css(dest),
SpecifiedValue::None => dest.write_str("none"),
}
}
@@ -211,11 +212,16 @@ ${helpers.single_keyword("mask-composite",
} else {
let image = try!(Image::parse(context, input));
match image {
Image::Url(url, data) => {
if url.fragment().is_some() {
Ok(SpecifiedValue::Url(url, data))
Image::Url(url_value) => {
let has_valid_url = match url_value.url() {
Some(url) => url.fragment().is_some(),
None => false,
};

if has_valid_url {
Ok(SpecifiedValue::Url(url_value))
} else {
Ok(SpecifiedValue::Image(Image::Url(url, data)))
Ok(SpecifiedValue::Image(Image::Url(url_value)))
}
}
image => Ok(SpecifiedValue::Image(image))
@@ -231,8 +237,8 @@ ${helpers.single_keyword("mask-composite",
SpecifiedValue::None => computed_value::T::None,
SpecifiedValue::Image(ref image) =>
computed_value::T::Image(image.to_computed_value(context)),
SpecifiedValue::Url(ref url, ref data) =>
computed_value::T::Url(url.clone(), data.clone()),
SpecifiedValue::Url(ref url) =>
computed_value::T::Url(url.clone()),
}
}

@@ -242,8 +248,8 @@ ${helpers.single_keyword("mask-composite",
computed_value::T::None => SpecifiedValue::None,
computed_value::T::Image(ref image) =>
SpecifiedValue::Image(ToComputedValue::from_computed_value(image)),
computed_value::T::Url(ref url, ref data) =>
SpecifiedValue::Url(url.clone(), data.clone()),
computed_value::T::Url(ref url) =>
SpecifiedValue::Url(url.clone()),
}
}
}
@@ -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(

0 comments on commit 5f2e7af

Please sign in to comment.
You can’t perform that action at this time.