michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* atom list for CSS pseudo-elements */ michael@0: michael@0: #include "mozilla/ArrayUtils.h" michael@0: michael@0: #include "nsCSSPseudoElements.h" michael@0: #include "nsAtomListUtils.h" michael@0: #include "nsStaticAtom.h" michael@0: #include "nsCSSAnonBoxes.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: // define storage for all atoms michael@0: #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ michael@0: nsICSSPseudoElement* nsCSSPseudoElements::name_; michael@0: #include "nsCSSPseudoElementList.h" michael@0: #undef CSS_PSEUDO_ELEMENT michael@0: michael@0: #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ michael@0: NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_) michael@0: #include "nsCSSPseudoElementList.h" michael@0: #undef CSS_PSEUDO_ELEMENT michael@0: michael@0: static const nsStaticAtom CSSPseudoElements_info[] = { michael@0: #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ michael@0: NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_), michael@0: #include "nsCSSPseudoElementList.h" michael@0: #undef CSS_PSEUDO_ELEMENT michael@0: }; michael@0: michael@0: // Separate from the array above so that we can have an array of michael@0: // nsStaticAtom (to pass to NS_RegisterStaticAtoms and michael@0: // nsAtomListUtils::IsMember), but with corresponding indices (so the michael@0: // i-th element of this array is the flags for the i-th pseudo-element michael@0: // in the previous array). michael@0: static const uint32_t CSSPseudoElements_flags[] = { michael@0: #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ michael@0: flags_, michael@0: #include "nsCSSPseudoElementList.h" michael@0: #undef CSS_PSEUDO_ELEMENT michael@0: }; michael@0: michael@0: void nsCSSPseudoElements::AddRefAtoms() michael@0: { michael@0: NS_RegisterStaticAtoms(CSSPseudoElements_info); michael@0: } michael@0: michael@0: bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom) michael@0: { michael@0: return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info, michael@0: ArrayLength(CSSPseudoElements_info)); michael@0: } michael@0: michael@0: /* static */ bool michael@0: nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom) michael@0: { michael@0: // We don't implement this using PseudoElementHasFlags because callers michael@0: // want to pass things that could be anon boxes. michael@0: NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) || michael@0: nsCSSAnonBoxes::IsAnonBox(aAtom), michael@0: "must be pseudo element or anon box"); michael@0: bool result = aAtom == nsCSSPseudoElements::after || michael@0: aAtom == nsCSSPseudoElements::before || michael@0: aAtom == nsCSSPseudoElements::firstLetter || michael@0: aAtom == nsCSSPseudoElements::firstLine; michael@0: NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) || michael@0: result == michael@0: PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2), michael@0: "result doesn't match flags"); michael@0: return result; michael@0: } michael@0: michael@0: /* static */ nsCSSPseudoElements::Type michael@0: nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom) michael@0: { michael@0: for (uint32_t i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) { michael@0: if (*CSSPseudoElements_info[i].mAtom == aAtom) { michael@0: return Type(i); michael@0: } michael@0: } michael@0: michael@0: if (nsCSSAnonBoxes::IsAnonBox(aAtom)) { michael@0: #ifdef MOZ_XUL michael@0: if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) { michael@0: return ePseudo_XULTree; michael@0: } michael@0: #endif michael@0: michael@0: return ePseudo_AnonBox; michael@0: } michael@0: michael@0: return ePseudo_NotPseudoElement; michael@0: } michael@0: michael@0: /* static */ nsIAtom* michael@0: nsCSSPseudoElements::GetPseudoAtom(Type aType) michael@0: { michael@0: NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount, michael@0: "Unexpected type"); michael@0: return *CSSPseudoElements_info[aType].mAtom; michael@0: } michael@0: michael@0: /* static */ uint32_t michael@0: nsCSSPseudoElements::FlagsForPseudoElement(const Type aType) michael@0: { michael@0: size_t index = static_cast(aType); michael@0: NS_ASSERTION(index < ArrayLength(CSSPseudoElements_flags), michael@0: "argument must be a pseudo-element"); michael@0: return CSSPseudoElements_flags[index]; michael@0: } michael@0: michael@0: /* static */ bool michael@0: nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType) michael@0: { michael@0: return PseudoElementHasFlags(aType, michael@0: CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE); michael@0: }