Bug 1942816 - Simplify computed/specified url split. r=dshin

This was only needed because computed images serialized differently, but
we fixed that in bug 1738693.

Differential Revision: https://phabricator.services.mozilla.com/D234968
This commit is contained in:
Emilio Cobos Álvarez
2025-01-21 15:02:57 +00:00
parent 94ea87970f
commit 9b3e0ffaaa
17 changed files with 27 additions and 122 deletions

View File

@@ -1113,16 +1113,6 @@ void Gecko_GetComputedURLSpec(const StyleComputedUrl* aURL, nsCString* aOut) {
aOut->Assign(aURL->SpecifiedSerialization());
return;
}
Gecko_GetComputedImageURLSpec(aURL, aOut);
}
void Gecko_GetComputedImageURLSpec(const StyleComputedUrl* aURL,
nsCString* aOut) {
if (aURL->IsLocalRef() &&
StaticPrefs::layout_css_computed_style_dont_resolve_image_local_refs()) {
aOut->Assign(aURL->SpecifiedSerialization());
return;
}
if (nsIURI* uri = aURL->GetURI()) {
nsresult rv = uri->GetSpec(*aOut);

View File

@@ -318,8 +318,8 @@ void Gecko_CopyImageOrientationFrom(nsStyleVisibility* aDst,
// list-style-image style.
void Gecko_SetListStyleImageNone(nsStyleList* style_struct);
void Gecko_SetListStyleImageImageValue(
nsStyleList* style_struct, const mozilla::StyleComputedImageUrl* url);
void Gecko_SetListStyleImageImageValue(nsStyleList* style_struct,
const mozilla::StyleComputedUrl* url);
void Gecko_CopyListStyleImageFrom(nsStyleList* dest, const nsStyleList* src);
@@ -425,9 +425,6 @@ void Gecko_nsStyleSVG_CopyContextProperties(nsStyleSVG* dst,
void Gecko_GetComputedURLSpec(const mozilla::StyleComputedUrl* url,
nsCString* spec);
void Gecko_GetComputedImageURLSpec(const mozilla::StyleComputedUrl* url,
nsCString* spec);
// Return true if the given image MIME type is supported
bool Gecko_IsSupportedImageMimeType(const uint8_t* mime_type,
const uint32_t len);

View File

@@ -405,7 +405,7 @@ void ImageLoader::ClearFrames(nsPresContext* aPresContext) {
}
static CORSMode EffectiveCorsMode(nsIURI* aURI,
const StyleComputedImageUrl& aImage) {
const StyleComputedUrl& aImage) {
MOZ_ASSERT(aURI);
StyleCorsMode mode = aImage.CorsMode();
if (mode == StyleCorsMode::None) {
@@ -420,7 +420,7 @@ static CORSMode EffectiveCorsMode(nsIURI* aURI,
/* static */
already_AddRefed<imgRequestProxy> ImageLoader::LoadImage(
const StyleComputedImageUrl& aImage, Document& aDocument) {
const StyleComputedUrl& aImage, Document& aDocument) {
MOZ_ASSERT(NS_IsMainThread());
nsIURI* uri = aImage.GetURI();
if (!uri) {

View File

@@ -533,9 +533,7 @@ cbindgen-types = [
{ gecko = "StyleGenericCalcNode", servo = "crate::values::generics::calc::GenericCalcNode" },
{ gecko = "StyleCssUrl", servo = "crate::gecko::url::CssUrl" },
{ gecko = "StyleSpecifiedUrl", servo = "crate::gecko::url::SpecifiedUrl" },
{ gecko = "StyleSpecifiedImageUrl", servo = "crate::gecko::url::SpecifiedImageUrl" },
{ gecko = "StyleComputedUrl", servo = "crate::gecko::url::ComputedUrl" },
{ gecko = "StyleComputedImageUrl", servo = "crate::gecko::url::ComputedImageUrl" },
{ gecko = "StyleLoadData", servo = "crate::gecko::url::LoadData" },
{ gecko = "StyleGenericFilter", servo = "crate::values::generics::effects::Filter" },
{ gecko = "StyleGenericGradient", servo = "crate::values::generics::image::Gradient" },

View File

@@ -442,11 +442,11 @@ inline bool StyleComputedUrl::HasRef() const {
return false;
}
inline bool StyleComputedImageUrl::IsImageResolved() const {
inline bool StyleComputedUrl::IsImageResolved() const {
return bool(LoadData().flags & StyleLoadDataFlags::TRIED_TO_RESOLVE_IMAGE);
}
inline imgRequestProxy* StyleComputedImageUrl::GetImage() const {
inline imgRequestProxy* StyleComputedUrl::GetImage() const {
MOZ_ASSERT(IsImageResolved());
return LoadData().resolved_image;
}
@@ -1005,8 +1005,7 @@ inline bool StyleImage::IsImageRequestType() const {
}
template <>
inline const StyleComputedImageUrl* StyleImage::GetImageRequestURLValue()
const {
inline const StyleComputedUrl* StyleImage::GetImageRequestURLValue() const {
const auto& finalImage = FinalImage();
if (finalImage.IsUrl()) {
return &finalImage.AsUrl();

View File

@@ -1550,7 +1550,7 @@ void StyleImage::ResolveImage(Document& aDoc, const StyleImage* aOld) {
const auto* url = GetImageRequestURLValue();
// We could avoid this const_cast generating more code but it's not really
// worth it.
const_cast<StyleComputedImageUrl*>(url)->ResolveImage(aDoc, old);
const_cast<StyleComputedUrl*>(url)->ResolveImage(aDoc, old);
}
template <>
@@ -1903,7 +1903,7 @@ bool nsStyleImageLayers::Layer::operator==(const Layer& aOther) const {
template <class ComputedValueItem>
static void FillImageLayerList(
nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
ComputedValueItem nsStyleImageLayers::Layer::*aResultLocation,
ComputedValueItem nsStyleImageLayers::Layer::* aResultLocation,
uint32_t aItemCount, uint32_t aFillCount) {
MOZ_ASSERT(aFillCount <= aLayers.Length(), "unexpected array length");
for (uint32_t sourceLayer = 0, destLayer = aItemCount; destLayer < aFillCount;
@@ -1916,7 +1916,7 @@ static void FillImageLayerList(
// layer.mPosition.*aResultLocation instead of layer.*aResultLocation.
static void FillImageLayerPositionCoordList(
nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
LengthPercentage Position::*aResultLocation, uint32_t aItemCount,
LengthPercentage Position::* aResultLocation, uint32_t aItemCount,
uint32_t aFillCount) {
MOZ_ASSERT(aFillCount <= aLayers.Length(), "unexpected array length");
for (uint32_t sourceLayer = 0, destLayer = aItemCount; destLayer < aFillCount;

View File

@@ -133,7 +133,7 @@ static already_AddRefed<nsIURI> GetBaseURLForLocalRef(nsIContent* content,
}
static already_AddRefed<URLAndReferrerInfo> ResolveURLUsingLocalRef(
nsIFrame* aFrame, const StyleComputedImageUrl& aURL) {
nsIFrame* aFrame, const StyleComputedUrl& aURL) {
MOZ_ASSERT(aFrame);
nsCOMPtr<nsIURI> uri = aURL.GetURI();
@@ -1016,7 +1016,7 @@ SVGMaskObserverList::SVGMaskObserverList(nsIFrame* aFrame) : mFrame(aFrame) {
const nsStyleSVGReset* svgReset = aFrame->StyleSVGReset();
for (uint32_t i = 0; i < svgReset->mMask.mImageCount; i++) {
const StyleComputedImageUrl* data =
const StyleComputedUrl* data =
svgReset->mMask.mLayers[i].mImage.GetImageRequestURLValue();
RefPtr<URLAndReferrerInfo> maskUri;
if (data) {

View File

@@ -9315,16 +9315,6 @@
value: true
mirror: always
# Whether computed local-fragment-only image urls serialize using the same
# rules as filter/mask/etc (not resolving the URL for local refs).
#
# See https://github.com/w3c/csswg-drafts/issues/3195
- name: layout.css.computed-style.dont-resolve-image-local-refs
type: RelaxedAtomicBool
value: true
mirror: always
rust: true
# Are implicit tracks in computed grid templates serialized?
- name: layout.css.serialize-grid-implicit-tracks
type: RelaxedAtomicBool

View File

@@ -60,7 +60,8 @@ impl PartialEq for CssUrlData {
}
impl CssUrl {
fn parse_with_cors_mode<'i, 't>(
/// Parse a URL with a particular CORS mode.
pub fn parse_with_cors_mode<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
cors_mode: CorsMode,
@@ -278,52 +279,6 @@ impl ToComputedValue for SpecifiedUrl {
}
}
/// A specified image `url()` value.
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub struct SpecifiedImageUrl(pub SpecifiedUrl);
impl SpecifiedImageUrl {
/// Parse a URL from a string value that is a valid CSS token for a URL.
pub fn parse_from_string(url: String, context: &ParserContext, cors_mode: CorsMode) -> Self {
SpecifiedImageUrl(SpecifiedUrl::parse_from_string(url, context, cors_mode))
}
/// Provides an alternate method for parsing that associates the URL
/// with anonymous CORS headers.
pub fn parse_with_cors_mode<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
cors_mode: CorsMode,
) -> Result<Self, ParseError<'i>> {
Ok(SpecifiedImageUrl(SpecifiedUrl::parse_with_cors_mode(
context, input, cors_mode,
)?))
}
}
impl Parse for SpecifiedImageUrl {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
SpecifiedUrl::parse(context, input).map(SpecifiedImageUrl)
}
}
impl ToComputedValue for SpecifiedImageUrl {
type ComputedValue = ComputedImageUrl;
#[inline]
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 {
SpecifiedImageUrl(ToComputedValue::from_computed_value(&computed.0))
}
}
/// The computed value of a CSS non-image `url()`.
///
/// The only difference between specified and computed URLs is the
@@ -360,21 +315,6 @@ impl ToCss for ComputedUrl {
}
}
/// The computed value of a CSS image `url()`.
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
#[repr(transparent)]
pub struct ComputedImageUrl(pub ComputedUrl);
impl ToCss for ComputedImageUrl {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
self.0
.serialize_with(bindings::Gecko_GetComputedImageURLSpec, dest)
}
}
lazy_static! {
/// A table mapping CssUrlData objects to their lazily created LoadData
/// objects.

View File

@@ -204,9 +204,6 @@ impl ToComputedValue for SpecifiedUrl {
}
}
/// A specified image url() value for servo.
pub type SpecifiedImageUrl = CssUrl;
/// The computed value of a CSS `url()`, resolved relative to the stylesheet URL.
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub enum ComputedUrl {
@@ -241,6 +238,3 @@ impl ToCss for ComputedUrl {
dest.write_char(')')
}
}
/// The computed value of a CSS `url()` for image.
pub type ComputedImageUrl = ComputedUrl;

View File

@@ -9,7 +9,7 @@
use crate::values::computed::percentage::Percentage;
use crate::values::computed::position::Position;
use crate::values::computed::url::ComputedImageUrl;
use crate::values::computed::url::ComputedUrl;
use crate::values::computed::{Angle, Color, Context};
use crate::values::computed::{
AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage,
@@ -26,7 +26,7 @@ pub use specified::ImageRendering;
/// Computed values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = generic::GenericImage<Gradient, ComputedImageUrl, Color, Percentage, Resolution>;
pub type Image = generic::GenericImage<Gradient, ComputedUrl, Color, Percentage, Resolution>;
// Images should remain small, see https://github.com/servo/servo/pull/18430
size_of_test!(Image, 16);

View File

@@ -7,9 +7,9 @@
use crate::values::generics::url::UrlOrNone as GenericUrlOrNone;
#[cfg(feature = "gecko")]
pub use crate::gecko::url::{ComputedImageUrl, ComputedUrl};
pub use crate::gecko::url::ComputedUrl;
#[cfg(feature = "servo")]
pub use crate::servo::url::{ComputedImageUrl, ComputedUrl};
pub use crate::servo::url::ComputedUrl;
/// Computed <url> | <none>
pub type UrlOrNone = GenericUrlOrNone<ComputedUrl>;

View File

@@ -95,8 +95,6 @@ trivial_to_resolved_value!(crate::values::AtomIdent);
trivial_to_resolved_value!(crate::custom_properties::VariableValue);
trivial_to_resolved_value!(crate::stylesheets::UrlExtraData);
trivial_to_resolved_value!(computed::url::ComputedUrl);
#[cfg(feature = "gecko")]
trivial_to_resolved_value!(computed::url::ComputedImageUrl);
#[cfg(feature = "servo")]
trivial_to_resolved_value!(crate::Namespace);
#[cfg(feature = "servo")]

View File

@@ -19,7 +19,7 @@ use crate::values::generics::position::Position as GenericPosition;
use crate::values::generics::NonNegative;
use crate::values::specified::position::{HorizontalPositionKeyword, VerticalPositionKeyword};
use crate::values::specified::position::{Position, PositionComponent, Side};
use crate::values::specified::url::SpecifiedImageUrl;
use crate::values::specified::url::SpecifiedUrl;
use crate::values::specified::{
Angle, AngleOrPercentage, Color, Length, LengthPercentage, NonNegativeLength,
NonNegativeLengthPercentage, Resolution,
@@ -40,7 +40,7 @@ fn gradient_color_interpolation_method_enabled() -> bool {
/// Specified values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = generic::Image<Gradient, SpecifiedImageUrl, Color, Percentage, Resolution>;
pub type Image = generic::Image<Gradient, SpecifiedUrl, Color, Percentage, Resolution>;
// Images should remain small, see https://github.com/servo/servo/pull/18430
size_of_test!(Image, 16);
@@ -216,7 +216,7 @@ impl Image {
}
if let Ok(url) = input
.try_parse(|input| SpecifiedImageUrl::parse_with_cors_mode(context, input, cors_mode))
.try_parse(|input| SpecifiedUrl::parse_with_cors_mode(context, input, cors_mode))
{
return Ok(generic::Image::Url(url));
}
@@ -419,7 +419,7 @@ impl ImageSetItem {
flags: ParseImageFlags,
) -> Result<Self, ParseError<'i>> {
let image = match input.try_parse(|i| i.expect_url_or_string()) {
Ok(url) => Image::Url(SpecifiedImageUrl::parse_from_string(
Ok(url) => Image::Url(SpecifiedUrl::parse_from_string(
url.as_ref().into(),
context,
cors_mode,

View File

@@ -7,9 +7,9 @@
use crate::values::generics::url::GenericUrlOrNone;
#[cfg(feature = "gecko")]
pub use crate::gecko::url::{SpecifiedImageUrl, SpecifiedUrl};
pub use crate::gecko::url::SpecifiedUrl;
#[cfg(feature = "servo")]
pub use crate::servo::url::{SpecifiedImageUrl, SpecifiedUrl};
pub use crate::servo::url::SpecifiedUrl;
/// Specified <url> | <none>
pub type UrlOrNone = GenericUrlOrNone<SpecifiedUrl>;

View File

@@ -257,7 +257,6 @@ include = [
"Translate",
"BorderImageWidth",
"ComputedUrl",
"ComputedImageUrl",
"UrlOrNone",
"Filter",
"Gradient",
@@ -946,7 +945,7 @@ renaming_overrides_prefixing = true
bool IsImageRequestType() const;
// Gets the image request URL.
const StyleComputedImageUrl* GetImageRequestURLValue() const;
const StyleComputedUrl* GetImageRequestURLValue() const;
// Gets the image data of this image if it has any image request.
imgRequestProxy* GetImageRequest() const;

View File

@@ -5937,7 +5937,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(
use style::properties::PropertyDeclaration;
use style::stylesheets::CorsMode;
use style::values::generics::image::Image;
use style::values::specified::url::SpecifiedImageUrl;
use style::values::specified::url::SpecifiedUrl;
let url_data = UrlExtraData::from_ptr_ref(&raw_extra_data);
let string = value.as_str_unchecked();
@@ -5951,7 +5951,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(
None,
None,
);
let url = SpecifiedImageUrl::parse_from_string(string.into(), &context, CorsMode::None);
let url = SpecifiedUrl::parse_from_string(string.into(), &context, CorsMode::None);
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(vec![Image::Url(url)].into()));
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
decls.push(decl, Importance::Normal);