2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2000-08-05 08:40:03 +04:00
|
|
|
* emk <VYV03354@nifty.ne.jp>
|
2001-02-13 17:06:29 +03:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
2001-03-06 04:57:30 +03:00
|
|
|
* L. David Baron <dbaron@fas.harvard.edu>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSParser.h"
|
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "nsCSSKeywords.h"
|
|
|
|
#include "nsCSSScanner.h"
|
1999-05-19 03:12:17 +04:00
|
|
|
#include "nsICSSLoader.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-06-10 09:25:23 +04:00
|
|
|
#include "nsICSSImportRule.h"
|
|
|
|
#include "nsICSSMediaRule.h"
|
|
|
|
#include "nsICSSNameSpaceRule.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIUnicharInputStream.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
2002-01-16 01:43:37 +03:00
|
|
|
#include "nsCSSDeclaration.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIURL.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-07-21 03:53:03 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsString.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-08 10:08:38 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsVoidArray.h"
|
1999-06-10 09:25:23 +04:00
|
|
|
#include "nsISupportsArray.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsColor.h"
|
1998-07-18 03:00:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
1998-12-11 05:50:43 +03:00
|
|
|
#include "nsCSSAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsINameSpace.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsThemeConstants.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
|
1999-02-10 11:37:52 +03:00
|
|
|
// verify ! is followed by important and nothing else
|
1998-05-28 22:39:42 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-08-24 17:45:48 +04:00
|
|
|
#define ENABLE_OUTLINE // un-comment this to enable the outline properties (bug 9816)
|
|
|
|
// XXX un-commenting for temporary fix for nsbeta3+ Bug 48973
|
|
|
|
// so we can use "mozoutline
|
|
|
|
|
2000-08-08 04:34:42 +04:00
|
|
|
//#define ENABLE_COUNTERS // un-comment this to enable counters (bug 15174)
|
2000-03-23 17:45:04 +03:00
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(SelectorList)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// e.g. "P B, H1 B { ... }" has a selector list with two elements,
|
|
|
|
// each of which has two selectors.
|
|
|
|
struct SelectorList {
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList(void);
|
|
|
|
~SelectorList(void);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
void AddSelector(const nsCSSSelector& aSelector);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
1998-12-11 05:50:43 +03:00
|
|
|
void Dump(void);
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
|
|
|
|
1999-02-27 10:15:59 +03:00
|
|
|
nsCSSSelector* mSelectors;
|
|
|
|
PRInt32 mWeight;
|
|
|
|
SelectorList* mNext;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList::SelectorList(void)
|
|
|
|
: mSelectors(nsnull),
|
|
|
|
mNext(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(SelectorList);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectorList::~SelectorList()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(SelectorList);
|
1998-12-11 05:50:43 +03:00
|
|
|
nsCSSSelector* sel = mSelectors;
|
|
|
|
while (nsnull != sel) {
|
|
|
|
nsCSSSelector* dead = sel;
|
|
|
|
sel = sel->mNext;
|
|
|
|
delete dead;
|
|
|
|
}
|
|
|
|
if (nsnull != mNext) {
|
|
|
|
delete mNext;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
void SelectorList::AddSelector(const nsCSSSelector& aSelector)
|
|
|
|
{ // prepend to list
|
|
|
|
nsCSSSelector* newSel = new nsCSSSelector(aSelector);
|
1999-02-10 11:37:52 +03:00
|
|
|
if (nsnull != newSel) {
|
|
|
|
newSel->mNext = mSelectors;
|
|
|
|
mSelectors = newSel;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void SelectorList::Dump()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Your basic top-down recursive descent style parser
|
|
|
|
class CSSParserImpl : public nsICSSParser {
|
|
|
|
public:
|
|
|
|
CSSParserImpl();
|
1999-02-12 20:45:58 +03:00
|
|
|
virtual ~CSSParserImpl();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
NS_IMETHOD Init(nsICSSStyleSheet* aSheet);
|
|
|
|
|
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-12-21 08:58:58 +03:00
|
|
|
NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive);
|
1998-12-11 05:50:43 +03:00
|
|
|
|
1999-07-07 05:29:49 +04:00
|
|
|
NS_IMETHOD SetQuirkMode(PRBool aQuirkMode);
|
|
|
|
|
1999-05-19 03:12:17 +04:00
|
|
|
NS_IMETHOD SetChildLoader(nsICSSLoader* aChildLoader);
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aInputURL,
|
1998-11-26 04:34:53 +03:00
|
|
|
nsICSSStyleSheet*& aResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIStyleRule** aResult);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool aParseOnlyOneDecl,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint* aHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD ParseRule(const nsAString& aRule,
|
2001-09-05 04:00:18 +04:00
|
|
|
nsIURI* aBaseURL,
|
2001-09-06 17:14:35 +04:00
|
|
|
nsISupportsArray** aResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD ParseProperty(const nsAString& aPropName,
|
|
|
|
const nsAString& aPropValue,
|
2001-09-28 05:38:36 +04:00
|
|
|
nsIURI* aBaseURL,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint* aHint);
|
2001-09-28 05:38:36 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
void AppendRule(nsICSSRule* aRule);
|
2000-04-23 06:01:40 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
protected:
|
1999-09-22 05:19:29 +04:00
|
|
|
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI);
|
|
|
|
nsresult ReleaseScanner(void);
|
|
|
|
|
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();
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool ExpectSymbol(PRInt32& aErrorCode, PRUnichar aSymbol, PRBool aSkipWS);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ExpectEndProperty(PRInt32& aErrorCode, PRBool aSkipWS);
|
|
|
|
nsString* NextIdent(PRInt32& aErrorCode);
|
|
|
|
void SkipUntil(PRInt32& aErrorCode, PRUnichar aStopSymbol);
|
|
|
|
void SkipRuleSet(PRInt32& aErrorCode);
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool SkipAtRule(PRInt32& aErrorCode);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool SkipDeclaration(PRInt32& aErrorCode, PRBool aCheckForBraces);
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool PushGroup(nsICSSGroupRule* aRule);
|
|
|
|
void PopGroup(void);
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool ParseRuleSet(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseAtRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseCharsetRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseImportRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool GatherMedia(PRInt32& aErrorCode, nsString& aMedia, nsISupportsArray* aMediaAtoms);
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseMediaRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseNameSpaceRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool ProcessNameSpace(PRInt32& aErrorCode, const nsString& aPrefix,
|
2001-09-06 17:14:35 +04:00
|
|
|
const nsString& aURLSpec, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
|
|
|
PRBool ParseFontFaceRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParsePageRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
void ParseIDSelector(PRInt32& aDataMask, nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode);
|
|
|
|
void ParseClassSelector(PRInt32& aDataMask, nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode);
|
|
|
|
void ParsePseudoSelector(PRInt32& aDataMask, nsCSSSelector& aSelector,
|
2001-03-20 14:49:20 +03:00
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode,
|
|
|
|
PRBool aIsNegated);
|
2001-03-09 02:27:39 +03:00
|
|
|
void ParseAttributeSelector(PRInt32& aDataMask, nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode);
|
|
|
|
|
|
|
|
void ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
2001-03-20 14:49:20 +03:00
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode,
|
|
|
|
PRBool aIsNegated);
|
|
|
|
void ParseNegatedSimpleSelector(PRInt32& aDataMask, nsCSSSelector& aSelector,
|
2001-03-09 02:27:39 +03:00
|
|
|
PRInt32& aParsingStatus, PRInt32& aErrorCode);
|
2002-08-14 16:34:39 +04:00
|
|
|
void ParseLangSelector(nsCSSSelector& aSelector, PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode);
|
2001-03-09 02:27:39 +03:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
PRBool ParseSelectorList(PRInt32& aErrorCode, SelectorList*& aListHead);
|
|
|
|
PRBool ParseSelectorGroup(PRInt32& aErrorCode, SelectorList*& aListHead);
|
2001-03-07 02:07:33 +03:00
|
|
|
PRBool ParseSelector(PRInt32& aErrorCode, nsCSSSelector& aSelectorResult);
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* 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,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1998-09-30 03:50:09 +04:00
|
|
|
PRBool aCheckForBraces,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint);
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool ParseProperty(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsCSSProperty aPropID, nsChangeHint& aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool ParseSingleValueProperty(PRInt32& aErrorCode, nsCSSValue& aValue,
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSProperty aPropID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-02-16 00:25:31 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
PRBool ParseTreePseudoElement(PRInt32& aErrorCode, nsCSSSelector& aSelector);
|
2001-02-16 00:25:31 +03:00
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Property specific parsing routines
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseAppearance(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool ParseAzimuth(PRInt32& aErrorCode, nsCSSValue& aValue);
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseBackground(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBackgroundPosition(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorder(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorderColor(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorderColors(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint,
|
2001-12-05 11:35:05 +03:00
|
|
|
nsCSSProperty aProperty);
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseBorderSpacing(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool ParseBorderSide(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
const nsCSSProperty aPropIDs[], nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorderStyle(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorderWidth(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseBorderRadius(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseOutlineRadius(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseClip(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseContent(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool ParseCounterData(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsCSSProperty aPropID, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseCue(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseCursor(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseFont(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
1999-09-10 09:55:36 +04:00
|
|
|
PRBool ParseFontWeight(PRInt32& aErrorCode, nsCSSValue& aValue);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool ParseFamily(PRInt32& aErrorCode, nsCSSValue& aValue);
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseImageRegion(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseListStyle(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseMargin(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool ParseMarks(PRInt32& aErrorCode, nsCSSValue& aValue);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseOutline(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParsePadding(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParsePause(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParsePlayDuring(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseQuotes(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
|
|
|
PRBool ParseSize(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool ParseTextDecoration(PRInt32& aErrorCode, nsCSSValue& aValue);
|
2002-08-24 18:41:28 +04:00
|
|
|
PRBool ParseTextShadow(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Reused utility parsing routines
|
2002-01-16 01:43:37 +03:00
|
|
|
nsresult AppendValue(nsCSSDeclaration* aDeclaration, nsCSSProperty aPropID,
|
2002-08-24 18:41:28 +04:00
|
|
|
const nsCSSValue& aValue, nsChangeHint& aChangeHint);
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool ParseBoxProperties(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
const nsCSSProperty aPropIDs[], nsChangeHint& aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 ParseChoice(PRInt32& aErrorCode, nsCSSValue aValues[],
|
1999-07-18 04:31:37 +04:00
|
|
|
const nsCSSProperty aPropIDs[], PRInt32 aNumIDs);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ParseColor(PRInt32& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseColorComponent(PRInt32& aErrorCode, PRUint8& aComponent,
|
2002-09-14 09:28:26 +04:00
|
|
|
PRInt32& aType, char aStop);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ParseEnum(PRInt32& aErrorCode, nsCSSValue& aValue, const PRInt32 aKeywordTable[]);
|
1999-07-18 04:31:37 +04:00
|
|
|
PRInt32 SearchKeywordTable(nsCSSKeyword aKeyword, const PRInt32 aTable[]);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ParseVariant(PRInt32& aErrorCode, nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 aKeywordTable[]);
|
|
|
|
PRBool ParsePositiveVariant(PRInt32& aErrorCode, nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[]);
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool ParseCounter(PRInt32& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseAttr(PRInt32& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue);
|
2000-08-08 04:34:42 +04:00
|
|
|
PRBool TranslateDimension(PRInt32& aErrorCode, nsCSSValue& aValue, PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
float aNumber, const nsString& aUnit);
|
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;
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* mURL;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsICSSStyleSheet* mSheet;
|
1999-05-19 03:12:17 +04:00
|
|
|
PRInt32 mChildSheetCount;
|
|
|
|
nsICSSLoader* mChildLoader; // not ref counted, it owns us
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
enum nsCSSSection {
|
|
|
|
eCSSSection_Charset,
|
|
|
|
eCSSSection_Import,
|
|
|
|
eCSSSection_NameSpace,
|
|
|
|
eCSSSection_General
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCSSSection mSection;
|
1998-10-28 04:12:38 +03:00
|
|
|
|
|
|
|
PRBool mNavQuirkMode;
|
1998-12-21 08:58:58 +03:00
|
|
|
PRBool mCaseSensitive;
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
nsINameSpace* mNameSpace;
|
|
|
|
|
|
|
|
nsISupportsArray* mGroupStack;
|
2000-04-23 06:01:40 +04:00
|
|
|
|
2000-08-05 08:40:03 +04:00
|
|
|
PRBool mParsingCompoundProperty;
|
|
|
|
void SetParsingCompoundProperty(PRBool aBool) {mParsingCompoundProperty = aBool;};
|
|
|
|
PRBool IsParsingCompoundProperty(void) {return mParsingCompoundProperty;};
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PR_STATIC_CALLBACK(void) AppendRuleToArray(nsICSSRule* aRule, void* aArray)
|
|
|
|
{
|
|
|
|
nsISupportsArray* arr = (nsISupportsArray*) aArray;
|
|
|
|
arr->AppendElement(aRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void) AppendRuleToSheet(nsICSSRule* aRule, void* aParser)
|
|
|
|
{
|
|
|
|
CSSParserImpl* parser = (CSSParserImpl*) aParser;
|
|
|
|
parser->AppendRule(aRule);
|
|
|
|
}
|
|
|
|
|
2001-10-20 00:59:33 +04:00
|
|
|
NS_EXPORT nsresult
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_NewCSSParser(nsICSSParser** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
CSSParserImpl *it = new CSSParserImpl();
|
|
|
|
|
|
|
|
if (it == nsnull) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
return it->QueryInterface(NS_GET_IID(nsICSSParser), (void **) aInstancePtrResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
2002-07-09 08:28:58 +04:00
|
|
|
#define REPORT_UNEXPECTED(err_) \
|
|
|
|
mScanner->AddToError(err_)
|
2000-09-08 06:05:09 +04:00
|
|
|
|
2002-07-09 08:28:58 +04:00
|
|
|
#define REPORT_UNEXPECTED_EOF(err_) \
|
|
|
|
mScanner->AddToError(NS_LITERAL_STRING("Unexpected end of file while searching for ") + err_ + NS_LITERAL_STRING("."))
|
2000-09-08 06:05:09 +04:00
|
|
|
|
2002-07-09 08:28:58 +04:00
|
|
|
#define REPORT_UNEXPECTED_TOKEN(reason_) \
|
|
|
|
ReportUnexpectedToken(mScanner,mToken,reason_)
|
2000-09-06 06:27:46 +04:00
|
|
|
|
2001-03-06 04:57:30 +03:00
|
|
|
#define OUTPUT_ERROR() \
|
|
|
|
mScanner->OutputError()
|
|
|
|
|
|
|
|
#define CLEAR_ERROR() \
|
|
|
|
mScanner->ClearError()
|
|
|
|
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
static void ReportUnexpectedToken(nsCSSScanner *sc,
|
|
|
|
nsCSSToken& tok,
|
2002-03-24 01:56:05 +03:00
|
|
|
const nsAString& err)
|
2000-09-06 06:27:46 +04:00
|
|
|
{
|
2001-03-06 04:57:30 +03:00
|
|
|
nsAutoString error(err + NS_LITERAL_STRING(" '"));
|
2000-09-08 06:05:09 +04:00
|
|
|
tok.AppendToString(error);
|
2001-03-06 04:57:30 +03:00
|
|
|
error += NS_LITERAL_STRING("'.");
|
|
|
|
sc->AddToError(error);
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2002-07-09 08:28:58 +04:00
|
|
|
#define REPORT_UNEXPECTED(err_)
|
|
|
|
#define REPORT_UNEXPECTED_EOF(err_)
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN(reason_)
|
2001-03-06 04:57:30 +03:00
|
|
|
#define OUTPUT_ERROR()
|
|
|
|
#define CLEAR_ERROR()
|
2000-09-06 06:27:46 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
CSSParserImpl::CSSParserImpl()
|
1999-06-10 09:25:23 +04:00
|
|
|
: mToken(),
|
|
|
|
mHavePushBack(PR_FALSE),
|
|
|
|
mScanner(nsnull),
|
|
|
|
mURL(nsnull),
|
|
|
|
mSheet(nsnull),
|
|
|
|
mChildSheetCount(0),
|
|
|
|
mChildLoader(nsnull),
|
|
|
|
mSection(eCSSSection_Charset),
|
1999-07-07 05:29:49 +04:00
|
|
|
mNavQuirkMode(PR_FALSE),
|
1999-06-10 09:25:23 +04:00
|
|
|
mCaseSensitive(PR_FALSE),
|
|
|
|
mNameSpace(nsnull),
|
2000-09-06 06:27:46 +04:00
|
|
|
mGroupStack(nsnull),
|
|
|
|
mParsingCompoundProperty(PR_FALSE)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-09-07 21:13:19 +04:00
|
|
|
NS_INIT_ISUPPORTS();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::Init(nsICSSStyleSheet* aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-06-10 09:25:23 +04:00
|
|
|
NS_IF_RELEASE(mGroupStack);
|
|
|
|
NS_IF_RELEASE(mNameSpace);
|
|
|
|
NS_IF_RELEASE(mSheet);
|
|
|
|
mSheet = aSheet;
|
|
|
|
if (mSheet) {
|
|
|
|
NS_ADDREF(aSheet);
|
|
|
|
mSheet->StyleSheetCount(mChildSheetCount);
|
|
|
|
mSheet->GetNameSpace(mNameSpace);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(CSSParserImpl, nsICSSParser)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
CSSParserImpl::~CSSParserImpl()
|
|
|
|
{
|
1999-06-10 09:25:23 +04:00
|
|
|
NS_IF_RELEASE(mGroupStack);
|
|
|
|
NS_IF_RELEASE(mNameSpace);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_IF_RELEASE(mSheet);
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_IMETHODIMP
|
1998-05-28 22:39:42 +04:00
|
|
|
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-12-11 05:50:43 +03:00
|
|
|
NS_IMETHODIMP
|
1998-11-26 04:34:53 +03:00
|
|
|
CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null ptr");
|
|
|
|
if (nsnull == aSheet) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
if (aSheet != mSheet) {
|
|
|
|
// Switch to using the new sheet
|
1999-06-10 09:25:23 +04:00
|
|
|
NS_IF_RELEASE(mGroupStack);
|
|
|
|
NS_IF_RELEASE(mNameSpace);
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IF_RELEASE(mSheet);
|
|
|
|
mSheet = aSheet;
|
|
|
|
NS_ADDREF(mSheet);
|
1999-06-10 09:25:23 +04:00
|
|
|
mSheet->StyleSheetCount(mChildSheetCount);
|
|
|
|
mSheet->GetNameSpace(mNameSpace);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_IMETHODIMP
|
1998-12-21 08:58:58 +03:00
|
|
|
CSSParserImpl::SetCaseSensitive(PRBool aCaseSensitive)
|
1998-12-11 05:50:43 +03:00
|
|
|
{
|
1998-12-21 08:58:58 +03:00
|
|
|
mCaseSensitive = aCaseSensitive;
|
1998-12-11 05:50:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 05:29:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::SetQuirkMode(PRBool aQuirkMode)
|
|
|
|
{
|
|
|
|
mNavQuirkMode = aQuirkMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:12:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
|
|
|
|
{
|
|
|
|
mChildLoader = aChildLoader; // not ref counted, it owns us
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
nsresult
|
|
|
|
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(! mScanner, "already have scanner");
|
|
|
|
|
|
|
|
mScanner = new nsCSSScanner();
|
|
|
|
if (! mScanner) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
mScanner->Init(aInput, aURI);
|
1999-09-22 05:19:29 +04:00
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
mURL = aURI;
|
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CSSParserImpl::ReleaseScanner(void)
|
|
|
|
{
|
|
|
|
if (mScanner) {
|
|
|
|
delete mScanner;
|
|
|
|
mScanner = nsnull;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-05-28 22:39:42 +04:00
|
|
|
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aInputURL,
|
1998-11-26 04:34:53 +03:00
|
|
|
nsICSSStyleSheet*& aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-15 05:06:13 +03:00
|
|
|
NS_ASSERTION(nsnull != aInputURL, "need base URL");
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! mSheet) {
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_NewCSSStyleSheet(&mSheet, aInputURL);
|
1999-05-19 03:12:17 +04:00
|
|
|
mChildSheetCount = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! mSheet) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
PRInt32 errorCode = NS_OK;
|
1999-09-22 05:19:29 +04:00
|
|
|
|
|
|
|
nsresult result = InitScanner(aInput, aInputURL);
|
|
|
|
if (! NS_SUCCEEDED(result)) {
|
|
|
|
return result;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
PRInt32 ruleCount = 0;
|
|
|
|
mSheet->StyleRuleCount(ruleCount);
|
|
|
|
if (0 < ruleCount) {
|
|
|
|
nsICSSRule* lastRule = nsnull;
|
|
|
|
mSheet->GetStyleRuleAt(ruleCount - 1, lastRule);
|
|
|
|
if (lastRule) {
|
|
|
|
PRInt32 type;
|
|
|
|
lastRule->GetType(type);
|
|
|
|
switch (type) {
|
|
|
|
case nsICSSRule::CHARSET_RULE:
|
|
|
|
case nsICSSRule::IMPORT_RULE:
|
|
|
|
mSection = eCSSSection_Import;
|
|
|
|
break;
|
|
|
|
case nsICSSRule::NAMESPACE_RULE:
|
|
|
|
mSection = eCSSSection_NameSpace;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(lastRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSection = eCSSSection_Charset; // sheet is empty, any rules are fair
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
|
|
|
// Get next non-whitespace token
|
1998-10-27 02:22:40 +03:00
|
|
|
if (!GetToken(errorCode, PR_TRUE)) {
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-02-03 05:59:51 +03:00
|
|
|
if (eCSSToken_HTMLComment == tk->mType) {
|
|
|
|
continue; // legal here only
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (eCSSToken_AtKeyword == tk->mType) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ParseAtRule(errorCode, AppendRuleToSheet, this);
|
1998-04-14 00:24:54 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UngetToken();
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseRuleSet(errorCode, AppendRuleToSheet, this)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-09-22 05:19:29 +04:00
|
|
|
ReleaseScanner();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
aResult = mSheet;
|
|
|
|
NS_ADDREF(aResult);
|
1998-05-28 22:39:42 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
|
2001-09-18 03:59:30 +04:00
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIStyleRule** aResult)
|
1998-05-28 22:39:42 +04:00
|
|
|
{
|
1999-01-15 05:06:13 +03:00
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
|
|
|
|
2001-09-18 03:59:30 +04:00
|
|
|
// XXXldb XXXperf nsIUnicharInputStream is horrible! It makes us make
|
|
|
|
// a copy.
|
2001-11-29 11:48:53 +03:00
|
|
|
nsString* str = new nsAutoString(aAttributeValue);
|
1998-05-28 22:39:42 +04:00
|
|
|
if (nsnull == str) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsIUnicharInputStream* input = nsnull;
|
|
|
|
nsresult rv = NS_NewStringUnicharInputStream(&input, str);
|
|
|
|
if (NS_OK != rv) {
|
1999-02-10 11:37:52 +03:00
|
|
|
delete str;
|
1998-05-28 22:39:42 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
rv = InitScanner(input, aBaseURL);
|
1998-05-28 22:39:42 +04:00
|
|
|
NS_RELEASE(input);
|
1999-09-22 05:19:29 +04:00
|
|
|
if (! NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-05-28 22:39:42 +04:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
1998-05-28 22:39:42 +04:00
|
|
|
PRInt32 errorCode = NS_OK;
|
|
|
|
|
2001-09-18 03:59:30 +04:00
|
|
|
// In quirks mode, allow style declarations to have braces or not
|
|
|
|
// (bug 99554).
|
|
|
|
PRBool haveBraces;
|
|
|
|
if (mNavQuirkMode) {
|
|
|
|
GetToken(errorCode, PR_TRUE);
|
|
|
|
haveBraces = eCSSToken_Symbol == mToken.mType &&
|
|
|
|
'{' == mToken.mSymbol;
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
haveBraces = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* declaration =
|
2001-09-18 03:59:30 +04:00
|
|
|
ParseDeclarationBlock(errorCode, haveBraces);
|
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);
|
2001-09-18 03:59:30 +04:00
|
|
|
*aResult = rule;
|
1998-05-28 22:39:42 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-09-18 03:59:30 +04:00
|
|
|
*aResult = nsnull;
|
1998-05-28 22:39:42 +04:00
|
|
|
}
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
ReleaseScanner();
|
1998-05-28 22:39:42 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_IMETHODIMP
|
2002-08-24 18:41:28 +04:00
|
|
|
CSSParserImpl::ParseAndAppendDeclaration(const nsAString& aBuffer,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool aParseOnlyOneDecl,
|
|
|
|
nsChangeHint* aHint)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
1999-08-04 09:06:19 +04:00
|
|
|
// NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
1999-01-15 05:06:13 +03:00
|
|
|
|
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) {
|
1999-02-10 11:37:52 +03:00
|
|
|
delete str;
|
1998-09-25 04:51:45 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
rv = InitScanner(input, aBaseURL);
|
1998-09-25 04:51:45 +04:00
|
|
|
NS_RELEASE(input);
|
1999-09-22 05:19:29 +04:00
|
|
|
if (! NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-09-25 04:51:45 +04:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
1998-09-25 04:51:45 +04:00
|
|
|
PRInt32 errorCode = NS_OK;
|
|
|
|
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint hint = NS_STYLE_HINT_NONE;
|
1998-10-27 02:22:40 +03:00
|
|
|
|
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
|
|
|
|
2000-05-04 01:42:00 +04:00
|
|
|
do {
|
|
|
|
if (ParseDeclaration(errorCode, aDeclaration, PR_FALSE, hint)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
if (aHint) {
|
|
|
|
NS_UpdateHint(*aHint, hint);
|
2000-05-04 01:42:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (errorCode != -1) { // -1 means EOF so we ignore that
|
|
|
|
rv = errorCode;
|
|
|
|
}
|
|
|
|
|
2001-07-18 23:43:39 +04:00
|
|
|
if (NS_FAILED(errorCode))
|
|
|
|
break;
|
2002-03-12 18:28:27 +03:00
|
|
|
|
|
|
|
if (!SkipDeclaration(errorCode, PR_FALSE)) {
|
|
|
|
if (errorCode != -1) {
|
|
|
|
rv = errorCode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-05-04 01:42:00 +04:00
|
|
|
}
|
|
|
|
} while (!aParseOnlyOneDecl);
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
ReleaseScanner();
|
2000-05-04 01:42:00 +04:00
|
|
|
return rv;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSParserImpl::ParseRule(const nsAString& aRule,
|
2001-09-05 04:00:18 +04:00
|
|
|
nsIURI* aBaseURL,
|
2001-09-06 17:14:35 +04:00
|
|
|
nsISupportsArray** aResult)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsString* str = new nsString(aRule);
|
|
|
|
if (nsnull == str) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIUnicharInputStream> input = nsnull;
|
|
|
|
nsresult rv = NS_NewStringUnicharInputStream(getter_AddRefs(input), str);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-09-05 04:00:18 +04:00
|
|
|
delete str;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = InitScanner(input, aBaseURL);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
rv = NS_NewISupportsArray(aResult);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSection = eCSSSection_Charset; // callers are responsible for rejecting invalid rules.
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 errorCode = NS_OK;
|
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
// Get first non-whitespace token
|
|
|
|
if (!GetToken(errorCode, PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
REPORT_UNEXPECTED(
|
|
|
|
NS_LITERAL_STRING("Whitespace-only string given to be parsed as rule."));
|
2001-09-05 04:00:18 +04:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
} else if (eCSSToken_AtKeyword == tk->mType) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ParseAtRule(errorCode, AppendRuleToArray, *aResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
2001-09-06 17:14:35 +04:00
|
|
|
ParseRuleSet(errorCode, AppendRuleToArray, *aResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
OUTPUT_ERROR();
|
2001-09-05 04:00:18 +04:00
|
|
|
ReleaseScanner();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-28 05:38:36 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSParserImpl::ParseProperty(const nsAString& aPropName,
|
|
|
|
const nsAString& aPropValue,
|
2001-09-28 05:38:36 +04:00
|
|
|
nsIURI* aBaseURL,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint* aHint)
|
2001-09-28 05:38:36 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
|
|
|
NS_ASSERTION(nsnull != aDeclaration, "Need declaration to parse into!");
|
|
|
|
|
2001-11-29 11:48:53 +03:00
|
|
|
nsString* str = new nsAutoString(aPropValue);
|
2001-09-28 05:38:36 +04:00
|
|
|
if (!str) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUnicharInputStream> input;
|
|
|
|
nsresult rv = NS_NewStringUnicharInputStream(getter_AddRefs(input), str);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete str;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = InitScanner(input, aBaseURL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
PRInt32 errorCode = NS_OK;
|
|
|
|
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint hint = NS_STYLE_HINT_NONE;
|
2001-09-28 05:38:36 +04:00
|
|
|
|
|
|
|
if (aHint) {
|
|
|
|
*aHint = hint;
|
|
|
|
}
|
|
|
|
nsCSSProperty propID = nsCSSProps::LookupProperty(aPropName);
|
|
|
|
if (eCSSProperty_UNKNOWN == propID) { // unknown property
|
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Unknown property '") +
|
|
|
|
aPropName +
|
|
|
|
NS_LITERAL_STRING("'. Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! ParseProperty(errorCode, aDeclaration, propID, hint)) {
|
|
|
|
REPORT_UNEXPECTED(
|
|
|
|
NS_LITERAL_STRING("Error in parsing value for property '") +
|
|
|
|
aPropName +
|
|
|
|
NS_LITERAL_STRING("'. Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
if (errorCode != -1) { // -1 means EOF which we ignore
|
|
|
|
ReleaseScanner();
|
|
|
|
return errorCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CLEAR_ERROR();
|
|
|
|
|
2002-08-24 18:41:28 +04:00
|
|
|
if (aHint) {
|
|
|
|
NS_UpdateHint(*aHint, hint);
|
2001-09-28 05:38:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseScanner();
|
|
|
|
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,
|
1999-06-10 09:25:23 +04:00
|
|
|
PRUnichar aSymbol,
|
1998-04-14 00:24:54 +04:00
|
|
|
PRBool aSkipWS)
|
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, aSkipWS)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
if (mToken.IsSymbol(aSymbol)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
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)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE; // properties may end with eof
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == mToken.mType) &&
|
1999-02-10 11:37:52 +03:00
|
|
|
((';' == mToken.mSymbol) || ('!' == mToken.mSymbol) || ('}' == mToken.mSymbol))) {
|
|
|
|
// XXX need to verify that ! is only followed by "important [;|}]
|
|
|
|
// XXX this requires a multi-token pushback buffer
|
1998-10-27 02:22:40 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected end of value for property but found"));
|
1998-10-27 02:22:40 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsString* CSSParserImpl::NextIdent(PRInt32& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-09-06 06:27:46 +04:00
|
|
|
// XXX Error reporting?
|
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;
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool CSSParserImpl::SkipAtRule(PRInt32& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("end of unknown at-rule"));
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
if (eCSSToken_Symbol == mToken.mType) {
|
|
|
|
PRUnichar symbol = mToken.mSymbol;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (symbol == ';') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (symbol == '{') {
|
|
|
|
SkipUntil(aErrorCode, '}');
|
|
|
|
break;
|
|
|
|
} else if (symbol == '(') {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
} else if (symbol == '[') {
|
|
|
|
SkipUntil(aErrorCode, ']');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseAtRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
if ((mSection <= eCSSSection_Charset) &&
|
|
|
|
(mToken.mIdent.EqualsIgnoreCase("charset"))) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseCharsetRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_Import; // only one charset allowed
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((mSection <= eCSSSection_Import) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("import")) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseImportRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_Import;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((mSection <= eCSSSection_NameSpace) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("namespace")) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseNameSpaceRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_NameSpace;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mToken.mIdent.EqualsIgnoreCase("media")) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseMediaRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mToken.mIdent.EqualsIgnoreCase("font-face")) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParseFontFaceRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mToken.mIdent.EqualsIgnoreCase("page")) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (ParsePageRule(aErrorCode, aAppendFunc, aData)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unrecognized at-rule or error parsing at-rule"));
|
|
|
|
OUTPUT_ERROR();
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
// Skip over unsupported at rule, don't advance section
|
|
|
|
return SkipAtRule(aErrorCode);
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseCharsetRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
2002-08-06 09:26:41 +04:00
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("charset string in @charset rule"));
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_String != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected charset string but found"));
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString charset = mToken.mIdent;
|
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
NS_NewCSSCharsetRule(getter_AddRefs(rule), charset);
|
|
|
|
|
|
|
|
if (rule) {
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool CSSParserImpl::GatherMedia(PRInt32& aErrorCode, nsString& aMedia,
|
|
|
|
nsISupportsArray* aMediaAtoms)
|
1999-01-23 10:08:11 +03:00
|
|
|
{
|
1998-11-26 08:16:22 +03:00
|
|
|
PRBool first = PR_TRUE;
|
1999-02-03 05:59:51 +03:00
|
|
|
PRBool expectIdent = PR_TRUE;
|
1998-11-26 08:16:22 +03:00
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("end of media list in @import or @media rule"));
|
1998-11-26 08:16:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == mToken.mType) {
|
|
|
|
PRUnichar symbol = mToken.mSymbol;
|
1999-06-10 09:25:23 +04:00
|
|
|
if ((';' == symbol) || ('{' == symbol)) {
|
1998-11-26 08:16:22 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (',' != symbol) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected ',' in media list but found"));
|
1998-11-26 08:16:22 +03:00
|
|
|
UngetToken();
|
1999-06-10 09:25:23 +04:00
|
|
|
break;
|
1999-02-03 05:59:51 +03:00
|
|
|
} else if (expectIdent) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected identifier in media list but found"));
|
1999-02-03 05:59:51 +03:00
|
|
|
UngetToken();
|
1999-06-10 09:25:23 +04:00
|
|
|
break;
|
1999-02-03 05:59:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
expectIdent = PR_TRUE;
|
1998-11-26 08:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Ident == mToken.mType) {
|
1999-02-03 05:59:51 +03:00
|
|
|
if (expectIdent) {
|
|
|
|
if (! first) {
|
2001-12-16 14:58:03 +03:00
|
|
|
aMedia.Append(PRUnichar(','));
|
1999-02-03 05:59:51 +03:00
|
|
|
}
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent); // case insensitive from CSS - must be lower cased
|
1999-06-10 09:25:23 +04:00
|
|
|
if (aMediaAtoms) {
|
|
|
|
nsIAtom* medium = NS_NewAtom(mToken.mIdent);
|
|
|
|
aMediaAtoms->AppendElement(medium);
|
|
|
|
NS_RELEASE(medium);
|
|
|
|
}
|
1999-02-03 05:59:51 +03:00
|
|
|
aMedia.Append(mToken.mIdent);
|
|
|
|
first = PR_FALSE;
|
|
|
|
expectIdent = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected ',' in media list but found"));
|
1999-02-03 05:59:51 +03:00
|
|
|
UngetToken();
|
1999-06-10 09:25:23 +04:00
|
|
|
break;
|
1998-11-26 08:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
expectIdent
|
|
|
|
? NS_LITERAL_STRING("Expected identifier in media list but found")
|
|
|
|
: NS_LITERAL_STRING("Expected ',' in media list but found"));
|
1999-02-03 05:59:51 +03:00
|
|
|
UngetToken();
|
1998-11-26 08:16:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aMedia.Truncate();
|
1999-06-10 09:25:23 +04:00
|
|
|
if (aMediaAtoms) {
|
|
|
|
aMediaAtoms->Clear();
|
|
|
|
}
|
1998-11-26 08:16:22 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
// Parse a CSS2 import rule: "@import STRING | URL [medium [, mdeium]]"
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseImportRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("URI in @import rule"));
|
1998-04-14 00:24:54 +04:00
|
|
|
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;
|
1999-06-10 09:25:23 +04:00
|
|
|
if (GatherMedia(aErrorCode, media, nsnull)) {
|
1998-11-26 08:16:22 +03:00
|
|
|
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ProcessImport(aErrorCode, url, media, aAppendFunc, aData);
|
1998-11-26 08:16:22 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
else if ((eCSSToken_Function == mToken.mType) &&
|
|
|
|
(mToken.mIdent.EqualsIgnoreCase("url"))) {
|
1998-10-27 02:22:40 +03:00
|
|
|
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)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
if (GatherMedia(aErrorCode, media, nsnull)) {
|
1998-11-26 08:16:22 +03:00
|
|
|
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ProcessImport(aErrorCode, url, media, aAppendFunc, aData);
|
1998-11-26 08:16:22 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-03 05:59:51 +03:00
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unexpected token within @import:"));
|
1999-06-10 09:25:23 +04:00
|
|
|
// don't advance section, simply ignore invalid @import
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia, RuleAppendFunc aAppendFunc, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
nsCOMPtr<nsICSSImportRule> rule;
|
2001-09-06 17:14:35 +04:00
|
|
|
aErrorCode = NS_NewCSSImportRule(getter_AddRefs(rule), aURLSpec, aMedia);
|
|
|
|
if (NS_FAILED(aErrorCode)) {
|
|
|
|
return PR_FALSE;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
(*aAppendFunc)(rule, aData);
|
1999-06-10 09:25:23 +04:00
|
|
|
|
1999-05-19 03:12:17 +04:00
|
|
|
if (mChildLoader) {
|
2001-08-05 01:19:53 +04:00
|
|
|
nsCOMPtr<nsIURI> url;
|
2002-03-06 10:48:55 +03:00
|
|
|
aErrorCode = NS_NewURI(getter_AddRefs(url), aURLSpec, nsnull, mURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-05-19 03:12:17 +04:00
|
|
|
if (NS_FAILED(aErrorCode)) {
|
|
|
|
// import url is bad
|
|
|
|
// XXX log this somewhere for easier web page debugging
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
PRBool bContains = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(mSheet->ContainsStyleSheet(url,bContains)) &&
|
|
|
|
bContains != PR_TRUE ) { // don't allow circular references
|
2001-08-05 01:19:53 +04:00
|
|
|
mChildLoader->LoadChildSheet(mSheet, url, aMedia, kNameSpaceID_Unknown, mChildSheetCount++, rule);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
// Parse a CSS2 media rule: "@media medium [, medium] { ... }"
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseMediaRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
nsAutoString mediaStr;
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> media;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(media));
|
1999-06-10 09:25:23 +04:00
|
|
|
if (media) {
|
|
|
|
if (GatherMedia(aErrorCode, mediaStr, media)) {
|
2002-01-24 05:03:19 +03:00
|
|
|
if ((!mediaStr.IsEmpty()) &&
|
1999-06-10 09:25:23 +04:00
|
|
|
ExpectSymbol(aErrorCode, '{', PR_TRUE)) {
|
|
|
|
// push media rule on stack, loop over children
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsICSSMediaRule> rule;
|
|
|
|
NS_NewCSSMediaRule(getter_AddRefs(rule));
|
1999-06-10 09:25:23 +04:00
|
|
|
if (rule) {
|
|
|
|
if (PushGroup(rule)) {
|
|
|
|
|
|
|
|
nsCSSSection holdSection = mSection;
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// Get next non-whitespace token
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("end of @media rule"));
|
1999-06-10 09:25:23 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mToken.IsSymbol('}')) { // done!
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_AtKeyword == mToken.mType) {
|
|
|
|
SkipAtRule(aErrorCode); // @media cannot contain @rules
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UngetToken();
|
2001-09-06 17:14:35 +04:00
|
|
|
ParseRuleSet(aErrorCode, AppendRuleToSheet, this);
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
PopGroup();
|
|
|
|
|
|
|
|
if (ExpectSymbol(aErrorCode, '}', PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
// Append first, so when we do SetMedia() the rule
|
|
|
|
// knows what its stylesheet is.
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
rule->SetMedia(media);
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
mSection = holdSection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // failed to create rule, backup and skip block
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a CSS3 namespace rule: "@namespace [prefix] STRING | URL;"
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseNameSpaceRule(PRInt32& aErrorCode,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("namespace prefix in @namespace rule"));
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString prefix;
|
|
|
|
nsAutoString url;
|
|
|
|
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
prefix = mToken.mIdent;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(prefix); // always case insensitive, since stays within CSS
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("namespace URI in @namespace rule"));
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_String == mToken.mType) {
|
|
|
|
url = mToken.mIdent;
|
|
|
|
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ProcessNameSpace(aErrorCode, prefix, url, aAppendFunc, aData);
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((eCSSToken_Function == mToken.mType) &&
|
|
|
|
(mToken.mIdent.EqualsIgnoreCase("url"))) {
|
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
if (GetURLToken(aErrorCode, PR_TRUE)) {
|
|
|
|
if ((eCSSToken_String == mToken.mType) || (eCSSToken_URL == mToken.mType)) {
|
|
|
|
url = mToken.mIdent;
|
|
|
|
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
if (ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
2001-09-06 17:14:35 +04:00
|
|
|
ProcessNameSpace(aErrorCode, prefix, url, aAppendFunc, aData);
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unexpected token within @namespace:"));
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool CSSParserImpl::ProcessNameSpace(PRInt32& aErrorCode, const nsString& aPrefix,
|
2001-09-06 17:14:35 +04:00
|
|
|
const nsString& aURLSpec, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> rule;
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
1999-06-10 09:25:23 +04:00
|
|
|
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aPrefix.IsEmpty()) {
|
2001-09-05 04:00:18 +04:00
|
|
|
prefix = dont_AddRef(NS_NewAtom(aPrefix));
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_NewCSSNameSpaceRule(getter_AddRefs(rule), prefix, aURLSpec);
|
1999-06-10 09:25:23 +04:00
|
|
|
if (rule) {
|
2001-09-06 17:14:35 +04:00
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
NS_IF_RELEASE(mNameSpace);
|
|
|
|
mSheet->GetNameSpace(mNameSpace);
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseFontFaceRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
// XXX not yet implemented
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParsePageRule(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
// XXX not yet implemented
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
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)) {
|
2000-09-06 06:27:46 +04:00
|
|
|
if (aCheckForBraces) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("closing } of declaration block"));
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
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)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("closing } of invalid rule set"));
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
|
|
|
if ('{' == symbol) {
|
|
|
|
SkipUntil(aErrorCode, '}');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ('(' == symbol) {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
} else if ('[' == symbol) {
|
|
|
|
SkipUntil(aErrorCode, ']');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool CSSParserImpl::PushGroup(nsICSSGroupRule* aRule)
|
|
|
|
{
|
|
|
|
if (! mGroupStack) {
|
|
|
|
NS_NewISupportsArray(&mGroupStack);
|
|
|
|
}
|
|
|
|
if (mGroupStack) {
|
|
|
|
mGroupStack->AppendElement(aRule);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSParserImpl::PopGroup(void)
|
|
|
|
{
|
|
|
|
if (mGroupStack) {
|
|
|
|
PRUint32 count;
|
|
|
|
mGroupStack->Count(&count);
|
|
|
|
if (0 < count) {
|
|
|
|
mGroupStack->RemoveElementAt(count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSParserImpl::AppendRule(nsICSSRule* aRule)
|
|
|
|
{
|
|
|
|
PRUint32 count = 0;
|
|
|
|
if (mGroupStack) {
|
|
|
|
mGroupStack->Count(&count);
|
|
|
|
}
|
|
|
|
if (0 < count) {
|
|
|
|
nsICSSGroupRule* group = (nsICSSGroupRule*)mGroupStack->ElementAt(count - 1);
|
|
|
|
group->AppendStyleRule(aRule);
|
|
|
|
NS_RELEASE(group);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSheet->AppendStyleRule(aRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// First get the list of selectors for the rule
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList* slist = nsnull;
|
2001-01-22 07:03:48 +03:00
|
|
|
PRUint32 linenum = mScanner->GetLineNumber();
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! ParseSelectorList(aErrorCode, slist)) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(
|
|
|
|
NS_LITERAL_STRING("Ruleset ignored due to bad selector."));
|
|
|
|
OUTPUT_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
SkipRuleSet(aErrorCode);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_ASSERTION(nsnull != slist, "null selector list");
|
2001-03-06 04:57:30 +03:00
|
|
|
CLEAR_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Next parse the declaration block
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* declaration = ParseDeclarationBlock(aErrorCode, PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == declaration) {
|
|
|
|
// XXX skip something here
|
1998-12-11 05:50:43 +03:00
|
|
|
delete slist;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
slist->Dump();
|
|
|
|
fputs("{\n", stdout);
|
|
|
|
declaration->List();
|
|
|
|
fputs("}\n", stdout);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Translate the selector list and declaration block into style data
|
|
|
|
|
|
|
|
SelectorList* list = slist;
|
|
|
|
|
|
|
|
while (nsnull != list) {
|
1998-12-11 05:50:43 +03:00
|
|
|
nsICSSStyleRule* rule = nsnull;
|
2001-01-22 07:03:48 +03:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_NewCSSStyleRule(&rule, *(list->mSelectors));
|
1998-05-19 01:07:54 +04:00
|
|
|
if (nsnull != rule) {
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull != list->mSelectors->mNext) { // hand off other selectors to new rule
|
|
|
|
nsCSSSelector* ruleFirst = rule->FirstSelector();
|
|
|
|
ruleFirst->mNext = list->mSelectors->mNext;
|
|
|
|
list->mSelectors->mNext = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-01-22 07:03:48 +03:00
|
|
|
rule->SetLineNumber(linenum);
|
1998-04-14 00:24:54 +04:00
|
|
|
rule->SetDeclaration(declaration);
|
1999-02-27 10:15:59 +03:00
|
|
|
rule->SetWeight(list->mWeight);
|
1998-04-14 00:24:54 +04:00
|
|
|
// rule->List();
|
2001-09-06 17:14:35 +04:00
|
|
|
(*aAppendFunc)(rule, aData);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release temporary storage
|
1998-12-11 05:50:43 +03:00
|
|
|
delete slist;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorList(PRInt32& aErrorCode,
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList*& aListHead)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList* list = nsnull;
|
|
|
|
if (! ParseSelectorGroup(aErrorCode, list)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// must have at least one selector group
|
1998-12-11 05:50:43 +03:00
|
|
|
aListHead = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
NS_ASSERTION(nsnull != list, "no selector list");
|
|
|
|
aListHead = list;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// After that there must either be a "," or a "{"
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("',' or '{'"));
|
1998-12-11 05:50:43 +03:00
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-03-06 05:30:30 +03:00
|
|
|
|
2001-03-06 04:57:30 +03:00
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
if (',' == tk->mSymbol) {
|
|
|
|
SelectorList* newList = nsnull;
|
|
|
|
// Another selector group must follow
|
|
|
|
if (! ParseSelectorGroup(aErrorCode, newList)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// add new list to the end of the selector list
|
|
|
|
list->mNext = newList;
|
|
|
|
list = newList;
|
|
|
|
continue;
|
|
|
|
} else if ('{' == tk->mSymbol) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected ',' or '{' but found"));
|
|
|
|
UngetToken();
|
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
delete aListHead;
|
|
|
|
aListHead = nsnull;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool IsPseudoClass(const nsIAtom* aAtom)
|
|
|
|
{
|
|
|
|
return PRBool((nsCSSAtoms::activePseudo == aAtom) ||
|
2001-06-05 05:00:11 +04:00
|
|
|
(nsCSSAtoms::anyLinkPseudo == aAtom) ||
|
1999-07-18 04:31:37 +04:00
|
|
|
(nsCSSAtoms::checkedPseudo == aAtom) ||
|
1999-02-27 10:15:59 +03:00
|
|
|
(nsCSSAtoms::disabledPseudo == aAtom) ||
|
1999-05-19 03:12:17 +04:00
|
|
|
(nsCSSAtoms::dragOverPseudo == aAtom) ||
|
1999-02-27 10:15:59 +03:00
|
|
|
(nsCSSAtoms::enabledPseudo == aAtom) ||
|
2001-04-11 06:55:41 +04:00
|
|
|
(nsCSSAtoms::emptyPseudo == aAtom) ||
|
1998-12-11 05:50:43 +03:00
|
|
|
(nsCSSAtoms::firstChildPseudo == aAtom) ||
|
1999-09-11 04:08:30 +04:00
|
|
|
(nsCSSAtoms::firstNodePseudo == aAtom) ||
|
1998-12-11 05:50:43 +03:00
|
|
|
(nsCSSAtoms::focusPseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::hoverPseudo == aAtom) ||
|
|
|
|
(nsCSSAtoms::langPseudo == aAtom) ||
|
2001-03-30 14:20:57 +04:00
|
|
|
(nsCSSAtoms::lastChildPseudo == aAtom) ||
|
2001-03-20 14:49:20 +03:00
|
|
|
(nsCSSAtoms::lastNodePseudo == aAtom) ||
|
1998-12-11 05:50:43 +03:00
|
|
|
(nsCSSAtoms::linkPseudo == aAtom) ||
|
1999-08-08 05:17:29 +04:00
|
|
|
(nsCSSAtoms::rootPseudo == aAtom) ||
|
2001-03-13 05:34:02 +03:00
|
|
|
(nsCSSAtoms::xblBoundElementPseudo == aAtom) ||
|
1998-12-11 05:50:43 +03:00
|
|
|
(nsCSSAtoms::visitedPseudo == aAtom));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool IsSinglePseudoClass(const nsCSSSelector& aSelector)
|
|
|
|
{
|
|
|
|
return PRBool((aSelector.mNameSpace == kNameSpaceID_Unknown) &&
|
|
|
|
(aSelector.mTag == nsnull) &&
|
2001-02-13 17:06:29 +03:00
|
|
|
(aSelector.mIDList == nsnull) &&
|
1998-12-11 05:50:43 +03:00
|
|
|
(aSelector.mClassList == nsnull) &&
|
|
|
|
(aSelector.mAttrList == nsnull) &&
|
2001-06-27 14:41:49 +04:00
|
|
|
(aSelector.mNegations == nsnull) &&
|
1998-12-11 05:50:43 +03:00
|
|
|
(aSelector.mPseudoClassList != nsnull) &&
|
|
|
|
(aSelector.mPseudoClassList->mNext == nsnull));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-02-16 00:25:31 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
static PRBool IsTreePseudoElement(const nsString& aPseudo)
|
2001-02-16 00:25:31 +03:00
|
|
|
{
|
2002-03-29 05:46:01 +03:00
|
|
|
return Substring(aPseudo, 0, 10).Equals(NS_LITERAL_STRING("-moz-tree-"));
|
2001-02-16 00:25:31 +03:00
|
|
|
}
|
|
|
|
|
2002-03-29 05:46:01 +03:00
|
|
|
static PRBool IsTreePseudoElement(nsIAtom* aPseudo)
|
2001-02-16 00:25:31 +03:00
|
|
|
{
|
|
|
|
nsAutoString str;
|
|
|
|
aPseudo->ToString(str);
|
2002-03-29 05:46:01 +03:00
|
|
|
return Substring(str, 0, 11).Equals(NS_LITERAL_STRING(":-moz-tree-"));
|
2001-02-16 00:25:31 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorGroup(PRInt32& aErrorCode,
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList*& aList)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
SelectorList* list = nsnull;
|
1999-02-27 10:15:59 +03:00
|
|
|
PRUnichar combinator = PRUnichar(0);
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
PRBool havePseudoElement = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
1998-12-11 05:50:43 +03:00
|
|
|
nsCSSSelector selector;
|
2001-03-07 02:07:33 +03:00
|
|
|
if (! ParseSelector(aErrorCode, selector)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull == list) {
|
|
|
|
list = new SelectorList();
|
1999-02-10 11:37:52 +03:00
|
|
|
if (nsnull == list) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
list->AddSelector(selector);
|
|
|
|
nsCSSSelector* listSel = list->mSelectors;
|
|
|
|
|
|
|
|
// pull out pseudo elements here
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList* prevList = nsnull;
|
|
|
|
nsAtomStringList* pseudoClassList = listSel->mPseudoClassList;
|
1998-12-11 05:50:43 +03:00
|
|
|
while (nsnull != pseudoClassList) {
|
|
|
|
if (! IsPseudoClass(pseudoClassList->mAtom)) {
|
1999-02-27 10:15:59 +03:00
|
|
|
havePseudoElement = PR_TRUE;
|
1998-12-11 05:50:43 +03:00
|
|
|
if (IsSinglePseudoClass(*listSel)) { // convert to pseudo element selector
|
|
|
|
nsIAtom* pseudoElement = pseudoClassList->mAtom; // steal ref count
|
|
|
|
pseudoClassList->mAtom = nsnull;
|
|
|
|
listSel->Reset();
|
1999-04-16 01:22:41 +04:00
|
|
|
if (listSel->mNext) {// more to the selector
|
|
|
|
listSel->mOperator = PRUnichar('>');
|
|
|
|
nsCSSSelector empty;
|
|
|
|
list->AddSelector(empty); // leave a blank (universal) selector in the middle
|
|
|
|
listSel = list->mSelectors; // use the new one for the pseudo
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
listSel->mTag = pseudoElement;
|
|
|
|
}
|
|
|
|
else { // append new pseudo element selector
|
|
|
|
selector.Reset();
|
|
|
|
selector.mTag = pseudoClassList->mAtom; // steal ref count
|
2001-12-30 01:07:54 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
if (IsTreePseudoElement(selector.mTag)) {
|
2001-02-16 00:25:31 +03:00
|
|
|
// Take the remaining "pseudoclasses" that we parsed
|
2002-03-29 05:46:01 +03:00
|
|
|
// inside the tree pseudoelement's ()-list, and
|
2001-02-16 00:25:31 +03:00
|
|
|
// make our new selector have these pseudoclasses
|
|
|
|
// in its pseudoclass list.
|
|
|
|
selector.mPseudoClassList = pseudoClassList->mNext;
|
|
|
|
pseudoClassList->mNext = nsnull;
|
|
|
|
}
|
2001-12-30 01:07:54 +03:00
|
|
|
#endif
|
1998-12-11 05:50:43 +03:00
|
|
|
list->AddSelector(selector);
|
|
|
|
pseudoClassList->mAtom = nsnull;
|
1999-02-27 10:15:59 +03:00
|
|
|
listSel->mOperator = PRUnichar('>');
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull == prevList) { // delete list entry
|
|
|
|
listSel->mPseudoClassList = pseudoClassList->mNext;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prevList->mNext = pseudoClassList->mNext;
|
|
|
|
}
|
|
|
|
pseudoClassList->mNext = nsnull;
|
|
|
|
delete pseudoClassList;
|
1999-02-27 10:15:59 +03:00
|
|
|
weight += listSel->CalcWeight(); // capture weight from remainder
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
break; // only one pseudo element per selector
|
|
|
|
}
|
|
|
|
prevList = pseudoClassList;
|
|
|
|
pseudoClassList = pseudoClassList->mNext;
|
|
|
|
}
|
1999-02-27 10:15:59 +03:00
|
|
|
|
|
|
|
combinator = PRUnichar(0);
|
|
|
|
if (GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
if ((eCSSToken_Symbol == mToken.mType) &&
|
|
|
|
(('+' == mToken.mSymbol) || ('>' == mToken.mSymbol))) {
|
|
|
|
combinator = mToken.mSymbol;
|
|
|
|
list->mSelectors->SetOperator(combinator);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken(); // give it back to selector
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (havePseudoElement) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
weight += selector.CalcWeight();
|
|
|
|
}
|
|
|
|
}
|
2000-09-08 06:05:09 +04:00
|
|
|
if (!list) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Selector expected"));
|
2000-09-08 06:05:09 +04:00
|
|
|
}
|
1999-02-27 10:15:59 +03:00
|
|
|
if (PRUnichar(0) != combinator) { // no dangling combinators
|
|
|
|
if (list) {
|
|
|
|
delete list;
|
|
|
|
}
|
|
|
|
list = nsnull;
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Dangling combinator"));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
aList = list;
|
1999-02-08 00:48:27 +03:00
|
|
|
if (nsnull != list) {
|
1999-02-27 10:15:59 +03:00
|
|
|
list->mWeight = weight;
|
1999-02-08 00:48:27 +03:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
return PRBool(nsnull != aList);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
#define SEL_MASK_NSPACE 0x01
|
|
|
|
#define SEL_MASK_ELEM 0x02
|
|
|
|
#define SEL_MASK_ID 0x04
|
|
|
|
#define SEL_MASK_CLASS 0x08
|
|
|
|
#define SEL_MASK_ATTRIB 0x10
|
|
|
|
#define SEL_MASK_PCLASS 0x20
|
|
|
|
#define SEL_MASK_PELEM 0x40
|
1998-05-19 01:07:54 +04:00
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
#define SELECTOR_PARSING_ENDED_OK 1
|
|
|
|
#define SELECTOR_PARSING_STOPPED_OK 2
|
|
|
|
#define SELECTOR_PARSING_STOPPED_ERROR 3
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parses an ID selector #name
|
|
|
|
//
|
2001-03-09 02:27:39 +03:00
|
|
|
void CSSParserImpl::ParseIDSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!mToken.mIdent.IsEmpty()) { // verify is legal ID
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ID;
|
|
|
|
aSelector.AddID(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING(
|
|
|
|
"Expected non-empty name for ID selector, but found"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parses a class selector .name
|
|
|
|
//
|
2001-03-09 02:27:39 +03:00
|
|
|
void CSSParserImpl::ParseClassSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode)
|
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // get ident
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("class name"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) { // malformed selector
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for class selector but found"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_CLASS;
|
2001-08-16 11:42:15 +04:00
|
|
|
|
2001-09-07 04:23:37 +04:00
|
|
|
aSelector.AddClass(mToken.mIdent);
|
2001-08-16 11:42:15 +04:00
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse a type element selector or a universal selector
|
|
|
|
// namespace|type or namespace|* or *|* or *
|
|
|
|
//
|
2001-03-09 02:27:39 +03:00
|
|
|
void CSSParserImpl::ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
2001-03-20 14:49:20 +03:00
|
|
|
PRInt32& aErrorCode,
|
|
|
|
PRBool aIsNegated)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
1999-06-10 09:25:23 +04:00
|
|
|
if (mToken.IsSymbol('*')) { // universal element selector, or universal namespace
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) { // was namespace
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // namespace wildcard
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("element type"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
aSelector.SetTag(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent, buffer);
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetTag(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected element name or '*' but found"));
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was universal element selector
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
|
|
|
if (mNameSpace) { // look for default namespace
|
|
|
|
nsINameSpace* defaultNameSpace = nsnull;
|
|
|
|
mNameSpace->FindNameSpace(nsnull, defaultNameSpace);
|
|
|
|
if (defaultNameSpace) {
|
|
|
|
PRInt32 defaultID;
|
|
|
|
defaultNameSpace->GetNameSpaceID(defaultID);
|
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
NS_RELEASE(defaultNameSpace);
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
// don't set any tag in the selector
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_OK;
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
else if (eCSSToken_Ident == mToken.mType) { // element name or namespace name
|
|
|
|
buffer = mToken.mIdent; // hang on to ident
|
|
|
|
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) { // was namespace
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
1999-06-10 09:25:23 +04:00
|
|
|
PRInt32 nameSpaceID = kNameSpaceID_Unknown;
|
|
|
|
if (mNameSpace) {
|
|
|
|
nsIAtom* prefix;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(buffer); // always case insensitive, since stays within CSS
|
2000-09-08 06:05:09 +04:00
|
|
|
prefix = NS_NewAtom(buffer);
|
1999-06-10 09:25:23 +04:00
|
|
|
mNameSpace->FindNameSpaceID(prefix, nameSpaceID);
|
|
|
|
NS_IF_RELEASE(prefix);
|
|
|
|
} // else, no delcared namespaces
|
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
2001-03-09 02:27:39 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Unknown namespace prefix"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
aSelector.SetNameSpace(nameSpaceID);
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("element type"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
aSelector.SetTag(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent, buffer);
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetTag(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
2001-03-09 02:27:39 +03:00
|
|
|
NS_LITERAL_STRING("Expected element name or '*' but found"));
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was element name
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
|
|
|
if (mNameSpace) { // look for default namespace
|
|
|
|
nsINameSpace* defaultNameSpace = nsnull;
|
|
|
|
mNameSpace->FindNameSpace(nsnull, defaultNameSpace);
|
|
|
|
if (defaultNameSpace) {
|
|
|
|
PRInt32 defaultID;
|
|
|
|
defaultNameSpace->GetNameSpaceID(defaultID);
|
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
NS_RELEASE(defaultNameSpace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCaseSensitive) {
|
|
|
|
aSelector.SetTag(buffer);
|
|
|
|
}
|
|
|
|
else {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(buffer);
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetTag(buffer);
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_OK;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // No namespace
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetNameSpace(kNameSpaceID_None); // explicit NO namespace
|
|
|
|
|
|
|
|
// get mandatory tag
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("element type"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1998-12-21 08:58:58 +03:00
|
|
|
if (mCaseSensitive) {
|
1998-12-11 05:50:43 +03:00
|
|
|
aSelector.SetTag(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent, buffer);
|
1998-12-11 05:50:43 +03:00
|
|
|
aSelector.SetTag(buffer);
|
1998-07-17 09:50:07 +04:00
|
|
|
}
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
1999-06-10 09:25:23 +04:00
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected element name or '*' but found"));
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_OK;
|
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
2001-06-09 05:32:19 +04:00
|
|
|
else {
|
|
|
|
// no tag or namespace: implied universal selector
|
|
|
|
// set namespace to unknown since it is not specified
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
|
|
|
if (mNameSpace) { // look for default namespace
|
|
|
|
nsINameSpace* defaultNameSpace = nsnull;
|
|
|
|
mNameSpace->FindNameSpace(nsnull, defaultNameSpace);
|
|
|
|
if (defaultNameSpace) {
|
|
|
|
PRInt32 defaultID;
|
|
|
|
defaultNameSpace->GetNameSpaceID(defaultID);
|
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
NS_RELEASE(defaultNameSpace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
2001-03-20 14:49:20 +03:00
|
|
|
if (aIsNegated) {
|
|
|
|
// restore last token read in case of a negated type selector
|
|
|
|
UngetToken();
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse attribute selectors [attr], [attr=value], [attr|=value],
|
|
|
|
// [attr~=value], [attr^=value], [attr$=value] and [attr*=value]
|
|
|
|
//
|
2001-03-09 02:27:39 +03:00
|
|
|
void CSSParserImpl::ParseAttributeSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode)
|
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("attribute name"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nameSpaceID = kNameSpaceID_None;
|
|
|
|
nsAutoString attr;
|
|
|
|
if (mToken.IsSymbol('*')) { // wildcard namespace
|
|
|
|
nameSpaceID = kNameSpaceID_Unknown;
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) {
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("attribute name"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-03-09 02:27:39 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for attribute name but found"));
|
1998-12-11 05:50:43 +03:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected '|' but found"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // NO namespace
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("attribute name"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for attribute name but found"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Ident == mToken.mType) { // attr name or namespace
|
|
|
|
attr = mToken.mIdent; // hang on to it
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) { // was a namespace
|
|
|
|
nameSpaceID = kNameSpaceID_Unknown;
|
|
|
|
if (mNameSpace) {
|
|
|
|
nsIAtom* prefix;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(attr); // always case insensitive, since stays within CSS
|
2001-03-09 02:27:39 +03:00
|
|
|
prefix = NS_NewAtom(attr);
|
|
|
|
mNameSpace->FindNameSpaceID(prefix, nameSpaceID);
|
|
|
|
NS_IF_RELEASE(prefix);
|
|
|
|
} // else, no delcared namespaces
|
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unknown namespace prefix"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("attribute name"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-03-09 02:27:39 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for attribute name but found"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
else { // malformed
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected attribute name or namespace but found"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! mCaseSensitive) {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(attr);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("part of attribute selector"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == mToken.mType) ||
|
|
|
|
(eCSSToken_Includes == mToken.mType) ||
|
|
|
|
(eCSSToken_Dashmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Beginsmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Endsmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Containsmatch == mToken.mType)) {
|
|
|
|
PRUint8 func;
|
|
|
|
if (eCSSToken_Includes == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_INCLUDES;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Dashmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_DASHMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Beginsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_BEGINSMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Endsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_ENDSMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Containsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_CONTAINSMATCH;
|
|
|
|
}
|
|
|
|
else if (']' == mToken.mSymbol) {
|
|
|
|
aDataMask |= SEL_MASK_ATTRIB;
|
|
|
|
aSelector.AddAttribute(nameSpaceID, attr);
|
|
|
|
func = NS_ATTR_FUNC_SET;
|
|
|
|
}
|
|
|
|
else if ('=' == mToken.mSymbol) {
|
|
|
|
func = NS_ATTR_FUNC_EQUALS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unexpected token in attribute selector: "));
|
|
|
|
UngetToken(); // bad function
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NS_ATTR_FUNC_SET != func) { // get value
|
1999-03-25 09:42:42 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("attribute value"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if ((eCSSToken_Ident == mToken.mType) || (eCSSToken_String == mToken.mType)) {
|
|
|
|
nsAutoString value(mToken.mIdent);
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("] to end attribute selector"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if (mToken.IsSymbol(']')) {
|
2001-04-18 08:36:52 +04:00
|
|
|
PRBool isCaseSensitive = mCaseSensitive;
|
2002-05-21 02:47:02 +04:00
|
|
|
if (nameSpaceID == kNameSpaceID_None ||
|
|
|
|
nameSpaceID == kNameSpaceID_XHTML) {
|
2001-04-18 08:36:52 +04:00
|
|
|
static const char* caseSensitiveHTMLAttribute[] = {
|
|
|
|
// list based on http://www.w3.org/TR/REC-html40/index/attributes.html
|
|
|
|
"abbr", "alt", "label",
|
|
|
|
"prompt", "standby", "summary",
|
|
|
|
"title", nsnull
|
|
|
|
};
|
|
|
|
short i = 0;
|
|
|
|
const char* htmlAttr;
|
|
|
|
while ((htmlAttr = caseSensitiveHTMLAttribute[i++])) {
|
|
|
|
if (attr.EqualsIgnoreCase(htmlAttr)) {
|
|
|
|
isCaseSensitive = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_ATTRIB;
|
2001-04-18 08:36:52 +04:00
|
|
|
aSelector.AddAttribute(nameSpaceID, attr, func, value, isCaseSensitive);
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
else {
|
2001-03-09 02:27:39 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected ']' to terminate attribute selector but found"));
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier or string for value in attribute selector but found"));
|
1998-12-11 05:50:43 +03:00
|
|
|
UngetToken();
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Unexpected token in attribute selector: "));
|
|
|
|
UngetToken(); // bad dog, no biscut!
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse pseudo-classes and pseudo-elements
|
|
|
|
//
|
2001-03-09 02:27:39 +03:00
|
|
|
void CSSParserImpl::ParsePseudoSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
2001-03-20 14:49:20 +03:00
|
|
|
PRInt32& aErrorCode,
|
|
|
|
PRBool aIsNegated)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("name of pseudo-selector"));
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
|
|
|
buffer.Truncate();
|
2001-12-16 14:58:03 +03:00
|
|
|
buffer.Append(PRUnichar(':'));
|
2001-03-20 14:49:20 +03:00
|
|
|
buffer.Append(mToken.mIdent);
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(buffer);
|
2002-08-14 16:34:39 +04:00
|
|
|
nsCOMPtr<nsIAtom> pseudo = do_GetAtom(buffer);
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
if (eCSSToken_Ident != mToken.mType) { // malformed selector
|
2001-03-20 14:49:20 +03:00
|
|
|
if (eCSSToken_Function != mToken.mType ||
|
|
|
|
!(
|
2001-03-09 02:27:39 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
// -moz-tree is a pseudo-element and therefore cannot be negated
|
|
|
|
(!aIsNegated && IsTreePseudoElement(mToken.mIdent)) ||
|
2001-03-09 02:27:39 +03:00
|
|
|
#endif
|
2001-03-20 14:49:20 +03:00
|
|
|
// the negation pseudo-class is a function
|
2002-08-14 16:34:39 +04:00
|
|
|
(nsCSSAtoms::notPseudo == pseudo) ||
|
|
|
|
// as is the lang pseudo-class
|
|
|
|
(nsCSSAtoms::langPseudo == pseudo))) {
|
2001-03-20 14:49:20 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for pseudo-class selector not found"));
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
|
|
|
if (nsCSSAtoms::notPseudo == pseudo) {
|
|
|
|
if (aIsNegated) { // :not() can't be itself negated
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Negation pseudo-class can't be negated"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// CSS 3 Negation pseudo-class takes one simple selector as argument
|
|
|
|
ParseNegatedSimpleSelector(aDataMask, aSelector, aParsingStatus, aErrorCode);
|
|
|
|
if (SELECTOR_PARSING_ENDED_OK != aParsingStatus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsPseudoClass(pseudo)) {
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_PCLASS;
|
2002-08-14 16:34:39 +04:00
|
|
|
if (nsCSSAtoms::langPseudo == pseudo) {
|
|
|
|
ParseLangSelector(aSelector, aParsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
// XXX are there more pseudo classes which accept arguments ?
|
|
|
|
else {
|
|
|
|
aSelector.AddPseudoClass(pseudo);
|
|
|
|
}
|
|
|
|
if (SELECTOR_PARSING_ENDED_OK != aParsingStatus) {
|
|
|
|
return;
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-03-20 14:49:20 +03:00
|
|
|
if (aIsNegated) { // pseudo-elements can't be negated
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Pseudo-elements can't be negated"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if (0 == (aDataMask & SEL_MASK_PELEM)) {
|
|
|
|
aDataMask |= SEL_MASK_PELEM;
|
|
|
|
aSelector.AddPseudoClass(pseudo); // store it here, it gets pulled later
|
|
|
|
|
|
|
|
#ifdef INCLUDE_XUL
|
|
|
|
if (eCSSToken_Function == mToken.mType &&
|
2002-03-29 05:46:01 +03:00
|
|
|
IsTreePseudoElement(mToken.mIdent)) {
|
2001-03-09 02:27:39 +03:00
|
|
|
// We have encountered a pseudoelement of the form
|
2002-03-29 05:46:01 +03:00
|
|
|
// -moz-tree-xxxx(a,b,c). We parse (a,b,c) and add each
|
2001-03-09 02:27:39 +03:00
|
|
|
// item in the list to the pseudoclass list. They will be pulled
|
|
|
|
// from the list later along with the pseudoelement.
|
2002-03-29 05:46:01 +03:00
|
|
|
if (!ParseTreePseudoElement(aErrorCode, aSelector))
|
2001-03-09 02:27:39 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// ensure selector ends here, must be followed by EOF, space, '{' or ','
|
|
|
|
if (GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
|
|
|
if ((eCSSToken_WhiteSpace == mToken.mType) ||
|
|
|
|
(mToken.IsSymbol('{') || mToken.IsSymbol(','))) {
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_OK;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Found trailing token after pseudo-element, which must be the last part of a selector: "));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
else { // multiple pseudo elements, not legal
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Extra pseudo-element"));
|
|
|
|
UngetToken();
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse the argument of a negation pseudo-class :not()
|
|
|
|
//
|
|
|
|
void CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode)
|
|
|
|
{
|
|
|
|
// Check if we have the first parenthesis
|
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("selector within negation"));
|
2001-03-20 14:49:20 +03:00
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aParsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
nsCSSSelector* newSel = new nsCSSSelector();
|
|
|
|
if (nsnull == aSelector.mNegations &&
|
|
|
|
((eCSSToken_ID == mToken.mType) ||
|
|
|
|
mToken.IsSymbol('.') ||
|
|
|
|
mToken.IsSymbol(':') ||
|
|
|
|
mToken.IsSymbol('['))) {
|
|
|
|
// ID, class and attribute selectors and pseudo-classes are stored in
|
|
|
|
// the first mNegations attached to a selector
|
|
|
|
aSelector.mNegations = newSel;
|
|
|
|
}
|
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
|
|
|
ParseIDSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
|
|
|
ParseClassSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
|
|
|
ParsePseudoSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode, PR_TRUE);
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('[')) { // attribute
|
|
|
|
ParseAttributeSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// then it should be a type element or universal selector
|
|
|
|
if (nsnull == aSelector.mNegations) {
|
|
|
|
aSelector.mNegations = newSel;
|
|
|
|
}
|
|
|
|
newSel = new nsCSSSelector();
|
|
|
|
nsCSSSelector* negations = aSelector.mNegations;
|
|
|
|
while (nsnull != negations->mNegations) {
|
|
|
|
negations = negations->mNegations;
|
|
|
|
}
|
|
|
|
// negated type element selectors and universal selectors are stored after the first
|
|
|
|
// mNegations containing only negated IDs, classes, attributes and pseudo-classes
|
|
|
|
negations->mNegations = newSel;
|
|
|
|
ParseTypeOrUniversalSelector(aDataMask, *newSel, aParsingStatus, aErrorCode, PR_TRUE);
|
|
|
|
}
|
|
|
|
if (SELECTOR_PARSING_STOPPED_ERROR == aParsingStatus) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Malformed simple selector as negation pseudo-class argument"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// close the parenthesis
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Missing closing ')' in negation pseudo-class"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Missing argument in negation pseudo-class"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 16:34:39 +04:00
|
|
|
//
|
|
|
|
// Parse the argument of a pseudo-class :lang()
|
|
|
|
//
|
|
|
|
void CSSParserImpl::ParseLangSelector(nsCSSSelector& aSelector,
|
|
|
|
PRInt32& aParsingStatus,
|
|
|
|
PRInt32& aErrorCode)
|
|
|
|
{
|
|
|
|
// Check if we have the first parenthesis
|
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature eof
|
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("argument to :lang selector"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We expect an identifier with a language abbreviation
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected identifier for lang pseudo-class parameter"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the pseudo with the language parameter
|
|
|
|
aSelector.AddPseudoClass(nsCSSAtoms::langPseudo, mToken.mIdent.get());
|
|
|
|
|
|
|
|
// close the parenthesis
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Missing closing ')' in lang pseudo-class"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Missing argument in lang pseudo-class"));
|
|
|
|
aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
/**
|
|
|
|
* This is the format for selectors:
|
|
|
|
* operator? [[namespace |]? element_name]? [ ID | class | attrib | pseudo ]*
|
|
|
|
*/
|
|
|
|
PRBool CSSParserImpl::ParseSelector(PRInt32& aErrorCode,
|
|
|
|
nsCSSSelector& aSelector)
|
|
|
|
{
|
|
|
|
PRInt32 dataMask = 0;
|
|
|
|
PRInt32 parsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("selector"));
|
2001-03-09 02:27:39 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
ParseTypeOrUniversalSelector(dataMask, aSelector, parsingStatus, aErrorCode, PR_FALSE);
|
2001-03-09 02:27:39 +03:00
|
|
|
if (SELECTOR_PARSING_STOPPED_OK == parsingStatus) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (SELECTOR_PARSING_STOPPED_ERROR == parsingStatus) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
parsingStatus = SELECTOR_PARSING_ENDED_OK;
|
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
|
|
|
ParseIDSelector(dataMask, aSelector, parsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
|
|
|
ParseClassSelector(dataMask, aSelector, parsingStatus, aErrorCode);
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
2001-03-20 14:49:20 +03:00
|
|
|
ParsePseudoSelector(dataMask, aSelector, parsingStatus, aErrorCode, PR_FALSE);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('[')) { // attribute
|
|
|
|
ParseAttributeSelector(dataMask, aSelector, parsingStatus, aErrorCode);
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
else { // not a selector token, we're done
|
|
|
|
break;
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
|
|
|
|
if (SELECTOR_PARSING_STOPPED_OK == parsingStatus) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (SELECTOR_PARSING_STOPPED_ERROR == parsingStatus) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
|
|
|
return PR_TRUE;
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
UngetToken();
|
|
|
|
return PRBool(0 != dataMask);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration*
|
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)) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected '{' to begin declaration block but found"));
|
|
|
|
OUTPUT_ERROR();
|
1998-05-28 22:39:42 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* declaration = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (NS_OK == NS_NewCSSDeclaration(&declaration)) {
|
1998-05-14 02:40:54 +04:00
|
|
|
PRInt32 count = 0;
|
2000-03-23 17:45:04 +03:00
|
|
|
PRBool dropDeclaration = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint hint = NS_STYLE_HINT_NONE;
|
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 {
|
2000-03-23 17:45:04 +03:00
|
|
|
dropDeclaration = (aErrorCode == NS_CSS_PARSER_DROP_DECLARATION);
|
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.
|
|
|
|
}
|
|
|
|
}
|
2002-02-19 05:27:38 +03:00
|
|
|
if (dropDeclaration) {
|
2002-01-16 01:43:37 +03:00
|
|
|
if (nsnull != declaration) {
|
|
|
|
declaration->RuleAbort();
|
|
|
|
declaration = nsnull;
|
|
|
|
}
|
1998-05-14 02:40:54 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return declaration;
|
|
|
|
}
|
|
|
|
|
2002-09-14 09:28:26 +04:00
|
|
|
// The types to pass to ParseColorComponent. These correspond to the
|
|
|
|
// various datatypes that can go within rgb().
|
|
|
|
#define COLOR_TYPE_UNKNOWN 0
|
|
|
|
#define COLOR_TYPE_INTEGERS 1
|
|
|
|
#define COLOR_TYPE_PERCENTAGES 2
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseColor(PRInt32& aErrorCode, nsCSSValue& aValue)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("color"));
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
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
|
1999-07-18 04:31:37 +04:00
|
|
|
if (NS_HexToRGB(tk->mIdent, &rgba)) {
|
1998-10-27 02:22:40 +03:00
|
|
|
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:
|
1999-07-18 04:31:37 +04:00
|
|
|
if (NS_ColorNameToRGB(tk->mIdent, &rgba)) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aValue.SetStringValue(tk->mIdent, eCSSUnit_String);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-09-10 09:55:36 +04:00
|
|
|
else {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) { // known keyword
|
|
|
|
PRInt32 index = SearchKeywordTable(keyword, nsCSSProps::kColorKTable);
|
|
|
|
if (0 < index) {
|
1999-10-12 05:31:33 +04:00
|
|
|
aValue.SetIntValue(nsCSSProps::kColorKTable[index], eCSSUnit_Integer);
|
1999-09-10 09:55:36 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
break;
|
|
|
|
case eCSSToken_Function:
|
1999-06-10 09:25:23 +04:00
|
|
|
if (mToken.mIdent.EqualsIgnoreCase("rgb")) {
|
|
|
|
// rgb ( component , component , component )
|
|
|
|
PRUint8 r, g, b;
|
2002-09-14 09:28:26 +04:00
|
|
|
PRInt32 type = COLOR_TYPE_UNKNOWN;
|
2001-03-06 04:57:30 +03:00
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE) && // this won't fail
|
2002-09-14 09:28:26 +04:00
|
|
|
ParseColorComponent(aErrorCode, r, type, ',') &&
|
|
|
|
ParseColorComponent(aErrorCode, g, type, ',') &&
|
|
|
|
ParseColorComponent(aErrorCode, b, type, ')')) {
|
1999-07-18 04:31:37 +04:00
|
|
|
rgba = NS_RGB(r,g,b);
|
1999-06-10 09:25:23 +04:00
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE; // already pushed back
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
break;
|
1998-10-27 02:22:40 +03:00
|
|
|
default:
|
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-08-05 08:40:03 +04:00
|
|
|
// try 'xxyyzz' without '#' prefix for compatibility with IE and Nav4x (bug 23236 and 45804)
|
|
|
|
if (mNavQuirkMode && !IsParsingCompoundProperty()) {
|
2000-01-08 13:11:10 +03:00
|
|
|
// - If the string starts with 'a-f', the nsCSSScanner builds the token
|
|
|
|
// as a eCSSToken_Ident and we can parse the string as a 'xxyyzz' RGB color.
|
|
|
|
// - If it only contains '0-9' digits, the token is a eCSSToken_Number and it
|
|
|
|
// must be converted back to a 6 characters string to be parsed as a RGB color.
|
|
|
|
// - If it starts with '0-9' and contains any 'a-f', the token is a eCSSToken_Dimension,
|
|
|
|
// the mNumber part must be converted back to a string and the mIdent part must be
|
|
|
|
// appended to that string so that the resulting string has 6 characters.
|
|
|
|
// Note: This is a hack for Nav compatibility. Do not attempt to simplify it
|
|
|
|
// by hacking into the ncCSSScanner. This would be very bad.
|
|
|
|
nsAutoString str;
|
|
|
|
char buffer[10];
|
|
|
|
switch (tk->mType) {
|
|
|
|
case eCSSToken_Ident:
|
2000-03-12 12:14:14 +03:00
|
|
|
str.Assign(tk->mIdent);
|
2000-01-08 13:11:10 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Number:
|
|
|
|
if (tk->mIntegerValid) {
|
|
|
|
sprintf(buffer, "%06d", tk->mInteger);
|
2000-04-16 00:15:37 +04:00
|
|
|
str.AssignWithConversion(buffer);
|
2000-01-08 13:11:10 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
if (tk->mIdent.Length() <= 6) {
|
|
|
|
sprintf(buffer, "%06.0f", tk->mNumber);
|
|
|
|
nsAutoString temp;
|
2000-04-16 00:15:37 +04:00
|
|
|
temp.AssignWithConversion(buffer);
|
2000-01-08 13:11:10 +03:00
|
|
|
temp.Right(str, 6 - tk->mIdent.Length());
|
|
|
|
str.Append(tk->mIdent);
|
|
|
|
}
|
|
|
|
break;
|
2000-03-30 07:21:26 +04:00
|
|
|
default:
|
|
|
|
// There is a whole bunch of cases that are
|
|
|
|
// not handled by this switch. Ignore them.
|
|
|
|
break;
|
2000-01-08 13:11:10 +03:00
|
|
|
}
|
|
|
|
if (NS_HexToRGB(str, &rgba)) {
|
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// It's not a color
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected color but found"));
|
1998-04-14 00:24:54 +04:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-09-14 09:28:26 +04:00
|
|
|
// aType will be set if we have already parsed other color components
|
|
|
|
// in this color spec
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseColorComponent(PRInt32& aErrorCode,
|
|
|
|
PRUint8& aComponent,
|
2002-09-14 09:28:26 +04:00
|
|
|
PRInt32& aType,
|
1998-04-14 00:24:54 +04:00
|
|
|
char aStop)
|
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("color component"));
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
float value;
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
switch (tk->mType) {
|
|
|
|
case eCSSToken_Number:
|
2002-09-14 09:28:26 +04:00
|
|
|
switch (aType) {
|
|
|
|
case COLOR_TYPE_UNKNOWN:
|
|
|
|
aType = COLOR_TYPE_INTEGERS;
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_INTEGERS:
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_PERCENTAGES:
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected a percentage but found"));
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Someone forgot to add the new color component type in here");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mToken.mIntegerValid) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected an integer but found"));
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
value = tk->mNumber;
|
|
|
|
break;
|
|
|
|
case eCSSToken_Percentage:
|
2002-09-14 09:28:26 +04:00
|
|
|
switch (aType) {
|
|
|
|
case COLOR_TYPE_UNKNOWN:
|
|
|
|
aType = COLOR_TYPE_PERCENTAGES;
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_INTEGERS:
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected an integer but found"));
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
case COLOR_TYPE_PERCENTAGES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Someone forgot to add the new color component type in here");
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
value = tk->mNumber * 255.0f;
|
|
|
|
break;
|
|
|
|
default:
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected number or percentage in rgb() but found"));
|
1998-04-14 00:24:54 +04:00
|
|
|
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;
|
|
|
|
}
|
2001-04-03 01:14:23 +04:00
|
|
|
PRUnichar stopString[2];
|
|
|
|
stopString[0] = PRUnichar(aStop);
|
|
|
|
stopString[1] = PRUnichar(0);
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected ") +
|
2001-05-23 18:18:38 +04:00
|
|
|
nsDependentString(stopString, 1) +
|
2001-04-03 01:14:23 +04:00
|
|
|
NS_LITERAL_STRING(" but found"));
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-02-16 00:25:31 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
PRBool CSSParserImpl::ParseTreePseudoElement(PRInt32& aErrorCode,
|
2001-02-16 00:25:31 +03:00
|
|
|
nsCSSSelector& aSelector)
|
|
|
|
{
|
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
while (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
nsCOMPtr<nsIAtom> pseudo = getter_AddRefs(NS_NewAtom(mToken.mIdent));
|
|
|
|
aSelector.AddPseudoClass(pseudo);
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Symbol == mToken.mType) {
|
|
|
|
if (!mToken.IsSymbol(','))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-05-28 03:38:16 +04:00
|
|
|
PRBool
|
1998-10-27 02:22:40 +03:00
|
|
|
CSSParserImpl::ParseDeclaration(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1998-09-30 03:50:09 +04:00
|
|
|
PRBool aCheckForBraces,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Get property name
|
|
|
|
nsCSSToken* tk = &mToken;
|
1999-07-18 04:31:37 +04:00
|
|
|
nsAutoString propertyName;
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2000-09-06 06:27:46 +04:00
|
|
|
if (aCheckForBraces) {
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(
|
|
|
|
NS_LITERAL_STRING("';' or '}' to end declaration"));
|
2000-09-06 06:27:46 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == tk->mType) {
|
1999-07-18 04:31:37 +04:00
|
|
|
propertyName = tk->mIdent;
|
1998-09-25 05:50:34 +04:00
|
|
|
// grab the ident before the ExpectSymbol trashes the token
|
1998-04-14 00:24:54 +04:00
|
|
|
if (!ExpectSymbol(aErrorCode, ':', PR_TRUE)) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(NS_LITERAL_STRING("Expected ':' but found"));
|
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
if (tk->IsSymbol(';')) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// dangling semicolons are skipped
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-06-05 05:00:11 +04:00
|
|
|
if (!tk->IsSymbol('}')) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected declaration but found"));
|
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Skipped to next declaration."));
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
// Not a declaration...
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map property name to it's ID and then parse the property
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSProperty propID = nsCSSProps::LookupProperty(propertyName);
|
|
|
|
if (eCSSProperty_UNKNOWN == propID) { // unknown property
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Unknown property '") +
|
|
|
|
propertyName +
|
|
|
|
NS_LITERAL_STRING("'. Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (! ParseProperty(aErrorCode, aDeclaration, propID, aChangeHint)) {
|
2000-09-06 06:27:46 +04:00
|
|
|
// XXX Much better to put stuff in the value parsers instead...
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(
|
|
|
|
NS_LITERAL_STRING("Error in parsing value for property '") +
|
|
|
|
propertyName +
|
|
|
|
NS_LITERAL_STRING("'. Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
CLEAR_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
|
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
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("end of declaration"));
|
1998-05-28 22:39:42 +04:00
|
|
|
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
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("important"));
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Ident != tk->mType) ||
|
|
|
|
!tk->mIdent.EqualsIgnoreCase("important")) {
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected 'important' but found"));
|
|
|
|
OUTPUT_ERROR();
|
1998-05-28 22:39:42 +04:00
|
|
|
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
|
2002-07-09 08:28:58 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(NS_LITERAL_STRING("';' or '}' to end declaration"));
|
1998-05-28 22:39:42 +04:00
|
|
|
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.
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
NS_LITERAL_STRING("Expected ';' to terminate declaration but found"));
|
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if ('}' == tk->mSymbol) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED_TOKEN(
|
|
|
|
aCheckForBraces
|
|
|
|
? NS_LITERAL_STRING("Expected ';' or '}' to terminate declaration but found")
|
|
|
|
: NS_LITERAL_STRING("Expected ';' to terminate declaration but found"));
|
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Declaration dropped."));
|
|
|
|
OUTPUT_ERROR();
|
1998-04-14 00:24:54 +04:00
|
|
|
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)
|
|
|
|
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderTopIDs[] = {
|
|
|
|
eCSSProperty_border_top_width,
|
|
|
|
eCSSProperty_border_top_style,
|
|
|
|
eCSSProperty_border_top_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderRightIDs[] = {
|
|
|
|
eCSSProperty_border_right_width,
|
|
|
|
eCSSProperty_border_right_style,
|
|
|
|
eCSSProperty_border_right_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderBottomIDs[] = {
|
|
|
|
eCSSProperty_border_bottom_width,
|
|
|
|
eCSSProperty_border_bottom_style,
|
|
|
|
eCSSProperty_border_bottom_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderLeftIDs[] = {
|
|
|
|
eCSSProperty_border_left_width,
|
|
|
|
eCSSProperty_border_left_style,
|
|
|
|
eCSSProperty_border_left_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1999-07-18 04:31:37 +04:00
|
|
|
PRInt32 CSSParserImpl::SearchKeywordTable(nsCSSKeyword aKeyword, 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]) {
|
1999-07-18 04:31:37 +04:00
|
|
|
if (aKeyword == nsCSSKeyword(aKeywordTable[index++])) {
|
1998-10-27 02:22:40 +03:00
|
|
|
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;
|
|
|
|
}
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(*ident);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) {
|
1998-10-27 02:22:40 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-08-08 04:34:42 +04:00
|
|
|
PRBool CSSParserImpl::TranslateDimension(PRInt32& aErrorCode,
|
|
|
|
nsCSSValue& aValue,
|
1998-10-27 02:22:40 +03:00
|
|
|
PRInt32 aVariantMask,
|
|
|
|
float aNumber,
|
1999-02-10 11:37:52 +03:00
|
|
|
const nsString& aUnit)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
nsCSSUnit units;
|
1998-10-27 02:22:40 +03:00
|
|
|
PRInt32 type = 0;
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!aUnit.IsEmpty()) {
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSKeyword id = nsCSSKeywords::LookupKeyword(aUnit);
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (id) {
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSKeyword_em: units = eCSSUnit_EM; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_ex: units = eCSSUnit_XHeight; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_ch: units = eCSSUnit_Char; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_px: units = eCSSUnit_Pixel; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_in: units = eCSSUnit_Inch; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_cm: units = eCSSUnit_Centimeter; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_mm: units = eCSSUnit_Millimeter; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_pt: units = eCSSUnit_Point; type = VARIANT_LENGTH; break;
|
|
|
|
case eCSSKeyword_pc: units = eCSSUnit_Pica; type = VARIANT_LENGTH; break;
|
|
|
|
|
|
|
|
case eCSSKeyword_deg: units = eCSSUnit_Degree; type = VARIANT_ANGLE; break;
|
|
|
|
case eCSSKeyword_grad: units = eCSSUnit_Grad; type = VARIANT_ANGLE; break;
|
|
|
|
case eCSSKeyword_rad: units = eCSSUnit_Radian; type = VARIANT_ANGLE; break;
|
|
|
|
|
|
|
|
case eCSSKeyword_hz: units = eCSSUnit_Hertz; type = VARIANT_FREQUENCY; break;
|
|
|
|
case eCSSKeyword_khz: units = eCSSUnit_Kilohertz; type = VARIANT_FREQUENCY; break;
|
|
|
|
|
|
|
|
case eCSSKeyword_s: units = eCSSUnit_Seconds; type = VARIANT_TIME; break;
|
|
|
|
case eCSSKeyword_ms: units = eCSSUnit_Milliseconds; type = VARIANT_TIME; break;
|
1998-10-27 02:22:40 +03:00
|
|
|
default:
|
|
|
|
// unknown unit
|
2000-08-08 04:34:42 +04:00
|
|
|
aErrorCode = NS_ERROR_ILLEGAL_VALUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
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);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-06 22:25:25 +03:00
|
|
|
PRBool CSSParserImpl::ParsePositiveVariant(PRInt32& aErrorCode,
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue& aValue,
|
1999-01-06 22:25:25 +03:00
|
|
|
PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 aKeywordTable[])
|
1999-01-06 22:25:25 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseVariant(aErrorCode, aValue, aVariantMask, aKeywordTable)) {
|
|
|
|
if (eCSSUnit_Number == aValue.GetUnit() ||
|
|
|
|
aValue.IsLengthUnit()){
|
|
|
|
if (aValue.GetFloatValue() < 0) {
|
2001-10-06 19:13:23 +04:00
|
|
|
UngetToken();
|
1999-01-06 22:25:25 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
else if(aValue.GetUnit() == eCSSUnit_Percent) {
|
|
|
|
if (aValue.GetPercentValue() < 0) {
|
2001-10-06 19:13:23 +04:00
|
|
|
UngetToken();
|
1999-01-06 22:25:25 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseVariant(PRInt32& aErrorCode, nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 aKeywordTable[])
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
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)) {
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) { // known keyword
|
1998-10-27 02:22:40 +03:00
|
|
|
if ((aVariantMask & VARIANT_AUTO) != 0) {
|
1999-07-18 04:31:37 +04:00
|
|
|
if (eCSSKeyword_auto == keyword) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aValue.SetAutoValue();
|
1998-04-30 23:57:36 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
if ((aVariantMask & VARIANT_INHERIT) != 0) {
|
1999-07-18 04:31:37 +04:00
|
|
|
if (eCSSKeyword_inherit == keyword) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aValue.SetInheritValue();
|
1998-04-30 23:57:36 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (eCSSKeyword__moz_initial == keyword) { // anything that can inherit can also take an initial val.
|
|
|
|
aValue.SetInitialValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-30 23:57:36 +04:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
if ((aVariantMask & VARIANT_NONE) != 0) {
|
1999-07-18 04:31:37 +04:00
|
|
|
if (eCSSKeyword_none == keyword) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aValue.SetNoneValue();
|
1998-04-30 23:57:36 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
if ((aVariantMask & VARIANT_NORMAL) != 0) {
|
1999-07-18 04:31:37 +04:00
|
|
|
if (eCSSKeyword_normal == keyword) {
|
1998-10-27 02:22:40 +03:00
|
|
|
aValue.SetNormalValue();
|
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);
|
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) &&
|
1999-06-10 09:25:23 +04:00
|
|
|
tk->IsDimension()) {
|
2000-08-08 04:34:42 +04:00
|
|
|
return TranslateDimension(aErrorCode, aValue, aVariantMask, tk->mNumber, tk->mIdent);
|
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);
|
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);
|
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);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-08-05 08:40:03 +04:00
|
|
|
if (mNavQuirkMode && !IsParsingCompoundProperty()) { // NONSTANDARD: Nav interprets unitless numbers as px
|
1998-10-28 04:12:38 +03:00
|
|
|
if (((aVariantMask & VARIANT_LENGTH) != 0) &&
|
|
|
|
(eCSSToken_Number == tk->mType)) {
|
|
|
|
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Pixel);
|
|
|
|
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)) {
|
|
|
|
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) {
|
2000-08-05 08:40:03 +04:00
|
|
|
if ((mNavQuirkMode && !IsParsingCompoundProperty()) || // NONSTANDARD: Nav interprets 'xxyyzz' values even without '#' prefix
|
2000-01-08 13:11:10 +03:00
|
|
|
(eCSSToken_ID == tk->mType) ||
|
1998-10-27 02:22:40 +03:00
|
|
|
(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)) {
|
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);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_IDENTIFIER) != 0) &&
|
|
|
|
(eCSSToken_Ident == tk->mType)) {
|
|
|
|
aValue.SetStringValue(tk->mIdent, eCSSUnit_String);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_COUNTER) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
|
|
|
(tk->mIdent.EqualsIgnoreCase("counter") ||
|
|
|
|
tk->mIdent.EqualsIgnoreCase("counters"))) {
|
2000-08-08 04:34:42 +04:00
|
|
|
#ifdef ENABLE_COUNTERS
|
1998-10-27 02:22:40 +03:00
|
|
|
if (ParseCounter(aErrorCode, aValue)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-08-08 04:34:42 +04:00
|
|
|
#endif
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_ATTR) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
|
|
|
tk->mIdent.EqualsIgnoreCase("attr")) {
|
|
|
|
|
|
|
|
if (ParseAttr(aErrorCode, aValue)) {
|
|
|
|
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)) {
|
2001-12-16 14:58:03 +03:00
|
|
|
counter.Append(PRUnichar(','));
|
1998-10-27 02:22:40 +03:00
|
|
|
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)) {
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
|
|
|
|
if ((eCSSKeyword_UNKNOWN < keyword) &&
|
1998-10-27 02:22:40 +03:00
|
|
|
(0 < SearchKeywordTable(keyword, nsCSSProps::kListStyleKTable))) {
|
2001-12-16 14:58:03 +03:00
|
|
|
counter.Append(PRUnichar(','));
|
1998-10-27 02:22:40 +03:00
|
|
|
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)) {
|
1999-06-10 09:25:23 +04:00
|
|
|
nsAutoString attr;
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name or namespace
|
|
|
|
nsAutoString holdIdent(mToken.mIdent);
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) { // namespace
|
|
|
|
PRInt32 nameSpaceID = kNameSpaceID_Unknown;
|
|
|
|
if (mNameSpace) {
|
|
|
|
nsIAtom* prefix;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(holdIdent); // always case insensitive, since stays within CSS
|
2000-09-08 06:05:09 +04:00
|
|
|
prefix = NS_NewAtom(holdIdent);
|
1999-06-10 09:25:23 +04:00
|
|
|
mNameSpace->FindNameSpaceID(prefix, nameSpaceID);
|
|
|
|
NS_IF_RELEASE(prefix);
|
|
|
|
} // else, no delcared namespaces
|
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-04-16 00:15:37 +04:00
|
|
|
attr.AppendInt(nameSpaceID, 10);
|
2001-12-16 14:58:03 +03:00
|
|
|
attr.Append(PRUnichar('|'));
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
2000-04-27 04:12:25 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
attr.Append(mToken.mIdent);
|
|
|
|
} else {
|
|
|
|
nsAutoString buffer;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent, buffer);
|
2000-04-27 04:12:25 +04:00
|
|
|
attr.Append(buffer);
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // no namespace
|
2000-04-27 04:12:25 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
attr = holdIdent;
|
|
|
|
}
|
|
|
|
else {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(holdIdent, attr);
|
2000-04-27 04:12:25 +04:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // namespace wildcard
|
|
|
|
if (ExpectSymbol(aErrorCode, '|', PR_FALSE)) {
|
2000-04-16 00:15:37 +04:00
|
|
|
attr.AppendInt(kNameSpaceID_Unknown, 10);
|
2001-12-16 14:58:03 +03:00
|
|
|
attr.Append(PRUnichar('|'));
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
attr.Append(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // explicit NO namespace
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
2000-04-27 04:12:25 +04:00
|
|
|
if (mCaseSensitive) {
|
|
|
|
attr.Append(mToken.mIdent);
|
|
|
|
} else {
|
|
|
|
nsAutoString buffer;
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(mToken.mIdent, buffer);
|
2000-04-27 04:12:25 +04:00
|
|
|
attr.Append(buffer);
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
aValue.SetStringValue(attr, eCSSUnit_Attr);
|
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-09-09 01:13:20 +04:00
|
|
|
inline static PRBool
|
|
|
|
css_RequiresAbsoluteURI(const nsString& uri)
|
|
|
|
{
|
|
|
|
// cheap shot at figuring out if this requires an absolute url translation
|
|
|
|
return Substring(uri, 0, 9).Equals(NS_LITERAL_STRING("chrome:")) == PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
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;
|
2001-09-09 01:13:20 +04:00
|
|
|
if (nsnull != mURL && css_RequiresAbsoluteURI(tk->mIdent)) {
|
1999-06-18 21:34:08 +04:00
|
|
|
nsresult rv;
|
2001-09-09 01:13:20 +04:00
|
|
|
rv = NS_MakeAbsoluteURI(absURL, tk->mIdent, mURL);
|
1999-01-15 05:06:13 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
absURL = tk->mIdent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1998-10-27 02:22:40 +03:00
|
|
|
absURL = tk->mIdent;
|
|
|
|
}
|
|
|
|
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
aValue.SetStringValue(absURL, eCSSUnit_URL);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 CSSParserImpl::ParseChoice(PRInt32& aErrorCode, nsCSSValue aValues[],
|
1999-07-18 04:31:37 +04:00
|
|
|
const nsCSSProperty aPropIDs[], PRInt32 aNumIDs)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 found = 0;
|
2000-08-05 08:40:03 +04:00
|
|
|
SetParsingCompoundProperty(PR_TRUE);
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 loop;
|
1998-10-27 02:22:40 +03:00
|
|
|
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;
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
1998-10-27 02:22:40 +03:00
|
|
|
for (index = 0; index < aNumIDs; index++) {
|
|
|
|
PRInt32 bit = 1 << index;
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((found & bit) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, aValues[index], aPropIDs[index])) {
|
1998-04-14 00:24:54 +04:00
|
|
|
found |= bit;
|
|
|
|
}
|
2000-08-08 04:34:42 +04:00
|
|
|
if (aErrorCode == NS_ERROR_ILLEGAL_VALUE) { // bug 47138
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
found = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
if (found == hadFound) { // found nothing new
|
|
|
|
break;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (0 < found) {
|
|
|
|
if (1 == found) { // only first property
|
|
|
|
if (eCSSUnit_Inherit == aValues[0].GetUnit()) { // one inherit, all inherit
|
|
|
|
for (loop = 1; loop < aNumIDs; loop++) {
|
|
|
|
aValues[loop].SetInheritValue();
|
|
|
|
}
|
|
|
|
found = ((1 << aNumIDs) - 1);
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (eCSSUnit_Initial == aValues[0].GetUnit()) { // one initial, all initial
|
|
|
|
for (loop = 1; loop < aNumIDs; loop++) {
|
|
|
|
aValues[loop].SetInitialValue();
|
|
|
|
}
|
|
|
|
found = ((1 << aNumIDs) - 1);
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else { // more than one value, verify no inherits or initials
|
1999-02-10 11:37:52 +03:00
|
|
|
for (loop = 0; loop < aNumIDs; loop++) {
|
|
|
|
if (eCSSUnit_Inherit == aValues[loop].GetUnit()) {
|
|
|
|
found = -1;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (eCSSUnit_Initial == aValues[loop].GetUnit()) {
|
|
|
|
found = -1;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-08-08 04:34:42 +04:00
|
|
|
done:
|
2000-08-05 08:40:03 +04:00
|
|
|
SetParsingCompoundProperty(PR_FALSE);
|
1998-04-14 00:24:54 +04:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2002-08-24 18:41:28 +04:00
|
|
|
static nsChangeHint ComputeChangeHint(nsCSSProperty aPropID,
|
|
|
|
const nsCSSValue& aOldValue,
|
|
|
|
const nsCSSValue& aValue)
|
2002-01-27 10:53:27 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aOldValue != aValue,
|
|
|
|
"ComputeChangeHint should not be called with equal values");
|
|
|
|
|
|
|
|
switch (aPropID) {
|
|
|
|
case eCSSProperty_opacity:
|
|
|
|
// If the opacity is changing to or from 1.0, then reframe to (possibly)
|
|
|
|
// cause a view to be created or eliminated
|
|
|
|
// Otherwise we just need a visual change. This is important because
|
|
|
|
// opacity is frequently used for fade effects, and we don't want to reframe
|
|
|
|
// for every step of the fade.
|
|
|
|
if (aOldValue.GetUnit() == eCSSUnit_Number && aValue.GetUnit() == eCSSUnit_Number) {
|
|
|
|
if (aOldValue.GetFloatValue() == 1.0 || aValue.GetFloatValue() == 1.0) {
|
|
|
|
// XXX: it would be better to pass out a hint NS_STYLE_HINT_VIEWCHANGE,
|
|
|
|
// but it does not exist
|
|
|
|
return NS_STYLE_HINT_FRAMECHANGE;
|
|
|
|
}
|
2002-02-08 03:05:16 +03:00
|
|
|
return NS_STYLE_HINT_VISUAL;
|
2002-01-27 10:53:27 +03:00
|
|
|
}
|
2002-02-08 03:05:16 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2002-01-27 10:53:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSProps::kHintTable[aPropID];
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsresult CSSParserImpl::AppendValue(nsCSSDeclaration* aDeclaration, nsCSSProperty aPropID,
|
2002-08-24 18:41:28 +04:00
|
|
|
const nsCSSValue& aValue, nsChangeHint& aChangeHint)
|
1999-08-08 05:17:29 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
nsCSSValue oldValue;
|
|
|
|
result = aDeclaration->GetValue(aPropID, oldValue);
|
|
|
|
|
|
|
|
if (aValue != oldValue) {
|
|
|
|
result = aDeclaration->AppendValue(aPropID, aValue);
|
2002-01-27 10:53:27 +03:00
|
|
|
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, ComputeChangeHint(aPropID, oldValue, aValue));
|
1999-08-08 05:17:29 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* 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
|
1999-02-10 11:37:52 +03:00
|
|
|
* existing values.
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseBoxProperties(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1999-08-08 05:17:29 +04:00
|
|
|
const nsCSSProperty aPropIDs[],
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Get up to four values for the property
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[4];
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 count = 0;
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
1998-10-27 02:22:40 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (! ParseSingleValueProperty(aErrorCode, values[index], aPropIDs[index])) {
|
2000-08-08 04:34:42 +04:00
|
|
|
if (aErrorCode == NS_ERROR_ILLEGAL_VALUE) { // bug 47138
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
count = 0;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((count == 0) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
if (1 < count) { // verify no more than single inherit or initial
|
1999-02-10 11:37:52 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
2001-06-01 02:19:43 +04:00
|
|
|
if (eCSSUnit_Inherit == values[index].GetUnit() ||
|
|
|
|
eCSSUnit_Initial == values[index].GetUnit()) {
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Provide missing values by replicating some of the values found
|
|
|
|
switch (count) {
|
|
|
|
case 1: // Make right == top
|
1999-02-10 11:37:52 +03:00
|
|
|
values[1] = values[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
case 2: // Make bottom == top
|
1999-02-10 11:37:52 +03:00
|
|
|
values[2] = values[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
case 3: // Make left == right
|
1999-02-10 11:37:52 +03:00
|
|
|
values[3] = values[1];
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, aPropIDs[index], values[index], aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseProperty(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSProperty aPropID,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
switch (aPropID) { // handle shorthand or multiple properties
|
2001-12-18 01:51:39 +03:00
|
|
|
case eCSSProperty_appearance:
|
|
|
|
return ParseAppearance(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBackground(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_position:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBackgroundPosition(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorder(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_color:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderColor(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_spacing:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderSpacing(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_style:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderStyle(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_bottom:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderSide(aErrorCode, aDeclaration, kBorderBottomIDs, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_left:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderSide(aErrorCode, aDeclaration, kBorderLeftIDs, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_right:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderSide(aErrorCode, aDeclaration, kBorderRightIDs, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_top:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderSide(aErrorCode, aDeclaration, kBorderTopIDs, aChangeHint);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_bottom_colors:
|
|
|
|
case eCSSProperty_border_left_colors:
|
|
|
|
case eCSSProperty_border_right_colors:
|
|
|
|
case eCSSProperty_border_top_colors:
|
|
|
|
return ParseBorderColors(aErrorCode, aDeclaration, aChangeHint, aPropID);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_width:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBorderWidth(aErrorCode, aDeclaration, aChangeHint);
|
1999-12-22 14:27:10 +03:00
|
|
|
case eCSSProperty__moz_border_radius:
|
|
|
|
return ParseBorderRadius(aErrorCode, aDeclaration, aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2000-01-24 14:19:55 +03:00
|
|
|
case eCSSProperty__moz_outline_radius:
|
|
|
|
return ParseOutlineRadius(aErrorCode, aDeclaration, aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_clip:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseClip(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_content:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseContent(aErrorCode, aDeclaration, aChangeHint);
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_counter_increment:
|
|
|
|
case eCSSProperty__moz_counter_reset:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseCounterData(aErrorCode, aDeclaration, aPropID, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cue:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseCue(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cursor:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseCursor(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseFont(aErrorCode, aDeclaration, aChangeHint);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_image_region:
|
|
|
|
return ParseImageRegion(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseListStyle(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_margin:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseMargin(aErrorCode, aDeclaration, aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_outline:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseOutline(aErrorCode, aDeclaration, aChangeHint);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParsePadding(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pause:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParsePause(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_play_during:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParsePlayDuring(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_quotes:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseQuotes(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_size:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseSize(aErrorCode, aDeclaration, aChangeHint);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_shadow:
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseTextShadow(aErrorCode, aDeclaration, aChangeHint);
|
|
|
|
|
|
|
|
// Strip out properties we use internally. These properties are used
|
|
|
|
// by compound property parsing routines (e.g. "background-position").
|
|
|
|
case eCSSProperty_background_x_position:
|
|
|
|
case eCSSProperty_background_y_position:
|
|
|
|
case eCSSProperty_border_x_spacing:
|
|
|
|
case eCSSProperty_border_y_spacing:
|
|
|
|
case eCSSProperty_clip_bottom:
|
|
|
|
case eCSSProperty_clip_left:
|
|
|
|
case eCSSProperty_clip_right:
|
|
|
|
case eCSSProperty_clip_top:
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_image_region_bottom:
|
|
|
|
case eCSSProperty_image_region_left:
|
|
|
|
case eCSSProperty_image_region_right:
|
|
|
|
case eCSSProperty_image_region_top:
|
1999-08-08 05:17:29 +04:00
|
|
|
case eCSSProperty_play_during_flags:
|
|
|
|
case eCSSProperty_quotes_close:
|
|
|
|
case eCSSProperty_quotes_open:
|
|
|
|
case eCSSProperty_size_height:
|
|
|
|
case eCSSProperty_size_width:
|
|
|
|
case eCSSProperty_text_shadow_color:
|
|
|
|
case eCSSProperty_text_shadow_radius:
|
|
|
|
case eCSSProperty_text_shadow_x:
|
|
|
|
case eCSSProperty_text_shadow_y:
|
|
|
|
// The user can't use these
|
2001-03-06 04:57:30 +03:00
|
|
|
REPORT_UNEXPECTED(NS_LITERAL_STRING("Attempt to use inaccessible property"));
|
1999-08-08 05:17:29 +04:00
|
|
|
return PR_FALSE;
|
1999-02-10 11:37:52 +03:00
|
|
|
|
|
|
|
default: // must be single property
|
|
|
|
{
|
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseSingleValueProperty(aErrorCode, value, aPropID)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
aErrorCode = AppendValue(aDeclaration, aPropID, value, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-09-06 06:27:46 +04:00
|
|
|
// XXX Report errors?
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2000-09-06 06:27:46 +04:00
|
|
|
// XXX Report errors?
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bits used in determining which background position info we have
|
1999-03-28 08:29:57 +04:00
|
|
|
#define BG_CENTER 0x01
|
|
|
|
#define BG_TOP 0x02
|
|
|
|
#define BG_BOTTOM 0x04
|
|
|
|
#define BG_LEFT 0x08
|
|
|
|
#define BG_RIGHT 0x10
|
|
|
|
#define BG_CENTER1 0x20
|
|
|
|
#define BG_CENTER2 0x40
|
1999-02-10 11:37:52 +03:00
|
|
|
|
|
|
|
// Note: Don't change this table unless you update
|
|
|
|
// parseBackgroundPosition!
|
|
|
|
|
|
|
|
static const PRInt32 kBackgroundXYPositionKTable[] = {
|
1999-07-18 04:31:37 +04:00
|
|
|
eCSSKeyword_center, BG_CENTER,
|
|
|
|
eCSSKeyword_top, BG_TOP,
|
|
|
|
eCSSKeyword_bottom, BG_BOTTOM,
|
|
|
|
eCSSKeyword_left, BG_LEFT,
|
|
|
|
eCSSKeyword_right, BG_RIGHT,
|
1999-02-10 11:37:52 +03:00
|
|
|
-1,
|
|
|
|
};
|
|
|
|
|
|
|
|
PRBool CSSParserImpl::ParseSingleValueProperty(PRInt32& aErrorCode,
|
|
|
|
nsCSSValue& aValue,
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSProperty aPropID)
|
1999-02-10 11:37:52 +03:00
|
|
|
{
|
|
|
|
switch (aPropID) {
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_UNKNOWN:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background:
|
|
|
|
case eCSSProperty_background_position:
|
|
|
|
case eCSSProperty_border:
|
|
|
|
case eCSSProperty_border_color:
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_bottom_colors:
|
|
|
|
case eCSSProperty_border_left_colors:
|
|
|
|
case eCSSProperty_border_right_colors:
|
|
|
|
case eCSSProperty_border_top_colors:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_spacing:
|
|
|
|
case eCSSProperty_border_style:
|
|
|
|
case eCSSProperty_border_bottom:
|
|
|
|
case eCSSProperty_border_left:
|
|
|
|
case eCSSProperty_border_right:
|
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_width:
|
|
|
|
case eCSSProperty_clip:
|
|
|
|
case eCSSProperty_content:
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_counter_increment:
|
|
|
|
case eCSSProperty__moz_counter_reset:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cue:
|
|
|
|
case eCSSProperty_cursor:
|
|
|
|
case eCSSProperty_font:
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_image_region:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style:
|
|
|
|
case eCSSProperty_margin:
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_outline:
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding:
|
|
|
|
case eCSSProperty_pause:
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_play_during:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_quotes:
|
|
|
|
case eCSSProperty_size:
|
|
|
|
case eCSSProperty_text_shadow:
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_COUNT:
|
1999-02-10 11:37:52 +03:00
|
|
|
NS_ERROR("not a single value property");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_border_x_spacing:
|
|
|
|
case eCSSProperty_border_y_spacing:
|
|
|
|
case eCSSProperty_clip_bottom:
|
|
|
|
case eCSSProperty_clip_left:
|
|
|
|
case eCSSProperty_clip_right:
|
|
|
|
case eCSSProperty_clip_top:
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_image_region_bottom:
|
|
|
|
case eCSSProperty_image_region_left:
|
|
|
|
case eCSSProperty_image_region_right:
|
|
|
|
case eCSSProperty_image_region_top:
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_play_during_flags:
|
|
|
|
case eCSSProperty_quotes_close:
|
|
|
|
case eCSSProperty_quotes_open:
|
|
|
|
case eCSSProperty_size_height:
|
|
|
|
case eCSSProperty_size_width:
|
|
|
|
case eCSSProperty_text_shadow_color:
|
|
|
|
case eCSSProperty_text_shadow_radius:
|
|
|
|
case eCSSProperty_text_shadow_x:
|
|
|
|
case eCSSProperty_text_shadow_y:
|
|
|
|
NS_ERROR("not currently parsed here");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_azimuth:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseAzimuth(aErrorCode, aValue);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_attachment:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBackgroundAttachmentKTable);
|
2002-10-08 14:24:53 +04:00
|
|
|
case eCSSProperty__moz_background_clip:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBackgroundClipKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_color:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HCK,
|
|
|
|
nsCSSProps::kBackgroundColorKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_image:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
2002-10-08 14:24:53 +04:00
|
|
|
case eCSSProperty__moz_background_origin:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_repeat:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBackgroundRepeatKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_x_position:
|
|
|
|
case eCSSProperty_background_y_position:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HKLP,
|
|
|
|
kBackgroundXYPositionKTable);
|
2001-12-18 01:51:39 +03:00
|
|
|
case eCSSProperty_appearance:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK, nsCSSProps::kAppearanceKTable);
|
2001-06-01 02:19:43 +04:00
|
|
|
case eCSSProperty_binding:
|
2000-01-11 06:40:41 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_collapse:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBorderCollapseKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_bottom_color:
|
|
|
|
case eCSSProperty_border_left_color:
|
|
|
|
case eCSSProperty_border_right_color:
|
|
|
|
case eCSSProperty_border_top_color:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HCK,
|
|
|
|
nsCSSProps::kBorderColorKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_bottom_style:
|
|
|
|
case eCSSProperty_border_left_style:
|
|
|
|
case eCSSProperty_border_right_style:
|
|
|
|
case eCSSProperty_border_top_style:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kBorderStyleKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_bottom_width:
|
|
|
|
case eCSSProperty_border_left_width:
|
|
|
|
case eCSSProperty_border_right_width:
|
|
|
|
case eCSSProperty_border_top_width:
|
2002-09-11 05:47:25 +04:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HKL,
|
|
|
|
nsCSSProps::kBorderWidthKTable);
|
1999-12-22 14:27:10 +03:00
|
|
|
case eCSSProperty__moz_border_radius_topLeft:
|
|
|
|
case eCSSProperty__moz_border_radius_topRight:
|
|
|
|
case eCSSProperty__moz_border_radius_bottomRight:
|
|
|
|
case eCSSProperty__moz_border_radius_bottomLeft:
|
1999-04-03 07:15:01 +04:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2000-01-28 13:03:10 +03:00
|
|
|
case eCSSProperty__moz_outline_radius_topLeft:
|
|
|
|
case eCSSProperty__moz_outline_radius_topRight:
|
|
|
|
case eCSSProperty__moz_outline_radius_bottomRight:
|
|
|
|
case eCSSProperty__moz_outline_radius_bottomLeft:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_left:
|
|
|
|
case eCSSProperty_right:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHLP, nsnull);
|
2001-03-06 05:30:30 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
2001-08-02 04:09:27 +04:00
|
|
|
case eCSSProperty_box_align:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBoxAlignKTable);
|
|
|
|
case eCSSProperty_box_direction:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBoxDirectionKTable);
|
|
|
|
case eCSSProperty_box_flex:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN, nsnull);
|
2001-03-06 05:30:30 +03:00
|
|
|
case eCSSProperty_box_orient:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBoxOrientKTable);
|
2001-08-02 04:09:27 +04:00
|
|
|
case eCSSProperty_box_pack:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBoxPackKTable);
|
2001-09-26 02:17:00 +04:00
|
|
|
case eCSSProperty_box_ordinal_group:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_INTEGER, nsnull);
|
2001-12-12 10:59:31 +03:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_fill:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC | VARIANT_NONE,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_fill_opacity:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_fill_rule:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kFillRuleKTable);
|
|
|
|
case eCSSProperty_stroke:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC | VARIANT_NONE,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOS,
|
|
|
|
nsnull); // XXX parse into new CSS value type, not string
|
|
|
|
case eCSSProperty_stroke_dashoffset:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLPN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_linecap:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kStrokeLinecapKTable);
|
|
|
|
case eCSSProperty_stroke_linejoin:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kStrokeLinejoinKTable);
|
|
|
|
case eCSSProperty_stroke_miterlimit:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull); // XXX value > 1
|
|
|
|
case eCSSProperty_stroke_opacity:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_width:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLPN,
|
|
|
|
nsnull);
|
2001-03-06 05:30:30 +03:00
|
|
|
#endif
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_box_sizing:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBoxSizingKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_height:
|
|
|
|
case eCSSProperty_width:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_AHLP, nsnull);
|
2002-03-26 23:14:05 +03:00
|
|
|
case eCSSProperty_force_broken_image_icon:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_INTEGER, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_caption_side:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kCaptionSideKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_clear:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kClearKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_color:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cue_after:
|
|
|
|
case eCSSProperty_cue_before:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_direction:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kDirectionKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_display:
|
2000-03-23 17:45:04 +03:00
|
|
|
if (ParseVariant(aErrorCode, aValue, VARIANT_HOK, nsCSSProps::kDisplayKTable)) {
|
|
|
|
if (aValue.GetUnit() == eCSSUnit_Enumerated) {
|
|
|
|
switch (aValue.GetIntValue()) {
|
2000-08-05 08:40:03 +04:00
|
|
|
case NS_STYLE_DISPLAY_MARKER: // bug 2055
|
|
|
|
case NS_STYLE_DISPLAY_RUN_IN: // bug 2056
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT: // bug 14983
|
2000-03-26 00:26:14 +03:00
|
|
|
case NS_STYLE_DISPLAY_INLINE_TABLE: // bug 18218
|
2000-08-05 08:40:03 +04:00
|
|
|
//aErrorCode = NS_CSS_PARSER_DROP_DECLARATION; // bug 15432 (commented out for bug 46562 and 38397)
|
2000-03-23 17:45:04 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_elevation:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK | VARIANT_ANGLE,
|
|
|
|
nsCSSProps::kElevationKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_empty_cells:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kEmptyCellsKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_float:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kFloatKTable);
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_float_edge:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kFloatEdgeKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_family:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseFamily(aErrorCode, aValue);
|
2000-02-11 04:22:47 +03:00
|
|
|
case eCSSProperty_font_size:
|
2001-08-11 02:46:53 +04:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HKLP,
|
|
|
|
nsCSSProps::kFontSizeKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_size_adjust:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HON,
|
|
|
|
nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_stretch:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK,
|
|
|
|
nsCSSProps::kFontStretchKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_style:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK,
|
|
|
|
nsCSSProps::kFontStyleKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_variant:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK,
|
|
|
|
nsCSSProps::kFontVariantKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font_weight:
|
1999-09-10 09:55:36 +04:00
|
|
|
return ParseFontWeight(aErrorCode, aValue);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_letter_spacing:
|
|
|
|
case eCSSProperty_word_spacing:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HL | VARIANT_NORMAL, nsnull);
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_key_equivalent:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kKeyEquivalentKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_line_height:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLPN | VARIANT_NORMAL, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style_image:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style_position:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK, nsCSSProps::kListStylePositionKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style_type:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK, nsCSSProps::kListStyleKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_margin_bottom:
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_top:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHLP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_marker_offset:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHL, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_marks:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseMarks(aErrorCode, aValue);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_max_height:
|
|
|
|
case eCSSProperty_max_width:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLPO, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_min_height:
|
|
|
|
case eCSSProperty_min_width:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_opacity:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HPN, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_orphans:
|
|
|
|
case eCSSProperty_widows:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HI, nsnull);
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_outline_color:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HCK,
|
|
|
|
nsCSSProps::kOutlineColorKTable);
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_outline_style:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kBorderStyleKTable);
|
2002-09-26 07:46:50 +04:00
|
|
|
case eCSSProperty__moz_outline_width:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HKL,
|
|
|
|
nsCSSProps::kBorderWidthKTable);
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_overflow:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kOverflowKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding_bottom:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_top:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_page:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AUTO | VARIANT_IDENTIFIER, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_page_break_after:
|
|
|
|
case eCSSProperty_page_break_before:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kPageBreakKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_page_break_inside:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kPageBreakInsideKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pause_after:
|
|
|
|
case eCSSProperty_pause_before:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HTP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pitch:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HKF, nsCSSProps::kPitchKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pitch_range:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_position:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK, nsCSSProps::kPositionKTable);
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_resizer:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK | VARIANT_NONE,
|
|
|
|
nsCSSProps::kResizerKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_richness:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_speak:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK | VARIANT_NONE,
|
|
|
|
nsCSSProps::kSpeakKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_speak_header:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kSpeakHeaderKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_speak_numeral:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kSpeakNumeralKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_speak_punctuation:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kSpeakPunctuationKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_speech_rate:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN | VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kSpeechRateKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_stress:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_table_layout:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kTableLayoutKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_align:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK | VARIANT_STRING,
|
|
|
|
nsCSSProps::kTextAlignKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_decoration:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseTextDecoration(aErrorCode, aValue);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_indent:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_transform:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kTextTransformKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_unicode_bidi:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK,
|
|
|
|
nsCSSProps::kUnicodeBidiKTable);
|
1999-09-04 03:40:35 +04:00
|
|
|
case eCSSProperty_user_focus:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK | VARIANT_NONE,
|
|
|
|
nsCSSProps::kUserFocusKTable);
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_user_input:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK | VARIANT_NONE,
|
|
|
|
nsCSSProps::kUserInputKTable);
|
1999-09-04 03:40:35 +04:00
|
|
|
case eCSSProperty_user_modify:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kUserModifyKTable);
|
|
|
|
case eCSSProperty_user_select:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
|
|
|
nsCSSProps::kUserSelectKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_vertical_align:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HKLP,
|
|
|
|
nsCSSProps::kVerticalAlignKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_visibility:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kVisibilityKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_voice_family:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseFamily(aErrorCode, aValue);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_volume:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HPN | VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kVolumeKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_white_space:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HMK,
|
|
|
|
nsCSSProps::kWhitespaceKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_z_index:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHI, nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-07-24 23:04:42 +04:00
|
|
|
// explicitly do NOT have a default case to let the compiler
|
|
|
|
// help find missing properties
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool CSSParserImpl::ParseAzimuth(PRInt32& aErrorCode, nsCSSValue& aValue)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseVariant(aErrorCode, aValue, VARIANT_HK | VARIANT_ANGLE,
|
|
|
|
nsCSSProps::kAzimuthKTable)) {
|
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
|
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
1998-10-27 02:22:40 +03:00
|
|
|
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))) {
|
1999-02-10 11:37:52 +03:00
|
|
|
aValue.SetIntValue(intValue | enumValue, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// Put the unknown identifier back and return
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseAppearance(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
2001-12-18 01:51:39 +03:00
|
|
|
{
|
|
|
|
nsCSSValue appearance;
|
|
|
|
if (!ParseVariant(aErrorCode, appearance, VARIANT_HK, nsCSSProps::kAppearanceKTable))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE))
|
|
|
|
aErrorCode = AppendValue(aDeclaration, eCSSProperty_appearance, appearance, aChangeHint);
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBackground(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 6;
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBackgroundIDs[numProps] = {
|
|
|
|
eCSSProperty_background_color,
|
|
|
|
eCSSProperty_background_image,
|
|
|
|
eCSSProperty_background_repeat,
|
|
|
|
eCSSProperty_background_attachment,
|
|
|
|
eCSSProperty_background_x_position,
|
|
|
|
eCSSProperty_background_y_position
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[numProps];
|
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, kBackgroundIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
if (0 != (found & 0x30)) { // found one or more position values, validate them
|
|
|
|
if (0 == (found & 0x20)) { // x value only
|
|
|
|
if (eCSSUnit_Enumerated == values[4].GetUnit()) {
|
|
|
|
switch (values[4].GetIntValue()) {
|
|
|
|
case BG_CENTER:
|
|
|
|
values[4].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
values[5].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_TOP:
|
|
|
|
values[4].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
values[5].SetIntValue(0, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_BOTTOM:
|
|
|
|
values[4].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
values[5].SetIntValue(100, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_LEFT:
|
|
|
|
values[4].SetIntValue(0, eCSSUnit_Enumerated);
|
|
|
|
values[5].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_RIGHT:
|
|
|
|
values[4].SetIntValue(100, eCSSUnit_Enumerated);
|
|
|
|
values[5].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Inherit == values[4].GetUnit()) {
|
|
|
|
values[5].SetInheritValue();
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (eCSSUnit_Initial == values[4].GetUnit()) {
|
|
|
|
values[5].SetInitialValue();
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
else {
|
2000-08-05 08:40:03 +04:00
|
|
|
values[5].SetPercentValue(0.5f);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // both x & y values
|
|
|
|
nsCSSUnit xUnit = values[4].GetUnit();
|
|
|
|
nsCSSUnit yUnit = values[5].GetUnit();
|
|
|
|
if (eCSSUnit_Enumerated == xUnit) { // if one is enumerated, both must be
|
|
|
|
if (eCSSUnit_Enumerated == yUnit) {
|
|
|
|
PRInt32 xValue = values[4].GetIntValue();
|
|
|
|
PRInt32 yValue = values[5].GetIntValue();
|
2002-02-22 03:25:57 +03:00
|
|
|
if (0 != (xValue & (BG_LEFT | BG_RIGHT)) && // x is really an x value
|
|
|
|
0 != (yValue & (BG_LEFT | BG_RIGHT))) { // y is also an x value
|
|
|
|
return PR_FALSE;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2002-02-22 03:25:57 +03:00
|
|
|
if (0 != (xValue & (BG_TOP | BG_BOTTOM)) && // x is really an y value
|
|
|
|
0 != (yValue & (BG_TOP | BG_BOTTOM))) { // y is also an y value
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (0 != (xValue & (BG_TOP | BG_BOTTOM)) || // x is really a y value
|
|
|
|
0 != (yValue & (BG_LEFT | BG_RIGHT))) { // or y is really an x value
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 holdXValue = xValue;
|
|
|
|
xValue = yValue;
|
|
|
|
yValue = holdXValue;
|
|
|
|
}
|
|
|
|
switch (xValue) {
|
|
|
|
case BG_LEFT:
|
|
|
|
values[4].SetIntValue(0, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_CENTER:
|
|
|
|
values[4].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_RIGHT:
|
|
|
|
values[4].SetIntValue(100, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad x value");
|
|
|
|
}
|
|
|
|
switch (yValue) {
|
|
|
|
case BG_TOP:
|
|
|
|
values[5].SetIntValue(0, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_CENTER:
|
|
|
|
values[5].SetIntValue(50, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case BG_BOTTOM:
|
|
|
|
values[5].SetIntValue(100, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("bad y value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eCSSUnit_Enumerated == yUnit) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Provide missing values
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 0x01) == 0) {
|
|
|
|
values[0].SetIntValue(NS_STYLE_BG_COLOR_TRANSPARENT, eCSSUnit_Enumerated);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 0x02) == 0) {
|
|
|
|
values[1].SetNoneValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 0x04) == 0) {
|
|
|
|
values[2].SetIntValue(NS_STYLE_BG_REPEAT_XY, eCSSUnit_Enumerated);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 0x08) == 0) {
|
|
|
|
values[3].SetIntValue(NS_STYLE_BG_ATTACHMENT_SCROLL, eCSSUnit_Enumerated);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 0x30) == 0) {
|
|
|
|
values[4].SetPercentValue(0.0f);
|
|
|
|
values[5].SetPercentValue(0.0f);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
2002-10-08 14:24:53 +04:00
|
|
|
for (index = 0; index < numProps; ++index) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kBackgroundIDs[index], values[index], aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
|
|
|
|
// Background properties not settable from the shorthand get reset to their initial value
|
|
|
|
const PRInt32 numResetProps = 2;
|
|
|
|
static const nsCSSProperty kBackgroundResetIDs[numResetProps] = {
|
|
|
|
eCSSProperty__moz_background_clip,
|
|
|
|
eCSSProperty__moz_background_origin
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCSSValue initial;
|
|
|
|
initial.SetInitialValue();
|
|
|
|
for (index = 0; index < numResetProps; ++index) {
|
|
|
|
AppendValue(aDeclaration, kBackgroundResetIDs[index], initial, aChangeHint);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParseBackgroundPosition(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// First try a number or a length value
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue xValue;
|
|
|
|
if (ParseVariant(aErrorCode, xValue, VARIANT_HLP, nsnull)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
if (eCSSUnit_Inherit == xValue.GetUnit() ||
|
|
|
|
eCSSUnit_Initial == xValue.GetUnit()) { // both are inherited or both are set to initial
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_x_position, xValue, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_y_position, xValue, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
// We have one number/length. Get the optional second number/length.
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue yValue;
|
|
|
|
if (ParseVariant(aErrorCode, yValue, VARIANT_LP, nsnull)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// We have two numbers
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_x_position, xValue, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_y_position, yValue, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have one number which is the x position. Create an value for
|
|
|
|
// the vertical position which is of value 50%
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_x_position, xValue, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_y_position, nsCSSValue(0.5f, eCSSUnit_Percent), aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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++) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (PR_FALSE == ParseEnum(aErrorCode, xValue, kBackgroundXYPositionKTable)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 bit = xValue.GetIntValue();
|
1999-05-19 03:12:17 +04:00
|
|
|
if (BG_CENTER == bit) {
|
1999-02-10 11:37:52 +03: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;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
mask |= bit;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 xEnumValue = 50;
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((mask & (BG_LEFT | BG_RIGHT)) != 0) {
|
|
|
|
// We have an x value
|
1999-02-10 11:37:52 +03:00
|
|
|
xEnumValue = ((mask & BG_LEFT) != 0) ? 0 : 100;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 yEnumValue = 50;
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((mask & (BG_TOP | BG_BOTTOM)) != 0) {
|
|
|
|
// We have a y value
|
1999-02-10 11:37:52 +03:00
|
|
|
yEnumValue = ((mask & BG_TOP) != 0) ? 0 : 100;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
// Create style values
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_x_position, nsCSSValue(xEnumValue, eCSSUnit_Enumerated), aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_background_y_position, nsCSSValue(yEnumValue, eCSSUnit_Enumerated), aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
// These must be in CSS order (top,right,bottom,left) for indexing to work
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderStyleIDs[] = {
|
|
|
|
eCSSProperty_border_top_style,
|
|
|
|
eCSSProperty_border_right_style,
|
|
|
|
eCSSProperty_border_bottom_style,
|
|
|
|
eCSSProperty_border_left_style
|
1998-10-27 02:22:40 +03:00
|
|
|
};
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderWidthIDs[] = {
|
|
|
|
eCSSProperty_border_top_width,
|
|
|
|
eCSSProperty_border_right_width,
|
|
|
|
eCSSProperty_border_bottom_width,
|
|
|
|
eCSSProperty_border_left_width
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderColorIDs[] = {
|
|
|
|
eCSSProperty_border_top_color,
|
|
|
|
eCSSProperty_border_right_color,
|
|
|
|
eCSSProperty_border_bottom_color,
|
|
|
|
eCSSProperty_border_left_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-12-22 14:27:10 +03:00
|
|
|
static const nsCSSProperty kBorderRadiusIDs[] = {
|
|
|
|
eCSSProperty__moz_border_radius_topLeft,
|
|
|
|
eCSSProperty__moz_border_radius_topRight,
|
|
|
|
eCSSProperty__moz_border_radius_bottomRight,
|
|
|
|
eCSSProperty__moz_border_radius_bottomLeft
|
|
|
|
};
|
2000-01-24 14:19:55 +03:00
|
|
|
static const nsCSSProperty kOutlineRadiusIDs[] = {
|
|
|
|
eCSSProperty__moz_outline_radius_topLeft,
|
|
|
|
eCSSProperty__moz_outline_radius_topRight,
|
|
|
|
eCSSProperty__moz_outline_radius_bottomRight,
|
|
|
|
eCSSProperty__moz_outline_radius_bottomLeft
|
|
|
|
};
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorder(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 3;
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kBorderIDs[] = {
|
|
|
|
eCSSProperty_border_top_width, // only one value per property
|
|
|
|
eCSSProperty_border_top_style,
|
|
|
|
eCSSProperty_border_top_color
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1998-10-27 02:22:40 +03:00
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[numProps];
|
1998-10-27 02:22:40 +03:00
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, kBorderIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
|
|
|
|
if (0 == (found & 1)) { // provide missing border width's
|
|
|
|
values[0].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
if (0 == (found & 2)) { // provide missing border style's
|
|
|
|
values[1].SetNoneValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-05-02 14:31:31 +04:00
|
|
|
if (0 == (found & 4)) { // text color will be used
|
|
|
|
values[2].SetIntValue(NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < 4; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kBorderWidthIDs[index], values[0], aChangeHint);
|
|
|
|
AppendValue(aDeclaration, kBorderStyleIDs[index], values[1], aChangeHint);
|
|
|
|
AppendValue(aDeclaration, kBorderColorIDs[index], values[2], aChangeHint);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderColor(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderColorIDs, aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderSpacing(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue xValue;
|
2001-10-06 19:13:23 +04:00
|
|
|
if (ParsePositiveVariant(aErrorCode, xValue, VARIANT_HL, nsnull)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (xValue.IsLengthUnit()) {
|
|
|
|
// We have one length. Get the optional second length.
|
|
|
|
nsCSSValue yValue;
|
2001-10-06 19:13:23 +04:00
|
|
|
if (ParsePositiveVariant(aErrorCode, yValue, VARIANT_LENGTH, nsnull)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
// We have two numbers
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_border_x_spacing, xValue, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_border_y_spacing, yValue, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have one length which is the horizontal spacing. Create a value for
|
|
|
|
// the vertical spacing which is equal
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_border_x_spacing, xValue, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_border_y_spacing, xValue, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderSide(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
const nsCSSProperty aPropIDs[], nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
nsCSSValue values[numProps];
|
|
|
|
|
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, aPropIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 1) == 0) { // Provide default border-width
|
|
|
|
values[0].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 2) == 0) { // Provide default border-style
|
|
|
|
values[1].SetNoneValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if ((found & 4) == 0) { // reset border-color so color property gets used
|
|
|
|
values[2].Reset();
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < numProps; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, aPropIDs[index], values[index], aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderStyle(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderStyleIDs, aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderWidth(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderWidthIDs, aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderRadius(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1999-12-22 14:27:10 +03:00
|
|
|
{
|
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kBorderRadiusIDs, aChangeHint);
|
|
|
|
}
|
|
|
|
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseOutlineRadius(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
2000-01-24 14:19:55 +03:00
|
|
|
{
|
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kOutlineRadiusIDs, aChangeHint);
|
|
|
|
}
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1999-12-22 14:27:10 +03:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderColors(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint, nsCSSProperty aProperty)
|
2001-12-05 11:35:05 +03:00
|
|
|
{
|
|
|
|
nsCSSValue value;
|
2001-12-11 14:13:53 +03:00
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_HCK|VARIANT_NONE, nsCSSProps::kBorderColorKTable)) {
|
2001-12-05 11:35:05 +03:00
|
|
|
nsCSSValueList* listHead = new nsCSSValueList();
|
|
|
|
nsCSSValueList* list = listHead;
|
|
|
|
if (!list) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
list->mValue = value;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
aErrorCode = aDeclaration->AppendStructValue(aProperty, listHead);
|
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
2001-12-11 14:13:53 +03:00
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_HCK|VARIANT_NONE, nsCSSProps::kBorderColorKTable)) {
|
2001-12-05 11:35:05 +03:00
|
|
|
list->mNext = new nsCSSValueList();
|
|
|
|
list = list->mNext;
|
|
|
|
if (list)
|
|
|
|
list->mValue = value;
|
|
|
|
else
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete listHead;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseClip(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kClipIDs[] = {
|
|
|
|
eCSSProperty_clip_top,
|
|
|
|
eCSSProperty_clip_right,
|
|
|
|
eCSSProperty_clip_bottom,
|
|
|
|
eCSSProperty_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;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
1998-10-27 02:22:40 +03:00
|
|
|
if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("auto")) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue valueAuto(eCSSUnit_Auto);
|
|
|
|
for (index = 0; index < 4; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kClipIDs[index], valueAuto, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
} else if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("inherit")) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue inherit(eCSSUnit_Inherit);
|
|
|
|
for (index = 0; index < 4; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kClipIDs[index], inherit, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-05-13 02:56:18 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
else if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("-moz-initial")) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue initial(eCSSUnit_Initial);
|
|
|
|
for (index = 0; index < 4; index++) {
|
|
|
|
AppendValue(aDeclaration, kClipIDs[index], initial, aChangeHint);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[4];
|
1998-10-27 02:22:40 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
1999-04-10 21:33:09 +04:00
|
|
|
if (! ParseVariant(aErrorCode, values[index], VARIANT_AL, nsnull)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
for (index = 0; index < 4; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kClipIDs[index], values[index], aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseImageRegion(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
2001-12-05 11:35:05 +03:00
|
|
|
{
|
|
|
|
static const nsCSSProperty kImageRegionIDs[] = {
|
|
|
|
eCSSProperty_image_region_top,
|
|
|
|
eCSSProperty_image_region_right,
|
|
|
|
eCSSProperty_image_region_bottom,
|
|
|
|
eCSSProperty_image_region_left
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("auto")) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue valueAuto(eCSSUnit_Auto);
|
|
|
|
for (index = 0; index < 4; index++) {
|
|
|
|
AppendValue(aDeclaration, kImageRegionIDs[index], valueAuto, aChangeHint);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("inherit")) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue inherit(eCSSUnit_Inherit);
|
|
|
|
for (index = 0; index < 4; index++) {
|
|
|
|
AppendValue(aDeclaration, kImageRegionIDs[index], inherit, aChangeHint);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((eCSSToken_Ident == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("-moz-initial")) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue initial(eCSSUnit_Initial);
|
|
|
|
for (index = 0; index < 4; index++) {
|
|
|
|
AppendValue(aDeclaration, kImageRegionIDs[index], initial, aChangeHint);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else if ((eCSSToken_Function == mToken.mType) &&
|
|
|
|
mToken.mIdent.EqualsIgnoreCase("rect")) {
|
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
nsCSSValue values[4];
|
|
|
|
for (index = 0; index < 4; index++) {
|
|
|
|
if (!ParseVariant(aErrorCode, values[index], VARIANT_AL, nsnull))
|
|
|
|
return PR_FALSE;
|
|
|
|
if (3 != index) {
|
|
|
|
// skip optional commas between elements
|
|
|
|
ExpectSymbol(aErrorCode, ',', PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
for (index = 0; index < 4; index++)
|
|
|
|
AppendValue(aDeclaration, kImageRegionIDs[index], values[index], aChangeHint);
|
|
|
|
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)
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseContent(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_CONTENT | VARIANT_INHERIT,
|
|
|
|
nsCSSProps::kContentKTable)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
if (eCSSUnit_Inherit == value.GetUnit() || eCSSUnit_Initial == value.GetUnit()) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_content, value, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValueList* listHead = new nsCSSValueList();
|
|
|
|
nsCSSValueList* list = listHead;
|
|
|
|
if (nsnull == list) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
list->mValue = value;
|
|
|
|
|
|
|
|
while (nsnull != list) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[eCSSProperty_content]);
|
1999-07-18 04:31:37 +04:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(eCSSProperty_content, listHead);
|
1999-02-10 11:37:52 +03:00
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_CONTENT, nsCSSProps::kContentKTable)) {
|
|
|
|
list->mNext = new nsCSSValueList();
|
|
|
|
list = list->mNext;
|
|
|
|
if (nsnull != list) {
|
|
|
|
list->mValue = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete listHead;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseCounterData(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsCSSProperty aPropID, nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
nsString* ident = NextIdent(aErrorCode);
|
|
|
|
if (nsnull == ident) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (ident->EqualsIgnoreCase("none")) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, aPropID, nsCSSValue(eCSSUnit_None), aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else if (ident->EqualsIgnoreCase("inherit")) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, aPropID, nsCSSValue(eCSSUnit_Inherit), aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (ident->EqualsIgnoreCase("-moz-initial")) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
AppendValue(aDeclaration, aPropID, nsCSSValue(eCSSUnit_Initial), aChangeHint);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
else {
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSCounterData* dataHead = new nsCSSCounterData();
|
|
|
|
nsCSSCounterData* data = dataHead;
|
|
|
|
if (nsnull == data) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
data->mCounter.SetStringValue(*ident, eCSSUnit_String);
|
|
|
|
|
|
|
|
while (nsnull != data) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[aPropID]);
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(aPropID, dataHead);
|
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Number == mToken.mType) && (mToken.mIntegerValid)) {
|
|
|
|
data->mValue.SetIntValue(mToken.mInteger, eCSSUnit_Integer);
|
1998-10-27 02:22:40 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[aPropID]);
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(aPropID, dataHead);
|
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
data->mNext = new nsCSSCounterData();
|
|
|
|
data = data->mNext;
|
|
|
|
if (nsnull != data) {
|
|
|
|
data->mCounter.SetStringValue(mToken.mIdent, eCSSUnit_String);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
delete dataHead;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseCue(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue before;
|
1999-07-18 04:31:37 +04:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, before, eCSSProperty_cue_before)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (eCSSUnit_URL == before.GetUnit()) {
|
|
|
|
nsCSSValue after;
|
1999-07-18 04:31:37 +04:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, after, eCSSProperty_cue_after)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_cue_before, before, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_cue_after, after, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_cue_before, before, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_cue_after, before, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseCursor(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_AHUK, nsCSSProps::kCursorKTable)) {
|
|
|
|
if (eCSSUnit_URL == value.GetUnit()) {
|
|
|
|
nsCSSValueList* listHead = new nsCSSValueList();
|
|
|
|
nsCSSValueList* list = listHead;
|
|
|
|
if (nsnull == list) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
list->mValue = value;
|
|
|
|
while (nsnull != list) {
|
|
|
|
if (eCSSUnit_URL != value.GetUnit()) {
|
|
|
|
if (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[eCSSProperty_cursor]);
|
1999-07-18 04:31:37 +04:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(eCSSProperty_cursor, listHead);
|
1999-02-10 11:37:52 +03:00
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_AHUK, nsCSSProps::kCursorKTable)) {
|
|
|
|
list->mNext = new nsCSSValueList();
|
|
|
|
list = list->mNext;
|
|
|
|
if (nsnull != list) {
|
|
|
|
list->mValue = value;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
delete listHead;
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_cursor, value, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseFont(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty fontIDs[] = {
|
|
|
|
eCSSProperty_font_style,
|
|
|
|
eCSSProperty_font_variant,
|
|
|
|
eCSSProperty_font_weight
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue family;
|
|
|
|
if (ParseVariant(aErrorCode, family, VARIANT_HK, nsCSSProps::kFontKTable)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
if (eCSSUnit_Inherit == family.GetUnit()) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_family, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_style, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_variant, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_weight, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_line_height, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_stretch, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size_adjust, family, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_family, family, aChangeHint); // keyword value overrides everything else
|
1999-02-27 10:15:59 +03:00
|
|
|
nsCSSValue empty;
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_style, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_variant, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_weight, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_line_height, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_stretch, empty, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size_adjust, empty, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Get optional font-style, font-variant and font-weight (in any order)
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
nsCSSValue values[numProps];
|
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, fontIDs, numProps);
|
2001-06-01 02:19:43 +04:00
|
|
|
if ((found < 0) || (eCSSUnit_Inherit == values[0].GetUnit()) ||
|
|
|
|
(eCSSUnit_Initial == values[0].GetUnit())) { // illegal data
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((found & 1) == 0) {
|
|
|
|
// Provide default font-style
|
1999-02-10 11:37:52 +03:00
|
|
|
values[0].SetNormalValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if ((found & 2) == 0) {
|
|
|
|
// Provide default font-variant
|
1999-02-10 11:37:52 +03:00
|
|
|
values[1].SetNormalValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) {
|
|
|
|
// Provide default font-weight
|
1999-02-10 11:37:52 +03:00
|
|
|
values[2].SetNormalValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get mandatory font-size
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue size;
|
|
|
|
if (! ParseVariant(aErrorCode, size, VARIANT_KEYWORD | VARIANT_LP, nsCSSProps::kFontSizeKTable)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get optional "/" line-height
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue lineHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (ExpectSymbol(aErrorCode, '/', PR_TRUE)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (! ParseVariant(aErrorCode, lineHeight, VARIANT_NUMBER | VARIANT_LP | VARIANT_NORMAL, nsnull)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
else {
|
1999-02-10 11:37:52 +03:00
|
|
|
lineHeight.SetNormalValue();
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Get final mandatory font-family
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseFamily(aErrorCode, family)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
if ((eCSSUnit_Inherit != family.GetUnit()) && (eCSSUnit_Initial != family.GetUnit()) &&
|
|
|
|
ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_family, family, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_style, values[0], aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_variant, values[1], aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_weight, values[2], aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size, size, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_line_height, lineHeight, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_stretch, nsCSSValue(eCSSUnit_Normal), aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_font_size_adjust, nsCSSValue(eCSSUnit_None), aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-09-10 09:55:36 +04:00
|
|
|
PRBool CSSParserImpl::ParseFontWeight(PRInt32& aErrorCode, nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
if (ParseVariant(aErrorCode, aValue, VARIANT_HMKI, nsCSSProps::kFontWeightKTable)) {
|
|
|
|
if (eCSSUnit_Integer == aValue.GetUnit()) { // ensure unit value
|
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
2001-08-11 02:46:53 +04:00
|
|
|
if ((100 <= intValue) &&
|
|
|
|
(intValue <= 900) &&
|
|
|
|
(0 == (intValue % 100))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-09-10 09:55:36 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool CSSParserImpl::ParseFamily(PRInt32& aErrorCode, nsCSSValue& aValue)
|
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")) {
|
1999-02-10 11:37:52 +03:00
|
|
|
aValue.SetInheritValue();
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
else if (tk->mIdent.EqualsIgnoreCase("initial")) {
|
|
|
|
aValue.SetInitialValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2002-01-24 05:03:19 +03:00
|
|
|
if (family.IsEmpty()) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
aValue.SetStringValue(family, eCSSUnit_String);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseListStyle(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 3;
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty listStyleIDs[] = {
|
|
|
|
eCSSProperty_list_style_type,
|
|
|
|
eCSSProperty_list_style_position,
|
|
|
|
eCSSProperty_list_style_image
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1998-10-27 02:22:40 +03:00
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[numProps];
|
|
|
|
PRInt32 index;
|
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, listStyleIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
|
|
|
|
// Provide default values
|
|
|
|
if ((found & 1) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[0].SetIntValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
if ((found & 2) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[1].SetIntValue(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE, eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[2].SetNoneValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < numProps; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, listStyleIDs[index], values[index], aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseMargin(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kMarginSideIDs[] = {
|
|
|
|
eCSSProperty_margin_top,
|
|
|
|
eCSSProperty_margin_right,
|
|
|
|
eCSSProperty_margin_bottom,
|
|
|
|
eCSSProperty_margin_left
|
1998-10-27 02:22:40 +03:00
|
|
|
};
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kMarginSideIDs, aChangeHint);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool CSSParserImpl::ParseMarks(PRInt32& aErrorCode, nsCSSValue& aValue)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseVariant(aErrorCode, aValue, VARIANT_HOK, nsCSSProps::kPageMarksKTable)) {
|
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
|
|
|
|
if (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSValue second;
|
|
|
|
if (ParseEnum(aErrorCode, second, nsCSSProps::kPageMarksKTable)) {
|
|
|
|
aValue.SetIntValue(aValue.GetIntValue() | second.GetIntValue(), eCSSUnit_Enumerated);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
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;
|
|
|
|
}
|
|
|
|
|
2000-08-05 08:40:03 +04:00
|
|
|
#ifdef ENABLE_OUTLINE
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseOutline(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 numProps = 3;
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kOutlineIDs[] = {
|
2002-09-26 07:46:50 +04:00
|
|
|
eCSSProperty__moz_outline_color,
|
|
|
|
eCSSProperty__moz_outline_style,
|
|
|
|
eCSSProperty__moz_outline_width
|
1998-10-27 02:22:40 +03:00
|
|
|
};
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue values[numProps];
|
|
|
|
PRInt32 found = ParseChoice(aErrorCode, values, kOutlineIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty(aErrorCode, PR_TRUE))) {
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Provide default values
|
|
|
|
if ((found & 1) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[0].SetIntValue(NS_STYLE_COLOR_INVERT, eCSSUnit_Enumerated);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if ((found & 2) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[1].SetNoneValue();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) {
|
1999-02-10 11:37:52 +03:00
|
|
|
values[2].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < numProps; index++) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, kOutlineIDs[index], values[index], aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-08-05 08:40:03 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParsePadding(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kPaddingSideIDs[] = {
|
|
|
|
eCSSProperty_padding_top,
|
|
|
|
eCSSProperty_padding_right,
|
|
|
|
eCSSProperty_padding_bottom,
|
|
|
|
eCSSProperty_padding_left
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
1999-08-08 05:17:29 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, aDeclaration, kPaddingSideIDs, aChangeHint);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
PRBool CSSParserImpl::ParsePause(PRInt32& aErrorCode,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsCSSDeclaration* aDeclaration, nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue before;
|
1999-07-18 04:31:37 +04:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, before, eCSSProperty_pause_before)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
if (eCSSUnit_Inherit != before.GetUnit() && eCSSUnit_Initial != before.GetUnit()) {
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue after;
|
1999-07-18 04:31:37 +04:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, after, eCSSProperty_pause_after)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_pause_before, before, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_pause_after, after, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_pause_before, before, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_pause_after, before, aChangeHint);
|
1999-02-10 11:37:52 +03: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::ParsePlayDuring(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue playDuring;
|
|
|
|
nsCSSValue flags;
|
|
|
|
if (ParseVariant(aErrorCode, playDuring, VARIANT_AHUO, nsnull)) {
|
|
|
|
if (eCSSUnit_URL == playDuring.GetUnit()) {
|
|
|
|
if (ParseEnum(aErrorCode, flags, nsCSSProps::kPlayDuringKTable)) {
|
|
|
|
PRInt32 intValue = flags.GetIntValue();
|
|
|
|
if (ParseEnum(aErrorCode, flags, nsCSSProps::kPlayDuringKTable)) {
|
|
|
|
flags.SetIntValue(intValue | flags.GetIntValue(), eCSSUnit_Enumerated);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_play_during, playDuring, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_play_during_flags, flags, aChangeHint);
|
1999-02-10 11:37:52 +03: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::ParseQuotes(PRInt32& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint &aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue open;
|
|
|
|
if (ParseVariant(aErrorCode, open, VARIANT_HOS, nsnull)) {
|
|
|
|
if (eCSSUnit_String == open.GetUnit()) {
|
|
|
|
nsCSSQuotes* quotesHead = new nsCSSQuotes();
|
|
|
|
nsCSSQuotes* quotes = quotesHead;
|
|
|
|
if (nsnull == quotes) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
quotes->mOpen = open;
|
|
|
|
while (nsnull != quotes) {
|
|
|
|
// get mandatory close
|
|
|
|
if (ParseVariant(aErrorCode, quotes->mClose, VARIANT_STRING, nsnull)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[eCSSProperty_quotes]);
|
1999-07-18 04:31:37 +04:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(eCSSProperty_quotes, quotesHead);
|
1999-02-10 11:37:52 +03:00
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
|
|
|
// look for another open
|
|
|
|
if (ParseVariant(aErrorCode, open, VARIANT_STRING, nsnull)) {
|
|
|
|
quotes->mNext = new nsCSSQuotes();
|
|
|
|
quotes = quotes->mNext;
|
|
|
|
if (nsnull != quotes) {
|
|
|
|
quotes->mOpen = open;
|
|
|
|
continue;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
break;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
delete quotesHead;
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_quotes_open, open, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
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
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
PRBool CSSParserImpl::ParseSize(PRInt32& aErrorCode, nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue width;
|
|
|
|
if (ParseVariant(aErrorCode, width, VARIANT_AHKL, nsCSSProps::kPageSizeKTable)) {
|
|
|
|
if (width.IsLengthUnit()) {
|
|
|
|
nsCSSValue height;
|
|
|
|
if (ParseVariant(aErrorCode, height, VARIANT_LENGTH, nsnull)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_size_width, width, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_size_height, height, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_size_width, width, aChangeHint);
|
|
|
|
AppendValue(aDeclaration, eCSSProperty_size_height, width, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
PRBool CSSParserImpl::ParseTextDecoration(PRInt32& aErrorCode, nsCSSValue& aValue)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseVariant(aErrorCode, aValue, VARIANT_HOK, nsCSSProps::kTextDecorationKTable)) {
|
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) { // look for more keywords
|
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
|
|
|
nsCSSValue keyword;
|
|
|
|
PRInt32 index;
|
1998-10-27 02:22:40 +03:00
|
|
|
for (index = 0; index < 3; index++) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseEnum(aErrorCode, keyword, nsCSSProps::kTextDecorationKTable)) {
|
|
|
|
intValue |= keyword.GetIntValue();
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
aValue.SetIntValue(intValue, eCSSUnit_Enumerated);
|
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,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsChangeHint& aChangeHint)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_HC | VARIANT_LENGTH | VARIANT_NONE, nsnull)) {
|
|
|
|
nsCSSUnit unit = value.GetUnit();
|
|
|
|
if ((eCSSUnit_Color == unit) || (eCSSUnit_String == unit) || value.IsLengthUnit()) {
|
|
|
|
nsCSSShadow* shadowHead = new nsCSSShadow();
|
|
|
|
nsCSSShadow* shadow = shadowHead;
|
|
|
|
if (nsnull == shadow) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
while (nsnull != shadow) {
|
|
|
|
PRBool haveColor = PR_FALSE;
|
|
|
|
if (value.IsLengthUnit()) {
|
|
|
|
shadow->mXOffset = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
haveColor = PR_TRUE;
|
|
|
|
shadow->mColor = value;
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull)) {
|
|
|
|
shadow->mXOffset = value;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull)) {
|
|
|
|
shadow->mYOffset = value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_LENGTH, nsnull)) {
|
|
|
|
shadow->mRadius = value;
|
|
|
|
} // optional
|
|
|
|
if (PR_FALSE == haveColor) {
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_COLOR, nsnull)) {
|
|
|
|
shadow->mColor = value;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
|
|
|
shadow->mNext = new nsCSSShadow();
|
|
|
|
shadow = shadow->mNext;
|
|
|
|
if (nsnull == shadow) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
if (PR_FALSE == ParseVariant(aErrorCode, value, VARIANT_COLOR | VARIANT_LENGTH, nsnull)) {
|
1998-10-27 02:22:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
else {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2002-08-24 18:41:28 +04:00
|
|
|
NS_UpdateHint(aChangeHint, nsCSSProps::kHintTable[eCSSProperty_text_shadow]);
|
1999-07-18 04:31:37 +04:00
|
|
|
aErrorCode = aDeclaration->AppendStructValue(eCSSProperty_text_shadow, shadowHead);
|
1999-02-10 11:37:52 +03:00
|
|
|
return NS_SUCCEEDED(aErrorCode);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
delete shadowHead;
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 11:37:52 +03:00
|
|
|
// value is inherit or none
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
1999-08-08 05:17:29 +04:00
|
|
|
AppendValue(aDeclaration, eCSSProperty_text_shadow_x, value, aChangeHint);
|
1999-02-10 11:37:52 +03:00
|
|
|
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
|
|
|
}
|