/src/mozilla-central/layout/style/nsCSSKeywords.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* keywords used within CSS property values */ |
8 | | |
9 | | #include "nsCSSKeywords.h" |
10 | | #include "nsString.h" |
11 | | #include "nsStaticNameTable.h" |
12 | | |
13 | | // required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it |
14 | | extern const char* const kCSSRawKeywords[]; |
15 | | |
16 | | // define an array of all CSS keywords |
17 | | #define CSS_KEY(_name,_id) #_name, |
18 | | const char* const kCSSRawKeywords[] = { |
19 | | #include "nsCSSKeywordList.h" |
20 | | }; |
21 | | #undef CSS_KEY |
22 | | |
23 | | static int32_t gKeywordTableRefCount; |
24 | | static nsStaticCaseInsensitiveNameTable* gKeywordTable; |
25 | | |
26 | | void |
27 | | nsCSSKeywords::AddRefTable(void) |
28 | 3 | { |
29 | 3 | if (0 == gKeywordTableRefCount++) { |
30 | 3 | NS_ASSERTION(!gKeywordTable, "pre existing array!"); |
31 | 3 | gKeywordTable = |
32 | 3 | new nsStaticCaseInsensitiveNameTable(kCSSRawKeywords, eCSSKeyword_COUNT); |
33 | | #ifdef DEBUG |
34 | | // Partially verify the entries. |
35 | | int32_t index = 0; |
36 | | for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) { |
37 | | nsAutoCString temp(kCSSRawKeywords[index]); |
38 | | NS_ASSERTION(-1 == temp.FindChar('_'), "underscore char in table"); |
39 | | } |
40 | | NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync"); |
41 | | #endif |
42 | | } |
43 | 3 | } |
44 | | |
45 | | void |
46 | | nsCSSKeywords::ReleaseTable(void) |
47 | 0 | { |
48 | 0 | if (0 == --gKeywordTableRefCount) { |
49 | 0 | if (gKeywordTable) { |
50 | 0 | delete gKeywordTable; |
51 | 0 | gKeywordTable = nullptr; |
52 | 0 | } |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | nsCSSKeyword |
57 | | nsCSSKeywords::LookupKeyword(const nsACString& aKeyword) |
58 | 0 | { |
59 | 0 | NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); |
60 | 0 | if (gKeywordTable) { |
61 | 0 | return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); |
62 | 0 | } |
63 | 0 | return eCSSKeyword_UNKNOWN; |
64 | 0 | } |
65 | | |
66 | | nsCSSKeyword |
67 | | nsCSSKeywords::LookupKeyword(const nsAString& aKeyword) |
68 | 0 | { |
69 | 0 | NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); |
70 | 0 | if (gKeywordTable) { |
71 | 0 | return nsCSSKeyword(gKeywordTable->Lookup(aKeyword)); |
72 | 0 | } |
73 | 0 | return eCSSKeyword_UNKNOWN; |
74 | 0 | } |
75 | | |
76 | | const nsCString& |
77 | | nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword) |
78 | 0 | { |
79 | 0 | NS_ASSERTION(gKeywordTable, "no lookup table, needs addref"); |
80 | 0 | NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range"); |
81 | 0 | if (gKeywordTable) { |
82 | 0 | return gKeywordTable->GetStringValue(int32_t(aKeyword)); |
83 | 0 | } else { |
84 | 0 | static nsDependentCString kNullStr(""); |
85 | 0 | return kNullStr; |
86 | 0 | } |
87 | 0 | } |
88 | | |