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:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user