Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / layout / style / nsCSSPseudoElements.cpp
blob42e3d463d49a89e0ea49ee17f7d16a3c4bcec65a
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_) \
42 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));
58 /* static */ bool
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) ||
71 result ==
72 PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2),
73 "result doesn't match flags");
74 return result;
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) {
82 return Type(i);
86 if (nsCSSAnonBoxes::IsAnonBox(aAtom)) {
87 #ifdef MOZ_XUL
88 if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) {
89 return ePseudo_XULTree;
91 #endif
93 return ePseudo_AnonBox;
96 return ePseudo_NotPseudoElement;
99 /* static */ nsIAtom*
100 nsCSSPseudoElements::GetPseudoAtom(Type aType)
102 NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
103 "Unexpected type");
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];
116 /* static */ bool
117 nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType)
119 return PseudoElementHasFlags(aType,
120 CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE);