From fb6aceba31a88c2fac329b57a60d21d4745c25c9 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Thu, 6 Apr 2017 10:01:50 +0900 Subject: [PATCH] Add a function that returns a base computed values (i.e. computed values without any animations rules). This base value will be used for additive, accumulative animations and also SMIL. --- components/style/matching.rs | 28 ++++++++++++++++++++++++++++ ports/geckolib/glue.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/components/style/matching.rs b/components/style/matching.rs index 46e249863d0..4bc5a183167 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -1210,6 +1210,34 @@ pub trait MatchMethods : TElement { }); } } + + /// Returns computed values without animation and transition rules. + fn get_base_style(&self, + shared_context: &SharedStyleContext, + primary_style: &ComputedStyle, + pseudo_style: &Option<(&PseudoElement, &ComputedStyle)>) + -> Arc { + let style = &pseudo_style.as_ref().map_or(primary_style, |p| &*p.1); + let rule_node = &style.rules; + let without_animation_rules = + shared_context.stylist.rule_tree.remove_animation_and_transition_rules(rule_node); + if without_animation_rules == *rule_node { + // Note that unwrapping here is fine, because the style is + // only incomplete during the styling process. + return style.values.as_ref().unwrap().clone(); + } + + let mut cascade_flags = CascadeFlags::empty(); + if self.skip_root_and_item_based_display_fixup() { + cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) + } + self.cascade_with_rules(shared_context, + &without_animation_rules, + primary_style, + cascade_flags, + pseudo_style.is_some()) + } + } impl MatchMethods for E {} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 69a2b57d30e..b093919462a 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -310,6 +310,36 @@ pub extern "C" fn Servo_AnimationValue_DeepEqual(this: RawServoAnimationValueBor this_value == other_value } +#[no_mangle] +pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawServoStyleSetBorrowed, + element: RawGeckoElementBorrowed, + pseudo_tag: *mut nsIAtom) + -> ServoComputedValuesStrong +{ + use style::matching::MatchMethods; + + let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); + let global_style_data = &*GLOBAL_STYLE_DATA; + let guard = global_style_data.shared_lock.read(); + let shared_context = &create_shared_context(&guard, &doc_data, false); + + let element = GeckoElement(element); + let element_data = element.borrow_data().unwrap(); + let styles = element_data.styles(); + + let pseudo = if pseudo_tag.is_null() { + None + } else { + let atom = Atom::from(pseudo_tag); + Some(PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false)) + }; + let pseudos = &styles.pseudos; + let pseudo_style = pseudo.as_ref().map(|p| (p, pseudos.get(p).unwrap())); + + element.get_base_style(shared_context, &styles.primary, &pseudo_style) + .into_strong() +} + #[no_mangle] pub extern "C" fn Servo_StyleWorkerThreadCount() -> u32 { GLOBAL_STYLE_DATA.num_threads as u32