2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
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.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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>
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2004-04-18 17:54:27 +04:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>
|
2005-03-27 15:36:08 +04:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2005-09-20 16:04:45 +04:00
|
|
|
* Christian Biesinger <cbiesinger@web.de>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of 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"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** 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"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsCSSRules.h"
|
1999-06-10 09:25:23 +04:00
|
|
|
#include "nsICSSNameSpaceRule.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIUnicharInputStream.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"
|
2003-03-18 08:21:30 +03:00
|
|
|
#include "nsCOMArray.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsColor.h"
|
1998-07-18 03:00:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsCSSPseudoClasses.h"
|
2003-07-04 05:33:10 +04:00
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
1998-12-11 05:50:43 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2005-02-19 03:10:38 +03:00
|
|
|
#include "nsXMLNameSpaceMap.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsThemeConstants.h"
|
2002-11-25 14:21:22 +03:00
|
|
|
#include "nsContentErrors.h"
|
2003-03-18 09:45:57 +03:00
|
|
|
#include "nsUnitConversion.h"
|
2003-06-08 02:14:42 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2005-03-30 04:36:57 +04:00
|
|
|
#include "nsIMediaList.h"
|
2005-04-18 06:51:40 +04:00
|
|
|
#include "nsILookAndFeel.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-15 04:29:58 +04:00
|
|
|
#include "prprf.h"
|
2003-03-18 09:48:04 +03:00
|
|
|
#include "math.h"
|
2002-10-15 04:29:58 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
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);
|
|
|
|
|
2004-08-10 04:02:47 +04:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
NS_IMETHOD SetSVGMode(PRBool aSVGMode);
|
|
|
|
#endif
|
|
|
|
|
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,
|
2004-09-10 10:45:59 +04:00
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
2004-09-09 21:32:35 +04:00
|
|
|
PRUint32 aLineNumber,
|
1998-11-26 04:34:53 +03:00
|
|
|
nsICSSStyleSheet*& aResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-10-30 04:40:33 +03:00
|
|
|
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aDocURL,
|
2003-10-30 04:40:33 +03:00
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsICSSStyleRule** aResult);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aSheetURL,
|
2002-03-24 01:56:05 +03:00
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool aParseOnlyOneDecl,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool aClearOldDecl);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_IMETHOD ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCOMArray<nsICSSRule>& aResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
NS_IMETHOD ParseProperty(const nsCSSProperty aPropID,
|
2002-03-24 01:56:05 +03:00
|
|
|
const nsAString& aPropValue,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aSheetURL,
|
2001-09-28 05:38:36 +04:00
|
|
|
nsIURI* aBaseURL,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged);
|
2001-09-28 05:38:36 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_IMETHOD ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode);
|
|
|
|
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_IMETHOD ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
PRBool aHandleAlphaColors,
|
|
|
|
nscolor* aColor);
|
|
|
|
|
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:
|
2005-09-20 16:04:45 +04:00
|
|
|
class nsAutoParseCompoundProperty;
|
|
|
|
friend class nsAutoParseCompoundProperty;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This helper class automatically calls SetParsingCompoundProperty in its
|
|
|
|
* constructor and takes care of resetting it to false in its destructor.
|
|
|
|
*/
|
|
|
|
class nsAutoParseCompoundProperty {
|
|
|
|
public:
|
|
|
|
nsAutoParseCompoundProperty(CSSParserImpl* aParser) : mParser(aParser)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParser, "Null parser?");
|
|
|
|
aParser->SetParsingCompoundProperty(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsAutoParseCompoundProperty()
|
|
|
|
{
|
|
|
|
mParser->SetParsingCompoundProperty(PR_FALSE);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
CSSParserImpl* mParser;
|
|
|
|
};
|
|
|
|
|
2004-09-10 10:45:59 +04:00
|
|
|
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI);
|
2005-03-30 04:36:57 +04:00
|
|
|
// the caller must hold on to aBuffer until parsing is done
|
|
|
|
nsresult InitScanner(const nsAString& aBuffer, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI);
|
1999-09-22 05:19:29 +04:00
|
|
|
nsresult ReleaseScanner(void);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult DoParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList);
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool GetToken(nsresult& aErrorCode, PRBool aSkipWS);
|
|
|
|
PRBool GetURLToken(nsresult& aErrorCode, PRBool aSkipWS);
|
1998-04-14 00:24:54 +04:00
|
|
|
void UngetToken();
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ExpectSymbol(nsresult& aErrorCode, PRUnichar aSymbol, PRBool aSkipWS);
|
|
|
|
PRBool ExpectEndProperty(nsresult& aErrorCode, PRBool aSkipWS);
|
|
|
|
nsString* NextIdent(nsresult& aErrorCode);
|
|
|
|
void SkipUntil(nsresult& aErrorCode, PRUnichar aStopSymbol);
|
|
|
|
void SkipRuleSet(nsresult& aErrorCode);
|
|
|
|
PRBool SkipAtRule(nsresult& aErrorCode);
|
|
|
|
PRBool SkipDeclaration(nsresult& aErrorCode, PRBool aCheckForBraces);
|
2005-04-02 03:07:00 +04:00
|
|
|
PRBool GetNonCloseParenToken(nsresult& aErrorCode, PRBool aSkipWS);
|
1998-10-27 02:22:40 +03:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
PRBool PushGroup(nsICSSGroupRule* aRule);
|
|
|
|
void PopGroup(void);
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseRuleSet(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseAtRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseCharsetRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseImportRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
2004-08-05 22:26:14 +04:00
|
|
|
PRBool GatherURL(nsresult& aErrorCode, nsString& aURL);
|
2005-03-30 04:36:57 +04:00
|
|
|
PRBool GatherMedia(nsresult& aErrorCode, nsMediaList* aMedia,
|
|
|
|
PRUnichar aStopSymbol);
|
2004-01-10 05:27:41 +03:00
|
|
|
PRBool ProcessImport(nsresult& aErrorCode,
|
|
|
|
const nsString& aURLSpec,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia,
|
2004-01-10 05:27:41 +03:00
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
2004-08-05 22:26:14 +04:00
|
|
|
PRBool ParseGroupRule(nsresult& aErrorCode, nsICSSGroupRule* aRule, RuleAppendFunc aAppendFunc, void* aProcessData);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseMediaRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
2004-08-05 22:26:14 +04:00
|
|
|
PRBool ParseMozDocumentRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseNameSpaceRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ProcessNameSpace(nsresult& aErrorCode, const nsString& aPrefix,
|
2001-09-06 17:14:35 +04:00
|
|
|
const nsString& aURLSpec, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseFontFaceRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParsePageRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aProcessData);
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
enum nsSelectorParsingStatus {
|
|
|
|
// we have parsed a selector and we saw a token that cannot be part of a selector:
|
|
|
|
eSelectorParsingStatus_Done,
|
|
|
|
// we should continue parsing the selector:
|
|
|
|
eSelectorParsingStatus_Continue,
|
|
|
|
// same as "Done" but we did not find a selector:
|
|
|
|
eSelectorParsingStatus_Empty,
|
|
|
|
// we saw an unexpected token or token value,
|
|
|
|
// or we saw end-of-file with an unfinished selector:
|
|
|
|
eSelectorParsingStatus_Error
|
|
|
|
};
|
|
|
|
nsSelectorParsingStatus ParseIDSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseClassSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParsePseudoSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode,
|
|
|
|
PRBool aIsNegated);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseAttributeSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode,
|
|
|
|
PRBool aIsNegated);
|
|
|
|
|
2005-10-16 19:57:13 +04:00
|
|
|
nsSelectorParsingStatus ParsePseudoClassWithIdentArg(nsCSSSelector& aSelector,
|
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsresult& aErrorCode);
|
2004-11-27 00:05:45 +03:00
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseNegatedSimpleSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseSelector(nsresult& aErrorCode,
|
|
|
|
nsCSSSelector& aSelectorResult);
|
2001-03-09 02:27:39 +03:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseSelectorList(nsresult& aErrorCode, nsCSSSelectorList*& aListHead);
|
|
|
|
PRBool ParseSelectorGroup(nsresult& aErrorCode, nsCSSSelectorList*& aListHead);
|
|
|
|
nsCSSDeclaration* ParseDeclarationBlock(nsresult& aErrorCode,
|
1998-05-28 22:39:42 +04:00
|
|
|
PRBool aCheckForBraces);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseDeclaration(nsresult& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1998-09-30 03:50:09 +04:00
|
|
|
PRBool aCheckForBraces,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged);
|
2003-06-08 02:14:42 +04:00
|
|
|
// After a parse error parsing |aPropID|, clear the data in
|
|
|
|
// |mTempData|.
|
|
|
|
void ClearTempData(nsCSSProperty aPropID);
|
|
|
|
// After a successful parse of |aPropID|, transfer data from
|
2003-07-01 01:39:22 +04:00
|
|
|
// |mTempData| to |mData|. Set |*aChanged| to true if something
|
2005-04-29 00:19:24 +04:00
|
|
|
// changed, but leave it unmodified otherwise. If aMustCallValueAppended
|
|
|
|
// is false, will not call ValueAppended on aDeclaration if the property
|
|
|
|
// is already set in it.
|
2003-06-08 02:14:42 +04:00
|
|
|
void TransferTempData(nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID, PRBool aIsImportant,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged);
|
2003-06-08 02:14:42 +04:00
|
|
|
void DoTransferTempData(nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID, PRBool aIsImportant,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseProperty(nsresult& aErrorCode, nsCSSProperty aPropID);
|
|
|
|
PRBool ParseSingleValueProperty(nsresult& aErrorCode, nsCSSValue& aValue,
|
1999-07-18 04:31:37 +04:00
|
|
|
nsCSSProperty aPropID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseTreePseudoElement(nsresult& aErrorCode, nsCSSSelector& aSelector);
|
2001-02-16 00:25:31 +03:00
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Property specific parsing routines
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseAzimuth(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseBackground(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBackgroundPosition(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBorderColor(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBorderColors(nsresult& aErrorCode,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSValueList** aResult,
|
2001-12-05 11:35:05 +03:00
|
|
|
nsCSSProperty aProperty);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseBorderSpacing(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBorderSide(nsresult& aErrorCode,
|
2003-07-31 03:45:34 +04:00
|
|
|
const nsCSSProperty aPropIDs[],
|
|
|
|
PRBool aSetAllSides);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseBorderStyle(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBorderWidth(nsresult& aErrorCode);
|
|
|
|
PRBool ParseBorderRadius(nsresult& aErrorCode);
|
|
|
|
PRBool ParseOutlineRadius(nsresult& aErrorCode);
|
2003-06-08 02:14:42 +04:00
|
|
|
// for 'clip' and '-moz-image-region'
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseRect(nsCSSRect& aRect, nsresult& aErrorCode,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool DoParseRect(nsCSSRect& aRect, nsresult& aErrorCode);
|
|
|
|
PRBool ParseContent(nsresult& aErrorCode);
|
|
|
|
PRBool ParseCounterData(nsresult& aErrorCode,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCounterData** aResult,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseCue(nsresult& aErrorCode);
|
|
|
|
PRBool ParseCursor(nsresult& aErrorCode);
|
|
|
|
PRBool ParseFont(nsresult& aErrorCode);
|
|
|
|
PRBool ParseFontWeight(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseFamily(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseListStyle(nsresult& aErrorCode);
|
|
|
|
PRBool ParseMargin(nsresult& aErrorCode);
|
|
|
|
PRBool ParseMarks(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseOutline(nsresult& aErrorCode);
|
2004-09-05 04:04:04 +04:00
|
|
|
PRBool ParseOverflow(nsresult& aErrorCode);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParsePadding(nsresult& aErrorCode);
|
|
|
|
PRBool ParsePause(nsresult& aErrorCode);
|
|
|
|
PRBool ParseQuotes(nsresult& aErrorCode);
|
|
|
|
PRBool ParseSize(nsresult& aErrorCode);
|
|
|
|
PRBool ParseTextDecoration(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseTextShadow(nsresult& aErrorCode);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-11-09 21:19:28 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
PRBool ParseDasharray(nsresult& aErrorCode);
|
2004-12-09 06:16:15 +03:00
|
|
|
PRBool ParseMarker(nsresult& aErrorCode);
|
2004-11-09 21:19:28 +03:00
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Reused utility parsing routines
|
2003-07-01 01:39:22 +04:00
|
|
|
void AppendValue(nsCSSProperty aPropID, const nsCSSValue& aValue);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseBoxProperties(nsresult& aErrorCode, nsCSSRect& aResult,
|
2003-07-01 01:39:22 +04:00
|
|
|
const nsCSSProperty aPropIDs[]);
|
2004-02-04 09:10:56 +03:00
|
|
|
PRBool ParseDirectionalBoxProperty(nsresult& aErrorCode,
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
PRInt32 aSourceType);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRInt32 ParseChoice(nsresult& aErrorCode, nsCSSValue aValues[],
|
1999-07-18 04:31:37 +04:00
|
|
|
const nsCSSProperty aPropIDs[], PRInt32 aNumIDs);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseColor(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseColorComponent(nsresult& aErrorCode, PRUint8& aComponent,
|
2002-09-14 09:28:26 +04:00
|
|
|
PRInt32& aType, char aStop);
|
2003-03-18 08:43:12 +03:00
|
|
|
// ParseHSLColor parses everything starting with the opening '(' up through
|
|
|
|
// and including the aStop char.
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseHSLColor(nsresult& aErrorCode, nscolor& aColor, char aStop);
|
2003-03-18 08:43:12 +03:00
|
|
|
// ParseColorOpacity will enforce that the color ends with a ')' after the opacity
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseColorOpacity(nsresult& aErrorCode, PRUint8& aOpacity);
|
|
|
|
PRBool ParseEnum(nsresult& aErrorCode, nsCSSValue& aValue, const PRInt32 aKeywordTable[]);
|
|
|
|
PRBool ParseVariant(nsresult& aErrorCode, nsCSSValue& aValue,
|
1998-10-27 02:22:40 +03:00
|
|
|
PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 aKeywordTable[]);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParsePositiveVariant(nsresult& aErrorCode, nsCSSValue& aValue,
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[]);
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool ParseCounter(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseAttr(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool ParseURL(nsresult& aErrorCode, nsCSSValue& aValue);
|
|
|
|
PRBool TranslateDimension(nsresult& 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
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
void SetParsingCompoundProperty(PRBool aBool) {
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_ASSERTION(aBool == PR_TRUE || aBool == PR_FALSE, "bad PRBool value");
|
2003-03-18 08:21:30 +03:00
|
|
|
mParsingCompoundProperty = aBool;
|
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
PRBool IsParsingCompoundProperty(void) const {
|
2003-03-18 08:21:30 +03:00
|
|
|
return mParsingCompoundProperty;
|
|
|
|
}
|
|
|
|
|
2005-09-20 16:04:45 +04:00
|
|
|
// Current token. The value is valid after calling GetToken and invalidated
|
|
|
|
// by UngetToken.
|
1998-04-14 00:24:54 +04:00
|
|
|
nsCSSToken mToken;
|
|
|
|
|
2004-10-14 07:30:55 +04:00
|
|
|
// Our scanner.
|
|
|
|
nsCSSScanner mScanner;
|
2003-03-18 08:21:30 +03:00
|
|
|
|
|
|
|
// The URI to be used as a base for relative URIs.
|
2004-09-10 10:45:59 +04:00
|
|
|
nsCOMPtr<nsIURI> mBaseURL;
|
2003-03-18 08:21:30 +03:00
|
|
|
|
2005-07-20 00:44:49 +04:00
|
|
|
// The URI to be used as an HTTP "Referer" and for error reporting.
|
|
|
|
nsCOMPtr<nsIURI> mSheetURL;
|
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
// The sheet we're parsing into
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> mSheet;
|
|
|
|
|
|
|
|
// Used for @import rules
|
1999-05-19 03:12:17 +04:00
|
|
|
nsICSSLoader* mChildLoader; // not ref counted, it owns us
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
// Sheet section we're in. This is used to enforce correct ordering of the
|
|
|
|
// various rule types (eg the fact that a @charset rule must come before
|
|
|
|
// anything else).
|
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
|
|
|
|
2005-02-19 03:10:38 +03:00
|
|
|
nsXMLNameSpaceMap *mNameSpaceMap; // weak, mSheet owns it
|
1999-06-10 09:25:23 +04:00
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
// After an UngetToken is done this flag is true. The next call to
|
|
|
|
// GetToken clears the flag.
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mHavePushBack : 1;
|
1999-06-10 09:25:23 +04:00
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
// True if we are in quirks mode; false in standards or almost standards mode
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mNavQuirkMode : 1;
|
2000-04-23 06:01:40 +04:00
|
|
|
|
2004-08-10 04:02:47 +04:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
// True if we are in SVG mode; false in "normal" CSS
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mSVGMode : 1;
|
2004-08-10 04:02:47 +04:00
|
|
|
#endif
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
// True for parsing media lists for HTML attributes, where we have to
|
|
|
|
// ignore CSS comments.
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mHTMLMediaMode : 1;
|
|
|
|
|
|
|
|
// True if ParseColor should handle rgba() and hsla(), which most of
|
|
|
|
// Gecko currently doesn't understand.
|
|
|
|
PRPackedBool mHandleAlphaColors : 1;
|
2005-03-30 04:36:57 +04:00
|
|
|
|
2003-03-18 08:21:30 +03:00
|
|
|
// True if tagnames and attributes are case-sensitive
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mCaseSensitive : 1;
|
2003-03-18 08:21:30 +03:00
|
|
|
|
|
|
|
// This flag is set when parsing a non-box shorthand; it's used to not apply
|
|
|
|
// some quirks during shorthand parsing
|
2005-04-18 06:51:40 +04:00
|
|
|
PRPackedBool mParsingCompoundProperty : 1;
|
2003-03-18 08:21:30 +03:00
|
|
|
|
|
|
|
// Stack of rule groups; used for @media and such.
|
|
|
|
nsCOMArray<nsICSSGroupRule> mGroupStack;
|
2003-06-08 02:14:42 +04:00
|
|
|
|
|
|
|
// During the parsing of a property (which may be a shorthand), the data
|
|
|
|
// are stored in |mTempData|. (It is needed to ensure that parser
|
|
|
|
// errors cause the data to be ignored, and to ensure that a
|
|
|
|
// non-'!important' declaration does not override an '!important'
|
|
|
|
// one.)
|
|
|
|
nsCSSExpandedDataBlock mTempData;
|
|
|
|
|
|
|
|
// All data from successfully parsed properties are placed into |mData|.
|
|
|
|
nsCSSExpandedDataBlock mData;
|
2004-10-14 07:30:55 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRPackedBool mScannerInited;
|
|
|
|
#endif
|
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)
|
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_STATIC_CAST(nsCOMArray<nsICSSRule>*, aArray)->AppendObject(aRule);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void) AppendRuleToSheet(nsICSSRule* aRule, void* aParser)
|
|
|
|
{
|
|
|
|
CSSParserImpl* parser = (CSSParserImpl*) aParser;
|
|
|
|
parser->AppendRule(aRule);
|
|
|
|
}
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
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
|
|
|
|
|
2004-09-20 23:38:11 +04:00
|
|
|
#define REPORT_UNEXPECTED(msg_) \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ReportUnexpected(#msg_)
|
2000-09-08 06:05:09 +04:00
|
|
|
|
2004-09-20 23:38:11 +04:00
|
|
|
#define REPORT_UNEXPECTED_P(msg_, params_) \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ReportUnexpectedParams(#msg_, params_, NS_ARRAY_LENGTH(params_))
|
2004-09-20 23:38:11 +04:00
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_) \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ReportUnexpectedEOF(#lf_)
|
2004-09-20 23:38:11 +04:00
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN(msg_) \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ReportUnexpectedToken(mToken, #msg_)
|
2004-09-20 23:38:11 +04:00
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN_P(msg_, params_) \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ReportUnexpectedTokenParams(mToken, #msg_, \
|
|
|
|
params_, NS_ARRAY_LENGTH(params_))
|
2000-09-08 06:05:09 +04:00
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
|
2001-03-06 04:57:30 +03:00
|
|
|
#define OUTPUT_ERROR() \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.OutputError()
|
2001-03-06 04:57:30 +03:00
|
|
|
|
|
|
|
#define CLEAR_ERROR() \
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.ClearError()
|
2004-09-20 23:38:11 +04:00
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
#else
|
|
|
|
|
2004-09-20 23:38:11 +04:00
|
|
|
#define REPORT_UNEXPECTED(msg_)
|
|
|
|
#define REPORT_UNEXPECTED_P(msg_, params_)
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_)
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN(msg_)
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN_P(msg_, params_)
|
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(),
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner(),
|
1999-06-10 09:25:23 +04:00
|
|
|
mChildLoader(nsnull),
|
|
|
|
mSection(eCSSSection_Charset),
|
2005-02-18 22:18:37 +03:00
|
|
|
mNameSpaceMap(nsnull),
|
2003-03-18 08:21:30 +03:00
|
|
|
mHavePushBack(PR_FALSE),
|
1999-07-07 05:29:49 +04:00
|
|
|
mNavQuirkMode(PR_FALSE),
|
2004-08-10 04:02:47 +04:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
mSVGMode(PR_FALSE),
|
|
|
|
#endif
|
2005-03-30 04:36:57 +04:00
|
|
|
mHTMLMediaMode(PR_FALSE),
|
2005-04-18 06:51:40 +04:00
|
|
|
mHandleAlphaColors(PR_FALSE),
|
1999-06-10 09:25:23 +04:00
|
|
|
mCaseSensitive(PR_FALSE),
|
2000-09-06 06:27:46 +04:00
|
|
|
mParsingCompoundProperty(PR_FALSE)
|
2004-10-14 07:30:55 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mScannerInited(PR_FALSE)
|
|
|
|
#endif
|
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()
|
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
mData.AssertInitialState();
|
|
|
|
mTempData.AssertInitialState();
|
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
|
2003-03-18 08:21:30 +03:00
|
|
|
mGroupStack.Clear();
|
1998-11-26 04:34:53 +03:00
|
|
|
mSheet = aSheet;
|
2005-02-18 22:18:37 +03:00
|
|
|
mNameSpaceMap = mSheet->GetNameSpaceMap();
|
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
|
|
|
{
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_ASSERTION(aCaseSensitive == PR_TRUE || aCaseSensitive == PR_FALSE, "bad PRBool value");
|
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)
|
|
|
|
{
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_ASSERTION(aQuirkMode == PR_TRUE || aQuirkMode == PR_FALSE, "bad PRBool value");
|
1999-07-07 05:29:49 +04:00
|
|
|
mNavQuirkMode = aQuirkMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-10 04:02:47 +04:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::SetSVGMode(PRBool aSVGMode)
|
|
|
|
{
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_ASSERTION(aSVGMode == PR_TRUE || aSVGMode == PR_FALSE, "bad PRBool value");
|
2004-08-10 04:02:47 +04:00
|
|
|
mSVGMode = aSVGMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
2004-09-10 10:45:59 +04:00
|
|
|
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI)
|
1999-09-22 05:19:29 +04:00
|
|
|
{
|
2004-10-14 07:30:55 +04:00
|
|
|
NS_ASSERTION(! mScannerInited, "already have scanner");
|
1999-09-22 05:19:29 +04:00
|
|
|
|
2005-11-11 01:26:06 +03:00
|
|
|
mScanner.Init(aInput, nsnull, 0, aSheetURI, aLineNumber);
|
2004-10-14 19:06:04 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_TRUE;
|
|
|
|
#endif
|
2004-09-10 10:45:59 +04:00
|
|
|
mBaseURL = aBaseURI;
|
2005-07-20 00:44:49 +04:00
|
|
|
mSheetURL = aSheetURI;
|
1999-09-22 05:19:29 +04:00
|
|
|
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult
|
|
|
|
CSSParserImpl::InitScanner(const nsAString& aBuffer, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI)
|
|
|
|
{
|
|
|
|
// Having it not own the string is OK since the caller will hold on to
|
|
|
|
// the stream until we're done parsing.
|
2005-11-11 01:26:06 +03:00
|
|
|
NS_ASSERTION(! mScannerInited, "already have scanner");
|
|
|
|
|
|
|
|
const nsAFlatString& flat = PromiseFlatString(aBuffer);
|
|
|
|
mScanner.Init(nsnull, flat.get(), flat.Length(), aSheetURI, aLineNumber);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
mBaseURL = aBaseURI;
|
|
|
|
mSheetURL = aSheetURI;
|
2005-03-30 04:36:57 +04:00
|
|
|
|
2005-11-11 01:26:06 +03:00
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2005-03-30 04:36:57 +04:00
|
|
|
}
|
|
|
|
|
1999-09-22 05:19:29 +04:00
|
|
|
nsresult
|
|
|
|
CSSParserImpl::ReleaseScanner(void)
|
|
|
|
{
|
2004-10-14 07:30:55 +04:00
|
|
|
mScanner.Close();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_FALSE;
|
|
|
|
#endif
|
2004-09-10 10:45:59 +04:00
|
|
|
mBaseURL = nsnull;
|
2005-07-20 00:44:49 +04:00
|
|
|
mSheetURL = nsnull;
|
1999-09-22 05:19:29 +04:00
|
|
|
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,
|
2004-09-10 10:45:59 +04:00
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
2004-09-09 21:32:35 +04:00
|
|
|
PRUint32 aLineNumber,
|
1998-11-26 04:34:53 +03:00
|
|
|
nsICSSStyleSheet*& aResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-09-10 13:31:10 +04:00
|
|
|
NS_ASSERTION(nsnull != aBaseURI, "need base URL");
|
|
|
|
NS_ASSERTION(nsnull != aSheetURI, "need sheet URL");
|
1999-01-15 05:06:13 +03:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
if (! mSheet) {
|
2004-09-10 10:45:59 +04:00
|
|
|
NS_NewCSSStyleSheet(getter_AddRefs(mSheet));
|
2005-02-18 22:18:37 +03:00
|
|
|
NS_ENSURE_TRUE(mSheet, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2004-09-10 10:45:59 +04:00
|
|
|
mSheet->SetURIs(aSheetURI, aBaseURI);
|
2005-02-18 22:18:37 +03:00
|
|
|
mNameSpaceMap = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-09-10 13:31:10 +04:00
|
|
|
mSheet->GetSheetURI(getter_AddRefs(uri));
|
2002-12-03 08:48:14 +03:00
|
|
|
PRBool equal;
|
2004-09-10 13:31:10 +04:00
|
|
|
aSheetURI->Equals(uri, &equal);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(equal, "Sheet URI does not match passed URI");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
nsresult errorCode = NS_OK;
|
1999-09-22 05:19:29 +04:00
|
|
|
|
2004-09-10 10:45:59 +04:00
|
|
|
nsresult result = InitScanner(aInput, aSheetURI, aLineNumber, aBaseURI);
|
1999-09-22 05:19:29 +04:00
|
|
|
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,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aDocURL,
|
2001-09-18 03:59:30 +04:00
|
|
|
nsIURI* aBaseURL,
|
2003-10-30 04:40:33 +03:00
|
|
|
nsICSSStyleRule** aResult)
|
1998-05-28 22:39:42 +04:00
|
|
|
{
|
1999-01-15 05:06:13 +03:00
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult rv =
|
|
|
|
InitScanner(aAttributeValue, aDocURL, 0, aBaseURL); // XXX line number
|
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;
|
2003-11-14 01:48:05 +03:00
|
|
|
nsresult errorCode = NS_OK;
|
1998-05-28 22:39:42 +04:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSDeclaration* declaration = ParseDeclarationBlock(errorCode, haveBraces);
|
|
|
|
if (declaration) {
|
1998-05-28 22:39:42 +04:00
|
|
|
// Create a style rule for the delcaration
|
|
|
|
nsICSSStyleRule* rule = nsnull;
|
2003-06-18 05:59:57 +04:00
|
|
|
rv = NS_NewCSSStyleRule(&rule, nsnull, declaration);
|
2003-06-15 03:50:54 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
declaration->RuleAbort();
|
2004-01-10 05:27:41 +03:00
|
|
|
ReleaseScanner();
|
2003-06-15 03:50:54 +04:00
|
|
|
return rv;
|
|
|
|
}
|
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,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aSheetURL,
|
2002-08-24 18:41:28 +04:00
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool aParseOnlyOneDecl,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged,
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool aClearOldDecl)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
1999-08-04 09:06:19 +04:00
|
|
|
// NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
2003-07-01 01:39:22 +04:00
|
|
|
*aChanged = PR_FALSE;
|
1999-01-15 05:06:13 +03:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult rv = InitScanner(aBuffer, aSheetURL, 0, aBaseURL);
|
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;
|
2003-11-14 01:48:05 +03:00
|
|
|
nsresult errorCode = NS_OK;
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
if (aClearOldDecl) {
|
|
|
|
mData.AssertInitialState();
|
|
|
|
aDeclaration->ClearData();
|
2003-07-01 01:39:22 +04:00
|
|
|
// We could check if it was already empty, but...
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
} else {
|
|
|
|
aDeclaration->ExpandTo(&mData);
|
|
|
|
}
|
|
|
|
|
2000-05-04 01:42:00 +04:00
|
|
|
do {
|
2005-04-29 00:19:24 +04:00
|
|
|
// If we cleared the old decl, then we want to be calling
|
|
|
|
// ValueAppended as we parse.
|
|
|
|
if (!ParseDeclaration(errorCode, aDeclaration, PR_FALSE,
|
|
|
|
aClearOldDecl, aChanged)) {
|
2003-11-14 01:48:05 +03:00
|
|
|
NS_ASSERTION(errorCode != nsresult(-1), "-1 is no longer used for EOF");
|
|
|
|
rv = errorCode;
|
2000-05-04 01:42:00 +04:00
|
|
|
|
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)) {
|
2003-11-14 01:48:05 +03:00
|
|
|
NS_ASSERTION(errorCode != nsresult(-1), "-1 is no longer used for EOF");
|
|
|
|
rv = errorCode;
|
2002-03-12 18:28:27 +03:00
|
|
|
break;
|
|
|
|
}
|
2000-05-04 01:42:00 +04:00
|
|
|
}
|
|
|
|
} while (!aParseOnlyOneDecl);
|
2003-06-08 02:14:42 +04:00
|
|
|
aDeclaration->CompressFrom(&mData);
|
2000-05-04 01:42:00 +04:00
|
|
|
|
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
|
2005-10-16 00:21:20 +04:00
|
|
|
CSSParserImpl::ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsCOMArray<nsICSSRule>& aResult)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult rv = InitScanner(aRule, aSheetURL, 0, 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
|
|
|
mSection = eCSSSection_Charset; // callers are responsible for rejecting invalid rules.
|
2003-11-14 01:48:05 +03:00
|
|
|
nsresult errorCode = NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
// Get first non-whitespace token
|
|
|
|
if (!GetToken(errorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED(PEParseRuleWSOnly);
|
2001-09-05 04:00:18 +04:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
} else if (eCSSToken_AtKeyword == tk->mType) {
|
2005-10-16 00:21:20 +04:00
|
|
|
ParseAtRule(errorCode, AppendRuleToArray, &aResult);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
2005-10-16 00:21:20 +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;
|
|
|
|
}
|
|
|
|
|
2002-11-06 05:07:17 +03:00
|
|
|
//XXXbz this function does not deal well with something like "foo
|
|
|
|
//!important" as the aPropValue. It will parse the "foo" and set it
|
|
|
|
//in the decl, then ignore the !important. It should either fail to
|
|
|
|
//parse this or do !important correctly....
|
2001-09-28 05:38:36 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-08 05:32:29 +04:00
|
|
|
CSSParserImpl::ParseProperty(const nsCSSProperty aPropID,
|
2002-03-24 01:56:05 +03:00
|
|
|
const nsAString& aPropValue,
|
2004-09-11 03:31:48 +04:00
|
|
|
nsIURI* aSheetURL,
|
2001-09-28 05:38:36 +04:00
|
|
|
nsIURI* aBaseURL,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged)
|
2001-09-28 05:38:36 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
|
|
|
|
NS_ASSERTION(nsnull != aDeclaration, "Need declaration to parse into!");
|
2003-07-01 01:39:22 +04:00
|
|
|
*aChanged = PR_FALSE;
|
2001-09-28 05:38:36 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult rv = InitScanner(aPropValue, aSheetURL, 0, aBaseURL);
|
2001-09-28 05:38:36 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSection = eCSSSection_General;
|
2003-11-14 01:48:05 +03:00
|
|
|
nsresult errorCode = NS_OK;
|
2001-09-28 05:38:36 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
if (eCSSProperty_UNKNOWN == aPropID) { // unknown property
|
2004-09-20 23:38:11 +04:00
|
|
|
NS_ConvertASCIItoUTF16 propName(nsCSSProps::GetStringValue(aPropID));
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownProperty, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-09-28 05:38:36 +04:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
mData.AssertInitialState();
|
|
|
|
mTempData.AssertInitialState();
|
|
|
|
aDeclaration->ExpandTo(&mData);
|
|
|
|
nsresult result = NS_OK;
|
2004-06-08 05:32:29 +04:00
|
|
|
if (ParseProperty(errorCode, aPropID)) {
|
2005-04-29 00:19:24 +04:00
|
|
|
TransferTempData(aDeclaration, aPropID, PR_FALSE, PR_FALSE, aChanged);
|
2003-06-08 02:14:42 +04:00
|
|
|
} else {
|
2004-09-20 23:38:11 +04:00
|
|
|
NS_ConvertASCIItoUTF16 propName(nsCSSProps::GetStringValue(aPropID));
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEPropertyParsingError, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-09-28 05:38:36 +04:00
|
|
|
OUTPUT_ERROR();
|
2004-06-08 05:32:29 +04:00
|
|
|
ClearTempData(aPropID);
|
2003-11-14 01:48:05 +03:00
|
|
|
NS_ASSERTION(errorCode != nsresult(-1), "-1 is no longer used for EOF");
|
|
|
|
result = errorCode;
|
2001-09-28 05:38:36 +04:00
|
|
|
}
|
|
|
|
CLEAR_ERROR();
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
aDeclaration->CompressFrom(&mData);
|
2001-09-28 05:38:36 +04:00
|
|
|
|
|
|
|
ReleaseScanner();
|
2003-06-08 02:14:42 +04:00
|
|
|
return result;
|
2001-09-28 05:38:36 +04:00
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode)
|
|
|
|
{
|
|
|
|
aMediaList->Clear();
|
2005-03-31 03:05:02 +04:00
|
|
|
nsresult rv = NS_OK;
|
2005-03-30 04:36:57 +04:00
|
|
|
|
|
|
|
if (aHTMLMode) {
|
|
|
|
mHTMLMediaMode = PR_TRUE;
|
|
|
|
|
|
|
|
// XXXldb We need to make the scanner not skip CSS comments! (Or
|
|
|
|
// should we?)
|
|
|
|
|
|
|
|
// Follow the parsing rules in
|
|
|
|
// http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-media-descriptors
|
|
|
|
|
|
|
|
for (PRUint32 sub = 0, sub_end; sub < aBuffer.Length(); sub = sub_end + 1) {
|
|
|
|
sub_end = aBuffer.FindChar(PRUnichar(','), sub);
|
2005-07-13 22:16:00 +04:00
|
|
|
if (sub_end == PRUint32(kNotFound))
|
2005-03-30 04:36:57 +04:00
|
|
|
sub_end = aBuffer.Length();
|
|
|
|
|
|
|
|
PRUint32 parse_start, parse_end;
|
|
|
|
for (parse_start = sub;
|
|
|
|
parse_start < sub_end && nsCRT::IsAsciiSpace(aBuffer[parse_start]);
|
|
|
|
++parse_start)
|
|
|
|
;
|
|
|
|
|
|
|
|
for (parse_end = parse_start;
|
|
|
|
parse_end < sub_end &&
|
|
|
|
(nsCRT::IsAsciiAlpha(aBuffer[parse_end]) ||
|
|
|
|
nsCRT::IsAsciiDigit(aBuffer[parse_end]) ||
|
|
|
|
aBuffer[parse_end] == PRUnichar('-'));
|
|
|
|
++parse_end)
|
|
|
|
;
|
|
|
|
|
|
|
|
DoParseMediaList(Substring(aBuffer, parse_start, parse_end - parse_start),
|
|
|
|
aURL, aLineNumber, aMediaList);
|
|
|
|
}
|
|
|
|
|
|
|
|
mHTMLMediaMode = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
rv = DoParseMediaList(aBuffer, aURL, aLineNumber, aMediaList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All parameters but the first are the same as for |ParseMediaList|,
|
|
|
|
// but for HTML we get the buffer in chunks according to the HTML spec's
|
|
|
|
// parsing rules instead of in one piece.
|
|
|
|
nsresult
|
|
|
|
CSSParserImpl::DoParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList)
|
|
|
|
{
|
|
|
|
// fake base URL since media lists don't have URLs in them
|
|
|
|
nsresult rv = InitScanner(aBuffer, aURL, aLineNumber, aURL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GatherMedia(rv, aMediaList, PRUnichar(0)) && !mHTMLMediaMode) {
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
}
|
|
|
|
CLEAR_ERROR();
|
|
|
|
ReleaseScanner();
|
2005-03-31 03:05:02 +04:00
|
|
|
return rv;
|
2005-03-30 04:36:57 +04:00
|
|
|
}
|
|
|
|
|
2005-04-18 06:51:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSParserImpl::ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
PRBool aHandleAlphaColors,
|
|
|
|
nscolor* aColor)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aHandleAlphaColors == PR_TRUE || aHandleAlphaColors == PR_FALSE, "bad PRBool value");
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = InitScanner(aBuffer, aURL, aLineNumber, aURL);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mHandleAlphaColors = aHandleAlphaColors;
|
|
|
|
|
|
|
|
nsCSSValue value;
|
2005-06-01 19:41:12 +04:00
|
|
|
PRBool colorParsed = ParseColor(rv, value);
|
|
|
|
|
|
|
|
CLEAR_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
|
|
|
|
mHandleAlphaColors = PR_FALSE;
|
|
|
|
|
|
|
|
if (!colorParsed) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2005-04-18 06:51:40 +04:00
|
|
|
|
|
|
|
if (value.GetUnit() == eCSSUnit_String) {
|
|
|
|
nsAutoString s;
|
|
|
|
nscolor rgba;
|
|
|
|
if (NS_ColorNameToRGB(value.GetStringValue(s), &rgba)) {
|
|
|
|
(*aColor) = rgba;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
} else if (value.GetUnit() == eCSSUnit_Color) {
|
|
|
|
(*aColor) = value.GetColorValue();
|
|
|
|
rv = NS_OK;
|
|
|
|
} else if (value.GetUnit() == eCSSUnit_Integer) {
|
|
|
|
PRInt32 intValue = value.GetIntValue();
|
|
|
|
if (intValue >= 0) {
|
|
|
|
nsCOMPtr<nsILookAndFeel> lfSvc = do_GetService("@mozilla.org/widget/lookandfeel;1");
|
|
|
|
if (lfSvc) {
|
|
|
|
nscolor rgba;
|
|
|
|
rv = lfSvc->GetColor((nsILookAndFeel::nsColorID) value.GetIntValue(), rgba);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
(*aColor) = rgba;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX - this is NS_COLOR_CURRENTCOLOR, NS_COLOR_MOZ_HYPERLINKTEXT, etc.
|
|
|
|
// which we don't handle as per the ParseColorString definition. Should
|
|
|
|
// remove this limitation at some point.
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::GetToken(nsresult& aErrorCode, PRBool aSkipWS)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (!mHavePushBack) {
|
2004-10-14 07:30:55 +04:00
|
|
|
if (!mScanner.Next(aErrorCode, mToken)) {
|
1998-10-27 02:22:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
if (aSkipWS && (eCSSToken_WhiteSpace == mToken.mType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::GetURLToken(nsresult& aErrorCode, PRBool aSkipWS)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
for (;;) {
|
2005-03-18 09:56:03 +03:00
|
|
|
// XXXldb This pushback code doesn't make sense.
|
1998-10-27 02:22:40 +03:00
|
|
|
if (! mHavePushBack) {
|
2004-10-14 07:30:55 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ExpectSymbol(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ExpectEndProperty(nsresult& aErrorCode, PRBool aSkipWS)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectEndProperty);
|
1998-10-27 02:22:40 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
nsString* CSSParserImpl::NextIdent(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::SkipAtRule(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PESkipAtRuleEOF);
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseAtRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc,
|
2001-09-06 17:14:35 +04:00
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
if ((mSection <= eCSSSection_Charset) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("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) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("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) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("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;
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("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;
|
|
|
|
}
|
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-document")) {
|
|
|
|
if (ParseMozDocumentRule(aErrorCode, aAppendFunc, aData)) {
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("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;
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("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;
|
|
|
|
}
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEUnknownAtRule);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
// Skip over unsupported at rule, don't advance section
|
|
|
|
return SkipAtRule(aErrorCode);
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseCharsetRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc,
|
2001-09-06 17:14:35 +04:00
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
2002-08-06 09:26:41 +04:00
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PECharsetRuleEOF);
|
2002-08-06 09:26:41 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_String != mToken.mType) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PECharsetRuleNotString);
|
2002-08-06 09:26:41 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
PRBool CSSParserImpl::GatherURL(nsresult& aErrorCode, nsString& aURL)
|
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_String == mToken.mType) {
|
|
|
|
aURL = mToken.mIdent;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Function == mToken.mType &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url") &&
|
|
|
|
ExpectSymbol(aErrorCode, '(', PR_FALSE) &&
|
|
|
|
GetURLToken(aErrorCode, PR_TRUE) &&
|
|
|
|
(eCSSToken_String == mToken.mType ||
|
|
|
|
eCSSToken_URL == mToken.mType)) {
|
|
|
|
aURL = mToken.mIdent;
|
|
|
|
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-10 05:27:41 +03:00
|
|
|
PRBool CSSParserImpl::GatherMedia(nsresult& aErrorCode,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia,
|
|
|
|
PRUnichar aStopSymbol)
|
1999-01-23 10:08:11 +03:00
|
|
|
{
|
1998-11-26 08:16:22 +03:00
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEGatherMediaEOF);
|
1998-11-26 08:16:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEGatherMediaNotIdent);
|
|
|
|
UngetToken();
|
|
|
|
break;
|
1998-11-26 08:16:22 +03:00
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
ToLowerCase(mToken.mIdent); // case insensitive from CSS - must be lower cased
|
|
|
|
nsCOMPtr<nsIAtom> medium = do_GetAtom(mToken.mIdent);
|
|
|
|
aMedia->AppendAtom(medium);
|
|
|
|
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
if (aStopSymbol == PRUnichar(0))
|
|
|
|
return PR_TRUE;
|
|
|
|
REPORT_UNEXPECTED_EOF(PEGatherMediaEOF);
|
|
|
|
break;
|
1998-11-26 08:16:22 +03:00
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
|
|
|
|
if (eCSSToken_Symbol == mToken.mType &&
|
|
|
|
mToken.mSymbol == aStopSymbol) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (eCSSToken_Symbol != mToken.mType ||
|
|
|
|
mToken.mSymbol != ',') {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEGatherMediaNotComma);
|
1999-02-03 05:59:51 +03:00
|
|
|
UngetToken();
|
1998-11-26 08:16:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
// Parse a CSS2 import rule: "@import STRING | URL [medium [, medium]]"
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseImportRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
nsCOMPtr<nsMediaList> media = new nsMediaList();
|
2004-01-10 05:27:41 +03:00
|
|
|
if (!media) {
|
2005-03-30 04:36:57 +04:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2004-01-10 05:27:41 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsAutoString url;
|
2004-08-05 22:26:14 +04:00
|
|
|
if (!GatherURL(aErrorCode, url)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEImportNotURI);
|
2004-08-05 22:26:14 +04:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
if (!ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
|
|
|
if (!GatherMedia(aErrorCode, media, ';') ||
|
|
|
|
!ExpectSymbol(aErrorCode, ';', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEImportUnexpected);
|
|
|
|
// don't advance section, simply ignore invalid @import
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(media->Count() != 0, "media list must be nonempty");
|
1999-02-03 05:59:51 +03:00
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
|
|
|
|
ProcessImport(aErrorCode, url, media, aAppendFunc, aData);
|
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2004-01-10 05:27:41 +03:00
|
|
|
PRBool CSSParserImpl::ProcessImport(nsresult& aErrorCode,
|
|
|
|
const nsString& aURLSpec,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia,
|
2004-01-10 05:27:41 +03:00
|
|
|
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;
|
2003-07-18 04:35:49 +04:00
|
|
|
// XXX should pass a charset!
|
2004-09-10 10:45:59 +04:00
|
|
|
aErrorCode = NS_NewURI(getter_AddRefs(url), aURLSpec, nsnull, mBaseURL);
|
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
|
|
|
|
2003-07-18 05:26:47 +04:00
|
|
|
mChildLoader->LoadChildSheet(mSheet, url, aMedia, 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
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// Parse the {} part of an @media or @-moz-document rule.
|
|
|
|
PRBool CSSParserImpl::ParseGroupRule(nsresult& aErrorCode,
|
|
|
|
nsICSSGroupRule* aRule,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
// XXXbz this could use better error reporting throughout the method
|
|
|
|
if (!ExpectSymbol(aErrorCode, '{', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// push rule on stack, loop over children
|
|
|
|
if (!PushGroup(aRule)) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSSection holdSection = mSection;
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// Get next non-whitespace token
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEGroupRuleEOF);
|
2004-08-05 22:26:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mToken.IsSymbol('}')) { // done!
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_AtKeyword == mToken.mType) {
|
|
|
|
SkipAtRule(aErrorCode); // group rules cannot contain @rules
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UngetToken();
|
|
|
|
ParseRuleSet(aErrorCode, AppendRuleToSheet, this);
|
|
|
|
}
|
|
|
|
PopGroup();
|
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, '}', PR_TRUE)) {
|
|
|
|
mSection = holdSection;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
(*aAppendFunc)(aRule, aData);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-09-06 06:27:46 +04:00
|
|
|
// Parse a CSS2 media rule: "@media medium [, medium] { ... }"
|
2004-08-05 22:26:14 +04:00
|
|
|
PRBool CSSParserImpl::ParseMediaRule(nsresult& aErrorCode,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
2001-09-06 17:14:35 +04:00
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
nsCOMPtr<nsMediaList> media = new nsMediaList();
|
|
|
|
if (!media) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GatherMedia(aErrorCode, media, '{')) {
|
|
|
|
NS_ASSERTION(media->Count() != 0, "media list must be nonempty");
|
|
|
|
// XXXbz this could use better error reporting throughout the method
|
|
|
|
nsRefPtr<nsCSSMediaRule> rule(new nsCSSMediaRule());
|
|
|
|
// Append first, so when we do SetMedia() the rule
|
|
|
|
// knows what its stylesheet is.
|
|
|
|
if (rule && ParseGroupRule(aErrorCode, rule, aAppendFunc, aData)) {
|
|
|
|
rule->SetMedia(media);
|
|
|
|
return PR_TRUE;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// Parse a @-moz-document rule. This is like an @media rule, but instead
|
|
|
|
// of a medium it has a nonempty list of items where each item is either
|
|
|
|
// url(), url-prefix(), or domain().
|
|
|
|
PRBool CSSParserImpl::ParseMozDocumentRule(nsresult& aErrorCode,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsCSSDocumentRule::URL *urls = nsnull;
|
|
|
|
nsCSSDocumentRule::URL **next = &urls;
|
|
|
|
do {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE) ||
|
|
|
|
eCSSToken_Function != mToken.mType ||
|
|
|
|
!(mToken.mIdent.LowerCaseEqualsLiteral("url") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url-prefix") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("domain"))) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMozDocRuleBadFunc);
|
2004-08-05 22:26:14 +04:00
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSDocumentRule::URL *cur = *next = new nsCSSDocumentRule::URL;
|
|
|
|
if (!cur) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
next = &cur->next;
|
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("url")) {
|
|
|
|
cur->func = nsCSSDocumentRule::eURL;
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("url-prefix")) {
|
|
|
|
cur->func = nsCSSDocumentRule::eURLPrefix;
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("domain")) {
|
|
|
|
cur->func = nsCSSDocumentRule::eDomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_FALSE) ||
|
|
|
|
!GetURLToken(aErrorCode, PR_TRUE) ||
|
|
|
|
(eCSSToken_String != mToken.mType &&
|
|
|
|
eCSSToken_URL != mToken.mType)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMozDocRuleNotURI);
|
2004-08-05 22:26:14 +04:00
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could try to make the URL (as long as it's not domain())
|
|
|
|
// canonical and absolute with NS_NewURI and GetSpec, but I'm
|
|
|
|
// inclined to think we shouldn't.
|
|
|
|
CopyUTF16toUTF8(mToken.mIdent, cur->url);
|
|
|
|
} while (ExpectSymbol(aErrorCode, ',', PR_TRUE));
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSDocumentRule> rule(new nsCSSDocumentRule());
|
|
|
|
if (!rule) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
rule->SetURLs(urls);
|
|
|
|
|
|
|
|
return ParseGroupRule(aErrorCode, rule, aAppendFunc, aData);
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
// Parse a CSS3 namespace rule: "@namespace [prefix] STRING | URL;"
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseNameSpaceRule(nsresult& aErrorCode,
|
2001-09-06 17:14:35 +04:00
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAtNSPrefixEOF);
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAtNSURIEOF);
|
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) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("url"))) {
|
1999-06-10 09:25:23 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAtNSUnexpected);
|
1999-06-10 09:25:23 +04:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ProcessNameSpace(nsresult& 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()) {
|
2002-12-11 17:24:49 +03:00
|
|
|
prefix = do_GetAtom(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);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
// If this was the first namespace rule encountered, it will trigger
|
|
|
|
// creation of a namespace map.
|
|
|
|
if (!mNameSpaceMap) {
|
|
|
|
mNameSpaceMap = mSheet->GetNameSpaceMap();
|
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseFontFaceRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
// XXX not yet implemented
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParsePageRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1999-06-10 09:25:23 +04:00
|
|
|
{
|
|
|
|
// XXX not yet implemented
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
void CSSParserImpl::SkipUntil(nsresult& 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, ')');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
PRBool CSSParserImpl::GetNonCloseParenToken(nsresult& aErrorCode, PRBool aSkipWS)
|
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, aSkipWS))
|
|
|
|
return PR_FALSE;
|
|
|
|
if (mToken.mType == eCSSToken_Symbol && mToken.mSymbol == ')') {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-05-28 22:39:42 +04:00
|
|
|
PRBool
|
2003-11-14 01:48:05 +03:00
|
|
|
CSSParserImpl::SkipDeclaration(nsresult& 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) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PESkipDeclBraceEOF);
|
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
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
void CSSParserImpl::SkipRuleSet(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PESkipRSBraceEOF);
|
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)
|
|
|
|
{
|
2003-03-18 08:21:30 +03:00
|
|
|
if (mGroupStack.AppendObject(aRule))
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_TRUE;
|
2003-03-18 08:21:30 +03:00
|
|
|
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSParserImpl::PopGroup(void)
|
|
|
|
{
|
2003-03-18 08:21:30 +03:00
|
|
|
PRInt32 count = mGroupStack.Count();
|
|
|
|
if (0 < count) {
|
|
|
|
mGroupStack.RemoveObjectAt(count - 1);
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSParserImpl::AppendRule(nsICSSRule* aRule)
|
|
|
|
{
|
2003-03-18 08:21:30 +03:00
|
|
|
PRInt32 count = mGroupStack.Count();
|
1999-06-10 09:25:23 +04:00
|
|
|
if (0 < count) {
|
2003-03-18 08:21:30 +03:00
|
|
|
mGroupStack[count - 1]->AppendStyleRule(aRule);
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSheet->AppendStyleRule(aRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseRuleSet(nsresult& aErrorCode, RuleAppendFunc aAppendFunc, void* aData)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// First get the list of selectors for the rule
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* slist = nsnull;
|
2004-10-14 07:30:55 +04:00
|
|
|
PRUint32 linenum = mScanner.GetLineNumber();
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! ParseSelectorList(aErrorCode, slist)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED(PEBadSelectorRSIgnored);
|
2001-03-06 04:57:30 +03:00
|
|
|
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
|
|
|
|
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCOMPtr<nsICSSStyleRule> rule;
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_NewCSSStyleRule(getter_AddRefs(rule), slist, declaration);
|
2003-06-15 03:50:54 +04:00
|
|
|
if (!rule) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
delete slist;
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2003-06-15 03:50:54 +04:00
|
|
|
rule->SetLineNumber(linenum);
|
|
|
|
(*aAppendFunc)(rule, aData);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorList(nsresult& aErrorCode,
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList*& aListHead)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* list = nsnull;
|
1998-12-11 05:50:43 +03:00
|
|
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PESelectorListExtraEOF);
|
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) {
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* newList = nsnull;
|
2001-03-06 04:57:30 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PESelectorListExtra);
|
2001-03-06 04:57:30 +03:00
|
|
|
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 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
|
|
|
}
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-03-29 05:46:01 +03:00
|
|
|
static PRBool IsTreePseudoElement(nsIAtom* aPseudo)
|
2001-02-16 00:25:31 +03:00
|
|
|
{
|
2003-03-25 21:55:59 +03:00
|
|
|
const char* str;
|
|
|
|
aPseudo->GetUTF8String(&str);
|
|
|
|
static const char moz_tree[] = ":-moz-tree-";
|
|
|
|
return nsCRT::strncmp(str, moz_tree, PRInt32(sizeof(moz_tree)-1)) == 0;
|
2001-02-16 00:25:31 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseSelectorGroup(nsresult& aErrorCode,
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList*& aList)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-15 03:50:54 +04:00
|
|
|
nsCSSSelectorList* list = nsnull;
|
1999-02-27 10:15:59 +03:00
|
|
|
PRUnichar combinator = PRUnichar(0);
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
PRBool havePseudoElement = PR_FALSE;
|
2003-11-04 06:16:10 +03:00
|
|
|
PRBool done = PR_FALSE;
|
|
|
|
while (!done) {
|
2002-11-16 15:07:13 +03:00
|
|
|
nsCSSSelector selector;
|
2004-11-27 00:05:45 +03:00
|
|
|
nsSelectorParsingStatus parsingStatus = ParseSelector(aErrorCode, selector);
|
|
|
|
if (parsingStatus == eSelectorParsingStatus_Empty) {
|
|
|
|
if (!list) {
|
|
|
|
REPORT_UNEXPECTED(PESelectorGroupNoSelector);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (parsingStatus == eSelectorParsingStatus_Error) {
|
|
|
|
if (list) {
|
|
|
|
delete list;
|
|
|
|
list = nsnull;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull == list) {
|
2003-06-15 03:50:54 +04:00
|
|
|
list = new nsCSSSelectorList();
|
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
|
|
|
}
|
2002-11-16 15:07:13 +03:00
|
|
|
list->AddSelector(selector);
|
|
|
|
nsCSSSelector* listSel = list->mSelectors;
|
1998-12-11 05:50:43 +03:00
|
|
|
|
|
|
|
// pull out pseudo elements here
|
2002-08-14 16:34:39 +04:00
|
|
|
nsAtomStringList* prevList = nsnull;
|
2002-11-16 15:07:13 +03:00
|
|
|
nsAtomStringList* pseudoClassList = listSel->mPseudoClassList;
|
1998-12-11 05:50:43 +03:00
|
|
|
while (nsnull != pseudoClassList) {
|
2002-11-17 18:37:56 +03:00
|
|
|
if (! nsCSSPseudoClasses::IsPseudoClass(pseudoClassList->mAtom)) {
|
1999-02-27 10:15:59 +03:00
|
|
|
havePseudoElement = PR_TRUE;
|
2002-11-16 15:07:13 +03:00
|
|
|
if (IsSinglePseudoClass(*listSel)) { // convert to pseudo element selector
|
1998-12-11 05:50:43 +03:00
|
|
|
nsIAtom* pseudoElement = pseudoClassList->mAtom; // steal ref count
|
|
|
|
pseudoClassList->mAtom = nsnull;
|
2002-11-16 15:07:13 +03:00
|
|
|
listSel->Reset();
|
|
|
|
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
|
1999-04-16 01:22:41 +04:00
|
|
|
}
|
2002-11-16 15:07:13 +03:00
|
|
|
listSel->mTag = pseudoElement;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
else { // append new pseudo element selector
|
2002-11-16 15:07:13 +03:00
|
|
|
selector.Reset();
|
|
|
|
selector.mTag = pseudoClassList->mAtom; // steal ref count
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-11-16 15:07:13 +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.
|
2002-11-16 15:07:13 +03:00
|
|
|
selector.mPseudoClassList = pseudoClassList->mNext;
|
2001-02-16 00:25:31 +03:00
|
|
|
pseudoClassList->mNext = nsnull;
|
|
|
|
}
|
2001-12-30 01:07:54 +03:00
|
|
|
#endif
|
2002-11-16 15:07:13 +03:00
|
|
|
list->AddSelector(selector);
|
1998-12-11 05:50:43 +03:00
|
|
|
pseudoClassList->mAtom = nsnull;
|
2002-11-16 15:07:13 +03:00
|
|
|
listSel->mOperator = PRUnichar('>');
|
1998-12-11 05:50:43 +03:00
|
|
|
if (nsnull == prevList) { // delete list entry
|
2002-11-16 15:07:13 +03:00
|
|
|
listSel->mPseudoClassList = pseudoClassList->mNext;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
prevList->mNext = pseudoClassList->mNext;
|
|
|
|
}
|
|
|
|
pseudoClassList->mNext = nsnull;
|
|
|
|
delete pseudoClassList;
|
2002-11-16 15:07:13 +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);
|
2003-11-04 06:16:10 +03:00
|
|
|
if (!GetToken(aErrorCode, PR_FALSE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume we are done unless we find a combinator here.
|
|
|
|
done = PR_TRUE;
|
|
|
|
if (eCSSToken_WhiteSpace == mToken.mType) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
break;
|
1999-02-27 10:15:59 +03:00
|
|
|
}
|
2003-11-04 06:16:10 +03:00
|
|
|
done = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_Symbol == mToken.mType &&
|
2004-01-14 23:12:03 +03:00
|
|
|
('+' == mToken.mSymbol ||
|
|
|
|
'>' == mToken.mSymbol ||
|
|
|
|
'~' == mToken.mSymbol)) {
|
2003-11-04 06:16:10 +03:00
|
|
|
done = PR_FALSE;
|
|
|
|
combinator = mToken.mSymbol;
|
|
|
|
list->mSelectors->SetOperator(combinator);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken(); // give it back to selector
|
1999-02-27 10:15:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (havePseudoElement) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2002-11-16 15:07:13 +03:00
|
|
|
weight += selector.CalcWeight();
|
1999-02-27 10:15:59 +03:00
|
|
|
}
|
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
|
1999-02-27 10:15:59 +03:00
|
|
|
if (PRUnichar(0) != combinator) { // no dangling combinators
|
|
|
|
if (list) {
|
|
|
|
delete list;
|
2004-11-27 00:05:45 +03:00
|
|
|
list = nsnull;
|
1999-02-27 10:15:59 +03:00
|
|
|
}
|
2002-11-19 18:12:02 +03:00
|
|
|
// This should report the problematic combinator
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED(PESelectorGroupExtraCombinator);
|
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-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parses an ID selector #name
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseIDSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2005-07-20 00:49:34 +04:00
|
|
|
NS_ASSERTION(!mToken.mIdent.IsEmpty(),
|
|
|
|
"Empty mIdent in eCSSToken_ID token?");
|
|
|
|
aDataMask |= SEL_MASK_ID;
|
|
|
|
aSelector.AddID(mToken.mIdent);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Continue;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parses a class selector .name
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseClassSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // get ident
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEClassSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) { // malformed selector
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEClassSelNotIdent);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Continue;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse a type element selector or a universal selector
|
|
|
|
// namespace|type or namespace|* or *|* or *
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& 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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was universal element selector
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) { // look for default namespace
|
|
|
|
PRInt32 defaultID = mNameSpaceMap->FindNameSpaceID(nsnull);
|
|
|
|
if (defaultID != kNameSpaceID_None) {
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
}
|
|
|
|
}
|
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!)
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Done;
|
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;
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(buffer); // always case insensitive, since stays within CSS
|
2002-12-11 17:24:49 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix = do_GetAtom(buffer);
|
2005-02-18 22:18:37 +03:00
|
|
|
nameSpaceID = mNameSpaceMap->FindNameSpaceID(prefix);
|
2002-12-11 17:24:49 +03:00
|
|
|
} // else, no declared namespaces
|
1999-06-10 09:25:23 +04:00
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
buffer.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownNamespacePrefix, params);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
aSelector.SetNameSpace(nameSpaceID);
|
|
|
|
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was element name
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) { // look for default namespace
|
|
|
|
PRInt32 defaultID = mNameSpaceMap->FindNameSpaceID(nsnull);
|
|
|
|
if (defaultID != kNameSpaceID_None) {
|
1999-06-10 09:25:23 +04:00
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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!)
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Done;
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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!)
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Done;
|
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
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) { // look for default namespace
|
|
|
|
PRInt32 defaultID = mNameSpaceMap->FindNameSpaceID(nsnull);
|
|
|
|
if (defaultID != kNameSpaceID_None) {
|
2001-06-09 05:32:19 +04:00
|
|
|
aSelector.SetNameSpace(defaultID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
if (aIsNegated) {
|
|
|
|
// restore last token read in case of a negated type selector
|
|
|
|
UngetToken();
|
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Continue;
|
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]
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseAttributeSelector(PRInt32& aDataMask,
|
2001-03-09 02:27:39 +03:00
|
|
|
nsCSSSelector& aSelector,
|
2004-11-27 00:05:45 +03:00
|
|
|
nsresult& aErrorCode)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
1998-12-11 05:50:43 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
else {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelNoBar);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
|
|
|
}
|
|
|
|
else {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(attr); // always case insensitive, since stays within CSS
|
2002-12-11 17:24:49 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix = do_GetAtom(attr);
|
2005-02-18 22:18:37 +03:00
|
|
|
nameSpaceID = mNameSpaceMap->FindNameSpaceID(prefix);
|
2002-12-11 17:24:49 +03:00
|
|
|
} // else, no declared namespaces
|
2001-03-09 02:27:39 +03:00
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
attr.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownNamespacePrefix, params);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature EOF
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameOrNamespaceExpected);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelInnerEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelUnexpected);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken(); // bad function
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
if (NS_ATTR_FUNC_SET != func) { // get value
|
1999-03-25 09:42:42 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature EOF
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelValueEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelCloseEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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",
|
2003-12-30 20:58:17 +03:00
|
|
|
"prompt", "standby", "summary",
|
|
|
|
"title", "class", "archive",
|
|
|
|
"cite", "datetime", "href",
|
|
|
|
"name", nsnull
|
2001-04-18 08:36:52 +04:00
|
|
|
};
|
|
|
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelNoClose);
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
else {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelBadValue);
|
1998-12-11 05:50:43 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelUnexpected);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken(); // bad dog, no biscut!
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Continue;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
1999-06-10 09:25:23 +04:00
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse pseudo-classes and pseudo-elements
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParsePseudoSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode,
|
|
|
|
PRBool aIsNegated)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// First, find out whether we are parsing a CSS3 pseudo-element
|
|
|
|
PRBool parsingPseudoElement = PR_FALSE;
|
|
|
|
if (mToken.IsSymbol(':')) {
|
|
|
|
parsingPseudoElement = PR_TRUE;
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoSelEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do some sanity-checking on the token
|
|
|
|
if (eCSSToken_Ident != mToken.mType && eCSSToken_Function != mToken.mType) {
|
|
|
|
// malformed selector
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelBadName);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2003-07-04 05:33:10 +04:00
|
|
|
// OK, now we know we have an mIdent. Atomize it. All the atoms, for
|
|
|
|
// pseudo-classes as well as pseudo-elements, start with a single ':'.
|
|
|
|
nsAutoString buffer;
|
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
|
|
|
|
2003-07-04 05:33:10 +04:00
|
|
|
// stash away some info about this pseudo so we only have to get it once.
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2004-01-13 02:56:18 +03:00
|
|
|
// If a tree pseudo-element is using the function syntax, it will
|
|
|
|
// get isTree set here and will pass the check below that only
|
|
|
|
// allows functions if they are in our list of things allowed to be
|
|
|
|
// functions. If it is _not_ using the function syntax, isTree will
|
|
|
|
// be false, and it will still pass that check. So the tree
|
|
|
|
// pseudo-elements are allowed to be either functions or not, as
|
|
|
|
// desired.
|
2003-07-04 05:33:10 +04:00
|
|
|
PRBool isTree = (eCSSToken_Function == mToken.mType) &&
|
|
|
|
IsTreePseudoElement(pseudo);
|
2001-03-09 02:27:39 +03:00
|
|
|
#endif
|
2003-07-04 05:33:10 +04:00
|
|
|
PRBool isPseudoElement = nsCSSPseudoElements::IsPseudoElement(pseudo);
|
|
|
|
PRBool isAnonBox = nsCSSAnonBoxes::IsAnonBox(pseudo);
|
2005-08-16 05:46:04 +04:00
|
|
|
PRBool isPseudoClass = nsCSSPseudoClasses::IsPseudoClass(pseudo);
|
|
|
|
|
|
|
|
if (!isPseudoClass && !isPseudoElement && !isAnonBox) {
|
|
|
|
// Not a pseudo-class, not a pseudo-element.... forget it
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelUnknown);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2003-07-04 05:33:10 +04:00
|
|
|
|
2004-01-13 02:56:18 +03:00
|
|
|
// If it's a function token, it better be on our "ok" list, and if the name
|
|
|
|
// is that of a function pseudo it better be a function token
|
|
|
|
if ((eCSSToken_Function == mToken.mType) !=
|
|
|
|
(
|
2003-07-04 05:33:10 +04:00
|
|
|
#ifdef MOZ_XUL
|
2004-01-13 02:56:18 +03:00
|
|
|
isTree ||
|
2003-07-04 05:33:10 +04:00
|
|
|
#endif
|
2004-01-13 02:56:18 +03:00
|
|
|
nsCSSPseudoClasses::notPseudo == pseudo ||
|
2005-10-16 19:57:13 +04:00
|
|
|
nsCSSPseudoClasses::lang == pseudo ||
|
|
|
|
nsCSSPseudoClasses::mozEmptyExceptChildrenWithLocalname == pseudo)) {
|
|
|
|
// There are no other function pseudos
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNonFunc);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it starts with "::", it better be a pseudo-element
|
|
|
|
if (parsingPseudoElement &&
|
|
|
|
!isPseudoElement &&
|
|
|
|
!isAnonBox) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNotPE);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2001-03-20 14:49:20 +03:00
|
|
|
|
2005-08-16 05:46:04 +04:00
|
|
|
if (!parsingPseudoElement && nsCSSPseudoClasses::notPseudo == pseudo) {
|
2001-03-20 14:49:20 +03:00
|
|
|
if (aIsNegated) { // :not() can't be itself negated
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelDoubleNot);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
// CSS 3 Negation pseudo-class takes one simple selector as argument
|
2004-11-27 00:05:45 +03:00
|
|
|
nsSelectorParsingStatus parsingStatus =
|
|
|
|
ParseNegatedSimpleSelector(aDataMask, aSelector, aErrorCode);
|
|
|
|
if (eSelectorParsingStatus_Continue != parsingStatus) {
|
|
|
|
return parsingStatus;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
}
|
2005-08-16 05:46:04 +04:00
|
|
|
else if (!parsingPseudoElement && isPseudoClass) {
|
2001-03-09 02:27:39 +03:00
|
|
|
aDataMask |= SEL_MASK_PCLASS;
|
2005-10-16 19:57:13 +04:00
|
|
|
if (nsCSSPseudoClasses::lang == pseudo ||
|
|
|
|
nsCSSPseudoClasses::mozEmptyExceptChildrenWithLocalname == pseudo) {
|
|
|
|
nsSelectorParsingStatus parsingStatus =
|
|
|
|
ParsePseudoClassWithIdentArg(aSelector, pseudo, aErrorCode);
|
2004-11-27 00:05:45 +03:00
|
|
|
if (eSelectorParsingStatus_Continue != parsingStatus) {
|
|
|
|
return parsingStatus;
|
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
// XXX are there more pseudo classes which accept arguments ?
|
|
|
|
else {
|
|
|
|
aSelector.AddPseudoClass(pseudo);
|
|
|
|
}
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2003-07-04 05:33:10 +04:00
|
|
|
else if (isPseudoElement || isAnonBox) {
|
|
|
|
// Pseudo-element. Make some more sanity checks.
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
if (aIsNegated) { // pseudo-elements can't be negated
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelPEInNot);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
2003-09-21 09:21:40 +04:00
|
|
|
// CSS2 pseudo-elements and -moz-tree-* pseudo-elements are allowed
|
|
|
|
// to have a single ':' on them. Others (CSS3+ pseudo-elements and
|
|
|
|
// various -moz-* pseudo-elements) must have |parsingPseudoElement|
|
|
|
|
// set.
|
2003-07-04 05:33:10 +04:00
|
|
|
if (!parsingPseudoElement &&
|
2003-09-23 03:52:16 +04:00
|
|
|
!nsCSSPseudoElements::IsCSS2PseudoElement(pseudo)
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
&& !IsTreePseudoElement(pseudo)
|
|
|
|
#endif
|
|
|
|
) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNewStyleOnly);
|
2003-07-04 05:33:10 +04:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2003-07-04 05:33:10 +04:00
|
|
|
if (isTree) {
|
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
|
2003-07-04 05:33:10 +04:00
|
|
|
// from the list later along with the pseudo-element.
|
|
|
|
if (!ParseTreePseudoElement(aErrorCode, aSelector)) {
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2003-07-04 05:33:10 +04:00
|
|
|
}
|
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();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Done;
|
1998-12-11 05:50:43 +03:00
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelTrailing);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelMultiplePE);
|
2001-03-09 02:27:39 +03:00
|
|
|
UngetToken();
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
2005-08-16 05:46:04 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
// We should never end up here. Indeed, if we ended up here, we know (from
|
|
|
|
// the current if/else cascade) that !isPseudoElement and !isAnonBox. But
|
|
|
|
// then due to our earlier check we know that isPseudoClass. Since we
|
|
|
|
// didn't fall into the isPseudoClass case in this cascade, we must have
|
|
|
|
// parsingPseudoElement. But we've already checked the
|
|
|
|
// parsingPseudoElement && !isPseudoClass && !isAnonBox case and bailed if
|
|
|
|
// it's happened.
|
|
|
|
NS_NOTREACHED("How did this happen?");
|
|
|
|
}
|
|
|
|
#endif
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Continue;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 14:49:20 +03:00
|
|
|
//
|
|
|
|
// Parse the argument of a negation pseudo-class :not()
|
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
nsresult& aErrorCode)
|
2001-03-20 14:49:20 +03:00
|
|
|
{
|
|
|
|
// Check if we have the first parenthesis
|
2004-11-27 00:05:45 +03:00
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationBadArg);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
2004-11-28 18:04:13 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature eof
|
2004-11-27 00:05:45 +03:00
|
|
|
REPORT_UNEXPECTED_EOF(PENegationEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2005-11-09 07:17:26 +03:00
|
|
|
|
|
|
|
// Create a new nsCSSSelector and add it to the end of
|
|
|
|
// aSelector.mNegations.
|
|
|
|
// Given the current parsing rules, every selector in mNegations
|
|
|
|
// contains only one simple selector (css3 definition) within it.
|
|
|
|
// This could easily change in future versions of CSS, and the only
|
|
|
|
// thing we need to change to support that is this parsing code.
|
|
|
|
nsCSSSelector *newSel = new nsCSSSelector();
|
|
|
|
if (!newSel) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return eSelectorParsingStatus_Error;
|
2004-11-27 00:05:45 +03:00
|
|
|
}
|
2005-11-09 07:17:26 +03:00
|
|
|
nsCSSSelector* negations = &aSelector;
|
|
|
|
while (negations->mNegations) {
|
|
|
|
negations = negations->mNegations;
|
|
|
|
}
|
|
|
|
negations->mNegations = newSel;
|
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
nsSelectorParsingStatus parsingStatus;
|
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
2005-11-09 07:17:26 +03:00
|
|
|
parsingStatus = ParseIDSelector(aDataMask, *newSel, aErrorCode);
|
2004-11-27 00:05:45 +03:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
2005-11-09 07:17:26 +03:00
|
|
|
parsingStatus = ParseClassSelector(aDataMask, *newSel, aErrorCode);
|
2004-11-27 00:05:45 +03:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
2005-11-09 07:17:26 +03:00
|
|
|
parsingStatus = ParsePseudoSelector(aDataMask, *newSel, aErrorCode, PR_TRUE);
|
2004-11-27 00:05:45 +03:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('[')) { // [attribute
|
2005-11-09 07:17:26 +03:00
|
|
|
parsingStatus = ParseAttributeSelector(aDataMask, *newSel, aErrorCode);
|
2004-11-27 00:05:45 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// then it should be a type element or universal selector
|
|
|
|
parsingStatus = ParseTypeOrUniversalSelector(aDataMask, *newSel, aErrorCode, PR_TRUE);
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
if (eSelectorParsingStatus_Error == parsingStatus) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationBadInner);
|
|
|
|
return parsingStatus;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
// close the parenthesis
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationNoClose);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eSelectorParsingStatus_Continue;
|
2001-03-20 14:49:20 +03:00
|
|
|
}
|
|
|
|
|
2002-08-14 16:34:39 +04:00
|
|
|
//
|
2005-10-16 19:57:13 +04:00
|
|
|
// Parse the argument of a pseudo-class that has an ident arg
|
2002-08-14 16:34:39 +04:00
|
|
|
//
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
2005-10-16 19:57:13 +04:00
|
|
|
CSSParserImpl::ParsePseudoClassWithIdentArg(nsCSSSelector& aSelector,
|
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsresult& aErrorCode)
|
2002-08-14 16:34:39 +04:00
|
|
|
{
|
|
|
|
// Check if we have the first parenthesis
|
2004-11-27 00:05:45 +03:00
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
2005-10-16 19:57:13 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassNoArg);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) { // premature eof
|
2005-10-16 19:57:13 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
// We expect an identifier with a language abbreviation
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
2005-10-16 19:57:13 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotIdent);
|
2004-11-27 00:05:45 +03:00
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2002-08-14 16:34:39 +04:00
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
// Add the pseudo with the language parameter
|
2005-10-16 19:57:13 +04:00
|
|
|
aSelector.AddPseudoClass(aPseudo, mToken.mIdent.get());
|
2002-08-14 16:34:39 +04:00
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
// close the parenthesis
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
2005-10-16 19:57:13 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassNoClose);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
|
|
|
|
return eSelectorParsingStatus_Continue;
|
2002-08-14 16:34:39 +04:00
|
|
|
}
|
|
|
|
|
2001-03-09 02:27:39 +03:00
|
|
|
/**
|
|
|
|
* This is the format for selectors:
|
|
|
|
* operator? [[namespace |]? element_name]? [ ID | class | attrib | pseudo ]*
|
|
|
|
*/
|
2004-11-27 00:05:45 +03:00
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseSelector(nsresult& aErrorCode, nsCSSSelector& aSelector)
|
2001-03-09 02:27:39 +03:00
|
|
|
{
|
|
|
|
if (! GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PESelectorEOF);
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Error;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
2004-11-27 00:05:45 +03:00
|
|
|
PRInt32 dataMask = 0;
|
|
|
|
nsSelectorParsingStatus parsingStatus =
|
|
|
|
ParseTypeOrUniversalSelector(dataMask, aSelector, aErrorCode, PR_FALSE);
|
|
|
|
if (parsingStatus != eSelectorParsingStatus_Continue) {
|
|
|
|
return parsingStatus;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2004-11-27 00:05:45 +03:00
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
|
|
|
parsingStatus = ParseIDSelector(dataMask, aSelector, aErrorCode);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
|
|
|
parsingStatus = ParseClassSelector(dataMask, aSelector, aErrorCode);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
|
|
|
parsingStatus = ParsePseudoSelector(dataMask, aSelector, aErrorCode, PR_FALSE);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
else if (mToken.IsSymbol('[')) { // [attribute
|
|
|
|
parsingStatus = ParseAttributeSelector(dataMask, aSelector, aErrorCode);
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
else { // not a selector token, we're done
|
2004-11-27 00:05:45 +03:00
|
|
|
parsingStatus = eSelectorParsingStatus_Done;
|
1998-12-11 05:50:43 +03:00
|
|
|
break;
|
1998-05-19 01:07:54 +04:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
|
|
|
|
if (parsingStatus != eSelectorParsingStatus_Continue) {
|
|
|
|
return parsingStatus;
|
2001-03-09 02:27:39 +03:00
|
|
|
}
|
2004-11-27 00:05:45 +03:00
|
|
|
|
1998-12-11 05:50:43 +03:00
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) { // premature eof is ok (here!)
|
2004-11-27 00:05:45 +03:00
|
|
|
return eSelectorParsingStatus_Done;
|
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();
|
2004-11-27 00:05:45 +03:00
|
|
|
return dataMask ? parsingStatus : eSelectorParsingStatus_Empty;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration*
|
2003-11-14 01:48:05 +03:00
|
|
|
CSSParserImpl::ParseDeclarationBlock(nsresult& 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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclBlockStart);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
1998-05-28 22:39:42 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSDeclaration* declaration = new nsCSSDeclaration();
|
|
|
|
mData.AssertInitialState();
|
|
|
|
if (declaration) {
|
1998-04-14 00:24:54 +04:00
|
|
|
for (;;) {
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool changed;
|
|
|
|
if (!ParseDeclaration(aErrorCode, declaration, aCheckForBraces,
|
2005-04-29 00:19:24 +04:00
|
|
|
PR_TRUE, &changed)) {
|
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.
|
|
|
|
}
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
declaration->CompressFrom(&mData);
|
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
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseColor(nsresult& aErrorCode, nsCSSValue& aValue)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorEOF);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
1998-10-27 02:22:40 +03:00
|
|
|
nscolor rgba;
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (tk->mType) {
|
1998-10-27 02:22:40 +03:00
|
|
|
case eCSSToken_ID:
|
2005-07-20 00:49:34 +04:00
|
|
|
case eCSSToken_Ref:
|
1998-10-27 02:22:40 +03:00
|
|
|
// #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
|
2004-10-01 21:15:15 +04:00
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kColorKTable, value)) {
|
|
|
|
aValue.SetIntValue(value, 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:
|
2004-06-17 04:13:25 +04:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("rgb")) {
|
1999-06-10 09:25:23 +04:00
|
|
|
// 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, ')')) {
|
2003-03-18 08:43:12 +03:00
|
|
|
aValue.SetColorValue(NS_RGB(r,g,b));
|
1999-06-10 09:25:23 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE; // already pushed back
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2005-04-18 06:51:40 +04:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-rgba") ||
|
|
|
|
(mHandleAlphaColors && mToken.mIdent.LowerCaseEqualsLiteral("rgba"))) {
|
2003-03-18 08:43:12 +03:00
|
|
|
// rgba ( component , component , component , opacity )
|
|
|
|
PRUint8 r, g, b, a;
|
|
|
|
PRInt32 type = COLOR_TYPE_UNKNOWN;
|
|
|
|
if (ExpectSymbol(aErrorCode, '(', PR_FALSE) && // this won't fail
|
|
|
|
ParseColorComponent(aErrorCode, r, type, ',') &&
|
|
|
|
ParseColorComponent(aErrorCode, g, type, ',') &&
|
|
|
|
ParseColorComponent(aErrorCode, b, type, ',') &&
|
|
|
|
ParseColorOpacity(aErrorCode, a)) {
|
|
|
|
aValue.SetColorValue(NS_RGBA(r, g, b, a));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE; // already pushed back
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("hsl")) {
|
2003-03-18 08:43:12 +03:00
|
|
|
// hsl ( hue , saturation , lightness )
|
|
|
|
// "hue" is a number, "saturation" and "lightness" are percentages.
|
|
|
|
if (ParseHSLColor(aErrorCode, rgba, ')')) {
|
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2005-04-18 06:51:40 +04:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-hsla") ||
|
|
|
|
(mHandleAlphaColors && mToken.mIdent.LowerCaseEqualsLiteral("hsla"))) {
|
2003-03-18 08:43:12 +03:00
|
|
|
// hsla ( hue , saturation , lightness , opacity )
|
|
|
|
// "hue" is a number, "saturation" and "lightness" are percentages,
|
|
|
|
// "opacity" is a number.
|
|
|
|
PRUint8 a;
|
|
|
|
if (ParseHSLColor(aErrorCode, rgba, ',') &&
|
|
|
|
ParseColorOpacity(aErrorCode, a)) {
|
|
|
|
aValue.SetColorValue(NS_RGBA(NS_GET_R(rgba), NS_GET_G(rgba),
|
|
|
|
NS_GET_B(rgba), a));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
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()) {
|
2002-10-15 03:49:48 +04: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[20];
|
|
|
|
switch (tk->mType) {
|
|
|
|
case eCSSToken_Ident:
|
|
|
|
str.Assign(tk->mIdent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Number:
|
|
|
|
if (tk->mIntegerValid) {
|
2002-10-15 04:29:58 +04:00
|
|
|
PR_snprintf(buffer, sizeof(buffer), "%06d", tk->mInteger);
|
2002-10-15 03:49:48 +04:00
|
|
|
str.AssignWithConversion(buffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
if (tk->mIdent.Length() <= 6) {
|
2002-10-15 04:29:58 +04:00
|
|
|
PR_snprintf(buffer, sizeof(buffer), "%06.0f", tk->mNumber);
|
2002-10-15 03:49:48 +04:00
|
|
|
nsAutoString temp;
|
|
|
|
temp.AssignWithConversion(buffer);
|
|
|
|
temp.Right(str, 6 - tk->mIdent.Length());
|
|
|
|
str.Append(tk->mIdent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// There is a whole bunch of cases that are
|
|
|
|
// not handled by this switch. Ignore them.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_HexToRGB(str, &rgba)) {
|
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-01-08 13:11:10 +03:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// It's not a color
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEColorNotColor);
|
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
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseColorComponent(nsresult& aErrorCode,
|
1998-10-27 02:22:40 +03:00
|
|
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorComponentEOF);
|
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:
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
2002-09-14 09:28:26 +04:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Someone forgot to add the new color component type in here");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mToken.mIntegerValid) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedInt);
|
2002-09-14 09:28:26 +04:00
|
|
|
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:
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedInt);
|
2002-09-14 09:28:26 +04:00
|
|
|
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:
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEColorBadRGBContents);
|
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;
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar stopString[] = { PRUnichar(aStop), PRUnichar(0) };
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
nsnull,
|
|
|
|
stopString
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_TOKEN_P(PEColorComponentBadTerm, params);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-18 08:43:12 +03:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseHSLColor(nsresult& aErrorCode, nscolor& aColor,
|
2003-03-18 08:43:12 +03:00
|
|
|
char aStop)
|
|
|
|
{
|
|
|
|
float h, s, l;
|
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
|
|
|
|
NS_ERROR("How did this get to be a function token?");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the hue
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorHueEOF);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Number) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedNumber);
|
2003-03-18 08:43:12 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
h = mToken.mNumber;
|
|
|
|
h /= 360.0f;
|
|
|
|
// hue values are wraparound
|
2003-03-18 11:29:00 +03:00
|
|
|
h = h - floor(h);
|
2003-03-18 08:43:12 +03:00
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedComma);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the saturation
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorSaturationEOF);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Percentage) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
2003-03-18 08:43:12 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
s = mToken.mNumber;
|
|
|
|
if (s < 0.0f) s = 0.0f;
|
|
|
|
if (s > 1.0f) s = 1.0f;
|
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedComma);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the lightness
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorLightnessEOF);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Percentage) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
2003-03-18 08:43:12 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
l = mToken.mNumber;
|
|
|
|
if (l < 0.0f) l = 0.0f;
|
|
|
|
if (l > 1.0f) l = 1.0f;
|
|
|
|
|
|
|
|
if (ExpectSymbol(aErrorCode, aStop, PR_TRUE)) {
|
|
|
|
aColor = NS_HSL2RGB(h, s, l);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar stopString[] = { PRUnichar(aStop), PRUnichar(0) };
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
nsnull,
|
|
|
|
stopString
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_TOKEN_P(PEColorComponentBadTerm, params);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseColorOpacity(nsresult& aErrorCode, PRUint8& aOpacity)
|
2003-03-18 08:43:12 +03:00
|
|
|
{
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorOpacityEOF);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mToken.mType != eCSSToken_Number) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedNumber);
|
2003-03-18 08:43:12 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-26 20:59:40 +04:00
|
|
|
PRInt32 value = NSToIntRound(mToken.mNumber*255);
|
2003-03-18 08:43:12 +03:00
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedCloseParen);
|
2003-03-18 08:43:12 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value < 0) value = 0;
|
|
|
|
if (value > 255) value = 255;
|
|
|
|
aOpacity = (PRUint8)value;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseTreePseudoElement(nsresult& 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) {
|
2002-12-11 17:24:49 +03:00
|
|
|
nsCOMPtr<nsIAtom> pseudo = do_GetAtom(mToken.mIdent);
|
2001-02-16 00:25:31 +03:00
|
|
|
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
|
2003-11-14 01:48:05 +03:00
|
|
|
CSSParserImpl::ParseDeclaration(nsresult& aErrorCode,
|
2002-01-16 01:43:37 +03:00
|
|
|
nsCSSDeclaration* aDeclaration,
|
1998-09-30 03:50:09 +04:00
|
|
|
PRBool aCheckForBraces,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.AssertInitialState();
|
|
|
|
|
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) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEDeclEndEOF);
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationNoColon);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-03-06 04:57:30 +03:00
|
|
|
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('}')) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationDeclExpected);
|
|
|
|
REPORT_UNEXPECTED(PEDeclSkipped);
|
2001-06-05 05:00:11 +04:00
|
|
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propertyName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownProperty, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2003-07-01 01:39:22 +04:00
|
|
|
if (! ParseProperty(aErrorCode, propID)) {
|
2000-09-06 06:27:46 +04:00
|
|
|
// XXX Much better to put stuff in the value parsers instead...
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propertyName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEPropertyParsingError, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
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)) {
|
2005-10-09 22:22:51 +04:00
|
|
|
// EOF is a perfectly good way to end a declaration and declaration block
|
2005-04-29 00:19:24 +04:00
|
|
|
TransferTempData(aDeclaration, propID, isImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
1998-05-28 22:39:42 +04:00
|
|
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEImportantEOF);
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Ident != tk->mType) ||
|
2004-06-17 04:13:25 +04:00
|
|
|
!tk->mIdent.LowerCaseEqualsLiteral("important")) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedImportant);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
1998-05-28 22:39:42 +04:00
|
|
|
UngetToken();
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
1998-05-28 22:39:42 +04:00
|
|
|
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
|
|
|
|
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
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEDeclEndEOF);
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2005-04-29 00:19:24 +04:00
|
|
|
TransferTempData(aDeclaration, propID, isImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
1998-05-28 22:39:42 +04:00
|
|
|
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) {
|
2005-04-29 00:19:24 +04:00
|
|
|
TransferTempData(aDeclaration, propID, isImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
1998-04-14 00:24:54 +04:00
|
|
|
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.
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclEnd);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
1998-05-28 22:39:42 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if ('}' == tk->mSymbol) {
|
|
|
|
UngetToken();
|
2005-04-29 00:19:24 +04:00
|
|
|
TransferTempData(aDeclaration, propID, isImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-09-20 23:38:11 +04:00
|
|
|
if (aCheckForBraces)
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclOrRuleEnd);
|
|
|
|
else
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclEnd);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
2001-03-06 04:57:30 +03:00
|
|
|
OUTPUT_ERROR();
|
2003-06-08 02:14:42 +04:00
|
|
|
ClearTempData(propID);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
void
|
|
|
|
CSSParserImpl::ClearTempData(nsCSSProperty aPropID)
|
|
|
|
{
|
|
|
|
if (nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
|
|
|
mTempData.ClearProperty(*p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mTempData.ClearProperty(aPropID);
|
|
|
|
}
|
|
|
|
mTempData.AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSParserImpl::TransferTempData(nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID, PRBool aIsImportant,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
|
|
|
if (nsCSSProps::IsShorthand(aPropID)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
|
2005-04-29 00:19:24 +04:00
|
|
|
DoTransferTempData(aDeclaration, *p, aIsImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
} else {
|
2005-04-29 00:19:24 +04:00
|
|
|
DoTransferTempData(aDeclaration, aPropID, aIsImportant,
|
|
|
|
aMustCallValueAppended, aChanged);
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
|
|
|
mTempData.AssertInitialState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perhaps the transferring code should be in nsCSSExpandedDataBlock, in
|
|
|
|
// case some other caller wants to use it in the future (although I
|
|
|
|
// can't think of why).
|
|
|
|
void
|
|
|
|
CSSParserImpl::DoTransferTempData(nsCSSDeclaration* aDeclaration,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID, PRBool aIsImportant,
|
2005-04-29 00:19:24 +04:00
|
|
|
PRBool aMustCallValueAppended,
|
2003-07-01 01:39:22 +04:00
|
|
|
PRBool* aChanged)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mTempData.HasPropertyBit(aPropID), "oops");
|
|
|
|
if (aIsImportant) {
|
2003-07-01 01:39:22 +04:00
|
|
|
if (!mData.HasImportantBit(aPropID))
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
mData.SetImportantBit(aPropID);
|
|
|
|
} else {
|
|
|
|
if (mData.HasImportantBit(aPropID)) {
|
|
|
|
mTempData.ClearProperty(aPropID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2005-04-29 00:19:24 +04:00
|
|
|
|
|
|
|
if (aMustCallValueAppended || !mData.HasPropertyBit(aPropID)) {
|
|
|
|
aDeclaration->ValueAppended(aPropID);
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
mData.SetPropertyBit(aPropID);
|
|
|
|
mTempData.ClearPropertyBit(aPropID);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save needless copying and allocation by calling the destructor in
|
|
|
|
* the destination, copying memory directly, and then using placement
|
|
|
|
* new.
|
|
|
|
*/
|
|
|
|
void *v_source = mTempData.PropertyAt(aPropID);
|
|
|
|
void *v_dest = mData.PropertyAt(aPropID);
|
|
|
|
switch (nsCSSProps::kTypeTable[aPropID]) {
|
|
|
|
case eCSSType_Value: {
|
|
|
|
nsCSSValue *source = NS_STATIC_CAST(nsCSSValue*, v_source);
|
|
|
|
nsCSSValue *dest = NS_STATIC_CAST(nsCSSValue*, v_dest);
|
2003-07-01 01:39:22 +04:00
|
|
|
if (*source != *dest)
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
dest->~nsCSSValue();
|
|
|
|
memcpy(dest, source, sizeof(nsCSSValue));
|
|
|
|
new (source) nsCSSValue();
|
2005-04-29 00:19:24 +04:00
|
|
|
if (dest->GetUnit() == eCSSUnit_Null) {
|
|
|
|
// Some of our property parsers actually want to _clear_ properties in
|
|
|
|
// mData (eg the "font" shorthand parser does for system fonts). We've
|
|
|
|
// cleared the data; now clear the bit too.
|
|
|
|
mData.ClearPropertyBit(aPropID);
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Rect: {
|
|
|
|
nsCSSRect *source = NS_STATIC_CAST(nsCSSRect*, v_source);
|
|
|
|
nsCSSRect *dest = NS_STATIC_CAST(nsCSSRect*, v_dest);
|
2003-07-01 01:39:22 +04:00
|
|
|
if (*source != *dest)
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
dest->~nsCSSRect();
|
|
|
|
memcpy(dest, source, sizeof(nsCSSRect));
|
|
|
|
new (source) nsCSSRect();
|
|
|
|
} break;
|
|
|
|
|
2004-09-10 07:26:58 +04:00
|
|
|
case eCSSType_ValuePair: {
|
|
|
|
nsCSSValuePair *source = NS_STATIC_CAST(nsCSSValuePair*, v_source);
|
|
|
|
nsCSSValuePair *dest = NS_STATIC_CAST(nsCSSValuePair*, v_dest);
|
|
|
|
if (*source != *dest)
|
|
|
|
*aChanged = PR_TRUE;
|
|
|
|
dest->~nsCSSValuePair();
|
|
|
|
memcpy(dest, source, sizeof(nsCSSValuePair));
|
|
|
|
new (source) nsCSSValuePair();
|
|
|
|
} break;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSType_ValueList: {
|
|
|
|
nsCSSValueList **source = NS_STATIC_CAST(nsCSSValueList**, v_source);
|
|
|
|
nsCSSValueList **dest = NS_STATIC_CAST(nsCSSValueList**, v_dest);
|
2003-07-01 01:39:22 +04:00
|
|
|
if (!nsCSSValueList::Equal(*source, *dest))
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
delete *dest;
|
|
|
|
*dest = *source;
|
|
|
|
*source = nsnull;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_CounterData: {
|
|
|
|
nsCSSCounterData **source = NS_STATIC_CAST(nsCSSCounterData**, v_source);
|
|
|
|
nsCSSCounterData **dest = NS_STATIC_CAST(nsCSSCounterData**, v_dest);
|
2003-07-01 01:39:22 +04:00
|
|
|
if (!nsCSSCounterData::Equal(*source, *dest))
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
delete *dest;
|
|
|
|
*dest = *source;
|
|
|
|
*source = nsnull;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case eCSSType_Quotes: {
|
|
|
|
nsCSSQuotes **source = NS_STATIC_CAST(nsCSSQuotes**, v_source);
|
|
|
|
nsCSSQuotes **dest = NS_STATIC_CAST(nsCSSQuotes**, v_dest);
|
2003-07-01 01:39:22 +04:00
|
|
|
if (!nsCSSQuotes::Equal(*source, *dest))
|
|
|
|
*aChanged = PR_TRUE;
|
2003-06-08 02:14:42 +04:00
|
|
|
delete *dest;
|
|
|
|
*dest = *source;
|
|
|
|
*source = nsnull;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// 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
|
2005-09-20 16:04:45 +04:00
|
|
|
#define VARIANT_COLOR 0x000008 // C eCSSUnit_Color, eCSSUnit_String (e.g. "red")
|
1998-10-27 02:22:40 +03:00
|
|
|
#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
|
2005-09-20 16:04:45 +04:00
|
|
|
#define VARIANT_INHERIT 0x020000 // H eCSSUnit_Initial, eCSSUnit_Inherit
|
1998-10-27 02:22:40 +03:00
|
|
|
#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)
|
2004-01-18 04:12:58 +03:00
|
|
|
#define VARIANT_AUK (VARIANT_AUTO | VARIANT_URL | 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
|
|
|
};
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseEnum(nsresult& aErrorCode, nsCSSValue& aValue,
|
1998-10-27 02:22:40 +03:00
|
|
|
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) {
|
2004-10-01 21:15:15 +04:00
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) {
|
|
|
|
aValue.SetIntValue(value, eCSSUnit_Enumerated);
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the unknown identifier back and return
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::TranslateDimension(nsresult& aErrorCode,
|
2000-08-08 04:34:42 +04:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
2003-03-17 06:58:06 +03:00
|
|
|
else {
|
|
|
|
NS_ERROR("Variant mask does not include dimension; why were we called?");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParsePositiveVariant(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2005-07-01 08:29:42 +04:00
|
|
|
// Assigns to aValue iff it returns PR_TRUE.
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseVariant(nsresult& aErrorCode, nsCSSValue& aValue,
|
1998-10-27 02:22:40 +03:00
|
|
|
PRInt32 aVariantMask,
|
1999-02-10 11:37:52 +03:00
|
|
|
const PRInt32 aKeywordTable[])
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
2005-09-20 16:04:45 +04:00
|
|
|
NS_ASSERTION(IsParsingCompoundProperty() ||
|
|
|
|
((~aVariantMask) & (VARIANT_LENGTH|VARIANT_COLOR)),
|
|
|
|
"cannot distinguish lengths and colors in quirks mode");
|
|
|
|
|
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) {
|
2004-10-01 21:15:15 +04:00
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) {
|
|
|
|
aValue.SetIntValue(value, 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()) {
|
2003-03-17 06:58:06 +03:00
|
|
|
if (TranslateDimension(aErrorCode, aValue, aVariantMask, tk->mNumber, tk->mIdent)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// Put the token back; we didn't parse it, so we shouldn't consume it
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
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;
|
|
|
|
}
|
|
|
|
}
|
2004-08-10 04:02:47 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
if (mSVGMode && !IsParsingCompoundProperty()) {
|
|
|
|
// STANDARD: SVG Spec states that lengths and coordinates can be unitless
|
|
|
|
// in which case they default to user-units (1 px = 1 user unit)
|
|
|
|
if (((aVariantMask & VARIANT_LENGTH) != 0) &&
|
|
|
|
(eCSSToken_Number == tk->mType)) {
|
|
|
|
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Pixel);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
if (((aVariantMask & VARIANT_URL) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("url")) {
|
1998-10-27 02:22:40 +03:00
|
|
|
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) ||
|
2005-07-20 00:49:34 +04:00
|
|
|
(eCSSToken_Ref == tk->mType) ||
|
1998-10-27 02:22:40 +03:00
|
|
|
(eCSSToken_Ident == tk->mType) ||
|
|
|
|
((eCSSToken_Function == tk->mType) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
(tk->mIdent.LowerCaseEqualsLiteral("rgb") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("hsl") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-rgba") ||
|
2005-04-18 06:51:40 +04:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-hsla") ||
|
|
|
|
(mHandleAlphaColors && (tk->mIdent.LowerCaseEqualsLiteral("rgba") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("hsla"))))))
|
|
|
|
{
|
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) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
(tk->mIdent.LowerCaseEqualsLiteral("counter") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("counters"))) {
|
2005-04-02 03:07:00 +04:00
|
|
|
return ParseCounter(aErrorCode, aValue);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_ATTR) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("attr")) {
|
2005-04-02 03:07:00 +04:00
|
|
|
return ParseAttr(aErrorCode, aValue);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseCounter(nsresult& aErrorCode, nsCSSValue& aValue)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
nsCSSUnit unit = (mToken.mIdent.LowerCaseEqualsLiteral("counter") ?
|
1998-10-27 02:22:40 +03:00
|
|
|
eCSSUnit_Counter : eCSSUnit_Counters);
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_FALSE))
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
if (!GetNonCloseParenToken(aErrorCode, PR_TRUE) ||
|
|
|
|
eCSSToken_Ident != mToken.mType) {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
nsRefPtr<nsCSSValue::Array> val =
|
|
|
|
nsCSSValue::Array::Create(unit == eCSSUnit_Counter ? 2 : 3);
|
|
|
|
if (!val) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
val->Item(0).SetStringValue(mToken.mIdent, eCSSUnit_String);
|
|
|
|
|
|
|
|
if (eCSSUnit_Counters == unit) {
|
|
|
|
// get mandatory separator string
|
|
|
|
if (!ExpectSymbol(aErrorCode, ',', PR_TRUE) ||
|
|
|
|
!(GetNonCloseParenToken(aErrorCode, PR_TRUE) &&
|
|
|
|
eCSSToken_String == mToken.mType)) {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
val->Item(1).SetStringValue(mToken.mIdent, eCSSUnit_String);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get optional type
|
|
|
|
PRInt32 type = NS_STYLE_LIST_STYLE_DECIMAL;
|
|
|
|
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
|
|
|
nsCSSKeyword keyword;
|
|
|
|
PRBool success = GetNonCloseParenToken(aErrorCode, PR_TRUE) &&
|
|
|
|
eCSSToken_Ident == mToken.mType &&
|
|
|
|
(keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent)) !=
|
|
|
|
eCSSKeyword_UNKNOWN;
|
|
|
|
if (success) {
|
|
|
|
if (keyword == eCSSKeyword_none) {
|
|
|
|
type = NS_STYLE_LIST_STYLE_NONE;
|
|
|
|
} else {
|
|
|
|
success = nsCSSProps::FindKeyword(keyword,
|
|
|
|
nsCSSProps::kListStyleKTable, type);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
if (!success) {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
PRInt32 typeItem = eCSSUnit_Counters == unit ? 2 : 1;
|
|
|
|
val->Item(typeItem).SetIntValue(type, eCSSUnit_Enumerated);
|
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
|
|
|
SkipUntil(aErrorCode, ')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aValue.SetArrayValue(val, unit);
|
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseAttr(nsresult& aErrorCode, nsCSSValue& aValue)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
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;
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) {
|
2001-12-08 10:08:38 +03:00
|
|
|
ToLowerCase(holdIdent); // always case insensitive, since stays within CSS
|
2002-12-11 17:24:49 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix = do_GetAtom(holdIdent);
|
2005-02-18 22:18:37 +03:00
|
|
|
nameSpaceID = mNameSpaceMap->FindNameSpaceID(prefix);
|
2002-12-11 17:24:49 +03:00
|
|
|
} // else, no declared namespaces
|
1999-06-10 09:25:23 +04:00
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) { // unknown prefix, dump it
|
2004-09-20 23:38:11 +04:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
holdIdent.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownNamespacePrefix, params);
|
1999-06-10 09:25:23 +04:00
|
|
|
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)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
1999-06-10 09:25:23 +04:00
|
|
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
1999-06-10 09:25:23 +04:00
|
|
|
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
|
2003-10-30 05:06:12 +03:00
|
|
|
// Wildcard namespace makes no sense here and is not allowed
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
2003-10-30 05:06:12 +03:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
1999-06-10 09:25:23 +04:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // explicit NO namespace
|
|
|
|
if (! GetToken(aErrorCode, PR_FALSE)) {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
1999-06-10 09:25:23 +04:00
|
|
|
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 {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
1999-06-10 09:25:23 +04:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameOrNamespaceExpected);
|
1998-10-27 02:22:40 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseURL(nsresult& aErrorCode, nsCSSValue& aValue)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
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.
|
2003-10-30 04:45:37 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-09-10 10:45:59 +04:00
|
|
|
NS_NewURI(getter_AddRefs(uri), tk->mIdent, nsnull, mBaseURL);
|
1998-10-27 02:22:40 +03:00
|
|
|
if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) {
|
2003-10-02 02:53:56 +04:00
|
|
|
// Set a null value on failure. Most failure cases should be
|
|
|
|
// NS_ERROR_MALFORMED_URI.
|
2004-09-10 10:45:59 +04:00
|
|
|
nsCSSValue::URL *url =
|
2005-07-20 00:44:49 +04:00
|
|
|
new nsCSSValue::URL(uri, tk->mIdent.get(), mSheetURL);
|
2003-10-30 04:45:37 +03:00
|
|
|
if (!url || !url->mString) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
delete url;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
aValue.SetURLValue(url);
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRInt32 CSSParserImpl::ParseChoice(nsresult& 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;
|
2005-09-20 16:04:45 +04:00
|
|
|
nsAutoParseCompoundProperty compound(this);
|
2000-08-05 08:40:03 +04:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
void
|
|
|
|
CSSParserImpl::AppendValue(nsCSSProperty aPropID,
|
2003-07-01 01:39:22 +04:00
|
|
|
const nsCSSValue& aValue)
|
1999-08-08 05:17:29 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
NS_ASSERTION(0 <= aPropID && aPropID < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property out of range");
|
|
|
|
NS_ASSERTION(nsCSSProps::kTypeTable[aPropID] == eCSSType_Value,
|
|
|
|
nsPrintfCString(64, "type error (property=\'%s\')",
|
|
|
|
nsCSSProps::GetStringValue(aPropID).get()).get());
|
|
|
|
nsCSSValue& storage =
|
|
|
|
*NS_STATIC_CAST(nsCSSValue*, mTempData.PropertyAt(aPropID));
|
2003-07-01 01:39:22 +04:00
|
|
|
storage = aValue;
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.SetPropertyBit(aPropID);
|
1999-08-08 05:17:29 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBoxProperties(nsresult& aErrorCode,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSRect& aResult,
|
2003-07-01 01:39:22 +04:00
|
|
|
const nsCSSProperty aPropIDs[])
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// Get up to four values for the property
|
|
|
|
PRInt32 count = 0;
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 index;
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSRect result;
|
1998-10-27 02:22:40 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
2003-06-08 02:14:42 +04:00
|
|
|
if (! ParseSingleValueProperty(aErrorCode,
|
|
|
|
result.*(nsCSSRect::sides[index]),
|
|
|
|
aPropIDs[index])) {
|
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++) {
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSUnit unit = (result.*(nsCSSRect::sides[index])).GetUnit();
|
|
|
|
if (eCSSUnit_Inherit == unit || eCSSUnit_Initial == unit) {
|
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
|
2003-06-08 02:14:42 +04:00
|
|
|
result.mRight = result.mTop;
|
1998-04-14 00:24:54 +04:00
|
|
|
case 2: // Make bottom == top
|
2003-06-08 02:14:42 +04:00
|
|
|
result.mBottom = result.mTop;
|
1998-04-14 00:24:54 +04:00
|
|
|
case 3: // Make left == right
|
2003-06-08 02:14:42 +04:00
|
|
|
result.mLeft = result.mRight;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
for (index = 0; index < 4; index++) {
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.SetPropertyBit(aPropIDs[index]);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
aResult = result;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-02-04 09:10:56 +03:00
|
|
|
PRBool CSSParserImpl::ParseDirectionalBoxProperty(nsresult& aErrorCode,
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
PRInt32 aSourceType)
|
|
|
|
{
|
|
|
|
const nsCSSProperty* subprops = nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ASSERTION(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
|
|
|
nsCSSValue value;
|
|
|
|
if (!ParseSingleValueProperty(aErrorCode, value, subprops[0]) ||
|
|
|
|
!ExpectEndProperty(aErrorCode, PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
AppendValue(subprops[0], value);
|
|
|
|
nsCSSValue typeVal(aSourceType, eCSSUnit_Enumerated);
|
|
|
|
AppendValue(subprops[1], typeVal);
|
|
|
|
AppendValue(subprops[2], typeVal);
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseProperty(nsresult& aErrorCode,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-10 11:37:52 +03:00
|
|
|
switch (aPropID) { // handle shorthand or multiple properties
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBackground(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_background_position:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBackgroundPosition(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border:
|
2003-07-31 03:45:34 +04:00
|
|
|
return ParseBorderSide(aErrorCode, kBorderTopIDs, PR_TRUE);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_color:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBorderColor(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_spacing:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBorderSpacing(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_style:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBorderStyle(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_bottom:
|
2003-07-31 03:45:34 +04:00
|
|
|
return ParseBorderSide(aErrorCode, kBorderBottomIDs, PR_FALSE);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_left:
|
2003-07-31 03:45:34 +04:00
|
|
|
return ParseBorderSide(aErrorCode, kBorderLeftIDs, PR_FALSE);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_right:
|
2003-07-31 03:45:34 +04:00
|
|
|
return ParseBorderSide(aErrorCode, kBorderRightIDs, PR_FALSE);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_top:
|
2003-07-31 03:45:34 +04:00
|
|
|
return ParseBorderSide(aErrorCode, kBorderTopIDs, PR_FALSE);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_bottom_colors:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBorderColors(aErrorCode,
|
|
|
|
&mTempData.mMargin.mBorderColors.mBottom,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_left_colors:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBorderColors(aErrorCode,
|
|
|
|
&mTempData.mMargin.mBorderColors.mLeft,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_right_colors:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBorderColors(aErrorCode,
|
|
|
|
&mTempData.mMargin.mBorderColors.mRight,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_border_top_colors:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBorderColors(aErrorCode,
|
|
|
|
&mTempData.mMargin.mBorderColors.mTop,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_border_width:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBorderWidth(aErrorCode);
|
1999-12-22 14:27:10 +03:00
|
|
|
case eCSSProperty__moz_border_radius:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseBorderRadius(aErrorCode);
|
2000-01-24 14:19:55 +03:00
|
|
|
case eCSSProperty__moz_outline_radius:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseOutlineRadius(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_clip:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseRect(mTempData.mDisplay.mClip, aErrorCode,
|
2003-07-01 01:39:22 +04:00
|
|
|
eCSSProperty_clip);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_content:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseContent(aErrorCode);
|
2005-04-02 03:07:00 +04:00
|
|
|
case eCSSProperty_counter_increment:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseCounterData(aErrorCode, &mTempData.mContent.mCounterIncrement,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
2005-04-02 03:07:00 +04:00
|
|
|
case eCSSProperty_counter_reset:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseCounterData(aErrorCode, &mTempData.mContent.mCounterReset,
|
2003-07-01 01:39:22 +04:00
|
|
|
aPropID);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cue:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseCue(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_cursor:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseCursor(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_font:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseFont(aErrorCode);
|
2001-12-05 11:35:05 +03:00
|
|
|
case eCSSProperty_image_region:
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseRect(mTempData.mList.mImageRegion, aErrorCode,
|
2003-07-01 01:39:22 +04:00
|
|
|
eCSSProperty_image_region);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_list_style:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseListStyle(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_margin:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseMargin(aErrorCode);
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_end:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_margin_end,
|
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_margin_left,
|
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_margin_right,
|
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_margin_start:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_margin_start,
|
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseOutline(aErrorCode);
|
2004-09-05 04:04:04 +04:00
|
|
|
case eCSSProperty_overflow:
|
|
|
|
return ParseOverflow(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParsePadding(aErrorCode);
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_padding_end:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_padding_end,
|
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_padding_left,
|
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_padding_right,
|
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_padding_start:
|
|
|
|
return ParseDirectionalBoxProperty(aErrorCode, eCSSProperty_padding_start,
|
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pause:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParsePause(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_quotes:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseQuotes(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_size:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseSize(aErrorCode);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_text_shadow:
|
2003-07-01 01:39:22 +04:00
|
|
|
return ParseTextShadow(aErrorCode);
|
1999-08-08 05:17:29 +04:00
|
|
|
|
2004-12-09 06:16:15 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
|
|
|
return ParseDasharray(aErrorCode);
|
|
|
|
case eCSSProperty_marker:
|
|
|
|
return ParseMarker(aErrorCode);
|
|
|
|
#endif
|
|
|
|
|
1999-08-08 05:17:29 +04:00
|
|
|
// 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:
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_end_value:
|
|
|
|
case eCSSProperty_margin_left_value:
|
|
|
|
case eCSSProperty_margin_right_value:
|
|
|
|
case eCSSProperty_margin_start_value:
|
|
|
|
case eCSSProperty_margin_left_ltr_source:
|
|
|
|
case eCSSProperty_margin_left_rtl_source:
|
|
|
|
case eCSSProperty_margin_right_ltr_source:
|
|
|
|
case eCSSProperty_margin_right_rtl_source:
|
|
|
|
case eCSSProperty_padding_end_value:
|
|
|
|
case eCSSProperty_padding_left_value:
|
|
|
|
case eCSSProperty_padding_right_value:
|
|
|
|
case eCSSProperty_padding_start_value:
|
|
|
|
case eCSSProperty_padding_left_ltr_source:
|
|
|
|
case eCSSProperty_padding_left_rtl_source:
|
|
|
|
case eCSSProperty_padding_right_ltr_source:
|
|
|
|
case eCSSProperty_padding_right_rtl_source:
|
1999-08-08 05:17:29 +04:00
|
|
|
// The user can't use these
|
2004-09-20 23:38:11 +04:00
|
|
|
REPORT_UNEXPECTED(PEInaccessibleProperty);
|
1999-08-08 05:17:29 +04:00
|
|
|
return PR_FALSE;
|
1999-02-10 11:37:52 +03:00
|
|
|
|
|
|
|
default: // must be single property
|
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSValue value;
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ParseSingleValueProperty(aErrorCode, value, aPropID)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(aPropID, value);
|
2003-06-08 02:14:42 +04:00
|
|
|
aErrorCode = NS_OK;
|
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
|
2004-04-10 09:08:02 +04:00
|
|
|
#define BG_CTB (BG_CENTER | BG_TOP | BG_BOTTOM)
|
|
|
|
#define BG_CLR (BG_CENTER | BG_LEFT | BG_RIGHT)
|
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,
|
|
|
|
};
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseSingleValueProperty(nsresult& aErrorCode,
|
1999-02-10 11:37:52 +03:00
|
|
|
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:
|
2003-03-17 06:58:06 +03:00
|
|
|
case eCSSProperty__moz_border_radius:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_clip:
|
|
|
|
case eCSSProperty_content:
|
2005-04-02 03:07:00 +04:00
|
|
|
case eCSSProperty_counter_increment:
|
|
|
|
case eCSSProperty_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:
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_end:
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_start:
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline:
|
2003-03-17 06:58:06 +03:00
|
|
|
case eCSSProperty__moz_outline_radius:
|
2004-09-05 04:04:04 +04:00
|
|
|
case eCSSProperty_overflow:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding:
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_padding_end:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_start:
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_pause:
|
|
|
|
case eCSSProperty_quotes:
|
|
|
|
case eCSSProperty_size:
|
|
|
|
case eCSSProperty_text_shadow:
|
1999-07-24 23:04:42 +04:00
|
|
|
case eCSSProperty_COUNT:
|
2004-11-09 21:19:28 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
2004-12-09 06:16:15 +03:00
|
|
|
case eCSSProperty_marker:
|
2004-11-09 21:19:28 +03:00
|
|
|
#endif
|
1999-02-10 11:37:52 +03:00
|
|
|
NS_ERROR("not a single value property");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_left_ltr_source:
|
|
|
|
case eCSSProperty_margin_left_rtl_source:
|
|
|
|
case eCSSProperty_margin_right_ltr_source:
|
|
|
|
case eCSSProperty_margin_right_rtl_source:
|
|
|
|
case eCSSProperty_padding_left_ltr_source:
|
|
|
|
case eCSSProperty_padding_left_rtl_source:
|
|
|
|
case eCSSProperty_padding_right_ltr_source:
|
|
|
|
case eCSSProperty_padding_right_rtl_source:
|
1999-07-24 23:04:42 +04:00
|
|
|
NS_ERROR("not currently parsed here");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
case eCSSProperty_appearance:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kAppearanceKTable);
|
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);
|
2003-01-17 12:33:52 +03:00
|
|
|
case eCSSProperty__moz_background_inline_policy:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kBackgroundInlinePolicyKTable);
|
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);
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_background_x_position: // for internal use
|
|
|
|
case eCSSProperty_background_y_position: // for internal use
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HKLP,
|
|
|
|
kBackgroundXYPositionKTable);
|
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);
|
2004-06-17 15:57:37 +04:00
|
|
|
case eCSSProperty__moz_column_count:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_AHI, nsnull);
|
|
|
|
case eCSSProperty__moz_column_width:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHL, nsnull);
|
2004-07-18 16:12:46 +04:00
|
|
|
case eCSSProperty__moz_column_gap:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
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);
|
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-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
|
|
|
#ifdef MOZ_SVG
|
2005-01-25 06:55:03 +03:00
|
|
|
case eCSSProperty_clip_path:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
|
|
|
case eCSSProperty_clip_rule:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kFillRuleKTable);
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
case eCSSProperty_dominant_baseline:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kDominantBaselineKTable);
|
2001-12-12 10:59:31 +03:00
|
|
|
case eCSSProperty_fill:
|
2004-10-15 03:02:53 +04:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC | VARIANT_NONE | VARIANT_URL,
|
2001-12-12 10:59:31 +03:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_fill_opacity:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_fill_rule:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kFillRuleKTable);
|
2005-09-07 02:30:40 +04:00
|
|
|
case eCSSProperty_filter:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
2004-12-09 06:16:15 +03:00
|
|
|
case eCSSProperty_marker_end:
|
|
|
|
case eCSSProperty_marker_mid:
|
|
|
|
case eCSSProperty_marker_start:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HUO, nsnull);
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
case eCSSProperty_pointer_events:
|
2005-04-05 01:42:26 +04:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK,
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
nsCSSProps::kPointerEventsKTable);
|
|
|
|
case eCSSProperty_shape_rendering:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kShapeRenderingKTable);
|
2004-10-15 03:02:53 +04:00
|
|
|
case eCSSProperty_stop_color:
|
2001-12-12 10:59:31 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC | VARIANT_NONE,
|
|
|
|
nsnull);
|
2004-10-15 03:02:53 +04:00
|
|
|
case eCSSProperty_stop_opacity:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HC | VARIANT_NONE | VARIANT_URL,
|
|
|
|
nsnull);
|
2001-12-12 10:59:31 +03:00
|
|
|
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,
|
2005-04-05 01:42:26 +04:00
|
|
|
nsnull);
|
2001-12-12 10:59:31 +03:00
|
|
|
case eCSSProperty_stroke_opacity:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN,
|
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_width:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLPN,
|
|
|
|
nsnull);
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
case eCSSProperty_text_anchor:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kTextAnchorKTable);
|
|
|
|
case eCSSProperty_text_rendering:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
|
|
|
nsCSSProps::kTextRenderingKTable);
|
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-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-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:
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_margin_end_value: // for internal use
|
|
|
|
case eCSSProperty_margin_left_value: // for internal use
|
|
|
|
case eCSSProperty_margin_right_value: // for internal use
|
|
|
|
case eCSSProperty_margin_start_value: // for internal use
|
1999-07-18 04:31:37 +04:00
|
|
|
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:
|
2004-01-06 02:59:25 +03:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLPO, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_min_height:
|
|
|
|
case eCSSProperty_min_width:
|
2004-01-06 02:59:25 +03:00
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HLP, nsnull);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_opacity:
|
2003-03-08 06:08:25 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HN, 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);
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline_color:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HCK,
|
|
|
|
nsCSSProps::kOutlineColorKTable);
|
2005-03-27 15:36:08 +04:00
|
|
|
case eCSSProperty_outline_style:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HOK | VARIANT_AUTO,
|
|
|
|
nsCSSProps::kOutlineStyleKTable);
|
|
|
|
case eCSSProperty_outline_width:
|
|
|
|
return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HKL,
|
|
|
|
nsCSSProps::kBorderWidthKTable);
|
|
|
|
case eCSSProperty_outline_offset:
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HL, nsnull);
|
2004-09-05 04:04:04 +04:00
|
|
|
case eCSSProperty_overflow_x:
|
|
|
|
case eCSSProperty_overflow_y:
|
1999-02-10 11:37:52 +03:00
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_AHK,
|
2004-09-05 04:04:04 +04:00
|
|
|
nsCSSProps::kOverflowSubKTable);
|
1999-07-18 04:31:37 +04:00
|
|
|
case eCSSProperty_padding_bottom:
|
2004-02-04 09:10:56 +03:00
|
|
|
case eCSSProperty_padding_end_value: // for internal use
|
|
|
|
case eCSSProperty_padding_left_value: // for internal use
|
|
|
|
case eCSSProperty_padding_right_value: // for internal use
|
|
|
|
case eCSSProperty_padding_start_value: // for internal use
|
1999-07-18 04:31:37 +04:00
|
|
|
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-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:
|
2003-03-18 08:25:37 +03:00
|
|
|
// When we support aligning on a string, we can parse text-align
|
|
|
|
// as a string....
|
|
|
|
return ParseVariant(aErrorCode, aValue, VARIANT_HK /* | VARIANT_STRING */,
|
1999-02-10 11:37:52 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseAzimuth(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2004-04-10 09:08:02 +04:00
|
|
|
static nsCSSValue
|
|
|
|
BackgroundPositionMaskToCSSValue(PRInt32 aMask, PRBool isX)
|
|
|
|
{
|
|
|
|
PRInt32 pct = 50;
|
|
|
|
if (isX) {
|
|
|
|
if (aMask & BG_LEFT) {
|
|
|
|
pct = 0;
|
|
|
|
}
|
|
|
|
else if (aMask & BG_RIGHT) {
|
|
|
|
pct = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aMask & BG_TOP) {
|
|
|
|
pct = 0;
|
|
|
|
}
|
|
|
|
else if (aMask & BG_BOTTOM) {
|
|
|
|
pct = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSValue(pct, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBackground(nsresult& aErrorCode)
|
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
|
2004-04-10 09:08:02 +04:00
|
|
|
if (0 == (found & 0x20)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
if (eCSSUnit_Enumerated == values[4].GetUnit()) {
|
2004-04-10 09:08:02 +04:00
|
|
|
PRInt32 mask = values[4].GetIntValue();
|
|
|
|
values[4] = BackgroundPositionMaskToCSSValue(mask, PR_TRUE);
|
|
|
|
values[5] = BackgroundPositionMaskToCSSValue(mask, PR_FALSE);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
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();
|
2004-04-10 09:08:02 +04:00
|
|
|
if (eCSSUnit_Enumerated == xUnit) {
|
|
|
|
PRInt32 xValue = values[4].GetIntValue();
|
1999-02-10 11:37:52 +03:00
|
|
|
if (eCSSUnit_Enumerated == yUnit) {
|
|
|
|
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;
|
|
|
|
}
|
2004-04-10 09:08:02 +04:00
|
|
|
NS_ASSERTION(xValue & BG_CLR, "bad x value");
|
|
|
|
NS_ASSERTION(yValue & BG_CTB, "bad y value");
|
|
|
|
values[4] = BackgroundPositionMaskToCSSValue(xValue, PR_TRUE);
|
|
|
|
values[5] = BackgroundPositionMaskToCSSValue(yValue, PR_FALSE);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-04-10 09:08:02 +04:00
|
|
|
if (!(xValue & BG_CLR)) {
|
|
|
|
// The first keyword can only be 'center', 'left', or 'right'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
values[4] = BackgroundPositionMaskToCSSValue(xValue, PR_TRUE);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (eCSSUnit_Enumerated == yUnit) {
|
2004-04-10 09:08:02 +04:00
|
|
|
PRInt32 yValue = values[5].GetIntValue();
|
|
|
|
if (!(yValue & BG_CTB)) {
|
|
|
|
// The second keyword can only be 'center', 'top', or 'bottom'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
values[5] = BackgroundPositionMaskToCSSValue(yValue, PR_FALSE);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(kBackgroundIDs[index], values[index]);
|
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
|
2003-01-17 12:33:52 +03:00
|
|
|
static const PRInt32 numResetProps = 3;
|
2002-10-08 14:24:53 +04:00
|
|
|
static const nsCSSProperty kBackgroundResetIDs[numResetProps] = {
|
|
|
|
eCSSProperty__moz_background_clip,
|
2003-01-17 12:33:52 +03:00
|
|
|
eCSSProperty__moz_background_inline_policy,
|
2002-10-08 14:24:53 +04:00
|
|
|
eCSSProperty__moz_background_origin
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCSSValue initial;
|
|
|
|
initial.SetInitialValue();
|
|
|
|
for (index = 0; index < numResetProps; ++index) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(kBackgroundResetIDs[index], initial);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBackgroundPosition(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-04-10 09:08:02 +04:00
|
|
|
// First try a percentage or a length value
|
|
|
|
nsCSSValue xValue, yValue;
|
1999-02-10 11:37:52 +03:00
|
|
|
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)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, xValue);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2004-04-10 09:08:02 +04:00
|
|
|
// We have one percentage/length. Get the optional second
|
|
|
|
// percentage/length/keyword.
|
1999-02-10 11:37:52 +03:00
|
|
|
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)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, yValue);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-04-10 09:08:02 +04:00
|
|
|
if (ParseEnum(aErrorCode, yValue, kBackgroundXYPositionKTable)) {
|
|
|
|
PRInt32 yVal = yValue.GetIntValue();
|
|
|
|
if (!(yVal & BG_CTB)) {
|
|
|
|
// The second keyword can only be 'center', 'top', or 'bottom'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
yValue = BackgroundPositionMaskToCSSValue(yVal, PR_FALSE);
|
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, yValue);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If only one percentage or length value is given, it sets the
|
|
|
|
// horizontal position only, and the vertical position will be 50%.
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, nsCSSValue(0.5f, eCSSUnit_Percent));
|
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;
|
2004-04-10 09:08:02 +04:00
|
|
|
if (ParseEnum(aErrorCode, xValue, kBackgroundXYPositionKTable)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
PRInt32 bit = xValue.GetIntValue();
|
|
|
|
mask |= bit;
|
2004-04-10 09:08:02 +04:00
|
|
|
if (ParseEnum(aErrorCode, xValue, kBackgroundXYPositionKTable)) {
|
|
|
|
bit = xValue.GetIntValue();
|
|
|
|
if (mask & (bit & ~BG_CENTER)) {
|
|
|
|
// Only the 'center' keyword can be duplicated.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
mask |= bit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Only one keyword. See if we have a length or percentage.
|
|
|
|
if (ParseVariant(aErrorCode, yValue, VARIANT_LP, nsnull)) {
|
|
|
|
if (!(mask & BG_CLR)) {
|
|
|
|
// The first keyword can only be 'center', 'left', or 'right'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
xValue = BackgroundPositionMaskToCSSValue(mask, PR_TRUE);
|
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, yValue);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
1999-02-10 11:37:52 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
// Create style values
|
2004-04-10 09:08:02 +04:00
|
|
|
xValue = BackgroundPositionMaskToCSSValue(mask, PR_TRUE);
|
|
|
|
yValue = BackgroundPositionMaskToCSSValue(mask, PR_FALSE);
|
|
|
|
AppendValue(eCSSProperty_background_x_position, xValue);
|
|
|
|
AppendValue(eCSSProperty_background_y_position, yValue);
|
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
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderColor(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mBorderColor,
|
2003-07-01 01:39:22 +04:00
|
|
|
kBorderColorIDs);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderSpacing(nsresult& aErrorCode)
|
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)) {
|
2004-09-10 07:26:58 +04:00
|
|
|
mTempData.mTable.mBorderSpacing.mXValue = xValue;
|
|
|
|
mTempData.mTable.mBorderSpacing.mYValue = yValue;
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_border_spacing);
|
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)) {
|
2004-09-10 07:26:58 +04:00
|
|
|
mTempData.mTable.mBorderSpacing.SetBothValuesTo(xValue);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_border_spacing);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderSide(nsresult& aErrorCode,
|
2003-07-31 03:45:34 +04:00
|
|
|
const nsCSSProperty aPropIDs[],
|
|
|
|
PRBool aSetAllSides)
|
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
|
|
|
}
|
2003-07-31 03:45:34 +04:00
|
|
|
if ((found & 4) == 0) { // 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
|
|
|
}
|
|
|
|
|
2003-07-31 03:45:34 +04:00
|
|
|
if (aSetAllSides) {
|
|
|
|
// Parsing "border" shorthand; set all four sides to the same thing
|
|
|
|
for (PRInt32 index = 0; index < 4; index++) {
|
|
|
|
NS_ASSERTION(numProps == 3, "This code needs updating");
|
|
|
|
AppendValue(kBorderWidthIDs[index], values[0]);
|
|
|
|
AppendValue(kBorderStyleIDs[index], values[1]);
|
|
|
|
AppendValue(kBorderColorIDs[index], values[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Just set our one side
|
|
|
|
for (PRInt32 index = 0; index < numProps; index++) {
|
|
|
|
AppendValue(aPropIDs[index], values[index]);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderStyle(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mBorderStyle,
|
2003-07-01 01:39:22 +04:00
|
|
|
kBorderStyleIDs);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderWidth(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mBorderWidth,
|
2003-07-01 01:39:22 +04:00
|
|
|
kBorderWidthIDs);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderRadius(nsresult& aErrorCode)
|
1999-12-22 14:27:10 +03:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mBorderRadius,
|
2003-07-01 01:39:22 +04:00
|
|
|
kBorderRadiusIDs);
|
1999-12-22 14:27:10 +03:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseOutlineRadius(nsresult& aErrorCode)
|
2000-01-24 14:19:55 +03:00
|
|
|
{
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mOutlineRadius,
|
2003-07-01 01:39:22 +04:00
|
|
|
kOutlineRadiusIDs);
|
2000-01-24 14:19:55 +03:00
|
|
|
}
|
1999-12-22 14:27:10 +03:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseBorderColors(nsresult& aErrorCode,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSValueList** aResult,
|
2003-07-01 01:39:22 +04:00
|
|
|
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)) {
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.SetPropertyBit(aProperty);
|
|
|
|
*aResult = listHead;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2003-06-08 02:14:42 +04:00
|
|
|
PRBool
|
2003-11-14 01:48:05 +03:00
|
|
|
CSSParserImpl::ParseRect(nsCSSRect& aRect, nsresult& aErrorCode,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID)
|
2003-06-08 02:14:42 +04:00
|
|
|
{
|
|
|
|
nsCSSRect rect;
|
|
|
|
PRBool result;
|
2003-07-01 01:39:22 +04:00
|
|
|
if ((result = DoParseRect(rect, aErrorCode)) &&
|
2003-06-08 02:14:42 +04:00
|
|
|
rect != aRect) {
|
|
|
|
aRect = rect;
|
|
|
|
mTempData.SetPropertyBit(aPropID);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2003-11-14 01:48:05 +03:00
|
|
|
CSSParserImpl::DoParseRect(nsCSSRect& aRect, nsresult& aErrorCode)
|
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;
|
|
|
|
}
|
2003-11-16 04:12:50 +03:00
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
|
|
|
|
switch (keyword) {
|
|
|
|
case eCSSKeyword_auto:
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
aRect.SetAllSidesTo(nsCSSValue(eCSSUnit_Auto));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_inherit:
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
aRect.SetAllSidesTo(nsCSSValue(eCSSUnit_Inherit));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eCSSKeyword__moz_initial:
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
aRect.SetAllSidesTo(nsCSSValue(eCSSUnit_Initial));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UngetToken();
|
|
|
|
break;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
} else if ((eCSSToken_Function == mToken.mType) &&
|
2004-06-17 04:13:25 +04:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("rect")) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if (!ExpectSymbol(aErrorCode, '(', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-04-13 01:54:45 +04:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2003-06-08 02:14:42 +04:00
|
|
|
if (! ParseVariant(aErrorCode, aRect.*(nsCSSRect::sides[side]),
|
|
|
|
VARIANT_AL, nsnull)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2003-06-08 02:14:42 +04:00
|
|
|
if (3 != side) {
|
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)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
} 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)
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseContent(nsresult& aErrorCode)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
2005-04-02 03:07:00 +04:00
|
|
|
// XXX Rewrite to make it look more like ParseCursor or ParseCounterData?
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSValue value;
|
2004-10-06 04:45:42 +04:00
|
|
|
if (ParseVariant(aErrorCode, value,
|
|
|
|
VARIANT_CONTENT | VARIANT_INHERIT | VARIANT_NORMAL,
|
1999-02-10 11:37:52 +03:00
|
|
|
nsCSSProps::kContentKTable)) {
|
|
|
|
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)) {
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.SetPropertyBit(eCSSProperty_content);
|
|
|
|
mTempData.mContent.mContent = listHead;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (eCSSUnit_Inherit == value.GetUnit() ||
|
2004-10-06 04:45:42 +04:00
|
|
|
eCSSUnit_Initial == value.GetUnit() ||
|
2005-09-18 22:05:40 +04:00
|
|
|
eCSSUnit_Normal == value.GetUnit() ||
|
|
|
|
(eCSSUnit_Enumerated == value.GetUnit() &&
|
|
|
|
NS_STYLE_CONTENT_ALT_CONTENT == value.GetIntValue())) {
|
2003-06-08 02:14:42 +04:00
|
|
|
// This only matters the first time through the loop.
|
|
|
|
return PR_FALSE;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2005-09-18 22:05:40 +04:00
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_CONTENT, nsCSSProps::kContentKTable) &&
|
|
|
|
// Make sure we didn't end up with NS_STYLE_CONTENT_ALT_CONTENT here
|
|
|
|
(value.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
value.GetIntValue() != NS_STYLE_CONTENT_ALT_CONTENT)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
struct SingleCounterPropValue {
|
|
|
|
char str[13];
|
|
|
|
nsCSSUnit unit;
|
|
|
|
};
|
2003-06-08 02:14:42 +04:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseCounterData(nsresult& aErrorCode,
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSCounterData** aResult,
|
2003-07-01 01:39:22 +04:00
|
|
|
nsCSSProperty aPropID)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
|
|
|
nsString* ident = NextIdent(aErrorCode);
|
|
|
|
if (nsnull == ident) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
static const SingleCounterPropValue singleValues[] = {
|
|
|
|
{ "none", eCSSUnit_None },
|
|
|
|
{ "inherit", eCSSUnit_Inherit },
|
|
|
|
{ "-moz-initial", eCSSUnit_Initial }
|
|
|
|
};
|
|
|
|
for (const SingleCounterPropValue *sv = singleValues,
|
|
|
|
*sv_end = singleValues + NS_ARRAY_LENGTH(singleValues);
|
|
|
|
sv != sv_end; ++sv) {
|
|
|
|
if (ident->LowerCaseEqualsLiteral(sv->str)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
nsCSSCounterData* dataHead = new nsCSSCounterData();
|
|
|
|
if (!dataHead) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
dataHead->mCounter = nsCSSValue(sv->unit);
|
|
|
|
*aResult = dataHead;
|
|
|
|
mTempData.SetPropertyBit(aPropID);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
UngetToken(); // undo NextIdent
|
|
|
|
|
|
|
|
nsCSSCounterData* dataHead = nsnull;
|
|
|
|
nsCSSCounterData **next = &dataHead;
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(aErrorCode, PR_TRUE) || mToken.mType != eCSSToken_Ident) {
|
|
|
|
break;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSCounterData *data = *next = new nsCSSCounterData();
|
|
|
|
if (!data) {
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2005-04-02 03:07:00 +04:00
|
|
|
break;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
next = &data->mNext;
|
|
|
|
data->mCounter.SetStringValue(mToken.mIdent, eCSSUnit_String);
|
|
|
|
if (GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
if (eCSSToken_Number == mToken.mType && mToken.mIntegerValid) {
|
1999-02-10 11:37:52 +03:00
|
|
|
data->mValue.SetIntValue(mToken.mInteger, eCSSUnit_Integer);
|
2005-04-02 03:07:00 +04:00
|
|
|
} else {
|
|
|
|
UngetToken();
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
mTempData.SetPropertyBit(aPropID);
|
|
|
|
*aResult = dataHead;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
delete dataHead;
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseCue(nsresult& aErrorCode)
|
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)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_cue_before, before);
|
|
|
|
AppendValue(eCSSProperty_cue_after, after);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_cue_before, before);
|
|
|
|
AppendValue(eCSSProperty_cue_after, before);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseCursor(nsresult& aErrorCode)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
2004-01-18 04:12:58 +03:00
|
|
|
nsCSSValueList *list = nsnull;
|
|
|
|
for (nsCSSValueList **curp = &list, *cur; ; curp = &cur->mNext) {
|
|
|
|
cur = *curp = new nsCSSValueList();
|
|
|
|
if (!cur) {
|
2003-06-08 02:14:42 +04:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2005-07-01 08:29:42 +04:00
|
|
|
break;
|
2003-06-08 02:14:42 +04:00
|
|
|
}
|
2004-01-18 04:12:58 +03:00
|
|
|
if (!ParseVariant(aErrorCode, cur->mValue,
|
|
|
|
(cur == list) ? VARIANT_AHUK : VARIANT_AUK,
|
|
|
|
nsCSSProps::kCursorKTable)) {
|
2005-07-01 08:29:42 +04:00
|
|
|
break;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-07-01 08:29:42 +04:00
|
|
|
if (cur->mValue.GetUnit() != eCSSUnit_URL) {
|
|
|
|
if (!ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Only success case here, since having the failure case at the
|
|
|
|
// end allows more sharing of code.
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_cursor);
|
|
|
|
mTempData.mUserInterface.mCursor = list;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// We have a URL, so make a value array with three values.
|
|
|
|
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(3);
|
|
|
|
if (!val) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2004-01-18 04:12:58 +03:00
|
|
|
break;
|
2005-07-01 08:29:42 +04:00
|
|
|
}
|
|
|
|
val->Item(0) = cur->mValue;
|
|
|
|
cur->mValue.SetArrayValue(val, eCSSUnit_Array);
|
|
|
|
|
|
|
|
// Parse optional x and y position of cursor hotspot (css3-ui).
|
|
|
|
if (ParseVariant(aErrorCode, val->Item(1), VARIANT_NUMBER, nsnull)) {
|
|
|
|
// If we have one number, we must have two.
|
|
|
|
if (!ParseVariant(aErrorCode, val->Item(2), VARIANT_NUMBER, nsnull)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-18 04:12:58 +03:00
|
|
|
if (!ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
2005-07-01 08:29:42 +04:00
|
|
|
break;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
2005-07-01 08:29:42 +04:00
|
|
|
// Have failure case at the end so we can |break| to get to it.
|
|
|
|
delete list;
|
|
|
|
return PR_FALSE;
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseFont(nsresult& aErrorCode)
|
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()) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_font_family, family);
|
|
|
|
AppendValue(eCSSProperty_font_style, family);
|
|
|
|
AppendValue(eCSSProperty_font_variant, family);
|
|
|
|
AppendValue(eCSSProperty_font_weight, family);
|
|
|
|
AppendValue(eCSSProperty_font_size, family);
|
|
|
|
AppendValue(eCSSProperty_line_height, family);
|
|
|
|
AppendValue(eCSSProperty_font_stretch, family);
|
|
|
|
AppendValue(eCSSProperty_font_size_adjust, family);
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_font_family, family); // keyword value overrides everything else
|
1999-02-27 10:15:59 +03:00
|
|
|
nsCSSValue empty;
|
2005-04-29 00:19:24 +04:00
|
|
|
// XXXbz this is actually _clearing_ the values for the following
|
|
|
|
// properties in mTempData, but setting the bit for them. We need that
|
|
|
|
// because we want to clear out the values in mData when all is said
|
|
|
|
// and done. See the code in TransferTempData that handles this. The
|
|
|
|
// end result is that mData always has its property bits set like it
|
|
|
|
// should, but mTempData can, in fact, have bits set for properties
|
|
|
|
// that are not set...
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_font_style, empty);
|
|
|
|
AppendValue(eCSSProperty_font_variant, empty);
|
|
|
|
AppendValue(eCSSProperty_font_weight, empty);
|
|
|
|
AppendValue(eCSSProperty_font_size, empty);
|
|
|
|
AppendValue(eCSSProperty_line_height, empty);
|
|
|
|
AppendValue(eCSSProperty_font_stretch, empty);
|
|
|
|
AppendValue(eCSSProperty_font_size_adjust, empty);
|
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)) {
|
2004-04-19 00:10:09 +04:00
|
|
|
if (! ParsePositiveVariant(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)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_font_family, family);
|
|
|
|
AppendValue(eCSSProperty_font_style, values[0]);
|
|
|
|
AppendValue(eCSSProperty_font_variant, values[1]);
|
|
|
|
AppendValue(eCSSProperty_font_weight, values[2]);
|
|
|
|
AppendValue(eCSSProperty_font_size, size);
|
|
|
|
AppendValue(eCSSProperty_line_height, lineHeight);
|
|
|
|
AppendValue(eCSSProperty_font_stretch, nsCSSValue(eCSSUnit_Normal));
|
|
|
|
AppendValue(eCSSProperty_font_size_adjust, nsCSSValue(eCSSUnit_None));
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseFontWeight(nsresult& aErrorCode, nsCSSValue& aValue)
|
1999-09-10 09:55:36 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseFamily(nsresult& 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) {
|
2003-11-16 04:12:50 +03:00
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
|
|
|
if (keyword == eCSSKeyword_inherit) {
|
1999-02-10 11:37:52 +03:00
|
|
|
aValue.SetInheritValue();
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2003-11-16 04:12:50 +03:00
|
|
|
else if (keyword == eCSSKeyword__moz_initial) {
|
2001-06-01 02:19:43 +04:00
|
|
|
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
|
2005-04-02 03:07:00 +04:00
|
|
|
family.Append(tk->mIdent); // XXX What if it had escaped quotes?
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseListStyle(nsresult& aErrorCode)
|
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++) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(listStyleIDs[index], values[index]);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseMargin(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kMarginSideIDs[] = {
|
|
|
|
eCSSProperty_margin_top,
|
2004-02-04 09:10:56 +03:00
|
|
|
eCSSProperty_margin_right_value,
|
1999-07-18 04:31:37 +04:00
|
|
|
eCSSProperty_margin_bottom,
|
2004-02-04 09:10:56 +03:00
|
|
|
eCSSProperty_margin_left_value
|
1998-10-27 02:22:40 +03:00
|
|
|
};
|
2004-02-04 09:10:56 +03:00
|
|
|
// do this now, in case 4 values weren't specified
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_margin_left_ltr_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_margin_left_rtl_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_margin_right_ltr_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_margin_right_rtl_source);
|
|
|
|
mTempData.mMargin.mMarginLeftLTRSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mMarginLeftRTLSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mMarginRightLTRSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mMarginRightRTLSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mMargin,
|
2003-07-01 01:39:22 +04:00
|
|
|
kMarginSideIDs);
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseMarks(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseOutline(nsresult& aErrorCode)
|
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[] = {
|
2005-03-27 15:36:08 +04:00
|
|
|
eCSSProperty_outline_color,
|
|
|
|
eCSSProperty_outline_style,
|
|
|
|
eCSSProperty_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++) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(kOutlineIDs[index], values[index]);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-09-05 04:04:04 +04:00
|
|
|
PRBool CSSParserImpl::ParseOverflow(nsresult& aErrorCode)
|
|
|
|
{
|
|
|
|
nsCSSValue overflow;
|
|
|
|
if (!ParseVariant(aErrorCode, overflow, VARIANT_AHK,
|
|
|
|
nsCSSProps::kOverflowKTable) ||
|
|
|
|
!ExpectEndProperty(aErrorCode, PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCSSValue overflowX(overflow);
|
|
|
|
nsCSSValue overflowY(overflow);
|
|
|
|
if (eCSSUnit_Enumerated == overflow.GetUnit())
|
|
|
|
switch(overflow.GetIntValue()) {
|
|
|
|
case NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL:
|
|
|
|
overflowX.SetIntValue(NS_STYLE_OVERFLOW_SCROLL, eCSSUnit_Enumerated);
|
|
|
|
overflowY.SetIntValue(NS_STYLE_OVERFLOW_HIDDEN, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL:
|
|
|
|
overflowX.SetIntValue(NS_STYLE_OVERFLOW_HIDDEN, eCSSUnit_Enumerated);
|
|
|
|
overflowY.SetIntValue(NS_STYLE_OVERFLOW_SCROLL, eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
AppendValue(eCSSProperty_overflow_x, overflowX);
|
|
|
|
AppendValue(eCSSProperty_overflow_y, overflowY);
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParsePadding(nsresult& aErrorCode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-18 04:31:37 +04:00
|
|
|
static const nsCSSProperty kPaddingSideIDs[] = {
|
|
|
|
eCSSProperty_padding_top,
|
2004-02-04 09:10:56 +03:00
|
|
|
eCSSProperty_padding_right_value,
|
1999-07-18 04:31:37 +04:00
|
|
|
eCSSProperty_padding_bottom,
|
2004-02-04 09:10:56 +03:00
|
|
|
eCSSProperty_padding_left_value
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
2004-02-04 09:10:56 +03:00
|
|
|
// do this now, in case 4 values weren't specified
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_padding_left_ltr_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_padding_left_rtl_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_padding_right_ltr_source);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_padding_right_rtl_source);
|
|
|
|
mTempData.mMargin.mPaddingLeftLTRSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mPaddingLeftRTLSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mPaddingRightLTRSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
mTempData.mMargin.mPaddingRightRTLSource.SetIntValue(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
2003-06-08 02:14:42 +04:00
|
|
|
return ParseBoxProperties(aErrorCode, mTempData.mMargin.mPadding,
|
2003-07-01 01:39:22 +04:00
|
|
|
kPaddingSideIDs);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParsePause(nsresult& aErrorCode)
|
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)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_pause_before, before);
|
|
|
|
AppendValue(eCSSProperty_pause_after, after);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
2003-07-01 01:39:22 +04:00
|
|
|
AppendValue(eCSSProperty_pause_before, before);
|
|
|
|
AppendValue(eCSSProperty_pause_after, before);
|
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
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseQuotes(nsresult& aErrorCode)
|
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)) {
|
2003-06-08 02:14:42 +04:00
|
|
|
mTempData.SetPropertyBit(eCSSProperty_quotes);
|
|
|
|
mTempData.mContent.mQuotes = quotesHead;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
// 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)) {
|
2003-06-08 02:14:42 +04:00
|
|
|
nsCSSQuotes* quotesHead = new nsCSSQuotes();
|
|
|
|
quotesHead->mOpen = open;
|
|
|
|
mTempData.mContent.mQuotes = quotesHead;
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_quotes);
|
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
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseSize(nsresult& aErrorCode)
|
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)) {
|
2004-09-10 07:26:58 +04:00
|
|
|
mTempData.mPage.mSize.mXValue = width;
|
|
|
|
mTempData.mPage.mSize.mYValue = height;
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_size);
|
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)) {
|
2004-09-10 07:26:58 +04:00
|
|
|
mTempData.mPage.mSize.SetBothValuesTo(width);
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_size);
|
1999-02-10 11:37:52 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseTextDecoration(nsresult& 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;
|
|
|
|
}
|
|
|
|
|
2003-11-14 01:48:05 +03:00
|
|
|
PRBool CSSParserImpl::ParseTextShadow(nsresult& aErrorCode)
|
1998-10-27 02:22:40 +03:00
|
|
|
{
|
2005-09-20 16:04:45 +04:00
|
|
|
nsAutoParseCompoundProperty compound(this);
|
|
|
|
|
|
|
|
// Parses x, y, radius, color (in two possible orders)
|
|
|
|
// This parses the input into a list. Either it contains just a "none" or
|
|
|
|
// "inherit" value, or a list of arrays.
|
|
|
|
// The resulting arrays will always contain the above order, with color and
|
|
|
|
// radius as null values as needed
|
|
|
|
enum {
|
|
|
|
IndexX,
|
|
|
|
IndexY,
|
|
|
|
IndexRadius,
|
|
|
|
IndexColor
|
|
|
|
};
|
|
|
|
|
|
|
|
// This variable is set to true if we already parsed an "end of property"
|
|
|
|
// token. We can't unget it, as ExpectEndProperty already ungets the token in
|
|
|
|
// some cases, and we can't detect that.
|
|
|
|
PRBool atEOP = PR_FALSE;
|
|
|
|
|
|
|
|
nsCSSValueList *list = nsnull;
|
|
|
|
for (nsCSSValueList **curp = &list, *cur; ; curp = &cur->mNext) {
|
|
|
|
cur = *curp = new nsCSSValueList();
|
|
|
|
if (!cur) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ParseVariant(aErrorCode, cur->mValue,
|
|
|
|
(cur == list) ? VARIANT_HC | VARIANT_LENGTH | VARIANT_NONE
|
|
|
|
: VARIANT_COLOR | VARIANT_LENGTH,
|
|
|
|
nsnull)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSUnit unit = cur->mValue.GetUnit();
|
|
|
|
if (unit != eCSSUnit_None && unit != eCSSUnit_Inherit &&
|
|
|
|
unit != eCSSUnit_Initial) {
|
|
|
|
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(4);
|
|
|
|
if (!val) {
|
1999-02-10 11:37:52 +03:00
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2005-09-20 16:04:45 +04:00
|
|
|
break;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
PRBool haveColor = PR_FALSE;
|
|
|
|
if (cur->mValue.IsLengthUnit()) {
|
|
|
|
val->Item(IndexX) = cur->mValue;
|
|
|
|
} else {
|
|
|
|
// Must be a color (as string or color value)
|
|
|
|
NS_ASSERTION(unit == eCSSUnit_String || unit == eCSSUnit_Color,
|
|
|
|
"Must be a color value");
|
|
|
|
haveColor = PR_TRUE;
|
|
|
|
val->Item(IndexColor) = cur->mValue;
|
|
|
|
|
|
|
|
// Parse the x coordinate
|
|
|
|
if (!ParseVariant(aErrorCode, val->Item(IndexX), VARIANT_LENGTH,
|
|
|
|
nsnull)) {
|
1999-02-10 11:37:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
}
|
|
|
|
cur->mValue.SetArrayValue(val, eCSSUnit_Array);
|
|
|
|
|
|
|
|
// Y coordinate; this one is not optional
|
|
|
|
if (!ParseVariant(aErrorCode, val->Item(IndexY), VARIANT_LENGTH, nsnull)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peek the next token to determine whether it's the radius or the color
|
|
|
|
// EOF is fine too (properties can end in EOF)
|
|
|
|
PRBool haveRadius = PR_FALSE;
|
|
|
|
if (GetToken(aErrorCode, PR_TRUE)) {
|
|
|
|
// The radius is a length, and all lengths are dimensions
|
|
|
|
haveRadius = mToken.IsDimension();
|
|
|
|
// Now unget the token, we didn't consume it
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveRadius) {
|
|
|
|
// Optional radius
|
|
|
|
if (!ParseVariant(aErrorCode, val->Item(IndexRadius), VARIANT_LENGTH,
|
|
|
|
nsnull)) {
|
|
|
|
break;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Might be at a comma now
|
|
|
|
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
|
|
|
// Go to next value
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!haveColor) {
|
|
|
|
// Now, we are either at the end of the property, or have a color (or
|
|
|
|
// have an error)
|
|
|
|
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
atEOP = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// Clear the error from ExpectEndProperty - not a real error (if we
|
|
|
|
// have a color here)
|
|
|
|
CLEAR_ERROR();
|
|
|
|
|
|
|
|
// Since we're not at the end of the property, we must have a color,
|
|
|
|
// or report an error.
|
|
|
|
if (!ParseVariant(aErrorCode, val->Item(IndexColor), VARIANT_COLOR,
|
|
|
|
nsnull)) {
|
1998-10-27 02:22:40 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
|
|
|
|
if (ExpectSymbol(aErrorCode, ',', PR_TRUE)) {
|
|
|
|
// Parse next value
|
|
|
|
continue;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
|
|
|
}
|
1998-10-27 02:22:40 +03:00
|
|
|
}
|
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
|
|
|
|
if (!atEOP && !ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
// Error
|
|
|
|
break;
|
1999-02-10 11:37:52 +03:00
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
|
|
|
|
// Only success case here, since having the failure case at the
|
|
|
|
// end allows more sharing of code.
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_text_shadow);
|
|
|
|
mTempData.mText.mTextShadow = list;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2005-09-20 16:04:45 +04:00
|
|
|
// Have failure case at the end so we can |break| to get to it.
|
|
|
|
delete list;
|
1998-10-27 02:22:40 +03:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2004-11-09 21:19:28 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
PRBool CSSParserImpl::ParseDasharray(nsresult& aErrorCode)
|
|
|
|
{
|
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(aErrorCode, value, VARIANT_HLPN | VARIANT_NONE, nsnull)) {
|
|
|
|
nsCSSValueList *listHead = new nsCSSValueList;
|
|
|
|
nsCSSValueList *list = listHead;
|
|
|
|
if (!list) {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->mValue = value;
|
|
|
|
|
2005-04-05 01:42:26 +04:00
|
|
|
for (;;) {
|
2004-11-09 21:19:28 +03:00
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
mTempData.SetPropertyBit(eCSSProperty_stroke_dasharray);
|
|
|
|
mTempData.mSVG.mStrokeDasharray = listHead;
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSUnit_Inherit == value.GetUnit() ||
|
2005-04-05 01:42:26 +04:00
|
|
|
eCSSUnit_Initial == value.GetUnit() ||
|
|
|
|
eCSSUnit_None == value.GetUnit())
|
|
|
|
break;
|
2004-11-09 21:19:28 +03:00
|
|
|
|
|
|
|
if (!ExpectSymbol(aErrorCode, ',', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
2005-04-05 01:42:26 +04:00
|
|
|
if (!ParseVariant(aErrorCode, value,
|
|
|
|
VARIANT_LENGTH | VARIANT_PERCENT | VARIANT_NUMBER,
|
|
|
|
nsnull))
|
|
|
|
break;
|
|
|
|
|
|
|
|
list->mNext = new nsCSSValueList;
|
|
|
|
list = list->mNext;
|
|
|
|
if (list)
|
|
|
|
list->mValue = value;
|
|
|
|
else {
|
|
|
|
aErrorCode = NS_ERROR_OUT_OF_MEMORY;
|
2004-11-09 21:19:28 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete listHead;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-12-09 06:16:15 +03:00
|
|
|
|
|
|
|
PRBool CSSParserImpl::ParseMarker(nsresult& aErrorCode)
|
|
|
|
{
|
|
|
|
nsCSSValue marker;
|
|
|
|
if (ParseSingleValueProperty(aErrorCode, marker, eCSSProperty_marker_end)) {
|
|
|
|
if (ExpectEndProperty(aErrorCode, PR_TRUE)) {
|
|
|
|
AppendValue(eCSSProperty_marker_end, marker);
|
|
|
|
AppendValue(eCSSProperty_marker_mid, marker);
|
|
|
|
AppendValue(eCSSProperty_marker_start, marker);
|
|
|
|
aErrorCode = NS_OK;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-11-09 21:19:28 +03:00
|
|
|
#endif
|