mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
stylo: Use ServoBundledURI everywhere else, fix from_ffi to handle the error case
MozReview-Commit-ID: DHNKLm3y5Gv
This commit is contained in:
parent
808ffffd1e
commit
77d7490d59
4 changed files with 41 additions and 62 deletions
|
@ -106,18 +106,8 @@ impl nsStyleImage {
|
||||||
self.set_gradient(gradient)
|
self.set_gradient(gradient)
|
||||||
},
|
},
|
||||||
Image::Url(ref url) if with_url => {
|
Image::Url(ref url) if with_url => {
|
||||||
let (ptr, len) = match url.as_slice_components() {
|
|
||||||
Ok(value) | Err(value) => value
|
|
||||||
};
|
|
||||||
let extra_data = url.extra_data();
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_SetUrlImageValue(self,
|
Gecko_SetUrlImageValue(self, url.for_ffi());
|
||||||
ptr,
|
|
||||||
len as u32,
|
|
||||||
extra_data.base.get(),
|
|
||||||
extra_data.referrer.get(),
|
|
||||||
extra_data.principal.get());
|
|
||||||
}
|
|
||||||
// We unfortunately must make any url() value uncacheable, since
|
// We unfortunately must make any url() value uncacheable, since
|
||||||
// the applicable declarations cache is not per document, but
|
// the applicable declarations cache is not per document, but
|
||||||
// global, and the imgRequestProxy objects we store in the style
|
// global, and the imgRequestProxy objects we store in the style
|
||||||
|
@ -126,6 +116,7 @@ impl nsStyleImage {
|
||||||
// FIXME(emilio): With the scoped TLS thing this is no longer
|
// FIXME(emilio): With the scoped TLS thing this is no longer
|
||||||
// true, remove this line in a follow-up!
|
// true, remove this line in a follow-up!
|
||||||
*cacheable = false;
|
*cacheable = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -631,10 +631,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_SetUrlImageValue(image: *mut nsStyleImage,
|
pub fn Gecko_SetUrlImageValue(image: *mut nsStyleImage,
|
||||||
url_bytes: *const u8, url_length: u32,
|
uri: ServoBundledURI);
|
||||||
base_uri: *mut ThreadSafeURIHolder,
|
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
|
||||||
principal: *mut ThreadSafePrincipalHolder);
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
|
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
|
||||||
|
@ -662,10 +659,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_SetCursorImage(cursor: *mut nsCursorImage,
|
pub fn Gecko_SetCursorImage(cursor: *mut nsCursorImage,
|
||||||
string_bytes: *const u8, string_length: u32,
|
uri: ServoBundledURI);
|
||||||
base_uri: *mut ThreadSafeURIHolder,
|
|
||||||
referrer: *mut ThreadSafeURIHolder,
|
|
||||||
principal: *mut ThreadSafePrincipalHolder);
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_CopyCursorArrayFrom(dest: *mut nsStyleUserInterface,
|
pub fn Gecko_CopyCursorArrayFrom(dest: *mut nsStyleUserInterface,
|
||||||
|
|
|
@ -394,11 +394,7 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
||||||
}
|
}
|
||||||
SVGPaintKind::PaintServer(url) => {
|
SVGPaintKind::PaintServer(url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(ffi) = url.for_ffi() {
|
bindings::Gecko_nsStyleSVGPaint_SetURLValue(paint, url.for_ffi());
|
||||||
bindings::Gecko_nsStyleSVGPaint_SetURLValue(paint, ffi);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SVGPaintKind::Color(color) => {
|
SVGPaintKind::Color(color) => {
|
||||||
|
@ -511,20 +507,26 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="impl_css_url(ident, gecko_ffi_name, need_clone=False)">
|
<%def name="impl_css_url(ident, gecko_ffi_name, need_clone=False, only_resolved=False)">
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||||
use gecko_bindings::sugar::refptr::RefPtr;
|
use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
match v {
|
match v {
|
||||||
Either::First(url) => {
|
Either::First(url) => {
|
||||||
let refptr = unsafe {
|
let refptr = unsafe {
|
||||||
if let Some(ffi) = url.for_ffi() {
|
% if only_resolved:
|
||||||
let ptr = bindings::Gecko_NewURLValue(ffi);
|
// -moz-binding can't handle relative URIs
|
||||||
RefPtr::from_addrefed(ptr)
|
if !url.has_resolved() {
|
||||||
} else {
|
|
||||||
self.gecko.${gecko_ffi_name}.clear();
|
self.gecko.${gecko_ffi_name}.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
% endif
|
||||||
|
let ptr = bindings::Gecko_NewURLValue(url.for_ffi());
|
||||||
|
if ptr.is_null() {
|
||||||
|
self.gecko.${gecko_ffi_name}.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RefPtr::from_addrefed(ptr)
|
||||||
};
|
};
|
||||||
self.gecko.${gecko_ffi_name}.set_move(refptr)
|
self.gecko.${gecko_ffi_name}.set_move(refptr)
|
||||||
}
|
}
|
||||||
|
@ -1423,7 +1425,7 @@ fn static_assert() {
|
||||||
page-break-before page-break-after
|
page-break-before page-break-after
|
||||||
scroll-snap-points-x scroll-snap-points-y transform
|
scroll-snap-points-x scroll-snap-points-y transform
|
||||||
scroll-snap-type-y scroll-snap-coordinate
|
scroll-snap-type-y scroll-snap-coordinate
|
||||||
perspective-origin transform-origin""" %>
|
perspective-origin transform-origin -moz-binding""" %>
|
||||||
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
||||||
|
|
||||||
// We manually-implement the |display| property until we get general
|
// We manually-implement the |display| property until we get general
|
||||||
|
@ -1611,6 +1613,8 @@ fn static_assert() {
|
||||||
longhands::scroll_snap_coordinate::computed_value::T(vec)
|
longhands::scroll_snap_coordinate::computed_value::T(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${impl_css_url('_moz_binding', 'mBinding', only_resolved=True)}
|
||||||
|
|
||||||
<%def name="transform_function_arm(name, keyword, items)">
|
<%def name="transform_function_arm(name, keyword, items)">
|
||||||
<%
|
<%
|
||||||
pattern = None
|
pattern = None
|
||||||
|
@ -2281,12 +2285,8 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
Either::First(ref url) => {
|
Either::First(ref url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(ffi) = url.for_ffi() {
|
|
||||||
Gecko_SetListStyleImage(&mut self.gecko,
|
Gecko_SetListStyleImage(&mut self.gecko,
|
||||||
ffi);
|
url.for_ffi());
|
||||||
} else {
|
|
||||||
Gecko_SetListStyleImageNone(&mut self.gecko);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// We don't need to record this struct as uncacheable, like when setting
|
// We don't need to record this struct as uncacheable, like when setting
|
||||||
// background-image to a url() value, since only properties in reset structs
|
// background-image to a url() value, since only properties in reset structs
|
||||||
|
@ -2575,9 +2575,7 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
Url(ref url) => {
|
Url(ref url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(ffi) = url.for_ffi() {
|
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url.for_ffi());
|
||||||
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, ffi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2940,9 +2938,7 @@ clip-path
|
||||||
match v {
|
match v {
|
||||||
ShapeSource::Url(ref url) => {
|
ShapeSource::Url(ref url) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(ffi) = url.for_ffi() {
|
bindings::Gecko_StyleClipPath_SetURLValue(clip_path, url.for_ffi());
|
||||||
bindings::Gecko_StyleClipPath_SetURLValue(clip_path, ffi);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShapeSource::None => {} // don't change the type
|
ShapeSource::None => {} // don't change the type
|
||||||
|
@ -3150,16 +3146,8 @@ clip-path
|
||||||
}
|
}
|
||||||
for i in 0..v.images.len() {
|
for i in 0..v.images.len() {
|
||||||
let image = &v.images[i];
|
let image = &v.images[i];
|
||||||
let extra_data = image.url.extra_data();
|
|
||||||
let (ptr, len) = match image.url.as_slice_components() {
|
|
||||||
Ok(value) | Err(value) => value,
|
|
||||||
};
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_SetCursorImage(&mut self.gecko.mCursorImages[i],
|
Gecko_SetCursorImage(&mut self.gecko.mCursorImages[i], image.url.for_ffi());
|
||||||
ptr, len as u32,
|
|
||||||
extra_data.base.get(),
|
|
||||||
extra_data.referrer.get(),
|
|
||||||
extra_data.principal.get());
|
|
||||||
}
|
}
|
||||||
// We don't need to record this struct as uncacheable, like when setting
|
// We don't need to record this struct as uncacheable, like when setting
|
||||||
// background-image to a url() value, since only properties in reset structs
|
// background-image to a url() value, since only properties in reset structs
|
||||||
|
|
|
@ -150,6 +150,11 @@ impl SpecifiedUrl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if it has a resolved URI
|
||||||
|
pub fn has_resolved(&self) -> bool {
|
||||||
|
self.resolved.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates an already specified url value from an already resolved URL
|
/// Creates an already specified url value from an already resolved URL
|
||||||
/// for insertion in the cascade.
|
/// for insertion in the cascade.
|
||||||
pub fn for_cascade(url: ServoUrl, extra_data: UrlExtraData) -> Self {
|
pub fn for_cascade(url: ServoUrl, extra_data: UrlExtraData) -> Self {
|
||||||
|
@ -173,19 +178,20 @@ impl SpecifiedUrl {
|
||||||
/// Create a bundled URI suitable for sending to Gecko
|
/// Create a bundled URI suitable for sending to Gecko
|
||||||
/// to be constructed into a css::URLValue
|
/// to be constructed into a css::URLValue
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub fn for_ffi(&self) -> Option<ServoBundledURI> {
|
pub fn for_ffi(&self) -> ServoBundledURI {
|
||||||
let extra_data = self.extra_data();
|
let extra_data = self.extra_data();
|
||||||
let (ptr, len) = match self.as_slice_components() {
|
let (ptr, len) = match self.as_slice_components() {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(_) => return None,
|
// we're okay with passing down the unresolved relative URI
|
||||||
|
Err(value) => value,
|
||||||
};
|
};
|
||||||
Some(ServoBundledURI {
|
ServoBundledURI {
|
||||||
mURLString: ptr,
|
mURLString: ptr,
|
||||||
mURLStringLength: len as u32,
|
mURLStringLength: len as u32,
|
||||||
mBaseURI: extra_data.base.get(),
|
mBaseURI: extra_data.base.get(),
|
||||||
mReferrer: extra_data.referrer.get(),
|
mReferrer: extra_data.referrer.get(),
|
||||||
mPrincipal: extra_data.principal.get(),
|
mPrincipal: extra_data.principal.get(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue