1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsCSSPseudoClasses.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* atom list for CSS pseudo-classes */ 1.10 + 1.11 +#include "mozilla/ArrayUtils.h" 1.12 + 1.13 +#include "nsCSSPseudoClasses.h" 1.14 +#include "nsStaticAtom.h" 1.15 +#include "mozilla/Preferences.h" 1.16 +#include "nsString.h" 1.17 + 1.18 +using namespace mozilla; 1.19 + 1.20 +// define storage for all atoms 1.21 +#define CSS_PSEUDO_CLASS(_name, _value, _pref) \ 1.22 + static nsIAtom* sPseudoClass_##_name; 1.23 +#include "nsCSSPseudoClassList.h" 1.24 +#undef CSS_PSEUDO_CLASS 1.25 + 1.26 +#define CSS_PSEUDO_CLASS(name_, value_, pref_) \ 1.27 + NS_STATIC_ATOM_BUFFER(name_##_pseudo_class_buffer, value_) 1.28 +#include "nsCSSPseudoClassList.h" 1.29 +#undef CSS_PSEUDO_CLASS 1.30 + 1.31 +static const nsStaticAtom CSSPseudoClasses_info[] = { 1.32 +#define CSS_PSEUDO_CLASS(name_, value_, pref_) \ 1.33 + NS_STATIC_ATOM(name_##_pseudo_class_buffer, &sPseudoClass_##name_), 1.34 +#include "nsCSSPseudoClassList.h" 1.35 +#undef CSS_PSEUDO_CLASS 1.36 +}; 1.37 + 1.38 +static bool sPseudoClassEnabled[] = { 1.39 +#define CSS_PSEUDO_CLASS(name_, value_, pref_) \ 1.40 + true, 1.41 +#include "nsCSSPseudoClassList.h" 1.42 +#undef CSS_PSEUDO_CLASS 1.43 +}; 1.44 + 1.45 +void nsCSSPseudoClasses::AddRefAtoms() 1.46 +{ 1.47 + NS_RegisterStaticAtoms(CSSPseudoClasses_info); 1.48 + 1.49 +#define CSS_PSEUDO_CLASS(name_, value_, pref_) \ 1.50 + if (pref_[0]) { \ 1.51 + Preferences::AddBoolVarCache(&sPseudoClassEnabled[ePseudoClass_##name_], \ 1.52 + pref_); \ 1.53 + } 1.54 +#include "nsCSSPseudoClassList.h" 1.55 +#undef CSS_PSEUDO_CLASS 1.56 +} 1.57 + 1.58 +bool 1.59 +nsCSSPseudoClasses::HasStringArg(Type aType) 1.60 +{ 1.61 + return aType == ePseudoClass_lang || 1.62 + aType == ePseudoClass_mozEmptyExceptChildrenWithLocalname || 1.63 + aType == ePseudoClass_mozSystemMetric || 1.64 + aType == ePseudoClass_mozLocaleDir || 1.65 + aType == ePseudoClass_dir; 1.66 +} 1.67 + 1.68 +bool 1.69 +nsCSSPseudoClasses::HasNthPairArg(Type aType) 1.70 +{ 1.71 + return aType == ePseudoClass_nthChild || 1.72 + aType == ePseudoClass_nthLastChild || 1.73 + aType == ePseudoClass_nthOfType || 1.74 + aType == ePseudoClass_nthLastOfType; 1.75 +} 1.76 + 1.77 +void 1.78 +nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString) 1.79 +{ 1.80 + NS_ABORT_IF_FALSE(aType < ePseudoClass_Count, "Unexpected type"); 1.81 + NS_ABORT_IF_FALSE(aType >= 0, "Very unexpected type"); 1.82 + (*CSSPseudoClasses_info[aType].mAtom)->ToString(aString); 1.83 +} 1.84 + 1.85 +nsCSSPseudoClasses::Type 1.86 +nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom) 1.87 +{ 1.88 + for (uint32_t i = 0; i < ArrayLength(CSSPseudoClasses_info); ++i) { 1.89 + if (*CSSPseudoClasses_info[i].mAtom == aAtom) { 1.90 + return sPseudoClassEnabled[i] ? Type(i) : ePseudoClass_NotPseudoClass; 1.91 + } 1.92 + } 1.93 + 1.94 + return nsCSSPseudoClasses::ePseudoClass_NotPseudoClass; 1.95 +} 1.96 + 1.97 +/* static */ bool 1.98 +nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType) 1.99 +{ 1.100 + // See http://dev.w3.org/csswg/selectors4/#useraction-pseudos 1.101 + return aType == ePseudoClass_hover || 1.102 + aType == ePseudoClass_active || 1.103 + aType == ePseudoClass_focus; 1.104 +}