LCOV - code coverage report
Current view: directory - layout/style - nsCSSKeywords.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 38 21 55.3 %
Date: 2012-06-02 Functions: 5 2 40.0 %

       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 mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1999
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : /* keywords used within CSS property values */
      39                 : 
      40                 : #include "nsCSSKeywords.h"
      41                 : #include "nsString.h"
      42                 : #include "nsStaticNameTable.h"
      43                 : #include "nsReadableUtils.h"
      44                 : #include "nsStyleConsts.h"
      45                 : 
      46                 : // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
      47                 : extern const char* const kCSSRawKeywords[];
      48                 : 
      49                 : // define an array of all CSS keywords
      50                 : #define CSS_KEY(_name,_id) #_name,
      51                 : const char* const kCSSRawKeywords[] = {
      52                 : #include "nsCSSKeywordList.h"
      53                 : };
      54                 : #undef CSS_KEY
      55                 : 
      56                 : static PRInt32 gTableRefCount;
      57                 : static nsStaticCaseInsensitiveNameTable* gKeywordTable;
      58                 : 
      59                 : void
      60            1404 : nsCSSKeywords::AddRefTable(void) 
      61                 : {
      62            1404 :   if (0 == gTableRefCount++) {
      63            1404 :     NS_ASSERTION(!gKeywordTable, "pre existing array!");
      64            1404 :     gKeywordTable = new nsStaticCaseInsensitiveNameTable();
      65            1404 :     if (gKeywordTable) {
      66                 : #ifdef DEBUG
      67                 :     {
      68                 :       // let's verify the table...
      69            1404 :       PRInt32 index = 0;
      70          777816 :       for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) {
      71         1552824 :         nsCAutoString temp1(kCSSRawKeywords[index]);
      72         1552824 :         nsCAutoString temp2(kCSSRawKeywords[index]);
      73          776412 :         ToLowerCase(temp1);
      74          776412 :         NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
      75          776412 :         NS_ASSERTION(-1 == temp1.FindChar('_'), "underscore char in table");
      76                 :       }
      77            1404 :       NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
      78                 :     }
      79                 : #endif      
      80            1404 :       gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT); 
      81                 :     }
      82                 :   }
      83            1404 : }
      84                 : 
      85                 : void
      86            1403 : nsCSSKeywords::ReleaseTable(void) 
      87                 : {
      88            1403 :   if (0 == --gTableRefCount) {
      89            1403 :     if (gKeywordTable) {
      90            1403 :       delete gKeywordTable;
      91            1403 :       gKeywordTable = nsnull;
      92                 :     }
      93                 :   }
      94            1403 : }
      95                 : 
      96                 : nsCSSKeyword 
      97               0 : nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
      98                 : {
      99               0 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
     100               0 :   if (gKeywordTable) {
     101               0 :     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
     102                 :   }  
     103               0 :   return eCSSKeyword_UNKNOWN;
     104                 : }
     105                 : 
     106                 : nsCSSKeyword 
     107               0 : nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
     108                 : {
     109               0 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
     110               0 :   if (gKeywordTable) {
     111               0 :     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
     112                 :   }  
     113               0 :   return eCSSKeyword_UNKNOWN;
     114                 : }
     115                 : 
     116                 : const nsAFlatCString& 
     117               0 : nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
     118                 : {
     119               0 :   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
     120               0 :   NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range");
     121               0 :   if (gKeywordTable) {
     122               0 :     return gKeywordTable->GetStringValue(PRInt32(aKeyword));
     123                 :   } else {
     124               0 :     static nsDependentCString kNullStr("");
     125               0 :     return kNullStr;
     126                 :   }
     127                 : }
     128                 : 

Generated by: LCOV version 1.7