mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Merge css::{URLValueData, ImageValue} into css::URLValue.
Differential Revision: https://phabricator.services.mozilla.com/D8061
This commit is contained in:
parent
cd439df54f
commit
9865a4194c
4 changed files with 80 additions and 102 deletions
|
@ -225,13 +225,13 @@ impl nsStyleImage {
|
||||||
match image {
|
match image {
|
||||||
GenericImage::Gradient(boxed_gradient) => self.set_gradient(*boxed_gradient),
|
GenericImage::Gradient(boxed_gradient) => self.set_gradient(*boxed_gradient),
|
||||||
GenericImage::Url(ref url) => unsafe {
|
GenericImage::Url(ref url) => unsafe {
|
||||||
bindings::Gecko_SetLayerImageImageValue(self, url.0.image_value.get());
|
bindings::Gecko_SetLayerImageImageValue(self, (url.0).0.url_value.get());
|
||||||
},
|
},
|
||||||
GenericImage::Rect(ref image_rect) => {
|
GenericImage::Rect(ref image_rect) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_SetLayerImageImageValue(
|
bindings::Gecko_SetLayerImageImageValue(
|
||||||
self,
|
self,
|
||||||
image_rect.url.0.image_value.get(),
|
(image_rect.url.0).0.url_value.get(),
|
||||||
);
|
);
|
||||||
bindings::Gecko_InitializeImageCropRect(self);
|
bindings::Gecko_InitializeImageCropRect(self);
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
use gecko_bindings::structs::ServoBundledURI;
|
use gecko_bindings::structs::ServoBundledURI;
|
||||||
use gecko_bindings::structs::mozilla::css::URLValueData;
|
|
||||||
use gecko_bindings::structs::root::{RustString, nsStyleImageRequest};
|
use gecko_bindings::structs::root::{RustString, nsStyleImageRequest};
|
||||||
use gecko_bindings::structs::root::mozilla::CORSMode;
|
use gecko_bindings::structs::root::mozilla::CORSMode;
|
||||||
use gecko_bindings::structs::root::mozilla::css::{ImageValue, URLValue};
|
use gecko_bindings::structs::root::mozilla::css::URLValue;
|
||||||
use gecko_bindings::sugar::refptr::RefPtr;
|
use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use nsstring::nsCString;
|
use nsstring::nsCString;
|
||||||
|
@ -38,8 +37,7 @@ pub struct CssUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CssUrl {
|
impl CssUrl {
|
||||||
/// Try to parse a URL from a string value that is a valid CSS token for a
|
/// Parse a URL from a string value that is a valid CSS token for a URL.
|
||||||
/// URL.
|
|
||||||
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
||||||
CssUrl {
|
CssUrl {
|
||||||
serialization: Arc::new(url),
|
serialization: Arc::new(url),
|
||||||
|
@ -54,8 +52,8 @@ impl CssUrl {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from URLValueData to SpecifiedUrl.
|
/// Convert from URLValue to CssUrl.
|
||||||
unsafe fn from_url_value_data(url: &URLValueData) -> Self {
|
unsafe fn from_url_value(url: &URLValue) -> Self {
|
||||||
let arc_type = &url.mString as *const _ as *const RawOffsetArc<String>;
|
let arc_type = &url.mString as *const _ as *const RawOffsetArc<String>;
|
||||||
CssUrl {
|
CssUrl {
|
||||||
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
serialization: Arc::from_raw_offset((*arc_type).clone()),
|
||||||
|
@ -117,7 +115,7 @@ impl MallocSizeOf for CssUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specified url() value for general usage.
|
/// A specified non-image `url()` value.
|
||||||
#[derive(Clone, Debug, SpecifiedValueInfo, ToCss)]
|
#[derive(Clone, Debug, SpecifiedValueInfo, ToCss)]
|
||||||
pub struct SpecifiedUrl {
|
pub struct SpecifiedUrl {
|
||||||
/// The specified url value.
|
/// The specified url value.
|
||||||
|
@ -129,72 +127,19 @@ pub struct SpecifiedUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedUrl {
|
impl SpecifiedUrl {
|
||||||
fn from_css_url(url: CssUrl) -> Self {
|
/// Parse a URL from a string value.
|
||||||
let url_value = unsafe {
|
|
||||||
let ptr = bindings::Gecko_NewURLValue(url.for_ffi());
|
|
||||||
// We do not expect Gecko_NewURLValue returns null.
|
|
||||||
debug_assert!(!ptr.is_null());
|
|
||||||
RefPtr::from_addrefed(ptr)
|
|
||||||
};
|
|
||||||
Self { url, url_value }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for SpecifiedUrl {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.url.eq(&other.url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for SpecifiedUrl {}
|
|
||||||
|
|
||||||
impl Parse for SpecifiedUrl {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
CssUrl::parse(context, input).map(Self::from_css_url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MallocSizeOf for SpecifiedUrl {
|
|
||||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
|
||||||
let mut n = self.url.size_of(ops);
|
|
||||||
// Although this is a RefPtr, this is the primary reference because
|
|
||||||
// SpecifiedUrl is responsible for creating the url_value. So we
|
|
||||||
// measure unconditionally here.
|
|
||||||
n += unsafe { bindings::Gecko_URLValue_SizeOfIncludingThis(self.url_value.get()) };
|
|
||||||
n
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A specified url() value for image.
|
|
||||||
///
|
|
||||||
/// This exists so that we can construct `ImageValue` and reuse it.
|
|
||||||
#[derive(Clone, Debug, SpecifiedValueInfo, ToCss)]
|
|
||||||
pub struct SpecifiedImageUrl {
|
|
||||||
/// The specified url value.
|
|
||||||
pub url: CssUrl,
|
|
||||||
/// Gecko's ImageValue so that we can reuse it while rematching a
|
|
||||||
/// property with this specified value.
|
|
||||||
#[css(skip)]
|
|
||||||
pub image_value: RefPtr<ImageValue>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SpecifiedImageUrl {
|
|
||||||
/// Parse a URL from a string value. See SpecifiedUrl::parse_from_string.
|
|
||||||
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
pub fn parse_from_string(url: String, context: &ParserContext) -> Self {
|
||||||
Self::from_css_url(CssUrl::parse_from_string(url, context))
|
Self::from_css_url(CssUrl::parse_from_string(url, context))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_css_url_with_cors(url: CssUrl, cors: CORSMode) -> Self {
|
fn from_css_url_with_cors(url: CssUrl, cors: CORSMode) -> Self {
|
||||||
let image_value = unsafe {
|
let url_value = unsafe {
|
||||||
let ptr = bindings::Gecko_ImageValue_Create(url.for_ffi(), cors);
|
let ptr = bindings::Gecko_URLValue_Create(url.for_ffi(), cors);
|
||||||
// We do not expect Gecko_ImageValue_Create returns null.
|
// We do not expect Gecko_URLValue_Create returns null.
|
||||||
debug_assert!(!ptr.is_null());
|
debug_assert!(!ptr.is_null());
|
||||||
RefPtr::from_addrefed(ptr)
|
RefPtr::from_addrefed(ptr)
|
||||||
};
|
};
|
||||||
Self { url, image_value }
|
Self { url, url_value }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_css_url(url: CssUrl) -> Self {
|
fn from_css_url(url: CssUrl) -> Self {
|
||||||
|
@ -206,18 +151,9 @@ impl SpecifiedImageUrl {
|
||||||
use gecko_bindings::structs::root::mozilla::CORSMode_CORS_ANONYMOUS;
|
use gecko_bindings::structs::root::mozilla::CORSMode_CORS_ANONYMOUS;
|
||||||
Self::from_css_url_with_cors(url, CORSMode_CORS_ANONYMOUS)
|
Self::from_css_url_with_cors(url, CORSMode_CORS_ANONYMOUS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provides an alternate method for parsing that associates the URL
|
|
||||||
/// with anonymous CORS headers.
|
|
||||||
pub fn parse_with_cors_anonymous<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
CssUrl::parse(context, input).map(Self::from_css_url_with_cors_anonymous)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for SpecifiedImageUrl {
|
impl Parse for SpecifiedUrl {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
|
@ -226,21 +162,21 @@ impl Parse for SpecifiedImageUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for SpecifiedImageUrl {
|
impl PartialEq for SpecifiedUrl {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.url.eq(&other.url)
|
self.url.eq(&other.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for SpecifiedImageUrl {}
|
impl Eq for SpecifiedUrl {}
|
||||||
|
|
||||||
impl MallocSizeOf for SpecifiedImageUrl {
|
impl MallocSizeOf for SpecifiedUrl {
|
||||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||||
let mut n = self.url.size_of(ops);
|
let mut n = self.url.size_of(ops);
|
||||||
// Although this is a RefPtr, this is the primary reference because
|
// Although this is a RefPtr, this is the primary reference because
|
||||||
// SpecifiedUrl is responsible for creating the image_value. So we
|
// SpecifiedUrl is responsible for creating the url_value. So we
|
||||||
// measure unconditionally here.
|
// measure unconditionally here.
|
||||||
n += unsafe { bindings::Gecko_ImageValue_SizeOfIncludingThis(self.image_value.get()) };
|
n += unsafe { bindings::Gecko_URLValue_SizeOfIncludingThis(self.url_value.get()) };
|
||||||
n
|
n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,6 +195,37 @@ impl ToComputedValue for SpecifiedUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A specified image `url()` value.
|
||||||
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||||
|
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) -> Self {
|
||||||
|
SpecifiedImageUrl(SpecifiedUrl::parse_from_string(url, context))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provides an alternate method for parsing that associates the URL
|
||||||
|
/// with anonymous CORS headers.
|
||||||
|
pub fn parse_with_cors_anonymous<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
CssUrl::parse(context, input)
|
||||||
|
.map(SpecifiedUrl::from_css_url_with_cors_anonymous)
|
||||||
|
.map(SpecifiedImageUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
impl ToComputedValue for SpecifiedImageUrl {
|
||||||
type ComputedValue = ComputedImageUrl;
|
type ComputedValue = ComputedImageUrl;
|
||||||
|
|
||||||
|
@ -274,9 +241,9 @@ impl ToComputedValue for SpecifiedImageUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_computed_url<W>(
|
fn serialize_computed_url<W>(
|
||||||
url_value_data: &URLValueData,
|
url_value: &URLValue,
|
||||||
dest: &mut CssWriter<W>,
|
dest: &mut CssWriter<W>,
|
||||||
get_url: unsafe extern "C" fn(*const URLValueData, *mut nsCString),
|
get_url: unsafe extern "C" fn(*const URLValue, *mut nsCString) -> (),
|
||||||
) -> fmt::Result
|
) -> fmt::Result
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
@ -284,13 +251,13 @@ where
|
||||||
dest.write_str("url(")?;
|
dest.write_str("url(")?;
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut string = nsCString::new();
|
let mut string = nsCString::new();
|
||||||
get_url(url_value_data, &mut string);
|
get_url(url_value, &mut string);
|
||||||
string.as_str_unchecked().to_css(dest)?;
|
string.as_str_unchecked().to_css(dest)?;
|
||||||
}
|
}
|
||||||
dest.write_char(')')
|
dest.write_char(')')
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The computed value of a CSS `url()`.
|
/// The computed value of a CSS non-image `url()`.
|
||||||
///
|
///
|
||||||
/// The only difference between specified and computed URLs is the
|
/// The only difference between specified and computed URLs is the
|
||||||
/// serialization.
|
/// serialization.
|
||||||
|
@ -303,7 +270,7 @@ impl ToCss for ComputedUrl {
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
serialize_computed_url(
|
serialize_computed_url(
|
||||||
&self.0.url_value._base,
|
&self.0.url_value,
|
||||||
dest,
|
dest,
|
||||||
bindings::Gecko_GetComputedURLSpec,
|
bindings::Gecko_GetComputedURLSpec,
|
||||||
)
|
)
|
||||||
|
@ -313,12 +280,17 @@ impl ToCss for ComputedUrl {
|
||||||
impl ComputedUrl {
|
impl ComputedUrl {
|
||||||
/// Convert from RefPtr<URLValue> to ComputedUrl.
|
/// Convert from RefPtr<URLValue> to ComputedUrl.
|
||||||
pub unsafe fn from_url_value(url_value: RefPtr<URLValue>) -> Self {
|
pub unsafe fn from_url_value(url_value: RefPtr<URLValue>) -> Self {
|
||||||
let url = CssUrl::from_url_value_data(&url_value._base);
|
let url = CssUrl::from_url_value(&*url_value);
|
||||||
ComputedUrl(SpecifiedUrl { url, url_value })
|
ComputedUrl(SpecifiedUrl { url, url_value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a raw pointer to the URLValue held by this ComputedUrl, for FFI.
|
||||||
|
pub fn url_value_ptr(&self) -> *mut URLValue {
|
||||||
|
self.0.url_value.get()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The computed value of a CSS `url()` for image.
|
/// The computed value of a CSS image `url()`.
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
|
||||||
pub struct ComputedImageUrl(pub SpecifiedImageUrl);
|
pub struct ComputedImageUrl(pub SpecifiedImageUrl);
|
||||||
|
|
||||||
|
@ -328,7 +300,7 @@ impl ToCss for ComputedImageUrl {
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
serialize_computed_url(
|
serialize_computed_url(
|
||||||
&self.0.image_value._base,
|
&(self.0).0.url_value,
|
||||||
dest,
|
dest,
|
||||||
bindings::Gecko_GetComputedImageURLSpec,
|
bindings::Gecko_GetComputedImageURLSpec,
|
||||||
)
|
)
|
||||||
|
@ -338,8 +310,13 @@ impl ToCss for ComputedImageUrl {
|
||||||
impl ComputedImageUrl {
|
impl ComputedImageUrl {
|
||||||
/// Convert from nsStyleImageReques to ComputedImageUrl.
|
/// Convert from nsStyleImageReques to ComputedImageUrl.
|
||||||
pub unsafe fn from_image_request(image_request: &nsStyleImageRequest) -> Self {
|
pub unsafe fn from_image_request(image_request: &nsStyleImageRequest) -> Self {
|
||||||
let image_value = image_request.mImageValue.to_safe();
|
let url_value = image_request.mImageValue.to_safe();
|
||||||
let url = CssUrl::from_url_value_data(&image_value._base);
|
let url = CssUrl::from_url_value(&*url_value);
|
||||||
ComputedImageUrl(SpecifiedImageUrl { url, image_value })
|
ComputedImageUrl(SpecifiedImageUrl(SpecifiedUrl { url, 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.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,11 +297,6 @@ impl_threadsafe_refcount!(
|
||||||
bindings::Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
bindings::Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
||||||
bindings::Gecko_ReleaseGridTemplateAreasValueArbitraryThread
|
bindings::Gecko_ReleaseGridTemplateAreasValueArbitraryThread
|
||||||
);
|
);
|
||||||
impl_threadsafe_refcount!(
|
|
||||||
structs::ImageValue,
|
|
||||||
bindings::Gecko_AddRefImageValueArbitraryThread,
|
|
||||||
bindings::Gecko_ReleaseImageValueArbitraryThread
|
|
||||||
);
|
|
||||||
impl_threadsafe_refcount!(
|
impl_threadsafe_refcount!(
|
||||||
structs::SharedFontList,
|
structs::SharedFontList,
|
||||||
bindings::Gecko_AddRefSharedFontListArbitraryThread,
|
bindings::Gecko_AddRefSharedFontListArbitraryThread,
|
||||||
|
|
|
@ -689,7 +689,10 @@ def set_gecko_property(ffi_name, expr):
|
||||||
}
|
}
|
||||||
SVGPaintKind::PaintServer(url) => {
|
SVGPaintKind::PaintServer(url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_nsStyleSVGPaint_SetURLValue(paint, url.0.url_value.get());
|
bindings::Gecko_nsStyleSVGPaint_SetURLValue(
|
||||||
|
paint,
|
||||||
|
url.url_value_ptr(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SVGPaintKind::Color(color) => {
|
SVGPaintKind::Color(color) => {
|
||||||
|
@ -4153,7 +4156,10 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
UrlOrNone::Url(ref url) => {
|
UrlOrNone::Url(ref url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_SetListStyleImageImageValue(&mut self.gecko, url.0.image_value.get());
|
Gecko_SetListStyleImageImageValue(
|
||||||
|
&mut self.gecko,
|
||||||
|
url.url_value_ptr(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5358,7 +5364,7 @@ clip-path
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_SetCursorImageValue(
|
Gecko_SetCursorImageValue(
|
||||||
&mut self.gecko.mCursorImages[i],
|
&mut self.gecko.mCursorImages[i],
|
||||||
v.images[i].url.0.image_value.get(),
|
v.images[i].url.url_value_ptr(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5659,7 +5665,7 @@ clip-path
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_SetContentDataImageValue(
|
bindings::Gecko_SetContentDataImageValue(
|
||||||
&mut self.gecko.mContents[i],
|
&mut self.gecko.mContents[i],
|
||||||
url.0.image_value.get(),
|
url.url_value_ptr(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue