style: Add way to disable XBL in servo.

Adds a feature "moz_xbl" that when disabled causes the XBL code in servo to
be stubbed out.

Differential Revision: https://phabricator.services.mozilla.com/D45614
This commit is contained in:
Brendan Dahl 2019-10-09 12:56:29 +02:00 committed by Emilio Cobos Álvarez
parent f6b587051d
commit 112a68723e
2 changed files with 33 additions and 1 deletions

View file

@ -25,6 +25,7 @@ servo-layout-2020 = []
gecko_debug = []
gecko_refcount_logging = []
gecko_profiler = []
moz_xbl = []
[dependencies]
app_units = "0.7"

View file

@ -54,8 +54,12 @@ use crate::gecko_bindings::structs::NODE_DESCENDANTS_NEED_FRAMES;
use crate::gecko_bindings::structs::NODE_NEEDS_FRAME;
use crate::gecko_bindings::structs::{nsAtom, nsIContent, nsINode_BooleanFlag};
use crate::gecko_bindings::structs::{
nsINode as RawGeckoNode, nsXBLBinding as RawGeckoXBLBinding, Element as RawGeckoElement,
nsINode as RawGeckoNode, Element as RawGeckoElement,
};
#[cfg(feature = "moz_xbl")]
use crate::gecko_bindings::structs::nsXBLBinding as RawGeckoXBLBinding;
#[cfg(not(feature = "moz_xbl"))]
use values::Impossible;
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use crate::global_style_data::GLOBAL_STYLE_DATA;
use crate::hash::FxHashMap;
@ -529,9 +533,11 @@ impl<'a> Iterator for GeckoChildrenIterator<'a> {
}
/// A Simple wrapper over a non-null Gecko `nsXBLBinding` pointer.
#[cfg(feature = "moz_xbl")]
#[derive(Clone, Copy)]
pub struct GeckoXBLBinding<'lb>(pub &'lb RawGeckoXBLBinding);
#[cfg(feature = "moz_xbl")]
impl<'lb> GeckoXBLBinding<'lb> {
#[inline]
fn base_binding(&self) -> Option<Self> {
@ -556,6 +562,23 @@ impl<'lb> GeckoXBLBinding<'lb> {
}
}
/// A stub wraper for GeckoXBLBinding.
#[cfg(not(feature = "moz_xbl"))]
pub struct GeckoXBLBinding<'lb>(&'lb Impossible);
#[cfg(not(feature = "moz_xbl"))]
impl<'lb> GeckoXBLBinding<'lb> {
#[inline]
fn anon_content(&self) -> *const nsIContent {
match *self.0 {}
}
fn binding_with_content(&self) -> Option<Self> {
None
}
}
/// A simple wrapper over a non-null Gecko `Element` pointer.
#[derive(Clone, Copy)]
pub struct GeckoElement<'le>(pub &'le RawGeckoElement);
@ -681,11 +704,13 @@ impl<'le> GeckoElement<'le> {
})
}
#[cfg(feature = "moz_xbl")]
#[inline]
fn may_be_in_binding_manager(&self) -> bool {
self.flags() & (structs::NODE_MAY_BE_IN_BINDING_MNGR as u32) != 0
}
#[cfg(feature = "moz_xbl")]
#[inline]
fn xbl_binding(&self) -> Option<GeckoXBLBinding<'le>> {
if !self.may_be_in_binding_manager() {
@ -696,6 +721,12 @@ impl<'le> GeckoElement<'le> {
unsafe { slots.mXBLBinding.mRawPtr.as_ref().map(GeckoXBLBinding) }
}
#[cfg(not(feature = "moz_xbl"))]
#[inline]
fn xbl_binding(&self) -> Option<GeckoXBLBinding<'le>> {
None
}
#[inline]
fn xbl_binding_with_content(&self) -> Option<GeckoXBLBinding<'le>> {
self.xbl_binding().and_then(|b| b.binding_with_content())