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"
|
1998-07-18 03:00:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-28 22:39:42 +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
|
|
|
|
|
|
|
struct Selector {
|
1998-09-30 03:50:09 +04:00
|
|
|
nsAutoString mTag; // weight 1
|
|
|
|
nsAutoString mID; // weight 100
|
|
|
|
nsAutoString mClass; // weight 10
|
|
|
|
nsAutoString mPseudoClass; // weight 10 (== class)
|
|
|
|
nsAutoString mPseudoElement; // weight 10 (== class) ??
|
|
|
|
|
|
|
|
PRUint32 mMask; // which fields have values
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
Selector();
|
|
|
|
~Selector();
|
|
|
|
|
|
|
|
PRInt32 Weight() const;
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Dump() const;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
1998-05-19 01:07:54 +04:00
|
|
|
#define SELECTOR_TAG 0x01
|
|
|
|
#define SELECTOR_ID 0x02
|
|
|
|
#define SELECTOR_CLASS 0x04
|
|
|
|
#define SELECTOR_PSEUDO_CLASS 0x08
|
|
|
|
#define SELECTOR_PSEUDO_ELEMENT 0x10
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#define SELECTOR_WEIGHT_BASE 10
|
|
|
|
|
|
|
|
Selector::Selector()
|
|
|
|
{
|
|
|
|
mMask = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Selector::~Selector()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 Selector::Weight() const
|
|
|
|
{
|
|
|
|
return (((0 != (SELECTOR_TAG & mMask)) ? 1 : 0) +
|
|
|
|
((0 != (SELECTOR_ID & mMask)) ? (SELECTOR_WEIGHT_BASE * SELECTOR_WEIGHT_BASE) : 0) +
|
1998-05-19 01:07:54 +04:00
|
|
|
((0 != ((SELECTOR_CLASS | SELECTOR_PSEUDO_CLASS | SELECTOR_PSEUDO_ELEMENT) & mMask)) ? SELECTOR_WEIGHT_BASE : 0));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Selector::Dump() const
|
|
|
|
{
|
|
|
|
PRBool needSpace = PR_FALSE;
|
|
|
|
if (mTag.Length() > 0) {
|
|
|
|
fputs(mTag, stdout);
|
|
|
|
needSpace = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mID.Length() > 0) {
|
|
|
|
if (needSpace) fputs(" ", stdout);
|
|
|
|
fputs("#", stdout);
|
|
|
|
fputs(mID, stdout);
|
|
|
|
needSpace = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mClass.Length() > 0) {
|
|
|
|
if (needSpace) fputs(" ", stdout);
|
|
|
|
fputs(".", stdout);
|
|
|
|
fputs(mClass, stdout);
|
|
|
|
needSpace = PR_TRUE;
|
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
if (mPseudoClass.Length() > 0) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if (needSpace) fputs(" ", stdout);
|
|
|
|
fputs(":", stdout);
|
1998-05-19 01:07:54 +04:00
|
|
|
fputs(mPseudoClass, stdout);
|
|
|
|
needSpace = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mPseudoElement.Length() > 0) {
|
|
|
|
if (needSpace) fputs(" ", stdout);
|
|
|
|
fputs(":", stdout);
|
|
|
|
fputs(mPseudoElement, stdout);
|
1998-04-14 00:24:54 +04:00
|
|
|
needSpace = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// e.g. "P B, H1 B { ... }" has a selector list with two elements,
|
|
|
|
// each of which has two selectors.
|
|
|
|
struct SelectorList {
|
|
|
|
SelectorList* mNext;
|
|
|
|
nsVoidArray mSelectors;
|
|
|
|
|
|
|
|
SelectorList();
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void AddSelector(Selector* aSelector) {
|
|
|
|
mSelectors.AppendElement(aSelector);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Dump();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
~SelectorList();
|
|
|
|
};
|
|
|
|
|
|
|
|
SelectorList::SelectorList()
|
|
|
|
{
|
|
|
|
mNext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectorList::~SelectorList()
|
|
|
|
{
|
|
|
|
PRInt32 n = mSelectors.Count();
|
|
|
|
for (PRInt32 i = 0; i < n; i++) {
|
|
|
|
Selector* sel = (Selector*) mSelectors.ElementAt(i);
|
|
|
|
delete sel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectorList::Destroy()
|
|
|
|
{
|
|
|
|
SelectorList* list = this;
|
|
|
|
while (nsnull != list) {
|
|
|
|
SelectorList* next = list->mNext;
|
|
|
|
delete list;
|
|
|
|
list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void SelectorList::Dump()
|
|
|
|
{
|
|
|
|
PRInt32 n = mSelectors.Count();
|
|
|
|
for (PRInt32 i = 0; i < n; i++) {
|
|
|
|
Selector* sel = (Selector*) mSelectors.ElementAt(i);
|
|
|
|
sel->Dump();
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
if (mNext) {
|
|
|
|
fputs(", ", stdout);
|
|
|
|
mNext->Dump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Your basic top-down recursive descent style parser
|
|
|
|
class CSSParserImpl : public nsICSSParser {
|
|
|
|
public:
|
|
|
|
CSSParserImpl();
|
|
|
|
CSSParserImpl(nsICSSStyleSheet* aSheet);
|
|
|
|
~CSSParserImpl();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
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-05-28 22:39:42 +04: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
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
|
|
|
|
nsIURL* aBaseURL,
|
|
|
|
nsIStyleRule*& aResult);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
PRBool ParseSelectorGroup(PRInt32& aErrorCode, SelectorList* aListHead);
|
|
|
|
PRBool ParseSelectorList(PRInt32& aErrorCode, SelectorList* aListHead);
|
|
|
|
PRBool ParseSelector(PRInt32& aErrorCode, Selector* aSelectorResult);
|
|
|
|
nsICSSDeclaration* ParseDeclarationBlock(PRInt32& aErrorCode,
|
1998-05-28 22:39:42 +04:00
|
|
|
PRBool aCheckForBraces);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ParseDeclaration(PRInt32& aErrorCode,
|
1998-05-28 22:39:42 +04:00
|
|
|
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 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;
|
1998-10-28 04:12:38 +03:00
|
|
|
|
|
|
|
PRBool mNavQuirkMode;
|
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();
|
|
|
|
mScanner = nsnull;
|
|
|
|
mSheet = nsnull;
|
|
|
|
mHavePushBack = PR_FALSE;
|
1998-10-28 04:12:38 +03:00
|
|
|
mNavQuirkMode = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSParserImpl::CSSParserImpl(nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mScanner = nsnull;
|
1998-10-05 09:11:18 +04:00
|
|
|
mSheet = aSheet; NS_ADDREF(aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
mHavePushBack = PR_FALSE;
|
1998-10-28 04:12:38 +03:00
|
|
|
mNavQuirkMode = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(CSSParserImpl,kICSSParserIID)
|
|
|
|
|
|
|
|
CSSParserImpl::~CSSParserImpl()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mSheet);
|
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
NS_METHOD
|
|
|
|
CSSParserImpl::GetInfoMask(PRUint32& aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-28 22:39:42 +04:00
|
|
|
aResult = NS_CSS_GETINFO_CSS1 | NS_CSS_GETINFO_CSSP;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
NS_METHOD
|
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-05-28 22:39:42 +04:00
|
|
|
NS_METHOD
|
|
|
|
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
|
|
|
{
|
|
|
|
if (nsnull == mSheet) {
|
|
|
|
NS_NewCSSStyleSheet(&mSheet, aInputURL);
|
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
PRInt32 errorCode = NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
mScanner = new nsCSSScanner();
|
|
|
|
mScanner->Init(aInput);
|
|
|
|
mURL = aInputURL;
|
1998-10-05 09:11:18 +04:00
|
|
|
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);
|
1998-05-28 22:39:42 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
|
|
|
|
nsIURL* aBaseURL,
|
|
|
|
nsIStyleRule*& aResult)
|
|
|
|
{
|
|
|
|
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);
|
1998-05-28 22:39:42 +04:00
|
|
|
if (nsnull != declaration) {
|
|
|
|
// Create a style rule for the delcaration
|
|
|
|
nsICSSStyleRule* rule = nsnull;
|
|
|
|
NS_NewCSSStyleRule(&rule, nsCSSSelector());
|
|
|
|
rule->SetDeclaration(declaration);
|
|
|
|
aResult = rule;
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_RELEASE(declaration);
|
1998-05-28 22:39:42 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mScanner;
|
|
|
|
mScanner = nsnull;
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-25 04:51:45 +04:00
|
|
|
NS_METHOD
|
1998-09-30 03:50:09 +04:00
|
|
|
CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
|
|
|
|
nsIURL* aBaseURL,
|
|
|
|
nsICSSDeclaration* aDeclaration,
|
|
|
|
PRInt32* aHint)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
1998-09-25 04:51:45 +04:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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-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;
|
1998-11-26 08:16:22 +03:00
|
|
|
aErrorCode = NS_NewURL(&url, mURL, cp);
|
|
|
|
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
|
|
|
|
|
|
|
|
PRInt32 ec;
|
|
|
|
nsIInputStream* in = url->Open(&ec);
|
|
|
|
if (nsnull == in) {
|
|
|
|
// 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)) {
|
|
|
|
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-10-06 05:39:33 +04:00
|
|
|
|
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, ')');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
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)) {
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
|
|
|
if (';' == symbol) {
|
|
|
|
break;
|
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
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, ']');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
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
|
|
|
|
SelectorList *slist = new SelectorList();
|
|
|
|
if (!ParseSelectorList(aErrorCode, slist)) {
|
|
|
|
SkipRuleSet(aErrorCode);
|
|
|
|
slist->Destroy();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next parse the declaration block
|
1998-05-28 22:39:42 +04:00
|
|
|
nsICSSDeclaration* declaration = ParseDeclarationBlock(aErrorCode, PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == declaration) {
|
|
|
|
// XXX skip something here
|
|
|
|
slist->Destroy();
|
|
|
|
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;
|
|
|
|
nsCSSSelector selector;
|
1998-05-19 01:07:54 +04:00
|
|
|
nsICSSStyleRule* rule = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
while (nsnull != list) {
|
|
|
|
PRInt32 selIndex = list->mSelectors.Count();
|
|
|
|
|
|
|
|
Selector* sel = (Selector*)list->mSelectors[--selIndex];
|
1998-05-19 01:07:54 +04:00
|
|
|
if (0 < sel->mPseudoElement.Length()) { // only pseudo elements at end selector
|
|
|
|
nsString nullStr;
|
|
|
|
selector.Set(sel->mPseudoElement, nullStr, nullStr, nullStr);
|
|
|
|
NS_NewCSSStyleRule(&rule, selector);
|
|
|
|
}
|
|
|
|
selector.Set(sel->mTag, sel->mID, sel->mClass, sel->mPseudoClass);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 weight = sel->Weight();
|
|
|
|
|
1998-05-19 01:07:54 +04:00
|
|
|
if (nsnull == rule) {
|
|
|
|
NS_NewCSSStyleRule(&rule, selector);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rule->AddSelector(selector);
|
|
|
|
}
|
|
|
|
if (nsnull != rule) {
|
1998-04-14 00:24:54 +04:00
|
|
|
while (--selIndex >= 0) {
|
|
|
|
Selector* sel = (Selector*)list->mSelectors[selIndex];
|
1998-05-19 01:07:54 +04:00
|
|
|
selector.Set(sel->mTag, sel->mID, sel->mClass, sel->mPseudoClass);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
rule->AddSelector(selector);
|
|
|
|
weight += sel->Weight();
|
|
|
|
}
|
|
|
|
rule->SetDeclaration(declaration);
|
|
|
|
rule->SetWeight(weight);
|
|
|
|
// rule->List();
|
|
|
|
mSheet->AppendStyleRule(rule);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release temporary storage
|
|
|
|
slist->Destroy();
|
|
|
|
NS_RELEASE(declaration);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorList(PRInt32& aErrorCode,
|
1998-04-14 00:24:54 +04:00
|
|
|
SelectorList* aListHead)
|
|
|
|
{
|
|
|
|
if (!ParseSelectorGroup(aErrorCode, aListHead)) {
|
|
|
|
// must have at least one selector group
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After that there must either be a "," or a "{"
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol != tk->mType) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (',' == tk->mSymbol) {
|
|
|
|
// Another selector group must follow
|
|
|
|
SelectorList* newList = new SelectorList();
|
|
|
|
if (!ParseSelectorGroup(aErrorCode, newList)) {
|
|
|
|
newList->Destroy();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// add new list to the end of the selector list
|
|
|
|
aListHead->mNext = newList;
|
|
|
|
aListHead = newList;
|
|
|
|
continue;
|
|
|
|
} else if ('{' == tk->mSymbol) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorGroup(PRInt32& aErrorCode,
|
1998-04-14 00:24:54 +04:00
|
|
|
SelectorList* aList)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
Selector* sel = new Selector();
|
|
|
|
if (!ParseSelector(aErrorCode, sel)) {
|
|
|
|
delete sel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aList->AddSelector(sel);
|
|
|
|
}
|
|
|
|
return (PRBool) (aList->mSelectors.Count() > 0);
|
|
|
|
}
|
|
|
|
|
1998-05-19 01:07:54 +04:00
|
|
|
static PRBool IsPseudoClass(const nsString& aBuffer)
|
|
|
|
{
|
|
|
|
return (aBuffer.EqualsIgnoreCase("link") ||
|
|
|
|
aBuffer.EqualsIgnoreCase("visited") ||
|
|
|
|
aBuffer.EqualsIgnoreCase("hover") ||
|
1998-05-19 04:09:29 +04:00
|
|
|
aBuffer.EqualsIgnoreCase("out-of-date") || // our extension
|
1998-05-19 01:07:54 +04:00
|
|
|
aBuffer.EqualsIgnoreCase("active"));
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
1998-09-25 05:50:34 +04:00
|
|
|
* These are the 31 possible kinds of CSS1 style selectors:
|
|
|
|
* (but there are 50 ways to leave your lover)
|
|
|
|
* [*] means it can repeat
|
1998-04-14 00:24:54 +04:00
|
|
|
* <UL>
|
|
|
|
* <LI>Tag
|
|
|
|
* <LI>Tag#Id
|
1998-09-25 05:50:34 +04:00
|
|
|
* <LI>Tag#Id.Class[*]
|
|
|
|
* <LI>Tag#Id.Class[*]:PseudoClass[*]
|
|
|
|
* <LI>Tag#Id.Class[*]:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>Tag#Id.Class[*]:PseudoElement
|
|
|
|
* <LI>Tag#Id:PseudoClass[*]
|
|
|
|
* <LI>Tag#Id:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>Tag#Id:PseudoElement
|
|
|
|
* <LI>Tag.Class[*]
|
|
|
|
* <LI>Tag.Class[*]:PseudoClass[*]
|
|
|
|
* <LI>Tag.Class[*]:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>Tag.Class[*]:PseudoElement
|
|
|
|
* <LI>Tag:PseudoClass[*]
|
|
|
|
* <LI>Tag:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>Tag:PseudoElement
|
1998-04-14 00:24:54 +04:00
|
|
|
* <LI>#Id
|
1998-09-25 05:50:34 +04:00
|
|
|
* <LI>#Id.Class[*]
|
|
|
|
* <LI>#Id.Class[*]:PseudoClass[*]
|
|
|
|
* <LI>#Id.Class[*]:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>#Id.Class[*]:PseudoElement
|
|
|
|
* <LI>#Id:PseudoClass[*]
|
|
|
|
* <LI>#Id:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>#Id:PseudoElement
|
|
|
|
* <LI>.Class[*]
|
|
|
|
* <LI>.Class[*]:PseudoClass[*]
|
|
|
|
* <LI>.Class[*]:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>.Class[*]:PseudoElement
|
|
|
|
* <LI>:PseudoClass[*]
|
|
|
|
* <LI>:PseudoClass[*]:PseudoElement
|
|
|
|
* <LI>:PseudoElement
|
1998-04-14 00:24:54 +04:00
|
|
|
* </UL>
|
|
|
|
*/
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelector(PRInt32& aErrorCode,
|
1998-04-14 00:24:54 +04:00
|
|
|
Selector* aSelectorResult)
|
|
|
|
{
|
|
|
|
PRUint32 mask = 0;
|
1998-05-19 01:07:54 +04:00
|
|
|
aSelectorResult->mTag.Truncate(0);
|
|
|
|
aSelectorResult->mClass.Truncate(0);
|
|
|
|
aSelectorResult->mID.Truncate(0);
|
|
|
|
aSelectorResult->mPseudoClass.Truncate(0);
|
|
|
|
aSelectorResult->mPseudoElement.Truncate(0);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == tk->mType) {
|
|
|
|
// tag
|
|
|
|
mask |= SELECTOR_TAG;
|
|
|
|
aSelectorResult->mTag.Append(tk->mIdent);
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof is ok (here!)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eCSSToken_ID == tk->mType) {
|
|
|
|
// #id
|
1998-09-10 05:18:06 +04:00
|
|
|
if ((0 < tk->mIdent.Length()) && (nsString::IsAlpha(tk->mIdent.CharAt(0)))) { // verify is legal ID
|
1998-07-17 09:50:07 +04:00
|
|
|
mask |= SELECTOR_ID;
|
|
|
|
aSelectorResult->mID.Append(tk->mIdent);
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof is ok (here!)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == tk->mType) && ('.' == tk->mSymbol)) {
|
|
|
|
// .class
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != tk->mType) {
|
|
|
|
// malformed selector
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
mask |= SELECTOR_CLASS;
|
1998-04-14 00:24:54 +04:00
|
|
|
aSelectorResult->mClass.Append(tk->mIdent);
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof is ok (here!)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == tk->mType) && (':' == tk->mSymbol)) {
|
|
|
|
// :pseudo
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != tk->mType) {
|
|
|
|
// malformed selector
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
if (IsPseudoClass(tk->mIdent)) {
|
|
|
|
mask |= SELECTOR_PSEUDO_CLASS;
|
|
|
|
aSelectorResult->mPseudoClass.Append(tk->mIdent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mask |= SELECTOR_PSEUDO_ELEMENT;
|
|
|
|
aSelectorResult->mPseudoElement.Append(':'); // keep the colon
|
|
|
|
aSelectorResult->mPseudoElement.Append(tk->mIdent);
|
|
|
|
}
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof is ok (here!)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == tk->mType) && (':' == tk->mSymbol)) {
|
|
|
|
// :pseudo
|
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
// premature eof
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != tk->mType) {
|
|
|
|
// malformed selector
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (! IsPseudoClass(tk->mIdent)) {
|
|
|
|
mask |= SELECTOR_PSEUDO_ELEMENT;
|
|
|
|
aSelectorResult->mPseudoElement.Truncate(0);
|
|
|
|
aSelectorResult->mPseudoElement.Append(':'); // keep the colon
|
|
|
|
aSelectorResult->mPseudoElement.Append(tk->mIdent);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
tk = nsnull;
|
|
|
|
}
|
|
|
|
if (nsnull != tk) {
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
if (mask == 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
aSelectorResult->mMask = mask;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
nsICSSDeclaration*
|
1998-10-27 02:22:40 +03:00
|
|
|
CSSParserImpl::ParseDeclarationBlock(PRInt32& aErrorCode,
|
1998-05-28 22:39:42 +04:00
|
|
|
PRBool aCheckForBraces)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-28 22:39:42 +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)) {
|
1998-05-14 02:40:54 +04:00
|
|
|
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)) {
|
1998-05-14 02:40:54 +04:00
|
|
|
count++; // count declarations
|
|
|
|
}
|
|
|
|
else {
|
1998-05-28 22:39:42 +04:00
|
|
|
if (!SkipDeclaration(aErrorCode, aCheckForBraces)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
1998-05-14 02:40:54 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-05-28 03:38:16 +04:00
|
|
|
PRBool
|
1998-10-27 02:22:40 +03:00
|
|
|
CSSParserImpl::ParseDeclaration(PRInt32& aErrorCode,
|
1998-05-28 22:39:42 +04:00
|
|
|
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;
|
1998-09-25 05:50:34 +04:00
|
|
|
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) {
|
1998-09-25 05:50:34 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-05-28 03:38:16 +04:00
|
|
|
// See if the declaration is followed by a "!important" declaration
|
|
|
|
PRBool isImportant = PR_FALSE;
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
1998-05-28 22:39:42 +04:00
|
|
|
if (aCheckForBraces) {
|
|
|
|
// Premature eof is not ok when proper termination is mandated
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-05-28 03:38:16 +04:00
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
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;
|
1998-05-28 03:38:16 +04:00
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
else {
|
|
|
|
// Not a !important declaration
|
1998-05-28 03:38:16 +04:00
|
|
|
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-05-28 03:38:16 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Make sure valid property declaration is terminated with either a
|
1998-05-28 22:39:42 +04:00
|
|
|
// 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)) {
|
1998-05-28 22:39:42 +04:00
|
|
|
if (aCheckForBraces) {
|
|
|
|
// Premature eof is not ok
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-05-28 03:38:16 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
if (';' == tk->mSymbol) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
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)
|
1998-05-13 02:56:18 +04:00
|
|
|
#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)
|
1998-05-13 02:56:18 +04:00
|
|
|
#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)
|
1998-05-13 02:56:18 +04:00
|
|
|
#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)
|
1998-05-28 06:02:43 +04:00
|
|
|
#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::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;
|
|
|
|
}
|
1998-10-28 04:12:38 +03:00
|
|
|
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;
|
|
|
|
nsString baseURL;
|
|
|
|
nsresult rv = NS_MakeAbsoluteURL(mURL, baseURL, tk->mIdent, absURL);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
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 ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_AHLP, nsnull, parsed);
|
|
|
|
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);
|
1998-04-26 07:47:37 +04:00
|
|
|
case PROP_CURSOR:
|
1998-10-27 02:22:40 +03:00
|
|
|
return ParseCursor(aErrorCode, aDeclaration);
|
1998-04-26 07:47:37 +04:00
|
|
|
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:
|
1998-10-27 02:22:40 +03:00
|
|
|
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HKLP,
|
|
|
|
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:
|
1998-10-27 02:22:40 +03:00
|
|
|
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLPN | VARIANT_NORMAL,
|
|
|
|
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:
|
1998-10-27 02:22:40 +03:00
|
|
|
return ParseVariant(aErrorCode, aDeclaration, aPropID, VARIANT_HLP, nsnull, parsed);
|
|
|
|
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,
|
1998-07-17 09:50:07 +04:00
|
|
|
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,
|
1998-09-26 03:35:55 +04:00
|
|
|
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,
|
1998-07-17 09:50:07 +04:00
|
|
|
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,
|
1998-07-17 09:50:07 +04:00
|
|
|
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],
|
1998-07-17 09:50:07 +04:00
|
|
|
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);
|
1998-05-13 02:56:18 +04:00
|
|
|
}
|
|
|
|
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) {
|
1998-04-28 19:24:44 +04:00
|
|
|
// 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(','));
|
|
|
|
}
|
1998-08-07 06:17:56 +04:00
|
|
|
family.Append(tk->mSymbol); // replace the quotes
|
1998-04-14 00:24:54 +04:00
|
|
|
family.Append(tk->mIdent);
|
1998-08-07 06:17:56 +04:00
|
|
|
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
|
|
|
|