summaryrefslogtreecommitdiffstats
path: root/dom/smil/SMILAttr.h
blob: a67921a9adb62d37fd7afd515252a5ac3b995d47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DOM_SMIL_SMILATTR_H_
#define DOM_SMIL_SMILATTR_H_

#include "nscore.h"
#include "nsStringFwd.h"

class nsIContent;

namespace mozilla {

class SMILValue;

namespace dom {
class SVGAnimationElement;
}  // namespace dom

////////////////////////////////////////////////////////////////////////
// SMILAttr: A variable targeted by SMIL for animation and can therefore have
// an underlying (base) value and an animated value For example, an attribute of
// a particular SVG element.
//
// These objects only exist during the compositing phase of SMIL animation
// calculations. They have a single owner who is responsible for deleting the
// object.

class SMILAttr {
 public:
  /**
   * Creates a new SMILValue for this attribute from a string. The string is
   * parsed in the context of this attribute so that context-dependent values
   * such as em-based units can be resolved into a canonical form suitable for
   * animation (including interpolation etc.).
   *
   * @param aStr        A string defining the new value to be created.
   * @param aSrcElement The source animation element. This may be needed to
   *                    provided additional context data such as for
   *                    animateTransform where the 'type' attribute is needed to
   *                    parse the value.
   * @param[out] aValue Outparam for storing the parsed value.
   * @param[out] aPreventCachingOfSandwich
   *                    Outparam to indicate whether the attribute contains
   *                    dependencies on its context that should prevent the
   *                    result of the animation sandwich from being cached and
   *                    reused in future samples.
   * @return NS_OK on success or an error code if creation failed.
   */
  virtual nsresult ValueFromString(
      const nsAString& aStr,
      const mozilla::dom::SVGAnimationElement* aSrcElement, SMILValue& aValue,
      bool& aPreventCachingOfSandwich) const = 0;

  /**
   * Gets the underlying value of this attribute.
   *
   * @return a SMILValue object. returned_object.IsNull() will be true if an
   * error occurred.
   */
  virtual SMILValue GetBaseValue() const = 0;

  /**
   * Clears the animated value of this attribute.
   *
   * NOTE: The animation target is not guaranteed to be in a document when this
   * method is called. (See bug 523188)
   */
  virtual void ClearAnimValue() = 0;

  /**
   * Sets the presentation value of this attribute.
   *
   * @param aValue  The value to set.
   * @return NS_OK on success or an error code if setting failed.
   */
  virtual nsresult SetAnimValue(const SMILValue& aValue) = 0;

  /**
   * Returns the targeted content node, for any SMILAttr implementations
   * that want to expose that to the animation logic.  Otherwise, returns
   * null.
   *
   * @return the targeted content node, if this SMILAttr implementation
   * wishes to make it avaiable.  Otherwise, nullptr.
   */
  virtual const nsIContent* GetTargetNode() const { return nullptr; }

  /**
   * Virtual destructor, to make sure subclasses can clean themselves up.
   */
  virtual ~SMILAttr() = default;
};

}  // namespace mozilla

#endif  // DOM_SMIL_SMILATTR_H_