LCOV - code coverage report
Current view: directory - layout/style - nsCSSPseudoElements.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 28 3 10.7 %
Date: 2012-06-02 Functions: 6 1 16.7 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is atom lists for CSS pseudos.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is 
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   L. David Baron <dbaron@dbaron.org>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : /* atom list for CSS pseudo-elements */
      40                 : 
      41                 : #include "mozilla/Util.h"
      42                 : 
      43                 : #include "nsCSSPseudoElements.h"
      44                 : #include "nsAtomListUtils.h"
      45                 : #include "nsStaticAtom.h"
      46                 : #include "nsMemory.h"
      47                 : #include "nsCSSAnonBoxes.h"
      48                 : 
      49                 : using namespace mozilla;
      50                 : 
      51                 : // define storage for all atoms
      52                 : #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
      53                 :   nsICSSPseudoElement* nsCSSPseudoElements::name_;
      54                 : #include "nsCSSPseudoElementList.h"
      55                 : #undef CSS_PSEUDO_ELEMENT
      56                 : 
      57                 : #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
      58                 :   NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
      59                 : #include "nsCSSPseudoElementList.h"
      60                 : #undef CSS_PSEUDO_ELEMENT
      61                 : 
      62                 : static const nsStaticAtom CSSPseudoElements_info[] = {
      63                 : #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
      64                 :   NS_STATIC_ATOM(name_##_buffer, (nsIAtom**)&nsCSSPseudoElements::name_),
      65                 : #include "nsCSSPseudoElementList.h"
      66                 : #undef CSS_PSEUDO_ELEMENT
      67                 : };
      68                 : 
      69                 : // Separate from the array above so that we can have an array of
      70                 : // nsStaticAtom (to pass to NS_RegisterStaticAtoms and
      71                 : // nsAtomListUtils::IsMember), but with corresponding indices (so the
      72                 : // i-th element of this array is the flags for the i-th pseudo-element
      73                 : // in the previous array).
      74                 : static const PRUint32 CSSPseudoElements_flags[] = {
      75                 : #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
      76                 :   flags_,
      77                 : #include "nsCSSPseudoElementList.h"
      78                 : #undef CSS_PSEUDO_ELEMENT
      79                 : };
      80                 : 
      81            1404 : void nsCSSPseudoElements::AddRefAtoms()
      82                 : {
      83            1404 :   NS_RegisterStaticAtoms(CSSPseudoElements_info);
      84            1404 : }
      85                 : 
      86               0 : bool nsCSSPseudoElements::IsPseudoElement(nsIAtom *aAtom)
      87                 : {
      88                 :   return nsAtomListUtils::IsMember(aAtom, CSSPseudoElements_info,
      89               0 :                                    ArrayLength(CSSPseudoElements_info));
      90                 : }
      91                 : 
      92                 : /* static */ bool
      93               0 : nsCSSPseudoElements::IsCSS2PseudoElement(nsIAtom *aAtom)
      94                 : {
      95                 :   // We don't implement this using PseudoElementHasFlags because callers
      96                 :   // want to pass things that could be anon boxes.
      97               0 :   NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) ||
      98                 :                nsCSSAnonBoxes::IsAnonBox(aAtom),
      99                 :                "must be pseudo element or anon box");
     100                 :   bool result = aAtom == nsCSSPseudoElements::after ||
     101                 :                   aAtom == nsCSSPseudoElements::before ||
     102                 :                   aAtom == nsCSSPseudoElements::firstLetter ||
     103               0 :                   aAtom == nsCSSPseudoElements::firstLine;
     104               0 :   NS_ASSERTION(nsCSSAnonBoxes::IsAnonBox(aAtom) ||
     105                 :                result ==
     106                 :                  PseudoElementHasFlags(aAtom, CSS_PSEUDO_ELEMENT_IS_CSS2),
     107                 :                "result doesn't match flags");
     108               0 :   return result;
     109                 : }
     110                 : 
     111                 : /* static */ nsCSSPseudoElements::Type
     112               0 : nsCSSPseudoElements::GetPseudoType(nsIAtom *aAtom)
     113                 : {
     114               0 :   for (PRUint32 i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) {
     115               0 :     if (*CSSPseudoElements_info[i].mAtom == aAtom) {
     116               0 :       return Type(i);
     117                 :     }
     118                 :   }
     119                 : 
     120               0 :   if (nsCSSAnonBoxes::IsAnonBox(aAtom)) {
     121                 : #ifdef MOZ_XUL
     122               0 :     if (nsCSSAnonBoxes::IsTreePseudoElement(aAtom)) {
     123               0 :       return ePseudo_XULTree;
     124                 :     }
     125                 : #endif
     126                 : 
     127               0 :     return ePseudo_AnonBox;
     128                 :   }
     129                 : 
     130               0 :   return ePseudo_NotPseudoElement;
     131                 : }
     132                 : 
     133                 : /* static */ nsIAtom*
     134               0 : nsCSSPseudoElements::GetPseudoAtom(Type aType)
     135                 : {
     136               0 :   NS_ASSERTION(aType < nsCSSPseudoElements::ePseudo_PseudoElementCount,
     137                 :                "Unexpected type");
     138               0 :   return *CSSPseudoElements_info[aType].mAtom;
     139                 : }
     140                 : 
     141                 : /* static */ PRUint32
     142               0 : nsCSSPseudoElements::FlagsForPseudoElement(nsIAtom *aAtom)
     143                 : {
     144                 :   PRUint32 i;
     145               0 :   for (i = 0; i < ArrayLength(CSSPseudoElements_info); ++i) {
     146               0 :     if (*CSSPseudoElements_info[i].mAtom == aAtom) {
     147               0 :       break;
     148                 :     }
     149                 :   }
     150               0 :   NS_ASSERTION(i < ArrayLength(CSSPseudoElements_info),
     151                 :                "argument must be a pseudo-element");
     152               0 :   return CSSPseudoElements_flags[i];
     153                 : }

Generated by: LCOV version 1.7