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 #include "SMILSetAnimationFunction.h"
8 
9 namespace mozilla {
10 
IsDisallowedAttribute(const nsAtom * aAttribute) const11 inline bool SMILSetAnimationFunction::IsDisallowedAttribute(
12     const nsAtom* aAttribute) const {
13   //
14   // A <set> element is similar to <animate> but lacks:
15   //   AnimationValue.attrib(calcMode, values, keyTimes, keySplines, from, to,
16   //                         by) -- BUT has 'to'
17   //   AnimationAddition.attrib(additive, accumulate)
18   //
19   return aAttribute == nsGkAtoms::calcMode || aAttribute == nsGkAtoms::values ||
20          aAttribute == nsGkAtoms::keyTimes ||
21          aAttribute == nsGkAtoms::keySplines || aAttribute == nsGkAtoms::from ||
22          aAttribute == nsGkAtoms::by || aAttribute == nsGkAtoms::additive ||
23          aAttribute == nsGkAtoms::accumulate;
24 }
25 
SetAttr(nsAtom * aAttribute,const nsAString & aValue,nsAttrValue & aResult,nsresult * aParseResult)26 bool SMILSetAnimationFunction::SetAttr(nsAtom* aAttribute,
27                                        const nsAString& aValue,
28                                        nsAttrValue& aResult,
29                                        nsresult* aParseResult) {
30   if (IsDisallowedAttribute(aAttribute)) {
31     aResult.SetTo(aValue);
32     if (aParseResult) {
33       // SMILANIM 4.2 says:
34       //
35       //   The additive and accumulate attributes are not allowed, and will be
36       //   ignored if specified.
37       //
38       // So at least for those two attributes we shouldn't report an error even
39       // if they're present. For now we'll also just silently ignore other
40       // attribute types too.
41       *aParseResult = NS_OK;
42     }
43     return true;
44   }
45 
46   return SMILAnimationFunction::SetAttr(aAttribute, aValue, aResult,
47                                         aParseResult);
48 }
49 
UnsetAttr(nsAtom * aAttribute)50 bool SMILSetAnimationFunction::UnsetAttr(nsAtom* aAttribute) {
51   if (IsDisallowedAttribute(aAttribute)) {
52     return true;
53   }
54 
55   return SMILAnimationFunction::UnsetAttr(aAttribute);
56 }
57 
HasAttr(nsAtom * aAttName) const58 bool SMILSetAnimationFunction::HasAttr(nsAtom* aAttName) const {
59   if (IsDisallowedAttribute(aAttName)) return false;
60 
61   return SMILAnimationFunction::HasAttr(aAttName);
62 }
63 
GetAttr(nsAtom * aAttName) const64 const nsAttrValue* SMILSetAnimationFunction::GetAttr(nsAtom* aAttName) const {
65   if (IsDisallowedAttribute(aAttName)) return nullptr;
66 
67   return SMILAnimationFunction::GetAttr(aAttName);
68 }
69 
GetAttr(nsAtom * aAttName,nsAString & aResult) const70 bool SMILSetAnimationFunction::GetAttr(nsAtom* aAttName,
71                                        nsAString& aResult) const {
72   if (IsDisallowedAttribute(aAttName)) return false;
73 
74   return SMILAnimationFunction::GetAttr(aAttName, aResult);
75 }
76 
WillReplace() const77 bool SMILSetAnimationFunction::WillReplace() const { return true; }
78 
79 }  // namespace mozilla
80