Bumping manifests a=b2g-bump
[gecko.git] / layout / style / nsCSSKeywords.cpp
blobc61b0f65715e2daf2d3afd91b77a366c37069e4c
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"
20 #undef CSS_KEY
22 static int32_t gKeywordTableRefCount;
23 static nsStaticCaseInsensitiveNameTable* gKeywordTable;
25 void
26 nsCSSKeywords::AddRefTable(void)
28 if (0 == gKeywordTableRefCount++) {
29 NS_ASSERTION(!gKeywordTable, "pre existing array!");
30 gKeywordTable = new nsStaticCaseInsensitiveNameTable();
31 if (gKeywordTable) {
32 #ifdef DEBUG
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");
43 NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
45 #endif
46 gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT);
51 void
52 nsCSSKeywords::ReleaseTable(void)
54 if (0 == --gKeywordTableRefCount) {
55 if (gKeywordTable) {
56 delete gKeywordTable;
57 gKeywordTable = nullptr;
62 nsCSSKeyword
63 nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
65 NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
66 if (gKeywordTable) {
67 return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
69 return eCSSKeyword_UNKNOWN;
72 nsCSSKeyword
73 nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
75 NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
76 if (gKeywordTable) {
77 return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
79 return eCSSKeyword_UNKNOWN;
82 const nsAFlatCString&
83 nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
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;