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/. */
7 #ifndef mozilla_AnimatedPropertyID_h
8 #define mozilla_AnimatedPropertyID_h
10 #include "nsCSSPropertyID.h"
11 #include "nsCSSProps.h"
13 #include "mozilla/HashFunctions.h"
14 #include "mozilla/ServoBindings.h"
18 struct AnimatedPropertyID
{
19 explicit AnimatedPropertyID(nsCSSPropertyID aProperty
) : mID(aProperty
) {
20 MOZ_ASSERT(aProperty
!= eCSSPropertyExtra_variable
,
21 "Cannot create an AnimatedPropertyID from only a "
22 "eCSSPropertyExtra_variable.");
25 explicit AnimatedPropertyID(RefPtr
<nsAtom
> aCustomName
)
26 : mID(eCSSPropertyExtra_variable
), mCustomName(std::move(aCustomName
)) {
27 MOZ_ASSERT(mCustomName
, "Null custom property name");
30 nsCSSPropertyID mID
= eCSSProperty_UNKNOWN
;
31 RefPtr
<nsAtom
> mCustomName
;
33 bool IsCustom() const { return mID
== eCSSPropertyExtra_variable
; }
34 bool operator==(const AnimatedPropertyID
& aOther
) const {
35 return mID
== aOther
.mID
&& mCustomName
== aOther
.mCustomName
;
37 bool operator!=(const AnimatedPropertyID
& aOther
) const {
38 return !(*this == aOther
);
41 bool IsValid() const {
42 if (mID
== eCSSProperty_UNKNOWN
) {
45 return IsCustom() == !!mCustomName
;
48 void ToString(nsACString
& aString
) const {
50 MOZ_ASSERT(mCustomName
, "Custom property should have a name");
51 // mCustomName does not include the "--" prefix
52 aString
.AssignLiteral("--");
53 AppendUTF16toUTF8(nsDependentAtomString(mCustomName
), aString
);
55 aString
.Assign(nsCSSProps::GetStringValue(mID
));
59 void ToString(nsAString
& aString
) const {
61 MOZ_ASSERT(mCustomName
, "Custom property should have a name");
62 // mCustomName does not include the "--" prefix
63 aString
.AssignLiteral("--");
64 aString
.Append(nsDependentAtomString(mCustomName
));
66 aString
.Assign(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(mID
)));
70 HashNumber
Hash() const {
71 HashNumber hash
= mCustomName
? mCustomName
->hash() : 0;
72 return AddToHash(hash
, mID
);
75 AnimatedPropertyID
ToPhysical(const ComputedStyle
& aStyle
) const {
79 return AnimatedPropertyID
{nsCSSProps::Physicalize(mID
, aStyle
)};
83 // MOZ_DBG support for AnimatedPropertyId
84 inline std::ostream
& operator<<(std::ostream
& aOut
,
85 const AnimatedPropertyID
& aProperty
) {
86 if (aProperty
.IsCustom()) {
87 return aOut
<< nsAtomCString(aProperty
.mCustomName
);
89 return aOut
<< nsCSSProps::GetStringValue(aProperty
.mID
);
92 } // namespace mozilla
94 #endif // mozilla_AnimatedPropertyID_h