style: Make Shadow DOM not use XBL anymore.

More improvements to come. In particular, this still iterates through Shadow DOM
in each_xbl_cascade_data, but that should be changed later. That allows to
cleanup a bunch of stuff and finally fix Shadow DOM cascade order.

We still rely on the binding parent to be setup properly in the shadow tree, but
that requirement can go away later (we can walk the containing shadow chain
instead).

This mostly focuses on removing the XBL binding from the Shadow host.

It'd be nice to do EnumerateShadowRoots faster. I think that should also be a
followup, if needed.

Bug: 1425759
Reviewed-by: xidorn
MozReview-Commit-ID: Jf2iGvLC5de
This commit is contained in:
Emilio Cobos Álvarez 2018-02-25 18:01:42 +01:00
parent 28ea593347
commit cfbdf3d694
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 58 additions and 7 deletions

View file

@ -1409,19 +1409,36 @@ impl<'le> TElement for GeckoElement<'le> {
// If we are a NAC pseudo-element, we want to get rules from our // If we are a NAC pseudo-element, we want to get rules from our
// rule_hash_target, that is, our originating element. // rule_hash_target, that is, our originating element.
let mut current = Some(self.rule_hash_target()); let mut current = Some(self.rule_hash_target());
while let Some(element) = current { while let Some(element) = current {
// TODO(emilio): Deal with Shadow DOM separately than with XBL
// (right now we still rely on get_xbl_binding_parent()).
//
// That will allow to clean up a bunch in
// push_applicable_declarations.
if let Some(shadow) = element.shadow_root() {
debug_assert!(!shadow.mServoStyles.mPtr.is_null());
let author_styles = unsafe {
&*(shadow.mServoStyles.mPtr
as *const structs::RawServoAuthorStyles
as *const bindings::RawServoAuthorStyles)
};
let author_styles: &'a _ = AuthorStyles::<GeckoStyleSheet>::from_ffi(author_styles);
f(&author_styles.data, author_styles.quirks_mode);
if element != *self {
break;
}
}
if let Some(binding) = element.xbl_binding() { if let Some(binding) = element.xbl_binding() {
binding.each_xbl_cascade_data(&mut f); binding.each_xbl_cascade_data(&mut f);
// If we're not looking at our original element, allow the // If we're not looking at our original element, allow the
// binding to cut off style inheritance. // binding to cut off style inheritance.
if element != *self { if element != *self && !binding.inherits_style() {
if !binding.inherits_style() { // Go no further; we're not inheriting style from
// Go no further; we're not inheriting style from // anything above here.
// anything above here. break;
break;
}
} }
} }

View file

@ -1149,6 +1149,40 @@ pub unsafe extern "C" fn Servo_AuthorStyles_AppendStyleSheet(
styles.stylesheets.append_stylesheet(None, sheet, &guard); styles.stylesheets.append_stylesheet(None, sheet, &guard);
} }
#[no_mangle]
pub unsafe extern "C" fn Servo_AuthorStyles_InsertStyleSheetBefore(
styles: RawServoAuthorStylesBorrowedMut,
sheet: *const ServoStyleSheet,
before_sheet: *const ServoStyleSheet,
) {
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
styles.stylesheets.insert_stylesheet_before(
None,
GeckoStyleSheet::new(sheet),
GeckoStyleSheet::new(before_sheet),
&guard,
);
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AuthorStyles_RemoveStyleSheet(
styles: RawServoAuthorStylesBorrowedMut,
sheet: *const ServoStyleSheet,
) {
let styles = AuthorStyles::<GeckoStyleSheet>::from_ffi_mut(styles);
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
styles.stylesheets.remove_stylesheet(
None,
GeckoStyleSheet::new(sheet),
&guard,
);
}
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn Servo_AuthorStyles_ForceDirty( pub unsafe extern "C" fn Servo_AuthorStyles_ForceDirty(
styles: RawServoAuthorStylesBorrowedMut, styles: RawServoAuthorStylesBorrowedMut,