Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef NS_SMILCOMPOSITOR_H_
8 : #define NS_SMILCOMPOSITOR_H_
9 :
10 : #include "mozilla/Move.h"
11 : #include "mozilla/UniquePtr.h"
12 : #include "nsTHashtable.h"
13 : #include "nsString.h"
14 : #include "nsSMILAnimationFunction.h"
15 : #include "nsSMILTargetIdentifier.h"
16 : #include "nsSMILCompositorTable.h"
17 : #include "PLDHashTable.h"
18 :
19 : //----------------------------------------------------------------------
20 : // nsSMILCompositor
21 : //
22 : // Performs the composition of the animation sandwich by combining the results
23 : // of a series animation functions according to the rules of SMIL composition
24 : // including prioritising animations.
25 :
26 : class nsSMILCompositor : public PLDHashEntryHdr
27 : {
28 : public:
29 : typedef nsSMILTargetIdentifier KeyType;
30 : typedef const KeyType& KeyTypeRef;
31 : typedef const KeyType* KeyTypePointer;
32 :
33 0 : explicit nsSMILCompositor(KeyTypePointer aKey)
34 0 : : mKey(*aKey),
35 0 : mForceCompositing(false)
36 0 : { }
37 0 : nsSMILCompositor(const nsSMILCompositor& toCopy)
38 0 : : mKey(toCopy.mKey),
39 : mAnimationFunctions(toCopy.mAnimationFunctions),
40 0 : mForceCompositing(false)
41 0 : { }
42 0 : ~nsSMILCompositor() { }
43 :
44 : // PLDHashEntryHdr methods
45 0 : KeyTypeRef GetKey() const { return mKey; }
46 : bool KeyEquals(KeyTypePointer aKey) const;
47 0 : static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
48 : static PLDHashNumber HashKey(KeyTypePointer aKey);
49 : enum { ALLOW_MEMMOVE = false };
50 :
51 : // Adds the given animation function to this Compositor's list of functions
52 : void AddAnimationFunction(nsSMILAnimationFunction* aFunc);
53 :
54 : // Composes the attribute's current value with the list of animation
55 : // functions, and assigns the resulting value to this compositor's target
56 : // attribute. If a change is made that might produce style updates,
57 : // aMightHavePendingStyleUpdates is set to true. Otherwise it is not modified.
58 : void ComposeAttribute(bool& aMightHavePendingStyleUpdates);
59 :
60 : // Clears animation effects on my target attribute
61 : void ClearAnimationEffects();
62 :
63 : // Cycle-collection support
64 : void Traverse(nsCycleCollectionTraversalCallback* aCallback);
65 :
66 : // Toggles a bit that will force us to composite (bypassing early-return
67 : // optimizations) when we hit ComposeAttribute.
68 0 : void ToggleForceCompositing() { mForceCompositing = true; }
69 :
70 : // Transfers |aOther|'s mCachedBaseValue to |this|
71 0 : void StealCachedBaseValue(nsSMILCompositor* aOther) {
72 0 : mCachedBaseValue = mozilla::Move(aOther->mCachedBaseValue);
73 0 : }
74 :
75 : private:
76 : // Create a nsISMILAttr for my target, on the heap.
77 : //
78 : // @param aBaseStyleContext An optional style context which, if set, will be
79 : // used when fetching the base style.
80 : mozilla::UniquePtr<nsISMILAttr>
81 : CreateSMILAttr(nsStyleContext* aBaseStyleContext);
82 :
83 : // Returns the CSS property this compositor should animate, or
84 : // eCSSProperty_UNKNOWN if this compositor does not animate a CSS property.
85 : nsCSSPropertyID GetCSSPropertyToAnimate() const;
86 :
87 : // Returns true if we might need to refer to base styles (i.e. we are
88 : // targeting a CSS property and have one or more animation functions that
89 : // don't just replace the underlying value).
90 : //
91 : // This might return true in some cases where we don't actually need the base
92 : // style since it doesn't build up the animation sandwich to check if the
93 : // functions that appear to need the base style are actually replaced by
94 : // a function further up the stack.
95 : bool MightNeedBaseStyle() const;
96 :
97 : // Finds the index of the first function that will affect our animation
98 : // sandwich. Also toggles the 'mForceCompositing' flag if it finds that any
99 : // (used) functions have changed.
100 : uint32_t GetFirstFuncToAffectSandwich();
101 :
102 : // If the passed-in base value differs from our cached base value, this
103 : // method updates the cached value (and toggles the 'mForceCompositing' flag)
104 : void UpdateCachedBaseValue(const nsSMILValue& aBaseValue);
105 :
106 : // The hash key (tuple of element and attributeName)
107 : KeyType mKey;
108 :
109 : // Hash Value: List of animation functions that animate the specified attr
110 : nsTArray<nsSMILAnimationFunction*> mAnimationFunctions;
111 :
112 : // Member data for detecting when we need to force-recompose
113 : // ---------------------------------------------------------
114 : // Flag for tracking whether we need to compose. Initialized to false, but
115 : // gets flipped to true if we detect that something has changed.
116 : bool mForceCompositing;
117 :
118 : // Cached base value, so we can detect & force-recompose when it changes
119 : // from one sample to the next. (nsSMILAnimationController moves this
120 : // forward from the previous sample's compositor by calling
121 : // StealCachedBaseValue.)
122 : nsSMILValue mCachedBaseValue;
123 : };
124 :
125 : #endif // NS_SMILCOMPOSITOR_H_
|