From cfbdf3d694740bf0120dc07611e9fd1881fc3bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Feb 2018 18:01:42 +0100 Subject: [PATCH] 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 --- components/style/gecko/wrapper.rs | 31 +++++++++++++++++++++------- ports/geckolib/glue.rs | 34 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index aadf55dd6a7..e8bfdf6dbc7 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1409,19 +1409,36 @@ impl<'le> TElement for GeckoElement<'le> { // If we are a NAC pseudo-element, we want to get rules from our // rule_hash_target, that is, our originating element. let mut current = Some(self.rule_hash_target()); - 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::::from_ffi(author_styles); + f(&author_styles.data, author_styles.quirks_mode); + if element != *self { + break; + } + } + if let Some(binding) = element.xbl_binding() { binding.each_xbl_cascade_data(&mut f); // If we're not looking at our original element, allow the // binding to cut off style inheritance. - if element != *self { - if !binding.inherits_style() { - // Go no further; we're not inheriting style from - // anything above here. - break; - } + if element != *self && !binding.inherits_style() { + // Go no further; we're not inheriting style from + // anything above here. + break; } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9f6a64e0dd1..1896b87fa71 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1149,6 +1149,40 @@ pub unsafe extern "C" fn Servo_AuthorStyles_AppendStyleSheet( 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::::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::::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] pub unsafe extern "C" fn Servo_AuthorStyles_ForceDirty( styles: RawServoAuthorStylesBorrowedMut,