2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 05:47:31 +00:00
|
|
|
|
|
|
|
/* atom list for CSS pseudo-elements */
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2002-11-17 15:37:56 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2003-02-22 15:58:07 +00:00
|
|
|
#include "nsAtomListUtils.h"
|
2003-04-02 04:51:07 +00:00
|
|
|
#include "nsStaticAtom.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1998-12-11 02:51:05 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
1999-07-18 00:24:47 +00:00
|
|
|
// define storage for all atoms
|
2009-08-10 22:52:29 +00:00
|
|
|
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
|
|
|
|
nsICSSPseudoElement* nsCSSPseudoElements::name_;
|
2002-11-17 15:37:56 +00:00
|
|
|
#include "nsCSSPseudoElementList.h"
|
|
|
|
#undef CSS_PSEUDO_ELEMENT
|
1998-12-11 02:51:05 +00:00
|
|
|
|
2010-03-08 15:44:59 +00:00
|
|
|
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
|
2013-11-15 02:42:57 +00:00
|
|
|
NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_)
|
2010-03-08 15:44:59 +00:00
|
|
|
#include "nsCSSPseudoElementList.h"
|
2010-03-10 20:33:37 +00:00
|
|
|
#undef CSS_PSEUDO_ELEMENT
|
2010-03-08 15:44:59 +00:00
|
|
|
|
2014-10-23 16:57:27 +00:00
|
|
|
// Array of nsStaticAtom for each of the pseudo-elements.
|
2003-04-02 04:51:07 +00:00
|
|
|
static const nsStaticAtom CSSPseudoElements_info[] = {
|
2009-08-10 22:52:29 +00:00
|
|
|
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
|
2013-11-15 02:42:57 +00:00
|
|
|
NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_),
|
2003-02-22 15:58:07 +00:00
|
|
|
#include "nsCSSPseudoElementList.h"
|
|
|
|
#undef CSS_PSEUDO_ELEMENT
|
|
|
|
};
|
|
|
|
|
2014-10-23 16:57:27 +00:00
|
|
|
// Flags data for each of the pseudo-elements, which must be separate
|
|
|
|
// from the previous array since there's no place for it in
|
|
|
|
// nsStaticAtom.
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint32_t CSSPseudoElements_flags[] = {
|
2009-08-10 22:52:29 +00:00
|
|
|
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
|
|
|
|
flags_,
|
|
|
|
#include "nsCSSPseudoElementList.h"
|
|
|
|
#undef CSS_PSEUDO_ELEMENT
|
|
|
|
};
|
|
|
|
|
2002-11-17 15:37:56 +00:00
|
|
|
void nsCSSPseudoElements::AddRefAtoms()
|
1998-12-11 02:51:05 +00:00
|
|
|
{
|
2012-03-09 02:22:57 +00:00
|
|
|
NS_RegisterStaticAtoms(CSSPseudoElements_info);
|
1998-12-11 02:51:05 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom)
|
2002-11-17 15:37:56 +00:00
|
|
|
{
|
2003-02-22 15:58:07 +00:00
|
|
|
return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(CSSPseudoElements_info));
|
2002-11-17 15:37:56 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* static */ bool
|
2009-10-08 03:22:42 +00:00
|
|
|
nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom)
|
|
|
|
{
|
|
|
|
// We don't implement this using PseudoElementHasFlags because callers
|
|
|
|
// want to pass things that could be anon boxes.
|
|
|
|
NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) ||
|
|
|
|
nsCSSAnonBoxes::IsAnonBox(aAtom),
|
|
|
|
"must be pseudo element or anon box");
|
2011-09-29 06:19:26 +00:00
|
|
|
bool result = aAtom == nsCSSPseudoElements::after ||
|
2009-10-08 03:22:42 +00:00
|
|
|
aAtom == nsCSSPseudoElements::before ||
|
|
|
|
aAtom == nsCSSPseudoElements::firstLetter ||
|
|
|
|
aAtom == nsCSSPseudoElements::firstLine;
|
|
|
|
NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) ||
|
|
|
|
result ==
|
2013-11-17 18:33:56 +00:00
|
|
|
PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2),
|
2009-10-08 03:22:42 +00:00
|
|
|
"result doesn't match flags");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-16 22:07:00 +00:00
|
|
|
/* static */ CSSPseudoElementType
|
2009-12-11 07:37:40 +00:00
|
|
|
nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) {
|
2009-12-11 07:37:40 +00:00
|
|
|
if (*CSSPseudoElements_info[i].mAtom == aAtom) {
|
|
|
|
return Type(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCSSAnonBoxes::IsAnonBox(aAtom)) {
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) {
|
2016-02-16 22:07:00 +00:00
|
|
|
return Type::XULTree;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-16 22:07:00 +00:00
|
|
|
return Type::AnonBox;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 22:07:00 +00:00
|
|
|
return Type::NotPseudo;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:37:40 +00:00
|
|
|
/* static */ nsIAtom*
|
|
|
|
nsCSSPseudoElements::GetPseudoAtom(Type aType)
|
|
|
|
{
|
2016-02-16 22:07:00 +00:00
|
|
|
NS_ASSERTION(aType < Type::Count,
|
2009-12-11 07:37:40 +00:00
|
|
|
"Unexpected type");
|
2016-02-16 22:07:00 +00:00
|
|
|
return *CSSPseudoElements_info[static_cast<uint8_t>(aType)].mAtom;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
/* static */ uint32_t
|
2013-11-17 18:33:56 +00:00
|
|
|
nsCSSPseudoElements::FlagsForPseudoElement(const Type aType)
|
2003-07-04 01:33:10 +00:00
|
|
|
{
|
2013-11-17 18:33:56 +00:00
|
|
|
size_t index = static_cast<size_t>(aType);
|
|
|
|
NS_ASSERTION(index < ArrayLength(CSSPseudoElements_flags),
|
2009-08-10 22:52:29 +00:00
|
|
|
"argument must be a pseudo-element");
|
2013-11-17 18:33:56 +00:00
|
|
|
return CSSPseudoElements_flags[index];
|
2003-07-04 01:33:10 +00:00
|
|
|
}
|
2013-11-28 06:46:38 +00:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType)
|
|
|
|
{
|
|
|
|
return PseudoElementHasFlags(aType,
|
|
|
|
CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE);
|
|
|
|
}
|