Skip to content

Commit

Permalink
Bug 1317209 - Part 5: Support transition cascade level. r=emilio
Browse files Browse the repository at this point in the history
Support a new enum, EffectCompositor_CascadeLevel, which is an equivalent of
EffectCompositor::CascadeLevel in Gecko.
  • Loading branch information
BorisChiou committed Jan 24, 2017
1 parent 3a89e89 commit 19aea7e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
12 changes: 8 additions & 4 deletions components/style/dom.rs
Expand Up @@ -227,6 +227,11 @@ pub trait PresentationalHintsSynthetizer {
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.
pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer {
/// The concrete node type.
Expand All @@ -248,10 +253,9 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
/// Get this element's style attribute.
fn style_attribute(&self) -> Option<&Arc<RwLock<PropertyDeclarationBlock>>>;

/// Get this element's animation rule.
fn get_animation_rule(&self, _pseudo: Option<&PseudoElement>)
-> Option<Arc<RwLock<PropertyDeclarationBlock>>> {
None
/// Get this element's animation rules.
fn get_animation_rules(&self, _pseudo: Option<&PseudoElement>) -> AnimationRules {
AnimationRules(None, None)
}

/// Get this element's state, for non-tree-structural pseudos.
Expand Down
12 changes: 8 additions & 4 deletions components/style/gecko/wrapper.rs
Expand Up @@ -16,7 +16,7 @@

use atomic_refcell::AtomicRefCell;
use data::ElementData;
use dom::{LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode};
use dom::{AnimationRules, LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode};
use dom::{OpaqueNode, PresentationalHintsSynthetizer};
use element_state::ElementState;
use error_reporting::StdoutErrorReporter;
Expand All @@ -35,6 +35,7 @@ use gecko_bindings::bindings::Gecko_GetStyleContext;
use gecko_bindings::structs;
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode};
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_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
use parking_lot::RwLock;
Expand Down Expand Up @@ -336,10 +337,13 @@ impl<'le> TElement for GeckoElement<'le> {
declarations.map(|s| s.as_arc_opt()).unwrap_or(None)
}

fn get_animation_rule(&self, pseudo: Option<&PseudoElement>)
-> Option<Arc<RwLock<PropertyDeclarationBlock>>> {
fn get_animation_rules(&self, pseudo: Option<&PseudoElement>) -> AnimationRules {
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 {
Expand Down
4 changes: 3 additions & 1 deletion components/style/gecko_bindings/bindings.rs
Expand Up @@ -3,6 +3,7 @@
pub use nsstring::{nsACString, nsAString};
type nsACString_internal = nsACString;
type nsAString_internal = nsAString;
use gecko_bindings::structs::EffectCompositor_CascadeLevel;
use gecko_bindings::structs::RawGeckoDocument;
use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoNode;
Expand Down Expand Up @@ -503,7 +504,8 @@ extern "C" {
}
extern "C" {
pub fn Gecko_GetAnimationRule(element: RawGeckoElementBorrowed,
aAtom: *mut nsIAtom)
aAtom: *mut nsIAtom,
aCascadeLevel: EffectCompositor_CascadeLevel)
-> RawServoDeclarationBlockStrong;
}
extern "C" {
Expand Down
6 changes: 6 additions & 0 deletions components/style/gecko_bindings/structs_debug.rs
Expand Up @@ -3573,6 +3573,12 @@ pub mod root {
impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self }
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EffectCompositor_CascadeLevel {
Animations = 0,
Transitions = 1,
}
#[repr(C)]
#[derive(Debug)]
pub struct PropertyStyleAnimationValuePair {
Expand Down
6 changes: 6 additions & 0 deletions components/style/gecko_bindings/structs_release.rs
Expand Up @@ -3544,6 +3544,12 @@ pub mod root {
impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self }
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum EffectCompositor_CascadeLevel {
Animations = 0,
Transitions = 1,
}
#[repr(C)]
#[derive(Debug)]
pub struct PropertyStyleAnimationValuePair {
Expand Down
8 changes: 4 additions & 4 deletions components/style/matching.rs
Expand Up @@ -589,14 +589,14 @@ pub trait MatchMethods : TElement {
let mut applicable_declarations: Vec<ApplicableDeclarationBlock> = Vec::with_capacity(16);
let stylist = &context.shared.stylist;
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.
let mut primary_relations =
stylist.push_applicable_declarations(self,
parent_bf,
style_attribute,
animation_rule,
animation_rules,
None,
&mut applicable_declarations,
MatchingReason::ForStyling);
Expand All @@ -606,9 +606,9 @@ pub trait MatchMethods : TElement {
let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default());
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
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,
pseudo_animation_rule,
pseudo_animation_rules,
Some(&pseudo.clone()),
&mut applicable_declarations,
MatchingReason::ForStyling);
Expand Down
22 changes: 17 additions & 5 deletions components/style/stylist.rs
Expand Up @@ -8,7 +8,7 @@

use {Atom, LocalName};
use data::ComputedStyle;
use dom::{PresentationalHintsSynthetizer, TElement};
use dom::{AnimationRules, PresentationalHintsSynthetizer, TElement};
use error_reporting::StdoutErrorReporter;
use keyframes::KeyframesAnimation;
use media_queries::Device;
Expand All @@ -21,7 +21,7 @@ use rule_tree::{RuleTree, StrongRuleNode, StyleSource};
use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot};
use selectors::Element;
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::{MatchingReason, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector};
Expand Down Expand Up @@ -387,7 +387,7 @@ impl Stylist {
self.push_applicable_declarations(element,
None,
None,
None,
AnimationRules(None, None),
Some(pseudo),
&mut declarations,
MatchingReason::ForStyling);
Expand Down Expand Up @@ -492,7 +492,7 @@ impl Stylist {
element: &E,
parent_bf: Option<&BloomFilter>,
style_attribute: Option<&Arc<RwLock<PropertyDeclarationBlock>>>,
animation_rule: Option<Arc<RwLock<PropertyDeclarationBlock>>>,
animation_rules: AnimationRules,
pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations
Expand Down Expand Up @@ -564,7 +564,9 @@ impl Stylist {
debug!("style attr: {:?}", relations);

// 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;
Push::push(
applicable_declarations,
Expand Down Expand Up @@ -617,6 +619,16 @@ impl Stylist {

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);

relations
Expand Down

0 comments on commit 19aea7e

Please sign in to comment.