2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* keywords used within CSS property values */
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCSSKeywords.h"
|
1999-07-18 04:32:32 +04:00
|
|
|
#include "nsString.h"
|
2000-08-22 10:57:32 +04:00
|
|
|
#include "nsStaticNameTable.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-02-26 06:34:15 +03:00
|
|
|
// required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
|
|
|
|
extern const char* const kCSSRawKeywords[];
|
|
|
|
|
1999-07-18 04:32:32 +04:00
|
|
|
// define an array of all CSS keywords
|
2000-08-22 10:57:32 +04:00
|
|
|
#define CSS_KEY(_name,_id) #_name,
|
2003-02-26 03:52:07 +03:00
|
|
|
const char* const kCSSRawKeywords[] = {
|
1999-07-18 04:32:32 +04:00
|
|
|
#include "nsCSSKeywordList.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-07-18 04:32:32 +04:00
|
|
|
#undef CSS_KEY
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-11-15 06:42:57 +04:00
|
|
|
static int32_t gKeywordTableRefCount;
|
2000-08-22 10:57:32 +04:00
|
|
|
static nsStaticCaseInsensitiveNameTable* gKeywordTable;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-18 04:32:32 +04:00
|
|
|
void
|
|
|
|
nsCSSKeywords::AddRefTable(void)
|
|
|
|
{
|
2013-11-15 06:42:57 +04:00
|
|
|
if (0 == gKeywordTableRefCount++) {
|
2000-08-22 10:57:32 +04:00
|
|
|
NS_ASSERTION(!gKeywordTable, "pre existing array!");
|
2015-05-06 07:13:53 +03:00
|
|
|
gKeywordTable =
|
|
|
|
new nsStaticCaseInsensitiveNameTable(kCSSRawKeywords, eCSSKeyword_COUNT);
|
2000-08-22 10:57:32 +04:00
|
|
|
#ifdef DEBUG
|
2015-05-06 07:13:53 +03:00
|
|
|
// Partially verify the entries.
|
|
|
|
int32_t index = 0;
|
|
|
|
for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) {
|
|
|
|
nsAutoCString temp(kCSSRawKeywords[index]);
|
|
|
|
NS_ASSERTION(-1 == temp.FindChar('_'), "underscore char in table");
|
2000-08-22 10:57:32 +04:00
|
|
|
}
|
2015-05-06 07:13:53 +03:00
|
|
|
NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
|
|
|
|
#endif
|
1999-07-18 04:32:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSKeywords::ReleaseTable(void)
|
|
|
|
{
|
2013-11-15 06:42:57 +04:00
|
|
|
if (0 == --gKeywordTableRefCount) {
|
2000-08-22 10:57:32 +04:00
|
|
|
if (gKeywordTable) {
|
|
|
|
delete gKeywordTable;
|
2012-07-30 18:20:58 +04:00
|
|
|
gKeywordTable = nullptr;
|
1999-07-18 04:32:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-18 04:32:32 +04:00
|
|
|
nsCSSKeyword
|
2001-11-28 00:13:53 +03:00
|
|
|
nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
|
1999-07-18 04:32:32 +04:00
|
|
|
{
|
2000-08-22 10:57:32 +04:00
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
|
|
|
if (gKeywordTable) {
|
|
|
|
return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
|
|
|
|
}
|
1999-07-18 04:32:32 +04:00
|
|
|
return eCSSKeyword_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2000-03-12 13:07:57 +03:00
|
|
|
nsCSSKeyword
|
2001-11-28 00:13:53 +03:00
|
|
|
nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
|
2000-08-22 10:57:32 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
|
|
|
if (gKeywordTable) {
|
|
|
|
return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
|
|
|
|
}
|
|
|
|
return eCSSKeyword_UNKNOWN;
|
2000-03-12 13:07:57 +03:00
|
|
|
}
|
|
|
|
|
2001-11-28 00:13:53 +03:00
|
|
|
const nsAFlatCString&
|
1999-07-18 04:32:32 +04:00
|
|
|
nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
|
|
|
|
{
|
2000-08-22 10:57:32 +04:00
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
2007-07-22 21:58:37 +04:00
|
|
|
NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range");
|
2000-08-22 10:57:32 +04:00
|
|
|
if (gKeywordTable) {
|
2012-08-22 19:56:38 +04:00
|
|
|
return gKeywordTable->GetStringValue(int32_t(aKeyword));
|
2000-08-22 10:57:32 +04:00
|
|
|
} else {
|
2001-11-28 00:13:53 +03:00
|
|
|
static nsDependentCString kNullStr("");
|
2000-08-22 10:57:32 +04:00
|
|
|
return kNullStr;
|
1999-07-18 04:32:32 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|