pjs/layout/style/nsCSSParser.cpp

3385 строки
107 KiB
C++
Исходник Обычный вид История

1998-04-14 00:24:54 +04:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsICSSParser.h"
#include "nsCSSProps.h"
#include "nsCSSKeywords.h"
#include "nsCSSScanner.h"
#include "nsICSSStyleRule.h"
#include "nsIUnicharInputStream.h"
#include "nsIStyleSet.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSDeclaration.h"
#include "nsStyleConsts.h"
#include "nsIURL.h"
#include "nsString.h"
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsColor.h"
#include "nsStyleConsts.h"
1998-12-11 05:50:43 +03:00
#include "nsCSSAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsINameSpace.h"
1998-04-14 00:24:54 +04:00
// XXX TODO:
// - rework aErrorCode stuff: switch over to nsresult
// - bug: "color: red {fish};" emits a property for color instead of zapping it
1998-04-14 00:24:54 +04:00
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID);
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
1998-10-27 02:22:40 +03:00
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
static NS_DEFINE_IID(kCSSContentSID, NS_CSS_CONTENT_SID);
static NS_DEFINE_IID(kCSSTextSID, NS_CSS_TEXT_SID);
#define KEYWORD_BUFFER_SIZE 50 // big enough for any keyword
1998-04-14 00:24:54 +04:00
// e.g. "P B, H1 B { ... }" has a selector list with two elements,
// each of which has two selectors.
struct SelectorList {
1998-12-11 05:50:43 +03:00
SelectorList(void);
~SelectorList(void);
1998-04-14 00:24:54 +04:00
1998-12-11 05:50:43 +03:00
void AddSelector(const nsCSSSelector& aSelector);
1998-04-14 00:24:54 +04:00
#ifdef NS_DEBUG
1998-12-11 05:50:43 +03:00
void Dump(void);
1998-04-14 00:24:54 +04:00
#endif
1998-12-11 05:50:43 +03:00
nsCSSSelector* mSelectors;
SelectorList* mNext;
1998-04-14 00:24:54 +04:00
};
1998-12-11 05:50:43 +03:00
SelectorList::SelectorList(void)
: mSelectors(nsnull),
mNext(nsnull)
1998-04-14 00:24:54 +04:00
{
}
SelectorList::~SelectorList()
{
1998-12-11 05:50:43 +03:00
nsCSSSelector* sel = mSelectors;
while (nsnull != sel) {
nsCSSSelector* dead = sel;
sel = sel->mNext;
delete dead;
}
if (nsnull != mNext) {
delete mNext;
1998-04-14 00:24:54 +04:00
}
}
1998-12-11 05:50:43 +03:00
void SelectorList::AddSelector(const nsCSSSelector& aSelector)
{ // prepend to list
nsCSSSelector* newSel = new nsCSSSelector(aSelector);
newSel->mNext = mSelectors;
mSelectors = newSel;
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
1998-04-14 00:24:54 +04:00
#ifdef NS_DEBUG
void SelectorList::Dump()
{
}
#endif
//----------------------------------------------------------------------
// Your basic top-down recursive descent style parser
class CSSParserImpl : public nsICSSParser {
public:
CSSParserImpl();
CSSParserImpl(nsICSSStyleSheet* aSheet);
~CSSParserImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD GetInfoMask(PRUint32& aResult);
1998-11-26 04:34:53 +03:00
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
1998-04-14 00:24:54 +04:00
1998-12-21 08:58:58 +03:00
NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive);
1998-12-11 05:50:43 +03:00
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
1998-11-26 04:34:53 +03:00
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult);
1998-04-14 00:24:54 +04:00
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
nsIURL* aBaseURL,
nsIStyleRule*& aResult);
1998-09-30 03:50:09 +04:00
NS_IMETHOD ParseAndAppendDeclaration(const nsString& aBuffer,
nsIURL* aBaseURL,
nsICSSDeclaration* aDeclaration,
PRInt32* aHint);
1998-04-14 00:24:54 +04:00
protected:
1998-10-27 02:22:40 +03:00
PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS);
PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS);
1998-04-14 00:24:54 +04:00
void UngetToken();
1998-10-27 02:22:40 +03:00
PRBool ExpectSymbol(PRInt32& aErrorCode, char aSymbol, PRBool aSkipWS);
PRBool ExpectEndProperty(PRInt32& aErrorCode, PRBool aSkipWS);
nsString* NextIdent(PRInt32& aErrorCode);
void SkipUntil(PRInt32& aErrorCode, PRUnichar aStopSymbol);
void SkipRuleSet(PRInt32& aErrorCode);
PRBool SkipDeclaration(PRInt32& aErrorCode, PRBool aCheckForBraces);
PRBool ParseRuleSet(PRInt32& aErrorCode);
PRBool ParseAtRule(PRInt32& aErrorCode);
PRBool ParseImportRule(PRInt32& aErrorCode);
1998-11-26 08:16:22 +03:00
PRBool GatherMedia(PRInt32& aErrorCode, nsString& aMedia);
PRBool ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia);
1998-10-27 02:22:40 +03:00
1998-12-11 05:50:43 +03:00
PRBool ParseSelectorList(PRInt32& aErrorCode, SelectorList*& aListHead);
PRBool ParseSelectorGroup(PRInt32& aErrorCode, SelectorList*& aListHead);
PRBool ParseSelector(PRInt32& aErrorCode, nsCSSSelector& aSelectorResult);
1998-10-27 02:22:40 +03:00
nsICSSDeclaration* ParseDeclarationBlock(PRInt32& aErrorCode,
PRBool aCheckForBraces);
1998-10-27 02:22:40 +03:00
PRBool ParseDeclaration(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration,
1998-09-30 03:50:09 +04:00
PRBool aCheckForBraces,
1998-10-27 02:22:40 +03:00
PRInt32& aChangeHint);
PRBool ParseProperty(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID, PRInt32& aChangeHint);
PRBool ParseProperty(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID);
1998-04-14 00:24:54 +04:00
// Property specific parsing routines
1998-10-27 02:22:40 +03:00
PRBool ParseAzimuth(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBackground(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBackgroundFilter(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseForegroundFilter(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBackgroundPosition(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBorder(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBorderColor(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBorderSpacing(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBorderSide(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
const PRInt32 aPropIDs[], PRInt32 aWhichSide);
PRBool ParseBorderStyle(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseBorderWidth(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseClip(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseContent(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseCounterData(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID);
PRBool ParseCue(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseCursor(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseFont(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseFamily(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration, PRInt32 aPropID);
PRBool ParseListStyle(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseMargin(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseMarks(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseOutline(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParsePadding(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParsePause(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParsePlayDuring(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseQuotes(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseSize(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseTextDecoration(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
PRBool ParseTextShadow(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration);
1998-04-14 00:24:54 +04:00
// Reused utility parsing routines
1998-10-27 02:22:40 +03:00
PRBool ParseBoxProperties(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
const PRInt32 aPropIDs[]);
PRInt32 ParseChoice(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
const PRInt32 aPropIDs[], PRInt32 aNumIDs);
PRBool ParseColor(PRInt32& aErrorCode, nsCSSValue& aValue);
PRBool ParseColorComponent(PRInt32& aErrorCode, PRUint8& aComponent,
1998-04-14 00:24:54 +04:00
char aStop);
1998-10-27 02:22:40 +03:00
PRBool ParseEnum(PRInt32& aErrorCode, nsCSSValue& aValue, const PRInt32 aKeywordTable[]);
PRInt32 SearchKeywordTable(PRInt32 aID, const PRInt32 aTable[]);
PRBool ParseVariant(PRInt32& aErrorCode, nsCSSValue& aValue,
PRInt32 aVariantMask,
const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant);
PRBool ParseVariant(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID, PRInt32 aVariantMask,
const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant);
PRBool ParsePositiveVariant(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID, PRInt32 aVariantMask,
const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant);
1998-10-27 02:22:40 +03:00
PRBool ParseCounter(PRInt32& aErrorCode, nsCSSValue& aValue);
PRBool ParseAttr(PRInt32& aErrorCode, nsCSSValue& aValue);
PRBool ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue);
PRBool TranslateDimension(nsCSSValue& aValue, PRInt32 aVariantMask,
float aNumber, const nsString& aUnit,
PRInt32& aParsedVariant);
1998-04-14 00:24:54 +04:00
// Current token. The value is valid after calling GetToken
nsCSSToken mToken;
// After an UngetToken is done this flag is true. The next call to
// GetToken clears the flag.
PRBool mHavePushBack;
nsCSSScanner* mScanner;
nsIURL* mURL;
nsICSSStyleSheet* mSheet;
PRBool mInHead;
PRBool mNavQuirkMode;
1998-12-21 08:58:58 +03:00
PRBool mCaseSensitive;
1998-04-14 00:24:54 +04:00
};
NS_HTML nsresult
NS_NewCSSParser(nsICSSParser** aInstancePtrResult)
{
CSSParserImpl *it = new CSSParserImpl();
if (it == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kICSSParserIID, (void **) aInstancePtrResult);
}
CSSParserImpl::CSSParserImpl()
{
NS_INIT_REFCNT();
1998-12-11 05:50:43 +03:00
nsCSSAtoms::AddrefAtoms();
1998-04-14 00:24:54 +04:00
mScanner = nsnull;
mSheet = nsnull;
mHavePushBack = PR_FALSE;
mNavQuirkMode = PR_TRUE;
1998-12-21 08:58:58 +03:00
mCaseSensitive = PR_FALSE;
1998-04-14 00:24:54 +04:00
}
CSSParserImpl::CSSParserImpl(nsICSSStyleSheet* aSheet)
{
NS_INIT_REFCNT();
1998-12-11 05:50:43 +03:00
nsCSSAtoms::AddrefAtoms();
1998-04-14 00:24:54 +04:00
mScanner = nsnull;
mSheet = aSheet; NS_ADDREF(aSheet);
1998-04-14 00:24:54 +04:00
mHavePushBack = PR_FALSE;
mNavQuirkMode = PR_TRUE;
1998-12-21 08:58:58 +03:00
mCaseSensitive = PR_FALSE;
1998-04-14 00:24:54 +04:00
}
NS_IMPL_ISUPPORTS(CSSParserImpl,kICSSParserIID)
CSSParserImpl::~CSSParserImpl()
{
NS_IF_RELEASE(mSheet);
1998-12-11 05:50:43 +03:00
nsCSSAtoms::ReleaseAtoms();
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
NS_IMETHODIMP
CSSParserImpl::GetInfoMask(PRUint32& aResult)
1998-04-14 00:24:54 +04:00
{
aResult = NS_CSS_GETINFO_CSS1 | NS_CSS_GETINFO_CSSP;
return NS_OK;
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
NS_IMETHODIMP
1998-11-26 04:34:53 +03:00
CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
1998-04-14 00:24:54 +04:00
{
NS_PRECONDITION(nsnull != aSheet, "null ptr");
if (nsnull == aSheet) {
return NS_ERROR_NULL_POINTER;
}
1998-11-26 04:34:53 +03:00
if (aSheet != mSheet) {
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = aSheet;
NS_ADDREF(mSheet);
1998-04-14 00:24:54 +04:00
}
return NS_OK;
}
1998-12-11 05:50:43 +03:00
NS_IMETHODIMP
1998-12-21 08:58:58 +03:00
CSSParserImpl::SetCaseSensitive(PRBool aCaseSensitive)
1998-12-11 05:50:43 +03:00
{
1998-12-21 08:58:58 +03:00
mCaseSensitive = aCaseSensitive;
1998-12-11 05:50:43 +03:00
return NS_OK;
}
NS_IMETHODIMP
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
1998-10-27 02:22:40 +03:00
nsIURL* aInputURL,
1998-11-26 04:34:53 +03:00
nsICSSStyleSheet*& aResult)
1998-04-14 00:24:54 +04:00
{
NS_ASSERTION(nsnull != aInputURL, "need base URL");
1998-04-14 00:24:54 +04:00
if (nsnull == mSheet) {
NS_NewCSSStyleSheet(&mSheet, aInputURL);
}
PRInt32 errorCode = NS_OK;
1998-04-14 00:24:54 +04:00
mScanner = new nsCSSScanner();
mScanner->Init(aInput);
mURL = aInputURL;
NS_IF_ADDREF(aInputURL);
1998-04-14 00:24:54 +04:00
mInHead = PR_TRUE;
nsCSSToken* tk = &mToken;
for (;;) {
// Get next non-whitespace token
1998-10-27 02:22:40 +03:00
if (!GetToken(errorCode, PR_TRUE)) {
1998-04-14 00:24:54 +04:00
break;
}
if (eCSSToken_AtKeyword == tk->mType) {
1998-10-27 02:22:40 +03:00
ParseAtRule(errorCode);
1998-04-14 00:24:54 +04:00
continue;
} else if (eCSSToken_Symbol == tk->mType) {
// Discard dangling semicolons. This is not part of the CSS1
// forward compatible parsing spec, but it makes alot of sense.
if (';' == tk->mSymbol) {
continue;
}
}
mInHead = PR_FALSE;
UngetToken();
1998-10-27 02:22:40 +03:00
ParseRuleSet(errorCode);
1998-04-14 00:24:54 +04:00
}
delete mScanner;
mScanner = nsnull;
NS_IF_RELEASE(mURL);
1998-11-26 04:34:53 +03:00
aResult = mSheet;
NS_ADDREF(aResult);
return NS_OK;
}
1998-12-11 05:50:43 +03:00
NS_IMETHODIMP
CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
nsIURL* aBaseURL,
nsIStyleRule*& aResult)
{
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
nsString* str = new nsString(aDeclaration);
if (nsnull == str) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsIUnicharInputStream* input = nsnull;
nsresult rv = NS_NewStringUnicharInputStream(&input, str);
if (NS_OK != rv) {
return rv;
}
mScanner = new nsCSSScanner();
mScanner->Init(input);
NS_RELEASE(input);
mURL = aBaseURL;
NS_IF_ADDREF(mURL);
mInHead = PR_FALSE;
PRInt32 errorCode = NS_OK;
1998-10-27 02:22:40 +03:00
nsICSSDeclaration* declaration = ParseDeclarationBlock(errorCode, PR_FALSE);
if (nsnull != declaration) {
// Create a style rule for the delcaration
nsICSSStyleRule* rule = nsnull;
NS_NewCSSStyleRule(&rule, nsCSSSelector());
rule->SetDeclaration(declaration);
aResult = rule;
NS_RELEASE(declaration);
}
else {
aResult = nsnull;
}
delete mScanner;
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK;
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
NS_IMETHODIMP
1998-09-30 03:50:09 +04:00
CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
nsIURL* aBaseURL,
nsICSSDeclaration* aDeclaration,
PRInt32* aHint)
{
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
nsString* str = new nsString(aBuffer);
if (nsnull == str) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsIUnicharInputStream* input = nsnull;
nsresult rv = NS_NewStringUnicharInputStream(&input, str);
if (NS_OK != rv) {
return rv;
}
mScanner = new nsCSSScanner();
mScanner->Init(input);
NS_RELEASE(input);
mURL = aBaseURL;
NS_IF_ADDREF(mURL);
mInHead = PR_FALSE;
PRInt32 errorCode = NS_OK;
1998-10-27 02:22:40 +03:00
PRInt32 hint = NS_STYLE_HINT_UNKNOWN;
ParseDeclaration(errorCode, aDeclaration, PR_FALSE, hint);
1998-10-28 05:04:06 +03:00
if (nsnull != aHint) {
1998-10-27 02:22:40 +03:00
*aHint = hint;
}
delete mScanner;
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK;
}
1998-04-14 00:24:54 +04:00
//----------------------------------------------------------------------
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::GetToken(PRInt32& aErrorCode, PRBool aSkipWS)
1998-04-14 00:24:54 +04:00
{
for (;;) {
if (!mHavePushBack) {
1998-10-27 02:22:40 +03:00
if (!mScanner->Next(aErrorCode, mToken)) {
break;
}
}
mHavePushBack = PR_FALSE;
if (aSkipWS && (eCSSToken_WhiteSpace == mToken.mType)) {
continue;
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS)
{
for (;;) {
if (! mHavePushBack) {
if (! mScanner->NextURL(aErrorCode, mToken)) {
1998-04-14 00:24:54 +04:00
break;
}
}
mHavePushBack = PR_FALSE;
if (aSkipWS && (eCSSToken_WhiteSpace == mToken.mType)) {
continue;
}
return PR_TRUE;
}
return PR_FALSE;
}
void CSSParserImpl::UngetToken()
{
NS_PRECONDITION(mHavePushBack == PR_FALSE, "double pushback");
mHavePushBack = PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ExpectSymbol(PRInt32& aErrorCode,
1998-04-14 00:24:54 +04:00
char aSymbol,
PRBool aSkipWS)
{
if (!GetToken(aErrorCode, aSkipWS)) {
return PR_FALSE;
}
nsCSSToken* tk = &mToken;
if ((eCSSToken_Symbol == tk->mType) && (aSymbol == tk->mSymbol)) {
return PR_TRUE;
}
UngetToken();
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ExpectEndProperty(PRInt32& aErrorCode, PRBool aSkipWS)
{
if (!GetToken(aErrorCode, aSkipWS)) {
return PR_FALSE;
}
if ((eCSSToken_Symbol == mToken.mType) &&
((';' == mToken.mSymbol) || ('!' == mToken.mSymbol))) {
UngetToken();
return PR_TRUE;
}
UngetToken();
return PR_FALSE;
}
nsString* CSSParserImpl::NextIdent(PRInt32& aErrorCode)
1998-04-14 00:24:54 +04:00
{
if (!GetToken(aErrorCode, PR_TRUE)) {
return nsnull;
}
if (eCSSToken_Ident != mToken.mType) {
UngetToken();
return nsnull;
}
return &mToken.mIdent;
}
// XXX @media type {, types } '{' rules '}'
// XXX @font-face
// XXX @page { :left | :right } '{' declarations '}'
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseAtRule(PRInt32& aErrorCode)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
if (mInHead && tk->mIdent.EqualsIgnoreCase("import")) {
ParseImportRule(aErrorCode);
return PR_TRUE;
}
// Skip over unsupported at rule
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
if (eCSSToken_Symbol == tk->mType) {
PRUnichar symbol = tk->mSymbol;
if (symbol == ';') {
break;
}
if (symbol == '{') {
SkipUntil(aErrorCode, '}');
break;
} else if (symbol == '(') {
SkipUntil(aErrorCode, ')');
} else if (symbol == '[') {
SkipUntil(aErrorCode, ']');
}
}
}
mInHead = PR_FALSE;
return PR_TRUE;
}
1998-11-26 08:16:22 +03:00
PRBool CSSParserImpl::GatherMedia(PRInt32& aErrorCode, nsString& aMedia)
{ // media is acse sensative
1998-11-26 08:16:22 +03:00
PRBool first = PR_TRUE;
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
break;
}
if (eCSSToken_Symbol == mToken.mType) {
PRUnichar symbol = mToken.mSymbol;
if (';' == symbol) {
UngetToken();
return PR_TRUE;
} else if (',' != symbol) {
UngetToken();
return PR_FALSE;
}
}
else if (eCSSToken_Ident == mToken.mType) {
if (! first) {
aMedia.Append(',');
}
aMedia.Append(mToken.mIdent);
first = PR_FALSE;
}
else {
break;
}
}
aMedia.Truncate();
return PR_FALSE;
}
// Parse a CSS1 import rule: "@import STRING | URL [medium [, mdeium]]"
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseImportRule(PRInt32& aErrorCode)
1998-04-14 00:24:54 +04:00
{
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
1998-11-26 08:16:22 +03:00
nsAutoString url;
nsAutoString media;
1998-10-27 02:22:40 +03:00
if (eCSSToken_String == mToken.mType) {
1998-11-26 08:16:22 +03:00
url = mToken.mIdent;
if (GatherMedia(aErrorCode, media)) {
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
ProcessImport(aErrorCode, url, media);
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if ((eCSSToken_Symbol != mToken.mType) || (';' != mToken.mSymbol)) {
1998-04-14 00:24:54 +04:00
SkipUntil(aErrorCode, ';');
}
}
1998-10-27 02:22:40 +03:00
else if (eCSSToken_Function == mToken.mType) {
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
if (GetURLToken(aErrorCode, PR_TRUE)) {
if ((eCSSToken_String == mToken.mType) || (eCSSToken_URL == mToken.mType)) {
1998-11-26 08:16:22 +03:00
url = mToken.mIdent;
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
if (GatherMedia(aErrorCode, media)) {
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
ProcessImport(aErrorCode, url, media);
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
}
}
}
}
1998-11-26 08:16:22 +03:00
if ((eCSSToken_Symbol != mToken.mType) || (';' != mToken.mSymbol)) {
SkipUntil(aErrorCode, ';');
}
1998-10-27 02:22:40 +03:00
}
1998-04-14 00:24:54 +04:00
mInHead = PR_FALSE;
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
1998-12-02 03:36:37 +03:00
typedef PRBool (*nsStringEnumFunc)(const nsString& aSubString, void *aData);
const PRUnichar kNullCh = PRUnichar('\0');
const PRUnichar kSingleQuote = PRUnichar('\'');
const PRUnichar kDoubleQuote = PRUnichar('\"');
const PRUnichar kComma = PRUnichar(',');
const PRUnichar kHyphenCh = PRUnichar('-');
1998-12-02 03:36:37 +03:00
static PRBool EnumerateString(const nsString& aStringList, nsStringEnumFunc aFunc, void* aData)
{
PRBool running = PR_TRUE;
nsAutoString stringList(aStringList); // copy to work buffer
nsAutoString subStr;
stringList.Append(kNullCh); // put an extra null at the end
PRUnichar* start = (PRUnichar*)stringList;
PRUnichar* end = start;
while (running && (kNullCh != *start)) {
PRBool quoted = PR_FALSE;
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
start++;
}
if ((kSingleQuote == *start) || (kDoubleQuote == *start)) { // quoted string
PRUnichar quote = *start++;
quoted = PR_TRUE;
end = start;
while (kNullCh != *end) {
if (quote == *end) { // found closing quote
*end++ = kNullCh; // end string here
while ((kNullCh != *end) && (kComma != *end)) { // keep going until comma
end++;
}
break;
}
end++;
}
}
else { // non-quoted string or ended
end = start;
while ((kNullCh != *end) && (kComma != *end)) { // look for comma
end++;
}
*end = kNullCh; // end string here
}
// truncate at first non letter, digit or hyphen
PRUnichar* test = start;
while (test <= end) {
if ((PR_FALSE == nsString::IsAlpha(*test)) &&
(PR_FALSE == nsString::IsDigit(*test)) && (kHyphenCh != *test)) {
*test = kNullCh;
break;
}
test++;
}
1998-12-02 03:36:37 +03:00
subStr = start;
if (PR_FALSE == quoted) {
subStr.CompressWhitespace(PR_FALSE, PR_TRUE);
}
if (0 < subStr.Length()) {
running = (*aFunc)(subStr, aData);
}
start = ++end;
}
return running;
}
static PRBool MediumEnumFunc(const nsString& aSubString, void *aData)
{
nsIAtom* medium = NS_NewAtom(aSubString);
((nsICSSStyleSheet*)aData)->AppendMedium(medium);
return PR_TRUE;
}
1998-11-26 08:16:22 +03:00
PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia)
1998-04-14 00:24:54 +04:00
{
1998-11-26 08:16:22 +03:00
PRBool result = PR_FALSE;
1998-04-14 00:24:54 +04:00
// XXX probably need a way to encode unicode junk for the part of
// the url that follows a "?"
char* cp = aURLSpec.ToNewCString();
nsIURL* url;
aErrorCode = NS_NewURL(&url, cp, mURL);
1998-11-26 08:16:22 +03:00
delete [] cp;
if (NS_FAILED(aErrorCode)) {
1998-04-14 00:24:54 +04:00
// import url is bad
// XXX log this somewhere for easier web page debugging
1998-11-26 08:16:22 +03:00
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
if (PR_FALSE == mSheet->ContainsStyleSheet(url)) { // don't allow circular references
nsIInputStream* in;
nsresult rv = NS_OpenURL(url, &in);
if (rv != NS_OK) {
1998-04-14 00:24:54 +04:00
// failure to make connection
// XXX log this somewhere for easier web page debugging
}
else {
nsIUnicharInputStream* uin;
1998-11-26 08:16:22 +03:00
aErrorCode = NS_NewConverterStream(&uin, nsnull, in);
if (NS_FAILED(aErrorCode)) {
1998-04-14 00:24:54 +04:00
// XXX no iso-latin-1 converter? out of memory?
NS_RELEASE(in);
}
else {
NS_RELEASE(in);
// Create a new parse to parse the import.
1998-11-26 08:16:22 +03:00
nsICSSParser* parser;
aErrorCode = NS_NewCSSParser(&parser);
if (NS_SUCCEEDED(aErrorCode)) {
nsICSSStyleSheet* childSheet = nsnull;
aErrorCode = parser->Parse(uin, url, childSheet);
NS_RELEASE(parser);
if (NS_SUCCEEDED(aErrorCode) && (nsnull != childSheet)) {
1998-12-02 03:36:37 +03:00
if (0 < aMedia.Length()) {
EnumerateString(aMedia, MediumEnumFunc, childSheet);
}
1998-11-26 08:16:22 +03:00
mSheet->AppendStyleSheet(childSheet);
result = PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-11-26 08:16:22 +03:00
NS_IF_RELEASE(childSheet);
1998-04-14 00:24:54 +04:00
}
NS_RELEASE(uin);
}
}
}
NS_RELEASE(url);
1998-11-26 08:16:22 +03:00
return result;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
void CSSParserImpl::SkipUntil(PRInt32& aErrorCode, PRUnichar aStopSymbol)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
break;
}
if (eCSSToken_Symbol == tk->mType) {
PRUnichar symbol = tk->mSymbol;
if (symbol == aStopSymbol) {
break;
} else if ('{' == symbol) {
SkipUntil(aErrorCode, '}');
} else if ('[' == symbol) {
SkipUntil(aErrorCode, ']');
} else if ('(' == symbol) {
SkipUntil(aErrorCode, ')');
}
}
}
}
PRBool
1998-10-27 02:22:40 +03:00
CSSParserImpl::SkipDeclaration(PRInt32& aErrorCode, PRBool aCheckForBraces)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
if (eCSSToken_Symbol == tk->mType) {
PRUnichar symbol = tk->mSymbol;
if (';' == symbol) {
break;
}
if (aCheckForBraces) {
if ('}' == symbol) {
UngetToken();
break;
}
1998-04-14 00:24:54 +04:00
}
if ('{' == symbol) {
SkipUntil(aErrorCode, '}');
} else if ('(' == symbol) {
SkipUntil(aErrorCode, ')');
} else if ('[' == symbol) {
SkipUntil(aErrorCode, ']');
}
}
}
return PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
void CSSParserImpl::SkipRuleSet(PRInt32& aErrorCode)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
break;
}
if (eCSSToken_Symbol == tk->mType) {
PRUnichar symbol = tk->mSymbol;
if ('{' == symbol) {
SkipUntil(aErrorCode, '}');
break;
}
if ('(' == symbol) {
SkipUntil(aErrorCode, ')');
} else if ('[' == symbol) {
SkipUntil(aErrorCode, ']');
}
}
}
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
// First get the list of selectors for the rule
1998-12-11 05:50:43 +03:00
SelectorList* slist = nsnull;
if (! ParseSelectorList(aErrorCode, slist)) {
1998-04-14 00:24:54 +04:00
SkipRuleSet(aErrorCode);
return PR_FALSE;
}
1998-12-11 05:50:43 +03:00
NS_ASSERTION(nsnull != slist, "null selector list");
1998-04-14 00:24:54 +04:00
// Next parse the declaration block
nsICSSDeclaration* declaration = ParseDeclarationBlock(aErrorCode, PR_TRUE);
1998-04-14 00:24:54 +04:00
if (nsnull == declaration) {
// XXX skip something here
1998-12-11 05:50:43 +03:00
delete slist;
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
#if 0
slist->Dump();
fputs("{\n", stdout);
declaration->List();
fputs("}\n", stdout);
#endif
// Translate the selector list and declaration block into style data
SelectorList* list = slist;
while (nsnull != list) {
1998-12-11 05:50:43 +03:00
PRInt32 weight = list->mSelectors->CalcWeight();
nsICSSStyleRule* rule = nsnull;
NS_NewCSSStyleRule(&rule, *(list->mSelectors));
1998-05-19 01:07:54 +04:00
if (nsnull != rule) {
1998-12-11 05:50:43 +03:00
if (nsnull != list->mSelectors->mNext) { // hand off other selectors to new rule
nsCSSSelector* ruleFirst = rule->FirstSelector();
ruleFirst->mNext = list->mSelectors->mNext;
list->mSelectors->mNext = nsnull;
1998-04-14 00:24:54 +04:00
}
rule->SetDeclaration(declaration);
rule->SetWeight(weight);
// rule->List();
mSheet->AppendStyleRule(rule);
NS_RELEASE(rule);
}
list = list->mNext;
}
// Release temporary storage
1998-12-11 05:50:43 +03:00
delete slist;
1998-04-14 00:24:54 +04:00
NS_RELEASE(declaration);
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseSelectorList(PRInt32& aErrorCode,
1998-12-11 05:50:43 +03:00
SelectorList*& aListHead)
1998-04-14 00:24:54 +04:00
{
1998-12-11 05:50:43 +03:00
SelectorList* list = nsnull;
if (! ParseSelectorGroup(aErrorCode, list)) {
1998-04-14 00:24:54 +04:00
// must have at least one selector group
1998-12-11 05:50:43 +03:00
aListHead = nsnull;
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
1998-12-11 05:50:43 +03:00
NS_ASSERTION(nsnull != list, "no selector list");
aListHead = list;
1998-04-14 00:24:54 +04:00
// After that there must either be a "," or a "{"
nsCSSToken* tk = &mToken;
for (;;) {
1998-12-11 05:50:43 +03:00
if (! GetToken(aErrorCode, PR_TRUE)) {
break;
1998-04-14 00:24:54 +04:00
}
if (eCSSToken_Symbol != tk->mType) {
UngetToken();
1998-12-11 05:50:43 +03:00
break;
1998-04-14 00:24:54 +04:00
}
if (',' == tk->mSymbol) {
1998-12-11 05:50:43 +03:00
SelectorList* newList = nsnull;
1998-04-14 00:24:54 +04:00
// Another selector group must follow
1998-12-11 05:50:43 +03:00
if (! ParseSelectorGroup(aErrorCode, newList)) {
break;
1998-04-14 00:24:54 +04:00
}
// add new list to the end of the selector list
1998-12-11 05:50:43 +03:00
list->mNext = newList;
list = newList;
1998-04-14 00:24:54 +04:00
continue;
} else if ('{' == tk->mSymbol) {
UngetToken();
1998-12-11 05:50:43 +03:00
return PR_TRUE;
1998-04-14 00:24:54 +04:00
} else {
UngetToken();
1998-12-11 05:50:43 +03:00
break;
1998-04-14 00:24:54 +04:00
}
}
1998-12-11 05:50:43 +03:00
delete aListHead;
aListHead = nsnull;
return PR_FALSE;
}
static PRBool IsPseudoClass(const nsIAtom* aAtom)
{
return PRBool((nsCSSAtoms::activePseudo == aAtom) ||
(nsCSSAtoms::firstChildPseudo == aAtom) ||
(nsCSSAtoms::focusPseudo == aAtom) ||
(nsCSSAtoms::hoverPseudo == aAtom) ||
(nsCSSAtoms::langPseudo == aAtom) ||
(nsCSSAtoms::linkPseudo == aAtom) ||
(nsCSSAtoms::outOfDatePseudo == aAtom) ||
(nsCSSAtoms::visitedPseudo == aAtom));
}
static PRBool IsSinglePseudoClass(const nsCSSSelector& aSelector)
{
return PRBool((aSelector.mNameSpace == kNameSpaceID_Unknown) &&
(aSelector.mTag == nsnull) &&
(aSelector.mID == nsnull) &&
(aSelector.mClassList == nsnull) &&
(aSelector.mAttrList == nsnull) &&
(aSelector.mPseudoClassList != nsnull) &&
(aSelector.mPseudoClassList->mNext == nsnull));
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseSelectorGroup(PRInt32& aErrorCode,
1998-12-11 05:50:43 +03:00
SelectorList*& aList)
1998-04-14 00:24:54 +04:00
{
1998-12-11 05:50:43 +03:00
SelectorList* list = nsnull;
1998-04-14 00:24:54 +04:00
for (;;) {
1998-12-11 05:50:43 +03:00
nsCSSSelector selector;
if (! ParseSelector(aErrorCode, selector)) {
1998-04-14 00:24:54 +04:00
break;
}
1998-12-11 05:50:43 +03:00
if (nsnull == list) {
list = new SelectorList();
}
list->AddSelector(selector);
nsCSSSelector* listSel = list->mSelectors;
// XXX parse combinator here
// pull out pseudo elements here
nsAtomList* prevList = nsnull;
nsAtomList* pseudoClassList = listSel->mPseudoClassList;
while (nsnull != pseudoClassList) {
if (! IsPseudoClass(pseudoClassList->mAtom)) {
if (IsSinglePseudoClass(*listSel)) { // convert to pseudo element selector
nsIAtom* pseudoElement = pseudoClassList->mAtom; // steal ref count
pseudoClassList->mAtom = nsnull;
listSel->Reset();
listSel->mTag = pseudoElement;
}
else { // append new pseudo element selector
selector.Reset();
selector.mTag = pseudoClassList->mAtom; // steal ref count
list->AddSelector(selector);
pseudoClassList->mAtom = nsnull;
if (nsnull == prevList) { // delete list entry
listSel->mPseudoClassList = pseudoClassList->mNext;
}
else {
prevList->mNext = pseudoClassList->mNext;
}
pseudoClassList->mNext = nsnull;
delete pseudoClassList;
}
break; // only one pseudo element per selector
}
prevList = pseudoClassList;
pseudoClassList = pseudoClassList->mNext;
}
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
aList = list;
return PRBool(nsnull != aList);
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
#define SEL_MASK_NSPACE 0x01
#define SEL_MASK_ELEM 0x02
#define SEL_MASK_ID 0x04
#define SEL_MASK_CLASS 0x08
#define SEL_MASK_ATTRIB 0x10
#define SEL_MASK_PCLASS 0x20
#define SEL_MASK_PELEM 0x40
1998-05-19 01:07:54 +04:00
1998-04-14 00:24:54 +04:00
/**
1998-12-11 05:50:43 +03:00
* This is the format for selectors:
* operator? [namespace \:]? element_name? [ ID | class | attrib | pseudo ]*
1998-04-14 00:24:54 +04:00
*/
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseSelector(PRInt32& aErrorCode,
1998-12-11 05:50:43 +03:00
nsCSSSelector& aSelector)
1998-04-14 00:24:54 +04:00
{
1998-12-11 05:50:43 +03:00
PRInt32 dataMask = 0;
nsAutoString buffer;
1998-04-14 00:24:54 +04:00
1998-12-11 05:50:43 +03:00
if (! GetToken(aErrorCode, PR_TRUE)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
1998-12-11 05:50:43 +03:00
if ((eCSSToken_Symbol == mToken.mType) && ('*' == mToken.mSymbol)) { // universal element selector
// don't set any tag in the selector
dataMask |= SEL_MASK_ELEM;
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
}
1998-12-11 05:50:43 +03:00
else if (eCSSToken_Ident == mToken.mType) { // element name
PRInt32 colon = mToken.mIdent.Find(':');
if (-1 == colon) { // no namespace
1998-12-21 08:58:58 +03:00
if (mCaseSensitive) {
1998-12-11 05:50:43 +03:00
aSelector.SetTag(mToken.mIdent);
}
else {
mToken.mIdent.ToUpperCase(buffer);
aSelector.SetTag(buffer);
}
}
1998-12-11 05:50:43 +03:00
else { // pull out the namespace
nsAutoString nameSpace;
mToken.mIdent.Left(nameSpace, colon);
mToken.mIdent.Right(buffer, (mToken.mIdent.Length() - (colon + 1)));
1998-12-21 08:58:58 +03:00
if (! mCaseSensitive) {
1998-12-11 05:50:43 +03:00
buffer.ToUpperCase();
}
// XXX lookup namespace, set it
// deal with * namespace (== unknown)
aSelector.SetTag(buffer);
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
dataMask |= SEL_MASK_ELEM;
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
}
1998-12-11 05:50:43 +03:00
for (;;) {
if (eCSSToken_ID == mToken.mType) { // #id
if ((0 == (dataMask & SEL_MASK_ID)) && // only one ID
(0 < mToken.mIdent.Length()) &&
(nsString::IsAlpha(mToken.mIdent.CharAt(0)))) { // verify is legal ID
dataMask |= SEL_MASK_ID;
aSelector.SetID(mToken.mIdent);
}
else {
UngetToken();
return PR_FALSE;
}
1998-05-19 01:07:54 +04:00
}
1998-12-11 05:50:43 +03:00
else if ((eCSSToken_Symbol == mToken.mType) && ('.' == mToken.mSymbol)) { // .class
if (! GetToken(aErrorCode, PR_FALSE)) { // get ident
return PR_FALSE;
}
if (eCSSToken_Ident != mToken.mType) { // malformed selector (XXX what about leading digits?)
UngetToken();
return PR_FALSE;
}
dataMask |= SEL_MASK_CLASS;
1998-12-21 08:58:58 +03:00
if (mCaseSensitive) {
1998-12-11 05:50:43 +03:00
aSelector.AddClass(mToken.mIdent);
}
else {
mToken.mIdent.ToUpperCase(buffer);
aSelector.AddClass(buffer);
}
1998-05-19 01:07:54 +04:00
}
1998-12-11 05:50:43 +03:00
else if ((eCSSToken_Symbol == mToken.mType) && (':' == mToken.mSymbol)) { // :pseudo
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof
return PR_FALSE;
}
if (eCSSToken_Ident != mToken.mType) { // malformed selector
UngetToken();
return PR_FALSE;
}
buffer.Truncate();
buffer.Append(':');
buffer.Append(mToken.mIdent);
buffer.ToUpperCase();
nsIAtom* pseudo = NS_NewAtom(buffer);
if (IsPseudoClass(pseudo)) {
// XXX parse lang pseudo class
dataMask |= SEL_MASK_PCLASS;
aSelector.AddPseudoClass(pseudo);
}
else {
if (0 == (dataMask & SEL_MASK_PELEM)) {
dataMask |= SEL_MASK_PELEM;
aSelector.AddPseudoClass(pseudo); // store it here, it gets pulled later
// ensure selector ends here, must be followed by EOF, space, '{' or ','
if (GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
if ((eCSSToken_WhiteSpace == mToken.mType) ||
((eCSSToken_Symbol == mToken.mType) &&
(('{' == mToken.mSymbol) || (',' == mToken.mSymbol)))) {
UngetToken();
return PR_TRUE;
}
UngetToken();
return PR_FALSE;
}
1998-12-11 05:50:43 +03:00
}
else { // multiple pseudo elements, not legal
UngetToken();
NS_RELEASE(pseudo);
return PR_FALSE;
}
}
NS_RELEASE(pseudo);
1998-05-19 01:07:54 +04:00
}
1998-12-11 05:50:43 +03:00
else if ((eCSSToken_Symbol == mToken.mType) && ('[' == mToken.mSymbol)) { // attribute
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if (eCSSToken_Ident != mToken.mType) { // malformed selector
UngetToken();
return PR_FALSE;
}
1998-12-20 04:15:18 +03:00
nsAutoString attr(mToken.mIdent);
1998-12-21 08:58:58 +03:00
if (! mCaseSensitive) {
1998-12-11 05:50:43 +03:00
attr.ToUpperCase();
}
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if (eCSSToken_Symbol == mToken.mType) {
PRUint8 func;
if (']' == mToken.mSymbol) {
dataMask |= SEL_MASK_ATTRIB;
aSelector.AddAttribute(attr);
func = NS_ATTR_FUNC_SET;
}
else if ('=' == mToken.mSymbol) {
func = NS_ATTR_FUNC_EQUALS;
}
else if ('~' == mToken.mSymbol) {
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if ((eCSSToken_Symbol == mToken.mType) && ('=' == mToken.mSymbol)) {
func = NS_ATTR_FUNC_INCLUDES;
}
else {
UngetToken();
return PR_FALSE;
}
}
else if ('|' == mToken.mSymbol) {
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if ((eCSSToken_Symbol == mToken.mType) && ('=' == mToken.mSymbol)) {
func = NS_ATTR_FUNC_DASHMATCH;
}
else {
UngetToken();
return PR_FALSE;
}
}
else {
UngetToken(); // bad function
return PR_FALSE;
}
if (NS_ATTR_FUNC_SET != func) { // get value
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if ((eCSSToken_Ident == mToken.mType) || (eCSSToken_String == mToken.mType)) {
nsAutoString value(mToken.mIdent);
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
return PR_FALSE;
}
if ((eCSSToken_Symbol == mToken.mType) && (']' == mToken.mSymbol)) {
dataMask |= SEL_MASK_ATTRIB;
1998-12-21 08:58:58 +03:00
if (! mCaseSensitive) {
1998-12-11 05:50:43 +03:00
value.ToUpperCase();
}
1998-12-21 08:58:58 +03:00
aSelector.AddAttribute(attr, func, value, mCaseSensitive);
1998-12-11 05:50:43 +03:00
}
else {
UngetToken();
return PR_FALSE;
}
}
else {
UngetToken();
return PR_FALSE;
}
}
}
else {
UngetToken(); // bad dog, no biscut!
return PR_FALSE;
}
1998-05-19 01:07:54 +04:00
}
1998-12-11 05:50:43 +03:00
else { // not a selector token, we're done
break;
1998-05-19 01:07:54 +04:00
}
1998-12-11 05:50:43 +03:00
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
return PR_TRUE;
1998-05-19 01:07:54 +04:00
}
1998-04-14 00:24:54 +04:00
}
1998-12-11 05:50:43 +03:00
UngetToken();
return PRBool(0 != dataMask);
1998-04-14 00:24:54 +04:00
}
nsICSSDeclaration*
1998-10-27 02:22:40 +03:00
CSSParserImpl::ParseDeclarationBlock(PRInt32& aErrorCode,
PRBool aCheckForBraces)
1998-04-14 00:24:54 +04:00
{
if (aCheckForBraces) {
if (!ExpectSymbol(aErrorCode, '{', PR_TRUE)) {
return nsnull;
}
1998-04-14 00:24:54 +04:00
}
nsICSSDeclaration* declaration = nsnull;
if (NS_OK == NS_NewCSSDeclaration(&declaration)) {
PRInt32 count = 0;
1998-04-14 00:24:54 +04:00
for (;;) {
1998-09-30 03:50:09 +04:00
PRInt32 hint;
1998-10-27 02:22:40 +03:00
if (ParseDeclaration(aErrorCode, declaration, aCheckForBraces, hint)) {
count++; // count declarations
}
else {
if (!SkipDeclaration(aErrorCode, aCheckForBraces)) {
1998-04-14 00:24:54 +04:00
break;
}
if (aCheckForBraces) {
if (ExpectSymbol(aErrorCode, '}', PR_TRUE)) {
break;
}
}
1998-04-14 00:24:54 +04:00
// Since the skipped declaration didn't end the block we parse
// the next declaration.
}
}
if (0 == count) { // didn't get any XXX is this ok with the DOM?
NS_RELEASE(declaration);
}
1998-04-14 00:24:54 +04:00
}
return declaration;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseColor(PRInt32& aErrorCode, nsCSSValue& aValue)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
char cbuf[KEYWORD_BUFFER_SIZE];
1998-04-14 00:24:54 +04:00
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
nsCSSToken* tk = &mToken;
1998-10-27 02:22:40 +03:00
nscolor rgba;
1998-04-14 00:24:54 +04:00
switch (tk->mType) {
1998-10-27 02:22:40 +03:00
case eCSSToken_ID:
// #xxyyzz
tk->mIdent.ToCString(cbuf, sizeof(cbuf));
if (NS_HexToRGB(cbuf, &rgba)) {
aValue.SetColorValue(rgba);
return PR_TRUE;
}
break;
1998-04-14 00:24:54 +04:00
1998-10-27 02:22:40 +03:00
case eCSSToken_Ident:
1998-04-14 00:24:54 +04:00
tk->mIdent.ToCString(cbuf, sizeof(cbuf));
1998-10-27 02:22:40 +03:00
if (NS_ColorNameToRGB(cbuf, &rgba)) {
aValue.SetStringValue(tk->mIdent, eCSSUnit_String);
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
break;
case eCSSToken_Function:
1998-04-14 00:24:54 +04:00
// rgb ( component , component , component )
PRUint8 r, g, b;
1998-10-27 02:22:40 +03:00
if (ExpectSymbol(aErrorCode, '(', PR_FALSE) &&
ParseColorComponent(aErrorCode, r, ',') &&
ParseColorComponent(aErrorCode, g, ',') &&
ParseColorComponent(aErrorCode, b, ')')) {
nscolor rgba = NS_RGB(r,g,b);
aValue.SetColorValue(rgba);
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
return PR_FALSE; // already pushed back
1998-04-14 00:24:54 +04:00
1998-10-27 02:22:40 +03:00
default:
break;
1998-04-14 00:24:54 +04:00
}
// It's not a color
UngetToken();
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseColorComponent(PRInt32& aErrorCode,
PRUint8& aComponent,
1998-04-14 00:24:54 +04:00
char aStop)
{
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
float value;
nsCSSToken* tk = &mToken;
switch (tk->mType) {
case eCSSToken_Number:
value = tk->mNumber;
break;
case eCSSToken_Percentage:
value = tk->mNumber * 255.0f;
break;
default:
UngetToken();
return PR_FALSE;
}
if (ExpectSymbol(aErrorCode, aStop, PR_TRUE)) {
if (value < 0.0f) value = 0.0f;
if (value > 255.0f) value = 255.0f;
1998-10-27 02:22:40 +03:00
aComponent = (PRUint8) value;
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
return PR_FALSE;
}
//----------------------------------------------------------------------
PRBool
1998-10-27 02:22:40 +03:00
CSSParserImpl::ParseDeclaration(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration,
1998-09-30 03:50:09 +04:00
PRBool aCheckForBraces,
1998-10-27 02:22:40 +03:00
PRInt32& aChangeHint)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
aChangeHint = NS_STYLE_HINT_UNKNOWN;
1998-09-30 03:50:09 +04:00
1998-04-14 00:24:54 +04:00
// Get property name
nsCSSToken* tk = &mToken;
char propertyName[100];
1998-04-14 00:24:54 +04:00
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
if (eCSSToken_Ident == tk->mType) {
tk->mIdent.ToCString(propertyName, sizeof(propertyName));
// grab the ident before the ExpectSymbol trashes the token
1998-04-14 00:24:54 +04:00
if (!ExpectSymbol(aErrorCode, ':', PR_TRUE)) {
return PR_FALSE;
}
break;
}
if ((eCSSToken_Symbol == tk->mType) && (';' == tk->mSymbol)) {
// dangling semicolons are skipped
continue;
}
// Not a declaration...
UngetToken();
return PR_FALSE;
}
// Map property name to it's ID and then parse the property
1998-10-27 02:22:40 +03:00
PRInt32 propID = nsCSSProps::LookupName(propertyName);
if (0 > propID) { // unknown property
return PR_FALSE;
}
if (! ParseProperty(aErrorCode, aDeclaration, propID, aChangeHint)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
// See if the declaration is followed by a "!important" declaration
PRBool isImportant = PR_FALSE;
if (!GetToken(aErrorCode, PR_TRUE)) {
if (aCheckForBraces) {
// Premature eof is not ok when proper termination is mandated
return PR_FALSE;
}
return PR_TRUE;
}
else {
if (eCSSToken_Symbol == tk->mType) {
if ('!' == tk->mSymbol) {
// Look for important ident
if (!GetToken(aErrorCode, PR_TRUE)) {
// Premature eof is not ok
return PR_FALSE;
}
if ((eCSSToken_Ident != tk->mType) ||
!tk->mIdent.EqualsIgnoreCase("important")) {
UngetToken();
return PR_FALSE;
}
isImportant = PR_TRUE;
}
else {
// Not a !important declaration
UngetToken();
}
}
else {
// Not a !important declaration
UngetToken();
}
}
1998-06-26 09:51:55 +04:00
if (PR_TRUE == isImportant) {
1998-11-06 03:52:30 +03:00
aDeclaration->SetValueImportant(propID);
1998-06-26 09:51:55 +04:00
}
1998-04-14 00:24:54 +04:00
// Make sure valid property declaration is terminated with either a
// semicolon or a right-curly-brace (when aCheckForBraces is true).
// When aCheckForBraces is false, proper termination is either
// semicolon or EOF.
1998-04-14 00:24:54 +04:00
if (!GetToken(aErrorCode, PR_TRUE)) {
if (aCheckForBraces) {
// Premature eof is not ok
return PR_FALSE;
}
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
if (eCSSToken_Symbol == tk->mType) {
if (';' == tk->mSymbol) {
return PR_TRUE;
}
if (!aCheckForBraces) {
// If we didn't hit eof and we didn't see a semicolon then the
// declaration is not properly terminated.
return PR_FALSE;
}
1998-04-14 00:24:54 +04:00
if ('}' == tk->mSymbol) {
UngetToken();
return PR_TRUE;
}
}
return PR_FALSE;
}
// Flags for ParseVariant method
1998-10-27 02:22:40 +03:00
#define VARIANT_KEYWORD 0x000001 // K
#define VARIANT_LENGTH 0x000002 // L
#define VARIANT_PERCENT 0x000004 // P
#define VARIANT_COLOR 0x000008 // C
#define VARIANT_URL 0x000010 // U
#define VARIANT_NUMBER 0x000020 // N
#define VARIANT_INTEGER 0x000040 // I
#define VARIANT_ANGLE 0x000080 // G
#define VARIANT_FREQUENCY 0x000100 // F
#define VARIANT_TIME 0x000200 // T
#define VARIANT_STRING 0x000400 // S
#define VARIANT_COUNTER 0x000800 //
#define VARIANT_ATTR 0x001000 //
#define VARIANT_IDENTIFIER 0x002000 // D
#define VARIANT_AUTO 0x010000 // A
#define VARIANT_INHERIT 0x020000 // H
#define VARIANT_NONE 0x040000 // O
#define VARIANT_NORMAL 0x080000 // M
1998-04-14 00:24:54 +04:00
// Common combinations of variants
1998-10-27 02:22:40 +03:00
#define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH)
#define VARIANT_LP (VARIANT_LENGTH | VARIANT_PERCENT)
#define VARIANT_AH (VARIANT_AUTO | VARIANT_INHERIT)
#define VARIANT_AHLP (VARIANT_AH | VARIANT_LP)
#define VARIANT_AHI (VARIANT_AH | VARIANT_INTEGER)
#define VARIANT_AHK (VARIANT_AH | VARIANT_KEYWORD)
1998-10-27 02:22:40 +03:00
#define VARIANT_AHUK (VARIANT_AH | VARIANT_URL | VARIANT_KEYWORD)
#define VARIANT_AHL (VARIANT_AH | VARIANT_LENGTH)
1998-10-27 02:22:40 +03:00
#define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH)
1998-05-27 03:16:55 +04:00
#define VARIANT_HK (VARIANT_INHERIT | VARIANT_KEYWORD)
1998-10-27 02:22:40 +03:00
#define VARIANT_HKF (VARIANT_HK | VARIANT_FREQUENCY)
#define VARIANT_HKL (VARIANT_HK | VARIANT_LENGTH)
#define VARIANT_HKLP (VARIANT_HK | VARIANT_LP)
1998-04-30 23:57:36 +04:00
#define VARIANT_HL (VARIANT_INHERIT | VARIANT_LENGTH)
1998-10-27 02:22:40 +03:00
#define VARIANT_HI (VARIANT_INHERIT | VARIANT_INTEGER)
#define VARIANT_HLP (VARIANT_HL | VARIANT_PERCENT)
#define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER)
1998-10-27 02:22:40 +03:00
#define VARIANT_HLPO (VARIANT_HLP | VARIANT_NONE)
#define VARIANT_HTP (VARIANT_INHERIT | VARIANT_TIME | VARIANT_PERCENT)
#define VARIANT_HMK (VARIANT_HK | VARIANT_NORMAL)
#define VARIANT_HMKI (VARIANT_HMK | VARIANT_INTEGER)
#define VARIANT_HC (VARIANT_INHERIT | VARIANT_COLOR)
#define VARIANT_HCK (VARIANT_HK | VARIANT_COLOR)
#define VARIANT_HUO (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE)
#define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO)
#define VARIANT_HPN (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER)
1998-10-27 02:22:40 +03:00
#define VARIANT_HOK (VARIANT_HK | VARIANT_NONE)
#define VARIANT_HN (VARIANT_INHERIT | VARIANT_NUMBER)
#define VARIANT_HON (VARIANT_HN | VARIANT_NONE)
#define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING)
static const PRInt32 kBorderTopIDs[] = {
PROP_BORDER_TOP_WIDTH,
PROP_BORDER_TOP_STYLE,
PROP_BORDER_TOP_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
static const PRInt32 kBorderRightIDs[] = {
PROP_BORDER_RIGHT_WIDTH,
PROP_BORDER_RIGHT_STYLE,
PROP_BORDER_RIGHT_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
static const PRInt32 kBorderBottomIDs[] = {
PROP_BORDER_BOTTOM_WIDTH,
PROP_BORDER_BOTTOM_STYLE,
PROP_BORDER_BOTTOM_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
static const PRInt32 kBorderLeftIDs[] = {
PROP_BORDER_LEFT_WIDTH,
PROP_BORDER_LEFT_STYLE,
PROP_BORDER_LEFT_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
PRInt32 CSSParserImpl::SearchKeywordTable(PRInt32 aKeywordID, const PRInt32 aKeywordTable[])
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
PRInt32 index = 0;
while (0 <= aKeywordTable[index]) {
if (aKeywordID == aKeywordTable[index++]) {
return index;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
index++;
1998-04-14 00:24:54 +04:00
}
return -1;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseEnum(PRInt32& aErrorCode, nsCSSValue& aValue,
const PRInt32 aKeywordTable[])
1998-04-14 00:24:54 +04:00
{
nsString* ident = NextIdent(aErrorCode);
if (nsnull == ident) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
char cbuf[KEYWORD_BUFFER_SIZE];
1998-04-14 00:24:54 +04:00
ident->ToCString(cbuf, sizeof(cbuf));
1998-10-27 02:22:40 +03:00
PRInt32 keyword = nsCSSKeywords::LookupName(cbuf);
if (0 <= keyword) {
PRInt32 index = SearchKeywordTable(keyword, aKeywordTable);
if (0 < index) {
aValue.SetIntValue(aKeywordTable[index], eCSSUnit_Enumerated);
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
}
// Put the unknown identifier back and return
UngetToken();
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::TranslateDimension(nsCSSValue& aValue,
PRInt32 aVariantMask,
float aNumber,
const nsString& aUnit,
PRInt32& aParsedVariant)
1998-04-14 00:24:54 +04:00
{
nsCSSUnit units;
1998-10-27 02:22:40 +03:00
PRInt32 type = 0;
aParsedVariant = 0;
if (0 != aUnit.Length()) {
char cbuf[KEYWORD_BUFFER_SIZE];
aUnit.ToCString(cbuf, sizeof(cbuf));
1998-04-14 00:24:54 +04:00
PRInt32 id = nsCSSKeywords::LookupName(cbuf);
switch (id) {
1998-10-27 02:22:40 +03:00
case KEYWORD_EM: units = eCSSUnit_EM; type = VARIANT_LENGTH; break;
case KEYWORD_EX: units = eCSSUnit_XHeight; type = VARIANT_LENGTH; break;
case KEYWORD_PX: units = eCSSUnit_Pixel; type = VARIANT_LENGTH; break;
case KEYWORD_IN: units = eCSSUnit_Inch; type = VARIANT_LENGTH; break;
case KEYWORD_CM: units = eCSSUnit_Centimeter; type = VARIANT_LENGTH; break;
case KEYWORD_MM: units = eCSSUnit_Millimeter; type = VARIANT_LENGTH; break;
case KEYWORD_PT: units = eCSSUnit_Point; type = VARIANT_LENGTH; break;
case KEYWORD_PC: units = eCSSUnit_Pica; type = VARIANT_LENGTH; break;
case KEYWORD_DEG: units = eCSSUnit_Degree; type = VARIANT_ANGLE; break;
case KEYWORD_GRAD: units = eCSSUnit_Grad; type = VARIANT_ANGLE; break;
case KEYWORD_RAD: units = eCSSUnit_Radian; type = VARIANT_ANGLE; break;
case KEYWORD_HZ: units = eCSSUnit_Hertz; type = VARIANT_FREQUENCY; break;
case KEYWORD_KHZ: units = eCSSUnit_Kilohertz; type = VARIANT_FREQUENCY; break;
case KEYWORD_S: units = eCSSUnit_Seconds; type = VARIANT_TIME; break;
case KEYWORD_MS: units = eCSSUnit_Milliseconds; type = VARIANT_TIME; break;
default:
// unknown unit
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
} else {
// Must be a zero number...
1998-10-27 02:22:40 +03:00
NS_ASSERTION(0 == aNumber, "numbers without units must be 0");
if ((VARIANT_LENGTH & aVariantMask) != 0) {
units = eCSSUnit_Point;
type = VARIANT_LENGTH;
}
else if ((VARIANT_ANGLE & aVariantMask) != 0) {
units = eCSSUnit_Degree;
type = VARIANT_ANGLE;
}
else if ((VARIANT_FREQUENCY & aVariantMask) != 0) {
units = eCSSUnit_Hertz;
type = VARIANT_FREQUENCY;
}
else if ((VARIANT_TIME & aVariantMask) != 0) {
units = eCSSUnit_Seconds;
type = VARIANT_TIME;
}
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if ((type & aVariantMask) != 0) {
aValue.SetFloatValue(aNumber, units);
aParsedVariant = type;
return PR_TRUE;
}
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseVariant(PRInt32& aErrorCode,
1998-04-14 00:24:54 +04:00
nsICSSDeclaration* aDeclaration,
1998-10-27 02:22:40 +03:00
PRInt32 aPropID,
PRInt32 aVariantMask, const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
nsCSSValue value;
if (ParseVariant(aErrorCode, value, aVariantMask, aKeywordTable, aParsedVariant)) {
aDeclaration->AppendValue(aPropID, value);
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParsePositiveVariant(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration,
PRInt32 aPropID,
PRInt32 aVariantMask,
const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant)
{
nsCSSValue value;
if (ParseVariant(aErrorCode, value, aVariantMask, aKeywordTable, aParsedVariant)) {
if (eCSSUnit_Number == value.GetUnit() ||
value.IsLengthUnit()){
if (value.GetFloatValue() < 0) {
return PR_FALSE;
}
}
else if(value.GetUnit() == eCSSUnit_Percent) {
if (value.GetPercentValue() < 0) {
return PR_FALSE;
}
}
aDeclaration->AppendValue(aPropID, value);
return PR_TRUE;
}
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseVariant(PRInt32& aErrorCode, nsCSSValue& aValue,
PRInt32 aVariantMask,
const PRInt32 aKeywordTable[],
PRInt32& aParsedVariant)
{
aParsedVariant = 0;
1998-04-14 00:24:54 +04:00
if (!GetToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
nsCSSToken* tk = &mToken;
if (((aVariantMask & (VARIANT_AHK | VARIANT_NORMAL | VARIANT_NONE)) != 0) &&
1998-04-14 00:24:54 +04:00
(eCSSToken_Ident == tk->mType)) {
1998-10-27 02:22:40 +03:00
char cbuf[KEYWORD_BUFFER_SIZE];
1998-04-14 00:24:54 +04:00
tk->mIdent.ToCString(cbuf, sizeof(cbuf));
1998-10-27 02:22:40 +03:00
PRInt32 keyword = nsCSSKeywords::LookupName(cbuf);
if (0 <= keyword) { // known keyword
if ((aVariantMask & VARIANT_AUTO) != 0) {
if (KEYWORD_AUTO == keyword) {
aValue.SetAutoValue();
aParsedVariant = VARIANT_AUTO;
1998-04-30 23:57:36 +04:00
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
if ((aVariantMask & VARIANT_INHERIT) != 0) {
if (KEYWORD_INHERIT == keyword) {
aValue.SetInheritValue();
aParsedVariant = VARIANT_INHERIT;
1998-04-30 23:57:36 +04:00
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
if ((aVariantMask & VARIANT_NONE) != 0) {
if (KEYWORD_NONE == keyword) {
aValue.SetNoneValue();
aParsedVariant = VARIANT_NONE;
1998-04-30 23:57:36 +04:00
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
if ((aVariantMask & VARIANT_NORMAL) != 0) {
if (KEYWORD_NORMAL == keyword) {
aValue.SetNormalValue();
aParsedVariant = VARIANT_NORMAL;
1998-04-30 23:57:36 +04:00
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
if ((aVariantMask & VARIANT_KEYWORD) != 0) {
PRInt32 index = SearchKeywordTable(keyword, aKeywordTable);
if (0 < index) {
aValue.SetIntValue(aKeywordTable[index], eCSSUnit_Enumerated);
aParsedVariant = VARIANT_KEYWORD;
1998-04-30 23:57:36 +04:00
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
}
}
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & (VARIANT_LENGTH | VARIANT_ANGLE | VARIANT_FREQUENCY | VARIANT_TIME)) != 0) &&
tk->isDimension()) {
return TranslateDimension(aValue, aVariantMask,
tk->mNumber, tk->mIdent,
aParsedVariant);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & VARIANT_PERCENT) != 0) &&
1998-04-14 00:24:54 +04:00
(eCSSToken_Percentage == tk->mType)) {
1998-10-27 02:22:40 +03:00
aValue.SetPercentValue(tk->mNumber);
aParsedVariant = VARIANT_PERCENT;
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & VARIANT_NUMBER) != 0) &&
1998-04-14 00:24:54 +04:00
(eCSSToken_Number == tk->mType)) {
1998-10-27 02:22:40 +03:00
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Number);
aParsedVariant = VARIANT_NUMBER;
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & VARIANT_INTEGER) != 0) &&
1998-04-14 00:24:54 +04:00
(eCSSToken_Number == tk->mType) && tk->mIntegerValid) {
1998-10-27 02:22:40 +03:00
aValue.SetIntValue(tk->mInteger, eCSSUnit_Integer);
aParsedVariant = VARIANT_INTEGER;
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
if (PR_TRUE == mNavQuirkMode) { // NONSTANDARD: Nav interprets unitless numbers as px
if (((aVariantMask & VARIANT_LENGTH) != 0) &&
(eCSSToken_Number == tk->mType)) {
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Pixel);
aParsedVariant = VARIANT_LENGTH;
return PR_TRUE;
}
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & VARIANT_URL) != 0) &&
(eCSSToken_Function == tk->mType) &&
tk->mIdent.EqualsIgnoreCase("url")) {
if (ParseURL(aErrorCode, aValue)) {
aParsedVariant = VARIANT_URL;
return PR_TRUE;
1998-05-12 03:28:47 +04:00
}
1998-10-27 02:22:40 +03:00
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if ((aVariantMask & VARIANT_COLOR) != 0) {
if ((eCSSToken_ID == tk->mType) ||
(eCSSToken_Ident == tk->mType) ||
((eCSSToken_Function == tk->mType) &&
(tk->mIdent.EqualsIgnoreCase("rgb")))) {
1998-04-14 00:24:54 +04:00
// Put token back so that parse color can get it
UngetToken();
1998-10-27 02:22:40 +03:00
if (ParseColor(aErrorCode, aValue)) {
aParsedVariant = VARIANT_COLOR;
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
return PR_FALSE;
}
}
1998-10-27 02:22:40 +03:00
if (((aVariantMask & VARIANT_STRING) != 0) &&
(eCSSToken_String == tk->mType)) {
nsAutoString buffer;
buffer.Append(tk->mSymbol);
buffer.Append(tk->mIdent);
buffer.Append(tk->mSymbol);
aValue.SetStringValue(buffer, eCSSUnit_String);
aParsedVariant = VARIANT_STRING;
return PR_TRUE;
}
if (((aVariantMask & VARIANT_IDENTIFIER) != 0) &&
(eCSSToken_Ident == tk->mType)) {
aValue.SetStringValue(tk->mIdent, eCSSUnit_String);
aParsedVariant = VARIANT_IDENTIFIER;
return PR_TRUE;
}
if (((aVariantMask & VARIANT_COUNTER) != 0) &&
(eCSSToken_Function == tk->mType) &&
(tk->mIdent.EqualsIgnoreCase("counter") ||
tk->mIdent.EqualsIgnoreCase("counters"))) {
if (ParseCounter(aErrorCode, aValue)) {
aParsedVariant = VARIANT_COUNTER;
return PR_TRUE;
}
return PR_FALSE;
}
if (((aVariantMask & VARIANT_ATTR) != 0) &&
(eCSSToken_Function == tk->mType) &&
tk->mIdent.EqualsIgnoreCase("attr")) {
if (ParseAttr(aErrorCode, aValue)) {
aParsedVariant = VARIANT_ATTR;
return PR_TRUE;
}
return PR_FALSE;
}
1998-04-14 00:24:54 +04:00
UngetToken();
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseCounter(PRInt32& aErrorCode, nsCSSValue& aValue)
{
nsCSSUnit unit = (mToken.mIdent.EqualsIgnoreCase("counter") ?
eCSSUnit_Counter : eCSSUnit_Counters);
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
if (GetToken(aErrorCode, PR_TRUE)) {
if (eCSSToken_Ident == mToken.mType) {
nsAutoString counter;
counter.Append(mToken.mIdent);
if (eCSSUnit_Counters == unit) {
// get mandatory string
if (! ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
return PR_FALSE;
}
if (GetToken(aErrorCode, PR_TRUE) && (eCSSToken_String == mToken.mType)) {
counter.Append(',');
counter.Append(mToken.mSymbol); // quote too
counter.Append(mToken.mIdent);
counter.Append(mToken.mSymbol); // quote too
}
else {
UngetToken();
return PR_FALSE;
}
}
// get optional type
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
if (GetToken(aErrorCode, PR_TRUE) && (eCSSToken_Ident == mToken.mType)) {
char cbuf[KEYWORD_BUFFER_SIZE];
mToken.mIdent.ToCString(cbuf, sizeof(cbuf));
PRInt32 keyword = nsCSSKeywords::LookupName(cbuf);
if ((0 <= keyword) &&
(0 < SearchKeywordTable(keyword, nsCSSProps::kListStyleKTable))) {
counter.Append(',');
counter.Append(mToken.mIdent);
}
else {
return PR_FALSE;
}
}
else {
UngetToken();
return PR_FALSE;
}
}
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
aValue.SetStringValue(counter, unit);
return PR_TRUE;
}
}
else {
UngetToken();
}
}
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseAttr(PRInt32& aErrorCode, nsCSSValue& aValue)
{
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
if (GetToken(aErrorCode, PR_TRUE)) {
if ((eCSSToken_String == mToken.mType) ||
(eCSSToken_Ident == mToken.mType)) {
nsAutoString attr;
if (eCSSToken_String == mToken.mType) {
attr.Append(mToken.mSymbol);
attr.Append(mToken.mIdent);
attr.Append(mToken.mSymbol);
}
else {
attr.Append(mToken.mIdent);
}
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
aValue.SetStringValue(attr, eCSSUnit_Attr);
return PR_TRUE;
}
}
else {
UngetToken();
}
}
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue)
{
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
if (! GetURLToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
}
nsCSSToken* tk = &mToken;
if ((eCSSToken_String == tk->mType) || (eCSSToken_URL == tk->mType)) {
// Translate url into an absolute url if the url is relative to
// the style sheet.
// XXX editors won't like this - too bad for now
nsAutoString absURL;
if (nsnull != mURL) {
nsString baseURL;
nsresult rv = NS_MakeAbsoluteURL(mURL, baseURL, tk->mIdent, absURL);
if (NS_FAILED(rv)) {
absURL = tk->mIdent;
}
}
else {
1998-10-27 02:22:40 +03:00
absURL = tk->mIdent;
}
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
aValue.SetStringValue(absURL, eCSSUnit_URL);
return PR_TRUE;
}
}
}
return PR_FALSE;
}
PRInt32 CSSParserImpl::ParseChoice(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
const PRInt32 aPropIDs[], PRInt32 aNumIDs)
1998-04-14 00:24:54 +04:00
{
PRInt32 found = 0;
1998-10-27 02:22:40 +03:00
int loop;
for (loop = 0; loop < aNumIDs; loop++) {
1998-04-14 00:24:54 +04:00
// Try each property parser in order
1998-10-27 02:22:40 +03:00
PRInt32 hadFound = found;
int index;
for (index = 0; index < aNumIDs; index++) {
PRInt32 bit = 1 << index;
1998-04-14 00:24:54 +04:00
if ((found & bit) == 0) {
1998-10-27 02:22:40 +03:00
if (ParseProperty(aErrorCode, aDeclaration, aPropIDs[index])) {
1998-04-14 00:24:54 +04:00
found |= bit;
}
}
}
1998-10-27 02:22:40 +03:00
if (found == hadFound) { // found nothing new
break;
}
1998-04-14 00:24:54 +04:00
}
return found;
}
/**
* Parse a "box" property. Box properties have 1 to 4 values. When less
* than 4 values are provided a standard mapping is used to replicate
* existing values. Note that the replication requires renaming the
* values.
*/
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBoxProperties(PRInt32& aErrorCode,
1998-04-14 00:24:54 +04:00
nsICSSDeclaration* aDeclaration,
1998-10-27 02:22:40 +03:00
const PRInt32 aPropIDs[])
1998-04-14 00:24:54 +04:00
{
// Get up to four values for the property
PRInt32 count = 0;
1998-10-27 02:22:40 +03:00
int index;
for (index = 0; index < 4; index++) {
if (! ParseProperty(aErrorCode, aDeclaration, aPropIDs[index])) {
1998-04-14 00:24:54 +04:00
break;
}
count++;
}
if (count == 0) {
return PR_FALSE;
}
// Provide missing values by replicating some of the values found
nsCSSValue value;
switch (count) {
case 1: // Make right == top
1998-10-27 02:22:40 +03:00
aDeclaration->GetValue(aPropIDs[0], value);
aDeclaration->AppendValue(aPropIDs[1], value);
1998-04-14 00:24:54 +04:00
case 2: // Make bottom == top
1998-10-27 02:22:40 +03:00
aDeclaration->GetValue(aPropIDs[0], value);
aDeclaration->AppendValue(aPropIDs[2], value);
1998-04-14 00:24:54 +04:00
case 3: // Make left == right
1998-10-27 02:22:40 +03:00
aDeclaration->GetValue(aPropIDs[1], value);
aDeclaration->AppendValue(aPropIDs[3], value);
1998-04-14 00:24:54 +04:00
}
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseProperty(PRInt32& aErrorCode,
1998-09-30 03:50:09 +04:00
nsICSSDeclaration* aDeclaration,
1998-10-27 02:22:40 +03:00
PRInt32 aPropID,
PRInt32& aChangeHint)
1998-04-14 00:24:54 +04:00
{
// Strip out properties we use internally. These properties are used
// by compound property parsing routines (e.g. "background-position").
1998-10-27 02:22:40 +03:00
switch (aPropID) {
case PROP_BACKGROUND_X_POSITION:
case PROP_BACKGROUND_Y_POSITION:
case PROP_BORDER_X_SPACING:
case PROP_BORDER_Y_SPACING:
case PROP_CLIP_BOTTOM:
case PROP_CLIP_LEFT:
case PROP_CLIP_RIGHT:
case PROP_CLIP_TOP:
// The user can't use these
return PR_FALSE;
default:
break;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if (aChangeHint < nsCSSProps::kHintTable[aPropID]) {
aChangeHint = nsCSSProps::kHintTable[aPropID];
}
1998-09-30 03:50:09 +04:00
1998-10-27 02:22:40 +03:00
return ParseProperty(aErrorCode, aDeclaration, aPropID);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
#define CSS_SIDE_TOP 0
#define CSS_SIDE_RIGHT 1
#define CSS_SIDE_BOTTOM 2
#define CSS_SIDE_LEFT 3
PRBool CSSParserImpl::ParseProperty(PRInt32& aErrorCode,
1998-04-14 00:24:54 +04:00
nsICSSDeclaration* aDeclaration,
1998-10-27 02:22:40 +03:00
PRInt32 aPropID)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
switch (aPropID) {
case PROP_AZIMUTH:
return ParseAzimuth(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_BACKGROUND:
return ParseBackground(aErrorCode, aDeclaration);
case PROP_BACKGROUND_ATTACHMENT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kBackgroundAttachmentKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BACKGROUND_COLOR:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HCK,
nsCSSProps::kBackgroundColorKTable, parsed);
case PROP_BACKGROUND_FILTER: // XXX
return ParseBackgroundFilter(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_BACKGROUND_IMAGE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HUO,
nsnull, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BACKGROUND_POSITION:
1998-10-27 02:22:40 +03:00
return ParseBackgroundPosition(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_BACKGROUND_REPEAT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kBackgroundRepeatKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BORDER:
return ParseBorder(aErrorCode, aDeclaration);
1998-10-27 02:22:40 +03:00
case PROP_BORDER_COLLAPSE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kBorderCollapseKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_COLOR:
return ParseBorderColor(aErrorCode, aDeclaration);
1998-10-27 02:22:40 +03:00
case PROP_BORDER_SPACING:
return ParseBorderSpacing(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_STYLE:
return ParseBorderStyle(aErrorCode, aDeclaration);
case PROP_BORDER_BOTTOM:
1998-10-27 02:22:40 +03:00
return ParseBorderSide(aErrorCode, aDeclaration, kBorderBottomIDs, CSS_SIDE_BOTTOM);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_LEFT:
1998-10-27 02:22:40 +03:00
return ParseBorderSide(aErrorCode, aDeclaration, kBorderLeftIDs, CSS_SIDE_LEFT);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_RIGHT:
1998-10-27 02:22:40 +03:00
return ParseBorderSide(aErrorCode, aDeclaration, kBorderRightIDs, CSS_SIDE_RIGHT);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_TOP:
1998-10-27 02:22:40 +03:00
return ParseBorderSide(aErrorCode, aDeclaration, kBorderTopIDs, CSS_SIDE_TOP);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_BOTTOM_COLOR:
case PROP_BORDER_LEFT_COLOR:
case PROP_BORDER_RIGHT_COLOR:
case PROP_BORDER_TOP_COLOR:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HCK,
nsCSSProps::kBorderColorKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_BOTTOM_STYLE:
case PROP_BORDER_LEFT_STYLE:
case PROP_BORDER_RIGHT_STYLE:
case PROP_BORDER_TOP_STYLE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kBorderStyleKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_BOTTOM_WIDTH:
case PROP_BORDER_LEFT_WIDTH:
case PROP_BORDER_RIGHT_WIDTH:
case PROP_BORDER_TOP_WIDTH:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKL,
nsCSSProps::kBorderWidthKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_BORDER_WIDTH:
return ParseBorderWidth(aErrorCode, aDeclaration);
1998-10-27 02:22:40 +03:00
case PROP_BOTTOM:
case PROP_TOP:
case PROP_LEFT:
case PROP_RIGHT:
case PROP_HEIGHT:
case PROP_WIDTH:
return ParsePositiveVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHLP, nsnull, parsed);
1998-10-27 02:22:40 +03:00
case PROP_CAPTION_SIDE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kCaptionSideKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_CLEAR:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kClearKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_CLIP:
return ParseClip(aErrorCode, aDeclaration);
case PROP_COLOR:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HC, nsnull, parsed);
case PROP_CONTENT:
return ParseContent(aErrorCode, aDeclaration);
case PROP_COUNTER_INCREMENT:
case PROP_COUNTER_RESET:
return ParseCounterData(aErrorCode, aDeclaration, aPropID);
case PROP_CUE:
return ParseCue(aErrorCode, aDeclaration);
case PROP_CUE_AFTER:
case PROP_CUE_BEFORE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HUO, nsnull, parsed);
case PROP_CURSOR:
1998-10-27 02:22:40 +03:00
return ParseCursor(aErrorCode, aDeclaration);
case PROP_DIRECTION:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kDirectionKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_DISPLAY:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kDisplayKTable, parsed);
case PROP_ELEVATION:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK | VARIANT_ANGLE,
nsCSSProps::kElevationKTable, parsed);
case PROP_EMPTY_CELLS:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kEmptyCellsKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_FILTER:
1998-10-27 02:22:40 +03:00
return ParseForegroundFilter(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_FLOAT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kFloatKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_FONT:
1998-10-27 02:22:40 +03:00
return ParseFont(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_FONT_FAMILY:
1998-10-27 02:22:40 +03:00
return ParseFamily(aErrorCode, aDeclaration, aPropID);
1998-04-14 00:24:54 +04:00
case PROP_FONT_SIZE:
return ParsePositiveVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKLP,
1998-10-27 02:22:40 +03:00
nsCSSProps::kFontSizeKTable, parsed);
case PROP_FONT_SIZE_ADJUST:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HON,
nsnull, parsed);
case PROP_FONT_STRETCH:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK,
nsCSSProps::kFontStretchKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_FONT_STYLE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK,
nsCSSProps::kFontStyleKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_FONT_VARIANT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK,
nsCSSProps::kFontVariantKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_FONT_WEIGHT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, PROP_FONT_WEIGHT, VARIANT_HMKI,
nsCSSProps::kFontWeightKTable, parsed);
case PROP_LETTER_SPACING:
case PROP_WORD_SPACING:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HL | VARIANT_NORMAL, nsnull, parsed);
1998-04-14 00:24:54 +04:00
case PROP_LINE_HEIGHT:
return ParsePositiveVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLPN | VARIANT_NORMAL,
1998-10-27 02:22:40 +03:00
nsnull, parsed);
1998-04-14 00:24:54 +04:00
case PROP_LIST_STYLE:
return ParseListStyle(aErrorCode, aDeclaration);
case PROP_LIST_STYLE_IMAGE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HUO, nsnull, parsed);
1998-04-14 00:24:54 +04:00
case PROP_LIST_STYLE_POSITION:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kListStylePositionKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_LIST_STYLE_TYPE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kListStyleKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_MARGIN:
return ParseMargin(aErrorCode, aDeclaration);
case PROP_MARGIN_BOTTOM:
case PROP_MARGIN_LEFT:
case PROP_MARGIN_RIGHT:
case PROP_MARGIN_TOP:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHLP, nsnull, parsed);
case PROP_MARKER_OFFSET:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHL, nsnull, parsed);
case PROP_MARKS:
return ParseMarks(aErrorCode, aDeclaration);
case PROP_MAX_HEIGHT:
case PROP_MAX_WIDTH:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLPO, nsnull, parsed);
case PROP_MIN_HEIGHT:
case PROP_MIN_WIDTH:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLP, nsnull, parsed);
case PROP_OPACITY:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HPN, nsnull, parsed);
case PROP_ORPHANS:
case PROP_WIDOWS:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HI, nsnull, parsed);
case PROP_OUTLINE:
return ParseOutline(aErrorCode, aDeclaration);
case PROP_OUTLINE_COLOR:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HCK,
nsCSSProps::kOutlineColorKTable, parsed);
case PROP_OUTLINE_STYLE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kBorderStyleKTable, parsed);
case PROP_OUTLINE_WIDTH:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKL,
nsCSSProps::kBorderWidthKTable, parsed);
case PROP_OVERFLOW:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHK,
nsCSSProps::kOverflowKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_PADDING:
return ParsePadding(aErrorCode, aDeclaration);
case PROP_PADDING_BOTTOM:
case PROP_PADDING_LEFT:
case PROP_PADDING_RIGHT:
case PROP_PADDING_TOP:
return ParsePositiveVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLP, nsnull, parsed);
1998-10-27 02:22:40 +03:00
case PROP_PAGE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AUTO | VARIANT_IDENTIFIER,
nsnull, parsed);
case PROP_PAGE_BREAK_AFTER:
case PROP_PAGE_BREAK_BEFORE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHK,
nsCSSProps::kPageBreakKTable, parsed);
case PROP_PAGE_BREAK_INSIDE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHK,
nsCSSProps::kPageBreakInsideKTable, parsed);
case PROP_PAUSE:
return ParsePause(aErrorCode, aDeclaration);
case PROP_PAUSE_AFTER:
case PROP_PAUSE_BEFORE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HTP, nsnull, parsed);
case PROP_PITCH:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKF,
nsCSSProps::kPitchKTable, parsed);
case PROP_PITCH_RANGE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HN, nsnull, parsed);
case PROP_PLAY_DURING:
return ParsePlayDuring(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_POSITION:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kPositionKTable, parsed);
case PROP_QUOTES:
return ParseQuotes(aErrorCode, aDeclaration);
case PROP_RICHNESS:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HN, nsnull, parsed);
case PROP_SIZE:
return ParseSize(aErrorCode, aDeclaration);
case PROP_SPEAK:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK | VARIANT_NONE,
nsCSSProps::kSpeakKTable, parsed);
case PROP_SPEAK_HEADER:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kSpeakHeaderKTable, parsed);
case PROP_SPEAK_NUMERAL:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kSpeakNumeralKTable, parsed);
case PROP_SPEAK_PUNCTUATION:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kSpeakPunctuationKTable, parsed);
case PROP_SPEECH_RATE:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HN | VARIANT_KEYWORD,
nsCSSProps::kSpeechRateKTable, parsed);
case PROP_STRESS:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HN, nsnull, parsed);
case PROP_TABLE_LAYOUT:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHK,
nsCSSProps::kTableLayoutKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_TEXT_ALIGN:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK | VARIANT_STRING,
nsCSSProps::kTextAlignKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_TEXT_DECORATION:
1998-10-27 02:22:40 +03:00
return ParseTextDecoration(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_TEXT_INDENT:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLP, nsnull, parsed);
case PROP_TEXT_SHADOW:
return ParseTextShadow(aErrorCode, aDeclaration);
1998-04-14 00:24:54 +04:00
case PROP_TEXT_TRANSFORM:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HOK,
nsCSSProps::kTextTransformKTable, parsed);
case PROP_UNICODE_BIDI:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK,
nsCSSProps::kUnicodeBidiKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_VERTICAL_ALIGN:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKLP,
nsCSSProps::kVerticalAlignKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_VISIBILITY:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HK,
nsCSSProps::kVisibilityKTable, parsed);
case PROP_VOICE_FAMILY:
return ParseFamily(aErrorCode, aDeclaration, aPropID);
case PROP_VOLUME:
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HPN | VARIANT_KEYWORD,
nsCSSProps::kVolumeKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_WHITE_SPACE:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HMK,
nsCSSProps::kWhitespaceKTable, parsed);
1998-04-14 00:24:54 +04:00
case PROP_Z_INDEX:
1998-10-27 02:22:40 +03:00
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHI, nsnull, parsed);
1998-04-14 00:24:54 +04:00
}
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseAzimuth(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_AZIMUTH, VARIANT_HK | VARIANT_ANGLE,
nsCSSProps::kAzimuthKTable, parsed)) {
if (VARIANT_KEYWORD == parsed) {
nsCSSValue value;
aDeclaration->GetValue(PROP_AZIMUTH, value);
PRInt32 intValue = value.GetIntValue();
if ((NS_STYLE_AZIMUTH_LEFT_SIDE <= intValue) &&
(intValue <= NS_STYLE_AZIMUTH_BEHIND)) { // look for optional modifier
nsCSSValue modifier;
if (ParseEnum(aErrorCode, modifier, nsCSSProps::kAzimuthKTable)) {
PRInt32 enumValue = modifier.GetIntValue();
if (((intValue == NS_STYLE_AZIMUTH_BEHIND) &&
(NS_STYLE_AZIMUTH_LEFT_SIDE <= enumValue) && (enumValue <= NS_STYLE_AZIMUTH_RIGHT_SIDE)) ||
((enumValue == NS_STYLE_AZIMUTH_BEHIND) &&
(NS_STYLE_AZIMUTH_LEFT_SIDE <= intValue) && (intValue <= NS_STYLE_AZIMUTH_RIGHT_SIDE))) {
value.SetIntValue(intValue | enumValue, eCSSUnit_Enumerated);
aDeclaration->AppendValue(PROP_AZIMUTH, value);
return PR_TRUE;
}
// Put the unknown identifier back and return
UngetToken();
value.Reset();
aDeclaration->AppendValue(PROP_AZIMUTH, value); // clear what we got
return PR_FALSE;
}
}
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseBackground(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
static const PRInt32 kBackgroundIDs[] = {
PROP_BACKGROUND_COLOR,
PROP_BACKGROUND_IMAGE,
PROP_BACKGROUND_REPEAT,
PROP_BACKGROUND_ATTACHMENT,
PROP_BACKGROUND_POSITION,
// PROP_BACKGROUND_FILTER
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
PRInt32 found = ParseChoice(aErrorCode, aDeclaration, kBackgroundIDs, 5);
1998-04-14 00:24:54 +04:00
if (0 == found) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
if (1 == found) {
nsCSSValue value;
aDeclaration->GetValue(PROP_BACKGROUND_COLOR, value);
if (eCSSUnit_Inherit == value.GetUnit()) { // one inherit value, all inherit
aDeclaration->AppendValue(PROP_BACKGROUND_IMAGE, value);
aDeclaration->AppendValue(PROP_BACKGROUND_REPEAT, value);
aDeclaration->AppendValue(PROP_BACKGROUND_ATTACHMENT, value);
aDeclaration->AppendValue(PROP_BACKGROUND_X_POSITION, value);
aDeclaration->AppendValue(PROP_BACKGROUND_Y_POSITION, value);
// aDeclaration->AppendValue(PROP_BACKGROUND_FILTER, value);
return PR_TRUE;
}
}
1998-04-14 00:24:54 +04:00
// Provide missing values
if ((found & 1) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_COLOR,
nsCSSValue(NS_STYLE_BG_COLOR_TRANSPARENT,
eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
if ((found & 2) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_IMAGE,
nsCSSValue(eCSSUnit_None));
1998-04-14 00:24:54 +04:00
}
if ((found & 4) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_REPEAT,
nsCSSValue(NS_STYLE_BG_REPEAT_XY,
eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
if ((found & 8) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_ATTACHMENT,
nsCSSValue(NS_STYLE_BG_ATTACHMENT_SCROLL,
eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
if ((found & 16) == 0) {
1998-10-27 02:22:40 +03:00
nsCSSValue zero(0.0f, eCSSUnit_Percent);
aDeclaration->AppendValue(PROP_BACKGROUND_X_POSITION, zero);
aDeclaration->AppendValue(PROP_BACKGROUND_Y_POSITION, zero);
1998-04-14 00:24:54 +04:00
}
// XXX Note: no default for filter (yet)
return PR_TRUE;
}
// Bits used in determining which background position info we have
#define BG_CENTER 0
#define BG_TOP 1
#define BG_BOTTOM 2
#define BG_LEFT 4
#define BG_RIGHT 8
#define BG_CENTER1 16
#define BG_CENTER2 32
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBackgroundPosition(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 kBackgroundPositionIDs[] = {
1998-04-14 00:24:54 +04:00
PROP_BACKGROUND_X_POSITION,
PROP_BACKGROUND_Y_POSITION,
};
// Note: Don't change this table unless you update
// parseBackgroundPosition!
1998-10-27 02:22:40 +03:00
static const PRInt32 kBackgroundXYPositionKTable[] = {
1998-04-14 00:24:54 +04:00
KEYWORD_CENTER, BG_CENTER,
KEYWORD_TOP, BG_TOP,
KEYWORD_BOTTOM, BG_BOTTOM,
KEYWORD_LEFT, BG_LEFT,
KEYWORD_RIGHT, BG_RIGHT,
-1,
};
// First try a number or a length value
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_BACKGROUND_X_POSITION, VARIANT_HLP, nsnull, parsed)) {
if (VARIANT_INHERIT == parsed) { // both are inherited
aDeclaration->AppendValue(PROP_BACKGROUND_Y_POSITION, nsCSSValue(eCSSUnit_Inherit));
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
// We have one number/length. Get the optional second number/length.
1998-10-27 02:22:40 +03:00
if (ParseVariant(aErrorCode, aDeclaration, PROP_BACKGROUND_Y_POSITION, VARIANT_LP, nsnull, parsed)) {
1998-04-14 00:24:54 +04:00
// We have two numbers
return PR_TRUE;
}
// We have one number which is the x position. Create an value for
// the vertical position which is of value 50%
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_Y_POSITION, nsCSSValue(0.5f, eCSSUnit_Percent));
1998-04-14 00:24:54 +04:00
// XXX shouldn't this be CENTER enum instead?
return PR_TRUE;
}
// Now try keywords. We do this manually to allow for the first
// appearance of "center" to apply to the either the x or y
// position (it's ambiguous so we have to disambiguate). Each
// allowed keyword value is assigned it's own bit. We don't allow
// any duplicate keywords other than center. We try to get two
// keywords but it's okay if there is only one.
PRInt32 mask = 0;
PRInt32 centerBit = BG_CENTER1;
for (PRInt32 i = 0; i < 2; i++) {
nsString* ident = NextIdent(aErrorCode);
if (nsnull == ident) {
break;
}
1998-10-27 02:22:40 +03:00
char cbuf[KEYWORD_BUFFER_SIZE];
1998-04-14 00:24:54 +04:00
ident->ToCString(cbuf, sizeof(cbuf));
1998-10-27 02:22:40 +03:00
PRInt32 index = SearchKeywordTable(nsCSSKeywords::LookupName(cbuf),
1998-04-14 00:24:54 +04:00
kBackgroundXYPositionKTable);
1998-10-27 02:22:40 +03:00
if (0 < index) {
PRInt32 bit = kBackgroundXYPositionKTable[index];
if (0 == bit) {
1998-04-14 00:24:54 +04:00
// Special hack for center bits: We can have two of them
mask |= centerBit;
centerBit <<= 1;
continue;
} else if ((mask & bit) != 0) {
// no duplicate values allowed (other than center)
return PR_FALSE;
}
mask |= bit;
} else {
UngetToken();
break;
}
}
// Check for bad input. Bad input consists of no matching keywords,
// or pairs of x keywords or pairs of y keywords.
if ((mask == 0) || (mask == (BG_TOP | BG_BOTTOM)) ||
(mask == (BG_LEFT | BG_RIGHT))) {
return PR_FALSE;
}
// Map good input
int xValue = 50;
if ((mask & (BG_LEFT | BG_RIGHT)) != 0) {
// We have an x value
xValue = ((mask & BG_LEFT) != 0) ? 0 : 100;
}
int yValue = 50;
if ((mask & (BG_TOP | BG_BOTTOM)) != 0) {
// We have a y value
yValue = ((mask & BG_TOP) != 0) ? 0 : 100;
}
// Create style values
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_BACKGROUND_X_POSITION, nsCSSValue(xValue, eCSSUnit_Enumerated));
aDeclaration->AppendValue(PROP_BACKGROUND_Y_POSITION, nsCSSValue(yValue, eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBackgroundFilter(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
// XXX not yet supported
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseForegroundFilter(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
// XXX not yet supported
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
// These must be in CSS order (top,right,bottom,left) for indexing to work
static const PRInt32 kBorderStyleIDs[] = {
PROP_BORDER_TOP_STYLE,
PROP_BORDER_RIGHT_STYLE,
PROP_BORDER_BOTTOM_STYLE,
PROP_BORDER_LEFT_STYLE
};
static const PRInt32 kBorderWidthIDs[] = {
PROP_BORDER_TOP_WIDTH,
PROP_BORDER_RIGHT_WIDTH,
PROP_BORDER_BOTTOM_WIDTH,
PROP_BORDER_LEFT_WIDTH
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
static const PRInt32 kBorderColorIDs[] = {
PROP_BORDER_TOP_COLOR,
PROP_BORDER_RIGHT_COLOR,
PROP_BORDER_BOTTOM_COLOR,
PROP_BORDER_LEFT_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBorder(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 kBorderIDs[] = {
PROP_BORDER_TOP_WIDTH, // only one value per property
PROP_BORDER_TOP_STYLE,
PROP_BORDER_TOP_COLOR
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
PRInt32 found = ParseChoice(aErrorCode, aDeclaration, kBorderIDs, 3);
1998-04-14 00:24:54 +04:00
if (0 == found) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
int index;
if (1 == found) { // only found width
nsCSSValue value;
aDeclaration->GetValue(PROP_BORDER_TOP_WIDTH, value);
if (eCSSUnit_Inherit == value.GetUnit()) { // one inherit value, all inherit
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kBorderWidthIDs[index], value);
aDeclaration->AppendValue(kBorderStyleIDs[index], value);
aDeclaration->AppendValue(kBorderColorIDs[index], value);
}
return PR_TRUE;
}
}
1998-04-14 00:24:54 +04:00
if (0 == (found & 1)) {
// provide missing border width's
1998-10-27 02:22:40 +03:00
nsCSSValue medium(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kBorderWidthIDs[index], medium);
1998-04-14 00:24:54 +04:00
}
}
1998-10-27 02:22:40 +03:00
else { // copy top to other three sides
nsCSSValue value;
aDeclaration->GetValue(PROP_BORDER_TOP_WIDTH, value);
for (index = 1; index < 4; index++) {
aDeclaration->AppendValue(kBorderWidthIDs[index], value);
}
}
1998-04-14 00:24:54 +04:00
if (0 == (found & 2)) {
// provide missing border style's
1998-10-27 02:22:40 +03:00
nsCSSValue none(eCSSUnit_None);
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kBorderStyleIDs[index], none);
}
}
else { // copy top to other three sides
nsCSSValue value;
aDeclaration->GetValue(PROP_BORDER_TOP_STYLE, value);
for (index = 1; index < 4; index++) {
aDeclaration->AppendValue(kBorderStyleIDs[index], value);
1998-04-14 00:24:54 +04:00
}
}
1998-10-27 02:22:40 +03:00
if (0 == (found & 4)) {
// clear missing color values so color property will be used
nsCSSValue null;
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kBorderColorIDs[index], null);
}
}
else { // copy top to other three sides
nsCSSValue value;
aDeclaration->GetValue(PROP_BORDER_TOP_COLOR, value);
for (index = 1; index < 4; index++) {
aDeclaration->AppendValue(kBorderColorIDs[index], value);
}
}
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBorderColor(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderColorIDs);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBorderSpacing(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_BORDER_X_SPACING, VARIANT_HL, nsnull, parsed)) {
if (VARIANT_INHERIT == parsed) { // both are inherited
aDeclaration->AppendValue(PROP_BORDER_Y_SPACING, nsCSSValue(eCSSUnit_Inherit));
return PR_TRUE;
}
// We have one length. Get the optional second length.
if (ParseVariant(aErrorCode, aDeclaration, PROP_BORDER_Y_SPACING, VARIANT_LENGTH,
nsnull, parsed)) {
// We have two numbers
return PR_TRUE;
}
// We have one length which is the horizontal spacing. Create a value for
// the vertical spacing which is equal
nsCSSValue value;
aDeclaration->GetValue(PROP_BORDER_X_SPACING, value);
aDeclaration->AppendValue(PROP_BORDER_Y_SPACING, value);
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseBorderSide(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
const PRInt32 aPropIDs[], PRInt32 aSide)
{
PRInt32 found = ParseChoice(aErrorCode, aDeclaration, aPropIDs, 3);
if (0 == found) {
return PR_FALSE;
}
if (1 == found) {
nsCSSValue value;
aDeclaration->GetValue(aPropIDs[0], value);
if (eCSSUnit_Inherit == value.GetUnit()) { // one inherit value, all inherit
aDeclaration->AppendValue(aPropIDs[1], value);
aDeclaration->AppendValue(aPropIDs[2], value);
return PR_TRUE;
}
}
1998-04-14 00:24:54 +04:00
if ((found & 1) == 0) {
// Provide default border-width
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(kBorderWidthIDs[aSide],
nsCSSValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
if ((found & 2) == 0) {
// Provide default border-style
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(kBorderStyleIDs[aSide], nsCSSValue(eCSSUnit_None));
}
if ((found & 4) == 0) {
// reset border-color so color property gets used
aDeclaration->AppendValue(kBorderColorIDs[aSide], nsCSSValue(eCSSUnit_Null));
1998-04-14 00:24:54 +04:00
}
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBorderStyle(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderStyleIDs);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseBorderWidth(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderWidthIDs);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseClip(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 kClipIDs[] = {
PROP_CLIP_TOP,
PROP_CLIP_RIGHT,
PROP_CLIP_BOTTOM,
PROP_CLIP_LEFT
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
if (! GetToken(aErrorCode, PR_TRUE)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
int index;
if ((eCSSToken_Ident == mToken.mType) &&
mToken.mIdent.EqualsIgnoreCase("auto")) {
nsCSSValue valueAuto(eCSSUnit_Auto);
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kClipIDs[index], valueAuto);
1998-04-14 00:24:54 +04:00
}
return PR_TRUE;
1998-10-27 02:22:40 +03:00
} else if ((eCSSToken_Ident == mToken.mType) &&
mToken.mIdent.EqualsIgnoreCase("inherit")) {
nsCSSValue inherit(eCSSUnit_Inherit);
for (index = 0; index < 4; index++) {
aDeclaration->AppendValue(kClipIDs[index], inherit);
}
return PR_TRUE;
1998-10-27 02:22:40 +03:00
} else if ((eCSSToken_Function == mToken.mType) &&
mToken.mIdent.EqualsIgnoreCase("rect")) {
1998-04-14 00:24:54 +04:00
if (!ExpectSymbol(aErrorCode, '(', PR_TRUE)) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
for (index = 0; index < 4; index++) {
PRInt32 parsed;
if (! ParseVariant(aErrorCode, aDeclaration, kClipIDs[index], VARIANT_AL, nsnull, parsed)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
1998-10-27 02:22:40 +03:00
// XXX need to reset values if failed
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
if (3 != index) {
// skip optional commas between elements
ExpectSymbol(aErrorCode, ',', PR_TRUE);
}
1998-04-14 00:24:54 +04:00
}
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
return PR_FALSE;
}
return PR_TRUE;
} else {
UngetToken();
}
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
#define VARIANT_CONTENT (VARIANT_STRING | VARIANT_URL | VARIANT_COUNTER | VARIANT_ATTR | \
VARIANT_KEYWORD)
PRBool CSSParserImpl::ParseContent(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_CONTENT, VARIANT_CONTENT | VARIANT_INHERIT,
nsCSSProps::kContentKTable, parsed)) {
if (VARIANT_INHERIT != parsed) {
nsCSSContent* content = nsnull;
aDeclaration->GetData(kCSSContentSID, (nsCSSStruct**)&content);
if (nsnull != content) {
nsCSSValueList* list = content->mContent;
while (nsnull != content) {
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
nsCSSValue value;
if (ParseVariant(aErrorCode, value, VARIANT_CONTENT,
nsCSSProps::kContentKTable, parsed)) {
list->mNext = new nsCSSValueList();
list = list->mNext;
if (nsnull != list) {
list->mValue = value;
}
}
else {
break;
}
}
}
aDeclaration->AppendValue(PROP_CONTENT, nsCSSValue());
return PR_FALSE;
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseCounterData(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID)
{
nsString* ident = NextIdent(aErrorCode);
if (nsnull == ident) {
return PR_FALSE;
}
if (ident->EqualsIgnoreCase("none")) {
aDeclaration->AppendValue(aPropID, nsCSSValue(eCSSUnit_None));
}
else if (ident->EqualsIgnoreCase("inherit")) {
aDeclaration->AppendValue(aPropID, nsCSSValue(eCSSUnit_Inherit));
}
else {
aDeclaration->AppendValue(aPropID, nsCSSValue(*ident, eCSSUnit_String));
nsCSSContent* content = nsnull;
aDeclaration->GetData(kCSSContentSID, (nsCSSStruct**)&content);
if (nsnull != content) {
nsCSSCounterData* data = ((PROP_COUNTER_INCREMENT == aPropID) ?
content->mCounterIncrement : content->mCounterReset);
data->mValue.Reset();
while (nsnull != data) {
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
if (! GetToken(aErrorCode, PR_TRUE)) {
break;
}
if ((eCSSToken_Number == mToken.mType) && (mToken.mIntegerValid)) {
data->mValue.SetIntValue(mToken.mInteger, eCSSUnit_Integer);
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
if (! GetToken(aErrorCode, PR_TRUE)) {
break;
}
}
if (eCSSToken_Ident == mToken.mType) {
data->mNext = new nsCSSCounterData();
data = data->mNext;
if (nsnull != data) {
data->mCounter.SetStringValue(mToken.mIdent, eCSSUnit_String);
}
}
else {
break;
}
}
}
aDeclaration->AppendValue(aPropID, nsCSSValue()); // clear it
return PR_FALSE;
}
return PR_TRUE;
}
PRBool CSSParserImpl::ParseCue(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
if (ParseProperty(aErrorCode, aDeclaration, PROP_CUE_BEFORE)) {
if (! ParseProperty(aErrorCode, aDeclaration, PROP_CUE_AFTER)) {
nsCSSValue value;
aDeclaration->GetValue(PROP_CUE_BEFORE, value);
aDeclaration->AppendValue(PROP_CUE_AFTER, value);
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseCursor(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_CURSOR, VARIANT_AHUK,
nsCSSProps::kCursorKTable, parsed)) {
if (VARIANT_URL == parsed) {
nsCSSColor* color = nsnull;
aDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&color);
if (nsnull != color) {
nsCSSValueList* list = color->mCursor;
while (nsnull != list) {
if ((VARIANT_URL != parsed) || ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
nsCSSValue value;
if (ParseVariant(aErrorCode, value, VARIANT_AHUK,
nsCSSProps::kCursorKTable, parsed)) {
list->mNext = new nsCSSValueList();
list = list->mNext;
if (nsnull != list) {
list->mValue = value;
}
}
else {
break;
}
}
}
aDeclaration->AppendValue(PROP_CURSOR, nsCSSValue());
return PR_FALSE;
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseFont(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
static const PRInt32 fontIDs[] = {
PROP_FONT_STYLE,
PROP_FONT_VARIANT,
PROP_FONT_WEIGHT
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_FONT_FAMILY, VARIANT_HK,
nsCSSProps::kFontKTable, parsed)) {
if (VARIANT_INHERIT == parsed) {
nsCSSValue inherit(eCSSUnit_Inherit);
aDeclaration->AppendValue(PROP_FONT_STYLE, inherit);
aDeclaration->AppendValue(PROP_FONT_VARIANT, inherit);
aDeclaration->AppendValue(PROP_FONT_WEIGHT, inherit);
aDeclaration->AppendValue(PROP_FONT_SIZE, inherit);
aDeclaration->AppendValue(PROP_LINE_HEIGHT, inherit);
}
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
// Get optional font-style, font-variant and font-weight (in any order)
1998-10-27 02:22:40 +03:00
PRInt32 found = ParseChoice(aErrorCode, aDeclaration, fontIDs, 3);
nsCSSValue normal(eCSSUnit_Normal);
1998-04-14 00:24:54 +04:00
if ((found & 1) == 0) {
// Provide default font-style
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(fontIDs[0], normal);
1998-04-14 00:24:54 +04:00
}
if ((found & 2) == 0) {
// Provide default font-variant
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(fontIDs[1], normal);
1998-04-14 00:24:54 +04:00
}
if ((found & 4) == 0) {
// Provide default font-weight
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(fontIDs[2], normal);
1998-04-14 00:24:54 +04:00
}
// Get mandatory font-size
1998-10-27 02:22:40 +03:00
if (!ParseVariant(aErrorCode, aDeclaration, PROP_FONT_SIZE,
VARIANT_HKLP, nsCSSProps::kFontSizeKTable, parsed)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
// Get optional "/" line-height
if (ExpectSymbol(aErrorCode, '/', PR_TRUE)) {
1998-10-27 02:22:40 +03:00
if (!ParseVariant(aErrorCode, aDeclaration, PROP_LINE_HEIGHT,
VARIANT_HLPN | VARIANT_NORMAL, nsnull, parsed)) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
}
1998-10-27 02:22:40 +03:00
else {
aDeclaration->AppendValue(PROP_LINE_HEIGHT, normal);
}
1998-04-14 00:24:54 +04:00
// Get final mandatory font-family
1998-10-27 02:22:40 +03:00
return ParseFamily(aErrorCode, aDeclaration, PROP_FONT_FAMILY);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseFamily(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration,
PRInt32 aPropID)
1998-04-14 00:24:54 +04:00
{
nsCSSToken* tk = &mToken;
nsAutoString family;
PRBool firstOne = PR_TRUE;
for (;;) {
if (!GetToken(aErrorCode, PR_TRUE)) {
break;
}
if (eCSSToken_Ident == tk->mType) {
1998-10-27 02:22:40 +03:00
if (firstOne) {
if (tk->mIdent.EqualsIgnoreCase("inherit")) {
aDeclaration->AppendValue(aPropID, nsCSSValue(eCSSUnit_Inherit));
return PR_TRUE;
}
}
else {
1998-04-14 00:24:54 +04:00
family.Append(PRUnichar(','));
}
family.Append(tk->mIdent);
for (;;) {
if (!GetToken(aErrorCode, PR_FALSE)) {
break;
}
if (eCSSToken_Ident == tk->mType) {
family.Append(tk->mIdent);
} else if (eCSSToken_WhiteSpace == tk->mType) {
// Lookahead one token and drop whitespace if we ending the
// font name.
if (!GetToken(aErrorCode, PR_TRUE)) {
break;
}
if (eCSSToken_Ident != tk->mType) {
UngetToken();
break;
}
UngetToken();
family.Append(PRUnichar(' '));
} else {
UngetToken();
break;
}
}
firstOne = PR_FALSE;
} else if (eCSSToken_String == tk->mType) {
if (!firstOne) {
family.Append(PRUnichar(','));
}
family.Append(tk->mSymbol); // replace the quotes
1998-04-14 00:24:54 +04:00
family.Append(tk->mIdent);
family.Append(tk->mSymbol);
1998-04-14 00:24:54 +04:00
firstOne = PR_FALSE;
} else if (eCSSToken_Symbol == tk->mType) {
if (',' != tk->mSymbol) {
UngetToken();
break;
}
} else {
UngetToken();
break;
}
}
if (family.Length() == 0) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(aPropID, nsCSSValue(family, eCSSUnit_String));
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseListStyle(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 listStyleIDs[] = {
PROP_LIST_STYLE_TYPE,
PROP_LIST_STYLE_POSITION,
PROP_LIST_STYLE_IMAGE
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
int found = ParseChoice(aErrorCode, aDeclaration, listStyleIDs, 3);
if (found == 0) {
1998-04-14 00:24:54 +04:00
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
if (1 == found) {
nsCSSValue value;
aDeclaration->GetValue(PROP_LIST_STYLE_TYPE, value);
if (eCSSUnit_Inherit == value.GetUnit()) { // one inherit value, all inherit
aDeclaration->AppendValue(PROP_LIST_STYLE_POSITION, value);
aDeclaration->AppendValue(PROP_LIST_STYLE_IMAGE, value);
return PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
}
// Provide default values
if ((found & 1) == 0) {
aDeclaration->AppendValue(PROP_LIST_STYLE_TYPE,
nsCSSValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated));
}
if ((found & 2) == 0) {
aDeclaration->AppendValue(PROP_LIST_STYLE_POSITION,
nsCSSValue(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE, eCSSUnit_Enumerated));
}
if ((found & 4) == 0) {
aDeclaration->AppendValue(PROP_LIST_STYLE_IMAGE, nsCSSValue(eCSSUnit_None));
1998-04-14 00:24:54 +04:00
}
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseMargin(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 kMarginSideIDs[] = {
PROP_MARGIN_TOP,
PROP_MARGIN_RIGHT,
PROP_MARGIN_BOTTOM,
PROP_MARGIN_LEFT
};
return ParseBoxProperties(aErrorCode, aDeclaration, kMarginSideIDs);
}
1998-04-14 00:24:54 +04:00
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseMarks(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_MARKS, VARIANT_HOK,
nsCSSProps::kPageMarksKTable, parsed)) {
if (VARIANT_KEYWORD == parsed) {
nsCSSValue second;
if (ParseEnum(aErrorCode, second, nsCSSProps::kPageMarksKTable)) {
nsCSSValue value;
aDeclaration->GetValue(PROP_MARKS, value);
value.SetIntValue(value.GetIntValue() | second.GetIntValue(), eCSSUnit_Enumerated);
aDeclaration->AppendValue(PROP_MARKS, value);
1998-04-14 00:24:54 +04:00
}
}
1998-10-27 02:22:40 +03:00
return PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
return PR_FALSE;
}
PRBool CSSParserImpl::ParseOutline(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
static const PRInt32 kOutlineIDs[] = {
PROP_OUTLINE_COLOR,
PROP_OUTLINE_STYLE,
PROP_OUTLINE_WIDTH
};
int found = ParseChoice(aErrorCode, aDeclaration, kOutlineIDs, 3);
1998-04-14 00:24:54 +04:00
if (found == 0) {
return PR_FALSE;
}
1998-10-27 02:22:40 +03:00
if (1 == found) {
nsCSSValue value;
aDeclaration->GetValue(PROP_OUTLINE_COLOR, value);
if (eCSSUnit_Inherit == value.GetUnit()) { // one inherit value, all inherit
aDeclaration->AppendValue(PROP_OUTLINE_STYLE, value);
aDeclaration->AppendValue(PROP_OUTLINE_WIDTH, value);
return PR_TRUE;
}
}
1998-04-14 00:24:54 +04:00
// Provide default values
if ((found & 1) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_OUTLINE_COLOR,
nsCSSValue(NS_STYLE_COLOR_INVERT, eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
if ((found & 2) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_OUTLINE_STYLE, nsCSSValue(eCSSUnit_None));
1998-04-14 00:24:54 +04:00
}
if ((found & 4) == 0) {
1998-10-27 02:22:40 +03:00
aDeclaration->AppendValue(PROP_OUTLINE_WIDTH,
nsCSSValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated));
1998-04-14 00:24:54 +04:00
}
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParsePadding(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
static const PRInt32 kPaddingSideIDs[] = {
PROP_PADDING_TOP,
PROP_PADDING_RIGHT,
PROP_PADDING_BOTTOM,
PROP_PADDING_LEFT
1998-04-14 00:24:54 +04:00
};
1998-10-27 02:22:40 +03:00
return ParseBoxProperties(aErrorCode, aDeclaration, kPaddingSideIDs);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParsePause(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
if (ParseProperty(aErrorCode, aDeclaration, PROP_PAUSE_BEFORE)) {
if (! ParseProperty(aErrorCode, aDeclaration, PROP_PAUSE_AFTER)) {
nsCSSValue value;
aDeclaration->GetValue(PROP_PAUSE_BEFORE, value);
aDeclaration->AppendValue(PROP_PAUSE_AFTER, value);
}
return PR_TRUE;
}
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParsePlayDuring(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
1998-04-14 00:24:54 +04:00
{
1998-10-27 02:22:40 +03:00
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_PLAY_DURING, VARIANT_AHUO,
nsnull, parsed)) {
if (VARIANT_URL == parsed) {
nsCSSValue value;
if (ParseEnum(aErrorCode, value, nsCSSProps::kPlayDuringKTable)) {
PRInt32 intValue = value.GetIntValue();
if (ParseEnum(aErrorCode, value, nsCSSProps::kPlayDuringKTable)) {
value.SetIntValue(intValue | value.GetIntValue(), eCSSUnit_Enumerated);
}
aDeclaration->AppendValue(PROP_PLAY_DURING_FLAGS, value);
}
}
return PR_TRUE;
}
return PR_FALSE;
}
1998-04-14 00:24:54 +04:00
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseQuotes(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_QUOTES_OPEN, VARIANT_HOS,
nsnull, parsed)) {
if (VARIANT_STRING == parsed) {
nsCSSContent* content = nsnull;
aDeclaration->GetData(kCSSContentSID, (nsCSSStruct**)&content);
if (nsnull != content) {
nsCSSQuotes* quotes = content->mQuotes;
while (nsnull != quotes) {
// get close
if (ParseVariant(aErrorCode, quotes->mClose, VARIANT_STRING, nsnull, parsed)) {
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
// look for another open
nsCSSValue value;
if (ParseVariant(aErrorCode, value, VARIANT_STRING, nsnull, parsed)) {
quotes->mNext = new nsCSSQuotes();
quotes = quotes->mNext;
if (nsnull != quotes) {
quotes->mOpen = value;
continue;
}
}
}
break;
}
}
aDeclaration->AppendValue(PROP_QUOTES_OPEN, nsCSSValue());
aDeclaration->AppendValue(PROP_QUOTES_CLOSE, nsCSSValue());
return PR_FALSE;
}
1998-04-14 00:24:54 +04:00
return PR_TRUE;
}
1998-10-27 02:22:40 +03:00
return PR_FALSE;
}
1998-04-14 00:24:54 +04:00
1998-10-27 02:22:40 +03:00
PRBool CSSParserImpl::ParseSize(PRInt32& aErrorCode, nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant (aErrorCode, aDeclaration, PROP_SIZE_WIDTH, VARIANT_AHKL,
nsCSSProps::kPageSizeKTable, parsed)) {
if (VARIANT_LENGTH == parsed) {
if (ParseVariant(aErrorCode, aDeclaration, PROP_SIZE_HEIGHT, VARIANT_LENGTH,
nsnull, parsed)) {
return PR_TRUE;
}
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
nsCSSValue value;
aDeclaration->GetValue(PROP_SIZE_WIDTH, value);
aDeclaration->AppendValue(PROP_SIZE_HEIGHT, value);
return PR_TRUE;
}
return PR_FALSE;
}
PRBool CSSParserImpl::ParseTextDecoration(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_TEXT_DECORATION, VARIANT_HOK,
nsCSSProps::kTextDecorationKTable, parsed)) {
if (VARIANT_KEYWORD == parsed) { // look for more keywords
nsCSSValue value;
aDeclaration->GetValue(PROP_TEXT_DECORATION, value);
PRInt32 intValue = value.GetIntValue();
int index;
for (index = 0; index < 3; index++) {
if (ParseEnum(aErrorCode, value, nsCSSProps::kTextDecorationKTable)) {
intValue |= value.GetIntValue();
}
else {
break;
}
}
value.SetIntValue(intValue, eCSSUnit_Enumerated);
aDeclaration->AppendValue(PROP_TEXT_DECORATION, value);
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
return PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
return PR_FALSE;
}
PRBool CSSParserImpl::ParseTextShadow(PRInt32& aErrorCode,
nsICSSDeclaration* aDeclaration)
{
PRInt32 parsed;
if (ParseVariant(aErrorCode, aDeclaration, PROP_TEXT_SHADOW_X,
VARIANT_HC | VARIANT_LENGTH | VARIANT_NONE,
nsnull, parsed)) {
if ((VARIANT_COLOR == parsed) || (VARIANT_LENGTH == parsed)) {
nsCSSText* text;
aDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&text);
if (nsnull != text) {
nsCSSShadow* shadow = text->mTextShadow;
while (nsnull != shadow) {
nsCSSValue value;
PRBool haveColor = PR_FALSE;
if (VARIANT_COLOR == parsed) {
haveColor = PR_TRUE;
shadow->mColor = shadow->mXOffset;
shadow->mXOffset.Reset();
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull, parsed)) {
shadow->mXOffset = value;
}
else {
break;
}
}
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull, parsed)) {
shadow->mYOffset = value;
}
else {
break;
}
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull, parsed)) {
shadow->mRadius = value;
} // optional
if (PR_FALSE == haveColor) {
if (ParseVariant(aErrorCode, value, VARIANT_COLOR, nsnull, parsed)) {
shadow->mColor = value;
}
}
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
shadow->mNext = new nsCSSShadow();
shadow = shadow->mNext;
if ((nsnull != shadow) &&
ParseVariant(aErrorCode, value, VARIANT_COLOR | VARIANT_LENGTH,
nsnull, parsed)) {
shadow->mXOffset = value;
}
else {
break;
}
}
else {
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
return PR_TRUE;
}
break;
}
}
}
nsCSSValue nullValue;
aDeclaration->AppendValue(PROP_TEXT_SHADOW_COLOR, nullValue);
aDeclaration->AppendValue(PROP_TEXT_SHADOW_X, nullValue);
aDeclaration->AppendValue(PROP_TEXT_SHADOW_Y, nullValue);
aDeclaration->AppendValue(PROP_TEXT_SHADOW_RADIUS, nullValue);
return PR_FALSE;
}
return PR_TRUE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00
return PR_FALSE;
1998-04-14 00:24:54 +04:00
}
1998-10-27 02:22:40 +03:00