layout/style/nsCSSKeywords.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing 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/. */
     6 /* keywords used within CSS property values */
     8 #include "nsCSSKeywords.h"
     9 #include "nsString.h"
    10 #include "nsStaticNameTable.h"
    12 // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
    13 extern const char* const kCSSRawKeywords[];
    15 // define an array of all CSS keywords
    16 #define CSS_KEY(_name,_id) #_name,
    17 const char* const kCSSRawKeywords[] = {
    18 #include "nsCSSKeywordList.h"
    19 };
    20 #undef CSS_KEY
    22 static int32_t gKeywordTableRefCount;
    23 static nsStaticCaseInsensitiveNameTable* gKeywordTable;
    25 void
    26 nsCSSKeywords::AddRefTable(void) 
    27 {
    28   if (0 == gKeywordTableRefCount++) {
    29     NS_ASSERTION(!gKeywordTable, "pre existing array!");
    30     gKeywordTable = new nsStaticCaseInsensitiveNameTable();
    31     if (gKeywordTable) {
    32 #ifdef DEBUG
    33     {
    34       // let's verify the table...
    35       int32_t index = 0;
    36       for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) {
    37         nsAutoCString temp1(kCSSRawKeywords[index]);
    38         nsAutoCString temp2(kCSSRawKeywords[index]);
    39         ToLowerCase(temp1);
    40         NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
    41         NS_ASSERTION(-1 == temp1.FindChar('_'), "underscore char in table");
    42       }
    43       NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
    44     }
    45 #endif      
    46       gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT); 
    47     }
    48   }
    49 }
    51 void
    52 nsCSSKeywords::ReleaseTable(void) 
    53 {
    54   if (0 == --gKeywordTableRefCount) {
    55     if (gKeywordTable) {
    56       delete gKeywordTable;
    57       gKeywordTable = nullptr;
    58     }
    59   }
    60 }
    62 nsCSSKeyword 
    63 nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
    64 {
    65   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
    66   if (gKeywordTable) {
    67     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
    68   }  
    69   return eCSSKeyword_UNKNOWN;
    70 }
    72 nsCSSKeyword 
    73 nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
    74 {
    75   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
    76   if (gKeywordTable) {
    77     return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
    78   }  
    79   return eCSSKeyword_UNKNOWN;
    80 }
    82 const nsAFlatCString& 
    83 nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
    84 {
    85   NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
    86   NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range");
    87   if (gKeywordTable) {
    88     return gKeywordTable->GetStringValue(int32_t(aKeyword));
    89   } else {
    90     static nsDependentCString kNullStr("");
    91     return kNullStr;
    92   }
    93 }

mercurial