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-classes */ michael@0: michael@0: #include "mozilla/ArrayUtils.h" michael@0: michael@0: #include "nsCSSPseudoClasses.h" michael@0: #include "nsStaticAtom.h" michael@0: #include "mozilla/Preferences.h" michael@0: #include "nsString.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: // define storage for all atoms michael@0: #define CSS_PSEUDO_CLASS(_name, _value, _pref) \ michael@0: static nsIAtom* sPseudoClass_##_name; michael@0: #include "nsCSSPseudoClassList.h" michael@0: #undef CSS_PSEUDO_CLASS michael@0: michael@0: #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ michael@0: NS_STATIC_ATOM_BUFFER(name_##_pseudo_class_buffer, value_) michael@0: #include "nsCSSPseudoClassList.h" michael@0: #undef CSS_PSEUDO_CLASS michael@0: michael@0: static const nsStaticAtom CSSPseudoClasses_info[] = { michael@0: #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ michael@0: NS_STATIC_ATOM(name_##_pseudo_class_buffer, &sPseudoClass_##name_), michael@0: #include "nsCSSPseudoClassList.h" michael@0: #undef CSS_PSEUDO_CLASS michael@0: }; michael@0: michael@0: static bool sPseudoClassEnabled[] = { michael@0: #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ michael@0: true, michael@0: #include "nsCSSPseudoClassList.h" michael@0: #undef CSS_PSEUDO_CLASS michael@0: }; michael@0: michael@0: void nsCSSPseudoClasses::AddRefAtoms() michael@0: { michael@0: NS_RegisterStaticAtoms(CSSPseudoClasses_info); michael@0: michael@0: #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ michael@0: if (pref_[0]) { \ michael@0: Preferences::AddBoolVarCache(&sPseudoClassEnabled[ePseudoClass_##name_], \ michael@0: pref_); \ michael@0: } michael@0: #include "nsCSSPseudoClassList.h" michael@0: #undef CSS_PSEUDO_CLASS michael@0: } michael@0: michael@0: bool michael@0: nsCSSPseudoClasses::HasStringArg(Type aType) michael@0: { michael@0: return aType == ePseudoClass_lang || michael@0: aType == ePseudoClass_mozEmptyExceptChildrenWithLocalname || michael@0: aType == ePseudoClass_mozSystemMetric || michael@0: aType == ePseudoClass_mozLocaleDir || michael@0: aType == ePseudoClass_dir; michael@0: } michael@0: michael@0: bool michael@0: nsCSSPseudoClasses::HasNthPairArg(Type aType) michael@0: { michael@0: return aType == ePseudoClass_nthChild || michael@0: aType == ePseudoClass_nthLastChild || michael@0: aType == ePseudoClass_nthOfType || michael@0: aType == ePseudoClass_nthLastOfType; michael@0: } michael@0: michael@0: void michael@0: nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString) michael@0: { michael@0: NS_ABORT_IF_FALSE(aType < ePseudoClass_Count, "Unexpected type"); michael@0: NS_ABORT_IF_FALSE(aType >= 0, "Very unexpected type"); michael@0: (*CSSPseudoClasses_info[aType].mAtom)->ToString(aString); michael@0: } michael@0: michael@0: nsCSSPseudoClasses::Type michael@0: nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom) michael@0: { michael@0: for (uint32_t i = 0; i < ArrayLength(CSSPseudoClasses_info); ++i) { michael@0: if (*CSSPseudoClasses_info[i].mAtom == aAtom) { michael@0: return sPseudoClassEnabled[i] ? Type(i) : ePseudoClass_NotPseudoClass; michael@0: } michael@0: } michael@0: michael@0: return nsCSSPseudoClasses::ePseudoClass_NotPseudoClass; michael@0: } michael@0: michael@0: /* static */ bool michael@0: nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType) michael@0: { michael@0: // See http://dev.w3.org/csswg/selectors4/#useraction-pseudos michael@0: return aType == ePseudoClass_hover || michael@0: aType == ePseudoClass_active || michael@0: aType == ePseudoClass_focus; michael@0: }