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 #ifndef DOM_SMIL_SMILTARGETIDENTIFIER_H_
8 #define DOM_SMIL_SMILTARGETIDENTIFIER_H_
9 
10 // XXX Avoid including this here by moving function bodies to the cpp file
11 #include "nsAtom.h"
12 #include "nsIContent.h"
13 #include "mozilla/dom/Element.h"
14 
15 class nsIContent;
16 
17 namespace mozilla {
18 namespace dom {
19 class Element;
20 }
21 
22 /**
23  * Struct: SMILTargetIdentifier
24  *
25  * Tuple of: { Animated Element, Attribute Name }
26  *
27  * Used in SMILAnimationController as hash key for mapping an animation
28  * target to the SMILCompositor for that target.
29  *
30  * NOTE: Need a nsRefPtr for the element & attribute name, because
31  * SMILAnimationController retain its hash table for one sample into the
32  * future, and we need to make sure their target isn't deleted in that time.
33  */
34 
35 struct SMILTargetIdentifier {
SMILTargetIdentifierSMILTargetIdentifier36   SMILTargetIdentifier()
37       : mElement(nullptr),
38         mAttributeName(nullptr),
39         mAttributeNamespaceID(kNameSpaceID_Unknown) {}
40 
EqualsSMILTargetIdentifier41   inline bool Equals(const SMILTargetIdentifier& aOther) const {
42     return (aOther.mElement == mElement &&
43             aOther.mAttributeName == mAttributeName &&
44             aOther.mAttributeNamespaceID == mAttributeNamespaceID);
45   }
46 
47   RefPtr<mozilla::dom::Element> mElement;
48   RefPtr<nsAtom> mAttributeName;
49   int32_t mAttributeNamespaceID;
50 };
51 
52 /**
53  * Class: SMILWeakTargetIdentifier
54  *
55  * Version of the above struct that uses non-owning pointers.  These are kept
56  * private, to ensure that they aren't ever dereferenced (or used at all,
57  * outside of Equals()).
58  *
59  * This is solely for comparisons to determine if a target has changed
60  * from one sample to the next.
61  */
62 class SMILWeakTargetIdentifier {
63  public:
64   // Trivial constructor
SMILWeakTargetIdentifier()65   SMILWeakTargetIdentifier() : mElement(nullptr), mAttributeName(nullptr) {}
66 
67   // Allow us to update a weak identifier to match a given non-weak identifier
68   SMILWeakTargetIdentifier& operator=(const SMILTargetIdentifier& aOther) {
69     mElement = aOther.mElement;
70     mAttributeName = aOther.mAttributeName;
71     return *this;
72   }
73 
74   // Allow for comparison vs. non-weak identifier
Equals(const SMILTargetIdentifier & aOther)75   inline bool Equals(const SMILTargetIdentifier& aOther) const {
76     return (aOther.mElement == mElement &&
77             aOther.mAttributeName == mAttributeName);
78   }
79 
80  private:
81   const nsIContent* mElement;
82   const nsAtom* mAttributeName;
83 };
84 
85 }  // namespace mozilla
86 
87 #endif  // DOM_SMIL_SMILTARGETIDENTIFIER_H_
88