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 */
|
|
|
|
|
2017-02-14 19:23:11 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
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"
|
2017-04-18 03:15:47 +00:00
|
|
|
#include "nsDOMString.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.
|
2016-05-10 08:44:05 +00:00
|
|
|
/* static */ const uint32_t
|
|
|
|
nsCSSPseudoElements::kPseudoElementFlags[] = {
|
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) ||
|
2016-05-10 08:44:05 +00:00
|
|
|
result == PseudoElementHasFlags(
|
|
|
|
GetPseudoType(aAtom, EnabledState::eIgnoreEnabledState),
|
|
|
|
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
|
2016-05-10 08:44:05 +00:00
|
|
|
nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom, EnabledState aEnabledState)
|
2009-12-11 07:37:40 +00:00
|
|
|
{
|
2016-02-18 18:18:00 +00:00
|
|
|
for (CSSPseudoElementTypeBase i = 0;
|
|
|
|
i < ArrayLength(CSSPseudoElements_info);
|
|
|
|
++i) {
|
2009-12-11 07:37:40 +00:00
|
|
|
if (*CSSPseudoElements_info[i].mAtom == aAtom) {
|
2016-05-10 08:44:05 +00:00
|
|
|
auto type = static_cast<Type>(i);
|
2016-09-07 23:38:38 +00:00
|
|
|
// ::moz-placeholder is an alias for ::placeholder
|
|
|
|
if (type == CSSPseudoElementType::mozPlaceholder) {
|
|
|
|
type = CSSPseudoElementType::placeholder;
|
|
|
|
}
|
2016-05-10 08:44:05 +00:00
|
|
|
return IsEnabled(type, aEnabledState) ? type : Type::NotPseudo;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-03-09 04:41:04 +00:00
|
|
|
if (nsCSSAnonBoxes::IsNonInheritingAnonBox(aAtom)) {
|
|
|
|
return Type::NonInheritingAnonBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Type::InheritingAnonBox;
|
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-17 20:37:00 +00:00
|
|
|
NS_ASSERTION(aType < Type::Count, "Unexpected type");
|
2016-02-18 18:18:00 +00:00
|
|
|
return *CSSPseudoElements_info[
|
|
|
|
static_cast<CSSPseudoElementTypeBase>(aType)].mAtom;
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 03:15:47 +00:00
|
|
|
/* static */ nsIAtom*
|
|
|
|
nsCSSPseudoElements::GetPseudoAtom(const nsAString& aPseudoElement)
|
|
|
|
{
|
|
|
|
if (DOMStringIsNull(aPseudoElement) || aPseudoElement.IsEmpty() ||
|
|
|
|
aPseudoElement.First() != char16_t(':')) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// deal with two-colon forms of aPseudoElt
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
aPseudoElement.BeginReading(start);
|
|
|
|
aPseudoElement.EndReading(end);
|
|
|
|
NS_ASSERTION(start != end, "aPseudoElement is not empty!");
|
|
|
|
++start;
|
|
|
|
bool haveTwoColons = true;
|
|
|
|
if (start == end || *start != char16_t(':')) {
|
|
|
|
--start;
|
|
|
|
haveTwoColons = false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIAtom> pseudo = NS_Atomize(Substring(start, end));
|
|
|
|
MOZ_ASSERT(pseudo);
|
|
|
|
|
|
|
|
// There aren't any non-CSS2 pseudo-elements with a single ':'
|
|
|
|
if (!haveTwoColons &&
|
|
|
|
(!IsPseudoElement(pseudo) || !IsCSS2PseudoElement(pseudo))) {
|
|
|
|
// XXXbz I'd really rather we threw an exception or something, but
|
|
|
|
// the DOM spec sucks.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pseudo;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|