1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILTargetIdentifier.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NS_SMILTARGETIDENTIFIER_H_ 1.10 +#define NS_SMILTARGETIDENTIFIER_H_ 1.11 + 1.12 +#include "mozilla/dom/Element.h" 1.13 +#include "nsAutoPtr.h" 1.14 + 1.15 +/** 1.16 + * Struct: nsSMILTargetIdentifier 1.17 + * 1.18 + * Tuple of: { Animated Element, Attribute Name, Attribute Type (CSS vs. XML) } 1.19 + * 1.20 + * Used in nsSMILAnimationController as hash key for mapping an animation 1.21 + * target to the nsSMILCompositor for that target. 1.22 + * 1.23 + * NOTE: Need a nsRefPtr for the element & attribute name, because 1.24 + * nsSMILAnimationController retain its hash table for one sample into the 1.25 + * future, and we need to make sure their target isn't deleted in that time. 1.26 + */ 1.27 + 1.28 +struct nsSMILTargetIdentifier 1.29 +{ 1.30 + nsSMILTargetIdentifier() 1.31 + : mElement(nullptr), mAttributeName(nullptr), 1.32 + mAttributeNamespaceID(kNameSpaceID_Unknown), mIsCSS(false) {} 1.33 + 1.34 + inline bool Equals(const nsSMILTargetIdentifier& aOther) const 1.35 + { 1.36 + return (aOther.mElement == mElement && 1.37 + aOther.mAttributeName == mAttributeName && 1.38 + aOther.mAttributeNamespaceID == mAttributeNamespaceID && 1.39 + aOther.mIsCSS == mIsCSS); 1.40 + } 1.41 + 1.42 + nsRefPtr<mozilla::dom::Element> mElement; 1.43 + nsRefPtr<nsIAtom> mAttributeName; 1.44 + int32_t mAttributeNamespaceID; 1.45 + bool mIsCSS; 1.46 +}; 1.47 + 1.48 +/** 1.49 + * Class: nsSMILWeakTargetIdentifier 1.50 + * 1.51 + * Version of the above struct that uses non-owning pointers. These are kept 1.52 + * private, to ensure that they aren't ever dereferenced (or used at all, 1.53 + * outside of Equals()). 1.54 + * 1.55 + * This is solely for comparisons to determine if a target has changed 1.56 + * from one sample to the next. 1.57 + */ 1.58 +class nsSMILWeakTargetIdentifier 1.59 +{ 1.60 +public: 1.61 + // Trivial constructor 1.62 + nsSMILWeakTargetIdentifier() 1.63 + : mElement(nullptr), mAttributeName(nullptr), mIsCSS(false) {} 1.64 + 1.65 + // Allow us to update a weak identifier to match a given non-weak identifier 1.66 + nsSMILWeakTargetIdentifier& 1.67 + operator=(const nsSMILTargetIdentifier& aOther) 1.68 + { 1.69 + mElement = aOther.mElement; 1.70 + mAttributeName = aOther.mAttributeName; 1.71 + mIsCSS = aOther.mIsCSS; 1.72 + return *this; 1.73 + } 1.74 + 1.75 + // Allow for comparison vs. non-weak identifier 1.76 + inline bool Equals(const nsSMILTargetIdentifier& aOther) const 1.77 + { 1.78 + return (aOther.mElement == mElement && 1.79 + aOther.mAttributeName == mAttributeName && 1.80 + aOther.mIsCSS == mIsCSS); 1.81 + } 1.82 + 1.83 +private: 1.84 + const nsIContent* mElement; 1.85 + const nsIAtom* mAttributeName; 1.86 + bool mIsCSS; 1.87 +}; 1.88 + 1.89 +#endif // NS_SMILTARGETIDENTIFIER_H_