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 /* DOM object for element.style */
8 
9 #ifndef nsDOMCSSAttributeDeclaration_h
10 #define nsDOMCSSAttributeDeclaration_h
11 
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/DocGroup.h"
14 #include "mozilla/ServoTypes.h"
15 #include "nsDOMCSSDeclaration.h"
16 
17 struct RawServoUnlockedDeclarationBlock;
18 
19 namespace mozilla {
20 
21 class SMILValue;
22 class SVGAnimatedLength;
23 class SVGAnimatedPathSegList;
24 
25 namespace dom {
26 class DomGroup;
27 class Element;
28 }  // namespace dom
29 }  // namespace mozilla
30 
31 class nsDOMCSSAttributeDeclaration final : public nsDOMCSSDeclaration {
32  public:
33   typedef mozilla::dom::Element Element;
34   typedef mozilla::SMILValue SMILValue;
35   typedef mozilla::SVGAnimatedLength SVGAnimatedLength;
36   nsDOMCSSAttributeDeclaration(Element* aContent, bool aIsSMILOverride);
37 
38   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
39   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
40       nsDOMCSSAttributeDeclaration, nsICSSDeclaration)
41 
42   mozilla::DeclarationBlock* GetOrCreateCSSDeclaration(
43       Operation aOperation, mozilla::DeclarationBlock** aCreated) final;
44 
45   nsDOMCSSDeclaration::ParsingEnvironment GetParsingEnvironment(
46       nsIPrincipal* aSubjectPrincipal) const final;
47 
GetParentRule()48   mozilla::css::Rule* GetParentRule() override { return nullptr; }
49 
GetAssociatedNode()50   nsINode* GetAssociatedNode() const override { return mElement; }
GetParentObject()51   nsINode* GetParentObject() const override { return mElement; }
52 
53   nsresult SetSMILValue(const nsCSSPropertyID aPropID, const SMILValue& aValue);
54   nsresult SetSMILValue(const nsCSSPropertyID aPropID,
55                         const SVGAnimatedLength& aLength);
56   nsresult SetSMILValue(const nsCSSPropertyID,
57                         const mozilla::SVGAnimatedPathSegList& aPath);
58 
59   void SetPropertyValue(const nsCSSPropertyID aPropID, const nsACString& aValue,
60                         nsIPrincipal* aSubjectPrincipal,
61                         mozilla::ErrorResult& aRv) override;
62 
63   static void MutationClosureFunction(void* aData);
64 
GetPropertyChangeClosure(mozilla::DeclarationBlockMutationClosure * aClosure,mozilla::MutationClosureData * aClosureData)65   void GetPropertyChangeClosure(
66       mozilla::DeclarationBlockMutationClosure* aClosure,
67       mozilla::MutationClosureData* aClosureData) final {
68     if (!mIsSMILOverride) {
69       aClosure->function = MutationClosureFunction;
70       aClosure->data = aClosureData;
71       aClosureData->mShouldBeCalled = true;
72       aClosureData->mElement = mElement;
73     }
74   }
75 
76  protected:
77   ~nsDOMCSSAttributeDeclaration();
78 
79   nsresult SetCSSDeclaration(
80       mozilla::DeclarationBlock* aDecl,
81       mozilla::MutationClosureData* aClosureData) override;
82   mozilla::dom::Document* DocToUpdate() override;
83 
84   RefPtr<Element> mElement;
85 
86   /* If true, this indicates that this nsDOMCSSAttributeDeclaration
87    * should interact with mContent's SMIL override style rule (rather
88    * than the inline style rule).
89    */
90   const bool mIsSMILOverride;
91 
92  private:
93   template <typename SetterFunc>
94   nsresult SetSMILValueHelper(SetterFunc aFunc);
95 };
96 
97 #endif /* nsDOMCSSAttributeDeclaration_h */
98