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"
|
2016-12-01 21:40:04 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2003-04-02 08:51:07 +04:00
|
|
|
#include "nsStaticAtom.h"
|
2012-12-25 07:35:34 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2017-01-06 13:12:08 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "nsString.h"
|
2017-01-06 14:10:08 +03:00
|
|
|
#include "nsAttrValueInlines.h"
|
2017-01-06 13:12:08 +03:00
|
|
|
#include "nsIMozBrowserFrame.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
|
|
|
|
|
2016-05-04 08:09:36 +03:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
|
|
|
static_assert(!((flags_) & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME) || \
|
|
|
|
((flags_) & CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS), \
|
|
|
|
"Pseudo-class '" #name_ "' is enabled in chrome, so it " \
|
|
|
|
"should also be enabled in UA sheets");
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
|
2014-10-23 20:57:27 +04:00
|
|
|
// Array of nsStaticAtom for each of the pseudo-classes.
|
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
|
|
|
|
};
|
|
|
|
|
2014-10-23 20:57:27 +04:00
|
|
|
// Flags data for each of the pseudo-classes, which must be separate
|
|
|
|
// from the previous array since there's no place for it in
|
|
|
|
// nsStaticAtom.
|
2016-05-10 11:44:05 +03:00
|
|
|
/* static */ const uint32_t
|
|
|
|
nsCSSPseudoClasses::kPseudoClassFlags[] = {
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
|
|
|
flags_,
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
};
|
|
|
|
|
2016-05-10 11:44:05 +03:00
|
|
|
/* static */ bool
|
|
|
|
nsCSSPseudoClasses::sPseudoClassEnabled[] = {
|
2016-05-04 08:09:36 +03:00
|
|
|
// If the pseudo class has any "ENABLED_IN" flag set, it is disabled by
|
|
|
|
// default. Note that, if a pseudo class has pref, whatever its default
|
|
|
|
// value is, it'll later be changed in nsCSSPseudoClasses::AddRefAtoms()
|
|
|
|
// If the pseudo class has "ENABLED_IN" flags but doesn't have a pref,
|
|
|
|
// it is an internal pseudo class which is disabled elsewhere.
|
|
|
|
#define IS_ENABLED_BY_DEFAULT(flags_) \
|
|
|
|
(!((flags_) & CSS_PSEUDO_CLASS_ENABLED_MASK))
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
2016-05-04 08:09:36 +03:00
|
|
|
IS_ENABLED_BY_DEFAULT(flags_),
|
2012-12-25 07:35:34 +04:00
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
2016-05-04 08:09:36 +03:00
|
|
|
#undef IS_ENABLED_BY_DEFAULT
|
2016-04-22 15:40:45 +03:00
|
|
|
};
|
2012-12-25 07:35:34 +04:00
|
|
|
|
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);
|
2016-04-22 15:40:45 +03:00
|
|
|
|
|
|
|
#define CSS_PSEUDO_CLASS(name_, value_, flags_, pref_) \
|
|
|
|
if (pref_[0]) { \
|
|
|
|
auto idx = static_cast<CSSPseudoElementTypeBase>(Type::name_); \
|
|
|
|
Preferences::AddBoolVarCache(&sPseudoClassEnabled[idx], pref_); \
|
2012-12-25 07:35:34 +04:00
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
2016-04-22 15:40:45 +03:00
|
|
|
return aType == Type::lang ||
|
|
|
|
aType == Type::mozEmptyExceptChildrenWithLocalname ||
|
|
|
|
aType == Type::mozSystemMetric ||
|
|
|
|
aType == Type::mozLocaleDir ||
|
|
|
|
aType == Type::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
|
|
|
{
|
2016-04-22 15:40:45 +03:00
|
|
|
return aType == Type::nthChild ||
|
|
|
|
aType == Type::nthLastChild ||
|
|
|
|
aType == Type::nthOfType ||
|
|
|
|
aType == Type::nthLastOfType;
|
2010-04-24 06:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 16:52:25 +03:00
|
|
|
void
|
|
|
|
nsCSSPseudoClasses::PseudoTypeToString(Type aType, nsAString& aString)
|
|
|
|
{
|
2016-04-22 15:40:45 +03:00
|
|
|
MOZ_ASSERT(aType < Type::Count, "Unexpected type");
|
|
|
|
auto idx = static_cast<CSSPseudoClassTypeBase>(aType);
|
|
|
|
(*CSSPseudoClasses_info[idx].mAtom)->ToString(aString);
|
2011-03-23 16:52:25 +03:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:09:36 +03:00
|
|
|
/* static */ CSSPseudoClassType
|
2016-05-10 11:44:05 +03:00
|
|
|
nsCSSPseudoClasses::GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState)
|
2009-12-11 10:37:41 +03:00
|
|
|
{
|
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) {
|
2016-05-04 08:09:36 +03:00
|
|
|
Type type = Type(i);
|
2016-05-10 11:44:05 +03:00
|
|
|
return IsEnabled(type, aEnabledState) ? type : Type::NotPseudo;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-22 15:40:45 +03:00
|
|
|
return Type::NotPseudo;
|
2009-12-11 10:37:41 +03:00
|
|
|
}
|
2013-11-28 10:46:38 +04:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsCSSPseudoClasses::IsUserActionPseudoClass(Type aType)
|
|
|
|
{
|
|
|
|
// See http://dev.w3.org/csswg/selectors4/#useraction-pseudos
|
2016-04-22 15:40:45 +03:00
|
|
|
return aType == Type::hover ||
|
|
|
|
aType == Type::active ||
|
|
|
|
aType == Type::focus;
|
2013-11-28 10:46:38 +04:00
|
|
|
}
|
2017-01-06 13:12:08 +03:00
|
|
|
|
|
|
|
/* static */ Maybe<bool>
|
|
|
|
nsCSSPseudoClasses::MatchesElement(Type aType, const dom::Element* aElement)
|
|
|
|
{
|
|
|
|
switch (aType) {
|
|
|
|
case CSSPseudoClassType::mozNativeAnonymous:
|
|
|
|
return Some(aElement->IsInNativeAnonymousSubtree());
|
|
|
|
case CSSPseudoClassType::mozTableBorderNonzero: {
|
|
|
|
if (!aElement->IsHTMLElement(nsGkAtoms::table)) {
|
|
|
|
return Some(false);
|
|
|
|
}
|
|
|
|
const nsAttrValue *val = aElement->GetParsedAttr(nsGkAtoms::border);
|
|
|
|
return Some(val && (val->Type() != nsAttrValue::eInteger ||
|
|
|
|
val->GetIntegerValue() != 0));
|
|
|
|
}
|
|
|
|
case CSSPseudoClassType::mozBrowserFrame: {
|
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame =
|
|
|
|
do_QueryInterface(const_cast<Element*>(aElement));
|
|
|
|
return Some(browserFrame && browserFrame->GetReallyIsBrowser());
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
}
|