2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* atom list for CSS pseudo-classes */
|
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSPseudoClasses.h"
|
2003-04-02 08:51:07 +04:00
|
|
|
#include "nsStaticAtom.h"
|
2012-12-25 07:35:34 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "nsString.h"
|
1998-12-11 05:51:05 +03:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
1999-07-18 04:24:47 +04:00
|
|
|
// define storage for all atoms
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value, _flags, _pref) \
|
2012-12-25 07:35:34 +04:00
|
|
|
static nsIAtom* sPseudoClass_##_name;
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
1998-12-11 05:51:05 +03:00
|
|
|
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
2013-11-15 06:42:57 +04:00
|
|
|
NS_STATIC_ATOM_BUFFER(name_##_pseudo_class_buffer, value_)
|
2010-03-08 18:44:59 +03:00
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
|
2003-04-02 08:51:07 +04:00
|
|
|
static const nsStaticAtom CSSPseudoClasses_info[] = {
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
2013-11-15 06:42:57 +04:00
|
|
|
NS_STATIC_ATOM(name_##_pseudo_class_buffer, &sPseudoClass_##name_),
|
2003-02-22 18:58:07 +03:00
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
};
|
|
|
|
|
2012-12-25 07:35:34 +04:00
|
|
|
static bool sPseudoClassEnabled[] = {
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
2012-12-25 07:35:34 +04:00
|
|
|
true,
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
};
|
|
|
|
|
2002-11-17 18:37:56 +03:00
|
|
|
void nsCSSPseudoClasses::AddRefAtoms()
|
1998-12-11 05:51:05 +03:00
|
|
|
{
|
2012-03-09 06:22:57 +04:00
|
|
|
NS_RegisterStaticAtoms(CSSPseudoClasses_info);
|
2012-12-25 07:35:34 +04:00
|
|
|
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
2012-12-25 07:35:34 +04:00
|
|
|
if (pref_[0]) { \
|
|
|
|
Preferences::AddBoolVarCache(&sPseudoClassEnabled[ePseudoClass_##name_], \
|
|
|
|
pref_); \
|
|
|
|
}
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
1998-12-11 05:51:05 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-03-23 16:52:24 +03:00
|
|
|
nsCSSPseudoClasses::HasStringArg(Type aType)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
return aType == ePseudoClass_lang ||
|
|
|
|
aType == ePseudoClass_mozEmptyExceptChildrenWithLocalname ||
|
|
|
|
aType == ePseudoClass_mozSystemMetric ||
|
2012-08-10 07:37:58 +04:00
|
|
|
aType == ePseudoClass_mozLocaleDir ||
|
|
|
|
aType == ePseudoClass_dir;
|
2008-06-03 07:17:35 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-03-23 16:52:24 +03:00
|
|
|
nsCSSPseudoClasses::HasNthPairArg(Type aType)
|
2008-06-03 07:17:35 +04:00
|
|
|
{
|
2011-03-23 16:52:24 +03:00
|
|
|
return aType == ePseudoClass_nthChild ||
|
|
|
|
aType == ePseudoClass_nthLastChild ||
|
|
|
|
aType == ePseudoClass_nthOfType ||
|
|
|
|
aType == ePseudoClass_nthLastOfType;
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void
|
|
|
|
nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aType < ePseudoClass_Count, "Unexpected type");
|
|
|
|
NS_ABORT_IF_FALSE(aType >= 0, "Very unexpected type");
|
|
|
|
(*CSSPseudoClasses_info[aType].mAtom)->ToString(aString);
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:41 +03:00
|
|
|
nsCSSPseudoClasses::Type
|
|
|
|
nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(CSSPseudoClasses_info); ++i) {
|
2009-12-11 10:37:41 +03:00
|
|
|
if (*CSSPseudoClasses_info[i].mAtom == aAtom) {
|
2012-12-25 07:35:34 +04:00
|
|
|
return sPseudoClassEnabled[i] ? Type(i) : ePseudoClass_NotPseudoClass;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSPseudoClasses::ePseudoClass_NotPseudoClass;
|
|
|
|
}
|
2013-11-28 10:46:38 +04:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType)
|
|
|
|
{
|
|
|
|
// See http://dev.w3.org/csswg/selectors4/#useraction-pseudos
|
|
|
|
return aType == ePseudoClass_hover ||
|
|
|
|
aType == ePseudoClass_active ||
|
|
|
|
aType == ePseudoClass_focus;
|
|
|
|
}
|