Skip to content

Commit

Permalink
stylo: Add mako template for URLOrNone, use for marker-* properties
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 4QKKzJ1DVYP
  • Loading branch information
Manishearth committed Feb 18, 2017
1 parent 3b0840d commit fa9881b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 39 deletions.
1 change: 1 addition & 0 deletions components/style/build_gecko.rs
Expand Up @@ -508,6 +508,7 @@ mod bindings {
.whitelisted_function("Servo_.*")
.whitelisted_function("Gecko_.*");
let structs_types = [
"mozilla::css::URLValue",
"RawGeckoDocument",
"RawGeckoElement",
"RawGeckoKeyframeList",
Expand Down
18 changes: 10 additions & 8 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -3,6 +3,7 @@
pub use nsstring::{nsACString, nsAString};
type nsACString_internal = nsACString;
type nsAString_internal = nsAString;
use gecko_bindings::structs::mozilla::css::URLValue;
use gecko_bindings::structs::RawGeckoDocument;
use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoKeyframeList;
Expand Down Expand Up @@ -618,14 +619,6 @@ extern "C" {
pub fn Gecko_CopyCursorArrayFrom(dest: *mut 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" {
pub fn Gecko_GetNodeFlags(node: RawGeckoNodeBorrowed) -> u32;
}
Expand Down Expand Up @@ -733,6 +726,15 @@ extern "C" {
extern "C" {
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" {
pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers,
max_len: u32);
Expand Down
3 changes: 3 additions & 0 deletions components/style/gecko_bindings/sugar/refptr.rs
Expand Up @@ -264,6 +264,9 @@ impl_threadsafe_refcount!(::gecko_bindings::structs::nsStyleQuoteValues,
impl_threadsafe_refcount!(::gecko_bindings::structs::nsCSSValueSharedList,
Gecko_AddRefCSSValueSharedListArbitraryThread,
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
/// use during stylesheet parsing and style computation.
pub type GeckoArcPrincipal = RefPtr<::gecko_bindings::structs::ThreadSafePrincipalHolder>;
Expand Down
80 changes: 54 additions & 26 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -26,7 +26,6 @@ use gecko_bindings::bindings::Gecko_CopyFontFamilyFrom;
use gecko_bindings::bindings::Gecko_CopyImageValueFrom;
use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom;
use gecko_bindings::bindings::Gecko_CopyListStyleTypeFrom;
use gecko_bindings::bindings::Gecko_CopyMozBindingFrom;
use gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendGeneric;
use gecko_bindings::bindings::Gecko_FontFamilyList_AppendNamed;
Expand All @@ -37,7 +36,6 @@ use gecko_bindings::bindings::Gecko_NewCSSShadowArray;
use gecko_bindings::bindings::Gecko_SetListStyleImage;
use gecko_bindings::bindings::Gecko_SetListStyleImageNone;
use gecko_bindings::bindings::Gecko_SetListStyleType;
use gecko_bindings::bindings::Gecko_SetMozBinding;
use gecko_bindings::bindings::Gecko_SetNullImageValue;
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
Expand Down Expand Up @@ -398,7 +396,11 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
}
SVGPaintKind::PaintServer(url) => {
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) => {
Expand Down Expand Up @@ -511,6 +513,41 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor {
% endif
</%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)">
${helpers.logical_setter(name, need_clone)}
</%def>
Expand Down Expand Up @@ -600,6 +637,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"Opacity": impl_simple,
"CSSColor": impl_color,
"SVGPaint": impl_svg_paint,
"UrlOrNone": impl_css_url,
}

def longhand_method(longhand):
Expand Down Expand Up @@ -1278,7 +1316,7 @@ fn static_assert() {
animation-name animation-delay animation-duration
animation-direction animation-fill-mode animation-play-state
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-type-y scroll-snap-coordinate
perspective-origin transform-origin""" %>
Expand Down Expand Up @@ -1373,24 +1411,6 @@ fn static_assert() {

<%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.
// Map 'auto' and 'avoid' to false, and 'always', 'left', and 'right' to true.
// "A conforming user agent may interpret the values 'left' and 'right'
Expand Down Expand Up @@ -2115,8 +2135,12 @@ fn static_assert() {
}
Either::First(ref url) => {
unsafe {
Gecko_SetListStyleImage(&mut self.gecko,
url.for_ffi());
if let Some(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
// background-image to a url() value, since only properties in reset structs
Expand Down Expand Up @@ -2317,7 +2341,9 @@ fn static_assert() {
}
Url(ref url) => {
unsafe {
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url.for_ffi());
if let Some(ffi) = url.for_ffi() {
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, ffi);
}
}
}
}
Expand Down Expand Up @@ -2677,7 +2703,9 @@ clip-path
match v {
ShapeSource::Url(ref url) => {
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
Expand Down
1 change: 1 addition & 0 deletions components/style/properties/longhand/box.mako.rs
Expand Up @@ -1922,6 +1922,7 @@ ${helpers.single_keyword("-moz-appearance",
${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
gecko_ffi_name="mBinding",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
disable_when_testing="True",
boxed=True)}
Expand Down
19 changes: 19 additions & 0 deletions components/style/properties/longhand/inherited_svg.mako.rs
Expand Up @@ -100,3 +100,22 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",
gecko_inexhaustive=True,
animatable=False,
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)}

9 changes: 4 additions & 5 deletions components/style/values/specified/url.rs
Expand Up @@ -173,20 +173,19 @@ impl SpecifiedUrl {
/// Create a bundled URI suitable for sending to Gecko
/// to be constructed into a css::URLValue
#[cfg(feature = "gecko")]
pub fn for_ffi(&self) -> ServoBundledURI {
use std::ptr;
pub fn for_ffi(&self) -> Option<ServoBundledURI> {
let extra_data = self.extra_data();
let (ptr, len) = match self.as_slice_components() {
Ok(value) => value,
Err(_) => (ptr::null(), 0),
Err(_) => return None,
};
ServoBundledURI {
Some(ServoBundledURI {
mURLString: ptr,
mURLStringLength: len as u32,
mBaseURI: extra_data.base.get(),
mReferrer: extra_data.referrer.get(),
mPrincipal: extra_data.principal.get(),
}
})
}
}

Expand Down

0 comments on commit fa9881b

Please sign in to comment.