layout/style/nsCSSPseudoElements.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsCSSPseudoElements.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* atom list for CSS pseudo-elements */
    1.10 +
    1.11 +#include "mozilla/ArrayUtils.h"
    1.12 +
    1.13 +#include "nsCSSPseudoElements.h"
    1.14 +#include "nsAtomListUtils.h"
    1.15 +#include "nsStaticAtom.h"
    1.16 +#include "nsCSSAnonBoxes.h"
    1.17 +
    1.18 +using namespace mozilla;
    1.19 +
    1.20 +// define storage for all atoms
    1.21 +#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
    1.22 +  nsICSSPseudoElement* nsCSSPseudoElements::name_;
    1.23 +#include "nsCSSPseudoElementList.h"
    1.24 +#undef CSS_PSEUDO_ELEMENT
    1.25 +
    1.26 +#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
    1.27 +  NS_STATIC_ATOM_BUFFER(name_##_pseudo_element_buffer, value_)
    1.28 +#include "nsCSSPseudoElementList.h"
    1.29 +#undef CSS_PSEUDO_ELEMENT
    1.30 +
    1.31 +static const nsStaticAtom CSSPseudoElements_info[] = {
    1.32 +#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
    1.33 +  NS_STATIC_ATOM(name_##_pseudo_element_buffer, (nsIAtom**)&nsCSSPseudoElements::name_),
    1.34 +#include "nsCSSPseudoElementList.h"
    1.35 +#undef CSS_PSEUDO_ELEMENT
    1.36 +};
    1.37 +
    1.38 +// Separate from the array above so that we can have an array of
    1.39 +// nsStaticAtom (to pass to NS_RegisterStaticAtoms and
    1.40 +// nsAtomListUtils::IsMember), but with corresponding indices (so the
    1.41 +// i-th element of this array is the flags for the i-th pseudo-element
    1.42 +// in the previous array).
    1.43 +static const uint32_t CSSPseudoElements_flags[] = {
    1.44 +#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
    1.45 +  flags_,
    1.46 +#include "nsCSSPseudoElementList.h"
    1.47 +#undef CSS_PSEUDO_ELEMENT
    1.48 +};
    1.49 +
    1.50 +void nsCSSPseudoElements::AddRefAtoms()
    1.51 +{
    1.52 +  NS_RegisterStaticAtoms(CSSPseudoElements_info);
    1.53 +}
    1.54 +
    1.55 +bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom)
    1.56 +{
    1.57 +  return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info,
    1.58 +                                   ArrayLength(CSSPseudoElements_info));
    1.59 +}
    1.60 +
    1.61 +/* static */ bool
    1.62 +nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom)
    1.63 +{
    1.64 +  // We don't implement this using PseudoElementHasFlags because callers
    1.65 +  // want to pass things that could be anon boxes.
    1.66 +  NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) ||
    1.67 +               nsCSSAnonBoxes::IsAnonBox(aAtom),
    1.68 +               "must be pseudo element or anon box");
    1.69 +  bool result = aAtom == nsCSSPseudoElements::after ||
    1.70 +                  aAtom == nsCSSPseudoElements::before ||
    1.71 +                  aAtom == nsCSSPseudoElements::firstLetter ||
    1.72 +                  aAtom == nsCSSPseudoElements::firstLine;
    1.73 +  NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) ||
    1.74 +               result ==
    1.75 +                 PseudoElementHasFlags(GetPseudoType(aAtom), CSS_PSEUDO_ELEMENT_IS_CSS2),
    1.76 +               "result doesn't match flags");
    1.77 +  return result;
    1.78 +}
    1.79 +
    1.80 +/* static */ nsCSSPseudoElements::Type
    1.81 +nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom)
    1.82 +{
    1.83 +  for (uint32_t i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) {
    1.84 +    if (*CSSPseudoElements_info[i].mAtom == aAtom) {
    1.85 +      return Type(i);
    1.86 +    }
    1.87 +  }
    1.88 +
    1.89 +  if (nsCSSAnonBoxes::IsAnonBox(aAtom)) {
    1.90 +#ifdef MOZ_XUL
    1.91 +    if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) {
    1.92 +      return ePseudo_XULTree;
    1.93 +    }
    1.94 +#endif
    1.95 +
    1.96 +    return ePseudo_AnonBox;
    1.97 +  }
    1.98 +
    1.99 +  return ePseudo_NotPseudoElement;
   1.100 +}
   1.101 +
   1.102 +/* static */ nsIAtom*
   1.103 +nsCSSPseudoElements::GetPseudoAtom(Type aType)
   1.104 +{
   1.105 +  NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
   1.106 +               "Unexpected type");
   1.107 +  return *CSSPseudoElements_info[aType].mAtom;
   1.108 +}
   1.109 +
   1.110 +/* static */ uint32_t
   1.111 +nsCSSPseudoElements::FlagsForPseudoElement(const Type aType)
   1.112 +{
   1.113 +  size_t index = static_cast<size_t>(aType);
   1.114 +  NS_ASSERTION(index < ArrayLength(CSSPseudoElements_flags),
   1.115 +               "argument must be a pseudo-element");
   1.116 +  return CSSPseudoElements_flags[index];
   1.117 +}
   1.118 +
   1.119 +/* static */ bool
   1.120 +nsCSSPseudoElements::PseudoElementSupportsUserActionState(const Type aType)
   1.121 +{
   1.122 +  return PseudoElementHasFlags(aType,
   1.123 +                               CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE);
   1.124 +}

mercurial