Bug 1315874 - Pass a base style context to nsSMILCSSProperty; r=heycam

We will use this in the next patch in this series to fetch the base style.

(I tried simply passing this as a parameter to GetBaseStyle but it proved to be
more complicated since all the overrides of GetBaseStyle would need to be
updated to take a parameter that would be irrelevant to most of them.)

MozReview-Commit-ID: Fdr4rFUlE9V

--HG--
extra : rebase_source : 26978951302b4764938959a065402f05220b6093
This commit is contained in:
Brian Birtles 2017-04-03 16:49:10 +09:00
Родитель 19ef9bec3d
Коммит c94eac8983
4 изменённых файлов: 40 добавлений и 8 удалений

Просмотреть файл

@ -53,8 +53,11 @@ GetCSSComputedValue(Element* aElem,
// Class Methods
nsSMILCSSProperty::nsSMILCSSProperty(nsCSSPropertyID aPropID,
Element* aElement)
: mPropID(aPropID), mElement(aElement)
Element* aElement,
nsStyleContext* aBaseStyleContext)
: mPropID(aPropID)
, mElement(aElement)
, mBaseStyleContext(aBaseStyleContext)
{
MOZ_ASSERT(IsPropertyAnimatable(mPropID),
"Creating a nsSMILCSSProperty for a property "

Просмотреть файл

@ -15,6 +15,8 @@
#include "nsCSSPropertyID.h"
#include "nsCSSValue.h"
class nsStyleContext;
namespace mozilla {
namespace dom {
class Element;
@ -33,8 +35,14 @@ public:
* Constructs a new nsSMILCSSProperty.
* @param aPropID The CSS property we're interested in animating.
* @param aElement The element whose CSS property is being animated.
* @param aBaseStyleContext The style context to use when getting the base
* value. If this is nullptr and GetBaseValue is
* called, an empty nsSMILValue initialized with
* the nsSMILCSSValueType will be returned.
*/
nsSMILCSSProperty(nsCSSPropertyID aPropID, mozilla::dom::Element* aElement);
nsSMILCSSProperty(nsCSSPropertyID aPropID,
mozilla::dom::Element* aElement,
nsStyleContext* aBaseStyleContext);
// nsISMILAttr methods
virtual nsresult ValueFromString(const nsAString& aStr,
@ -62,6 +70,12 @@ protected:
// as the Compositing step, and DOM elements don't get a chance to die during
// that time.
mozilla::dom::Element* mElement;
// The style context to use when fetching base styles.
// As with mElement, since an nsISMILAttr only lives as long as the
// compositing step and since ComposeAttribute holds an owning reference to
// the base style context, we can use a non-owning reference here.
nsStyleContext* mBaseStyleContext;
};
#endif // NS_SMILCSSPROPERTY_H_

Просмотреть файл

@ -6,6 +6,7 @@
#include "nsSMILCompositor.h"
#include "nsComputedDOMStyle.h"
#include "nsCSSProps.h"
#include "nsHashKeys.h"
#include "nsSMILCSSProperty.h"
@ -54,9 +55,18 @@ nsSMILCompositor::ComposeAttribute(bool& aMightHavePendingStyleUpdates)
if (!mKey.mElement)
return;
// If we might need to resolve base styles, grab a suitable style context
// for initializing our nsISMILAttr with.
RefPtr<nsStyleContext> baseStyleContext;
if (MightNeedBaseStyle()) {
baseStyleContext =
nsComputedDOMStyle::GetUnanimatedStyleContextNoFlush(mKey.mElement,
nullptr, nullptr);
}
// FIRST: Get the nsISMILAttr (to grab base value from, and to eventually
// give animated value to)
UniquePtr<nsISMILAttr> smilAttr = CreateSMILAttr();
UniquePtr<nsISMILAttr> smilAttr = CreateSMILAttr(baseStyleContext);
if (!smilAttr) {
// Target attribute not found (or, out of memory)
return;
@ -115,7 +125,7 @@ nsSMILCompositor::ClearAnimationEffects()
if (!mKey.mElement || !mKey.mAttributeName)
return;
UniquePtr<nsISMILAttr> smilAttr = CreateSMILAttr();
UniquePtr<nsISMILAttr> smilAttr = CreateSMILAttr(nullptr);
if (!smilAttr) {
// Target attribute not found (or, out of memory)
return;
@ -126,12 +136,13 @@ nsSMILCompositor::ClearAnimationEffects()
// Protected Helper Functions
// --------------------------
UniquePtr<nsISMILAttr>
nsSMILCompositor::CreateSMILAttr()
nsSMILCompositor::CreateSMILAttr(nsStyleContext* aBaseStyleContext)
{
nsCSSPropertyID propID = GetCSSPropertyToAnimate();
if (propID != eCSSProperty_UNKNOWN) {
return MakeUnique<nsSMILCSSProperty>(propID, mKey.mElement.get());
return MakeUnique<nsSMILCSSProperty>(propID, mKey.mElement.get(),
aBaseStyleContext);
}
return mKey.mElement->GetAnimatedAttr(mKey.mAttributeNamespaceID,

Просмотреть файл

@ -74,7 +74,11 @@ public:
private:
// Create a nsISMILAttr for my target, on the heap.
mozilla::UniquePtr<nsISMILAttr> CreateSMILAttr();
//
// @param aBaseStyleContext An optional style context which, if set, will be
// used when fetching the base style.
mozilla::UniquePtr<nsISMILAttr>
CreateSMILAttr(nsStyleContext* aBaseStyleContext);
// Returns the CSS property this compositor should animate, or
// eCSSProperty_UNKNOWN if this compositor does not animate a CSS property.