stylo: Add mako template for URLOrNone, use for marker-* properties

MozReview-Commit-ID: 4QKKzJ1DVYP
This commit is contained in:
Manish Goregaokar 2017-02-09 17:43:52 -08:00 committed by Manish Goregaokar
parent 3b0840d187
commit fa9881b829
7 changed files with 92 additions and 39 deletions

View file

@ -508,6 +508,7 @@ mod bindings {
.whitelisted_function("Servo_.*") .whitelisted_function("Servo_.*")
.whitelisted_function("Gecko_.*"); .whitelisted_function("Gecko_.*");
let structs_types = [ let structs_types = [
"mozilla::css::URLValue",
"RawGeckoDocument", "RawGeckoDocument",
"RawGeckoElement", "RawGeckoElement",
"RawGeckoKeyframeList", "RawGeckoKeyframeList",

View file

@ -3,6 +3,7 @@
pub use nsstring::{nsACString, nsAString}; pub use nsstring::{nsACString, nsAString};
type nsACString_internal = nsACString; type nsACString_internal = nsACString;
type nsAString_internal = nsAString; type nsAString_internal = nsAString;
use gecko_bindings::structs::mozilla::css::URLValue;
use gecko_bindings::structs::RawGeckoDocument; use gecko_bindings::structs::RawGeckoDocument;
use gecko_bindings::structs::RawGeckoElement; use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoKeyframeList; use gecko_bindings::structs::RawGeckoKeyframeList;
@ -618,14 +619,6 @@ extern "C" {
pub fn Gecko_CopyCursorArrayFrom(dest: *mut nsStyleUserInterface, pub fn Gecko_CopyCursorArrayFrom(dest: *mut nsStyleUserInterface,
src: *const nsStyleUserInterface); src: *const nsStyleUserInterface);
} }
extern "C" {
pub fn Gecko_SetMozBinding(style_struct: *mut nsStyleDisplay,
bundled_uri: ServoBundledURI);
}
extern "C" {
pub fn Gecko_CopyMozBindingFrom(des: *mut nsStyleDisplay,
src: *const nsStyleDisplay);
}
extern "C" { extern "C" {
pub fn Gecko_GetNodeFlags(node: RawGeckoNodeBorrowed) -> u32; pub fn Gecko_GetNodeFlags(node: RawGeckoNodeBorrowed) -> u32;
} }
@ -733,6 +726,15 @@ extern "C" {
extern "C" { extern "C" {
pub fn Gecko_nsStyleSVGPaint_Reset(paint: *mut nsStyleSVGPaint); pub fn Gecko_nsStyleSVGPaint_Reset(paint: *mut nsStyleSVGPaint);
} }
extern "C" {
pub fn Gecko_NewURLValue(uri: ServoBundledURI) -> *mut URLValue;
}
extern "C" {
pub fn Gecko_AddRefCSSURLValueArbitraryThread(aPtr: *mut URLValue);
}
extern "C" {
pub fn Gecko_ReleaseCSSURLValueArbitraryThread(aPtr: *mut URLValue);
}
extern "C" { extern "C" {
pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers, pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers,
max_len: u32); max_len: u32);

View file

@ -264,6 +264,9 @@ impl_threadsafe_refcount!(::gecko_bindings::structs::nsStyleQuoteValues,
impl_threadsafe_refcount!(::gecko_bindings::structs::nsCSSValueSharedList, impl_threadsafe_refcount!(::gecko_bindings::structs::nsCSSValueSharedList,
Gecko_AddRefCSSValueSharedListArbitraryThread, Gecko_AddRefCSSValueSharedListArbitraryThread,
Gecko_ReleaseCSSValueSharedListArbitraryThread); Gecko_ReleaseCSSValueSharedListArbitraryThread);
impl_threadsafe_refcount!(::gecko_bindings::structs::mozilla::css::URLValue,
Gecko_AddRefCSSURLValueArbitraryThread,
Gecko_ReleaseCSSURLValueArbitraryThread);
/// A Gecko `ThreadSafePrincipalHolder` wrapped in a safe refcounted pointer, to /// A Gecko `ThreadSafePrincipalHolder` wrapped in a safe refcounted pointer, to
/// use during stylesheet parsing and style computation. /// use during stylesheet parsing and style computation.
pub type GeckoArcPrincipal = RefPtr<::gecko_bindings::structs::ThreadSafePrincipalHolder>; pub type GeckoArcPrincipal = RefPtr<::gecko_bindings::structs::ThreadSafePrincipalHolder>;

View file

@ -26,7 +26,6 @@ use gecko_bindings::bindings::Gecko_CopyFontFamilyFrom;
use gecko_bindings::bindings::Gecko_CopyImageValueFrom; use gecko_bindings::bindings::Gecko_CopyImageValueFrom;
use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom; use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom;
use gecko_bindings::bindings::Gecko_CopyListStyleTypeFrom; use gecko_bindings::bindings::Gecko_CopyListStyleTypeFrom;
use gecko_bindings::bindings::Gecko_CopyMozBindingFrom;
use gecko_bindings::bindings::Gecko_EnsureImageLayersLength; use gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendGeneric; use gecko_bindings::bindings::Gecko_FontFamilyList_AppendGeneric;
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendNamed; use gecko_bindings::bindings::Gecko_FontFamilyList_AppendNamed;
@ -37,7 +36,6 @@ use gecko_bindings::bindings::Gecko_NewCSSShadowArray;
use gecko_bindings::bindings::Gecko_SetListStyleImage; use gecko_bindings::bindings::Gecko_SetListStyleImage;
use gecko_bindings::bindings::Gecko_SetListStyleImageNone; use gecko_bindings::bindings::Gecko_SetListStyleImageNone;
use gecko_bindings::bindings::Gecko_SetListStyleType; use gecko_bindings::bindings::Gecko_SetListStyleType;
use gecko_bindings::bindings::Gecko_SetMozBinding;
use gecko_bindings::bindings::Gecko_SetNullImageValue; use gecko_bindings::bindings::Gecko_SetNullImageValue;
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
@ -398,7 +396,11 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
} }
SVGPaintKind::PaintServer(url) => { SVGPaintKind::PaintServer(url) => {
unsafe { unsafe {
bindings::Gecko_nsStyleSVGPaint_SetURLValue(paint, url.for_ffi()); if let Some(ffi) = url.for_ffi() {
bindings::Gecko_nsStyleSVGPaint_SetURLValue(paint, ffi);
} else {
return;
}
} }
} }
SVGPaintKind::Color(color) => { SVGPaintKind::Color(color) => {
@ -511,6 +513,41 @@ 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)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
use gecko_bindings::sugar::refptr::RefPtr;
match v {
Either::First(url) => {
let refptr = unsafe {
if let Some(ffi) = url.for_ffi() {
let ptr = bindings::Gecko_NewURLValue(ffi);
RefPtr::from_addrefed(ptr)
} else {
self.gecko.${gecko_ffi_name}.clear();
return;
}
};
self.gecko.${gecko_ffi_name}.set_move(refptr)
}
Either::Second(_none) => {
unsafe {
self.gecko.${gecko_ffi_name}.clear();
}
}
}
}
#[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
unsafe {
self.gecko.${gecko_ffi_name}.set(&other.gecko.${gecko_ffi_name});
}
}
% if need_clone:
<% raise Exception("Do not know how to handle clone ") %>
% endif
</%def>
<%def name="impl_logical(name, need_clone=False, **kwargs)"> <%def name="impl_logical(name, need_clone=False, **kwargs)">
${helpers.logical_setter(name, need_clone)} ${helpers.logical_setter(name, need_clone)}
</%def> </%def>
@ -600,6 +637,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"Opacity": impl_simple, "Opacity": impl_simple,
"CSSColor": impl_color, "CSSColor": impl_color,
"SVGPaint": impl_svg_paint, "SVGPaint": impl_svg_paint,
"UrlOrNone": impl_css_url,
} }
def longhand_method(longhand): def longhand_method(longhand):
@ -1278,7 +1316,7 @@ fn static_assert() {
animation-name animation-delay animation-duration animation-name animation-delay animation-duration
animation-direction animation-fill-mode animation-play-state animation-direction animation-fill-mode animation-play-state
animation-iteration-count animation-timing-function animation-iteration-count animation-timing-function
-moz-binding 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""" %>
@ -1373,24 +1411,6 @@ fn static_assert() {
<%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call> <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call>
#[allow(non_snake_case)]
pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
use values::Either;
match v {
Either::Second(_none) => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
Either::First(ref url) => {
unsafe {
Gecko_SetMozBinding(&mut self.gecko, url.for_ffi());
}
}
}
}
#[allow(non_snake_case)]
pub fn copy__moz_binding_from(&mut self, other: &Self) {
unsafe { Gecko_CopyMozBindingFrom(&mut self.gecko, &other.gecko); }
}
// Temp fix for Bugzilla bug 24000. // Temp fix for Bugzilla bug 24000.
// Map 'auto' and 'avoid' to false, and 'always', 'left', and 'right' to true. // Map 'auto' and 'avoid' to false, and 'always', 'left', and 'right' to true.
// "A conforming user agent may interpret the values 'left' and 'right' // "A conforming user agent may interpret the values 'left' and 'right'
@ -2115,8 +2135,12 @@ fn static_assert() {
} }
Either::First(ref url) => { Either::First(ref url) => {
unsafe { unsafe {
Gecko_SetListStyleImage(&mut self.gecko, if let Some(ffi) = url.for_ffi() {
url.for_ffi()); Gecko_SetListStyleImage(&mut self.gecko,
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
@ -2317,7 +2341,9 @@ fn static_assert() {
} }
Url(ref url) => { Url(ref url) => {
unsafe { unsafe {
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url.for_ffi()); if let Some(ffi) = url.for_ffi() {
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, ffi);
}
} }
} }
} }
@ -2677,7 +2703,9 @@ clip-path
match v { match v {
ShapeSource::Url(ref url) => { ShapeSource::Url(ref url) => {
unsafe { unsafe {
bindings::Gecko_StyleClipPath_SetURLValue(clip_path, url.for_ffi()); if let Some(ffi) = url.for_ffi() {
bindings::Gecko_StyleClipPath_SetURLValue(clip_path, ffi);
}
} }
} }
ShapeSource::None => {} // don't change the type ShapeSource::None => {} // don't change the type

View file

@ -1922,6 +1922,7 @@ ${helpers.single_keyword("-moz-appearance",
${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)", ${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
products="gecko", products="gecko",
animatable="False", animatable="False",
gecko_ffi_name="mBinding",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
disable_when_testing="True", disable_when_testing="True",
boxed=True)} boxed=True)}

View file

@ -100,3 +100,22 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",
gecko_inexhaustive=True, gecko_inexhaustive=True,
animatable=False, animatable=False,
spec="https://www.w3.org/TR/SVG11/masking.html#ClipRuleProperty")} spec="https://www.w3.org/TR/SVG11/masking.html#ClipRuleProperty")}
${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties",
boxed=True)}
${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties",
boxed=True)}
${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties",
boxed=True)}

View file

@ -173,20 +173,19 @@ 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) -> ServoBundledURI { pub fn for_ffi(&self) -> Option<ServoBundledURI> {
use std::ptr;
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(_) => (ptr::null(), 0), Err(_) => return None,
}; };
ServoBundledURI { Some(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(),
} })
} }
} }