From cda445cba5768303e3ed60538a03fd396a19367e Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 21 Dec 2016 17:58:38 -0800 Subject: [PATCH] Bug 1325728 - Simplify pseudo-element handling. r=heycam --- components/style/gecko_bindings/bindings.rs | 17 ++---- ports/geckolib/glue.rs | 67 +++++++++++---------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index c3680ef7edd..b9dc050143b 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1183,17 +1183,6 @@ extern "C" { RawServoStyleSetBorrowed) -> ServoComputedValuesStrong; } -extern "C" { - pub fn Servo_ComputedValues_GetForPseudoElement(parent_style: - ServoComputedValuesBorrowed, - match_element: - RawGeckoElementBorrowed, - pseudo_tag: *mut nsIAtom, - set: - RawServoStyleSetBorrowed, - is_probe: bool) - -> ServoComputedValuesStrong; -} extern "C" { pub fn Servo_ComputedValues_Inherit(parent_style: ServoComputedValuesBorrowedOrNull) @@ -1225,6 +1214,12 @@ extern "C" { compute: LazyComputeBehavior) -> ServoComputedValuesStrong; } +extern "C" { + pub fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, + pseudo_tag: *mut nsIAtom, is_probe: bool, + set: RawServoStyleSetBorrowed) + -> ServoComputedValuesStrong; +} extern "C" { pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed, set: RawServoStyleSetBorrowed, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9a8b6ea0f7e..e59013a931d 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -19,7 +19,7 @@ use style::arc_ptr_eq; use style::atomic_refcell::AtomicRefMut; use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, StyleContext}; use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInfo}; -use style::data::{ElementData, RestyleData}; +use style::data::{ElementData, ElementStyles, RestyleData}; use style::dom::{ShowSubtreeData, TElement, TNode}; use style::error_reporting::StdoutErrorReporter; use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl}; @@ -474,45 +474,46 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: } #[no_mangle] -pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoComputedValuesBorrowed, - match_element: RawGeckoElementBorrowed, - pseudo_tag: *mut nsIAtom, - raw_data: RawServoStyleSetBorrowed, - is_probe: bool) - -> ServoComputedValuesStrong { - debug_assert!(!(match_element as *const _).is_null()); +pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, + pseudo_tag: *mut nsIAtom, is_probe: bool, + raw_data: RawServoStyleSetBorrowed) + -> ServoComputedValuesStrong +{ + let element = GeckoElement(element); + let data = unsafe { element.ensure_data() }.borrow_mut(); - let parent_or_null = || { - if is_probe { + // FIXME(bholley): Assert against this. + if data.get_styles().is_none() { + error!("Calling Servo_ResolvePseudoStyle on unstyled element"); + return if is_probe { Strong::null() } else { - ComputedValues::as_arc(&parent_style).clone().into_strong() - } - }; - - let atom = Atom::from(pseudo_tag); - let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false); - - let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); - let element = GeckoElement(match_element); + Arc::new(ComputedValues::initial_values().clone()).into_strong() + }; + } + let doc_data = PerDocumentStyleData::from_ffi(raw_data); + match get_pseudo_style(element, pseudo_tag, data.styles(), doc_data) { + Some(values) => values.into_strong(), + None if !is_probe => data.styles().primary.values.clone().into_strong(), + None => Strong::null(), + } +} +fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom, + styles: &ElementStyles, doc_data: &PerDocumentStyleData) + -> Option> +{ + let pseudo = PseudoElement::from_atom_unchecked(Atom::from(pseudo_tag), false); match SelectorImpl::pseudo_element_cascade_type(&pseudo) { - PseudoElementCascadeType::Eager => { - let maybe_computed = element.get_pseudo_style(&pseudo); - maybe_computed.map_or_else(parent_or_null, FFIArcHelpers::into_strong) - } + PseudoElementCascadeType::Eager => styles.pseudos.get(&pseudo).map(|s| s.values.clone()), + PseudoElementCascadeType::Precomputed => unreachable!("No anonymous boxes"), PseudoElementCascadeType::Lazy => { - let parent = ComputedValues::as_arc(&parent_style); - data.stylist - .lazily_compute_pseudo_element_style(&element, &pseudo, parent) - .map(|styles| styles.values) - .map_or_else(parent_or_null, FFIArcHelpers::into_strong) - } - PseudoElementCascadeType::Precomputed => { - unreachable!("Anonymous pseudo found in \ - Servo_GetComputedValuesForPseudoElement"); - } + let d = doc_data.borrow_mut(); + let base = &styles.primary.values; + d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base) + .map(|s| s.values.clone()) + }, } }