Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* atom list for CSS pseudo-classes */ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/ArrayUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCSSPseudoClasses.h" |
michael@0 | 11 | #include "nsStaticAtom.h" |
michael@0 | 12 | #include "mozilla/Preferences.h" |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla; |
michael@0 | 16 | |
michael@0 | 17 | // define storage for all atoms |
michael@0 | 18 | #define CSS_PSEUDO_CLASS(_name, _value, _pref) \ |
michael@0 | 19 | static nsIAtom* sPseudoClass_##_name; |
michael@0 | 20 | #include "nsCSSPseudoClassList.h" |
michael@0 | 21 | #undef CSS_PSEUDO_CLASS |
michael@0 | 22 | |
michael@0 | 23 | #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ |
michael@0 | 24 | NS_STATIC_ATOM_BUFFER(name_##_pseudo_class_buffer, value_) |
michael@0 | 25 | #include "nsCSSPseudoClassList.h" |
michael@0 | 26 | #undef CSS_PSEUDO_CLASS |
michael@0 | 27 | |
michael@0 | 28 | static const nsStaticAtom CSSPseudoClasses_info[] = { |
michael@0 | 29 | #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ |
michael@0 | 30 | NS_STATIC_ATOM(name_##_pseudo_class_buffer, &sPseudoClass_##name_), |
michael@0 | 31 | #include "nsCSSPseudoClassList.h" |
michael@0 | 32 | #undef CSS_PSEUDO_CLASS |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | static bool sPseudoClassEnabled[] = { |
michael@0 | 36 | #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ |
michael@0 | 37 | true, |
michael@0 | 38 | #include "nsCSSPseudoClassList.h" |
michael@0 | 39 | #undef CSS_PSEUDO_CLASS |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | void nsCSSPseudoClasses::AddRefAtoms() |
michael@0 | 43 | { |
michael@0 | 44 | NS_RegisterStaticAtoms(CSSPseudoClasses_info); |
michael@0 | 45 | |
michael@0 | 46 | #define CSS_PSEUDO_CLASS(name_, value_, pref_) \ |
michael@0 | 47 | if (pref_[0]) { \ |
michael@0 | 48 | Preferences::AddBoolVarCache(&sPseudoClassEnabled[ePseudoClass_##name_], \ |
michael@0 | 49 | pref_); \ |
michael@0 | 50 | } |
michael@0 | 51 | #include "nsCSSPseudoClassList.h" |
michael@0 | 52 | #undef CSS_PSEUDO_CLASS |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | bool |
michael@0 | 56 | nsCSSPseudoClasses::HasStringArg(Type aType) |
michael@0 | 57 | { |
michael@0 | 58 | return aType == ePseudoClass_lang || |
michael@0 | 59 | aType == ePseudoClass_mozEmptyExceptChildrenWithLocalname || |
michael@0 | 60 | aType == ePseudoClass_mozSystemMetric || |
michael@0 | 61 | aType == ePseudoClass_mozLocaleDir || |
michael@0 | 62 | aType == ePseudoClass_dir; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | bool |
michael@0 | 66 | nsCSSPseudoClasses::HasNthPairArg(Type aType) |
michael@0 | 67 | { |
michael@0 | 68 | return aType == ePseudoClass_nthChild || |
michael@0 | 69 | aType == ePseudoClass_nthLastChild || |
michael@0 | 70 | aType == ePseudoClass_nthOfType || |
michael@0 | 71 | aType == ePseudoClass_nthLastOfType; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString) |
michael@0 | 76 | { |
michael@0 | 77 | NS_ABORT_IF_FALSE(aType < ePseudoClass_Count, "Unexpected type"); |
michael@0 | 78 | NS_ABORT_IF_FALSE(aType >= 0, "Very unexpected type"); |
michael@0 | 79 | (*CSSPseudoClasses_info[aType].mAtom)->ToString(aString); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | nsCSSPseudoClasses::Type |
michael@0 | 83 | nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom) |
michael@0 | 84 | { |
michael@0 | 85 | for (uint32_t i = 0; i < ArrayLength(CSSPseudoClasses_info); ++i) { |
michael@0 | 86 | if (*CSSPseudoClasses_info[i].mAtom == aAtom) { |
michael@0 | 87 | return sPseudoClassEnabled[i] ? Type(i) : ePseudoClass_NotPseudoClass; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | return nsCSSPseudoClasses::ePseudoClass_NotPseudoClass; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /* static */ bool |
michael@0 | 95 | nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType) |
michael@0 | 96 | { |
michael@0 | 97 | // See http://dev.w3.org/csswg/selectors4/#useraction-pseudos |
michael@0 | 98 | return aType == ePseudoClass_hover || |
michael@0 | 99 | aType == ePseudoClass_active || |
michael@0 | 100 | aType == ePseudoClass_focus; |
michael@0 | 101 | } |