diff --git a/components/style/gecko_conversions.rs b/components/style/gecko_conversions.rs index 56e2e3bbc5f..ede574d181e 100644 --- a/components/style/gecko_conversions.rs +++ b/components/style/gecko_conversions.rs @@ -6,10 +6,23 @@ //! Ideally, it would be in geckolib itself, but coherence //! forces us to keep the traits and implementations here +#![allow(unsafe_code)] + use app_units::Au; +use gecko_bindings::bindings::{RawServoStyleSheet, ServoComputedValues}; use gecko_bindings::structs::nsStyleCoord_CalcValue; +use gecko_bindings::sugar::refptr::HasArcFFI; +use properties::ComputedValues; +use stylesheets::Stylesheet; use values::computed::{CalcLengthOrPercentage, LengthOrPercentage}; +unsafe impl HasArcFFI for Stylesheet { + type FFIType = RawServoStyleSheet; +} +unsafe impl HasArcFFI for ComputedValues { + type FFIType = ServoComputedValues; +} + impl From for nsStyleCoord_CalcValue { fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); diff --git a/components/style/gecko_glue.rs b/components/style/gecko_glue.rs deleted file mode 100644 index d9ec0bd5562..00000000000 --- a/components/style/gecko_glue.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#![allow(unsafe_code)] - -use std::marker::PhantomData; -use std::mem::{forget, transmute}; -use std::sync::Arc; - -pub struct ArcHelpers { - phantom1: PhantomData, - phantom2: PhantomData, -} - -impl ArcHelpers { - pub fn with(raw: *mut GeckoType, cb: F) -> Output - where F: FnOnce(&Arc) -> Output { - debug_assert!(!raw.is_null()); - - let owned = unsafe { Self::into(raw) }; - let result = cb(&owned); - forget(owned); - result - } - - pub fn maybe_with(maybe_raw: *mut GeckoType, cb: F) -> Output - where F: FnOnce(Option<&Arc>) -> Output { - let owned = if maybe_raw.is_null() { - None - } else { - Some(unsafe { Self::into(maybe_raw) }) - }; - - let result = cb(owned.as_ref()); - forget(owned); - - result - } - - pub unsafe fn into(ptr: *mut GeckoType) -> Arc { - transmute(ptr) - } - - pub fn from(owned: Arc) -> *mut GeckoType { - unsafe { transmute(owned) } - } - - pub fn borrow(borrowed: &Arc, cb: F) -> Output - where F: FnOnce(&mut GeckoType) -> Output - { - let borrowed_gecko_type: *const &mut GeckoType = - unsafe { transmute(borrowed) }; - - unsafe { cb(*borrowed_gecko_type) } - } - - pub unsafe fn addref(ptr: *mut GeckoType) { - Self::with(ptr, |arc| forget(arc.clone())); - } - - pub unsafe fn release(ptr: *mut GeckoType) { - let _ = Self::into(ptr); - } -} diff --git a/components/style/lib.rs b/components/style/lib.rs index 4cab0c84b47..3869b7867e9 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -83,7 +83,6 @@ pub mod element_state; pub mod error_reporting; pub mod font_face; #[cfg(feature = "gecko")] pub mod gecko_conversions; -#[cfg(feature = "gecko")] pub mod gecko_glue; #[cfg(feature = "gecko")] pub mod gecko_selector_impl; #[cfg(feature = "gecko")] pub mod gecko_values; pub mod keyframes; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 9fb7a1ac52d..95cc6de7cb3 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -24,10 +24,10 @@ use gecko_bindings::bindings::{Gecko_EnsureImageLayersLength, Gecko_CreateGradie use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom}; use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed}; use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear, Gecko_InitializeImageLayer}; -use gecko_bindings::bindings; +use gecko_bindings::bindings::ServoComputedValuesBorrowed; use gecko_bindings::structs; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; -use gecko_glue::ArcHelpers; +use gecko_bindings::sugar::refptr::HasArcFFI; use gecko_values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba}; use gecko_values::convert_rgba_to_nscolor; use gecko_values::round_border_to_device_pixels; @@ -1358,10 +1358,9 @@ fn static_assert() { <%def name="define_ffi_struct_accessor(style_struct)"> #[no_mangle] #[allow(non_snake_case, unused_variables)] -pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut bindings::ServoComputedValues) +pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: ServoComputedValuesBorrowed) -> *const ${style_struct.gecko_ffi_name} { - type Helpers = ArcHelpers; - Helpers::with(computed_values, |values| values.get_${style_struct.name_lower}().get_gecko() + ComputedValues::with(computed_values, |values| values.get_${style_struct.name_lower}().get_gecko() as *const ${style_struct.gecko_ffi_name}) } diff --git a/components/style/properties/longhand/inherited_svg.mako.rs b/components/style/properties/longhand/inherited_svg.mako.rs index 59e21e60ce5..ce233ecb366 100644 --- a/components/style/properties/longhand/inherited_svg.mako.rs +++ b/components/style/properties/longhand/inherited_svg.mako.rs @@ -34,6 +34,7 @@ ${helpers.predefined_type("fill-opacity", "Opacity", "1.0", products="gecko", animatable=False)} ${helpers.single_keyword("fill-rule", "nonzero evenodd", + gecko_enum_prefix="StyleFillRule", products="gecko", animatable=False)} ${helpers.single_keyword("shape-rendering", @@ -57,5 +58,5 @@ ${helpers.predefined_type("stroke-opacity", "Opacity", "1.0", // Section 14 - Clipping, Masking and Compositing ${helpers.single_keyword("clip-rule", "nonzero evenodd", products="gecko", - gecko_constant_prefix="NS_STYLE_FILL_RULE", + gecko_enum_prefix="StyleFillRule", animatable=False)} diff --git a/ports/geckolib/binding_tools/regen.py b/ports/geckolib/binding_tools/regen.py index df121054ed5..ba041fc9200 100755 --- a/ports/geckolib/binding_tools/regen.py +++ b/ports/geckolib/binding_tools/regen.py @@ -69,7 +69,7 @@ COMPILATION_TARGETS = { "nsAString", "nsSubstring", "nsTSubstring", "nsTString", "nsISupportsBase.h", "nsCOMPtr.h", "nsIAtom.h", "nsIURI.h", "nsAutoPtr.h", "nsColor.h", "nsCoord.h", "nsPoint.h", "nsRect.h", - "nsMargin.h", "nsThemeConstants.h", "nsCSSProperty.h", + "nsMargin.h", "nsThemeConstants.h", "nsCSSProperty.h", "nsCSSPropertyID.h", "CSSVariableValues.h", "nsFont.h", "nsTHashtable.h", "PLDHashTable.h", "nsColor.h", "nsStyleStruct.h", "nsStyleCoord.h", "RefPtr.h", "nsISupportsImpl.h", "gfxFontConstants.h", @@ -116,6 +116,9 @@ COMPILATION_TARGETS = { "raw_lines": [ "use heapsize::HeapSizeOf;", ], + "flags": [ + "-ignore-methods", + ], "match_headers": [ "ServoBindings.h", "nsStyleStructList.h", @@ -145,6 +148,7 @@ COMPILATION_TARGETS = { "void_types": [ "nsINode", "nsIDocument", "nsIPrincipal", "nsIURI", ], + "servo_arc_types": ["ServoComputedValues", "RawServoStyleSheet"] }, "atoms": { @@ -300,7 +304,16 @@ def build(objdir, target_name, kind_name=None, for ty in current_target["void_types"]: flags.append("-raw-line") flags.append("pub enum {} {{}}".format(ty)) - + if "servo_arc_types" in current_target: + for ty in current_target["servo_arc_types"]: + flags.append("-blacklist-type") + flags.append("{}Strong".format(ty)) + flags.append("-raw-line") + flags.append("pub type {0}Strong = ::sugar::refptr::Strong<{0}>;".format(ty)) + flags.append("-blacklist-type") + flags.append("{}Borrowed".format(ty)) + flags.append("-raw-line") + flags.append("pub type {0}Borrowed<'a> = ::sugar::refptr::Borrowed<'a, {0}>;".format(ty)) if "structs_types" in current_target: for ty in current_target["structs_types"]: ty_fragments = ty.split("::") diff --git a/ports/geckolib/gecko_bindings/bindings.rs b/ports/geckolib/gecko_bindings/bindings.rs index 2855ce4942b..2a330fb21b6 100644 --- a/ports/geckolib/gecko_bindings/bindings.rs +++ b/ports/geckolib/gecko_bindings/bindings.rs @@ -5,6 +5,10 @@ pub enum nsINode {} pub enum nsIDocument {} pub enum nsIPrincipal {} pub enum nsIURI {} +pub type ServoComputedValuesStrong = ::sugar::refptr::Strong; +pub type ServoComputedValuesBorrowed<'a> = ::sugar::refptr::Borrowed<'a, ServoComputedValues>; +pub type RawServoStyleSheetStrong = ::sugar::refptr::Strong; +pub type RawServoStyleSheetBorrowed<'a> = ::sugar::refptr::Borrowed<'a, RawServoStyleSheet>; use structs::nsStyleFont; unsafe impl Send for nsStyleFont {} unsafe impl Sync for nsStyleFont {} @@ -301,7 +305,7 @@ extern "C" { pub fn Gecko_GetStyleContext(node: *mut RawGeckoNode) -> *mut nsStyleContext; pub fn Gecko_CalcStyleDifference(oldstyle: *mut nsStyleContext, - newstyle: *mut ServoComputedValues) + newstyle: ServoComputedValuesBorrowed) -> nsChangeHint; pub fn Gecko_StoreStyleDifference(node: *mut RawGeckoNode, change: nsChangeHint); @@ -326,19 +330,20 @@ extern "C" { referrer: *mut ThreadSafeURIHolder, principal: *mut ThreadSafePrincipalHolder) - -> *mut RawServoStyleSheet; - pub fn Servo_AddRefStyleSheet(sheet: *mut RawServoStyleSheet); - pub fn Servo_ReleaseStyleSheet(sheet: *mut RawServoStyleSheet); - pub fn Servo_AppendStyleSheet(sheet: *mut RawServoStyleSheet, + -> RawServoStyleSheetStrong; + pub fn Servo_AddRefStyleSheet(sheet: RawServoStyleSheetBorrowed); + pub fn Servo_ReleaseStyleSheet(sheet: RawServoStyleSheetBorrowed); + pub fn Servo_AppendStyleSheet(sheet: RawServoStyleSheetBorrowed, set: *mut RawServoStyleSet); - pub fn Servo_PrependStyleSheet(sheet: *mut RawServoStyleSheet, + pub fn Servo_PrependStyleSheet(sheet: RawServoStyleSheetBorrowed, set: *mut RawServoStyleSet); - pub fn Servo_RemoveStyleSheet(sheet: *mut RawServoStyleSheet, + pub fn Servo_RemoveStyleSheet(sheet: RawServoStyleSheetBorrowed, set: *mut RawServoStyleSet); - pub fn Servo_InsertStyleSheetBefore(sheet: *mut RawServoStyleSheet, - reference: *mut RawServoStyleSheet, + pub fn Servo_InsertStyleSheetBefore(sheet: RawServoStyleSheetBorrowed, + reference: RawServoStyleSheetBorrowed, set: *mut RawServoStyleSet); - pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> bool; + pub fn Servo_StyleSheetHasRules(sheet: RawServoStyleSheetBorrowed) + -> bool; pub fn Servo_InitStyleSet() -> *mut RawServoStyleSet; pub fn Servo_DropStyleSet(set: *mut RawServoStyleSet); pub fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32, @@ -356,24 +361,25 @@ extern "C" { pub fn Servo_CSSSupports(name: *const u8, name_length: u32, value: *const u8, value_length: u32) -> bool; pub fn Servo_GetComputedValues(node: *mut RawGeckoNode) - -> *mut ServoComputedValues; + -> ServoComputedValuesStrong; pub fn Servo_GetComputedValuesForAnonymousBox(parentStyleOrNull: - *mut ServoComputedValues, + ServoComputedValuesBorrowed, pseudoTag: *mut nsIAtom, set: *mut RawServoStyleSet) - -> *mut ServoComputedValues; + -> ServoComputedValuesStrong; pub fn Servo_GetComputedValuesForPseudoElement(parent_style: - *mut ServoComputedValues, + ServoComputedValuesBorrowed, match_element: *mut RawGeckoElement, pseudo_tag: *mut nsIAtom, set: *mut RawServoStyleSet, is_probe: bool) - -> *mut ServoComputedValues; - pub fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues) - -> *mut ServoComputedValues; - pub fn Servo_AddRefComputedValues(arg1: *mut ServoComputedValues); - pub fn Servo_ReleaseComputedValues(arg1: *mut ServoComputedValues); + -> ServoComputedValuesStrong; + pub fn Servo_InheritComputedValues(parent_style: + ServoComputedValuesBorrowed) + -> ServoComputedValuesStrong; + pub fn Servo_AddRefComputedValues(arg1: ServoComputedValuesBorrowed); + pub fn Servo_ReleaseComputedValues(arg1: ServoComputedValuesBorrowed); pub fn Servo_Initialize(); pub fn Servo_Shutdown(); pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument, @@ -388,32 +394,33 @@ extern "C" { pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont, other: *const nsStyleFont); pub fn Gecko_Destroy_nsStyleFont(ptr: *mut nsStyleFont); - pub fn Servo_GetStyleFont(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleFont(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleFont; pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor); pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor, other: *const nsStyleColor); pub fn Gecko_Destroy_nsStyleColor(ptr: *mut nsStyleColor); - pub fn Servo_GetStyleColor(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleColor(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleColor; pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList); pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList, other: *const nsStyleList); pub fn Gecko_Destroy_nsStyleList(ptr: *mut nsStyleList); - pub fn Servo_GetStyleList(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleList(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleList; pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText); pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText, other: *const nsStyleText); pub fn Gecko_Destroy_nsStyleText(ptr: *mut nsStyleText); - pub fn Servo_GetStyleText(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleText(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleText; pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility); pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility, other: *const nsStyleVisibility); pub fn Gecko_Destroy_nsStyleVisibility(ptr: *mut nsStyleVisibility); - pub fn Servo_GetStyleVisibility(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleVisibility(computedValues: + ServoComputedValuesBorrowed) -> *const nsStyleVisibility; pub fn Gecko_Construct_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); @@ -423,7 +430,7 @@ extern "C" { *const nsStyleUserInterface); pub fn Gecko_Destroy_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); pub fn Servo_GetStyleUserInterface(computedValues: - *mut ServoComputedValues) + ServoComputedValuesBorrowed) -> *const nsStyleUserInterface; pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr: @@ -431,111 +438,115 @@ extern "C" { other: *const nsStyleTableBorder); pub fn Gecko_Destroy_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); - pub fn Servo_GetStyleTableBorder(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleTableBorder(computedValues: + ServoComputedValuesBorrowed) -> *const nsStyleTableBorder; pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG); pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG, other: *const nsStyleSVG); pub fn Gecko_Destroy_nsStyleSVG(ptr: *mut nsStyleSVG); - pub fn Servo_GetStyleSVG(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleSVG(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleSVG; pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables, other: *const nsStyleVariables); pub fn Gecko_Destroy_nsStyleVariables(ptr: *mut nsStyleVariables); - pub fn Servo_GetStyleVariables(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleVariables(computedValues: + ServoComputedValuesBorrowed) -> *const nsStyleVariables; pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground); pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground, other: *const nsStyleBackground); pub fn Gecko_Destroy_nsStyleBackground(ptr: *mut nsStyleBackground); - pub fn Servo_GetStyleBackground(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleBackground(computedValues: + ServoComputedValuesBorrowed) -> *const nsStyleBackground; pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition); pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition, other: *const nsStylePosition); pub fn Gecko_Destroy_nsStylePosition(ptr: *mut nsStylePosition); - pub fn Servo_GetStylePosition(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStylePosition(computedValues: ServoComputedValuesBorrowed) -> *const nsStylePosition; pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset); pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset, other: *const nsStyleTextReset); pub fn Gecko_Destroy_nsStyleTextReset(ptr: *mut nsStyleTextReset); - pub fn Servo_GetStyleTextReset(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleTextReset(computedValues: + ServoComputedValuesBorrowed) -> *const nsStyleTextReset; pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay); pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay, other: *const nsStyleDisplay); pub fn Gecko_Destroy_nsStyleDisplay(ptr: *mut nsStyleDisplay); - pub fn Servo_GetStyleDisplay(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleDisplay(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleDisplay; pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent); pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent, other: *const nsStyleContent); pub fn Gecko_Destroy_nsStyleContent(ptr: *mut nsStyleContent); - pub fn Servo_GetStyleContent(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleContent(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleContent; pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset); pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset, other: *const nsStyleUIReset); pub fn Gecko_Destroy_nsStyleUIReset(ptr: *mut nsStyleUIReset); - pub fn Servo_GetStyleUIReset(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleUIReset(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleUIReset; pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable); pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable, other: *const nsStyleTable); pub fn Gecko_Destroy_nsStyleTable(ptr: *mut nsStyleTable); - pub fn Servo_GetStyleTable(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleTable(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleTable; pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin); pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin, other: *const nsStyleMargin); pub fn Gecko_Destroy_nsStyleMargin(ptr: *mut nsStyleMargin); - pub fn Servo_GetStyleMargin(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleMargin(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleMargin; pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding); pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding, other: *const nsStylePadding); pub fn Gecko_Destroy_nsStylePadding(ptr: *mut nsStylePadding); - pub fn Servo_GetStylePadding(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStylePadding(computedValues: ServoComputedValuesBorrowed) -> *const nsStylePadding; pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder); pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder, other: *const nsStyleBorder); pub fn Gecko_Destroy_nsStyleBorder(ptr: *mut nsStyleBorder); - pub fn Servo_GetStyleBorder(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleBorder(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleBorder; pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline); pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline, other: *const nsStyleOutline); pub fn Gecko_Destroy_nsStyleOutline(ptr: *mut nsStyleOutline); - pub fn Servo_GetStyleOutline(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleOutline(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleOutline; pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL); pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL, other: *const nsStyleXUL); pub fn Gecko_Destroy_nsStyleXUL(ptr: *mut nsStyleXUL); - pub fn Servo_GetStyleXUL(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleXUL(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleXUL; pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, other: *const nsStyleSVGReset); pub fn Gecko_Destroy_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); - pub fn Servo_GetStyleSVGReset(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleSVGReset(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleSVGReset; pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn); pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn, other: *const nsStyleColumn); pub fn Gecko_Destroy_nsStyleColumn(ptr: *mut nsStyleColumn); - pub fn Servo_GetStyleColumn(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleColumn(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleColumn; pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects); pub fn Gecko_CopyConstruct_nsStyleEffects(ptr: *mut nsStyleEffects, other: *const nsStyleEffects); pub fn Gecko_Destroy_nsStyleEffects(ptr: *mut nsStyleEffects); - pub fn Servo_GetStyleEffects(computedValues: *mut ServoComputedValues) + pub fn Servo_GetStyleEffects(computedValues: ServoComputedValuesBorrowed) -> *const nsStyleEffects; } diff --git a/ports/geckolib/gecko_bindings/structs_debug.rs b/ports/geckolib/gecko_bindings/structs_debug.rs index fd7ae6167e6..aba838068c0 100644 --- a/ports/geckolib/gecko_bindings/structs_debug.rs +++ b/ports/geckolib/gecko_bindings/structs_debug.rs @@ -189,12 +189,6 @@ pub const NS_ERROR_MODULE_BASE_OFFSET: ::std::os::raw::c_uint = 69; pub const MOZ_STRING_WITH_OBSOLETE_API: ::std::os::raw::c_uint = 1; pub const NSID_LENGTH: ::std::os::raw::c_uint = 39; pub const NS_NUMBER_OF_FLAGS_IN_REFCNT: ::std::os::raw::c_uint = 2; -pub const _STL_PAIR_H: ::std::os::raw::c_uint = 1; -pub const _GLIBCXX_UTILITY: ::std::os::raw::c_uint = 1; -pub const __cpp_lib_tuple_element_t: ::std::os::raw::c_uint = 201402; -pub const __cpp_lib_tuples_by_type: ::std::os::raw::c_uint = 201304; -pub const __cpp_lib_exchange_function: ::std::os::raw::c_uint = 201304; -pub const __cpp_lib_integer_sequence: ::std::os::raw::c_uint = 201304; pub const NS_EVENT_STATE_HIGHEST_SERVO_BIT: ::std::os::raw::c_uint = 6; pub const DOM_USER_DATA: ::std::os::raw::c_uint = 1; pub const SMIL_MAPPED_ATTR_ANIMVAL: ::std::os::raw::c_uint = 2; @@ -804,8 +798,6 @@ pub const NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE: ::std::os::raw::c_uint = pub const NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE: ::std::os::raw::c_uint = 11; -pub const NS_STYLE_FILL_RULE_NONZERO: ::std::os::raw::c_uint = 0; -pub const NS_STYLE_FILL_RULE_EVENODD: ::std::os::raw::c_uint = 1; pub const NS_STYLE_IMAGE_RENDERING_AUTO: ::std::os::raw::c_uint = 0; pub const NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED: ::std::os::raw::c_uint = 1; pub const NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY: ::std::os::raw::c_uint = @@ -2797,12 +2789,6 @@ impl ::std::clone::Clone for nsIExpandedPrincipal { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _Make_integer_sequence<_Tp, _ISeq> { - pub _phantom0: ::std::marker::PhantomData<_Tp>, - pub _phantom1: ::std::marker::PhantomData<_ISeq>, -} -#[repr(C)] #[derive(Debug, Copy)] pub struct nsIURI { pub _base: nsISupports, @@ -2854,7 +2840,7 @@ impl ::std::clone::Clone for nsIRequest { #[repr(C)] #[derive(Debug, Copy)] pub struct EventStates { - pub mStates: ::std::os::raw::c_ulong, + pub mStates: ::std::os::raw::c_ulonglong, } impl ::std::clone::Clone for EventStates { fn clone(&self) -> Self { *self } @@ -2984,7 +2970,7 @@ fn bindgen_test_layout_nsMutationGuard() { extern "C" { #[link_name = "_ZN15nsMutationGuard11sGenerationE"] pub static mut nsMutationGuard_consts_sGeneration: - ::std::os::raw::c_ulong; + ::std::os::raw::c_ulonglong; } pub type Float = f32; #[repr(i8)] @@ -3514,6 +3500,7 @@ pub enum nsChangeHint { nsChangeHint_UpdateComputedBSize = 16777216, nsChangeHint_UpdateUsesOpacity = 33554432, nsChangeHint_UpdateBackgroundPosition = 67108864, + nsChangeHint_AllHints = 134217727, } pub type nsChangeHint_size_t = ::std::os::raw::c_int; /** @@ -4004,6 +3991,9 @@ pub enum StyleClipPathGeometryBox { } #[repr(i8)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum StyleFillRule { Nonzero = 0, Evenodd = 1, } +#[repr(i8)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum StyleFloat { None_ = 0, Left = 1, @@ -4052,21 +4042,21 @@ pub enum StyleUserSelect { MozAll = 8, MozText = 9, } -pub const eCSSProperty_COUNT_DUMMY: nsCSSProperty = - nsCSSProperty::eCSSProperty_z_index; -pub const eCSSProperty_all: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT_no_shorthands; -pub const eCSSProperty_COUNT_DUMMY2: nsCSSProperty = - nsCSSProperty::eCSSProperty_transition; -pub const eCSSPropertyAlias_WordWrap: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT; -pub const eCSSProperty_COUNT_DUMMY3: nsCSSProperty = - nsCSSProperty::eCSSPropertyAlias_WebkitUserSelect; -pub const eCSSPropertyExtra_no_properties: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT_with_aliases; +pub const eCSSProperty_COUNT_DUMMY: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_z_index; +pub const eCSSProperty_all: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT_no_shorthands; +pub const eCSSProperty_COUNT_DUMMY2: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_transition; +pub const eCSSPropertyAlias_WordWrap: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT; +pub const eCSSProperty_COUNT_DUMMY3: nsCSSPropertyID = + nsCSSPropertyID::eCSSPropertyAlias_WebkitUserSelect; +pub const eCSSPropertyExtra_no_properties: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT_with_aliases; #[repr(i32)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum nsCSSProperty { +pub enum nsCSSPropertyID { eCSSProperty_UNKNOWN = -1, eCSSProperty_align_content = 0, eCSSProperty_align_items = 1, @@ -5082,8 +5072,8 @@ fn bindgen_test_layout_nsCSSValueGradient() { pub struct nsCSSValueTokenStream { pub mRefCnt: nsAutoRefCnt, pub _mOwningThread: nsAutoOwningThread, - pub mPropertyID: nsCSSProperty, - pub mShorthandPropertyID: nsCSSProperty, + pub mPropertyID: nsCSSPropertyID, + pub mShorthandPropertyID: nsCSSPropertyID, pub mTokenStream: nsString, pub mBaseURI: nsCOMPtr, pub mSheetURI: nsCOMPtr, @@ -5823,10 +5813,10 @@ fn bindgen_test_layout_nsStyleImageLayers() { extern "C" { #[link_name = "_ZN18nsStyleImageLayers21kBackgroundLayerTableE"] pub static mut nsStyleImageLayers_consts_kBackgroundLayerTable: - *const nsCSSProperty; + *const nsCSSPropertyID; #[link_name = "_ZN18nsStyleImageLayers15kMaskLayerTableE"] pub static mut nsStyleImageLayers_consts_kMaskLayerTable: - *const nsCSSProperty; + *const nsCSSPropertyID; } #[repr(C)] pub struct nsStyleBackground { @@ -6357,7 +6347,7 @@ pub struct StyleTransition { pub mTimingFunction: nsTimingFunction, pub mDuration: f32, pub mDelay: f32, - pub mProperty: nsCSSProperty, + pub mProperty: nsCSSPropertyID, pub mUnknownProperty: nsCOMPtr, } #[test] @@ -6388,7 +6378,7 @@ pub struct StyleBasicShape { pub mRefCnt: nsAutoRefCnt, pub _mOwningThread: nsAutoOwningThread, pub mType: StyleBasicShapeType, - pub mFillRule: i32, + pub mFillRule: StyleFillRule, pub mCoordinates: nsTArray, pub mPosition: nsStyleImageLayers_Position, pub mRadius: nsStyleCorners, @@ -6738,10 +6728,10 @@ pub struct nsStyleSVG { pub mFillOpacity: f32, pub mStrokeMiterlimit: f32, pub mStrokeOpacity: f32, - pub mClipRule: u8, + pub mClipRule: StyleFillRule, pub mColorInterpolation: u8, pub mColorInterpolationFilters: u8, - pub mFillRule: u8, + pub mFillRule: StyleFillRule, pub mPaintOrder: u8, pub mShapeRendering: u8, pub mStrokeLinecap: u8, diff --git a/ports/geckolib/gecko_bindings/structs_release.rs b/ports/geckolib/gecko_bindings/structs_release.rs index 93aed4be6bd..26dc0b01f61 100644 --- a/ports/geckolib/gecko_bindings/structs_release.rs +++ b/ports/geckolib/gecko_bindings/structs_release.rs @@ -189,12 +189,6 @@ pub const NS_ERROR_MODULE_BASE_OFFSET: ::std::os::raw::c_uint = 69; pub const MOZ_STRING_WITH_OBSOLETE_API: ::std::os::raw::c_uint = 1; pub const NSID_LENGTH: ::std::os::raw::c_uint = 39; pub const NS_NUMBER_OF_FLAGS_IN_REFCNT: ::std::os::raw::c_uint = 2; -pub const _STL_PAIR_H: ::std::os::raw::c_uint = 1; -pub const _GLIBCXX_UTILITY: ::std::os::raw::c_uint = 1; -pub const __cpp_lib_tuple_element_t: ::std::os::raw::c_uint = 201402; -pub const __cpp_lib_tuples_by_type: ::std::os::raw::c_uint = 201304; -pub const __cpp_lib_exchange_function: ::std::os::raw::c_uint = 201304; -pub const __cpp_lib_integer_sequence: ::std::os::raw::c_uint = 201304; pub const NS_EVENT_STATE_HIGHEST_SERVO_BIT: ::std::os::raw::c_uint = 6; pub const DOM_USER_DATA: ::std::os::raw::c_uint = 1; pub const SMIL_MAPPED_ATTR_ANIMVAL: ::std::os::raw::c_uint = 2; @@ -804,8 +798,6 @@ pub const NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE: ::std::os::raw::c_uint = pub const NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE: ::std::os::raw::c_uint = 11; -pub const NS_STYLE_FILL_RULE_NONZERO: ::std::os::raw::c_uint = 0; -pub const NS_STYLE_FILL_RULE_EVENODD: ::std::os::raw::c_uint = 1; pub const NS_STYLE_IMAGE_RENDERING_AUTO: ::std::os::raw::c_uint = 0; pub const NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED: ::std::os::raw::c_uint = 1; pub const NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY: ::std::os::raw::c_uint = @@ -2776,12 +2768,6 @@ impl ::std::clone::Clone for nsIExpandedPrincipal { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _Make_integer_sequence<_Tp, _ISeq> { - pub _phantom0: ::std::marker::PhantomData<_Tp>, - pub _phantom1: ::std::marker::PhantomData<_ISeq>, -} -#[repr(C)] #[derive(Debug, Copy)] pub struct nsIURI { pub _base: nsISupports, @@ -2833,7 +2819,7 @@ impl ::std::clone::Clone for nsIRequest { #[repr(C)] #[derive(Debug, Copy)] pub struct EventStates { - pub mStates: ::std::os::raw::c_ulong, + pub mStates: ::std::os::raw::c_ulonglong, } impl ::std::clone::Clone for EventStates { fn clone(&self) -> Self { *self } @@ -2963,7 +2949,7 @@ fn bindgen_test_layout_nsMutationGuard() { extern "C" { #[link_name = "_ZN15nsMutationGuard11sGenerationE"] pub static mut nsMutationGuard_consts_sGeneration: - ::std::os::raw::c_ulong; + ::std::os::raw::c_ulonglong; } pub type Float = f32; #[repr(i8)] @@ -3493,6 +3479,7 @@ pub enum nsChangeHint { nsChangeHint_UpdateComputedBSize = 16777216, nsChangeHint_UpdateUsesOpacity = 33554432, nsChangeHint_UpdateBackgroundPosition = 67108864, + nsChangeHint_AllHints = 134217727, } pub type nsChangeHint_size_t = ::std::os::raw::c_int; /** @@ -3983,6 +3970,9 @@ pub enum StyleClipPathGeometryBox { } #[repr(i8)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum StyleFillRule { Nonzero = 0, Evenodd = 1, } +#[repr(i8)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum StyleFloat { None_ = 0, Left = 1, @@ -4031,21 +4021,21 @@ pub enum StyleUserSelect { MozAll = 8, MozText = 9, } -pub const eCSSProperty_COUNT_DUMMY: nsCSSProperty = - nsCSSProperty::eCSSProperty_z_index; -pub const eCSSProperty_all: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT_no_shorthands; -pub const eCSSProperty_COUNT_DUMMY2: nsCSSProperty = - nsCSSProperty::eCSSProperty_transition; -pub const eCSSPropertyAlias_WordWrap: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT; -pub const eCSSProperty_COUNT_DUMMY3: nsCSSProperty = - nsCSSProperty::eCSSPropertyAlias_WebkitUserSelect; -pub const eCSSPropertyExtra_no_properties: nsCSSProperty = - nsCSSProperty::eCSSProperty_COUNT_with_aliases; +pub const eCSSProperty_COUNT_DUMMY: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_z_index; +pub const eCSSProperty_all: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT_no_shorthands; +pub const eCSSProperty_COUNT_DUMMY2: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_transition; +pub const eCSSPropertyAlias_WordWrap: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT; +pub const eCSSProperty_COUNT_DUMMY3: nsCSSPropertyID = + nsCSSPropertyID::eCSSPropertyAlias_WebkitUserSelect; +pub const eCSSPropertyExtra_no_properties: nsCSSPropertyID = + nsCSSPropertyID::eCSSProperty_COUNT_with_aliases; #[repr(i32)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum nsCSSProperty { +pub enum nsCSSPropertyID { eCSSProperty_UNKNOWN = -1, eCSSProperty_align_content = 0, eCSSProperty_align_items = 1, @@ -5061,8 +5051,8 @@ fn bindgen_test_layout_nsCSSValueGradient() { pub struct nsCSSValueTokenStream { pub mRefCnt: nsAutoRefCnt, pub _mOwningThread: nsAutoOwningThread, - pub mPropertyID: nsCSSProperty, - pub mShorthandPropertyID: nsCSSProperty, + pub mPropertyID: nsCSSPropertyID, + pub mShorthandPropertyID: nsCSSPropertyID, pub mTokenStream: nsString, pub mBaseURI: nsCOMPtr, pub mSheetURI: nsCOMPtr, @@ -5801,10 +5791,10 @@ fn bindgen_test_layout_nsStyleImageLayers() { extern "C" { #[link_name = "_ZN18nsStyleImageLayers21kBackgroundLayerTableE"] pub static mut nsStyleImageLayers_consts_kBackgroundLayerTable: - *const nsCSSProperty; + *const nsCSSPropertyID; #[link_name = "_ZN18nsStyleImageLayers15kMaskLayerTableE"] pub static mut nsStyleImageLayers_consts_kMaskLayerTable: - *const nsCSSProperty; + *const nsCSSPropertyID; } #[repr(C)] pub struct nsStyleBackground { @@ -6335,7 +6325,7 @@ pub struct StyleTransition { pub mTimingFunction: nsTimingFunction, pub mDuration: f32, pub mDelay: f32, - pub mProperty: nsCSSProperty, + pub mProperty: nsCSSPropertyID, pub mUnknownProperty: nsCOMPtr, } #[test] @@ -6366,7 +6356,7 @@ pub struct StyleBasicShape { pub mRefCnt: nsAutoRefCnt, pub _mOwningThread: nsAutoOwningThread, pub mType: StyleBasicShapeType, - pub mFillRule: i32, + pub mFillRule: StyleFillRule, pub mCoordinates: nsTArray, pub mPosition: nsStyleImageLayers_Position, pub mRadius: nsStyleCorners, @@ -6715,10 +6705,10 @@ pub struct nsStyleSVG { pub mFillOpacity: f32, pub mStrokeMiterlimit: f32, pub mStrokeOpacity: f32, - pub mClipRule: u8, + pub mClipRule: StyleFillRule, pub mColorInterpolation: u8, pub mColorInterpolationFilters: u8, - pub mFillRule: u8, + pub mFillRule: StyleFillRule, pub mPaintOrder: u8, pub mShapeRendering: u8, pub mStrokeLinecap: u8, diff --git a/ports/geckolib/gecko_bindings/sugar/mod.rs b/ports/geckolib/gecko_bindings/sugar/mod.rs index 1cdd8b0c96a..4dfa016d3a9 100644 --- a/ports/geckolib/gecko_bindings/sugar/mod.rs +++ b/ports/geckolib/gecko_bindings/sugar/mod.rs @@ -5,3 +5,4 @@ mod ns_style_auto_array; pub mod ns_style_coord; mod ns_t_array; +pub mod refptr; diff --git a/ports/geckolib/gecko_bindings/sugar/refptr.rs b/ports/geckolib/gecko_bindings/sugar/refptr.rs new file mode 100644 index 00000000000..9d4eef9fd27 --- /dev/null +++ b/ports/geckolib/gecko_bindings/sugar/refptr.rs @@ -0,0 +1,117 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use std::marker::PhantomData; +use std::mem::{forget, transmute}; +use std::ptr; +use std::sync::Arc; + +/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs +/// +/// Should be implemented by types which are passed over FFI as Arcs +/// via Strong and Borrowed +pub unsafe trait HasArcFFI where Self: Sized { + /// Gecko's name for the type + /// This is equivalent to ArcInner + type FFIType: Sized; + + /// Given a non-null borrowed FFI reference, this produces a temporary + /// Arc which is borrowed by the given closure and used. + /// Panics on null. + fn with(raw: Borrowed, cb: F) -> Output + where F: FnOnce(&Arc) -> Output { + Self::maybe_with(raw, |opt| cb(opt.unwrap())) + } + + /// Given a maybe-null borrowed FFI reference, this produces a temporary + /// Option (None if null) which is borrowed by the given closure and used + fn maybe_with(maybe_raw: Borrowed, cb: F) -> Output + where F: FnOnce(Option<&Arc>) -> Output { + cb(Self::borrowed_as(&maybe_raw)) + } + + /// Given a non-null strong FFI reference, converts it into an Arc. + /// Panics on null. + fn into(ptr: Strong) -> Arc { + assert!(!ptr.is_null()); + unsafe { transmute(ptr) } + } + + fn borrowed_as<'a>(ptr: &'a Borrowed<'a, Self::FFIType>) -> Option<&'a Arc> { + unsafe { + if ptr.is_null() { + None + } else { + Some(transmute::<&Borrowed<_>, &Arc<_>>(ptr)) + } + } + } + + /// Converts an Arc into a strong FFI reference. + fn from_arc(owned: Arc) -> Strong { + unsafe { transmute(owned) } + } + + /// Artificially increments the refcount of a borrowed Arc over FFI. + unsafe fn addref(ptr: Borrowed) { + Self::with(ptr, |arc| forget(arc.clone())); + } + + /// Given a (possibly null) borrowed FFI reference, decrements the refcount. + /// Unsafe since it doesn't consume the backing Arc. Run it only when you + /// know that a strong reference to the backing Arc is disappearing + /// (usually on the C++ side) without running the Arc destructor. + unsafe fn release(ptr: Borrowed) { + if let Some(arc) = Self::borrowed_as(&ptr) { + let _: Arc<_> = ptr::read(arc as *const Arc<_>); + } + } + + /// Produces a borrowed FFI reference by borrowing an Arc. + fn to_borrowed<'a>(arc: &'a Arc) + -> Borrowed<'a, Self::FFIType> { + let borrowedptr = arc as *const Arc as *const Borrowed<'a, Self::FFIType>; + unsafe { ptr::read(borrowedptr) } + } + + /// Produces a null strong FFI reference + fn null_strong() -> Strong { + unsafe { transmute(ptr::null::()) } + } +} + +#[repr(C)] +/// Gecko-FFI-safe borrowed Arc (&T where T is an ArcInner). +/// This can be null. +pub struct Borrowed<'a, T: 'a> { + ptr: *const T, + _marker: PhantomData<&'a T>, +} + +// manual impls because derive doesn't realize that `T: Clone` isn't necessary +impl<'a, T> Copy for Borrowed<'a, T> {} + +impl<'a, T> Clone for Borrowed<'a, T> { + fn clone(&self) -> Self { *self } +} + +impl<'a, T> Borrowed<'a, T> { + pub fn is_null(&self) -> bool { + self.ptr == ptr::null() + } +} + +#[repr(C)] +/// Gecko-FFI-safe Arc (T is an ArcInner). +/// This can be null. +pub struct Strong { + ptr: *const T, + _marker: PhantomData, +} + +impl Strong { + pub fn is_null(&self) -> bool { + self.ptr == ptr::null() + } +} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 161f0e0a9d8..9a8728db6fb 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -8,14 +8,17 @@ use app_units::Au; use data::{NUM_THREADS, PerDocumentStyleData}; use env_logger; use euclid::Size2D; +use gecko_bindings::bindings::RawServoStyleSet; use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; -use gecko_bindings::bindings::{RawServoStyleSet, RawServoStyleSheet, ServoComputedValues}; +use gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; +use gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; use gecko_bindings::bindings::{ServoDeclarationBlock, ServoNodeData, ThreadSafePrincipalHolder}; use gecko_bindings::bindings::{ThreadSafeURIHolder, nsHTMLCSSStyleSheet}; use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::structs::ServoElementSnapshot; use gecko_bindings::structs::nsRestyleHint; use gecko_bindings::structs::{SheetParsingMode, nsIAtom}; +use gecko_bindings::sugar::refptr::HasArcFFI; use gecko_string_cache::Atom; use snapshot::GeckoElementSnapshot; use std::mem::transmute; @@ -27,7 +30,6 @@ use style::arc_ptr_eq; use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext}; use style::dom::{TDocument, TElement, TNode}; use style::error_reporting::StdoutErrorReporter; -use style::gecko_glue::ArcHelpers; use style::gecko_selector_impl::{GeckoSelectorImpl, PseudoElement}; use style::parallel; use style::parser::ParserContextExtraData; @@ -145,7 +147,7 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, base: *mut ThreadSafeURIHolder, referrer: *mut ThreadSafeURIHolder, principal: *mut ThreadSafePrincipalHolder) - -> *mut RawServoStyleSheet { + -> RawServoStyleSheetStrong { let input = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) }; let origin = match mode { @@ -169,11 +171,10 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, } #[no_mangle] -pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut RawServoStyleSheet, +pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: RawServoStyleSheetBorrowed, raw_data: *mut RawServoStyleSet) { - type Helpers = ArcHelpers; let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); - Helpers::with(raw_sheet, |sheet| { + Stylesheet::with(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); data.stylesheets.push(sheet.clone()); data.stylesheets_changed = true; @@ -181,11 +182,10 @@ pub extern "C" fn Servo_AppendStyleSheet(raw_sheet: *mut RawServoStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: *mut RawServoStyleSheet, +pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: RawServoStyleSheetBorrowed, raw_data: *mut RawServoStyleSet) { - type Helpers = ArcHelpers; let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); - Helpers::with(raw_sheet, |sheet| { + Stylesheet::with(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); data.stylesheets.insert(0, sheet.clone()); data.stylesheets_changed = true; @@ -193,13 +193,12 @@ pub extern "C" fn Servo_PrependStyleSheet(raw_sheet: *mut RawServoStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_InsertStyleSheetBefore(raw_sheet: *mut RawServoStyleSheet, - raw_reference: *mut RawServoStyleSheet, +pub extern "C" fn Servo_InsertStyleSheetBefore(raw_sheet: RawServoStyleSheetBorrowed, + raw_reference: RawServoStyleSheetBorrowed, raw_data: *mut RawServoStyleSet) { - type Helpers = ArcHelpers; let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); - Helpers::with(raw_sheet, |sheet| { - Helpers::with(raw_reference, |reference| { + Stylesheet::with(raw_sheet, |sheet| { + Stylesheet::with(raw_reference, |reference| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); let index = data.stylesheets.iter().position(|x| arc_ptr_eq(x, reference)).unwrap(); data.stylesheets.insert(index, sheet.clone()); @@ -209,37 +208,33 @@ pub extern "C" fn Servo_InsertStyleSheetBefore(raw_sheet: *mut RawServoStyleShee } #[no_mangle] -pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut RawServoStyleSheet, +pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: RawServoStyleSheetBorrowed, raw_data: *mut RawServoStyleSet) { - type Helpers = ArcHelpers; let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); - Helpers::with(raw_sheet, |sheet| { + Stylesheet::with(raw_sheet, |sheet| { data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet)); data.stylesheets_changed = true; }); } #[no_mangle] -pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> bool { - type Helpers = ArcHelpers; - Helpers::with(raw_sheet, |sheet| !sheet.rules.is_empty()) +pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: RawServoStyleSheetBorrowed) -> bool { + Stylesheet::with(raw_sheet, |sheet| !sheet.rules.is_empty()) } #[no_mangle] -pub extern "C" fn Servo_AddRefStyleSheet(sheet: *mut RawServoStyleSheet) -> () { - type Helpers = ArcHelpers; - unsafe { Helpers::addref(sheet) }; +pub extern "C" fn Servo_AddRefStyleSheet(sheet: RawServoStyleSheetBorrowed) -> () { + unsafe { Stylesheet::addref(sheet) }; } #[no_mangle] -pub extern "C" fn Servo_ReleaseStyleSheet(sheet: *mut RawServoStyleSheet) -> () { - type Helpers = ArcHelpers; - unsafe { Helpers::release(sheet) }; +pub extern "C" fn Servo_ReleaseStyleSheet(sheet: RawServoStyleSheetBorrowed) -> () { + unsafe { Stylesheet::release(sheet) }; } #[no_mangle] pub extern "C" fn Servo_GetComputedValues(node: *mut RawGeckoNode) - -> *mut ServoComputedValues { + -> ServoComputedValuesStrong { let node = unsafe { GeckoNode::from_raw(node) }; let arc_cv = match node.borrow_data().map_or(None, |data| data.style.clone()) { Some(style) => style, @@ -252,14 +247,14 @@ pub extern "C" fn Servo_GetComputedValues(node: *mut RawGeckoNode) Arc::new(ComputedValues::initial_values().clone()) }, }; - unsafe { transmute(arc_cv) } + ComputedValues::from_arc(arc_cv) } #[no_mangle] -pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *mut ServoComputedValues, +pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowed, pseudo_tag: *mut nsIAtom, raw_data: *mut RawServoStyleSet) - -> *mut ServoComputedValues { + -> ServoComputedValuesStrong { // The stylist consumes stylesheets lazily. let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); data.flush_stylesheets(); @@ -267,29 +262,27 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: * let atom = Atom::from(pseudo_tag); let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true); - type Helpers = ArcHelpers; - Helpers::maybe_with(parent_style_or_null, |maybe_parent| { + ComputedValues::maybe_with(parent_style_or_null, |maybe_parent| { let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent); - new_computed.map_or(ptr::null_mut(), |c| Helpers::from(c)) + new_computed.map_or(ComputedValues::null_strong(), |c| ComputedValues::from_arc(c)) }) } #[no_mangle] -pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut ServoComputedValues, +pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: ServoComputedValuesBorrowed, match_element: *mut RawGeckoElement, pseudo_tag: *mut nsIAtom, raw_data: *mut RawServoStyleSet, is_probe: bool) - -> *mut ServoComputedValues { + -> ServoComputedValuesStrong { debug_assert!(!match_element.is_null()); let parent_or_null = || { if is_probe { - ptr::null_mut() + ComputedValues::null_strong() } else { - Servo_AddRefComputedValues(parent_style); - parent_style + ComputedValues::from_arc(ComputedValues::with(parent_style, |parent| parent.clone())) } }; @@ -302,7 +295,6 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser let element = unsafe { GeckoElement::from_raw(match_element) }; - type Helpers = ArcHelpers; match GeckoSelectorImpl::pseudo_element_cascade_type(&pseudo) { PseudoElementCascadeType::Eager => { @@ -311,13 +303,13 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser .and_then(|data| { data.per_pseudo.get(&pseudo).map(|c| c.clone()) }); - maybe_computed.map_or_else(parent_or_null, Helpers::from) + maybe_computed.map_or_else(parent_or_null, ComputedValues::from_arc) } PseudoElementCascadeType::Lazy => { - Helpers::with(parent_style, |parent| { + ComputedValues::with(parent_style, |parent| { data.stylist .lazily_compute_pseudo_element_style(&element, &pseudo, parent) - .map_or_else(parent_or_null, Helpers::from) + .map_or_else(parent_or_null, ComputedValues::from_arc) }) } PseudoElementCascadeType::Precomputed => { @@ -328,27 +320,24 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser } #[no_mangle] -pub extern "C" fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues) - -> *mut ServoComputedValues { - type Helpers = ArcHelpers; +pub extern "C" fn Servo_InheritComputedValues(parent_style: ServoComputedValuesBorrowed) + -> ServoComputedValuesStrong { let style = if parent_style.is_null() { Arc::new(ComputedValues::initial_values().clone()) } else { - Helpers::with(parent_style, ComputedValues::inherit_from) + ComputedValues::with(parent_style, ComputedValues::inherit_from) }; - Helpers::from(style) + ComputedValues::from_arc(style) } #[no_mangle] -pub extern "C" fn Servo_AddRefComputedValues(ptr: *mut ServoComputedValues) -> () { - type Helpers = ArcHelpers; - unsafe { Helpers::addref(ptr) }; +pub extern "C" fn Servo_AddRefComputedValues(ptr: ServoComputedValuesBorrowed) -> () { + unsafe { ComputedValues::addref(ptr) }; } #[no_mangle] -pub extern "C" fn Servo_ReleaseComputedValues(ptr: *mut ServoComputedValues) -> () { - type Helpers = ArcHelpers; - unsafe { Helpers::release(ptr) }; +pub extern "C" fn Servo_ReleaseComputedValues(ptr: ServoComputedValuesBorrowed) -> () { + unsafe { ComputedValues::release(ptr) }; } #[no_mangle] diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index 2b27492a86c..78417d5fad8 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -9,7 +9,6 @@ use gecko_bindings::bindings::Gecko_ChildrenCount; use gecko_bindings::bindings::Gecko_ClassOrClassList; use gecko_bindings::bindings::Gecko_GetNodeData; use gecko_bindings::bindings::Gecko_GetStyleContext; -use gecko_bindings::bindings::ServoComputedValues; use gecko_bindings::bindings::ServoNodeData; use gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference}; use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement}; @@ -26,6 +25,7 @@ use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsEle use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO}; use gecko_bindings::structs::{nsIAtom, nsChangeHint, nsStyleContext}; +use gecko_bindings::sugar::refptr::HasArcFFI; use gecko_string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use glue::GeckoDeclarationBlock; use libc::uintptr_t; @@ -43,7 +43,6 @@ use style::dom::{OpaqueNode, PresentationalHintsSynthetizer}; use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode}; use style::element_state::ElementState; use style::error_reporting::StdoutErrorReporter; -use style::gecko_glue::ArcHelpers; use style::gecko_selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; use style::parser::ParserContextExtraData; use style::properties::{ComputedValues, parse_style_attribute}; @@ -108,13 +107,9 @@ impl TRestyleDamage for GeckoRestyleDamage { fn compute(source: &nsStyleContext, new_style: &Arc) -> Self { - type Helpers = ArcHelpers; let context = source as *const nsStyleContext as *mut nsStyleContext; - - Helpers::borrow(new_style, |new_style| { - let hint = unsafe { Gecko_CalcStyleDifference(context, new_style) }; - GeckoRestyleDamage(hint) - }) + let hint = unsafe { Gecko_CalcStyleDifference(context, ComputedValues::to_borrowed(new_style)) }; + GeckoRestyleDamage(hint) } fn rebuild_and_reflow() -> Self {