Bug 1317209 - Part 5: Support transition cascade level. r=emilio

Support a new enum, EffectCompositor_CascadeLevel, which is an equivalent of
EffectCompositor::CascadeLevel in Gecko.
This commit is contained in:
Boris Chiou 2017-01-24 15:34:08 +08:00
parent 3a89e89952
commit 19aea7ea78
7 changed files with 52 additions and 18 deletions

View file

@ -227,6 +227,11 @@ pub trait PresentationalHintsSynthetizer {
where V: Push<ApplicableDeclarationBlock>; where V: Push<ApplicableDeclarationBlock>;
} }
/// The animation rules. The first one is for Animation cascade level, and the second one is for
/// Transition cascade level.
pub struct AnimationRules(pub Option<Arc<RwLock<PropertyDeclarationBlock>>>,
pub Option<Arc<RwLock<PropertyDeclarationBlock>>>);
/// The element trait, the main abstraction the style crate acts over. /// The element trait, the main abstraction the style crate acts over.
pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer {
/// The concrete node type. /// The concrete node type.
@ -248,10 +253,9 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
/// Get this element's style attribute. /// Get this element's style attribute.
fn style_attribute(&self) -> Option<&Arc<RwLock<PropertyDeclarationBlock>>>; fn style_attribute(&self) -> Option<&Arc<RwLock<PropertyDeclarationBlock>>>;
/// Get this element's animation rule. /// Get this element's animation rules.
fn get_animation_rule(&self, _pseudo: Option<&PseudoElement>) fn get_animation_rules(&self, _pseudo: Option<&PseudoElement>) -> AnimationRules {
-> Option<Arc<RwLock<PropertyDeclarationBlock>>> { AnimationRules(None, None)
None
} }
/// Get this element's state, for non-tree-structural pseudos. /// Get this element's state, for non-tree-structural pseudos.

View file

@ -16,7 +16,7 @@
use atomic_refcell::AtomicRefCell; use atomic_refcell::AtomicRefCell;
use data::ElementData; use data::ElementData;
use dom::{LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode}; use dom::{AnimationRules, LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode};
use dom::{OpaqueNode, PresentationalHintsSynthetizer}; use dom::{OpaqueNode, PresentationalHintsSynthetizer};
use element_state::ElementState; use element_state::ElementState;
use error_reporting::StdoutErrorReporter; use error_reporting::StdoutErrorReporter;
@ -35,6 +35,7 @@ use gecko_bindings::bindings::Gecko_GetStyleContext;
use gecko_bindings::structs; use gecko_bindings::structs;
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode}; use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode};
use gecko_bindings::structs::{nsIAtom, nsIContent, nsStyleContext}; use gecko_bindings::structs::{nsIAtom, nsIContent, nsStyleContext};
use gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel;
use gecko_bindings::structs::NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO; use gecko_bindings::structs::NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO;
use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE; use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
use parking_lot::RwLock; use parking_lot::RwLock;
@ -336,10 +337,13 @@ impl<'le> TElement for GeckoElement<'le> {
declarations.map(|s| s.as_arc_opt()).unwrap_or(None) declarations.map(|s| s.as_arc_opt()).unwrap_or(None)
} }
fn get_animation_rule(&self, pseudo: Option<&PseudoElement>) fn get_animation_rules(&self, pseudo: Option<&PseudoElement>) -> AnimationRules {
-> Option<Arc<RwLock<PropertyDeclarationBlock>>> {
let atom_ptr = pseudo.map(|p| p.as_atom().as_ptr()).unwrap_or(ptr::null_mut()); let atom_ptr = pseudo.map(|p| p.as_atom().as_ptr()).unwrap_or(ptr::null_mut());
unsafe { Gecko_GetAnimationRule(self.0, atom_ptr) }.into_arc_opt() unsafe {
AnimationRules(
Gecko_GetAnimationRule(self.0, atom_ptr, CascadeLevel::Animations).into_arc_opt(),
Gecko_GetAnimationRule(self.0, atom_ptr, CascadeLevel::Transitions).into_arc_opt())
}
} }
fn get_state(&self) -> ElementState { fn get_state(&self) -> ElementState {

View file

@ -3,6 +3,7 @@
pub use nsstring::{nsACString, nsAString}; pub use nsstring::{nsACString, nsAString};
type nsACString_internal = nsACString; type nsACString_internal = nsACString;
type nsAString_internal = nsAString; type nsAString_internal = nsAString;
use gecko_bindings::structs::EffectCompositor_CascadeLevel;
use gecko_bindings::structs::RawGeckoDocument; use gecko_bindings::structs::RawGeckoDocument;
use gecko_bindings::structs::RawGeckoElement; use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoNode; use gecko_bindings::structs::RawGeckoNode;
@ -503,7 +504,8 @@ extern "C" {
} }
extern "C" { extern "C" {
pub fn Gecko_GetAnimationRule(element: RawGeckoElementBorrowed, pub fn Gecko_GetAnimationRule(element: RawGeckoElementBorrowed,
aAtom: *mut nsIAtom) aAtom: *mut nsIAtom,
aCascadeLevel: EffectCompositor_CascadeLevel)
-> RawServoDeclarationBlockStrong; -> RawServoDeclarationBlockStrong;
} }
extern "C" { extern "C" {

View file

@ -3573,6 +3573,12 @@ pub mod root {
impl Clone for StyleComplexColor { impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
} }
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EffectCompositor_CascadeLevel {
Animations = 0,
Transitions = 1,
}
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PropertyStyleAnimationValuePair { pub struct PropertyStyleAnimationValuePair {

View file

@ -3544,6 +3544,12 @@ pub mod root {
impl Clone for StyleComplexColor { impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
} }
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EffectCompositor_CascadeLevel {
Animations = 0,
Transitions = 1,
}
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PropertyStyleAnimationValuePair { pub struct PropertyStyleAnimationValuePair {

View file

@ -589,14 +589,14 @@ pub trait MatchMethods : TElement {
let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16); let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16);
let stylist = &context.shared.stylist; let stylist = &context.shared.stylist;
let style_attribute = self.style_attribute(); let style_attribute = self.style_attribute();
let animation_rule = self.get_animation_rule(None); let animation_rules = self.get_animation_rules(None);
// Compute the primary rule node. // Compute the primary rule node.
let mut primary_relations = let mut primary_relations =
stylist.push_applicable_declarations(self, stylist.push_applicable_declarations(self,
parent_bf, parent_bf,
style_attribute, style_attribute,
animation_rule, animation_rules,
None, None,
&mut applicable_declarations, &mut applicable_declarations,
MatchingReason::ForStyling); MatchingReason::ForStyling);
@ -606,9 +606,9 @@ pub trait MatchMethods : TElement {
let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default()); let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default());
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
debug_assert!(applicable_declarations.is_empty()); debug_assert!(applicable_declarations.is_empty());
let pseudo_animation_rule = self.get_animation_rule(Some(&pseudo)); let pseudo_animation_rules = self.get_animation_rules(Some(&pseudo));
stylist.push_applicable_declarations(self, parent_bf, None, stylist.push_applicable_declarations(self, parent_bf, None,
pseudo_animation_rule, pseudo_animation_rules,
Some(&pseudo.clone()), Some(&pseudo.clone()),
&mut applicable_declarations, &mut applicable_declarations,
MatchingReason::ForStyling); MatchingReason::ForStyling);

View file

@ -8,7 +8,7 @@
use {Atom, LocalName}; use {Atom, LocalName};
use data::ComputedStyle; use data::ComputedStyle;
use dom::{PresentationalHintsSynthetizer, TElement}; use dom::{AnimationRules, PresentationalHintsSynthetizer, TElement};
use error_reporting::StdoutErrorReporter; use error_reporting::StdoutErrorReporter;
use keyframes::KeyframesAnimation; use keyframes::KeyframesAnimation;
use media_queries::Device; use media_queries::Device;
@ -21,7 +21,7 @@ use rule_tree::{RuleTree, StrongRuleNode, StyleSource};
use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot}; use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::AFFECTED_BY_ANIMATIONS; use selectors::matching::{AFFECTED_BY_ANIMATIONS, AFFECTED_BY_TRANSITIONS};
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS}; use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
use selectors::matching::{MatchingReason, StyleRelations, matches_complex_selector}; use selectors::matching::{MatchingReason, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector}; use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector};
@ -387,7 +387,7 @@ impl Stylist {
self.push_applicable_declarations(element, self.push_applicable_declarations(element,
None, None,
None, None,
None, AnimationRules(None, None),
Some(pseudo), Some(pseudo),
&mut declarations, &mut declarations,
MatchingReason::ForStyling); MatchingReason::ForStyling);
@ -492,7 +492,7 @@ impl Stylist {
element: &E, element: &E,
parent_bf: Option<&BloomFilter>, parent_bf: Option<&BloomFilter>,
style_attribute: Option<&Arc<RwLock<PropertyDeclarationBlock>>>, style_attribute: Option<&Arc<RwLock<PropertyDeclarationBlock>>>,
animation_rule: Option<Arc<RwLock<PropertyDeclarationBlock>>>, animation_rules: AnimationRules,
pseudo_element: Option<&PseudoElement>, pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V, applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations reason: MatchingReason) -> StyleRelations
@ -564,7 +564,9 @@ impl Stylist {
debug!("style attr: {:?}", relations); debug!("style attr: {:?}", relations);
// Step 5: Animations. // Step 5: Animations.
if let Some(anim) = animation_rule { // The animations sheet (CSS animations, script-generated animations,
// and CSS transitions that are no longer tied to CSS markup)
if let Some(anim) = animation_rules.0 {
relations |= AFFECTED_BY_ANIMATIONS; relations |= AFFECTED_BY_ANIMATIONS;
Push::push( Push::push(
applicable_declarations, applicable_declarations,
@ -617,6 +619,16 @@ impl Stylist {
debug!("UA important: {:?}", relations); debug!("UA important: {:?}", relations);
// Step 10: Transitions.
// The transitions sheet (CSS transitions that are tied to CSS markup)
if let Some(anim) = animation_rules.1 {
relations |= AFFECTED_BY_TRANSITIONS;
Push::push(
applicable_declarations,
ApplicableDeclarationBlock::from_declarations(anim.clone(), Importance::Normal));
}
debug!("transition: {:?}", relations);
debug!("push_applicable_declarations: shareable: {:?}", relations); debug!("push_applicable_declarations: shareable: {:?}", relations);
relations relations