layout/style/nsCSSKeywords.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial