Bug 1552636 - Remove eStyleImageType_URL. r=TYLin

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-05-22 11:34:23 +00:00
parent 5ee1a7fd40
commit 7874fd4a2d
14 changed files with 37 additions and 133 deletions

View File

@ -2281,10 +2281,6 @@ nsFloatManager::FloatInfo::FloatInfo(nsIFrame* aFrame, nscoord aLineLeft,
// No need to create shape info.
return;
case StyleShapeSourceType::URL:
MOZ_ASSERT_UNREACHABLE("shape-outside doesn't have URL source type!");
return;
case StyleShapeSourceType::Path:
MOZ_ASSERT_UNREACHABLE("shape-outside doesn't have Path source type!");
return;

View File

@ -1540,11 +1540,6 @@ void Gecko_DestroyShapeSource(StyleShapeSource* aShape) {
aShape->~StyleShapeSource();
}
void Gecko_StyleShapeSource_SetURLValue(StyleShapeSource* aShape,
URLValue* aURL) {
aShape->SetURL(*aURL);
}
void Gecko_NewShapeImage(StyleShapeSource* aShape) {
aShape->SetShapeImage(MakeUnique<nsStyleImage>());
}

View File

@ -525,9 +525,6 @@ void Gecko_DestroyShapeSource(mozilla::StyleShapeSource* shape);
void Gecko_NewShapeImage(mozilla::StyleShapeSource* shape);
void Gecko_StyleShapeSource_SetURLValue(mozilla::StyleShapeSource* shape,
mozilla::css::URLValue* uri);
void Gecko_SetToSVGPath(
mozilla::StyleShapeSource* shape,
mozilla::StyleForgottenArcSlicePtr<mozilla::StylePathCommand>,

View File

@ -645,9 +645,6 @@ static void AddImageURL(const nsStyleImage& aImage, nsTArray<nsString>& aURLs) {
static void AddImageURL(const StyleShapeSource& aShapeSource,
nsTArray<nsString>& aURLs) {
switch (aShapeSource.GetType()) {
case StyleShapeSourceType::URL:
AddImageURL(aShapeSource.URL(), aURLs);
break;
case StyleShapeSourceType::Image:
AddImageURL(aShapeSource.ShapeImage(), aURLs);
break;
@ -2561,8 +2558,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetMask() {
!firstLayer.mRepeat.IsInitialValue() ||
!firstLayer.mSize.IsInitialValue() ||
!(firstLayer.mImage.GetType() == eStyleImageType_Null ||
firstLayer.mImage.GetType() == eStyleImageType_Image ||
firstLayer.mImage.GetType() == eStyleImageType_URL)) {
firstLayer.mImage.GetType() == eStyleImageType_Image)) {
return nullptr;
}

View File

@ -171,8 +171,7 @@ enum class StyleScrollbarWidth : uint8_t {
// Shape source type
enum class StyleShapeSourceType : uint8_t {
None,
URL, // clip-path only
Image, // shape-outside only
Image, // shape-outside / clip-path only, and clip-path only uses it for <url>s
Shape,
Box,
Path, // SVG path function

View File

@ -834,7 +834,6 @@ bool StyleShapeSource::operator==(const StyleShapeSource& aOther) const {
case StyleShapeSourceType::None:
return true;
case StyleShapeSourceType::URL:
case StyleShapeSourceType::Image:
return *mShapeImage == *aOther.mShapeImage;
@ -853,16 +852,6 @@ bool StyleShapeSource::operator==(const StyleShapeSource& aOther) const {
return true;
}
void StyleShapeSource::SetURL(const css::URLValue& aValue) {
if (mType != StyleShapeSourceType::Image &&
mType != StyleShapeSourceType::URL) {
DoDestroy();
new (&mShapeImage) UniquePtr<nsStyleImage>(new nsStyleImage());
}
mShapeImage->SetURLValue(do_AddRef(&aValue));
mType = StyleShapeSourceType::URL;
}
void StyleShapeSource::SetShapeImage(UniquePtr<nsStyleImage> aShapeImage) {
MOZ_ASSERT(aShapeImage);
DoDestroy();
@ -922,10 +911,6 @@ void StyleShapeSource::DoCopy(const StyleShapeSource& aOther) {
mType = StyleShapeSourceType::None;
break;
case StyleShapeSourceType::URL:
SetURL(aOther.URL());
break;
case StyleShapeSourceType::Image:
SetShapeImage(MakeUnique<nsStyleImage>(aOther.ShapeImage()));
break;
@ -955,7 +940,6 @@ void StyleShapeSource::DoDestroy() {
mBasicShape.~UniquePtr<StyleBasicShape>();
break;
case StyleShapeSourceType::Image:
case StyleShapeSourceType::URL:
mShapeImage.~UniquePtr<nsStyleImage>();
break;
case StyleShapeSourceType::Path:
@ -1108,6 +1092,7 @@ nsStyleSVGReset::nsStyleSVGReset(const nsStyleSVGReset& aSource)
void nsStyleSVGReset::TriggerImageLoads(Document& aDocument,
const nsStyleSVGReset* aOldStyle) {
MOZ_ASSERT(NS_IsMainThread());
// NOTE(emilio): we intentionally don't call TriggerImageLoads for clip-path.
NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mMask) {
nsStyleImage& image = mMask.mLayers[i].mImage;
@ -2021,8 +2006,6 @@ void nsStyleImage::DoCopy(const nsStyleImage& aOther) {
SetGradientData(aOther.mGradient);
} else if (aOther.mType == eStyleImageType_Element) {
SetElementId(do_AddRef(aOther.mElementId));
} else if (aOther.mType == eStyleImageType_URL) {
SetURLValue(do_AddRef(aOther.mURLValue));
}
UniquePtr<nsStyleSides> cropRectCopy;
@ -2039,10 +2022,6 @@ void nsStyleImage::SetNull() {
NS_RELEASE(mImage);
} else if (mType == eStyleImageType_Element) {
NS_RELEASE(mElementId);
} else if (mType == eStyleImageType_URL) {
// FIXME: NS_RELEASE doesn't handle const gracefully (unlike RefPtr).
const_cast<css::URLValue*>(mURLValue)->Release();
mURLValue = nullptr;
}
mType = eStyleImageType_Null;
@ -2096,19 +2075,6 @@ void nsStyleImage::SetCropRect(UniquePtr<nsStyleSides> aCropRect) {
mCropRect = std::move(aCropRect);
}
void nsStyleImage::SetURLValue(already_AddRefed<const URLValue> aValue) {
RefPtr<const URLValue> value = aValue;
if (mType != eStyleImageType_Null) {
SetNull();
}
if (value) {
mURLValue = value.forget().take();
mType = eStyleImageType_URL;
}
}
static int32_t ConvertToPixelCoord(const nsStyleCoord& aCoord,
int32_t aPercentScale) {
double pixelValue;
@ -2211,7 +2177,7 @@ bool nsStyleImage::IsOpaque() const {
return mGradient->IsOpaque();
}
if (mType == eStyleImageType_Element || mType == eStyleImageType_URL) {
if (mType == eStyleImageType_Element) {
return false;
}
@ -2243,7 +2209,6 @@ bool nsStyleImage::IsComplete() const {
return false;
case eStyleImageType_Gradient:
case eStyleImageType_Element:
case eStyleImageType_URL:
return true;
case eStyleImageType_Image: {
if (!IsResolved()) {
@ -2270,7 +2235,6 @@ bool nsStyleImage::IsLoaded() const {
return false;
case eStyleImageType_Gradient:
case eStyleImageType_Element:
case eStyleImageType_URL:
return true;
case eStyleImageType_Image: {
imgRequestProxy* req = GetImageData();
@ -2315,10 +2279,6 @@ bool nsStyleImage::operator==(const nsStyleImage& aOther) const {
return mElementId == aOther.mElementId;
}
if (mType == eStyleImageType_URL) {
return DefinitelyEqualURIs(mURLValue, aOther.mURLValue);
}
return true;
}
@ -2350,14 +2310,7 @@ already_AddRefed<nsIURI> nsStyleImage::GetImageURI() const {
}
const css::URLValue* nsStyleImage::GetURLValue() const {
if (mType == eStyleImageType_Image) {
return mImage->GetImageValue();
}
if (mType == eStyleImageType_URL) {
return mURLValue;
}
return nullptr;
return mType == eStyleImageType_Image ? mImage->GetImageValue() : nullptr;
}
// --------------------

View File

@ -263,7 +263,6 @@ enum nsStyleImageType {
eStyleImageType_Image,
eStyleImageType_Gradient,
eStyleImageType_Element,
eStyleImageType_URL
};
struct CachedBorderImageData {
@ -308,7 +307,6 @@ struct nsStyleImage {
void SetGradientData(nsStyleGradient* aGradient);
void SetElementId(already_AddRefed<nsAtom> aElementId);
void SetCropRect(mozilla::UniquePtr<nsStyleSides> aCropRect);
void SetURLValue(already_AddRefed<const URLValue> aURLValue);
void ResolveImage(mozilla::dom::Document& aDocument,
const nsStyleImage* aOldImage) {
@ -432,9 +430,6 @@ struct nsStyleImage {
union {
nsStyleImageRequest* mImage;
nsStyleGradient* mGradient;
const URLValue* mURLValue; // See the comment in SetStyleImage's 'case
// eCSSUnit_URL' section to know why we need to
// store URLValues separately from mImage.
nsAtom* mElementId;
};
@ -1598,14 +1593,6 @@ struct StyleShapeSource final {
StyleShapeSourceType GetType() const { return mType; }
const css::URLValue& URL() const {
MOZ_ASSERT(mType == StyleShapeSourceType::URL, "Wrong shape source type!");
MOZ_ASSERT(mShapeImage && mShapeImage->GetURLValue());
return *mShapeImage->GetURLValue();
}
void SetURL(const css::URLValue& aURLValue);
const nsStyleImage& ShapeImage() const {
MOZ_ASSERT(mType == StyleShapeSourceType::Image,
"Wrong shape source type!");

View File

@ -1171,12 +1171,13 @@ static nsSVGPaintingProperty* GetOrCreateClipPathObserver(
"Require first continuation");
const nsStyleSVGReset* svgStyleReset = aClippedFrame->StyleSVGReset();
if (svgStyleReset->mClipPath.GetType() != StyleShapeSourceType::URL) {
if (svgStyleReset->mClipPath.GetType() != StyleShapeSourceType::Image) {
return nullptr;
}
const css::URLValue& url = svgStyleReset->mClipPath.URL();
const css::URLValue* url = svgStyleReset->mClipPath.ShapeImage().GetURLValue();
MOZ_ASSERT(url);
RefPtr<URLAndReferrerInfo> pathURI =
ResolveURLUsingLocalRef(aClippedFrame, &url);
ResolveURLUsingLocalRef(aClippedFrame, url);
return GetPaintingProperty(pathURI, aClippedFrame, ClipPathProperty());
}

View File

@ -54,7 +54,7 @@ bool nsCSSClipPathInstance::HitTestBasicShapeOrPathClip(
MOZ_ASSERT(type != StyleShapeSourceType::None, "unexpected none value");
// In the future nsCSSClipPathInstance may handle <clipPath> references as
// well. For the time being return early.
if (type == StyleShapeSourceType::URL) {
if (type == StyleShapeSourceType::Image) {
return false;
}

View File

@ -457,10 +457,10 @@ void nsSVGUtils::DetermineMaskUsage(nsIFrame* aFrame, bool aHandleOpacity,
// XXX check return value?
SVGObserverUtils::GetAndObserveClipPath(firstFrame, &clipPathFrame);
MOZ_ASSERT(!clipPathFrame ||
svgReset->mClipPath.GetType() == StyleShapeSourceType::URL);
svgReset->mClipPath.GetType() == StyleShapeSourceType::Image);
switch (svgReset->mClipPath.GetType()) {
case StyleShapeSourceType::URL:
case StyleShapeSourceType::Image:
if (clipPathFrame) {
if (clipPathFrame->IsTrivial()) {
aUsage.shouldApplyClipPath = true;

View File

@ -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"),
}
}

View File

@ -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<W>(&self, dest: &mut CssWriter<W>) -> 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<URLValue> {
(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()
}
}

View File

@ -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;

View File

@ -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.