1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* atom list for CSS pseudo-elements */
8 #include "mozilla/ArrayUtils.h"
10 #include "nsCSSPseudoElements.h"
11 #include "nsAtomListUtils.h"
12 #include "nsStaticAtom.h"
13 #include "nsCSSAnonBoxes.h"
15 using namespace mozilla
;
17 // define storage for all atoms
18 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
19 nsICSSPseudoElement* nsCSSPseudoElements::name_;
20 #include "nsCSSPseudoElementList.h"
21 #undef CSS_PSEUDO_ELEMENT
23 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
24 NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_)
25 #include "nsCSSPseudoElementList.h"
26 #undef CSS_PSEUDO_ELEMENT
28 static const nsStaticAtom CSSPseudoElements_info
[] = {
29 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
30 NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_),
31 #include "nsCSSPseudoElementList.h"
32 #undef CSS_PSEUDO_ELEMENT
35 // Separate from the array above so that we can have an array of
36 // nsStaticAtom (to pass to NS_RegisterStaticAtoms and
37 // nsAtomListUtils::IsMember), but with corresponding indices (so the
38 // i-th element of this array is the flags for the i-th pseudo-element
39 // in the previous array).
40 static const uint32_t CSSPseudoElements_flags
[] = {
41 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
43 #include "nsCSSPseudoElementList.h"
44 #undef CSS_PSEUDO_ELEMENT
47 void nsCSSPseudoElements::AddRefAtoms()
49 NS_RegisterStaticAtoms(CSSPseudoElements_info
);
52 bool nsCSSPseudoElements::IsPseudoElement(nsIAtom
*aAtom
)
54 return nsAtomListUtils::IsMember(aAtom
, CSSPseudoElements_info
,
55 ArrayLength(CSSPseudoElements_info
));
59 nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom
*aAtom
)
61 // We don't implement this using PseudoElementHasFlags because callers
62 // want to pass things that could be anon boxes.
63 NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom
) ||
64 nsCSSAnonBoxes::IsAnonBox(aAtom
),
65 "must be pseudo element or anon box");
66 bool result
= aAtom
== nsCSSPseudoElements::after
||
67 aAtom
== nsCSSPseudoElements::before
||
68 aAtom
== nsCSSPseudoElements::firstLetter
||
69 aAtom
== nsCSSPseudoElements::firstLine
;
70 NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom
) ||
72 PseudoElementHasFlags(GetPseudoType(aAtom
), CSS_PSEUDO_ELEMENT_IS_CSS2
),
73 "result doesn't match flags");
77 /* static */ nsCSSPseudoElements::Type
78 nsCSSPseudoElements::GetPseudoType(nsIAtom
*aAtom
)
80 for (uint32_t i
= 0; i
< ArrayLength(CSSPseudoElements_info
); ++i
) {
81 if (*CSSPseudoElements_info
[i
].mAtom
== aAtom
) {
86 if (nsCSSAnonBoxes::IsAnonBox(aAtom
)) {
88 if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom
)) {
89 return ePseudo_XULTree
;
93 return ePseudo_AnonBox
;
96 return ePseudo_NotPseudoElement
;
100 nsCSSPseudoElements::GetPseudoAtom(Type aType
)
102 NS_ASSERTION(aType
< nsCSSPseudoElements::ePseudo_PseudoElementCount
,
104 return *CSSPseudoElements_info
[aType
].mAtom
;
107 /* static */ uint32_t
108 nsCSSPseudoElements::FlagsForPseudoElement(const Type aType
)
110 size_t index
= static_cast<size_t>(aType
);
111 NS_ASSERTION(index
< ArrayLength(CSSPseudoElements_flags
),
112 "argument must be a pseudo-element");
113 return CSSPseudoElements_flags
[index
];
117 nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType
)
119 return PseudoElementHasFlags(aType
,
120 CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE
);