LCOV - code coverage report
Current view: top level - layout/style - nsCSSPseudoClasses.h (source / functions) Hit Total Coverage
Test: output.info Lines: 13 14 92.9 %
Date: 2017-07-14 16:53:18 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* atom list for CSS pseudo-classes */
       7             : 
       8             : #ifndef nsCSSPseudoClasses_h___
       9             : #define nsCSSPseudoClasses_h___
      10             : 
      11             : #include "nsStringFwd.h"
      12             : #include "mozilla/CSSEnabledState.h"
      13             : #include "mozilla/Maybe.h"
      14             : 
      15             : // The following two flags along with the pref defines where this pseudo
      16             : // class can be used:
      17             : // * If none of the two flags is presented, the pref completely controls
      18             : //   the availability of this pseudo class. And in that case, if it has
      19             : //   no pref, this property is usable everywhere.
      20             : // * If any of the flags is set, this pseudo class is always enabled in
      21             : //   the specific contexts regardless of the value of the pref. If there
      22             : //   is no pref for this pseudo class at all in this case, it is an
      23             : //   internal-only pseudo class, which cannot be used anywhere else.
      24             : #define CSS_PSEUDO_CLASS_ENABLED_MASK                  (3<<0)
      25             : #define CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS          (1<<0)
      26             : #define CSS_PSEUDO_CLASS_ENABLED_IN_CHROME             (1<<1)
      27             : #define CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME \
      28             :   (CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS | CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)
      29             : 
      30             : class nsIAtom;
      31             : 
      32             : namespace mozilla {
      33             : namespace dom {
      34             : class Element;
      35             : } // namespace dom
      36             : 
      37             : // The total count of CSSPseudoClassType is less than 256,
      38             : // so use uint8_t as its underlying type.
      39             : typedef uint8_t CSSPseudoClassTypeBase;
      40             : enum class CSSPseudoClassType : CSSPseudoClassTypeBase
      41             : {
      42             : #define CSS_PSEUDO_CLASS(_name, _value, _flags, _pref) \
      43             :   _name,
      44             : #include "nsCSSPseudoClassList.h"
      45             : #undef CSS_PSEUDO_CLASS
      46             :   Count,
      47             :   NotPseudo,  // This value MUST be second last! SelectorMatches depends on it.
      48             :   MAX
      49             : };
      50             : 
      51             : } // namespace mozilla
      52             : 
      53             : class nsCSSPseudoClasses
      54             : {
      55             :   typedef mozilla::CSSPseudoClassType Type;
      56             :   typedef mozilla::CSSEnabledState EnabledState;
      57             : 
      58             : public:
      59             :   static void AddRefAtoms();
      60             : 
      61             :   static Type GetPseudoType(nsIAtom* aAtom, EnabledState aEnabledState);
      62             :   static bool HasStringArg(Type aType);
      63             :   static bool HasNthPairArg(Type aType);
      64        2385 :   static bool HasSelectorListArg(Type aType) {
      65        2385 :     return aType == Type::any;
      66             :   }
      67             :   static bool IsUserActionPseudoClass(Type aType);
      68             : 
      69             :   // Should only be used on types other than Count and NotPseudoClass
      70             :   static void PseudoTypeToString(Type aType, nsAString& aString);
      71             : 
      72        2501 :   static bool IsEnabled(Type aType, EnabledState aEnabledState)
      73             :   {
      74        2501 :     auto index = static_cast<size_t>(aType);
      75        2501 :     MOZ_ASSERT(index < static_cast<size_t>(Type::Count));
      76        2501 :     if (sPseudoClassEnabled[index] ||
      77             :         aEnabledState == EnabledState::eIgnoreEnabledState) {
      78        2336 :       return true;
      79             :     }
      80         165 :     auto flags = kPseudoClassFlags[index];
      81         540 :     if (((aEnabledState & EnabledState::eInChrome) &&
      82         735 :          (flags & CSS_PSEUDO_CLASS_ENABLED_IN_CHROME)) ||
      83         405 :         ((aEnabledState & EnabledState::eInUASheets) &&
      84         240 :          (flags & CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS))) {
      85         165 :       return true;
      86             :     }
      87           0 :     return false;
      88             :   }
      89             : 
      90             :   // Checks whether the given pseudo class matches the element.
      91             :   // It returns Some(result) if this function is able to check
      92             :   // the pseudo-class, Nothing() otherwise.
      93             :   static mozilla::Maybe<bool>
      94             :     MatchesElement(Type aType, const mozilla::dom::Element* aElement);
      95             : 
      96             : private:
      97             :   static const uint32_t kPseudoClassFlags[size_t(Type::Count)];
      98             :   static bool sPseudoClassEnabled[size_t(Type::Count)];
      99             : };
     100             : 
     101             : #endif /* nsCSSPseudoClasses_h___ */

Generated by: LCOV version 1.13