1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsCSSKeywords.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 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 +/* keywords used within CSS property values */ 1.10 + 1.11 +#include "nsCSSKeywords.h" 1.12 +#include "nsString.h" 1.13 +#include "nsStaticNameTable.h" 1.14 + 1.15 +// required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it 1.16 +extern const char* const kCSSRawKeywords[]; 1.17 + 1.18 +// define an array of all CSS keywords 1.19 +#define CSS_KEY(_name,_id) #_name, 1.20 +const char* const kCSSRawKeywords[] = { 1.21 +#include "nsCSSKeywordList.h" 1.22 +}; 1.23 +#undef CSS_KEY 1.24 + 1.25 +static int32_t gKeywordTableRefCount; 1.26 +static nsStaticCaseInsensitiveNameTable* gKeywordTable; 1.27 + 1.28 +void 1.29 +nsCSSKeywords::AddRefTable(void) 1.30 +{ 1.31 + if (0 == gKeywordTableRefCount++) { 1.32 + NS_ASSERTION(!gKeywordTable, "pre existing array!"); 1.33 + gKeywordTable = new nsStaticCaseInsensitiveNameTable(); 1.34 + if (gKeywordTable) { 1.35 +#ifdef DEBUG 1.36 + { 1.37 + // let's verify the table... 1.38 + int32_t index = 0; 1.39 + for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) { 1.40 + nsAutoCString temp1(kCSSRawKeywords[index]); 1.41 + nsAutoCString temp2(kCSSRawKeywords[index]); 1.42 + ToLowerCase(temp1); 1.43 + NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); 1.44 + NS_ASSERTION(-1 == temp1.FindChar('_'), "underscore char in table"); 1.45 + } 1.46 + NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync"); 1.47 + } 1.48 +#endif 1.49 + gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT); 1.50 + } 1.51 + } 1.52 +} 1.53 + 1.54 +void 1.55 +nsCSSKeywords::ReleaseTable(void) 1.56 +{ 1.57 + if (0 == --gKeywordTableRefCount) { 1.58 + if (gKeywordTable) { 1.59 + delete gKeywordTable; 1.60 + gKeywordTable = nullptr; 1.61 + } 1.62 + } 1.63 +} 1.64 + 1.65 +nsCSSKeyword 1.66 +nsCSSKeywords::LookupKeyword(const nsACString& aKeyword) 1.67 +{ 1.68 + NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); 1.69 + if (gKeywordTable) { 1.70 + return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); 1.71 + } 1.72 + return eCSSKeyword_UNKNOWN; 1.73 +} 1.74 + 1.75 +nsCSSKeyword 1.76 +nsCSSKeywords::LookupKeyword(const nsAString& aKeyword) 1.77 +{ 1.78 + NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); 1.79 + if (gKeywordTable) { 1.80 + return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); 1.81 + } 1.82 + return eCSSKeyword_UNKNOWN; 1.83 +} 1.84 + 1.85 +const nsAFlatCString& 1.86 +nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword) 1.87 +{ 1.88 + NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); 1.89 + NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range"); 1.90 + if (gKeywordTable) { 1.91 + return gKeywordTable->GetStringValue(int32_t(aKeyword)); 1.92 + } else { 1.93 + static nsDependentCString kNullStr(""); 1.94 + return kNullStr; 1.95 + } 1.96 +} 1.97 +