|
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/. */ |
|
5 |
|
6 /* atom list for CSS pseudo-elements */ |
|
7 |
|
8 #include "mozilla/ArrayUtils.h" |
|
9 |
|
10 #include "nsCSSPseudoElements.h" |
|
11 #include "nsAtomListUtils.h" |
|
12 #include "nsStaticAtom.h" |
|
13 #include "nsCSSAnonBoxes.h" |
|
14 |
|
15 using namespace mozilla; |
|
16 |
|
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 |
|
22 |
|
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 |
|
27 |
|
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 |
|
33 }; |
|
34 |
|
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_) \ |
|
42 flags_, |
|
43 #include "nsCSSPseudoElementList.h" |
|
44 #undef CSS_PSEUDO_ELEMENT |
|
45 }; |
|
46 |
|
47 void nsCSSPseudoElements::AddRefAtoms() |
|
48 { |
|
49 NS_RegisterStaticAtoms(CSSPseudoElements_info); |
|
50 } |
|
51 |
|
52 bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) |
|
53 { |
|
54 return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info, |
|
55 ArrayLength(CSSPseudoElements_info)); |
|
56 } |
|
57 |
|
58 /* static */ bool |
|
59 nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom) |
|
60 { |
|
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) || |
|
71 result == |
|
72 PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2), |
|
73 "result doesn't match flags"); |
|
74 return result; |
|
75 } |
|
76 |
|
77 /* static */ nsCSSPseudoElements::Type |
|
78 nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom) |
|
79 { |
|
80 for (uint32_t i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) { |
|
81 if (*CSSPseudoElements_info[i].mAtom == aAtom) { |
|
82 return Type(i); |
|
83 } |
|
84 } |
|
85 |
|
86 if (nsCSSAnonBoxes::IsAnonBox(aAtom)) { |
|
87 #ifdef MOZ_XUL |
|
88 if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) { |
|
89 return ePseudo_XULTree; |
|
90 } |
|
91 #endif |
|
92 |
|
93 return ePseudo_AnonBox; |
|
94 } |
|
95 |
|
96 return ePseudo_NotPseudoElement; |
|
97 } |
|
98 |
|
99 /* static */ nsIAtom* |
|
100 nsCSSPseudoElements::GetPseudoAtom(Type aType) |
|
101 { |
|
102 NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount, |
|
103 "Unexpected type"); |
|
104 return *CSSPseudoElements_info[aType].mAtom; |
|
105 } |
|
106 |
|
107 /* static */ uint32_t |
|
108 nsCSSPseudoElements::FlagsForPseudoElement(const Type aType) |
|
109 { |
|
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]; |
|
114 } |
|
115 |
|
116 /* static */ bool |
|
117 nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType) |
|
118 { |
|
119 return PseudoElementHasFlags(aType, |
|
120 CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE); |
|
121 } |