Auto merge of #12826 - Manishearth:addref, r=emilio,bholley

Add safer bindings for dealing with owned Arcs over FFI

Not yet ready to land, since I need to implement the logic for borrowed refs too. Ready for review for the first part.

The corresponding gecko changes are at https://github.com/servo/gecko-dev/compare/crashfix...Manishearth:addref-borrow

(I'll upload them to the bug once the borrow stuff is done)
r? @bholley

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12826)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-08-17 07:35:43 -05:00 committed by GitHub
commit fc7053e030
13 changed files with 305 additions and 252 deletions

View file

@ -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<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();

View file

@ -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<GeckoType, ServoType> {
phantom1: PhantomData<GeckoType>,
phantom2: PhantomData<ServoType>,
}
impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
pub fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
debug_assert!(!raw.is_null());
let owned = unsafe { Self::into(raw) };
let result = cb(&owned);
forget(owned);
result
}
pub fn maybe_with<F, Output>(maybe_raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(Option<&Arc<ServoType>>) -> 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<ServoType> {
transmute(ptr)
}
pub fn from(owned: Arc<ServoType>) -> *mut GeckoType {
unsafe { transmute(owned) }
}
pub fn borrow<F, Output>(borrowed: &Arc<ServoType>, 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);
}
}

View file

@ -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;

View file

@ -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<bindings::ServoComputedValues, ComputedValues>;
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})
}
</%def>

View file

@ -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)}

View file

@ -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("::")

View file

@ -5,6 +5,10 @@ pub enum nsINode {}
pub enum nsIDocument {}
pub enum nsIPrincipal {}
pub enum nsIURI {}
pub type ServoComputedValuesStrong = ::sugar::refptr::Strong<ServoComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = ::sugar::refptr::Borrowed<'a, ServoComputedValues>;
pub type RawServoStyleSheetStrong = ::sugar::refptr::Strong<RawServoStyleSheet>;
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;
}

View file

@ -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<nsIURI>,
pub mSheetURI: nsCOMPtr<nsIURI>,
@ -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<nsIAtom>,
}
#[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<nsStyleCoord>,
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,

View file

@ -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<nsIURI>,
pub mSheetURI: nsCOMPtr<nsIURI>,
@ -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<nsIAtom>,
}
#[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<nsStyleCoord>,
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,

View file

@ -5,3 +5,4 @@
mod ns_style_auto_array;
pub mod ns_style_coord;
mod ns_t_array;
pub mod refptr;

View file

@ -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<Self>
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<F, Output>(raw: Borrowed<Self::FFIType>, cb: F) -> Output
where F: FnOnce(&Arc<Self>) -> Output {
Self::maybe_with(raw, |opt| cb(opt.unwrap()))
}
/// Given a maybe-null borrowed FFI reference, this produces a temporary
/// Option<Arc> (None if null) which is borrowed by the given closure and used
fn maybe_with<F, Output>(maybe_raw: Borrowed<Self::FFIType>, cb: F) -> Output
where F: FnOnce(Option<&Arc<Self>>) -> 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<Self::FFIType>) -> Arc<Self> {
assert!(!ptr.is_null());
unsafe { transmute(ptr) }
}
fn borrowed_as<'a>(ptr: &'a Borrowed<'a, Self::FFIType>) -> Option<&'a Arc<Self>> {
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<Self>) -> Strong<Self::FFIType> {
unsafe { transmute(owned) }
}
/// Artificially increments the refcount of a borrowed Arc over FFI.
unsafe fn addref(ptr: Borrowed<Self::FFIType>) {
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<Self::FFIType>) {
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<Self>)
-> Borrowed<'a, Self::FFIType> {
let borrowedptr = arc as *const Arc<Self> as *const Borrowed<'a, Self::FFIType>;
unsafe { ptr::read(borrowedptr) }
}
/// Produces a null strong FFI reference
fn null_strong() -> Strong<Self::FFIType> {
unsafe { transmute(ptr::null::<Self::FFIType>()) }
}
}
#[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<T> {
ptr: *const T,
_marker: PhantomData<T>,
}
impl<T> Strong<T> {
pub fn is_null(&self) -> bool {
self.ptr == ptr::null()
}
}

View file

@ -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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<RawServoStyleSheet, Stylesheet>;
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<ServoComputedValues, ComputedValues>;
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<ServoComputedValues, ComputedValues>;
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<ServoComputedValues, ComputedValues>;
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<ServoComputedValues, ComputedValues>;
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<ServoComputedValues, ComputedValues>;
unsafe { Helpers::release(ptr) };
pub extern "C" fn Servo_ReleaseComputedValues(ptr: ServoComputedValuesBorrowed) -> () {
unsafe { ComputedValues::release(ptr) };
}
#[no_mangle]

View file

@ -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<ComputedValues>) -> Self {
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
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 {