Auto merge of #13404 - bholley:manage_node_data, r=Manishearth

stylo: Manage servo node data directly from Servo

Servo-side changes for: https://bugzilla.mozilla.org/show_bug.cgi?id=1304913

<!-- 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/13404)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-24 05:17:29 -05:00 committed by GitHub
commit 0dd005eacc
7 changed files with 1534 additions and 1127 deletions

View file

@ -66,6 +66,10 @@ COMPILATION_TARGETS = {
"release": {
}
},
"raw_lines": [
# We can get rid of this when the bindings move into the style crate.
"pub enum OpaqueStyleData {}",
],
"whitelist_vars": [
"NS_THEME_.*",
"NODE_.*",
@ -77,6 +81,9 @@ COMPILATION_TARGETS = {
"BORDER_STYLE_.*"
],
"whitelist": [
"RawGeckoNode",
"RawGeckoElement",
"RawGeckoDocument",
"Element",
"Side",
"nsTArrayHeader",
@ -168,6 +175,21 @@ COMPILATION_TARGETS = {
"gfxSize", # <- Same, union { struct { T width; T height; }; T components[2] };
"gfxSize_Super", # Ditto.
],
"servo_mapped_generic_types": [
{
"generic": True,
"gecko": "ServoUnsafeCell",
"servo": "::std::cell::UnsafeCell"
}, {
"generic": True,
"gecko": "ServoCell",
"servo": "::std::cell::Cell"
}, {
"generic": False,
"gecko": "ServoNodeData",
"servo": "OpaqueStyleData"
}
],
},
# Generation of the ffi bindings.
"bindings": {
@ -206,6 +228,8 @@ COMPILATION_TARGETS = {
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
"StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
"RawGeckoNode", "RawGeckoElement", "RawGeckoDocument",
"ServoNodeData",
],
"servo_nullable_arc_types": [
"ServoComputedValues", "RawServoStyleSheet",
@ -213,7 +237,6 @@ COMPILATION_TARGETS = {
],
"servo_owned_types": [
"RawServoStyleSet",
"ServoNodeData",
"StyleChildrenIterator",
],
"servo_immutable_borrow_types": [
@ -430,7 +453,17 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
flags.append("{}BorrowedOrNull".format(ty))
flags.append("--raw-line")
flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty))
zero_size_type(ty, flags)
# Right now the only immutable borrow types are ones which we import
# from the |structs| module. As such, we don't need to create an opaque
# type with zero_size_type. If we ever introduce immutable borrow types
# which _do_ need to be opaque, we'll need a separate mode.
if "servo_mapped_generic_types" in current_target:
for ty in current_target["servo_mapped_generic_types"]:
flags.append("--blacklist-type")
flags.append("{}".format(ty["gecko"]))
flags.append("--raw-line")
flags.append("pub type {0}{2} = {1}{2};".format(ty["gecko"], ty["servo"], "<T>" if ty["generic"] else ""))
if "servo_owned_types" in current_target:
for ty in current_target["servo_owned_types"]:

View file

@ -18,16 +18,10 @@ enum ServoDeclarationBlockVoid{ }
pub struct ServoDeclarationBlock(ServoDeclarationBlockVoid);
pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode;
pub type RawGeckoNodeBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoNode>;
enum RawGeckoNodeVoid{ }
pub struct RawGeckoNode(RawGeckoNodeVoid);
pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement;
pub type RawGeckoElementBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoElement>;
enum RawGeckoElementVoid{ }
pub struct RawGeckoElement(RawGeckoElementVoid);
pub type RawGeckoDocumentBorrowed<'a> = &'a RawGeckoDocument;
pub type RawGeckoDocumentBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoDocument>;
enum RawGeckoDocumentVoid{ }
pub struct RawGeckoDocument(RawGeckoDocumentVoid);
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
pub type RawServoStyleSetBorrowedMut<'a> = &'a mut RawServoStyleSet;
pub type RawServoStyleSetOwned = ::sugar::ownership::Owned<RawServoStyleSet>;
@ -36,14 +30,6 @@ pub type RawServoStyleSetBorrowedMutOrNull<'a> = ::sugar::ownership::BorrowedMut
pub type RawServoStyleSetOwnedOrNull = ::sugar::ownership::OwnedOrNull<RawServoStyleSet>;
enum RawServoStyleSetVoid{ }
pub struct RawServoStyleSet(RawServoStyleSetVoid);
pub type ServoNodeDataBorrowed<'a> = &'a ServoNodeData;
pub type ServoNodeDataBorrowedMut<'a> = &'a mut ServoNodeData;
pub type ServoNodeDataOwned = ::sugar::ownership::Owned<ServoNodeData>;
pub type ServoNodeDataBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, ServoNodeData>;
pub type ServoNodeDataBorrowedMutOrNull<'a> = ::sugar::ownership::BorrowedMut<'a, ServoNodeData>;
pub type ServoNodeDataOwnedOrNull = ::sugar::ownership::OwnedOrNull<ServoNodeData>;
enum ServoNodeDataVoid{ }
pub struct ServoNodeData(ServoNodeDataVoid);
pub type StyleChildrenIteratorBorrowed<'a> = &'a StyleChildrenIterator;
pub type StyleChildrenIteratorBorrowedMut<'a> = &'a mut StyleChildrenIterator;
pub type StyleChildrenIteratorOwned = ::sugar::ownership::Owned<StyleChildrenIterator>;
@ -179,6 +165,10 @@ use structs::nsINode;
use structs::nsIDocument;
use structs::nsIPrincipal;
use structs::nsIURI;
use structs::RawGeckoNode;
use structs::RawGeckoElement;
use structs::RawGeckoDocument;
use structs::ServoNodeData;
extern "C" {
pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void,
@ -189,7 +179,7 @@ extern "C" {
aElementSize: usize, aElementAlign: usize);
}
extern "C" {
pub fn Servo_NodeData_Drop(arg1: *mut ServoNodeData);
pub fn Servo_Node_ClearNodeData(arg1: *mut nsINode);
}
#[repr(C)]
#[derive(Debug, Copy)]
@ -387,14 +377,6 @@ extern "C" {
pub fn Gecko_GetServoDeclarationBlock(element: RawGeckoElementBorrowed)
-> ServoDeclarationBlockBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetNodeData(node: RawGeckoNodeBorrowed)
-> ServoNodeDataBorrowedOrNull;
}
extern "C" {
pub fn Gecko_SetNodeData(node: RawGeckoNodeBorrowed,
data: ServoNodeDataOwned);
}
extern "C" {
pub fn Gecko_Atomize(aString: *const ::std::os::raw::c_char, aLength: u32)
-> *mut nsIAtom;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -9,7 +9,7 @@ use data::{NUM_THREADS, PerDocumentStyleData};
use env_logger;
use euclid::Size2D;
use gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed};
use gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned, ServoNodeDataOwned};
use gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use gecko_bindings::bindings::{RawServoStyleSetBorrowedMut, RawGeckoDocumentBorrowed};
use gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
@ -44,7 +44,7 @@ use style::stylesheets::{Origin, Stylesheet};
use style::timer::Timer;
use traversal::RecalcStyleOnly;
use url::Url;
use wrapper::{DUMMY_BASE_URL, GeckoDocument, GeckoElement, GeckoNode, NonOpaqueStyleData};
use wrapper::{DUMMY_BASE_URL, GeckoDocument, GeckoElement, GeckoNode};
/*
* For Gecko->Servo function calls, we need to redeclare the same signature that was declared in
@ -126,8 +126,9 @@ pub extern "C" fn Servo_StyleWorkerThreadCount() -> u32 {
}
#[no_mangle]
pub extern "C" fn Servo_NodeData_Drop(data: ServoNodeDataOwned) -> () {
let _ = data.into_box::<NonOpaqueStyleData>();
pub extern "C" fn Servo_Node_ClearNodeData(node: RawGeckoNodeBorrowed) -> () {
let node = GeckoNode(node);
node.clear_data();
}
#[no_mangle]

View file

@ -486,6 +486,8 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_curpos: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms7currentE"]
pub static nsGkAtoms_current: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms12cutoutregionE"]
pub static nsGkAtoms_cutoutregion: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms6cyclerE"]
pub static nsGkAtoms_cycler: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms4dataE"]
@ -4100,6 +4102,10 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_onencrypted: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms9encryptedE"]
pub static nsGkAtoms_encrypted: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms15onwaitingforkeyE"]
pub static nsGkAtoms_onwaitingforkey: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms19onkeystatuseschangeE"]
pub static nsGkAtoms_onkeystatuseschange: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms13onremovetrackE"]
pub static nsGkAtoms_onremovetrack: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms9loadstartE"]
@ -4320,8 +4326,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_windows_default_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms18mac_graphite_themeE"]
pub static nsGkAtoms_mac_graphite_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms14mac_lion_themeE"]
pub static nsGkAtoms_mac_lion_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms18mac_yosemite_themeE"]
pub static nsGkAtoms_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms18windows_compositorE"]
@ -4376,8 +4380,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms__moz_windows_default_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms23_moz_mac_graphite_themeE"]
pub static nsGkAtoms__moz_mac_graphite_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms19_moz_mac_lion_themeE"]
pub static nsGkAtoms__moz_mac_lion_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms23_moz_mac_yosemite_themeE"]
pub static nsGkAtoms__moz_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "_ZN9nsGkAtoms23_moz_windows_compositorE"]
@ -5405,6 +5407,8 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_curpos: *mut nsIAtom;
#[link_name = "?current@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_current: *mut nsIAtom;
#[link_name = "?cutoutregion@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_cutoutregion: *mut nsIAtom;
#[link_name = "?cycler@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_cycler: *mut nsIAtom;
#[link_name = "?data@nsGkAtoms@@2PEAVnsIAtom@@EA"]
@ -9019,6 +9023,10 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_onencrypted: *mut nsIAtom;
#[link_name = "?encrypted@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_encrypted: *mut nsIAtom;
#[link_name = "?onwaitingforkey@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_onwaitingforkey: *mut nsIAtom;
#[link_name = "?onkeystatuseschange@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_onkeystatuseschange: *mut nsIAtom;
#[link_name = "?onremovetrack@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_onremovetrack: *mut nsIAtom;
#[link_name = "?loadstart@nsGkAtoms@@2PEAVnsIAtom@@EA"]
@ -9239,8 +9247,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_windows_default_theme: *mut nsIAtom;
#[link_name = "?mac_graphite_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_mac_graphite_theme: *mut nsIAtom;
#[link_name = "?mac_lion_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_mac_lion_theme: *mut nsIAtom;
#[link_name = "?mac_yosemite_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "?windows_compositor@nsGkAtoms@@2PEAVnsIAtom@@EA"]
@ -9295,8 +9301,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms__moz_windows_default_theme: *mut nsIAtom;
#[link_name = "?_moz_mac_graphite_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms__moz_mac_graphite_theme: *mut nsIAtom;
#[link_name = "?_moz_mac_lion_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms__moz_mac_lion_theme: *mut nsIAtom;
#[link_name = "?_moz_mac_yosemite_theme@nsGkAtoms@@2PEAVnsIAtom@@EA"]
pub static nsGkAtoms__moz_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "?_moz_windows_compositor@nsGkAtoms@@2PEAVnsIAtom@@EA"]
@ -10324,6 +10328,8 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_curpos: *mut nsIAtom;
#[link_name = "\x01?current@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_current: *mut nsIAtom;
#[link_name = "\x01?cutoutregion@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_cutoutregion: *mut nsIAtom;
#[link_name = "\x01?cycler@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_cycler: *mut nsIAtom;
#[link_name = "\x01?data@nsGkAtoms@@2PAVnsIAtom@@A"]
@ -13938,6 +13944,10 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_onencrypted: *mut nsIAtom;
#[link_name = "\x01?encrypted@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_encrypted: *mut nsIAtom;
#[link_name = "\x01?onwaitingforkey@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_onwaitingforkey: *mut nsIAtom;
#[link_name = "\x01?onkeystatuseschange@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_onkeystatuseschange: *mut nsIAtom;
#[link_name = "\x01?onremovetrack@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_onremovetrack: *mut nsIAtom;
#[link_name = "\x01?loadstart@nsGkAtoms@@2PAVnsIAtom@@A"]
@ -14158,8 +14168,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms_windows_default_theme: *mut nsIAtom;
#[link_name = "\x01?mac_graphite_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_mac_graphite_theme: *mut nsIAtom;
#[link_name = "\x01?mac_lion_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_mac_lion_theme: *mut nsIAtom;
#[link_name = "\x01?mac_yosemite_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "\x01?windows_compositor@nsGkAtoms@@2PAVnsIAtom@@A"]
@ -14214,8 +14222,6 @@ pub enum nsICSSAnonBoxPseudo {}
pub static nsGkAtoms__moz_windows_default_theme: *mut nsIAtom;
#[link_name = "\x01?_moz_mac_graphite_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms__moz_mac_graphite_theme: *mut nsIAtom;
#[link_name = "\x01?_moz_mac_lion_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms__moz_mac_lion_theme: *mut nsIAtom;
#[link_name = "\x01?_moz_mac_yosemite_theme@nsGkAtoms@@2PAVnsIAtom@@A"]
pub static nsGkAtoms__moz_mac_yosemite_theme: *mut nsIAtom;
#[link_name = "\x01?_moz_windows_compositor@nsGkAtoms@@2PAVnsIAtom@@A"]
@ -15013,6 +15019,7 @@ macro_rules! atom {
("crossorigin") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_crossorigin as *mut _) };
("curpos") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_curpos as *mut _) };
("current") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_current as *mut _) };
("cutoutregion") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_cutoutregion as *mut _) };
("cycler") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_cycler as *mut _) };
("data") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_data as *mut _) };
("datalist") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_datalist as *mut _) };
@ -16820,6 +16827,8 @@ macro_rules! atom {
("onexit") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_onexit as *mut _) };
("onencrypted") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_onencrypted as *mut _) };
("encrypted") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_encrypted as *mut _) };
("onwaitingforkey") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_onwaitingforkey as *mut _) };
("onkeystatuseschange") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_onkeystatuseschange as *mut _) };
("onremovetrack") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_onremovetrack as *mut _) };
("loadstart") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_loadstart as *mut _) };
("suspend") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_suspend as *mut _) };
@ -16930,7 +16939,6 @@ macro_rules! atom {
("overlay-scrollbars") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_overlay_scrollbars as *mut _) };
("windows-default-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_windows_default_theme as *mut _) };
("mac-graphite-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_mac_graphite_theme as *mut _) };
("mac-lion-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_mac_lion_theme as *mut _) };
("mac-yosemite-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_mac_yosemite_theme as *mut _) };
("windows-compositor") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_windows_compositor as *mut _) };
("windows-glass") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms_windows_glass as *mut _) };
@ -16958,7 +16966,6 @@ macro_rules! atom {
("-moz-overlay-scrollbars") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_overlay_scrollbars as *mut _) };
("-moz-windows-default-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_windows_default_theme as *mut _) };
("-moz-mac-graphite-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_mac_graphite_theme as *mut _) };
("-moz-mac-lion-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_mac_lion_theme as *mut _) };
("-moz-mac-yosemite-theme") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_mac_yosemite_theme as *mut _) };
("-moz-windows-compositor") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_windows_compositor as *mut _) };
("-moz-windows-classic") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::nsGkAtoms__moz_windows_classic as *mut _) };

View file

@ -17,16 +17,14 @@ use gecko_bindings::bindings::{Gecko_GetPrevSibling, Gecko_GetPrevSiblingElement
use gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument};
use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_IsTextNode};
use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink};
use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement, Gecko_SetNodeData};
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement};
use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_GetNodeData;
use gecko_bindings::bindings::Gecko_GetStyleContext;
use gecko_bindings::bindings::ServoNodeData;
use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO};
use gecko_bindings::structs::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use gecko_bindings::structs::{nsChangeHint, nsIAtom, nsStyleContext};
use gecko_bindings::sugar::ownership::{FFIArcHelpers, HasBoxFFI, HasFFI, HasSimpleFFI};
use gecko_bindings::sugar::ownership::Borrowed;
use gecko_bindings::structs::OpaqueStyleData;
use gecko_bindings::sugar::ownership::FFIArcHelpers;
use gecko_string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use glue::GeckoDeclarationBlock;
use libc::uintptr_t;
@ -55,18 +53,21 @@ use url::Url;
pub struct NonOpaqueStyleData(RefCell<PrivateStyleData>);
unsafe impl HasFFI for NonOpaqueStyleData {
type FFIType = ServoNodeData;
}
unsafe impl HasSimpleFFI for NonOpaqueStyleData {}
unsafe impl HasBoxFFI for NonOpaqueStyleData {}
impl NonOpaqueStyleData {
pub fn new() -> Self {
NonOpaqueStyleData(RefCell::new(PrivateStyleData::new()))
}
}
// We can eliminate OpaqueStyleData when the bindings move into the style crate.
fn to_opaque_style_data(d: *mut NonOpaqueStyleData) -> *mut OpaqueStyleData {
d as *mut OpaqueStyleData
}
fn from_opaque_style_data(d: *mut OpaqueStyleData) -> *mut NonOpaqueStyleData {
d as *mut NonOpaqueStyleData
}
// Important: We don't currently refcount the DOM, because the wrapper lifetime
// magic guarantees that our LayoutFoo references won't outlive the root, and
// we don't mutate any of the references on the Gecko side during restyle. We
@ -76,18 +77,25 @@ impl NonOpaqueStyleData {
pub struct GeckoNode<'ln>(pub &'ln RawGeckoNode);
impl<'ln> GeckoNode<'ln> {
fn get_node_data(&self) -> Borrowed<NonOpaqueStyleData> {
fn get_node_data(&self) -> Option<&NonOpaqueStyleData> {
unsafe {
Borrowed::from_ffi(Gecko_GetNodeData(&*self.0))
from_opaque_style_data(self.0.mServoData.get()).as_ref()
}
}
pub fn initialize_data(self) {
unsafe {
if self.get_node_data().is_null() {
let ptr = Box::new(NonOpaqueStyleData::new());
Gecko_SetNodeData(self.0, ptr.into_ffi());
}
if self.get_node_data().is_none() {
let ptr = Box::new(NonOpaqueStyleData::new());
debug_assert!(self.0.mServoData.get().is_null());
self.0.mServoData.set(to_opaque_style_data(Box::into_raw(ptr)));
}
}
pub fn clear_data(self) {
if !self.get_node_data().is_none() {
let d = from_opaque_style_data(self.0.mServoData.get());
let _ = unsafe { Box::from_raw(d) };
self.0.mServoData.set(ptr::null_mut());
}
}
}
@ -210,7 +218,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
fn is_dirty(&self) -> bool {
// Return true unconditionally if we're not yet styled. This is a hack
// and should go away soon.
if self.get_node_data().is_null() {
if self.get_node_data().is_none() {
return true;
}
@ -229,7 +237,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
fn has_dirty_descendants(&self) -> bool {
// Return true unconditionally if we're not yet styled. This is a hack
// and should go away soon.
if self.get_node_data().is_null() {
if self.get_node_data().is_none() {
return true;
}
let flags = unsafe { Gecko_GetNodeFlags(self.0) };
@ -257,18 +265,18 @@ impl<'ln> TNode for GeckoNode<'ln> {
#[inline(always)]
unsafe fn borrow_data_unchecked(&self) -> Option<*const PrivateStyleData> {
self.get_node_data().borrow_opt().map(|d| d.0.as_unsafe_cell().get()
self.get_node_data().as_ref().map(|d| d.0.as_unsafe_cell().get()
as *const PrivateStyleData)
}
#[inline(always)]
fn borrow_data(&self) -> Option<Ref<PrivateStyleData>> {
self.get_node_data().borrow_opt().map(|d| d.0.borrow())
self.get_node_data().as_ref().map(|d| d.0.borrow())
}
#[inline(always)]
fn mutate_data(&self) -> Option<RefMut<PrivateStyleData>> {
self.get_node_data().borrow_opt().map(|d| d.0.borrow_mut())
self.get_node_data().as_ref().map(|d| d.0.borrow_mut())
}
fn restyle_damage(self) -> Self::ConcreteRestyleDamage {