From b8fb41da0c7d43ba602a11989334163df307ebd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 24 Feb 2018 21:13:31 +0100 Subject: [PATCH] style: Remove get_css_transitions_info and might_need_transition_update_per_property from TElement. They're only called from wrapper.rs, there's no need to expose them in the common trait. --- components/style/dom.rs | 20 ---- components/style/gecko/wrapper.rs | 146 +++++++++++++++--------------- 2 files changed, 72 insertions(+), 94 deletions(-) diff --git a/components/style/dom.rs b/components/style/dom.rs index 4ba5d27e8ea..5aa339bd772 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -17,8 +17,6 @@ use element_state::ElementState; use font_metrics::FontMetricsProvider; use media_queries::Device; use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock}; -#[cfg(feature = "gecko")] use properties::LonghandId; -#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValue; use selector_parser::{AttrValue, PseudoClassStringArg, PseudoElement, SelectorImpl}; use selectors::Element as SelectorsElement; use selectors::matching::{ElementSelectorFlags, QuirksMode, VisitedHandlingMode}; @@ -26,7 +24,6 @@ use selectors::sink::Push; use servo_arc::{Arc, ArcBorrow}; use shared_lock::Locked; use std::fmt; -#[cfg(feature = "gecko")] use hash::FnvHashMap; use std::fmt::Debug; use std::hash::Hash; use std::ops::Deref; @@ -768,12 +765,6 @@ pub trait TElement cut_off_inheritance } - /// Gets the current existing CSS transitions, by |property, end value| pairs in a FnvHashMap. - #[cfg(feature = "gecko")] - fn get_css_transitions_info( - &self, - ) -> FnvHashMap>; - /// Does a rough (and cheap) check for whether or not transitions might need to be updated that /// will quickly return false for the common case of no transitions specified or running. If /// this returns false, we definitely don't need to update transitions but if it returns true @@ -797,17 +788,6 @@ pub trait TElement after_change_style: &ComputedValues ) -> bool; - /// Returns true if we need to update transitions for the specified property on this element. - #[cfg(feature = "gecko")] - fn needs_transitions_update_per_property( - &self, - property: &LonghandId, - combined_duration: f32, - before_change_style: &ComputedValues, - after_change_style: &ComputedValues, - existing_transitions: &FnvHashMap> - ) -> bool; - /// Returns the value of the `xml:lang=""` attribute (or, if appropriate, /// the `lang=""` attribute) on this element. fn lang_attr(&self) -> Option; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index d243d0f5879..7508da3a7b8 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -772,6 +772,76 @@ impl<'le> GeckoElement<'le> { self.is_in_native_anonymous_subtree() || (!self.is_in_shadow_tree() && self.has_xbl_binding_parent()) } + + fn css_transitions_info(&self) -> FnvHashMap> { + use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt; + use gecko_bindings::bindings::Gecko_ElementTransitions_Length; + + let collection_length = + unsafe { Gecko_ElementTransitions_Length(self.0) } as usize; + let mut map = FnvHashMap::with_capacity_and_hasher( + collection_length, + Default::default() + ); + + for i in 0..collection_length { + let raw_end_value = unsafe { + Gecko_ElementTransitions_EndValueAt(self.0, i) + }; + + let end_value = AnimationValue::arc_from_borrowed(&raw_end_value) + .expect("AnimationValue not found in ElementTransitions"); + + let property = end_value.id(); + map.insert(property, end_value.clone_arc()); + } + map + } + + fn needs_transitions_update_per_property( + &self, + longhand_id: &LonghandId, + combined_duration: f32, + before_change_style: &ComputedValues, + after_change_style: &ComputedValues, + existing_transitions: &FnvHashMap>, + ) -> bool { + use values::animated::{Animate, Procedure}; + + // If there is an existing transition, update only if the end value + // differs. + // + // If the end value has not changed, we should leave the currently + // running transition as-is since we don't want to interrupt its timing + // function. + if let Some(ref existing) = existing_transitions.get(longhand_id) { + let after_value = + AnimationValue::from_computed_values( + longhand_id, + after_change_style + ).unwrap(); + + return ***existing != after_value + } + + let from = AnimationValue::from_computed_values( + &longhand_id, + before_change_style, + ); + let to = AnimationValue::from_computed_values( + &longhand_id, + after_change_style, + ); + + debug_assert_eq!(to.is_some(), from.is_some()); + + combined_duration > 0.0f32 && + from != to && + from.unwrap().animate( + to.as_ref().unwrap(), + Procedure::Interpolate { progress: 0.5 } + ).is_ok() + } } /// Converts flags from the layout used by rust-selectors to the layout used @@ -1395,33 +1465,6 @@ impl<'le> TElement for GeckoElement<'le> { .map(|b| unsafe { GeckoNode::from_content(&*b.anon_content()) }) } - fn get_css_transitions_info( - &self, - ) -> FnvHashMap> { - use gecko_bindings::bindings::Gecko_ElementTransitions_EndValueAt; - use gecko_bindings::bindings::Gecko_ElementTransitions_Length; - - let collection_length = - unsafe { Gecko_ElementTransitions_Length(self.0) } as usize; - let mut map = FnvHashMap::with_capacity_and_hasher( - collection_length, - Default::default() - ); - - for i in 0..collection_length { - let raw_end_value = unsafe { - Gecko_ElementTransitions_EndValueAt(self.0, i) - }; - - let end_value = AnimationValue::arc_from_borrowed(&raw_end_value) - .expect("AnimationValue not found in ElementTransitions"); - - let property = end_value.id(); - map.insert(property, end_value.clone_arc()); - } - map - } - fn might_need_transitions_update( &self, old_values: Option<&ComputedValues>, @@ -1459,7 +1502,7 @@ impl<'le> TElement for GeckoElement<'le> { fn needs_transitions_update( &self, before_change_style: &ComputedValues, - after_change_style: &ComputedValues + after_change_style: &ComputedValues, ) -> bool { use gecko_bindings::structs::nsCSSPropertyID; use properties::LonghandIdSet; @@ -1471,7 +1514,7 @@ impl<'le> TElement for GeckoElement<'le> { let after_change_box_style = after_change_style.get_box(); let transitions_count = after_change_box_style.transition_property_count(); - let existing_transitions = self.get_css_transitions_info(); + let existing_transitions = self.css_transitions_info(); // Check if this property is none, custom or unknown. let is_none_or_custom_property = |property: nsCSSPropertyID| -> bool { @@ -1531,51 +1574,6 @@ impl<'le> TElement for GeckoElement<'le> { }) } - fn needs_transitions_update_per_property( - &self, - longhand_id: &LonghandId, - combined_duration: f32, - before_change_style: &ComputedValues, - after_change_style: &ComputedValues, - existing_transitions: &FnvHashMap>, - ) -> bool { - use values::animated::{Animate, Procedure}; - - // If there is an existing transition, update only if the end value - // differs. - // - // If the end value has not changed, we should leave the currently - // running transition as-is since we don't want to interrupt its timing - // function. - if let Some(ref existing) = existing_transitions.get(longhand_id) { - let after_value = - AnimationValue::from_computed_values( - longhand_id, - after_change_style - ).unwrap(); - - return ***existing != after_value - } - - let from = AnimationValue::from_computed_values( - &longhand_id, - before_change_style, - ); - let to = AnimationValue::from_computed_values( - &longhand_id, - after_change_style, - ); - - debug_assert_eq!(to.is_some(), from.is_some()); - - combined_duration > 0.0f32 && - from != to && - from.unwrap().animate( - to.as_ref().unwrap(), - Procedure::Interpolate { progress: 0.5 } - ).is_ok() - } - #[inline] fn lang_attr(&self) -> Option { let ptr = unsafe { bindings::Gecko_LangValue(self.0) };