From 431b9d00f5208bae539f776df24c18f6257a8d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 22 May 2019 11:34:23 +0000 Subject: [PATCH] style: Remove eStyleImageType_URL. It was introduced in bug 1352096 to reduce complexity with Stylo (apparently). Right now it doesn't look like it reduces any complexity, and it's a bit annoying with some of the patches that I'm writing at the moment. So unless there's any objection I think it should go away. Differential Revision: https://phabricator.services.mozilla.com/D31708 --- components/style/gecko/conversions.rs | 24 ++++++++--------------- components/style/gecko/url.rs | 19 +++++++----------- components/style/properties/gecko.mako.rs | 24 ++++++++--------------- components/style/values/animated/mod.rs | 3 ++- 4 files changed, 25 insertions(+), 45 deletions(-) diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 43082a7c04a..06e201bf2b5 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -383,7 +383,6 @@ impl nsStyleImage { let atom = bindings::Gecko_GetImageElement(self); Some(GenericImage::Element(Atom::from_raw(atom))) }, - _ => panic!("Unexpected image type"), } } @@ -535,10 +534,8 @@ pub mod basic_shape { use crate::gecko_bindings::structs::{ StyleGeometryBox, StyleShapeSource, StyleShapeSourceType, }; - use crate::gecko_bindings::sugar::refptr::RefPtr; use crate::values::computed::basic_shape::{BasicShape, ClippingShape, FloatAreaShape}; use crate::values::computed::motion::OffsetPath; - use crate::values::computed::url::ComputedUrl; use crate::values::generics::basic_shape::{GeometryBox, Path, ShapeBox, ShapeSource}; use crate::values::specified::SVGPathData; @@ -564,7 +561,7 @@ pub mod basic_shape { }; Some(ShapeSource::Shape(shape, reference_box)) }, - StyleShapeSourceType::URL | StyleShapeSourceType::Image => None, + StyleShapeSourceType::Image => None, StyleShapeSourceType::Path => { let path = self.to_svg_path().expect("expect an SVGPathData"); let fill = unsafe { &*self.__bindgen_anon_1.mSVGPath.as_ref().mPtr }.mFillRule; @@ -587,16 +584,15 @@ pub mod basic_shape { impl<'a> From<&'a StyleShapeSource> for ClippingShape { fn from(other: &'a StyleShapeSource) -> Self { + use crate::values::generics::image::Image as GenericImage; match other.mType { - StyleShapeSourceType::URL => unsafe { + StyleShapeSourceType::Image => unsafe { let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr; - let other_url = - RefPtr::new(*shape_image.__bindgen_anon_1.mURLValue.as_ref() as *mut _); - let url = ComputedUrl::from_url_value(other_url); - ShapeSource::ImageOrUrl(url) - }, - StyleShapeSourceType::Image => { - unreachable!("ClippingShape doesn't support Image!"); + let image = shape_image.into_image().expect("Cannot convert to Image"); + match image { + GenericImage::Url(url) => ShapeSource::ImageOrUrl(url.0), + _ => panic!("ClippingShape doesn't support non-url images"), + } }, _ => other .into_shape_source() @@ -608,9 +604,6 @@ pub mod basic_shape { impl<'a> From<&'a StyleShapeSource> for FloatAreaShape { fn from(other: &'a StyleShapeSource) -> Self { match other.mType { - StyleShapeSourceType::URL => { - unreachable!("FloatAreaShape doesn't support URL!"); - }, StyleShapeSourceType::Image => unsafe { let shape_image = &*other.__bindgen_anon_1.mShapeImage.as_ref().mPtr; let image = shape_image.into_image().expect("Cannot convert to Image"); @@ -632,7 +625,6 @@ pub mod basic_shape { StyleShapeSourceType::None => OffsetPath::none(), StyleShapeSourceType::Shape | StyleShapeSourceType::Box | - StyleShapeSourceType::URL | StyleShapeSourceType::Image => unreachable!("Unsupported offset-path type"), } } diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index 2da16043779..dbbb3399da7 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -310,13 +310,13 @@ impl ToComputedValue for SpecifiedImageUrl { type ComputedValue = ComputedImageUrl; #[inline] - fn to_computed_value(&self, _: &Context) -> Self::ComputedValue { - ComputedImageUrl(self.clone()) + fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { + ComputedImageUrl(self.0.to_computed_value(context)) } #[inline] fn from_computed_value(computed: &Self::ComputedValue) -> Self { - computed.0.clone() + SpecifiedImageUrl(ToComputedValue::from_computed_value(&computed.0)) } } @@ -378,7 +378,7 @@ impl ComputedUrl { /// The computed value of a CSS image `url()`. #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)] -pub struct ComputedImageUrl(pub SpecifiedImageUrl); +pub struct ComputedImageUrl(pub ComputedUrl); impl ToCss for ComputedImageUrl { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result @@ -395,22 +395,17 @@ impl ComputedImageUrl { /// Convert from nsStyleImageReques to ComputedImageUrl. pub unsafe fn from_image_request(image_request: &nsStyleImageRequest) -> Self { let url_value = image_request.mImageValue.to_safe(); - let css_url = &*url_value.mCssUrl.mRawPtr; - let url = CssUrl(CssUrlData::as_arc(&css_url).clone_arc()); - ComputedImageUrl(SpecifiedImageUrl(SpecifiedUrl { - url, - url_value: Box::new(URLValueSource::URLValue(url_value)), - })) + ComputedImageUrl(ComputedUrl::from_url_value(url_value)) } /// Clone a new, strong reference to the Gecko URLValue. pub fn clone_url_value(&self) -> RefPtr { - (self.0).0.clone_url_value() + self.0.clone_url_value() } /// Get a raw pointer to the URLValue held by this ComputedImageUrl, for FFI. pub fn url_value_ptr(&self) -> *mut URLValue { - (self.0).0.url_value_ptr() + self.0.url_value_ptr() } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 980abeafa47..2c83e8cf656 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -53,6 +53,7 @@ use std::mem::{forget, uninitialized, zeroed, ManuallyDrop}; use std::{cmp, ops, ptr}; use crate::values::{self, CustomIdent, Either, KeyframesName, None_}; use crate::values::computed::{NonNegativeLength, Percentage, TransitionProperty}; +use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::BorderStyle; use crate::values::computed::font::FontSize; use crate::values::computed::effects::Filter; @@ -60,6 +61,7 @@ use crate::values::generics::column::ColumnCount; use crate::values::generics::transform::TransformStyle; use crate::values::generics::url::UrlOrNone; + pub mod style_structs { % for style_struct in data.style_structs: pub use super::${style_struct.gecko_struct_name} as ${style_struct.name}; @@ -2850,8 +2852,6 @@ fn static_assert() { } pub fn clone_list_style_image(&self) -> longhands::list_style_image::computed_value::T { - use crate::values::computed::url::ComputedImageUrl; - if self.gecko.mListStyleImage.mRawPtr.is_null() { return UrlOrNone::None; } @@ -3489,25 +3489,19 @@ fn set_style_svg_path( ${ident}.mType = StyleShapeSourceType::None; match v { - % if ident == "clip_path": - ShapeSource::ImageOrUrl(ref url) => { - unsafe { - bindings::Gecko_StyleShapeSource_SetURLValue(${ident}, url.url_value_ptr()) - } - } - % elif ident == "shape_outside": + ShapeSource::None => {} // don't change the type ShapeSource::ImageOrUrl(image) => { + % if ident == "clip_path": + use crate::values::generics::image::Image; + + let image = Image::Url(ComputedImageUrl(image)); + % endif unsafe { bindings::Gecko_NewShapeImage(${ident}); let style_image = &mut *${ident}.__bindgen_anon_1.mShapeImage.as_mut().mPtr; style_image.set(image); } } - % else: - <% raise Exception("Unknown property: %s" % ident) %> - } - % endif - ShapeSource::None => {} // don't change the type ShapeSource::Box(reference) => { ${ident}.mReferenceBox = reference.into(); ${ident}.mType = StyleShapeSourceType::Box; @@ -3662,7 +3656,6 @@ clip-path pub fn clone_cursor(&self) -> longhands::cursor::computed_value::T { use crate::values::computed::ui::CursorImage; - use crate::values::computed::url::ComputedImageUrl; let keyword = self.gecko.mCursor; @@ -3878,7 +3871,6 @@ clip-path use crate::gecko::conversions::string_from_chars_pointer; use crate::gecko_bindings::structs::StyleContentType; use crate::values::generics::counters::{Content, ContentItem}; - use crate::values::computed::url::ComputedImageUrl; use crate::values::{CustomIdent, Either}; use crate::values::generics::CounterStyleOrNone; use crate::values::specified::Attr; diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 267ef0c8e6f..23c314a57a4 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -10,7 +10,7 @@ use crate::properties::PropertyId; use crate::values::computed::length::LengthPercentage; -use crate::values::computed::url::ComputedUrl; +use crate::values::computed::url::{ComputedUrl, ComputedImageUrl}; use crate::values::computed::Angle as ComputedAngle; use crate::values::computed::Image; use crate::values::specified::SVGPathData; @@ -380,6 +380,7 @@ trivial_to_animated_value!(Au); trivial_to_animated_value!(LengthPercentage); trivial_to_animated_value!(ComputedAngle); trivial_to_animated_value!(ComputedUrl); +trivial_to_animated_value!(ComputedImageUrl); trivial_to_animated_value!(bool); trivial_to_animated_value!(f32); // Note: This implementation is for ToAnimatedValue of ShapeSource.