SMILCSSProperty.h (3021B)
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 /* representation of a SMIL-animatable CSS property on an element */ 8 9 #ifndef DOM_SMIL_SMILCSSPROPERTY_H_ 10 #define DOM_SMIL_SMILCSSPROPERTY_H_ 11 12 #include "NonCustomCSSPropertyId.h" 13 #include "mozilla/SMILAttr.h" 14 #include "nsAtom.h" 15 #include "nsCSSValue.h" 16 17 namespace mozilla { 18 class ComputedStyle; 19 namespace dom { 20 class Element; 21 } // namespace dom 22 23 /** 24 * SMILCSSProperty: Implements the SMILAttr interface for SMIL animations 25 * that target CSS properties. Represents a particular animation-targeted CSS 26 * property on a particular element. 27 */ 28 class SMILCSSProperty : public SMILAttr { 29 public: 30 /** 31 * Constructs a new SMILCSSProperty. 32 * @param aPropId The CSS property we're interested in animating. 33 * @param aElement The element whose CSS property is being animated. 34 * @param aBaseComputedStyle The ComputedStyle to use when getting the base 35 * value. If this is nullptr and GetBaseValue is 36 * called, an empty SMILValue initialized with 37 * the SMILCSSValueType will be returned. 38 */ 39 SMILCSSProperty(NonCustomCSSPropertyId aPropId, dom::Element* aElement, 40 const ComputedStyle* aBaseComputedStyle); 41 42 // SMILAttr methods 43 nsresult ValueFromString(const nsAString& aStr, 44 const dom::SVGAnimationElement* aSrcElement, 45 SMILValue& aValue, 46 bool& aPreventCachingOfSandwich) const override; 47 SMILValue GetBaseValue() const override; 48 nsresult SetAnimValue(const SMILValue& aValue) override; 49 void ClearAnimValue() override; 50 51 /** 52 * Utility method - returns true if the given property is supported for 53 * SMIL animation. 54 * 55 * @param aProperty The property to check for animation support. 56 * @return true if the given property is supported for SMIL animation, or 57 * false otherwise 58 */ 59 static bool IsPropertyAnimatable(NonCustomCSSPropertyId aPropId); 60 61 protected: 62 NonCustomCSSPropertyId mPropId; 63 // Using non-refcounted pointer for mElement -- we know mElement will stay 64 // alive for my lifetime because a SMILAttr (like me) only lives as long 65 // as the Compositing step, and DOM elements don't get a chance to die during 66 // that time. 67 dom::Element* mElement; 68 69 // The style to use when fetching base styles. 70 // 71 // As with mElement, since a SMILAttr only lives as long as the 72 // compositing step and since ComposeAttribute holds an owning reference to 73 // the base ComputedStyle, we can use a non-owning reference here. 74 const ComputedStyle* mBaseComputedStyle; 75 }; 76 77 } // namespace mozilla 78 79 #endif // DOM_SMIL_SMILCSSPROPERTY_H_