2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-13 20:24:54 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* keywords used within CSS property values */
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCSSKeywords.h"
|
1999-07-18 00:32:32 +00:00
|
|
|
#include "nsString.h"
|
2000-08-22 06:57:32 +00:00
|
|
|
#include "nsStaticNameTable.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2007-03-15 16:16:20 +00:00
|
|
|
#include "nsStyleConsts.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2003-02-26 03:34:15 +00:00
|
|
|
// required to make the symbol external, so that TestCSSPropertyLookup.cpp can link with it
|
|
|
|
extern const char* const kCSSRawKeywords[];
|
|
|
|
|
1999-07-18 00:32:32 +00:00
|
|
|
// define an array of all CSS keywords
|
2000-08-22 06:57:32 +00:00
|
|
|
#define CSS_KEY(_name,_id) #_name,
|
2003-02-26 00:52:07 +00:00
|
|
|
const char* const kCSSRawKeywords[] = {
|
1999-07-18 00:32:32 +00:00
|
|
|
#include "nsCSSKeywordList.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
1999-07-18 00:32:32 +00:00
|
|
|
#undef CSS_KEY
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static int32_t gTableRefCount;
|
2000-08-22 06:57:32 +00:00
|
|
|
static nsStaticCaseInsensitiveNameTable* gKeywordTable;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-18 00:32:32 +00:00
|
|
|
void
|
|
|
|
nsCSSKeywords::AddRefTable(void)
|
|
|
|
{
|
|
|
|
if (0 == gTableRefCount++) {
|
2000-08-22 06:57:32 +00:00
|
|
|
NS_ASSERTION(!gKeywordTable, "pre existing array!");
|
|
|
|
gKeywordTable = new nsStaticCaseInsensitiveNameTable();
|
|
|
|
if (gKeywordTable) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
// let's verify the table...
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = 0;
|
2003-10-30 01:59:15 +00:00
|
|
|
for (; index < eCSSKeyword_COUNT && kCSSRawKeywords[index]; ++index) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString temp1(kCSSRawKeywords[index]);
|
|
|
|
nsAutoCString temp2(kCSSRawKeywords[index]);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToLowerCase(temp1);
|
2000-08-22 06:57:32 +00:00
|
|
|
NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
|
|
|
|
NS_ASSERTION(-1 == temp1.FindChar('_'), "underscore char in table");
|
1999-07-18 00:32:32 +00:00
|
|
|
}
|
2003-10-30 01:59:15 +00:00
|
|
|
NS_ASSERTION(index == eCSSKeyword_COUNT, "kCSSRawKeywords and eCSSKeyword_COUNT are out of sync");
|
1999-07-18 00:32:32 +00:00
|
|
|
}
|
2000-08-22 06:57:32 +00:00
|
|
|
#endif
|
|
|
|
gKeywordTable->Init(kCSSRawKeywords, eCSSKeyword_COUNT);
|
|
|
|
}
|
1999-07-18 00:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSKeywords::ReleaseTable(void)
|
|
|
|
{
|
|
|
|
if (0 == --gTableRefCount) {
|
2000-08-22 06:57:32 +00:00
|
|
|
if (gKeywordTable) {
|
|
|
|
delete gKeywordTable;
|
2012-07-30 14:20:58 +00:00
|
|
|
gKeywordTable = nullptr;
|
1999-07-18 00:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-18 00:32:32 +00:00
|
|
|
nsCSSKeyword
|
2001-11-27 21:13:53 +00:00
|
|
|
nsCSSKeywords::LookupKeyword(const nsACString& aKeyword)
|
1999-07-18 00:32:32 +00:00
|
|
|
{
|
2000-08-22 06:57:32 +00:00
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
|
|
|
if (gKeywordTable) {
|
|
|
|
return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
|
|
|
|
}
|
1999-07-18 00:32:32 +00:00
|
|
|
return eCSSKeyword_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2000-03-12 10:07:57 +00:00
|
|
|
nsCSSKeyword
|
2001-11-27 21:13:53 +00:00
|
|
|
nsCSSKeywords::LookupKeyword(const nsAString& aKeyword)
|
2000-08-22 06:57:32 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
|
|
|
if (gKeywordTable) {
|
|
|
|
return nsCSSKeyword(gKeywordTable->Lookup(aKeyword));
|
|
|
|
}
|
|
|
|
return eCSSKeyword_UNKNOWN;
|
2000-03-12 10:07:57 +00:00
|
|
|
}
|
|
|
|
|
2001-11-27 21:13:53 +00:00
|
|
|
const nsAFlatCString&
|
1999-07-18 00:32:32 +00:00
|
|
|
nsCSSKeywords::GetStringValue(nsCSSKeyword aKeyword)
|
|
|
|
{
|
2000-08-22 06:57:32 +00:00
|
|
|
NS_ASSERTION(gKeywordTable, "no lookup table, needs addref");
|
2007-07-22 17:58:37 +00:00
|
|
|
NS_ASSERTION(0 <= aKeyword && aKeyword < eCSSKeyword_COUNT, "out of range");
|
2000-08-22 06:57:32 +00:00
|
|
|
if (gKeywordTable) {
|
2012-08-22 15:56:38 +00:00
|
|
|
return gKeywordTable->GetStringValue(int32_t(aKeyword));
|
2000-08-22 06:57:32 +00:00
|
|
|
} else {
|
2001-11-27 21:13:53 +00:00
|
|
|
static nsDependentCString kNullStr("");
|
2000-08-22 06:57:32 +00:00
|
|
|
return kNullStr;
|
1999-07-18 00:32:32 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|