From fa9881b829d40a55a1bdd9d4f6a65227386a3d45 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 9 Feb 2017 17:43:52 -0800 Subject: [PATCH] stylo: Add mako template for URLOrNone, use for marker-* properties MozReview-Commit-ID: 4QKKzJ1DVYP --- components/style/build_gecko.rs | 1 + components/style/gecko_bindings/bindings.rs | 18 +++-- .../style/gecko_bindings/sugar/refptr.rs | 3 + components/style/properties/gecko.mako.rs | 80 +++++++++++++------ .../style/properties/longhand/box.mako.rs | 1 + .../properties/longhand/inherited_svg.mako.rs | 19 +++++ components/style/values/specified/url.rs | 9 +-- 7 files changed, 92 insertions(+), 39 deletions(-) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index e0b3d14452e..58064f4f897 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -508,6 +508,7 @@ mod bindings { .whitelisted_function("Servo_.*") .whitelisted_function("Gecko_.*"); let structs_types = [ + "mozilla::css::URLValue", "RawGeckoDocument", "RawGeckoElement", "RawGeckoKeyframeList", diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 8b475831452..71f9389a45b 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -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; @@ -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; } @@ -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); diff --git a/components/style/gecko_bindings/sugar/refptr.rs b/components/style/gecko_bindings/sugar/refptr.rs index 1689522e892..0202afb3292 100644 --- a/components/style/gecko_bindings/sugar/refptr.rs +++ b/components/style/gecko_bindings/sugar/refptr.rs @@ -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>; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 2ba1ca34c30..1a3ef55e8f4 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -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; @@ -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}; @@ -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) => { @@ -511,6 +513,41 @@ fn color_to_nscolor_zero_currentcolor(color: Color) -> structs::nscolor { % endif +<%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 name="impl_logical(name, need_clone=False, **kwargs)"> ${helpers.logical_setter(name, need_clone)} @@ -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): @@ -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""" %> @@ -1373,24 +1411,6 @@ fn static_assert() { <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"> - #[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' @@ -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 @@ -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); + } } } } @@ -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 diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index a0284a23bec..6cb2026b1d6 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -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)} diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 98112efbba0..3131e528af9 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -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)} + diff --git a/components/style/values/specified/url.rs b/components/style/values/specified/url.rs index 719a176f439..f6b8dd2de29 100644 --- a/components/style/values/specified/url.rs +++ b/components/style/values/specified/url.rs @@ -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 { 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(), - } + }) } }