2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* emk <VYV03354@nifty.ne.jp>
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>
|
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
|
|
|
* Christian Biesinger <cbiesinger@web.de>
|
2009-05-28 11:09:05 -07:00
|
|
|
* Jeff Walden <jwalden+code@mit.edu>
|
2009-08-20 14:52:47 -07:00
|
|
|
* Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>, Collabora Ltd.
|
|
|
|
* Siraj Razick <siraj.razick@collabora.co.uk>, Collabora Ltd.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
#include "nsCSSParser.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "nsCSSKeywords.h"
|
|
|
|
#include "nsCSSScanner.h"
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Loader.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsICSSStyleRule.h"
|
|
|
|
#include "nsICSSImportRule.h"
|
|
|
|
#include "nsCSSRules.h"
|
|
|
|
#include "nsICSSNameSpaceRule.h"
|
|
|
|
#include "nsIUnicharInputStream.h"
|
2010-05-11 13:41:47 -07:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsCSSPseudoClasses.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsXMLNameSpaceMap.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsContentErrors.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsIMediaList.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsStyleUtil.h"
|
2007-05-02 18:15:53 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "math.h"
|
2008-07-21 17:55:52 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMError.h"
|
2008-09-13 02:42:11 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsTArray.h"
|
2009-02-19 21:29:21 -08:00
|
|
|
#include "prlog.h"
|
2010-05-11 08:49:43 -07:00
|
|
|
#include "CSSCalc.h"
|
2010-05-11 13:41:47 -07:00
|
|
|
#include "nsMediaFeatures.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
// Flags for ParseVariant method
|
|
|
|
#define VARIANT_KEYWORD 0x000001 // K
|
|
|
|
#define VARIANT_LENGTH 0x000002 // L
|
|
|
|
#define VARIANT_PERCENT 0x000004 // P
|
2009-03-05 20:05:01 -08:00
|
|
|
#define VARIANT_COLOR 0x000008 // C eCSSUnit_Color, eCSSUnit_Ident (e.g. "red")
|
2008-07-26 09:14:48 -07: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
|
2008-09-09 21:38:14 -07:00
|
|
|
#define VARIANT_COUNTER 0x000800 //
|
2008-07-26 09:14:48 -07:00
|
|
|
#define VARIANT_ATTR 0x001000 //
|
|
|
|
#define VARIANT_IDENTIFIER 0x002000 // D
|
|
|
|
#define VARIANT_AUTO 0x010000 // A
|
|
|
|
#define VARIANT_INHERIT 0x020000 // H eCSSUnit_Initial, eCSSUnit_Inherit
|
|
|
|
#define VARIANT_NONE 0x040000 // O
|
|
|
|
#define VARIANT_NORMAL 0x080000 // M
|
|
|
|
#define VARIANT_SYSFONT 0x100000 // eCSSUnit_System_Font
|
2009-08-01 08:53:40 -07:00
|
|
|
#define VARIANT_GRADIENT 0x200000 // eCSSUnit_Gradient
|
2009-08-20 14:52:47 -07:00
|
|
|
#define VARIANT_CUBIC_BEZIER 0x400000 // CSS transition timing function
|
|
|
|
#define VARIANT_ALL 0x800000 //
|
2009-08-21 13:39:25 -07:00
|
|
|
#define VARIANT_IMAGE_RECT 0x01000000 // eCSSUnit_Function
|
2009-11-04 18:36:18 -08:00
|
|
|
// This is an extra bit that says that a VARIANT_ANGLE allows unitless zero:
|
|
|
|
#define VARIANT_ZERO_ANGLE 0x02000000 // unitless zero for angles
|
2010-05-11 08:49:43 -07:00
|
|
|
#define VARIANT_CALC 0x04000000 // eCSSUnit_Calc
|
2010-07-02 21:18:56 -07:00
|
|
|
#define VARIANT_CALC_NO_MIN_MAX 0x08000000 // no min() and max() for calc()
|
2010-08-13 06:33:37 -07:00
|
|
|
#define VARIANT_ELEMENT 0x10000000 // eCSSUnit_Element
|
2008-07-26 09:14:48 -07:00
|
|
|
|
|
|
|
// Common combinations of variants
|
|
|
|
#define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH)
|
|
|
|
#define VARIANT_LP (VARIANT_LENGTH | VARIANT_PERCENT)
|
|
|
|
#define VARIANT_AH (VARIANT_AUTO | VARIANT_INHERIT)
|
|
|
|
#define VARIANT_AHLP (VARIANT_AH | VARIANT_LP)
|
|
|
|
#define VARIANT_AHI (VARIANT_AH | VARIANT_INTEGER)
|
|
|
|
#define VARIANT_AHK (VARIANT_AH | VARIANT_KEYWORD)
|
|
|
|
#define VARIANT_AHKLP (VARIANT_AHLP | VARIANT_KEYWORD)
|
|
|
|
#define VARIANT_AHL (VARIANT_AH | VARIANT_LENGTH)
|
|
|
|
#define VARIANT_AHKL (VARIANT_AHK | VARIANT_LENGTH)
|
|
|
|
#define VARIANT_HK (VARIANT_INHERIT | VARIANT_KEYWORD)
|
|
|
|
#define VARIANT_HKF (VARIANT_HK | VARIANT_FREQUENCY)
|
2009-11-14 19:16:59 -08:00
|
|
|
#define VARIANT_HKI (VARIANT_HK | VARIANT_INTEGER)
|
2008-07-26 09:14:48 -07:00
|
|
|
#define VARIANT_HKL (VARIANT_HK | VARIANT_LENGTH)
|
|
|
|
#define VARIANT_HKLP (VARIANT_HK | VARIANT_LP)
|
|
|
|
#define VARIANT_HKLPO (VARIANT_HKLP | VARIANT_NONE)
|
|
|
|
#define VARIANT_HL (VARIANT_INHERIT | VARIANT_LENGTH)
|
|
|
|
#define VARIANT_HI (VARIANT_INHERIT | VARIANT_INTEGER)
|
|
|
|
#define VARIANT_HLP (VARIANT_HL | VARIANT_PERCENT)
|
|
|
|
#define VARIANT_HLPN (VARIANT_HLP | VARIANT_NUMBER)
|
|
|
|
#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_HC (VARIANT_INHERIT | VARIANT_COLOR)
|
|
|
|
#define VARIANT_HCK (VARIANT_HK | VARIANT_COLOR)
|
2009-10-21 14:57:57 -07:00
|
|
|
#define VARIANT_HUK (VARIANT_HK | VARIANT_URL)
|
2008-07-26 09:14:48 -07:00
|
|
|
#define VARIANT_HUO (VARIANT_INHERIT | VARIANT_URL | VARIANT_NONE)
|
|
|
|
#define VARIANT_AHUO (VARIANT_AUTO | VARIANT_HUO)
|
|
|
|
#define VARIANT_HPN (VARIANT_INHERIT | VARIANT_PERCENT | VARIANT_NUMBER)
|
|
|
|
#define VARIANT_HN (VARIANT_INHERIT | VARIANT_NUMBER)
|
|
|
|
#define VARIANT_HON (VARIANT_HN | VARIANT_NONE)
|
|
|
|
#define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING)
|
2009-08-20 14:52:47 -07:00
|
|
|
#define VARIANT_TIMING_FUNCTION (VARIANT_KEYWORD | VARIANT_CUBIC_BEZIER)
|
2009-10-21 14:57:57 -07:00
|
|
|
#define VARIANT_UK (VARIANT_URL | VARIANT_KEYWORD)
|
2010-08-19 12:33:44 -07:00
|
|
|
#define VARIANT_UO (VARIANT_URL | VARIANT_NONE)
|
2009-11-04 18:36:18 -08:00
|
|
|
#define VARIANT_ANGLE_OR_ZERO (VARIANT_ANGLE | VARIANT_ZERO_ANGLE)
|
2010-07-02 21:18:56 -07:00
|
|
|
#define VARIANT_TRANSFORM_LPCALC (VARIANT_LP | VARIANT_CALC | \
|
|
|
|
VARIANT_CALC_NO_MIN_MAX)
|
2010-08-13 06:33:37 -07:00
|
|
|
#define VARIANT_IMAGE (VARIANT_URL | VARIANT_NONE | VARIANT_GRADIENT | \
|
|
|
|
VARIANT_IMAGE_RECT | VARIANT_ELEMENT)
|
2008-07-26 09:14:48 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Rule processing function
|
|
|
|
typedef void (* RuleAppendFunc) (nsICSSRule* aRule, void* aData);
|
|
|
|
static void AppendRuleToArray(nsICSSRule* aRule, void* aArray);
|
|
|
|
static void AppendRuleToSheet(nsICSSRule* aRule, void* aParser);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Your basic top-down recursive descent style parser
|
2010-03-02 12:59:32 -08:00
|
|
|
// The exposed methods and members of this class are precisely those
|
|
|
|
// needed by nsCSSParser, far below.
|
|
|
|
class CSSParserImpl {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
CSSParserImpl();
|
2010-03-02 12:59:32 -08:00
|
|
|
~CSSParserImpl();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult SetQuirkMode(PRBool aQuirkMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult SetSVGMode(PRBool aSVGMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2010-03-02 13:00:53 -08:00
|
|
|
nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
// Clears everything set by the above Set*() functions.
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
nsresult Parse(nsIUnicharInputStream* aInput,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
PRBool aAllowUnsafeRules);
|
|
|
|
|
|
|
|
nsresult ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aNodePrincipal,
|
|
|
|
nsICSSStyleRule** aResult);
|
|
|
|
|
2010-07-23 11:00:19 -07:00
|
|
|
nsresult ParseDeclarations(const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
css::Declaration* aDeclaration,
|
|
|
|
PRBool* aChanged);
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
nsresult ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCOMArray<nsICSSRule>& aResult);
|
|
|
|
|
|
|
|
nsresult ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* aDeclaration,
|
2010-04-01 23:07:40 -07:00
|
|
|
PRBool* aChanged,
|
|
|
|
PRBool aIsImportant);
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
nsresult ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode);
|
|
|
|
|
|
|
|
nsresult ParseColorString(const nsSubstring& aBuffer,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
2010-03-02 12:59:32 -08:00
|
|
|
nscolor* aColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult ParseSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL, // for error reporting
|
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsCSSSelectorList **aSelectorList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
class nsAutoParseCompoundProperty;
|
|
|
|
friend class nsAutoParseCompoundProperty;
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
void AppendRule(nsICSSRule* aRule);
|
|
|
|
friend void AppendRuleToSheet(nsICSSRule*, void*); // calls AppendRule
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2007-06-12 11:28:56 -07:00
|
|
|
NS_ASSERTION(!aParser->IsParsingCompoundProperty(),
|
|
|
|
"already parsing compound property");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aParser, "Null parser?");
|
|
|
|
aParser->SetParsingCompoundProperty(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsAutoParseCompoundProperty()
|
|
|
|
{
|
|
|
|
mParser->SetParsingCompoundProperty(PR_FALSE);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
CSSParserImpl* mParser;
|
|
|
|
};
|
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
void InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
// the caller must hold on to aBuffer until parsing is done
|
2008-09-09 21:38:26 -07:00
|
|
|
void InitScanner(const nsSubstring& aString, nsIURI* aSheetURI,
|
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal);
|
|
|
|
void ReleaseScanner(void);
|
2008-08-12 07:02:22 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
PRBool IsSVGMode() const {
|
|
|
|
return mScanner.IsSVGMode();
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool GetToken(PRBool aSkipWS);
|
2007-03-22 10:30:00 -07:00
|
|
|
void UngetToken();
|
|
|
|
|
2009-08-05 17:45:49 -07:00
|
|
|
// get the part in paretheses of the url() function, which is really a
|
|
|
|
// part of a token in the CSS grammar, but we're using a combination
|
|
|
|
// of the parser and the scanner to do it to handle the backtracking
|
|
|
|
// required by the error handling of the tokenization (since if we
|
|
|
|
// fail to scan the full token, we should fall back to tokenizing as
|
|
|
|
// FUNCTION ... ')').
|
|
|
|
// Note that this function WILL WRITE TO aURL IN SOME FAILURE CASES.
|
|
|
|
PRBool GetURLInParens(nsString& aURL);
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
void AssertInitialState() {
|
|
|
|
NS_PRECONDITION(!mHTMLMediaMode, "Bad initial state");
|
|
|
|
NS_PRECONDITION(!mParsingCompoundProperty, "Bad initial state");
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ExpectSymbol(PRUnichar aSymbol, PRBool aSkipWS);
|
|
|
|
PRBool ExpectEndProperty();
|
2008-09-13 02:42:11 -07:00
|
|
|
PRBool CheckEndProperty();
|
2008-09-09 21:38:14 -07:00
|
|
|
nsSubstring* NextIdent();
|
|
|
|
void SkipUntil(PRUnichar aStopSymbol);
|
2008-11-02 11:44:56 -08:00
|
|
|
void SkipUntilOneOf(const PRUnichar* aStopSymbolChars);
|
2009-08-19 06:11:30 -07:00
|
|
|
void SkipRuleSet(PRBool aInsideBraces);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool SkipAtRule();
|
|
|
|
PRBool SkipDeclaration(PRBool aCheckForBraces);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool PushGroup(nsICSSGroupRule* aRule);
|
|
|
|
void PopGroup(void);
|
|
|
|
|
2009-08-19 06:11:30 -07:00
|
|
|
PRBool ParseRuleSet(RuleAppendFunc aAppendFunc, void* aProcessData,
|
|
|
|
PRBool aInsideBraces = PR_FALSE);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseAtRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseCharsetRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseImportRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool GatherURL(nsString& aURL);
|
|
|
|
PRBool GatherMedia(nsMediaList* aMedia,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUnichar aStopSymbol);
|
2008-10-11 17:49:42 -07:00
|
|
|
PRBool ParseMediaQuery(PRUnichar aStopSymbol, nsMediaQuery **aQuery,
|
|
|
|
PRBool *aParsedSomething, PRBool *aHitStop);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseMediaQueryExpression(nsMediaQuery* aQuery);
|
2010-02-17 13:02:56 -08:00
|
|
|
void ProcessImport(const nsString& aURLSpec,
|
|
|
|
nsMediaList* aMedia,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseGroupRule(nsICSSGroupRule* aRule, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
|
|
|
PRBool ParseMediaRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseMozDocumentRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseNameSpaceRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
2010-02-17 13:02:56 -08:00
|
|
|
void ProcessNameSpace(const nsString& aPrefix,
|
|
|
|
const nsString& aURLSpec, RuleAppendFunc aAppendFunc,
|
|
|
|
void* aProcessData);
|
2008-08-10 14:13:49 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseFontFaceRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
|
|
|
PRBool ParseFontDescriptor(nsCSSFontFaceRule* aRule);
|
|
|
|
PRBool ParseFontDescriptorValue(nsCSSFontDesc aDescID,
|
2008-08-10 14:13:49 -07:00
|
|
|
nsCSSValue& aValue);
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParsePageRule(RuleAppendFunc aAppendFunc, void* aProcessData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
enum nsSelectorParsingStatus {
|
2008-09-09 21:38:14 -07:00
|
|
|
// we have parsed a selector and we saw a token that cannot be
|
|
|
|
// part of a selector:
|
2007-03-22 10:30:00 -07:00
|
|
|
eSelectorParsingStatus_Done,
|
|
|
|
// we should continue parsing the selector:
|
|
|
|
eSelectorParsingStatus_Continue,
|
|
|
|
// we saw an unexpected token or token value,
|
|
|
|
// or we saw end-of-file with an unfinished selector:
|
2008-09-09 21:38:14 -07:00
|
|
|
eSelectorParsingStatus_Error
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
nsSelectorParsingStatus ParseIDSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseClassSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
// aPseudoElement and aPseudoElementArgs are the location where
|
|
|
|
// pseudo-elements (as opposed to pseudo-classes) are stored;
|
|
|
|
// pseudo-classes are stored on aSelector. aPseudoElement and
|
|
|
|
// aPseudoElementArgs must be non-null iff !aIsNegated.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSelectorParsingStatus ParsePseudoSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
2009-10-07 20:22:42 -07:00
|
|
|
PRBool aIsNegated,
|
|
|
|
nsIAtom** aPseudoElement,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsPseudoClassList** aPseudoElementArgs,
|
|
|
|
nsCSSPseudoElements::Type* aPseudoElementType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseAttributeSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSelectorParsingStatus ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRBool aIsNegated);
|
|
|
|
|
|
|
|
nsSelectorParsingStatus ParsePseudoClassWithIdentArg(nsCSSSelector& aSelector,
|
2009-12-10 23:37:41 -08:00
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
nsSelectorParsingStatus ParsePseudoClassWithNthPairArg(nsCSSSelector& aSelector,
|
2009-12-10 23:37:41 -08:00
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType);
|
2008-06-02 20:17:35 -07:00
|
|
|
|
2010-04-23 19:59:47 -07:00
|
|
|
nsSelectorParsingStatus ParsePseudoClassWithSelectorListArg(nsCSSSelector& aSelector,
|
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSelectorParsingStatus ParseNegatedSimpleSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-23 19:59:47 -07:00
|
|
|
// If aStopChar is non-zero, the selector list is done when we hit
|
|
|
|
// aStopChar. Otherwise, it's done when we hit EOF.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseSelectorList(nsCSSSelectorList*& aListHead,
|
2010-04-23 19:59:47 -07:00
|
|
|
PRUnichar aStopChar);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseSelectorGroup(nsCSSSelectorList*& aListHead);
|
2010-03-31 11:08:11 -07:00
|
|
|
PRBool ParseSelector(nsCSSSelectorList* aList, PRUnichar aPrevCombinator);
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* ParseDeclarationBlock(PRBool aCheckForBraces);
|
|
|
|
PRBool ParseDeclaration(css::Declaration* aDeclaration,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aCheckForBraces,
|
|
|
|
PRBool aMustCallValueAppended,
|
|
|
|
PRBool* aChanged);
|
2010-07-23 11:00:42 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseProperty(nsCSSProperty aPropID);
|
|
|
|
PRBool ParseSingleValueProperty(nsCSSValue& aValue,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProperty aPropID);
|
|
|
|
|
2010-07-23 11:00:37 -07:00
|
|
|
enum PriorityParsingStatus {
|
|
|
|
ePriority_None,
|
|
|
|
ePriority_Important,
|
|
|
|
ePriority_Error
|
|
|
|
};
|
|
|
|
PriorityParsingStatus ParsePriority();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XUL
|
2009-10-07 20:22:42 -07:00
|
|
|
PRBool ParseTreePseudoElement(nsPseudoClassList **aPseudoElementArgs);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-07-04 11:51:16 -07:00
|
|
|
void InitBoxPropsAsPhysical(const nsCSSProperty *aSourceProperties);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Property specific parsing routines
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseAzimuth(nsCSSValue& aValue);
|
|
|
|
PRBool ParseBackground();
|
2009-02-19 21:29:21 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
struct BackgroundParseState {
|
|
|
|
nsCSSValue& mColor;
|
|
|
|
nsCSSValueList* mImage;
|
|
|
|
nsCSSValueList* mRepeat;
|
|
|
|
nsCSSValueList* mAttachment;
|
|
|
|
nsCSSValueList* mClip;
|
|
|
|
nsCSSValueList* mOrigin;
|
|
|
|
nsCSSValuePairList* mPosition;
|
|
|
|
nsCSSValuePairList* mSize;
|
2009-02-19 21:29:21 -08:00
|
|
|
};
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseBackgroundItem(BackgroundParseState& aState);
|
2009-02-19 21:29:21 -08:00
|
|
|
|
|
|
|
PRBool ParseBackgroundList(nsCSSProperty aPropID); // a single value prop-id
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseBackgroundPosition();
|
2009-08-01 08:53:40 -07:00
|
|
|
PRBool ParseBoxPositionValues(nsCSSValuePair& aOut, PRBool aAcceptsInherit);
|
2009-05-28 11:09:05 -07:00
|
|
|
PRBool ParseBackgroundSize();
|
|
|
|
PRBool ParseBackgroundSizeValues(nsCSSValuePair& aOut);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseBorderColor();
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseBorderColors(nsCSSProperty aProperty);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseBorderImage();
|
|
|
|
PRBool ParseBorderSpacing();
|
|
|
|
PRBool ParseBorderSide(const nsCSSProperty aPropIDs[],
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aSetAllSides);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseDirectionalBorderSide(const nsCSSProperty aPropIDs[],
|
2007-07-04 11:51:16 -07:00
|
|
|
PRInt32 aSourceType);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseBorderStyle();
|
|
|
|
PRBool ParseBorderWidth();
|
2010-05-11 08:49:43 -07:00
|
|
|
|
|
|
|
PRBool ParseCalc(nsCSSValue &aValue, PRInt32 aVariantMask);
|
|
|
|
PRBool ParseCalcAdditiveExpression(nsCSSValue& aValue,
|
|
|
|
PRInt32& aVariantMask);
|
|
|
|
PRBool ParseCalcMultiplicativeExpression(nsCSSValue& aValue,
|
|
|
|
PRInt32& aVariantMask,
|
|
|
|
PRBool *aHadFinalWS);
|
|
|
|
PRBool ParseCalcTerm(nsCSSValue& aValue, PRInt32& aVariantMask);
|
|
|
|
PRBool ParseCalcMinMax(nsCSSValue& aValue, nsCSSUnit aUnit,
|
|
|
|
PRInt32& aVariantMask);
|
|
|
|
PRBool RequireWhitespace();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// for 'clip' and '-moz-image-region'
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseRect(nsCSSProperty aPropID);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseContent();
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseCounterData(nsCSSProperty aPropID);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseCue();
|
|
|
|
PRBool ParseCursor();
|
|
|
|
PRBool ParseFont();
|
|
|
|
PRBool ParseFontWeight(nsCSSValue& aValue);
|
|
|
|
PRBool ParseOneFamily(nsAString& aValue);
|
|
|
|
PRBool ParseFamily(nsCSSValue& aValue);
|
|
|
|
PRBool ParseFontSrc(nsCSSValue& aValue);
|
|
|
|
PRBool ParseFontSrcFormat(nsTArray<nsCSSValue>& values);
|
|
|
|
PRBool ParseFontRanges(nsCSSValue& aValue);
|
|
|
|
PRBool ParseListStyle();
|
|
|
|
PRBool ParseMargin();
|
|
|
|
PRBool ParseMarks(nsCSSValue& aValue);
|
2008-09-13 02:42:11 -07:00
|
|
|
PRBool ParseMozTransform();
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseOutline();
|
|
|
|
PRBool ParseOverflow();
|
|
|
|
PRBool ParsePadding();
|
|
|
|
PRBool ParsePause();
|
|
|
|
PRBool ParseQuotes();
|
|
|
|
PRBool ParseSize();
|
|
|
|
PRBool ParseTextDecoration(nsCSSValue& aValue);
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseShadowItem(nsCSSValue& aValue, PRBool aIsBoxShadow);
|
|
|
|
PRBool ParseShadowList(nsCSSProperty aProperty);
|
2009-08-20 14:52:47 -07:00
|
|
|
PRBool ParseTransitionTime(nsCSSProperty aPropID);
|
|
|
|
PRBool ParseTransitionProperty();
|
|
|
|
PRBool ParseTransition();
|
|
|
|
PRBool ParseTransitionTimingFunction();
|
|
|
|
PRBool ParseTransitionTimingFunctionValues(nsCSSValue& aValue);
|
2010-08-11 12:32:52 -07:00
|
|
|
PRBool ParseTransitionTimingFunctionValueComponent(float& aComponent,
|
|
|
|
char aStop,
|
|
|
|
PRBool aCheckRange);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParsePaint(nsCSSProperty aPropID);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseDasharray();
|
|
|
|
PRBool ParseMarker();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Reused utility parsing routines
|
|
|
|
void AppendValue(nsCSSProperty aPropID, const nsCSSValue& aValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseBoxProperties(const nsCSSProperty aPropIDs[]);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseDirectionalBoxProperty(nsCSSProperty aProperty,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aSourceType);
|
2008-09-30 22:50:52 -07:00
|
|
|
PRBool ParseBoxCornerRadius(const nsCSSProperty aPropID);
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseBoxCornerRadii(const nsCSSProperty aPropIDs[]);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32 ParseChoice(nsCSSValue aValues[],
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsCSSProperty aPropIDs[], PRInt32 aNumIDs);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseColor(nsCSSValue& aValue);
|
|
|
|
PRBool ParseColorComponent(PRUint8& aComponent,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32& aType, char aStop);
|
2008-09-09 21:38:14 -07:00
|
|
|
// ParseHSLColor parses everything starting with the opening '('
|
|
|
|
// up through and including the aStop char.
|
|
|
|
PRBool ParseHSLColor(nscolor& aColor, char aStop);
|
|
|
|
// ParseColorOpacity will enforce that the color ends with a ')'
|
|
|
|
// after the opacity
|
|
|
|
PRBool ParseColorOpacity(PRUint8& aOpacity);
|
|
|
|
PRBool ParseEnum(nsCSSValue& aValue, const PRInt32 aKeywordTable[]);
|
|
|
|
PRBool ParseVariant(nsCSSValue& aValue,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[]);
|
2009-03-09 16:14:34 -07:00
|
|
|
PRBool ParseNonNegativeVariant(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[]);
|
2009-03-09 16:14:34 -07:00
|
|
|
PRBool ParsePositiveNonZeroVariant(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[]);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseCounter(nsCSSValue& aValue);
|
|
|
|
PRBool ParseAttr(nsCSSValue& aValue);
|
2009-08-21 13:39:25 -07:00
|
|
|
PRBool SetValueToURL(nsCSSValue& aValue, const nsString& aURL);
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool ParseURL(nsCSSValue& aValue);
|
|
|
|
PRBool TranslateDimension(nsCSSValue& aValue, PRInt32 aVariantMask,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aNumber, const nsString& aUnit);
|
2009-08-21 13:39:25 -07:00
|
|
|
PRBool ParseImageRect(nsCSSValue& aImage);
|
2010-08-13 06:33:37 -07:00
|
|
|
PRBool ParseElement(nsCSSValue& aValue);
|
2009-11-02 11:36:43 -08:00
|
|
|
PRBool ParseColorStop(nsCSSValueGradient* aGradient);
|
|
|
|
PRBool ParseGradient(nsCSSValue& aValue, PRBool aIsRadial,
|
|
|
|
PRBool aIsRepeating);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void SetParsingCompoundProperty(PRBool aBool) {
|
|
|
|
NS_ASSERTION(aBool == PR_TRUE || aBool == PR_FALSE, "bad PRBool value");
|
|
|
|
mParsingCompoundProperty = aBool;
|
|
|
|
}
|
|
|
|
PRBool IsParsingCompoundProperty(void) const {
|
|
|
|
return mParsingCompoundProperty;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
/* Functions for -moz-transform Parsing */
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool ParseSingleTransform(nsCSSValue& aValue);
|
2008-09-13 02:42:11 -07:00
|
|
|
PRBool ParseFunction(const nsString &aFunction, const PRInt32 aAllowedTypes[],
|
|
|
|
PRUint16 aMinElems, PRUint16 aMaxElems,
|
|
|
|
nsCSSValue &aValue);
|
|
|
|
PRBool ParseFunctionInternals(const PRInt32 aVariantMask[],
|
|
|
|
PRUint16 aMinElems,
|
|
|
|
PRUint16 aMaxElems,
|
|
|
|
nsTArray<nsCSSValue>& aOutput);
|
|
|
|
|
|
|
|
/* Functions for -moz-transform-origin Parsing */
|
|
|
|
PRBool ParseMozTransformOrigin();
|
|
|
|
|
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
/* Find and return the namespace ID associated with aPrefix.
|
|
|
|
If aPrefix has not been declared in an @namespace rule, returns
|
|
|
|
kNameSpaceID_Unknown and sets mFoundUnresolvablePrefix to true. */
|
|
|
|
PRInt32 GetNamespaceIdForPrefix(const nsString& aPrefix);
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
/* Find the correct default namespace, and set it on aSelector. */
|
|
|
|
void SetDefaultNamespaceOnSelector(nsCSSSelector& aSelector);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Current token. The value is valid after calling GetToken and invalidated
|
|
|
|
// by UngetToken.
|
|
|
|
nsCSSToken mToken;
|
|
|
|
|
|
|
|
// Our scanner.
|
|
|
|
nsCSSScanner mScanner;
|
|
|
|
|
|
|
|
// The URI to be used as a base for relative URIs.
|
2010-03-02 12:59:32 -08:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The URI to be used as an HTTP "Referer" and for error reporting.
|
2010-03-02 12:59:32 -08:00
|
|
|
nsCOMPtr<nsIURI> mSheetURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-02 18:15:53 -07:00
|
|
|
// The principal of the sheet involved
|
|
|
|
nsCOMPtr<nsIPrincipal> mSheetPrincipal;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// The sheet we're parsing into
|
2010-05-11 13:41:47 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet> mSheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Used for @import rules
|
2010-03-02 13:00:53 -08:00
|
|
|
mozilla::css::Loader* mChildLoader; // not ref counted, it owns us
|
2007-03-22 10:30:00 -07: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
|
2008-09-09 11:08:11 -07:00
|
|
|
// anything else). Note that there are checks of similar things in various
|
|
|
|
// places in nsCSSStyleSheet.cpp (e.g in insertRule, RebuildChildList).
|
2008-09-09 21:38:14 -07:00
|
|
|
enum nsCSSSection {
|
|
|
|
eCSSSection_Charset,
|
|
|
|
eCSSSection_Import,
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSSection_NameSpace,
|
2008-09-09 21:38:14 -07:00
|
|
|
eCSSSection_General
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
nsCSSSection mSection;
|
|
|
|
|
|
|
|
nsXMLNameSpaceMap *mNameSpaceMap; // weak, mSheet owns it
|
|
|
|
|
|
|
|
// After an UngetToken is done this flag is true. The next call to
|
|
|
|
// GetToken clears the flag.
|
|
|
|
PRPackedBool mHavePushBack : 1;
|
|
|
|
|
|
|
|
// True if we are in quirks mode; false in standards or almost standards mode
|
|
|
|
PRPackedBool mNavQuirkMode : 1;
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// True if unsafe rules should be allowed
|
|
|
|
PRPackedBool mUnsafeRulesEnabled : 1;
|
|
|
|
|
|
|
|
// True for parsing media lists for HTML attributes, where we have to
|
|
|
|
// ignore CSS comments.
|
|
|
|
PRPackedBool mHTMLMediaMode : 1;
|
|
|
|
|
|
|
|
// This flag is set when parsing a non-box shorthand; it's used to not apply
|
|
|
|
// some quirks during shorthand parsing
|
|
|
|
PRPackedBool mParsingCompoundProperty : 1;
|
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
// GetNamespaceIdForPrefix will set mFoundUnresolvablePrefix to true
|
|
|
|
// when it encounters a prefix that is not mapped to a namespace.
|
|
|
|
PRPackedBool mFoundUnresolvablePrefix : 1;
|
2008-07-21 17:55:52 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRPackedBool mScannerInited : 1;
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Stack of rule groups; used for @media and such.
|
|
|
|
nsCOMArray<nsICSSGroupRule> mGroupStack;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
public:
|
|
|
|
// Used from nsCSSParser constructors and destructors
|
|
|
|
CSSParserImpl* mNextFree;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void AppendRuleToArray(nsICSSRule* aRule, void* aArray)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(aRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void AppendRuleToSheet(nsICSSRule* aRule, void* aParser)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
CSSParserImpl* parser = (CSSParserImpl*) aParser;
|
|
|
|
parser->AppendRule(aRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CSS_REPORT_PARSE_ERRORS
|
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED(msg_) \
|
|
|
|
mScanner.ReportUnexpected(#msg_)
|
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_P(msg_, params_) \
|
|
|
|
mScanner.ReportUnexpectedParams(#msg_, params_, NS_ARRAY_LENGTH(params_))
|
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_) \
|
|
|
|
mScanner.ReportUnexpectedEOF(#lf_)
|
|
|
|
|
2008-07-19 15:52:09 -07:00
|
|
|
#define REPORT_UNEXPECTED_EOF_CHAR(ch_) \
|
|
|
|
mScanner.ReportUnexpectedEOF(ch_)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define REPORT_UNEXPECTED_TOKEN(msg_) \
|
|
|
|
mScanner.ReportUnexpectedToken(mToken, #msg_)
|
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN_P(msg_, params_) \
|
|
|
|
mScanner.ReportUnexpectedTokenParams(mToken, #msg_, \
|
|
|
|
params_, NS_ARRAY_LENGTH(params_))
|
|
|
|
|
|
|
|
|
|
|
|
#define OUTPUT_ERROR() \
|
|
|
|
mScanner.OutputError()
|
|
|
|
|
|
|
|
#define CLEAR_ERROR() \
|
|
|
|
mScanner.ClearError()
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define REPORT_UNEXPECTED(msg_)
|
|
|
|
#define REPORT_UNEXPECTED_P(msg_, params_)
|
|
|
|
#define REPORT_UNEXPECTED_EOF(lf_)
|
2008-07-19 15:52:09 -07:00
|
|
|
#define REPORT_UNEXPECTED_EOF_CHAR(ch_)
|
2007-03-22 10:30:00 -07:00
|
|
|
#define REPORT_UNEXPECTED_TOKEN(msg_)
|
|
|
|
#define REPORT_UNEXPECTED_TOKEN_P(msg_, params_)
|
|
|
|
#define OUTPUT_ERROR()
|
|
|
|
#define CLEAR_ERROR()
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CSSParserImpl::CSSParserImpl()
|
|
|
|
: mToken(),
|
|
|
|
mScanner(),
|
|
|
|
mChildLoader(nsnull),
|
|
|
|
mSection(eCSSSection_Charset),
|
|
|
|
mNameSpaceMap(nsnull),
|
|
|
|
mHavePushBack(PR_FALSE),
|
|
|
|
mNavQuirkMode(PR_FALSE),
|
|
|
|
mUnsafeRulesEnabled(PR_FALSE),
|
|
|
|
mHTMLMediaMode(PR_FALSE),
|
2008-07-21 17:55:52 -07:00
|
|
|
mParsingCompoundProperty(PR_FALSE),
|
2010-03-05 10:43:50 -08:00
|
|
|
mFoundUnresolvablePrefix(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mScannerInited(PR_FALSE)
|
|
|
|
#endif
|
2010-03-02 12:59:32 -08:00
|
|
|
, mNextFree(nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSParserImpl::~CSSParserImpl()
|
|
|
|
{
|
|
|
|
mData.AssertInitialState();
|
|
|
|
mTempData.AssertInitialState();
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2010-05-11 13:41:47 -07:00
|
|
|
CSSParserImpl::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aSheet != mSheet) {
|
2008-02-14 20:21:57 -08:00
|
|
|
// Switch to using the new sheet, if any
|
2007-03-22 10:30:00 -07:00
|
|
|
mGroupStack.Clear();
|
|
|
|
mSheet = aSheet;
|
2008-02-14 20:21:57 -08:00
|
|
|
if (mSheet) {
|
|
|
|
mNameSpaceMap = mSheet->GetNameSpaceMap();
|
|
|
|
} else {
|
|
|
|
mNameSpaceMap = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::SetQuirkMode(PRBool aQuirkMode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aQuirkMode == PR_TRUE || aQuirkMode == PR_FALSE, "bad PRBool value");
|
|
|
|
mNavQuirkMode = aQuirkMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::SetSVGMode(PRBool aSVGMode)
|
|
|
|
{
|
2008-08-12 07:02:22 -07:00
|
|
|
NS_ASSERTION(aSVGMode == PR_TRUE || aSVGMode == PR_FALSE,
|
|
|
|
"bad PRBool value");
|
|
|
|
mScanner.SetSVGMode(aSVGMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2010-03-02 13:00:53 -08:00
|
|
|
CSSParserImpl::SetChildLoader(mozilla::css::Loader* aChildLoader)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mChildLoader = aChildLoader; // not ref counted, it owns us
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
void
|
|
|
|
CSSParserImpl::Reset()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(! mScannerInited, "resetting with scanner active");
|
|
|
|
SetStyleSheet(nsnull);
|
|
|
|
SetQuirkMode(PR_FALSE);
|
2010-06-06 10:45:18 -07:00
|
|
|
#ifdef MOZ_SVG
|
2010-03-02 12:59:32 -08:00
|
|
|
SetSVGMode(PR_FALSE);
|
2010-06-06 10:45:18 -07:00
|
|
|
#endif // MOZ_SVG
|
2010-03-02 12:59:32 -08:00
|
|
|
SetChildLoader(nsnull);
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(! mScannerInited, "already have scanner");
|
|
|
|
|
|
|
|
mScanner.Init(aInput, nsnull, 0, aSheetURI, aLineNumber);
|
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_TRUE;
|
|
|
|
#endif
|
2010-03-02 12:59:32 -08:00
|
|
|
mBaseURI = aBaseURI;
|
|
|
|
mSheetURI = aSheetURI;
|
2007-05-02 18:15:53 -07:00
|
|
|
mSheetPrincipal = aSheetPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
void
|
2007-07-05 18:21:56 -07:00
|
|
|
CSSParserImpl::InitScanner(const nsSubstring& aString, nsIURI* aSheetURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
PRUint32 aLineNumber, nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Having it not own the string is OK since the caller will hold on to
|
|
|
|
// the stream until we're done parsing.
|
|
|
|
NS_ASSERTION(! mScannerInited, "already have scanner");
|
|
|
|
|
2007-07-05 18:21:56 -07:00
|
|
|
mScanner.Init(nsnull, aString.BeginReading(), aString.Length(), aSheetURI, aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_TRUE;
|
|
|
|
#endif
|
2010-03-02 12:59:32 -08:00
|
|
|
mBaseURI = aBaseURI;
|
|
|
|
mSheetURI = aSheetURI;
|
2007-05-02 18:15:53 -07:00
|
|
|
mSheetPrincipal = aSheetPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ReleaseScanner(void)
|
|
|
|
{
|
|
|
|
mScanner.Close();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mScannerInited = PR_FALSE;
|
|
|
|
#endif
|
2010-03-02 12:59:32 -08:00
|
|
|
mBaseURI = nsnull;
|
|
|
|
mSheetURI = nsnull;
|
2008-02-14 20:21:57 -08:00
|
|
|
mSheetPrincipal = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aLineNumber,
|
2008-02-14 20:21:57 -08:00
|
|
|
PRBool aAllowUnsafeRules)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
NS_ASSERTION(nsnull != aBaseURI, "need base URI");
|
|
|
|
NS_ASSERTION(nsnull != aSheetURI, "need sheet URI");
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-14 20:21:57 -08:00
|
|
|
NS_PRECONDITION(mSheet, "Must have sheet to parse into");
|
|
|
|
NS_ENSURE_STATE(mSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-17 21:00:40 -07:00
|
|
|
nsIURI* uri = mSheet->GetSheetURI();
|
2008-02-14 20:21:57 -08:00
|
|
|
PRBool equal;
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(aSheetURI->Equals(uri, &equal)) && equal,
|
|
|
|
"Sheet URI does not match passed URI");
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(mSheet->Principal()->Equals(aSheetPrincipal,
|
|
|
|
&equal)) &&
|
|
|
|
equal,
|
|
|
|
"Sheet principal does not match passed principal");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
InitScanner(aInput, aSheetURI, aLineNumber, aBaseURI, aSheetPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
PRInt32 ruleCount = mSheet->StyleRuleCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (0 < ruleCount) {
|
|
|
|
nsICSSRule* lastRule = nsnull;
|
|
|
|
mSheet->GetStyleRuleAt(ruleCount - 1, lastRule);
|
|
|
|
if (lastRule) {
|
2010-07-18 07:39:20 -07:00
|
|
|
switch (lastRule->GetType()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsICSSRule::CHARSET_RULE:
|
2008-09-09 21:38:14 -07:00
|
|
|
case nsICSSRule::IMPORT_RULE:
|
|
|
|
mSection = eCSSSection_Import;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-09-09 21:38:14 -07:00
|
|
|
case nsICSSRule::NAMESPACE_RULE:
|
|
|
|
mSection = eCSSSection_NameSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-09-09 21:38:14 -07:00
|
|
|
default:
|
|
|
|
mSection = eCSSSection_General;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(lastRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSection = eCSSSection_Charset; // sheet is empty, any rules are fair
|
|
|
|
}
|
|
|
|
|
|
|
|
mUnsafeRulesEnabled = aAllowUnsafeRules;
|
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
|
|
|
// Get next non-whitespace token
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_HTMLComment == tk->mType) {
|
|
|
|
continue; // legal here only
|
|
|
|
}
|
|
|
|
if (eCSSToken_AtKeyword == tk->mType) {
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseAtRule(AppendRuleToSheet, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseRuleSet(AppendRuleToSheet, this)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReleaseScanner();
|
|
|
|
|
|
|
|
mUnsafeRulesEnabled = PR_FALSE;
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
// XXX check for low level errors
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-03 21:58:27 -07:00
|
|
|
/**
|
|
|
|
* Determines whether the identifier contained in the given string is a
|
|
|
|
* vendor-specific identifier, as described in CSS 2.1 section 4.1.2.1.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
NonMozillaVendorIdentifier(const nsAString& ident)
|
|
|
|
{
|
|
|
|
return (ident.First() == PRUnichar('-') &&
|
|
|
|
!StringBeginsWith(ident, NS_LITERAL_STRING("-moz-"))) ||
|
|
|
|
ident.First() == PRUnichar('_');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aDocURI,
|
|
|
|
nsIURI* aBaseURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
nsIPrincipal* aNodePrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsICSSStyleRule** aResult)
|
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
NS_PRECONDITION(aNodePrincipal, "Must have principal here!");
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
NS_ASSERTION(nsnull != aBaseURI, "need base URI");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-02 18:15:53 -07:00
|
|
|
// XXX line number?
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aAttributeValue, aDocURI, 0, aBaseURI, aNodePrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
|
|
|
// In quirks mode, allow style declarations to have braces or not
|
|
|
|
// (bug 99554).
|
|
|
|
PRBool haveBraces;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (mNavQuirkMode && GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
haveBraces = eCSSToken_Symbol == mToken.mType &&
|
|
|
|
'{' == mToken.mSymbol;
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
haveBraces = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* declaration = ParseDeclarationBlock(haveBraces);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (declaration) {
|
2008-07-03 14:28:39 -07:00
|
|
|
// Create a style rule for the declaration
|
2010-07-23 11:00:34 -07:00
|
|
|
*aResult = NS_NewCSSStyleRule(nsnull, declaration).get();
|
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aResult = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseScanner();
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
// XXX check for low level errors
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2010-07-23 11:00:19 -07:00
|
|
|
CSSParserImpl::ParseDeclarations(const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
css::Declaration* aDeclaration,
|
|
|
|
PRBool* aChanged)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aChanged = PR_FALSE;
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aBuffer, aSheetURI, 0, aBaseURI, aSheetPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
2010-07-23 11:00:19 -07:00
|
|
|
mData.AssertInitialState();
|
|
|
|
aDeclaration->ClearData();
|
|
|
|
// We could check if it was already empty, but...
|
|
|
|
*aChanged = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:26 -07:00
|
|
|
nsresult rv = NS_OK;
|
2010-07-23 11:00:19 -07:00
|
|
|
for (;;) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we cleared the old decl, then we want to be calling
|
|
|
|
// ValueAppended as we parse.
|
2010-07-23 11:00:19 -07:00
|
|
|
if (!ParseDeclaration(aDeclaration, PR_FALSE, PR_TRUE, aChanged)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
rv = mScanner.GetLowLevelError();
|
|
|
|
if (NS_FAILED(rv))
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!SkipDeclaration(PR_FALSE)) {
|
|
|
|
rv = mScanner.GetLowLevelError();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 11:00:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:19 -07:00
|
|
|
aDeclaration->CompressFrom(&mData);
|
2007-03-22 10:30:00 -07:00
|
|
|
ReleaseScanner();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ParseRule(const nsAString& aRule,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMArray<nsICSSRule>& aResult)
|
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
NS_ASSERTION(nsnull != aBaseURI, "need base URI");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aRule, aSheetURI, 0, aBaseURI, aSheetPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mSection = eCSSSection_Charset; // callers are responsible for rejecting invalid rules.
|
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
// Get first non-whitespace token
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED(PEParseRuleWSOnly);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
} else if (eCSSToken_AtKeyword == tk->mType) {
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseAtRule(AppendRuleToArray, &aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseRuleSet(AppendRuleToArray, &aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
2008-09-09 21:38:14 -07:00
|
|
|
// XXX check for low-level errors
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
2007-05-02 18:15:53 -07:00
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* aDeclaration,
|
2010-04-01 23:07:40 -07:00
|
|
|
PRBool* aChanged,
|
|
|
|
PRBool aIsImportant)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
|
2010-07-23 11:00:39 -07:00
|
|
|
NS_PRECONDITION(aBaseURI, "need base URI");
|
|
|
|
NS_PRECONDITION(aDeclaration, "Need declaration to parse into!");
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2010-07-23 11:00:39 -07:00
|
|
|
mData.AssertInitialState();
|
|
|
|
mTempData.AssertInitialState();
|
2010-07-23 11:00:49 -07:00
|
|
|
aDeclaration->AssertMutable();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aPropValue, aSheetURI, 0, aBaseURI, aSheetPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
2010-07-23 11:00:39 -07:00
|
|
|
*aChanged = PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSProperty_UNKNOWN == aPropID) { // unknown property
|
|
|
|
NS_ConvertASCIItoUTF16 propName(nsCSSProps::GetStringValue(aPropID));
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownProperty, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
PRBool parsedOK = ParseProperty(aPropID);
|
2010-07-23 11:00:39 -07:00
|
|
|
// We should now be at EOF
|
|
|
|
if (parsedOK && GetToken(PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectEndValue);
|
|
|
|
parsedOK = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parsedOK) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ConvertASCIItoUTF16 propName(nsCSSProps::GetStringValue(aPropID));
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propName.get()
|
|
|
|
};
|
2008-08-10 14:13:49 -07:00
|
|
|
REPORT_UNEXPECTED_P(PEValueParsingError, params);
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
2010-07-23 11:00:42 -07:00
|
|
|
mTempData.ClearProperty(aPropID);
|
2010-07-23 11:00:39 -07:00
|
|
|
} else {
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-07-23 11:00:39 -07:00
|
|
|
// We know we don't need to force a ValueAppended call for the new
|
|
|
|
// value. So if we are not processing a shorthand, and there's
|
|
|
|
// already a value for this property in the declaration at the
|
|
|
|
// same importance level, then we can just copy our parsed value
|
|
|
|
// directly into the declaration without going through the whole
|
|
|
|
// expand/compress thing.
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!aDeclaration->TryReplaceValue(aPropID, aIsImportant, mTempData,
|
|
|
|
aChanged)) {
|
|
|
|
// Do it the slow way
|
2010-07-23 11:00:39 -07:00
|
|
|
aDeclaration->ExpandTo(&mData);
|
2010-08-19 12:33:44 -07:00
|
|
|
*aChanged = mData.TransferFromBlock(mTempData, aPropID, aIsImportant,
|
|
|
|
PR_TRUE, PR_FALSE, aDeclaration);
|
2010-07-23 11:00:39 -07:00
|
|
|
aDeclaration->CompressFrom(&mData);
|
|
|
|
}
|
|
|
|
CLEAR_ERROR();
|
2009-07-09 14:50:39 -07:00
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-07-23 11:00:44 -07:00
|
|
|
mTempData.AssertInitialState();
|
|
|
|
|
2010-07-23 11:00:39 -07:00
|
|
|
nsresult result = mScanner.GetLowLevelError();
|
2007-03-22 10:30:00 -07:00
|
|
|
ReleaseScanner();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ParseMediaList(const nsSubstring& aBuffer,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aURI, // for error reporting
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode)
|
|
|
|
{
|
2008-07-26 09:14:48 -07:00
|
|
|
// XXX Are there cases where the caller wants to keep what it already
|
|
|
|
// has in case of parser error?
|
2007-03-22 10:30:00 -07:00
|
|
|
aMediaList->Clear();
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
// fake base URI since media lists don't have URIs in them
|
|
|
|
InitScanner(aBuffer, aURI, aLineNumber, aURI, nsnull);
|
2008-07-26 09:14:49 -07:00
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
|
|
|
NS_ASSERTION(aHTMLMode == PR_TRUE || aHTMLMode == PR_FALSE,
|
|
|
|
"invalid PRBool");
|
|
|
|
mHTMLMediaMode = aHTMLMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXXldb We need to make the scanner not skip CSS comments! (Or
|
|
|
|
// should we?)
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
// For aHTMLMode, we used to follow the parsing rules in
|
|
|
|
// http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-media-descriptors
|
|
|
|
// which wouldn't work for media queries since they remove all but the
|
|
|
|
// first word. However, they're changed in
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/section-document.html#media2
|
|
|
|
// (as of 2008-05-29) which says that the media attribute just points
|
|
|
|
// to a media query. (The main substative difference is the relative
|
|
|
|
// precedence of commas and paretheses.)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GatherMedia(aMediaList, PRUnichar(0))) {
|
2008-07-26 09:14:48 -07:00
|
|
|
aMediaList->Clear();
|
|
|
|
aMediaList->SetNonEmpty(); // don't match anything
|
|
|
|
if (!mHTMLMediaMode) {
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-09 21:38:26 -07:00
|
|
|
nsresult rv = mScanner.GetLowLevelError();
|
2007-03-22 10:30:00 -07:00
|
|
|
CLEAR_ERROR();
|
|
|
|
ReleaseScanner();
|
2008-07-26 09:14:49 -07:00
|
|
|
mHTMLMediaMode = PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
CSSParserImpl::ParseColorString(const nsSubstring& aBuffer,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aURI, // for error reporting
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nscolor* aColor)
|
|
|
|
{
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aBuffer, aURI, aLineNumber, aURI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCSSValue value;
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool colorParsed = ParseColor(value);
|
2008-09-09 21:38:26 -07:00
|
|
|
nsresult rv = mScanner.GetLowLevelError();
|
2007-03-22 10:30:00 -07:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
|
|
|
|
if (!colorParsed) {
|
2008-09-09 21:38:14 -07:00
|
|
|
return NS_FAILED(rv) ? rv : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-05 20:05:01 -08:00
|
|
|
if (value.GetUnit() == eCSSUnit_Ident) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nscolor rgba;
|
2007-07-05 18:21:56 -07:00
|
|
|
if (NS_ColorNameToRGB(nsDependentString(value.GetStringBufferValue()), &rgba)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
(*aColor) = rgba;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
} else if (value.GetUnit() == eCSSUnit_Color) {
|
|
|
|
(*aColor) = value.GetColorValue();
|
|
|
|
rv = NS_OK;
|
2008-02-08 11:51:41 -08:00
|
|
|
} else if (value.GetUnit() == eCSSUnit_EnumColor) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsresult
|
2008-07-21 17:55:52 -07:00
|
|
|
CSSParserImpl::ParseSelectorString(const nsSubstring& aSelectorString,
|
2010-03-02 12:59:32 -08:00
|
|
|
nsIURI* aURI, // for error reporting
|
2008-07-21 17:55:52 -07:00
|
|
|
PRUint32 aLineNumber, // for error reporting
|
|
|
|
nsCSSSelectorList **aSelectorList)
|
|
|
|
{
|
2010-03-02 12:59:32 -08:00
|
|
|
InitScanner(aSelectorString, aURI, aLineNumber, aURI, nsnull);
|
2008-07-21 17:55:52 -07:00
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
AssertInitialState();
|
2008-07-21 17:55:52 -07:00
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
// This is the only place that cares about mFoundUnresolvablePrefix,
|
|
|
|
// so this is the only place that bothers clearing it.
|
|
|
|
mFoundUnresolvablePrefix = PR_FALSE;
|
2008-07-21 17:55:52 -07:00
|
|
|
|
2010-04-23 19:59:47 -07:00
|
|
|
PRBool success = ParseSelectorList(*aSelectorList, PRUnichar(0));
|
2010-03-05 10:43:50 -08:00
|
|
|
PRBool prefixErr = mFoundUnresolvablePrefix;
|
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
OUTPUT_ERROR();
|
|
|
|
ReleaseScanner();
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
NS_ASSERTION(*aSelectorList, "Should have list!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
NS_ASSERTION(!*aSelectorList, "Shouldn't have list!");
|
2010-03-05 10:43:50 -08:00
|
|
|
if (prefixErr)
|
|
|
|
return NS_ERROR_DOM_NAMESPACE_ERR;
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::GetToken(PRBool aSkipWS)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (!mHavePushBack) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!mScanner.Next(mToken)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mHavePushBack = PR_FALSE;
|
|
|
|
if (aSkipWS && (eCSSToken_WhiteSpace == mToken.mType)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2009-08-05 17:45:49 -07:00
|
|
|
CSSParserImpl::GetURLInParens(nsString& aURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-27 16:20:04 -08:00
|
|
|
NS_ASSERTION(!mHavePushBack, "mustn't have pushback at this point");
|
2009-08-05 17:45:49 -07:00
|
|
|
do {
|
|
|
|
if (! mScanner.NextURL(mToken)) {
|
2010-08-11 12:32:52 -07:00
|
|
|
// EOF
|
2009-08-05 17:45:49 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-05 17:45:49 -07:00
|
|
|
} while (eCSSToken_WhiteSpace == mToken.mType);
|
|
|
|
|
|
|
|
aURL = mToken.mIdent;
|
|
|
|
|
|
|
|
if ((eCSSToken_String != mToken.mType && eCSSToken_URL != mToken.mType) ||
|
|
|
|
!ExpectSymbol(')', PR_TRUE)) {
|
2010-06-03 13:11:35 -07:00
|
|
|
// in the failure case, we do not have to match parentheses, since
|
|
|
|
// this is now an invalid URL token.
|
|
|
|
SkipUntil(')');
|
2009-08-05 17:45:49 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-05 17:45:49 -07:00
|
|
|
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
void
|
|
|
|
CSSParserImpl::UngetToken()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-02-07 07:52:43 -08:00
|
|
|
NS_PRECONDITION(!mHavePushBack, "double pushback");
|
2007-03-22 10:30:00 -07:00
|
|
|
mHavePushBack = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ExpectSymbol(PRUnichar aSymbol,
|
|
|
|
PRBool aSkipWS)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(aSkipWS)) {
|
2008-07-19 15:52:09 -07:00
|
|
|
// CSS2.1 specifies that all "open constructs" are to be closed at
|
|
|
|
// EOF. It simplifies higher layers if we claim to have found an
|
|
|
|
// ), ], }, or ; if we encounter EOF while looking for one of them.
|
|
|
|
// Do still issue a diagnostic, to aid debugging.
|
|
|
|
if (aSymbol == ')' || aSymbol == ']' ||
|
|
|
|
aSymbol == '}' || aSymbol == ';') {
|
|
|
|
REPORT_UNEXPECTED_EOF_CHAR(aSymbol);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (mToken.IsSymbol(aSymbol)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
// Checks to see if we're at the end of a property. If an error occurs during
|
|
|
|
// the check, does not signal a parse error.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2008-09-13 02:42:11 -07:00
|
|
|
CSSParserImpl::CheckEndProperty()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE; // properties may end with eof
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == mToken.mType) &&
|
2008-09-13 02:42:11 -07:00
|
|
|
((';' == mToken.mSymbol) ||
|
|
|
|
('!' == mToken.mSymbol) ||
|
|
|
|
('}' == mToken.mSymbol))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX need to verify that ! is only followed by "important [;|}]
|
|
|
|
// XXX this requires a multi-token pushback buffer
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
// Checks if we're at the end of a property, raising an error if we're not.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ExpectEndProperty()
|
|
|
|
{
|
|
|
|
if (CheckEndProperty())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// If we're here, we read something incorrect, so we should report it.
|
2009-04-17 07:47:45 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectEndValue);
|
2008-09-13 02:42:11 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:37 -07:00
|
|
|
// Parses the priority suffix on a property, which at present may be
|
|
|
|
// either '!important' or nothing.
|
|
|
|
CSSParserImpl::PriorityParsingStatus
|
|
|
|
CSSParserImpl::ParsePriority()
|
|
|
|
{
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
return ePriority_None; // properties may end with EOF
|
|
|
|
}
|
|
|
|
if (!mToken.IsSymbol('!')) {
|
|
|
|
UngetToken();
|
|
|
|
return ePriority_None; // dunno what it is, but it's not a priority
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
// EOF is not ok after !
|
|
|
|
REPORT_UNEXPECTED_EOF(PEImportantEOF);
|
|
|
|
return ePriority_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mToken.mType != eCSSToken_Ident ||
|
|
|
|
!mToken.mIdent.LowerCaseEqualsLiteral("important")) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedImportant);
|
|
|
|
UngetToken();
|
|
|
|
return ePriority_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ePriority_Important;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
nsSubstring*
|
|
|
|
CSSParserImpl::NextIdent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX Error reporting?
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
UngetToken();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return &mToken.mIdent;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::SkipAtRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PESkipAtRuleEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == mToken.mType) {
|
|
|
|
PRUnichar symbol = mToken.mSymbol;
|
|
|
|
if (symbol == ';') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (symbol == '{') {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil('}');
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
} else if (symbol == '(') {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (symbol == '[') {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(']');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
} else if (eCSSToken_Function == mToken.mType) {
|
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseAtRule(RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-16 19:44:20 -08:00
|
|
|
nsCSSSection newSection;
|
|
|
|
PRBool (CSSParserImpl::*parseFunc)(RuleAppendFunc, void*);
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if ((mSection <= eCSSSection_Charset) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("charset"))) {
|
2009-01-16 19:44:20 -08:00
|
|
|
parseFunc = &CSSParserImpl::ParseCharsetRule;
|
|
|
|
newSection = eCSSSection_Import; // only one charset allowed
|
|
|
|
|
|
|
|
} else if ((mSection <= eCSSSection_Import) &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("import")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParseImportRule;
|
|
|
|
newSection = eCSSSection_Import;
|
|
|
|
|
|
|
|
} else if ((mSection <= eCSSSection_NameSpace) &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("namespace")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParseNameSpaceRule;
|
|
|
|
newSection = eCSSSection_NameSpace;
|
|
|
|
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("media")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParseMediaRule;
|
|
|
|
newSection = eCSSSection_General;
|
|
|
|
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-document")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParseMozDocumentRule;
|
|
|
|
newSection = eCSSSection_General;
|
|
|
|
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("font-face")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParseFontFaceRule;
|
|
|
|
newSection = eCSSSection_General;
|
|
|
|
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("page")) {
|
|
|
|
parseFunc = &CSSParserImpl::ParsePageRule;
|
|
|
|
newSection = eCSSSection_General;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!NonMozillaVendorIdentifier(mToken.mIdent)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEUnknownAtRule);
|
|
|
|
OUTPUT_ERROR();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-16 19:44:20 -08:00
|
|
|
// Skip over unsupported at rule, don't advance section
|
|
|
|
return SkipAtRule();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-10-03 21:58:27 -07:00
|
|
|
|
2009-01-16 19:44:20 -08:00
|
|
|
if (!(this->*parseFunc)(aAppendFunc, aData)) {
|
|
|
|
// Skip over invalid at rule, don't advance section
|
2007-10-03 21:58:27 -07:00
|
|
|
OUTPUT_ERROR();
|
2009-01-16 19:44:20 -08:00
|
|
|
return SkipAtRule();
|
2007-10-03 21:58:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-16 19:44:20 -08:00
|
|
|
mSection = newSection;
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCharsetRule(RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PECharsetRuleEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_String != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PECharsetRuleNotString);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString charset = mToken.mIdent;
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectSymbol(';', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
NS_NewCSSCharsetRule(getter_AddRefs(rule), charset);
|
|
|
|
|
|
|
|
if (rule) {
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::GatherURL(nsString& aURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_String == mToken.mType) {
|
|
|
|
aURL = mToken.mIdent;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
else if (eCSSToken_Function == mToken.mType &&
|
2007-03-22 10:30:00 -07:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url") &&
|
2009-08-05 17:45:49 -07:00
|
|
|
GetURLInParens(aURL)) {
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2008-10-11 17:49:42 -07:00
|
|
|
CSSParserImpl::ParseMediaQuery(PRUnichar aStopSymbol,
|
|
|
|
nsMediaQuery **aQuery,
|
|
|
|
PRBool *aParsedSomething,
|
|
|
|
PRBool *aHitStop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-11 17:49:42 -07:00
|
|
|
*aQuery = nsnull;
|
|
|
|
*aParsedSomething = PR_FALSE;
|
|
|
|
*aHitStop = PR_FALSE;
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
// "If the comma-separated list is the empty list it is assumed to
|
|
|
|
// specify the media query 'all'." (css3-mediaqueries, section
|
|
|
|
// "Media Queries")
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2008-10-11 17:49:42 -07:00
|
|
|
*aHitStop = PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
// expected termination by EOF
|
|
|
|
if (aStopSymbol == PRUnichar(0))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2008-10-11 17:49:42 -07:00
|
|
|
// unexpected termination by EOF
|
2008-07-26 09:14:48 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEGatherMediaEOF);
|
2008-10-11 17:49:42 -07:00
|
|
|
return PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_Symbol == mToken.mType &&
|
|
|
|
mToken.mSymbol == aStopSymbol) {
|
2008-10-11 17:49:42 -07:00
|
|
|
*aHitStop = PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
UngetToken();
|
|
|
|
|
2008-10-11 17:49:42 -07:00
|
|
|
*aParsedSomething = PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
|
2008-10-11 17:49:42 -07:00
|
|
|
nsAutoPtr<nsMediaQuery> query(new nsMediaQuery);
|
|
|
|
if (!query) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
|
2008-10-11 17:49:42 -07:00
|
|
|
if (ExpectSymbol('(', PR_TRUE)) {
|
|
|
|
// we got an expression without a media type
|
|
|
|
UngetToken(); // so ParseMediaQueryExpression can handle it
|
|
|
|
query->SetType(nsGkAtoms::all);
|
|
|
|
query->SetTypeOmitted();
|
|
|
|
// Just parse the first expression here.
|
|
|
|
if (!ParseMediaQueryExpression(query)) {
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
query->SetHadUnknownExpression();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIAtom> mediaType;
|
|
|
|
PRBool gotNotOrOnly = PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2008-07-26 09:14:48 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEGatherMediaEOF);
|
2008-10-11 17:49:42 -07:00
|
|
|
return PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEGatherMediaNotIdent);
|
2008-07-26 09:14:48 -07:00
|
|
|
UngetToken();
|
2008-10-11 17:49:42 -07:00
|
|
|
return PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
// case insensitive from CSS - must be lower cased
|
2010-08-02 15:19:04 -07:00
|
|
|
nsContentUtils::ASCIIToLower(mToken.mIdent);
|
2008-10-11 17:49:42 -07:00
|
|
|
mediaType = do_GetAtom(mToken.mIdent);
|
|
|
|
if (gotNotOrOnly ||
|
|
|
|
(mediaType != nsGkAtoms::_not && mediaType != nsGkAtoms::only))
|
2008-07-26 09:14:48 -07:00
|
|
|
break;
|
2008-10-11 17:49:42 -07:00
|
|
|
gotNotOrOnly = PR_TRUE;
|
|
|
|
if (mediaType == nsGkAtoms::_not)
|
|
|
|
query->SetNegated();
|
|
|
|
else
|
|
|
|
query->SetHasOnly();
|
|
|
|
}
|
|
|
|
query->SetType(mediaType);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
*aHitStop = PR_TRUE;
|
|
|
|
// expected termination by EOF
|
|
|
|
if (aStopSymbol == PRUnichar(0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// unexpected termination by EOF
|
|
|
|
REPORT_UNEXPECTED_EOF(PEGatherMediaEOF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_Symbol == mToken.mType &&
|
|
|
|
mToken.mSymbol == aStopSymbol) {
|
|
|
|
*aHitStop = PR_TRUE;
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == mToken.mType && mToken.mSymbol == ',') {
|
|
|
|
// Done with the expressions for this query
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType ||
|
|
|
|
!mToken.mIdent.LowerCaseEqualsLiteral("and")) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEGatherMediaNotComma);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ParseMediaQueryExpression(query)) {
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
query->SetHadUnknownExpression();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aQuery = query.forget();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns false only when there is a low-level error in the scanner
|
|
|
|
// (out-of-memory).
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::GatherMedia(nsMediaList* aMedia,
|
|
|
|
PRUnichar aStopSymbol)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
nsAutoPtr<nsMediaQuery> query;
|
|
|
|
PRBool parsedSomething, hitStop;
|
|
|
|
if (!ParseMediaQuery(aStopSymbol, getter_Transfers(query),
|
|
|
|
&parsedSomething, &hitStop)) {
|
2008-11-02 11:44:56 -08:00
|
|
|
NS_ASSERTION(!hitStop, "should return true when hit stop");
|
2008-10-11 17:49:42 -07:00
|
|
|
if (NS_FAILED(mScanner.GetLowLevelError())) {
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-11-02 11:44:56 -08:00
|
|
|
const PRUnichar stopChars[] =
|
|
|
|
{ PRUnichar(','), aStopSymbol /* may be null */, PRUnichar(0) };
|
|
|
|
SkipUntilOneOf(stopChars);
|
|
|
|
// Rely on SkipUntilOneOf leaving mToken around as the last token read.
|
|
|
|
if (mToken.mType == eCSSToken_Symbol && mToken.mSymbol == aStopSymbol) {
|
|
|
|
UngetToken();
|
|
|
|
hitStop = PR_TRUE;
|
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
}
|
|
|
|
if (parsedSomething) {
|
|
|
|
aMedia->SetNonEmpty();
|
|
|
|
}
|
|
|
|
if (query) {
|
|
|
|
nsresult rv = aMedia->AppendQuery(query);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mScanner.SetLowLevelError(rv);
|
|
|
|
return PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
if (hitStop) {
|
|
|
|
break;
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2008-10-11 17:49:42 -07:00
|
|
|
return PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMediaQueryExpression(nsMediaQuery* aQuery)
|
2008-07-26 09:14:48 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol('(', PR_TRUE)) {
|
2008-07-26 09:14:48 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMQExpectedExpressionStart);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2008-07-26 09:14:48 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEMQExpressionEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMQExpectedFeatureName);
|
2010-01-27 16:20:05 -08:00
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(')');
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaExpression *expr = aQuery->NewExpression();
|
|
|
|
if (!expr) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
SkipUntil(')');
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// case insensitive from CSS - must be lower cased
|
2010-08-02 15:19:04 -07:00
|
|
|
nsContentUtils::ASCIIToLower(mToken.mIdent);
|
2008-07-26 09:14:48 -07:00
|
|
|
const PRUnichar *featureString;
|
|
|
|
if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("min-"))) {
|
|
|
|
expr->mRange = nsMediaExpression::eMin;
|
|
|
|
featureString = mToken.mIdent.get() + 4;
|
|
|
|
} else if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("max-"))) {
|
|
|
|
expr->mRange = nsMediaExpression::eMax;
|
|
|
|
featureString = mToken.mIdent.get() + 4;
|
|
|
|
} else {
|
|
|
|
expr->mRange = nsMediaExpression::eEqual;
|
|
|
|
featureString = mToken.mIdent.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> mediaFeatureAtom = do_GetAtom(featureString);
|
|
|
|
const nsMediaFeature *feature = nsMediaFeatures::features;
|
|
|
|
for (; feature->mName; ++feature) {
|
|
|
|
if (*(feature->mName) == mediaFeatureAtom) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
if (!feature->mName ||
|
|
|
|
(expr->mRange != nsMediaExpression::eEqual &&
|
|
|
|
feature->mRangeType != nsMediaFeature::eMinMaxAllowed)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMQExpectedFeatureName);
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(')');
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
expr->mFeature = feature;
|
|
|
|
|
2008-09-12 20:45:37 -07:00
|
|
|
if (!GetToken(PR_TRUE) || mToken.IsSymbol(')')) {
|
2008-09-06 07:04:28 -07:00
|
|
|
// Query expressions for any feature can be given without a value.
|
|
|
|
// However, min/max prefixes are not allowed.
|
|
|
|
if (expr->mRange != nsMediaExpression::eEqual) {
|
|
|
|
REPORT_UNEXPECTED(PEMQNoMinMaxWithoutValue);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
expr->mValue.Reset();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:45:37 -07:00
|
|
|
if (!mToken.IsSymbol(':')) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMQExpectedFeatureNameEnd);
|
2010-01-27 16:20:05 -08:00
|
|
|
UngetToken();
|
2008-09-12 20:45:37 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
PRBool rv;
|
|
|
|
switch (feature->mValueType) {
|
|
|
|
case nsMediaFeature::eLength:
|
2009-03-09 16:14:34 -07:00
|
|
|
rv = ParseNonNegativeVariant(expr->mValue, VARIANT_LENGTH, nsnull);
|
2008-07-26 09:14:48 -07:00
|
|
|
break;
|
|
|
|
case nsMediaFeature::eInteger:
|
2008-09-06 07:04:28 -07:00
|
|
|
case nsMediaFeature::eBoolInteger:
|
2009-03-09 16:14:34 -07:00
|
|
|
rv = ParseNonNegativeVariant(expr->mValue, VARIANT_INTEGER, nsnull);
|
2008-09-06 07:04:28 -07:00
|
|
|
// Enforce extra restrictions for eBoolInteger
|
|
|
|
if (rv &&
|
|
|
|
feature->mValueType == nsMediaFeature::eBoolInteger &&
|
|
|
|
expr->mValue.GetIntValue() > 1)
|
|
|
|
rv = PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
break;
|
|
|
|
case nsMediaFeature::eIntRatio:
|
|
|
|
{
|
|
|
|
// Two integers separated by '/', with optional whitespace on
|
|
|
|
// either side of the '/'.
|
|
|
|
nsRefPtr<nsCSSValue::Array> a = nsCSSValue::Array::Create(2);
|
|
|
|
if (!a) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
SkipUntil(')');
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
expr->mValue.SetArrayValue(a, eCSSUnit_Array);
|
2009-03-09 16:14:34 -07:00
|
|
|
// We don't bother with ParseNonNegativeVariant since we have to
|
2008-07-26 09:14:48 -07:00
|
|
|
// check for != 0 as well; no need to worry about the UngetToken
|
|
|
|
// since we're throwing out up to the next ')' anyway.
|
2008-09-09 21:38:14 -07:00
|
|
|
rv = ParseVariant(a->Item(0), VARIANT_INTEGER, nsnull) &&
|
2008-07-26 09:14:48 -07:00
|
|
|
a->Item(0).GetIntValue() > 0 &&
|
2008-09-09 21:38:14 -07:00
|
|
|
ExpectSymbol('/', PR_TRUE) &&
|
|
|
|
ParseVariant(a->Item(1), VARIANT_INTEGER, nsnull) &&
|
2008-07-26 09:14:48 -07:00
|
|
|
a->Item(1).GetIntValue() > 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eResolution:
|
2010-01-27 16:20:05 -08:00
|
|
|
rv = GetToken(PR_TRUE);
|
|
|
|
if (!rv)
|
|
|
|
break;
|
|
|
|
rv = mToken.mType == eCSSToken_Dimension &&
|
2008-07-26 09:14:48 -07:00
|
|
|
mToken.mIntegerValid && mToken.mNumber > 0.0f;
|
2010-01-27 16:20:05 -08:00
|
|
|
if (!rv) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// No worries about whether unitless zero is allowed, since the
|
|
|
|
// value must be positive (and we checked that above).
|
|
|
|
NS_ASSERTION(!mToken.mIdent.IsEmpty(), "unit lied");
|
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("dpi")) {
|
|
|
|
expr->mValue.SetFloatValue(mToken.mNumber, eCSSUnit_Inch);
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("dpcm")) {
|
|
|
|
expr->mValue.SetFloatValue(mToken.mNumber, eCSSUnit_Centimeter);
|
|
|
|
} else {
|
|
|
|
rv = PR_FALSE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eEnumerated:
|
2008-09-09 21:38:14 -07:00
|
|
|
rv = ParseVariant(expr->mValue, VARIANT_KEYWORD,
|
2009-10-15 17:23:18 -07:00
|
|
|
feature->mData.mKeywordTable);
|
2008-07-26 09:14:48 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-09-12 20:45:37 -07:00
|
|
|
if (!rv || !ExpectSymbol(')', PR_TRUE)) {
|
2008-07-26 09:14:48 -07:00
|
|
|
REPORT_UNEXPECTED(PEMQExpectedFeatureValue);
|
2008-09-12 20:45:37 -07:00
|
|
|
SkipUntil(')');
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:45:37 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a CSS2 import rule: "@import STRING | URL [medium [, medium]]"
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseImportRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-31 16:50:10 -07:00
|
|
|
nsRefPtr<nsMediaList> media = new nsMediaList();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!media) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString url;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GatherURL(url)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEImportNotURI);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectSymbol(';', PR_TRUE)) {
|
|
|
|
if (!GatherMedia(media, ';') ||
|
|
|
|
!ExpectSymbol(';', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEImportUnexpected);
|
|
|
|
// don't advance section, simply ignore invalid @import
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 18:39:38 -07:00
|
|
|
|
|
|
|
// Safe to assert this, since we ensured that there is something
|
|
|
|
// other than the ';' coming after the @import's url() token.
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(media->Count() != 0, "media list must be nonempty");
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
ProcessImport(url, media, aAppendFunc, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-17 13:02:56 -08:00
|
|
|
void
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ProcessImport(const nsString& aURLSpec,
|
|
|
|
nsMediaList* aMedia,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsICSSImportRule> rule;
|
2008-09-09 21:38:14 -07:00
|
|
|
nsresult rv = NS_NewCSSImportRule(getter_AddRefs(rule), aURLSpec, aMedia);
|
2010-02-17 13:02:56 -08:00
|
|
|
if (NS_FAILED(rv)) { // out of memory
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(rv);
|
2010-02-17 13:02:56 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
|
2010-02-17 13:02:56 -08:00
|
|
|
// Diagnose bad URIs even if we don't have a child loader.
|
|
|
|
nsCOMPtr<nsIURI> url;
|
2010-03-02 12:59:32 -08:00
|
|
|
// Charset will be deduced from mBaseURI, which is more or less correct.
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aURLSpec, nsnull, mBaseURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-17 13:02:56 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (rv == NS_ERROR_MALFORMED_URI) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// import url is bad
|
2010-02-17 13:02:56 -08:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
aURLSpec.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEImportBadURI, params);
|
|
|
|
OUTPUT_ERROR();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-02-17 13:02:56 -08:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-17 13:02:56 -08:00
|
|
|
if (mChildLoader) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mChildLoader->LoadChildSheet(mSheet, url, aMedia, rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the {} part of an @media or @-moz-document rule.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseGroupRule(nsICSSGroupRule* aRule,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXXbz this could use better error reporting throughout the method
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol('{', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// push rule on stack, loop over children
|
|
|
|
if (!PushGroup(aRule)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSSection holdSection = mSection;
|
|
|
|
mSection = eCSSSection_General;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// Get next non-whitespace token
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEGroupRuleEOF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mToken.IsSymbol('}')) { // done!
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_AtKeyword == mToken.mType) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipAtRule(); // group rules cannot contain @rules
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UngetToken();
|
2009-08-19 06:11:30 -07:00
|
|
|
ParseRuleSet(AppendRuleToSheet, this, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PopGroup();
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol('}', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mSection = holdSection;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
(*aAppendFunc)(aRule, aData);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a CSS2 media rule: "@media medium [, medium] { ... }"
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMediaRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-31 16:50:10 -07:00
|
|
|
nsRefPtr<nsMediaList> media = new nsMediaList();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!media) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (GatherMedia(media, '{')) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (rule && ParseGroupRule(rule, aAppendFunc, aData)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rule->SetMedia(media);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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().
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMozDocumentRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSDocumentRule::URL *urls = nsnull;
|
|
|
|
nsCSSDocumentRule::URL **next = &urls;
|
|
|
|
do {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSToken_Function != mToken.mType ||
|
|
|
|
!(mToken.mIdent.LowerCaseEqualsLiteral("url") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url-prefix") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("domain"))) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMozDocRuleBadFunc);
|
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSDocumentRule::URL *cur = *next = new nsCSSDocumentRule::URL;
|
|
|
|
if (!cur) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-05 17:45:49 -07:00
|
|
|
nsAutoString url;
|
|
|
|
if (!GetURLInParens(url)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEMozDocRuleNotURI);
|
|
|
|
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.
|
2009-08-05 17:45:49 -07:00
|
|
|
CopyUTF16toUTF8(url, cur->url);
|
2008-09-09 21:38:14 -07:00
|
|
|
} while (ExpectSymbol(',', PR_TRUE));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsCSSDocumentRule> rule(new nsCSSDocumentRule());
|
|
|
|
if (!rule) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete urls;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
rule->SetURLs(urls);
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseGroupRule(rule, aAppendFunc, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse a CSS3 namespace rule: "@namespace [prefix] STRING | URL;"
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseNameSpaceRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAtNSPrefixEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString prefix;
|
|
|
|
nsAutoString url;
|
|
|
|
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
prefix = mToken.mIdent;
|
2008-02-08 11:57:22 -08:00
|
|
|
// user-specified identifiers are case-sensitive (bug 416106)
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAtNSURIEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_String == mToken.mType) {
|
|
|
|
url = mToken.mIdent;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol(';', PR_TRUE)) {
|
|
|
|
ProcessNameSpace(prefix, url, aAppendFunc, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
else if ((eCSSToken_Function == mToken.mType) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("url"))) {
|
2009-08-05 17:45:49 -07:00
|
|
|
if (GetURLInParens(url) &&
|
|
|
|
ExpectSymbol(';', PR_TRUE)) {
|
|
|
|
ProcessNameSpace(prefix, url, aAppendFunc, aData);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-25 14:10:11 -07:00
|
|
|
else {
|
|
|
|
UngetToken();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAtNSUnexpected);
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-02-17 13:02:56 -08:00
|
|
|
void
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ProcessNameSpace(const nsString& aPrefix,
|
|
|
|
const nsString& aURLSpec,
|
|
|
|
RuleAppendFunc aAppendFunc,
|
|
|
|
void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> rule;
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
|
|
|
|
if (!aPrefix.IsEmpty()) {
|
|
|
|
prefix = do_GetAtom(aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NewCSSNameSpaceRule(getter_AddRefs(rule), prefix, aURLSpec);
|
|
|
|
if (rule) {
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
|
|
|
|
// If this was the first namespace rule encountered, it will trigger
|
|
|
|
// creation of a namespace map.
|
|
|
|
if (!mNameSpaceMap) {
|
|
|
|
mNameSpaceMap = mSheet->GetNameSpaceMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
// font-face-rule: '@font-face' '{' font-description '}'
|
|
|
|
// font-description: font-descriptor+
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontFaceRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-16 19:44:20 -08:00
|
|
|
if (!ExpectSymbol('{', PR_TRUE)) {
|
2009-02-11 20:15:56 -08:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadFontBlockStart);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-01-16 19:44:20 -08:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsCSSFontFaceRule> rule(new nsCSSFontFaceRule());
|
|
|
|
if (!rule) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2008-08-10 14:13:49 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEFontFaceEOF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mToken.IsSymbol('}')) { // done!
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore extra semicolons
|
|
|
|
if (mToken.IsSymbol(';'))
|
|
|
|
continue;
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseFontDescriptor(rule)) {
|
2008-08-10 14:13:49 -07:00
|
|
|
REPORT_UNEXPECTED(PEDeclSkipped);
|
|
|
|
OUTPUT_ERROR();
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!SkipDeclaration(PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-16 19:44:20 -08:00
|
|
|
if (!ExpectSymbol('}', PR_TRUE)) {
|
2009-02-11 20:15:56 -08:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadFontBlockEnd);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-01-16 19:44:20 -08:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
return PR_TRUE;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
// font-descriptor: font-family-desc
|
|
|
|
// | font-style-desc
|
|
|
|
// | font-weight-desc
|
|
|
|
// | font-stretch-desc
|
|
|
|
// | font-src-desc
|
|
|
|
// | unicode-range-desc
|
|
|
|
//
|
|
|
|
// All font-*-desc productions follow the pattern
|
|
|
|
// IDENT ':' value ';'
|
|
|
|
//
|
|
|
|
// On entry to this function, mToken is the IDENT.
|
|
|
|
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontDescriptor(nsCSSFontFaceRule* aRule)
|
2008-08-10 14:13:49 -07:00
|
|
|
{
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEFontDescExpected);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString descName = mToken.mIdent;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(':', PR_TRUE)) {
|
2008-08-10 14:13:49 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationNoColon);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(descName);
|
|
|
|
nsCSSValue value;
|
|
|
|
|
|
|
|
if (descID == eCSSFontDesc_UNKNOWN) {
|
|
|
|
if (NonMozillaVendorIdentifier(descName)) {
|
|
|
|
// silently skip other vendors' extensions
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipDeclaration(PR_TRUE);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
descName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownFontDesc, params);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseFontDescriptorValue(descID, value)) {
|
2008-08-10 14:13:49 -07:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
descName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEValueParsingError, params);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectEndProperty())
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
aRule->SetDesc(descID, value);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParsePageRule(RuleAppendFunc aAppendFunc, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX not yet implemented
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
void
|
|
|
|
CSSParserImpl::SkipUntil(PRUnichar aStopSymbol)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-03 13:11:35 -07:00
|
|
|
nsCSSToken* tk = &mToken;
|
2008-12-07 10:00:43 -08:00
|
|
|
nsAutoTArray<PRUnichar, 16> stack;
|
|
|
|
stack.AppendElement(aStopSymbol);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
2010-06-03 13:11:35 -07:00
|
|
|
PRUint32 stackTopIndex = stack.Length() - 1;
|
|
|
|
if (symbol == stack.ElementAt(stackTopIndex)) {
|
|
|
|
stack.RemoveElementAt(stackTopIndex);
|
2008-12-07 10:00:43 -08:00
|
|
|
if (stackTopIndex == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
|
|
|
|
// Just handle out-of-memory by parsing incorrectly. It's
|
|
|
|
// highly unlikely we're dealing with a legitimate style sheet
|
|
|
|
// anyway.
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('{' == symbol) {
|
2010-06-03 13:11:35 -07:00
|
|
|
stack.AppendElement('}');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('[' == symbol) {
|
2010-06-03 13:11:35 -07:00
|
|
|
stack.AppendElement(']');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('(' == symbol) {
|
2010-06-03 13:11:35 -07:00
|
|
|
stack.AppendElement(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
} else if (eCSSToken_Function == tk->mType) {
|
2010-06-03 13:11:35 -07:00
|
|
|
stack.AppendElement(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 11:44:56 -08:00
|
|
|
void
|
|
|
|
CSSParserImpl::SkipUntilOneOf(const PRUnichar* aStopSymbolChars)
|
|
|
|
{
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
nsDependentString stopSymbolChars(aStopSymbolChars);
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
|
|
|
if (stopSymbolChars.FindChar(symbol) != -1) {
|
|
|
|
break;
|
|
|
|
} else if ('{' == symbol) {
|
|
|
|
SkipUntil('}');
|
|
|
|
} else if ('[' == symbol) {
|
|
|
|
SkipUntil(']');
|
|
|
|
} else if ('(' == symbol) {
|
|
|
|
SkipUntil(')');
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
} else if (eCSSToken_Function == tk->mType) {
|
|
|
|
SkipUntil(')');
|
2008-11-02 11:44:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::SkipDeclaration(PRBool aCheckForBraces)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aCheckForBraces) {
|
|
|
|
REPORT_UNEXPECTED_EOF(PESkipDeclBraceEOF);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
|
|
|
if (';' == symbol) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aCheckForBraces) {
|
|
|
|
if ('}' == symbol) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ('{' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil('}');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('(' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('[' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(']');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
} else if (eCSSToken_Function == tk->mType) {
|
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
void
|
2009-08-19 06:11:30 -07:00
|
|
|
CSSParserImpl::SkipRuleSet(PRBool aInsideBraces)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PESkipRSBraceEOF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
PRUnichar symbol = tk->mSymbol;
|
2009-08-19 06:11:30 -07:00
|
|
|
if ('}' == symbol && aInsideBraces) {
|
|
|
|
// leave block closer for higher-level grammar to consume
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
} else if ('{' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil('}');
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2009-08-19 06:11:30 -07:00
|
|
|
} else if ('(' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if ('[' == symbol) {
|
2008-09-09 21:38:14 -07:00
|
|
|
SkipUntil(']');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
} else if (eCSSToken_Function == tk->mType) {
|
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::PushGroup(nsICSSGroupRule* aRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mGroupStack.AppendObject(aRule))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
void
|
|
|
|
CSSParserImpl::PopGroup(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 count = mGroupStack.Count();
|
|
|
|
if (0 < count) {
|
|
|
|
mGroupStack.RemoveObjectAt(count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
void
|
|
|
|
CSSParserImpl::AppendRule(nsICSSRule* aRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 count = mGroupStack.Count();
|
|
|
|
if (0 < count) {
|
|
|
|
mGroupStack[count - 1]->AppendStyleRule(aRule);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSheet->AppendStyleRule(aRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2009-08-19 06:11:30 -07:00
|
|
|
CSSParserImpl::ParseRuleSet(RuleAppendFunc aAppendFunc, void* aData,
|
|
|
|
PRBool aInsideBraces)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// First get the list of selectors for the rule
|
|
|
|
nsCSSSelectorList* slist = nsnull;
|
|
|
|
PRUint32 linenum = mScanner.GetLineNumber();
|
2010-04-23 19:59:47 -07:00
|
|
|
if (! ParseSelectorList(slist, PRUnichar('{'))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED(PEBadSelectorRSIgnored);
|
|
|
|
OUTPUT_ERROR();
|
2009-08-19 06:11:30 -07:00
|
|
|
SkipRuleSet(aInsideBraces);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(nsnull != slist, "null selector list");
|
|
|
|
CLEAR_ERROR();
|
|
|
|
|
|
|
|
// Next parse the declaration block
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* declaration = ParseDeclarationBlock(PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsnull == declaration) {
|
|
|
|
// XXX skip something here
|
|
|
|
delete slist;
|
|
|
|
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
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
nsCOMPtr<nsICSSStyleRule> rule = NS_NewCSSStyleRule(slist, declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
rule->SetLineNumber(linenum);
|
|
|
|
(*aAppendFunc)(rule, aData);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseSelectorList(nsCSSSelectorList*& aListHead,
|
2010-04-23 19:59:47 -07:00
|
|
|
PRUnichar aStopChar)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSSelectorList* list = nsnull;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! ParseSelectorGroup(list)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// must have at least one selector group
|
|
|
|
aListHead = nsnull;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(nsnull != list, "no selector list");
|
|
|
|
aListHead = list;
|
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
// After that there must either be a "," or a "{" (the latter if
|
2010-04-23 19:59:47 -07:00
|
|
|
// StopChar is nonzero)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2010-04-23 19:59:47 -07:00
|
|
|
if (aStopChar == PRUnichar(0)) {
|
2008-07-21 17:55:52 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PESelectorListExtraEOF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_Symbol == tk->mType) {
|
|
|
|
if (',' == tk->mSymbol) {
|
|
|
|
nsCSSSelectorList* newList = nsnull;
|
|
|
|
// Another selector group must follow
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! ParseSelectorGroup(newList)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// add new list to the end of the selector list
|
|
|
|
list->mNext = newList;
|
|
|
|
list = newList;
|
|
|
|
continue;
|
2010-04-23 19:59:47 -07:00
|
|
|
} else if (aStopChar == tk->mSymbol && aStopChar != PRUnichar(0)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PESelectorListExtra);
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete aListHead;
|
|
|
|
aListHead = nsnull;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
static PRBool IsUniversalSelector(const nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
return PRBool((aSelector.mNameSpace == kNameSpaceID_Unknown) &&
|
2009-08-01 08:53:40 -07:00
|
|
|
(aSelector.mLowercaseTag == nsnull) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aSelector.mIDList == nsnull) &&
|
|
|
|
(aSelector.mClassList == nsnull) &&
|
|
|
|
(aSelector.mAttrList == nsnull) &&
|
|
|
|
(aSelector.mNegations == nsnull) &&
|
2009-10-07 20:22:42 -07:00
|
|
|
(aSelector.mPseudoClassList == nsnull));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseSelectorGroup(nsCSSSelectorList*& aList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-31 11:08:09 -07:00
|
|
|
PRUnichar combinator = 0;
|
2010-03-31 11:08:08 -07:00
|
|
|
nsAutoPtr<nsCSSSelectorList> list(new nsCSSSelectorList());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-31 11:08:11 -07:00
|
|
|
for (;;) {
|
|
|
|
if (!ParseSelector(list, combinator)) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:08:08 -07:00
|
|
|
// Look for a combinator.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_FALSE)) {
|
2010-03-31 11:08:11 -07:00
|
|
|
break; // EOF ok here
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-31 11:08:11 -07:00
|
|
|
|
|
|
|
combinator = PRUnichar(0);
|
2010-03-31 11:08:08 -07:00
|
|
|
if (mToken.mType == eCSSToken_WhiteSpace) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2010-03-31 11:08:11 -07:00
|
|
|
break; // EOF ok here
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-31 11:08:09 -07:00
|
|
|
combinator = PRUnichar(' ');
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:08:11 -07:00
|
|
|
if (mToken.mType != eCSSToken_Symbol) {
|
|
|
|
UngetToken(); // not a combinator
|
2010-03-31 11:08:08 -07:00
|
|
|
} else {
|
2010-03-31 11:08:11 -07:00
|
|
|
PRUnichar symbol = mToken.mSymbol;
|
|
|
|
if (symbol == '+' || symbol == '>' || symbol == '~') {
|
|
|
|
combinator = mToken.mSymbol;
|
|
|
|
} else {
|
|
|
|
UngetToken(); // not a combinator
|
2010-04-23 19:59:47 -07:00
|
|
|
if (symbol == ',' || symbol == '{' || symbol == ')') {
|
2010-03-31 11:08:11 -07:00
|
|
|
break; // end of selector group
|
|
|
|
}
|
2007-07-23 18:48:10 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:08:11 -07:00
|
|
|
if (!combinator) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PESelectorListExtra);
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 18:48:10 -07:00
|
|
|
aList = list.forget();
|
2010-03-31 11:08:08 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07: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
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parses an ID selector #name
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseIDSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mToken.mIdent.IsEmpty(),
|
|
|
|
"Empty mIdent in eCSSToken_ID token?");
|
|
|
|
aDataMask |= SEL_MASK_ID;
|
|
|
|
aSelector.AddID(mToken.mIdent);
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parses a class selector .name
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseClassSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // get ident
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEClassSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) { // malformed selector
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEClassSelNotIdent);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
aDataMask |= SEL_MASK_CLASS;
|
|
|
|
|
|
|
|
aSelector.AddClass(mToken.mIdent);
|
|
|
|
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse a type element selector or a universal selector
|
|
|
|
// namespace|type or namespace|* or *|* or *
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseTypeOrUniversalSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
|
|
|
PRBool aIsNegated)
|
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
|
|
|
if (mToken.IsSymbol('*')) { // universal element selector, or universal namespace
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('|', PR_FALSE)) { // was namespace
|
2007-03-22 10:30:00 -07:00
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // namespace wildcard
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-09-28 23:07:45 -07:00
|
|
|
aSelector.SetTag(mToken.mIdent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was universal element selector
|
2008-07-21 17:55:52 -07:00
|
|
|
SetDefaultNamespaceOnSelector(aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
|
|
|
// don't set any tag in the selector
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof is ok (here!)
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Ident == mToken.mType) { // element name or namespace name
|
|
|
|
buffer = mToken.mIdent; // hang on to ident
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('|', PR_FALSE)) { // was namespace
|
2007-03-22 10:30:00 -07:00
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
2010-03-05 10:43:50 -08:00
|
|
|
PRInt32 nameSpaceID = GetNamespaceIdForPrefix(buffer);
|
|
|
|
if (nameSpaceID == kNameSpaceID_Unknown) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
aSelector.SetNameSpace(nameSpaceID);
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
2009-09-28 23:07:45 -07:00
|
|
|
aSelector.SetTag(mToken.mIdent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // was element name
|
2008-07-21 17:55:52 -07:00
|
|
|
SetDefaultNamespaceOnSelector(aSelector);
|
2009-09-28 23:07:45 -07:00
|
|
|
aSelector.SetTag(buffer);
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof is ok (here!)
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // No namespace
|
|
|
|
aDataMask |= SEL_MASK_NSPACE;
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_None); // explicit NO namespace
|
|
|
|
|
|
|
|
// get mandatory tag
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PETypeSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // element name
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
2009-09-28 23:07:45 -07:00
|
|
|
aSelector.SetTag(mToken.mIdent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('*')) { // universal selector
|
|
|
|
aDataMask |= SEL_MASK_ELEM;
|
|
|
|
// don't set tag
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PETypeSelNotType);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof is ok (here!)
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-07-21 17:55:52 -07:00
|
|
|
SetDefaultNamespaceOnSelector(aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsNegated) {
|
|
|
|
// restore last token read in case of a negated type selector
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse attribute selectors [attr], [attr=value], [attr|=value],
|
|
|
|
// [attr~=value], [attr^=value], [attr$=value] and [attr*=value]
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseAttributeSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nameSpaceID = kNameSpaceID_None;
|
|
|
|
nsAutoString attr;
|
|
|
|
if (mToken.IsSymbol('*')) { // wildcard namespace
|
|
|
|
nameSpaceID = kNameSpaceID_Unknown;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('|', PR_FALSE)) {
|
|
|
|
if (! GetToken(PR_FALSE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelNoBar);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // NO namespace
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Ident == mToken.mType) { // attr name or namespace
|
|
|
|
attr = mToken.mIdent; // hang on to it
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('|', PR_FALSE)) { // was a namespace
|
2010-03-05 10:43:50 -08:00
|
|
|
nameSpaceID = GetNamespaceIdForPrefix(attr);
|
|
|
|
if (nameSpaceID == kNameSpaceID_Unknown) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name
|
|
|
|
attr = mToken.mIdent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // malformed
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameOrNamespaceExpected);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelInnerEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Symbol == mToken.mType) ||
|
|
|
|
(eCSSToken_Includes == mToken.mType) ||
|
|
|
|
(eCSSToken_Dashmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Beginsmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Endsmatch == mToken.mType) ||
|
|
|
|
(eCSSToken_Containsmatch == mToken.mType)) {
|
|
|
|
PRUint8 func;
|
|
|
|
if (eCSSToken_Includes == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_INCLUDES;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Dashmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_DASHMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Beginsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_BEGINSMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Endsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_ENDSMATCH;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Containsmatch == mToken.mType) {
|
|
|
|
func = NS_ATTR_FUNC_CONTAINSMATCH;
|
|
|
|
}
|
|
|
|
else if (']' == mToken.mSymbol) {
|
|
|
|
aDataMask |= SEL_MASK_ATTRIB;
|
|
|
|
aSelector.AddAttribute(nameSpaceID, attr);
|
|
|
|
func = NS_ATTR_FUNC_SET;
|
|
|
|
}
|
|
|
|
else if ('=' == mToken.mSymbol) {
|
|
|
|
func = NS_ATTR_FUNC_EQUALS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelUnexpected);
|
|
|
|
UngetToken(); // bad function
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (NS_ATTR_FUNC_SET != func) { // get value
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelValueEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if ((eCSSToken_Ident == mToken.mType) || (eCSSToken_String == mToken.mType)) {
|
|
|
|
nsAutoString value(mToken.mIdent);
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature EOF
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEAttSelCloseEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (mToken.IsSymbol(']')) {
|
2007-07-10 16:23:05 -07:00
|
|
|
PRBool isCaseSensitive = PR_TRUE;
|
|
|
|
|
2009-09-28 23:07:45 -07:00
|
|
|
// For cases when this style sheet is applied to an HTML
|
|
|
|
// element in an HTML document, and the attribute selector is
|
|
|
|
// for a non-namespaced attribute, then check to see if it's
|
|
|
|
// one of the known attributes whose VALUE is
|
|
|
|
// case-insensitive.
|
|
|
|
if (nameSpaceID == kNameSpaceID_None) {
|
2007-07-10 16:23:05 -07:00
|
|
|
static const char* caseInsensitiveHTMLAttribute[] = {
|
2007-03-22 10:30:00 -07:00
|
|
|
// list based on http://www.w3.org/TR/html4/
|
2008-09-09 21:38:14 -07:00
|
|
|
"lang",
|
|
|
|
"dir",
|
|
|
|
"http-equiv",
|
|
|
|
"text",
|
|
|
|
"link",
|
|
|
|
"vlink",
|
|
|
|
"alink",
|
|
|
|
"compact",
|
|
|
|
"align",
|
|
|
|
"frame",
|
2007-07-10 16:23:05 -07:00
|
|
|
"rules",
|
2008-09-09 21:38:14 -07:00
|
|
|
"valign",
|
|
|
|
"scope",
|
|
|
|
"axis",
|
|
|
|
"nowrap",
|
|
|
|
"hreflang",
|
|
|
|
"rel",
|
|
|
|
"rev",
|
|
|
|
"charset",
|
|
|
|
"codetype",
|
2007-07-10 16:23:05 -07:00
|
|
|
"declare",
|
2008-09-09 21:38:14 -07:00
|
|
|
"valuetype",
|
|
|
|
"shape",
|
|
|
|
"nohref",
|
|
|
|
"media",
|
|
|
|
"bgcolor",
|
|
|
|
"clear",
|
|
|
|
"color",
|
|
|
|
"face",
|
2007-07-10 16:23:05 -07:00
|
|
|
"noshade",
|
2008-09-09 21:38:14 -07:00
|
|
|
"noresize",
|
|
|
|
"scrolling",
|
|
|
|
"target",
|
|
|
|
"method",
|
|
|
|
"enctype",
|
|
|
|
"accept-charset",
|
|
|
|
"accept",
|
2007-07-10 16:23:05 -07:00
|
|
|
"checked",
|
2008-09-09 21:38:14 -07:00
|
|
|
"multiple",
|
|
|
|
"selected",
|
|
|
|
"disabled",
|
|
|
|
"readonly",
|
|
|
|
"language",
|
|
|
|
"defer",
|
2007-07-10 16:23:05 -07:00
|
|
|
"type",
|
2008-07-12 03:30:39 -07:00
|
|
|
// additional attributes not in HTML4
|
|
|
|
"direction", // marquee
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
short i = 0;
|
|
|
|
const char* htmlAttr;
|
2007-07-10 16:23:05 -07:00
|
|
|
while ((htmlAttr = caseInsensitiveHTMLAttribute[i++])) {
|
2010-08-02 15:19:04 -07:00
|
|
|
if (attr.LowerCaseEqualsASCII(htmlAttr)) {
|
2007-07-10 16:23:05 -07:00
|
|
|
isCaseSensitive = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aDataMask |= SEL_MASK_ATTRIB;
|
|
|
|
aSelector.AddAttribute(nameSpaceID, attr, func, value, isCaseSensitive);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelNoClose);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelBadValue);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttSelUnexpected);
|
|
|
|
UngetToken(); // bad dog, no biscut!
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse pseudo-classes and pseudo-elements
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParsePseudoSelector(PRInt32& aDataMask,
|
|
|
|
nsCSSSelector& aSelector,
|
2009-10-07 20:22:42 -07:00
|
|
|
PRBool aIsNegated,
|
|
|
|
nsIAtom** aPseudoElement,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsPseudoClassList** aPseudoElementArgs,
|
|
|
|
nsCSSPseudoElements::Type* aPseudoElementType)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aIsNegated || (aPseudoElement && aPseudoElementArgs),
|
|
|
|
"expected location to store pseudo element");
|
|
|
|
NS_ASSERTION(!aIsNegated || (!aPseudoElement && !aPseudoElementArgs),
|
|
|
|
"negated selectors shouldn't have a place to store "
|
|
|
|
"pseudo elements");
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First, find out whether we are parsing a CSS3 pseudo-element
|
|
|
|
PRBool parsingPseudoElement = PR_FALSE;
|
|
|
|
if (mToken.IsSymbol(':')) {
|
|
|
|
parsingPseudoElement = PR_TRUE;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoSelEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do some sanity-checking on the token
|
|
|
|
if (eCSSToken_Ident != mToken.mType && eCSSToken_Function != mToken.mType) {
|
|
|
|
// malformed selector
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelBadName);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
buffer.Append(PRUnichar(':'));
|
|
|
|
buffer.Append(mToken.mIdent);
|
2010-08-02 15:19:04 -07:00
|
|
|
nsContentUtils::ASCIIToLower(buffer);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIAtom> pseudo = do_GetAtom(buffer);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!pseudo) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// stash away some info about this pseudo so we only have to get it once.
|
|
|
|
PRBool isTreePseudo = PR_FALSE;
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type pseudoElementType =
|
|
|
|
nsCSSPseudoElements::GetPseudoType(pseudo);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_XUL
|
2009-12-10 23:37:40 -08:00
|
|
|
isTreePseudo = (pseudoElementType == nsCSSPseudoElements::ePseudo_XULTree);
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
PRBool isTree = (eCSSToken_Function == mToken.mType) && isTreePseudo;
|
|
|
|
#endif
|
2009-12-10 23:37:40 -08:00
|
|
|
PRBool isPseudoElement =
|
|
|
|
(pseudoElementType < nsCSSPseudoElements::ePseudo_PseudoElementCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
// anonymous boxes are only allowed if they're the tree boxes or we have
|
|
|
|
// enabled unsafe rules
|
2009-12-10 23:37:40 -08:00
|
|
|
PRBool isAnonBox = isTreePseudo ||
|
|
|
|
(pseudoElementType == nsCSSPseudoElements::ePseudo_AnonBox &&
|
|
|
|
mUnsafeRulesEnabled);
|
2009-12-10 23:37:41 -08:00
|
|
|
nsCSSPseudoClasses::Type pseudoClassType =
|
|
|
|
nsCSSPseudoClasses::GetPseudoType(pseudo);
|
|
|
|
PRBool isPseudoClass =
|
|
|
|
(pseudoClassType != nsCSSPseudoClasses::ePseudoClass_NotPseudoClass);
|
2009-12-10 14:36:05 -08:00
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
NS_ASSERTION(!isPseudoClass ||
|
|
|
|
pseudoElementType == nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
"Why is this atom both a pseudo-class and a pseudo-element?");
|
|
|
|
NS_ASSERTION(isPseudoClass + isPseudoElement + isAnonBox <= 1,
|
|
|
|
"Shouldn't be more than one of these");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!isPseudoClass && !isPseudoElement && !isAnonBox) {
|
|
|
|
// Not a pseudo-class, not a pseudo-element.... forget it
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelUnknown);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) !=
|
|
|
|
(
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
isTree ||
|
|
|
|
#endif
|
|
|
|
nsCSSPseudoClasses::notPseudo == pseudo ||
|
2008-06-02 20:17:35 -07:00
|
|
|
nsCSSPseudoClasses::HasStringArg(pseudo) ||
|
2010-04-23 19:59:47 -07:00
|
|
|
nsCSSPseudoClasses::HasNthPairArg(pseudo) ||
|
|
|
|
nsCSSPseudoClasses::HasSelectorListArg(pseudo))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// There are no other function pseudos
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNonFunc);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If it starts with "::", it better be a pseudo-element
|
|
|
|
if (parsingPseudoElement &&
|
|
|
|
!isPseudoElement &&
|
|
|
|
!isAnonBox) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNotPE);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parsingPseudoElement && nsCSSPseudoClasses::notPseudo == pseudo) {
|
|
|
|
if (aIsNegated) { // :not() can't be itself negated
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelDoubleNot);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
// CSS 3 Negation pseudo-class takes one simple selector as argument
|
|
|
|
nsSelectorParsingStatus parsingStatus =
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseNegatedSimpleSelector(aDataMask, aSelector);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eSelectorParsingStatus_Continue != parsingStatus) {
|
|
|
|
return parsingStatus;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (!parsingPseudoElement && isPseudoClass) {
|
|
|
|
aDataMask |= SEL_MASK_PCLASS;
|
2010-04-23 19:59:47 -07:00
|
|
|
if (eCSSToken_Function == mToken.mType) {
|
|
|
|
nsSelectorParsingStatus parsingStatus;
|
|
|
|
if (nsCSSPseudoClasses::HasStringArg(pseudo)) {
|
|
|
|
parsingStatus =
|
|
|
|
ParsePseudoClassWithIdentArg(aSelector, pseudo, pseudoClassType);
|
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
else if (nsCSSPseudoClasses::HasNthPairArg(pseudo)) {
|
2010-04-23 19:59:47 -07:00
|
|
|
parsingStatus =
|
|
|
|
ParsePseudoClassWithNthPairArg(aSelector, pseudo, pseudoClassType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-23 19:59:47 -07:00
|
|
|
else {
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSPseudoClasses::HasSelectorListArg(pseudo),
|
|
|
|
"unexpected pseudo with function token");
|
|
|
|
parsingStatus = ParsePseudoClassWithSelectorListArg(aSelector, pseudo,
|
|
|
|
pseudoClassType);
|
|
|
|
}
|
2008-06-02 20:17:35 -07:00
|
|
|
if (eSelectorParsingStatus_Continue != parsingStatus) {
|
2010-04-23 19:59:47 -07:00
|
|
|
if (eSelectorParsingStatus_Error == parsingStatus) {
|
|
|
|
SkipUntil(')');
|
|
|
|
}
|
2008-06-02 20:17:35 -07:00
|
|
|
return parsingStatus;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else {
|
2009-12-10 23:37:41 -08:00
|
|
|
aSelector.AddPseudoClass(pseudo, pseudoClassType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isPseudoElement || isAnonBox) {
|
|
|
|
// Pseudo-element. Make some more sanity checks.
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIsNegated) { // pseudo-elements can't be negated
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelPEInNot);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
// 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.
|
|
|
|
if (!parsingPseudoElement &&
|
|
|
|
!nsCSSPseudoElements::IsCSS2PseudoElement(pseudo)
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
&& !isTreePseudo
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelNewStyleOnly);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == (aDataMask & SEL_MASK_PELEM)) {
|
|
|
|
aDataMask |= SEL_MASK_PELEM;
|
2009-10-07 20:22:42 -07:00
|
|
|
NS_ADDREF(*aPseudoElement = pseudo);
|
2009-12-10 23:37:40 -08:00
|
|
|
*aPseudoElementType = pseudoElementType;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (isTree) {
|
|
|
|
// We have encountered a pseudoelement of the form
|
|
|
|
// -moz-tree-xxxx(a,b,c). We parse (a,b,c) and add each
|
|
|
|
// item in the list to the pseudoclass list. They will be pulled
|
|
|
|
// from the list later along with the pseudo-element.
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!ParseTreePseudoElement(aPseudoElementArgs)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 11:08:08 -07:00
|
|
|
// the next *non*whitespace token must be '{' or ',' or EOF
|
|
|
|
if (!GetToken(PR_TRUE)) { // premature eof is ok (here!)
|
|
|
|
return eSelectorParsingStatus_Done;
|
|
|
|
}
|
|
|
|
if ((mToken.IsSymbol('{') || mToken.IsSymbol(','))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
2010-03-31 11:08:08 -07:00
|
|
|
return eSelectorParsingStatus_Done;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-31 11:08:08 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelTrailing);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else { // multiple pseudo elements, not legal
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoSelMultiplePE);
|
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse the argument of a negation pseudo-class :not()
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask,
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSSelector& aSelector)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature eof
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PENegationEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
2010-03-21 12:25:18 -07:00
|
|
|
if (mToken.IsSymbol(')')) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationBadArg);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2008-11-11 19:36:20 -08:00
|
|
|
// thing we need to change to support that is this parsing code and the
|
|
|
|
// serialization code for nsCSSSelector.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSSelector *newSel = new nsCSSSelector();
|
|
|
|
if (!newSel) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
nsCSSSelector* negations = &aSelector;
|
|
|
|
while (negations->mNegations) {
|
|
|
|
negations = negations->mNegations;
|
|
|
|
}
|
|
|
|
negations->mNegations = newSel;
|
|
|
|
|
|
|
|
nsSelectorParsingStatus parsingStatus;
|
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
2008-09-09 21:38:14 -07:00
|
|
|
parsingStatus = ParseIDSelector(aDataMask, *newSel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
2008-09-09 21:38:14 -07:00
|
|
|
parsingStatus = ParseClassSelector(aDataMask, *newSel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
2009-10-07 20:22:42 -07:00
|
|
|
parsingStatus = ParsePseudoSelector(aDataMask, *newSel, PR_TRUE,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsnull, nsnull, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('[')) { // [attribute
|
2008-09-09 21:38:14 -07:00
|
|
|
parsingStatus = ParseAttributeSelector(aDataMask, *newSel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// then it should be a type element or universal selector
|
2008-09-09 21:38:14 -07:00
|
|
|
parsingStatus = ParseTypeOrUniversalSelector(aDataMask, *newSel, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (eSelectorParsingStatus_Error == parsingStatus) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationBadInner);
|
2010-08-15 05:42:29 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
return parsingStatus;
|
|
|
|
}
|
|
|
|
// close the parenthesis
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PENegationNoClose);
|
2010-08-15 05:42:29 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
2008-11-11 19:36:20 -08:00
|
|
|
NS_ASSERTION(newSel->mNameSpace == kNameSpaceID_Unknown ||
|
|
|
|
(!newSel->mIDList && !newSel->mClassList &&
|
|
|
|
!newSel->mPseudoClassList && !newSel->mAttrList),
|
|
|
|
"Need to fix the serialization code to deal with this");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse the argument of a pseudo-class that has an ident arg
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParsePseudoClassWithIdentArg(nsCSSSelector& aSelector,
|
2009-12-10 23:37:41 -08:00
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) { // premature eof
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
// We expect an identifier with a language abbreviation
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotIdent);
|
|
|
|
UngetToken();
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-29 11:33:53 -07:00
|
|
|
// -moz-locale-dir can only have values of 'ltr' or 'rtl'.
|
|
|
|
if (aPseudo == nsCSSPseudoClasses::mozLocaleDir) {
|
|
|
|
if (!mToken.mIdent.EqualsLiteral("ltr") &&
|
|
|
|
!mToken.mIdent.EqualsLiteral("rtl")) {
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2009-07-29 11:33:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Add the pseudo with the language parameter
|
2009-12-10 23:37:41 -08:00
|
|
|
aSelector.AddPseudoClass(aPseudo, aType, mToken.mIdent.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// close the parenthesis
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassNoClose);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return eSelectorParsingStatus_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParsePseudoClassWithNthPairArg(nsCSSSelector& aSelector,
|
2009-12-10 23:37:41 -08:00
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType)
|
2008-06-02 20:17:35 -07:00
|
|
|
{
|
|
|
|
PRInt32 numbers[2] = { 0, 0 };
|
|
|
|
PRBool lookForB = PR_TRUE;
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
// Follow the whitespace rules as proposed in
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2008Mar/0121.html
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2008-06-02 20:17:35 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eCSSToken_Ident == mToken.mType || eCSSToken_Dimension == mToken.mType) {
|
|
|
|
// The CSS tokenization doesn't handle :nth-child() containing - well:
|
|
|
|
// 2n-1 is a dimension
|
|
|
|
// n-1 is an identifier
|
|
|
|
// The easiest way to deal with that is to push everything from the
|
|
|
|
// minus on back onto the scanner's pushback buffer.
|
|
|
|
PRUint32 truncAt = 0;
|
|
|
|
if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("n-"))) {
|
|
|
|
truncAt = 1;
|
|
|
|
} else if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("-n-"))) {
|
|
|
|
truncAt = 2;
|
|
|
|
}
|
|
|
|
if (truncAt != 0) {
|
|
|
|
for (PRUint32 i = mToken.mIdent.Length() - 1; i >= truncAt; --i) {
|
|
|
|
mScanner.Pushback(mToken.mIdent[i]);
|
|
|
|
}
|
|
|
|
mToken.mIdent.Truncate(truncAt);
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
2010-08-02 15:19:04 -07:00
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("odd")) {
|
2008-06-02 20:17:35 -07:00
|
|
|
numbers[0] = 2;
|
|
|
|
numbers[1] = 1;
|
|
|
|
lookForB = PR_FALSE;
|
|
|
|
}
|
2010-08-02 15:19:04 -07:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("even")) {
|
2008-06-02 20:17:35 -07:00
|
|
|
numbers[0] = 2;
|
|
|
|
numbers[1] = 0;
|
|
|
|
lookForB = PR_FALSE;
|
|
|
|
}
|
2010-08-02 15:19:04 -07:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("n")) {
|
2008-06-02 20:17:35 -07:00
|
|
|
numbers[0] = 1;
|
|
|
|
}
|
2010-08-02 15:19:04 -07:00
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("-n")) {
|
2008-06-02 20:17:35 -07:00
|
|
|
numbers[0] = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotNth);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Number == mToken.mType) {
|
|
|
|
if (!mToken.mIntegerValid) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotNth);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
numbers[1] = mToken.mInteger;
|
|
|
|
lookForB = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (eCSSToken_Dimension == mToken.mType) {
|
2010-08-02 15:19:04 -07:00
|
|
|
if (!mToken.mIntegerValid || !mToken.mIdent.LowerCaseEqualsLiteral("n")) {
|
2008-06-02 20:17:35 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotNth);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
numbers[0] = mToken.mInteger;
|
|
|
|
}
|
|
|
|
// XXX If it's a ')', is that valid? (as 0n+0)
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotNth);
|
2010-04-23 19:59:47 -07:00
|
|
|
UngetToken();
|
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2008-06-02 20:17:35 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
if (lookForB && !mToken.IsSymbol(')')) {
|
|
|
|
// The '+' or '-' sign can optionally be separated by whitespace.
|
|
|
|
// If it is separated by whitespace from what follows it, it appears
|
|
|
|
// as a separate token rather than part of the number token.
|
|
|
|
PRBool haveSign = PR_FALSE;
|
|
|
|
PRInt32 sign = 1;
|
|
|
|
if (mToken.IsSymbol('+') || mToken.IsSymbol('-')) {
|
|
|
|
haveSign = PR_TRUE;
|
|
|
|
if (mToken.IsSymbol('-')) {
|
|
|
|
sign = -1;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2008-06-02 20:17:35 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eCSSToken_Number != mToken.mType ||
|
|
|
|
!mToken.mIntegerValid || mToken.mHasSign == haveSign) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassArgNotNth);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
|
|
|
numbers[1] = mToken.mInteger * sign;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2008-06-02 20:17:35 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
|
|
|
|
return eSelectorParsingStatus_Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mToken.IsSymbol(')')) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassNoClose);
|
2010-04-23 19:59:47 -07:00
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
2008-06-02 20:17:35 -07:00
|
|
|
}
|
2009-12-10 23:37:41 -08:00
|
|
|
aSelector.AddPseudoClass(aPseudo, aType, numbers);
|
2007-03-22 10:30:00 -07:00
|
|
|
return eSelectorParsingStatus_Continue;
|
2010-04-23 19:59:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse the argument of a pseudo-class that has a selector list argument.
|
|
|
|
// Such selector lists cannot contain combinators, but can contain
|
|
|
|
// anything that goes between a pair of combinators.
|
|
|
|
//
|
|
|
|
CSSParserImpl::nsSelectorParsingStatus
|
|
|
|
CSSParserImpl::ParsePseudoClassWithSelectorListArg(nsCSSSelector& aSelector,
|
|
|
|
nsIAtom* aPseudo,
|
|
|
|
nsCSSPseudoClasses::Type aType)
|
|
|
|
{
|
|
|
|
nsAutoPtr<nsCSSSelectorList> slist;
|
|
|
|
if (! ParseSelectorList(*getter_Transfers(slist), PRUnichar(')'))) {
|
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that none of the selectors in the list have combinators or
|
|
|
|
// pseudo-elements.
|
|
|
|
for (nsCSSSelectorList *l = slist; l; l = l->mNext) {
|
|
|
|
nsCSSSelector *s = l->mSelectors;
|
|
|
|
if (s->mNext || s->IsPseudoElement()) {
|
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the pseudo with the selector list parameter
|
|
|
|
aSelector.AddPseudoClass(aPseudo, aType, slist.forget());
|
|
|
|
|
|
|
|
// close the parenthesis
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEPseudoClassNoClose);
|
|
|
|
return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
|
|
|
|
}
|
|
|
|
|
|
|
|
return eSelectorParsingStatus_Continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-02 20:17:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* This is the format for selectors:
|
|
|
|
* operator? [[namespace |]? element_name]? [ ID | class | attrib | pseudo ]*
|
|
|
|
*/
|
2010-03-31 11:08:11 -07:00
|
|
|
PRBool
|
2010-03-31 11:08:09 -07:00
|
|
|
CSSParserImpl::ParseSelector(nsCSSSelectorList* aList,
|
|
|
|
PRUnichar aPrevCombinator)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PESelectorEOF);
|
2010-03-31 11:08:11 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:08:09 -07:00
|
|
|
nsCSSSelector* selector = aList->AddSelector(aPrevCombinator);
|
2010-03-31 11:08:08 -07:00
|
|
|
nsCOMPtr<nsIAtom> pseudoElement;
|
|
|
|
nsAutoPtr<nsPseudoClassList> pseudoElementArgs;
|
|
|
|
nsCSSPseudoElements::Type pseudoElementType =
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 dataMask = 0;
|
|
|
|
nsSelectorParsingStatus parsingStatus =
|
2010-03-31 11:08:08 -07:00
|
|
|
ParseTypeOrUniversalSelector(dataMask, *selector, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-31 11:08:08 -07:00
|
|
|
while (parsingStatus == eSelectorParsingStatus_Continue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSToken_ID == mToken.mType) { // #id
|
2010-03-31 11:08:08 -07:00
|
|
|
parsingStatus = ParseIDSelector(dataMask, *selector);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('.')) { // .class
|
2010-03-31 11:08:08 -07:00
|
|
|
parsingStatus = ParseClassSelector(dataMask, *selector);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol(':')) { // :pseudo
|
2010-03-31 11:08:08 -07:00
|
|
|
parsingStatus = ParsePseudoSelector(dataMask, *selector, PR_FALSE,
|
|
|
|
getter_AddRefs(pseudoElement),
|
|
|
|
getter_Transfers(pseudoElementArgs),
|
|
|
|
&pseudoElementType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('[')) { // [attribute
|
2010-03-31 11:08:08 -07:00
|
|
|
parsingStatus = ParseAttributeSelector(dataMask, *selector);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else { // not a selector token, we're done
|
|
|
|
parsingStatus = eSelectorParsingStatus_Done;
|
2010-03-31 11:08:08 -07:00
|
|
|
UngetToken();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsingStatus != eSelectorParsingStatus_Continue) {
|
2010-03-31 11:08:08 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_FALSE)) { // premature eof is ok (here!)
|
2010-03-31 11:08:08 -07:00
|
|
|
parsingStatus = eSelectorParsingStatus_Done;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-03-31 11:08:08 -07:00
|
|
|
|
|
|
|
if (parsingStatus == eSelectorParsingStatus_Error) {
|
2010-03-31 11:08:11 -07:00
|
|
|
return PR_FALSE;
|
2010-03-31 11:08:08 -07:00
|
|
|
}
|
2010-03-31 11:08:11 -07:00
|
|
|
|
2010-03-31 11:08:08 -07:00
|
|
|
if (!dataMask) {
|
2010-03-31 11:08:11 -07:00
|
|
|
if (selector->mNext) {
|
|
|
|
REPORT_UNEXPECTED(PESelectorGroupExtraCombinator);
|
|
|
|
} else {
|
|
|
|
REPORT_UNEXPECTED(PESelectorGroupNoSelector);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2010-03-31 11:08:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pseudoElementType == nsCSSPseudoElements::ePseudo_AnonBox) {
|
|
|
|
// We got an anonymous box pseudo-element; it must be the only
|
|
|
|
// thing in this selector group.
|
2010-03-31 11:08:09 -07:00
|
|
|
if (selector->mNext || !IsUniversalSelector(*selector)) {
|
2010-03-31 11:08:08 -07:00
|
|
|
REPORT_UNEXPECTED(PEAnonBoxNotAlone);
|
2010-03-31 11:08:11 -07:00
|
|
|
return PR_FALSE;
|
2010-03-31 11:08:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite the current selector as this pseudo-element.
|
|
|
|
// It does not contribute to selector weight.
|
|
|
|
selector->mLowercaseTag.swap(pseudoElement);
|
|
|
|
selector->mPseudoClassList = pseudoElementArgs.forget();
|
|
|
|
selector->SetPseudoType(pseudoElementType);
|
2010-03-31 11:08:11 -07:00
|
|
|
return PR_TRUE;
|
2010-03-31 11:08:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
aList->mWeight += selector->CalcWeight();
|
|
|
|
|
|
|
|
// Pseudo-elements other than anonymous boxes are represented as
|
|
|
|
// direct children ('>' combinator) of the rest of the selector.
|
|
|
|
if (pseudoElement) {
|
2010-03-31 11:08:09 -07:00
|
|
|
selector = aList->AddSelector('>');
|
|
|
|
|
|
|
|
selector->mLowercaseTag.swap(pseudoElement);
|
|
|
|
selector->mPseudoClassList = pseudoElementArgs.forget();
|
|
|
|
selector->SetPseudoType(pseudoElementType);
|
2010-03-31 11:08:08 -07:00
|
|
|
}
|
|
|
|
|
2010-03-31 11:08:11 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration*
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseDeclarationBlock(PRBool aCheckForBraces)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aCheckForBraces) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol('{', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclBlockStart);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* declaration = new css::Declaration();
|
2007-03-22 10:30:00 -07:00
|
|
|
mData.AssertInitialState();
|
|
|
|
if (declaration) {
|
|
|
|
for (;;) {
|
|
|
|
PRBool changed;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseDeclaration(declaration, aCheckForBraces,
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_TRUE, &changed)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!SkipDeclaration(aCheckForBraces)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aCheckForBraces) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('}', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Since the skipped declaration didn't end the block we parse
|
|
|
|
// the next declaration.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
declaration->CompressFrom(&mData);
|
|
|
|
}
|
|
|
|
return declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseColor(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
nscolor rgba;
|
|
|
|
switch (tk->mType) {
|
|
|
|
case eCSSToken_ID:
|
|
|
|
case eCSSToken_Ref:
|
|
|
|
// #xxyyzz
|
|
|
|
if (NS_HexToRGB(tk->mIdent, &rgba)) {
|
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Ident:
|
|
|
|
if (NS_ColorNameToRGB(tk->mIdent, &rgba)) {
|
2009-03-05 20:05:01 -08:00
|
|
|
aValue.SetStringValue(tk->mIdent, eCSSUnit_Ident);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) { // known keyword
|
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kColorKTable, value)) {
|
2008-02-08 11:51:41 -08:00
|
|
|
aValue.SetIntValue(value, eCSSUnit_EnumColor);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eCSSToken_Function:
|
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("rgb")) {
|
|
|
|
// rgb ( component , component , component )
|
|
|
|
PRUint8 r, g, b;
|
|
|
|
PRInt32 type = COLOR_TYPE_UNKNOWN;
|
2010-01-27 16:20:04 -08:00
|
|
|
if (ParseColorComponent(r, type, ',') &&
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseColorComponent(g, type, ',') &&
|
|
|
|
ParseColorComponent(b, type, ')')) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.SetColorValue(NS_RGB(r,g,b));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2010-08-11 12:32:52 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-rgba") ||
|
2008-02-21 00:37:27 -08:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("rgba")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// rgba ( component , component , component , opacity )
|
|
|
|
PRUint8 r, g, b, a;
|
|
|
|
PRInt32 type = COLOR_TYPE_UNKNOWN;
|
2010-01-27 16:20:04 -08:00
|
|
|
if (ParseColorComponent(r, type, ',') &&
|
2008-09-09 21:38:14 -07:00
|
|
|
ParseColorComponent(g, type, ',') &&
|
|
|
|
ParseColorComponent(b, type, ',') &&
|
|
|
|
ParseColorOpacity(a)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.SetColorValue(NS_RGBA(r, g, b, a));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2010-08-11 12:32:52 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("hsl")) {
|
|
|
|
// hsl ( hue , saturation , lightness )
|
|
|
|
// "hue" is a number, "saturation" and "lightness" are percentages.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseHSLColor(rgba, ')')) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.SetColorValue(rgba);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2010-08-11 12:32:52 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-hsla") ||
|
2008-02-21 00:37:27 -08:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("hsla")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// hsla ( hue , saturation , lightness , opacity )
|
|
|
|
// "hue" is a number, "saturation" and "lightness" are percentages,
|
|
|
|
// "opacity" is a number.
|
|
|
|
PRUint8 a;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseHSLColor(rgba, ',') &&
|
|
|
|
ParseColorOpacity(a)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.SetColorValue(NS_RGBA(NS_GET_R(rgba), NS_GET_G(rgba),
|
|
|
|
NS_GET_B(rgba), a));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2010-08-11 12:32:52 -07:00
|
|
|
SkipUntil(')');
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try 'xxyyzz' without '#' prefix for compatibility with IE and Nav4x (bug 23236 and 45804)
|
|
|
|
if (mNavQuirkMode && !IsParsingCompoundProperty()) {
|
|
|
|
// - 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) {
|
|
|
|
PR_snprintf(buffer, sizeof(buffer), "%06d", tk->mInteger);
|
|
|
|
str.AssignWithConversion(buffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
if (tk->mIdent.Length() <= 6) {
|
|
|
|
PR_snprintf(buffer, sizeof(buffer), "%06.0f", tk->mNumber);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's not a color
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEColorNotColor);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aType will be set if we have already parsed other color components
|
|
|
|
// in this color spec
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseColorComponent(PRUint8& aComponent,
|
|
|
|
PRInt32& aType,
|
|
|
|
char aStop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorComponentEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
float value;
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
switch (tk->mType) {
|
|
|
|
case eCSSToken_Number:
|
|
|
|
switch (aType) {
|
|
|
|
case COLOR_TYPE_UNKNOWN:
|
|
|
|
aType = COLOR_TYPE_INTEGERS;
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_INTEGERS:
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_PERCENTAGES:
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Someone forgot to add the new color component type in here");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mToken.mIntegerValid) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedInt);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
value = tk->mNumber;
|
|
|
|
break;
|
|
|
|
case eCSSToken_Percentage:
|
|
|
|
switch (aType) {
|
|
|
|
case COLOR_TYPE_UNKNOWN:
|
|
|
|
aType = COLOR_TYPE_PERCENTAGES;
|
|
|
|
break;
|
|
|
|
case COLOR_TYPE_INTEGERS:
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedInt);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
case COLOR_TYPE_PERCENTAGES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Someone forgot to add the new color component type in here");
|
|
|
|
}
|
|
|
|
value = tk->mNumber * 255.0f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEColorBadRGBContents);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol(aStop, PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (value < 0.0f) value = 0.0f;
|
|
|
|
if (value > 255.0f) value = 255.0f;
|
2007-04-22 15:03:30 -07:00
|
|
|
aComponent = NSToIntRound(value);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
const PRUnichar stopString[] = { PRUnichar(aStop), PRUnichar(0) };
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
nsnull,
|
|
|
|
stopString
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_TOKEN_P(PEColorComponentBadTerm, params);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseHSLColor(nscolor& aColor,
|
|
|
|
char aStop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
float h, s, l;
|
|
|
|
|
|
|
|
// Get the hue
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorHueEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Number) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedNumber);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
h = mToken.mNumber;
|
|
|
|
h /= 360.0f;
|
|
|
|
// hue values are wraparound
|
|
|
|
h = h - floor(h);
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedComma);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the saturation
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorSaturationEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Percentage) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
s = mToken.mNumber;
|
|
|
|
if (s < 0.0f) s = 0.0f;
|
|
|
|
if (s > 1.0f) s = 1.0f;
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedComma);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the lightness
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorLightnessEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mToken.mType != eCSSToken_Percentage) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedPercent);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
l = mToken.mNumber;
|
|
|
|
if (l < 0.0f) l = 0.0f;
|
|
|
|
if (l > 1.0f) l = 1.0f;
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (ExpectSymbol(aStop, PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aColor = NS_HSL2RGB(h, s, l);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const PRUnichar stopString[] = { PRUnichar(aStop), PRUnichar(0) };
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
nsnull,
|
|
|
|
stopString
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_TOKEN_P(PEColorComponentBadTerm, params);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseColorOpacity(PRUint8& aOpacity)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_EOF(PEColorOpacityEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mToken.mType != eCSSToken_Number) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedNumber);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-30 20:50:31 -07:00
|
|
|
if (mToken.mNumber < 0.0f) {
|
|
|
|
mToken.mNumber = 0.0f;
|
|
|
|
} else if (mToken.mNumber > 1.0f) {
|
|
|
|
mToken.mNumber = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint8 value = nsStyleUtil::FloatToColorComponent(mToken.mNumber);
|
2009-07-04 02:30:59 -07:00
|
|
|
// Need to compare to something slightly larger
|
|
|
|
// than 0.5 due to floating point inaccuracies.
|
|
|
|
NS_ASSERTION(fabs(255.0f*mToken.mNumber - value) <= 0.51f,
|
2007-04-30 20:50:31 -07:00
|
|
|
"FloatToColorComponent did something weird");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedCloseParen);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-04-30 20:50:31 -07:00
|
|
|
aOpacity = value;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2009-10-07 20:22:42 -07:00
|
|
|
CSSParserImpl::ParseTreePseudoElement(nsPseudoClassList **aPseudoElementArgs)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:22:42 -07:00
|
|
|
// The argument to a tree pseudo-element is a sequence of identifiers
|
|
|
|
// that are either space- or comma-separated. (Was the intent to
|
|
|
|
// allow only comma-separated? That's not what was done.)
|
2009-10-07 20:22:42 -07:00
|
|
|
nsCSSSelector fakeSelector; // so we can reuse AddPseudoClass
|
2010-01-27 16:20:04 -08:00
|
|
|
|
|
|
|
while (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
nsCOMPtr<nsIAtom> pseudo = do_GetAtom(mToken.mIdent);
|
|
|
|
fakeSelector.AddPseudoClass(pseudo,
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_NotPseudoClass);
|
|
|
|
}
|
|
|
|
else if (!mToken.IsSymbol(',')) {
|
2010-01-27 16:20:05 -08:00
|
|
|
UngetToken();
|
2010-01-27 16:20:04 -08:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
*aPseudoElementArgs = fakeSelector.mPseudoClassList;
|
|
|
|
fakeSelector.mPseudoClassList = nsnull;
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
PRBool
|
2010-06-28 15:49:35 -07:00
|
|
|
CSSParserImpl::ParseDeclaration(css::Declaration* aDeclaration,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aCheckForBraces,
|
|
|
|
PRBool aMustCallValueAppended,
|
|
|
|
PRBool* aChanged)
|
|
|
|
{
|
|
|
|
mTempData.AssertInitialState();
|
|
|
|
|
|
|
|
// Get property name
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
nsAutoString propertyName;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aCheckForBraces) {
|
|
|
|
REPORT_UNEXPECTED_EOF(PEDeclEndEOF);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == tk->mType) {
|
|
|
|
propertyName = tk->mIdent;
|
|
|
|
// grab the ident before the ExpectSymbol trashes the token
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(':', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationNoColon);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tk->IsSymbol(';')) {
|
|
|
|
// dangling semicolons are skipped
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tk->IsSymbol('}')) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationDeclExpected);
|
|
|
|
REPORT_UNEXPECTED(PEDeclSkipped);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
}
|
|
|
|
// Not a declaration...
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-03 21:58:27 -07:00
|
|
|
// Map property name to its ID and then parse the property
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProperty propID = nsCSSProps::LookupProperty(propertyName);
|
|
|
|
if (eCSSProperty_UNKNOWN == propID) { // unknown property
|
2007-10-03 21:58:27 -07:00
|
|
|
if (!NonMozillaVendorIdentifier(propertyName)) {
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propertyName.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownProperty, params);
|
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! ParseProperty(propID)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX Much better to put stuff in the value parsers instead...
|
|
|
|
const PRUnichar *params[] = {
|
|
|
|
propertyName.get()
|
|
|
|
};
|
2008-08-10 14:13:49 -07:00
|
|
|
REPORT_UNEXPECTED_P(PEValueParsingError, params);
|
2007-03-22 10:30:00 -07:00
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
2010-07-23 11:00:42 -07:00
|
|
|
mTempData.ClearProperty(propID);
|
|
|
|
mTempData.AssertInitialState();
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
CLEAR_ERROR();
|
|
|
|
|
2010-07-23 11:00:37 -07:00
|
|
|
// Look for "!important".
|
|
|
|
PriorityParsingStatus status = ParsePriority();
|
2007-08-02 14:20:11 -07:00
|
|
|
|
2010-07-23 11:00:37 -07:00
|
|
|
// Look for a semicolon or close brace.
|
|
|
|
if (status != ePriority_Error) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2010-07-23 11:00:37 -07:00
|
|
|
// EOF is always ok
|
|
|
|
} else if (mToken.IsSymbol(';')) {
|
|
|
|
// semicolon is always ok
|
|
|
|
} else if (mToken.IsSymbol('}')) {
|
|
|
|
// brace is ok if aCheckForBraces, but don't eat it
|
2007-08-10 15:17:20 -07:00
|
|
|
UngetToken();
|
2010-07-23 11:00:37 -07:00
|
|
|
if (!aCheckForBraces) {
|
|
|
|
status = ePriority_Error;
|
|
|
|
}
|
|
|
|
} else {
|
2010-08-04 12:27:05 -07:00
|
|
|
UngetToken();
|
2010-07-23 11:00:37 -07:00
|
|
|
status = ePriority_Error;
|
2007-08-10 15:17:20 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:37 -07:00
|
|
|
if (status == ePriority_Error) {
|
|
|
|
if (aCheckForBraces) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEBadDeclOrRuleEnd2);
|
|
|
|
} else {
|
|
|
|
REPORT_UNEXPECTED(PEBadDeclEnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-23 11:00:37 -07:00
|
|
|
REPORT_UNEXPECTED(PEDeclDropped);
|
|
|
|
OUTPUT_ERROR();
|
2010-07-23 11:00:42 -07:00
|
|
|
mTempData.ClearProperty(propID);
|
|
|
|
mTempData.AssertInitialState();
|
2010-07-23 11:00:37 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-23 11:00:37 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
*aChanged |= mData.TransferFromBlock(mTempData, propID,
|
|
|
|
status == ePriority_Important,
|
|
|
|
PR_FALSE, aMustCallValueAppended,
|
|
|
|
aDeclaration);
|
2010-07-23 11:00:37 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const nsCSSProperty kBorderTopIDs[] = {
|
|
|
|
eCSSProperty_border_top_width,
|
|
|
|
eCSSProperty_border_top_style,
|
|
|
|
eCSSProperty_border_top_color
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderRightIDs[] = {
|
2007-07-04 11:51:16 -07:00
|
|
|
eCSSProperty_border_right_width_value,
|
|
|
|
eCSSProperty_border_right_style_value,
|
|
|
|
eCSSProperty_border_right_color_value,
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSProperty_border_right_width,
|
|
|
|
eCSSProperty_border_right_style,
|
|
|
|
eCSSProperty_border_right_color
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderBottomIDs[] = {
|
|
|
|
eCSSProperty_border_bottom_width,
|
|
|
|
eCSSProperty_border_bottom_style,
|
|
|
|
eCSSProperty_border_bottom_color
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderLeftIDs[] = {
|
2007-07-04 11:51:16 -07:00
|
|
|
eCSSProperty_border_left_width_value,
|
|
|
|
eCSSProperty_border_left_style_value,
|
|
|
|
eCSSProperty_border_left_color_value,
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSProperty_border_left_width,
|
|
|
|
eCSSProperty_border_left_style,
|
|
|
|
eCSSProperty_border_left_color
|
|
|
|
};
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kBorderStartIDs[] = {
|
|
|
|
eCSSProperty_border_start_width_value,
|
|
|
|
eCSSProperty_border_start_style_value,
|
|
|
|
eCSSProperty_border_start_color_value,
|
|
|
|
eCSSProperty_border_start_width,
|
|
|
|
eCSSProperty_border_start_style,
|
|
|
|
eCSSProperty_border_start_color
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderEndIDs[] = {
|
|
|
|
eCSSProperty_border_end_width_value,
|
|
|
|
eCSSProperty_border_end_style_value,
|
|
|
|
eCSSProperty_border_end_color_value,
|
|
|
|
eCSSProperty_border_end_width,
|
|
|
|
eCSSProperty_border_end_style,
|
|
|
|
eCSSProperty_border_end_color
|
|
|
|
};
|
2008-07-19 03:38:25 -07:00
|
|
|
static const nsCSSProperty kColumnRuleIDs[] = {
|
|
|
|
eCSSProperty__moz_column_rule_width,
|
|
|
|
eCSSProperty__moz_column_rule_style,
|
|
|
|
eCSSProperty__moz_column_rule_color
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseEnum(nsCSSValue& aValue,
|
|
|
|
const PRInt32 aKeywordTable[])
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
nsSubstring* ident = NextIdent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsnull == ident) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(*ident);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) {
|
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) {
|
|
|
|
aValue.SetIntValue(value, eCSSUnit_Enumerated);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the unknown identifier back and return
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct UnitInfo {
|
2010-08-13 02:58:02 -07:00
|
|
|
char name[6]; // needs to be long enough for the longest unit, with
|
2007-03-22 10:30:00 -07:00
|
|
|
// terminating null.
|
|
|
|
PRUint32 length;
|
|
|
|
nsCSSUnit unit;
|
|
|
|
PRInt32 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define STR_WITH_LEN(_str) \
|
|
|
|
_str, sizeof(_str) - 1
|
|
|
|
|
|
|
|
const UnitInfo UnitData[] = {
|
|
|
|
{ STR_WITH_LEN("px"), eCSSUnit_Pixel, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("em"), eCSSUnit_EM, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("ex"), eCSSUnit_XHeight, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("pt"), eCSSUnit_Point, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("in"), eCSSUnit_Inch, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("cm"), eCSSUnit_Centimeter, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("ch"), eCSSUnit_Char, VARIANT_LENGTH },
|
2009-01-20 13:58:48 -08:00
|
|
|
{ STR_WITH_LEN("rem"), eCSSUnit_RootEM, VARIANT_LENGTH },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ STR_WITH_LEN("mm"), eCSSUnit_Millimeter, VARIANT_LENGTH },
|
2010-08-13 02:58:02 -07:00
|
|
|
{ STR_WITH_LEN("mozmm"), eCSSUnit_PhysicalMillimeter, VARIANT_LENGTH },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ STR_WITH_LEN("pc"), eCSSUnit_Pica, VARIANT_LENGTH },
|
|
|
|
{ STR_WITH_LEN("deg"), eCSSUnit_Degree, VARIANT_ANGLE },
|
|
|
|
{ STR_WITH_LEN("grad"), eCSSUnit_Grad, VARIANT_ANGLE },
|
|
|
|
{ STR_WITH_LEN("rad"), eCSSUnit_Radian, VARIANT_ANGLE },
|
|
|
|
{ STR_WITH_LEN("hz"), eCSSUnit_Hertz, VARIANT_FREQUENCY },
|
|
|
|
{ STR_WITH_LEN("khz"), eCSSUnit_Kilohertz, VARIANT_FREQUENCY },
|
|
|
|
{ STR_WITH_LEN("s"), eCSSUnit_Seconds, VARIANT_TIME },
|
|
|
|
{ STR_WITH_LEN("ms"), eCSSUnit_Milliseconds, VARIANT_TIME }
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef STR_WITH_LEN
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::TranslateDimension(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
float aNumber,
|
|
|
|
const nsString& aUnit)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSUnit units;
|
|
|
|
PRInt32 type = 0;
|
|
|
|
if (!aUnit.IsEmpty()) {
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < NS_ARRAY_LENGTH(UnitData); ++i) {
|
|
|
|
if (aUnit.LowerCaseEqualsASCII(UnitData[i].name,
|
|
|
|
UnitData[i].length)) {
|
|
|
|
units = UnitData[i].unit;
|
|
|
|
type = UnitData[i].type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == NS_ARRAY_LENGTH(UnitData)) {
|
|
|
|
// Unknown unit
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Must be a zero number...
|
|
|
|
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) {
|
2009-11-04 18:36:18 -08:00
|
|
|
NS_ASSERTION(aVariantMask & VARIANT_ZERO_ANGLE,
|
|
|
|
"must have allowed zero angle");
|
2007-03-22 10:30:00 -07:00
|
|
|
units = eCSSUnit_Degree;
|
|
|
|
type = VARIANT_ANGLE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("Variant mask does not include dimension; why were we called?");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((type & aVariantMask) != 0) {
|
|
|
|
aValue.SetFloatValue(aNumber, units);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
// Note that this does include VARIANT_CALC, which is numeric. This is
|
|
|
|
// because calc() parsing, as proposed, drops range restrictions inside
|
|
|
|
// the calc() expression and clamps the result of the calculation to the
|
|
|
|
// range.
|
2009-03-09 16:14:34 -07:00
|
|
|
#define VARIANT_ALL_NONNUMERIC \
|
|
|
|
VARIANT_KEYWORD | \
|
|
|
|
VARIANT_COLOR | \
|
|
|
|
VARIANT_URL | \
|
|
|
|
VARIANT_STRING | \
|
|
|
|
VARIANT_COUNTER | \
|
|
|
|
VARIANT_ATTR | \
|
|
|
|
VARIANT_IDENTIFIER | \
|
|
|
|
VARIANT_AUTO | \
|
|
|
|
VARIANT_INHERIT | \
|
|
|
|
VARIANT_NONE | \
|
|
|
|
VARIANT_NORMAL | \
|
2009-08-20 14:52:47 -07:00
|
|
|
VARIANT_SYSFONT | \
|
|
|
|
VARIANT_GRADIENT | \
|
|
|
|
VARIANT_CUBIC_BEZIER | \
|
2010-05-11 08:49:43 -07:00
|
|
|
VARIANT_ALL | \
|
2010-07-02 21:18:56 -07:00
|
|
|
VARIANT_CALC | \
|
|
|
|
VARIANT_CALC_NO_MIN_MAX
|
2009-03-09 16:14:34 -07:00
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
// Note that callers passing VARIANT_CALC in aVariantMask will get
|
|
|
|
// full-range parsing inside the calc() expression, and the code that
|
|
|
|
// computes the calc will be required to clamp the resulting value to an
|
|
|
|
// appropriate range.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2009-03-09 16:14:34 -07:00
|
|
|
CSSParserImpl::ParseNonNegativeVariant(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[])
|
2008-09-09 21:38:14 -07:00
|
|
|
{
|
2009-03-09 16:14:34 -07:00
|
|
|
// The variant mask must only contain non-numeric variants or the ones
|
|
|
|
// that we specifically handle.
|
|
|
|
NS_ABORT_IF_FALSE((aVariantMask & ~(VARIANT_ALL_NONNUMERIC |
|
|
|
|
VARIANT_NUMBER |
|
|
|
|
VARIANT_LENGTH |
|
|
|
|
VARIANT_PERCENT |
|
|
|
|
VARIANT_INTEGER)) == 0,
|
|
|
|
"need to update code below to handle additional variants");
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseVariant(aValue, aVariantMask, aKeywordTable)) {
|
|
|
|
if (eCSSUnit_Number == aValue.GetUnit() ||
|
|
|
|
aValue.IsLengthUnit()){
|
|
|
|
if (aValue.GetFloatValue() < 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
else if (aValue.GetUnit() == eCSSUnit_Percent) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (aValue.GetPercentValue() < 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
} else if (aValue.GetUnit() == eCSSUnit_Integer) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (aValue.GetIntValue() < 0) {
|
2008-07-26 09:14:48 -07:00
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
// Note that callers passing VARIANT_CALC in aVariantMask will get
|
|
|
|
// full-range parsing inside the calc() expression, and the code that
|
|
|
|
// computes the calc will be required to clamp the resulting value to an
|
|
|
|
// appropriate range.
|
2009-03-09 16:14:34 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParsePositiveNonZeroVariant(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[])
|
|
|
|
{
|
|
|
|
// The variant mask must only contain non-numeric variants or the ones
|
|
|
|
// that we specifically handle.
|
|
|
|
NS_ABORT_IF_FALSE((aVariantMask & ~(VARIANT_ALL_NONNUMERIC |
|
|
|
|
VARIANT_INTEGER)) == 0,
|
|
|
|
"need to update code below to handle additional variants");
|
|
|
|
|
|
|
|
if (ParseVariant(aValue, aVariantMask, aKeywordTable)) {
|
|
|
|
if (aValue.GetUnit() == eCSSUnit_Integer) {
|
|
|
|
if (aValue.GetIntValue() <= 0) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Assigns to aValue iff it returns PR_TRUE.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseVariant(nsCSSValue& aValue,
|
|
|
|
PRInt32 aVariantMask,
|
|
|
|
const PRInt32 aKeywordTable[])
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
NS_ASSERTION(IsParsingCompoundProperty() ||
|
2007-03-22 10:30:00 -07:00
|
|
|
((~aVariantMask) & (VARIANT_LENGTH|VARIANT_COLOR)),
|
|
|
|
"cannot distinguish lengths and colors in quirks mode");
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSToken* tk = &mToken;
|
2009-08-20 14:52:47 -07:00
|
|
|
if (((aVariantMask & (VARIANT_AHK | VARIANT_NORMAL | VARIANT_NONE | VARIANT_ALL)) != 0) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(eCSSToken_Ident == tk->mType)) {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
|
|
|
if (eCSSKeyword_UNKNOWN < keyword) { // known keyword
|
|
|
|
if ((aVariantMask & VARIANT_AUTO) != 0) {
|
|
|
|
if (eCSSKeyword_auto == keyword) {
|
|
|
|
aValue.SetAutoValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((aVariantMask & VARIANT_INHERIT) != 0) {
|
2007-06-12 11:28:56 -07:00
|
|
|
// XXX Should we check IsParsingCompoundProperty, or do all
|
|
|
|
// callers handle it? (Not all callers set it, though, since
|
|
|
|
// they want the quirks that are disabled by setting it.)
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSKeyword_inherit == keyword) {
|
|
|
|
aValue.SetInheritValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (eCSSKeyword__moz_initial == keyword) { // anything that can inherit can also take an initial val.
|
|
|
|
aValue.SetInitialValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((aVariantMask & VARIANT_NONE) != 0) {
|
|
|
|
if (eCSSKeyword_none == keyword) {
|
|
|
|
aValue.SetNoneValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
if ((aVariantMask & VARIANT_ALL) != 0) {
|
|
|
|
if (eCSSKeyword_all == keyword) {
|
|
|
|
aValue.SetAllValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((aVariantMask & VARIANT_NORMAL) != 0) {
|
|
|
|
if (eCSSKeyword_normal == keyword) {
|
|
|
|
aValue.SetNormalValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-06-12 11:28:56 -07:00
|
|
|
if ((aVariantMask & VARIANT_SYSFONT) != 0) {
|
|
|
|
if (eCSSKeyword__moz_use_system_font == keyword &&
|
|
|
|
!IsParsingCompoundProperty()) {
|
|
|
|
aValue.SetSystemFontValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((aVariantMask & VARIANT_KEYWORD) != 0) {
|
|
|
|
PRInt32 value;
|
|
|
|
if (nsCSSProps::FindKeyword(keyword, aKeywordTable, value)) {
|
|
|
|
aValue.SetIntValue(value, eCSSUnit_Enumerated);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-04 18:36:18 -08:00
|
|
|
if (((aVariantMask & (VARIANT_LENGTH | VARIANT_ANGLE |
|
|
|
|
VARIANT_FREQUENCY | VARIANT_TIME)) != 0 &&
|
|
|
|
eCSSToken_Dimension == tk->mType) ||
|
|
|
|
((aVariantMask & (VARIANT_LENGTH | VARIANT_ZERO_ANGLE)) != 0 &&
|
|
|
|
eCSSToken_Number == tk->mType &&
|
|
|
|
tk->mNumber == 0.0f)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (TranslateDimension(aValue, aVariantMask, tk->mNumber, tk->mIdent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// Put the token back; we didn't parse it, so we shouldn't consume it
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_PERCENT) != 0) &&
|
|
|
|
(eCSSToken_Percentage == tk->mType)) {
|
|
|
|
aValue.SetPercentValue(tk->mNumber);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_NUMBER) != 0) &&
|
|
|
|
(eCSSToken_Number == tk->mType)) {
|
|
|
|
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Number);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_INTEGER) != 0) &&
|
|
|
|
(eCSSToken_Number == tk->mType) && tk->mIntegerValid) {
|
|
|
|
aValue.SetIntValue(tk->mInteger, eCSSUnit_Integer);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (mNavQuirkMode && !IsParsingCompoundProperty()) { // NONSTANDARD: Nav interprets unitless numbers as px
|
|
|
|
if (((aVariantMask & VARIANT_LENGTH) != 0) &&
|
|
|
|
(eCSSToken_Number == tk->mType)) {
|
|
|
|
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Pixel);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
2008-08-12 07:02:22 -07:00
|
|
|
if (IsSVGMode() && !IsParsingCompoundProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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
|
|
|
|
|
|
|
|
if (((aVariantMask & VARIANT_URL) != 0) &&
|
2008-09-09 21:38:14 -07:00
|
|
|
(eCSSToken_Function == tk->mType) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("url")) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseURL(aValue)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
if ((aVariantMask & VARIANT_GRADIENT) != 0 &&
|
|
|
|
eCSSToken_Function == tk->mType) {
|
|
|
|
// a generated gradient
|
|
|
|
if (tk->mIdent.LowerCaseEqualsLiteral("-moz-linear-gradient"))
|
2009-11-02 11:36:43 -08:00
|
|
|
return ParseGradient(aValue, PR_FALSE, PR_FALSE);
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
if (tk->mIdent.LowerCaseEqualsLiteral("-moz-radial-gradient"))
|
2009-11-02 11:36:43 -08:00
|
|
|
return ParseGradient(aValue, PR_TRUE, PR_FALSE);
|
|
|
|
|
|
|
|
if (tk->mIdent.LowerCaseEqualsLiteral("-moz-repeating-linear-gradient"))
|
|
|
|
return ParseGradient(aValue, PR_FALSE, PR_TRUE);
|
|
|
|
|
|
|
|
if (tk->mIdent.LowerCaseEqualsLiteral("-moz-repeating-radial-gradient"))
|
|
|
|
return ParseGradient(aValue, PR_TRUE, PR_TRUE);
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
2009-08-21 13:39:25 -07:00
|
|
|
if ((aVariantMask & VARIANT_IMAGE_RECT) != 0 &&
|
|
|
|
eCSSToken_Function == tk->mType &&
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-image-rect")) {
|
|
|
|
return ParseImageRect(aValue);
|
|
|
|
}
|
2010-08-13 06:33:37 -07:00
|
|
|
if ((aVariantMask & VARIANT_ELEMENT) != 0 &&
|
|
|
|
eCSSToken_Function == tk->mType &&
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-element")) {
|
|
|
|
return ParseElement(aValue);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((aVariantMask & VARIANT_COLOR) != 0) {
|
|
|
|
if ((mNavQuirkMode && !IsParsingCompoundProperty()) || // NONSTANDARD: Nav interprets 'xxyyzz' values even without '#' prefix
|
2008-09-09 21:38:14 -07:00
|
|
|
(eCSSToken_ID == tk->mType) ||
|
|
|
|
(eCSSToken_Ref == tk->mType) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(eCSSToken_Ident == tk->mType) ||
|
2008-09-09 21:38:14 -07:00
|
|
|
((eCSSToken_Function == tk->mType) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(tk->mIdent.LowerCaseEqualsLiteral("rgb") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("hsl") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-rgba") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-hsla") ||
|
2008-02-21 00:37:27 -08:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("rgba") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("hsla"))))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Put token back so that parse color can get it
|
|
|
|
UngetToken();
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseColor(aValue)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (((aVariantMask & VARIANT_STRING) != 0) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(eCSSToken_String == tk->mType)) {
|
|
|
|
nsAutoString buffer;
|
|
|
|
buffer.Append(tk->mIdent);
|
|
|
|
aValue.SetStringValue(buffer, eCSSUnit_String);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (((aVariantMask & VARIANT_IDENTIFIER) != 0) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(eCSSToken_Ident == tk->mType)) {
|
2009-03-05 20:05:01 -08:00
|
|
|
aValue.SetStringValue(tk->mIdent, eCSSUnit_Ident);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_COUNTER) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
2008-09-09 21:38:14 -07:00
|
|
|
(tk->mIdent.LowerCaseEqualsLiteral("counter") ||
|
2007-03-22 10:30:00 -07:00
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("counters"))) {
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseCounter(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (((aVariantMask & VARIANT_ATTR) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("attr")) {
|
2010-08-11 12:32:52 -07:00
|
|
|
if (!ParseAttr(aValue)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
if (((aVariantMask & VARIANT_CUBIC_BEZIER) != 0) &&
|
|
|
|
(eCSSToken_Function == tk->mType)) {
|
|
|
|
if (tk->mIdent.LowerCaseEqualsLiteral("cubic-bezier")) {
|
2010-08-11 12:32:52 -07:00
|
|
|
if (!ParseTransitionTimingFunctionValues(aValue)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-11 08:49:43 -07:00
|
|
|
if ((aVariantMask & VARIANT_CALC) &&
|
|
|
|
(eCSSToken_Function == tk->mType) &&
|
|
|
|
(tk->mIdent.LowerCaseEqualsLiteral("-moz-calc") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-min") ||
|
|
|
|
tk->mIdent.LowerCaseEqualsLiteral("-moz-max"))) {
|
|
|
|
// calc() currently allows only lengths and percents inside it.
|
2010-07-02 21:18:56 -07:00
|
|
|
return ParseCalc(aValue,
|
|
|
|
aVariantMask & (VARIANT_LP | VARIANT_CALC_NO_MIN_MAX));
|
2010-05-11 08:49:43 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCounter(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
nsCSSUnit unit = (mToken.mIdent.LowerCaseEqualsLiteral("counter") ?
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSUnit_Counter : eCSSUnit_Counters);
|
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
// A non-iterative for loop to break out when an error occurs.
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident != mToken.mType) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
nsRefPtr<nsCSSValue::Array> val =
|
|
|
|
nsCSSValue::Array::Create(unit == eCSSUnit_Counter ? 2 : 3);
|
|
|
|
if (!val) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
val->Item(0).SetStringValue(mToken.mIdent, eCSSUnit_Ident);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
if (eCSSUnit_Counters == unit) {
|
|
|
|
// must have a comma and then a separator string
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE) || !GetToken(PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (eCSSToken_String != mToken.mType) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
val->Item(1).SetStringValue(mToken.mIdent, eCSSUnit_String);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
// get optional type
|
|
|
|
PRInt32 type = NS_STYLE_LIST_STYLE_DECIMAL;
|
|
|
|
if (ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCSSKeyword keyword;
|
|
|
|
if (eCSSToken_Ident != mToken.mType ||
|
|
|
|
(keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent)) ==
|
|
|
|
eCSSKeyword_UNKNOWN ||
|
|
|
|
!nsCSSProps::FindKeyword(keyword, nsCSSProps::kListStyleKTable,
|
|
|
|
type)) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:05 -08:00
|
|
|
|
|
|
|
PRInt32 typeItem = eCSSUnit_Counters == unit ? 2 : 1;
|
|
|
|
val->Item(typeItem).SetIntValue(type, eCSSUnit_Enumerated);
|
|
|
|
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
aValue.SetArrayValue(val, unit);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-27 16:20:05 -08:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseAttr(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-27 16:20:04 -08:00
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString attr;
|
|
|
|
if (eCSSToken_Ident == mToken.mType) { // attr name or namespace
|
|
|
|
nsAutoString holdIdent(mToken.mIdent);
|
|
|
|
if (ExpectSymbol('|', PR_FALSE)) { // namespace
|
2010-03-05 10:43:50 -08:00
|
|
|
PRInt32 nameSpaceID = GetNamespaceIdForPrefix(holdIdent);
|
|
|
|
if (nameSpaceID == kNameSpaceID_Unknown) {
|
2010-01-27 16:20:04 -08:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
attr.AppendInt(nameSpaceID, 10);
|
|
|
|
attr.Append(PRUnichar('|'));
|
|
|
|
if (! GetToken(PR_FALSE)) {
|
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
attr.Append(mToken.mIdent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-01-27 16:20:04 -08:00
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
}
|
|
|
|
else { // no namespace
|
|
|
|
attr = holdIdent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-01-27 16:20:04 -08:00
|
|
|
else if (mToken.IsSymbol('*')) { // namespace wildcard
|
|
|
|
// Wildcard namespace makes no sense here and is not allowed
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (mToken.IsSymbol('|')) { // explicit NO namespace
|
|
|
|
if (! GetToken(PR_FALSE)) {
|
|
|
|
REPORT_UNEXPECTED_EOF(PEAttributeNameEOF);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
attr.Append(mToken.mIdent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameExpected);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEAttributeNameOrNamespaceExpected);
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
aValue.SetStringValue(attr, eCSSUnit_Attr);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
PRBool
|
2009-08-21 13:39:25 -07:00
|
|
|
CSSParserImpl::SetValueToURL(nsCSSValue& aValue, const nsString& aURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-02 18:15:53 -07:00
|
|
|
if (!mSheetPrincipal) {
|
|
|
|
NS_NOTREACHED("Codepaths that expect to parse URLs MUST pass in an "
|
|
|
|
"origin principal");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
// Translate url into an absolute url if the url is relative to the
|
|
|
|
// style sheet.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2010-03-02 12:59:32 -08:00
|
|
|
NS_NewURI(getter_AddRefs(uri), aURL, nsnull, mBaseURI);
|
2008-08-10 14:13:49 -07:00
|
|
|
|
2009-08-21 13:39:25 -07:00
|
|
|
nsStringBuffer* buffer = nsCSSValue::BufferFromString(aURL);
|
2008-08-10 14:13:49 -07:00
|
|
|
if (NS_UNLIKELY(!buffer)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
nsCSSValue::URL *urlVal =
|
2010-03-02 12:59:32 -08:00
|
|
|
new nsCSSValue::URL(uri, buffer, mSheetURI, mSheetPrincipal);
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
buffer->Release();
|
|
|
|
if (NS_UNLIKELY(!urlVal)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
aValue.SetURLValue(urlVal);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 13:39:25 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseURL(nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
nsAutoString url;
|
|
|
|
if (!GetURLInParens(url))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return SetValueToURL(aValue, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the arguments of -moz-image-rect() function.
|
|
|
|
* -moz-image-rect(<uri>, <top>, <right>, <bottom>, <left>)
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseImageRect(nsCSSValue& aImage)
|
|
|
|
{
|
|
|
|
// A non-iterative for loop to break out when an error occurs.
|
|
|
|
for (;;) {
|
|
|
|
nsCSSValue newFunction;
|
|
|
|
static const PRUint32 kNumArgs = 5;
|
|
|
|
nsCSSValue::Array* func =
|
|
|
|
newFunction.InitFunction(eCSSKeyword__moz_image_rect, kNumArgs);
|
|
|
|
if (!func) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// func->Item(0) is reserved for the function name.
|
|
|
|
nsCSSValue& url = func->Item(1);
|
|
|
|
nsCSSValue& top = func->Item(2);
|
|
|
|
nsCSSValue& right = func->Item(3);
|
|
|
|
nsCSSValue& bottom = func->Item(4);
|
|
|
|
nsCSSValue& left = func->Item(5);
|
|
|
|
|
|
|
|
if (!GetToken(PR_TRUE))
|
|
|
|
break;
|
|
|
|
if (mToken.mType == eCSSToken_String) {
|
|
|
|
if (!SetValueToURL(url, mToken.mIdent))
|
|
|
|
break;
|
|
|
|
} else if (mToken.mType == eCSSToken_Function &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url")) {
|
|
|
|
if (!ParseURL(url))
|
|
|
|
break;
|
|
|
|
} else {
|
2010-01-27 16:20:05 -08:00
|
|
|
UngetToken();
|
2009-08-21 13:39:25 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
static const PRInt32 VARIANT_SIDE = VARIANT_NUMBER | VARIANT_PERCENT;
|
|
|
|
if (!ParseNonNegativeVariant(top, VARIANT_SIDE, nsnull) ||
|
|
|
|
!ExpectSymbol(',', PR_TRUE) ||
|
|
|
|
!ParseNonNegativeVariant(right, VARIANT_SIDE, nsnull) ||
|
|
|
|
!ExpectSymbol(',', PR_TRUE) ||
|
|
|
|
!ParseNonNegativeVariant(bottom, VARIANT_SIDE, nsnull) ||
|
|
|
|
!ExpectSymbol(',', PR_TRUE) ||
|
|
|
|
!ParseNonNegativeVariant(left, VARIANT_SIDE, nsnull) ||
|
|
|
|
!ExpectSymbol(')', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
aImage = newFunction;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-13 06:33:37 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <element>: -moz-element(# <element_id> )
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseElement(nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
// A non-iterative for loop to break out when an error occurs.
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (mToken.mType == eCSSToken_ID) {
|
|
|
|
aValue.SetStringValue(mToken.mIdent, eCSSUnit_Element);
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-21 13:39:25 -07:00
|
|
|
// If we detect a syntax error, we must match the opening parenthesis of the
|
|
|
|
// function with the closing parenthesis and skip all the tokens in between.
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// <color-stop> : <color> [ <percentage> | <length> ]?
|
2009-08-01 08:53:40 -07:00
|
|
|
PRBool
|
2009-11-02 11:36:43 -08:00
|
|
|
CSSParserImpl::ParseColorStop(nsCSSValueGradient* aGradient)
|
2009-08-01 08:53:40 -07:00
|
|
|
{
|
2009-11-02 11:36:43 -08:00
|
|
|
nsCSSValueGradientStop* stop = aGradient->mStops.AppendElement();
|
|
|
|
if (!stop) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2009-08-01 08:53:40 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
if (!ParseVariant(stop->mColor, VARIANT_COLOR, nsnull)) {
|
|
|
|
return PR_FALSE;
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// Stop positions do not have to fall between the starting-point and
|
|
|
|
// ending-point, so we don't use ParseNonNegativeVariant.
|
|
|
|
if (!ParseVariant(stop->mLocation, VARIANT_LP, nsnull)) {
|
|
|
|
stop->mLocation.SetNoneValue();
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
2009-11-02 11:36:43 -08:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// <gradient>
|
|
|
|
// : linear-gradient( <gradient-line>? <color-stops> ')'
|
|
|
|
// : radial-gradient( <gradient-line>? <gradient-shape-size>?
|
|
|
|
// <color-stops> ')'
|
|
|
|
//
|
|
|
|
// <gradient-line> : [<bg-position> || <angle>] ,
|
|
|
|
//
|
|
|
|
// <gradient-shape-size> : [<gradient-shape> || <gradient-size>] ,
|
|
|
|
// <gradient-shape> : circle | ellipse
|
|
|
|
// <gradient-size> : closest-side | closest-corner
|
|
|
|
// | farthest-side | farthest-corner
|
|
|
|
// | contain | cover
|
|
|
|
//
|
|
|
|
// <color-stops> : <color-stop> , <color-stop> [, <color-stop>]*
|
2009-08-01 08:53:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
2009-11-02 11:36:43 -08:00
|
|
|
CSSParserImpl::ParseGradient(nsCSSValue& aValue, PRBool aIsRadial,
|
|
|
|
PRBool aIsRepeating)
|
2009-08-01 08:53:40 -07:00
|
|
|
{
|
2009-11-02 11:36:43 -08:00
|
|
|
nsRefPtr<nsCSSValueGradient> cssGradient
|
|
|
|
= new nsCSSValueGradient(aIsRadial, aIsRepeating);
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// <gradient-line>
|
|
|
|
// N.B. ParseBoxPositionValues is not guaranteed to put back
|
|
|
|
// everything it scanned if it fails, so we must only call it
|
|
|
|
// if there is no alternative to consuming a <box-position>.
|
|
|
|
// ParseVariant, as used here, will either succeed and consume
|
|
|
|
// a single token, or fail and consume none, so we can be more
|
|
|
|
// cavalier about calling it.
|
|
|
|
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
2009-08-01 08:53:40 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-11-02 11:36:43 -08:00
|
|
|
nsCSSTokenType ty = mToken.mType;
|
|
|
|
nsString id = mToken.mIdent;
|
|
|
|
UngetToken();
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
PRBool haveGradientLine = PR_FALSE;
|
|
|
|
switch (ty) {
|
|
|
|
case eCSSToken_Percentage:
|
|
|
|
case eCSSToken_Number:
|
|
|
|
case eCSSToken_Dimension:
|
|
|
|
haveGradientLine = PR_TRUE;
|
|
|
|
break;
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
case eCSSToken_Function:
|
|
|
|
case eCSSToken_ID:
|
|
|
|
case eCSSToken_Ref:
|
|
|
|
// this is a color
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSToken_Ident: {
|
|
|
|
// This is only a gradient line if it's a box position keyword.
|
|
|
|
nsCSSKeyword kw = nsCSSKeywords::LookupKeyword(id);
|
|
|
|
PRInt32 junk;
|
|
|
|
if (kw != eCSSKeyword_UNKNOWN &&
|
|
|
|
nsCSSProps::FindKeyword(kw, nsCSSProps::kBackgroundPositionKTable,
|
|
|
|
junk)) {
|
|
|
|
haveGradientLine = PR_TRUE;
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
2009-11-02 11:36:43 -08:00
|
|
|
break;
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
default:
|
|
|
|
// error
|
2009-08-01 08:53:40 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
if (haveGradientLine) {
|
|
|
|
PRBool haveAngle =
|
|
|
|
ParseVariant(cssGradient->mAngle, VARIANT_ANGLE, nsnull);
|
|
|
|
|
|
|
|
// if we got an angle, we might now have a comma, ending the gradient-line
|
|
|
|
if (!haveAngle || !ExpectSymbol(',', PR_TRUE)) {
|
2010-08-19 12:33:43 -07:00
|
|
|
if (!ParseBoxPositionValues(cssGradient->mBgPos, PR_FALSE)) {
|
2009-11-02 11:36:43 -08:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE) &&
|
|
|
|
// if we didn't already get an angle, we might have one now,
|
|
|
|
// otherwise it's an error
|
|
|
|
(haveAngle ||
|
|
|
|
!ParseVariant(cssGradient->mAngle, VARIANT_ANGLE, nsnull) ||
|
|
|
|
// now we better have a comma
|
|
|
|
!ExpectSymbol(',', PR_TRUE))) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
}
|
2009-11-02 11:36:43 -08:00
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// radial gradients might have a <gradient-shape-size> here
|
|
|
|
if (aIsRadial) {
|
|
|
|
PRBool haveShape =
|
|
|
|
ParseVariant(cssGradient->mRadialShape, VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kRadialGradientShapeKTable);
|
|
|
|
PRBool haveSize =
|
|
|
|
ParseVariant(cssGradient->mRadialSize, VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kRadialGradientSizeKTable);
|
|
|
|
|
|
|
|
// could be in either order
|
|
|
|
if (!haveShape) {
|
|
|
|
haveShape =
|
|
|
|
ParseVariant(cssGradient->mRadialShape, VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kRadialGradientShapeKTable);
|
|
|
|
}
|
|
|
|
if ((haveShape || haveSize) && !ExpectSymbol(',', PR_TRUE)) {
|
2009-08-01 08:53:40 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// At least two color stops are required
|
|
|
|
if (!ParseColorStop(cssGradient) ||
|
|
|
|
!ExpectSymbol(',', PR_TRUE) ||
|
|
|
|
!ParseColorStop(cssGradient)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-08-01 08:53:40 -07:00
|
|
|
|
2009-11-02 11:36:43 -08:00
|
|
|
// Additional color stops
|
2009-08-01 08:53:40 -07:00
|
|
|
while (ExpectSymbol(',', PR_TRUE)) {
|
2009-11-02 11:36:43 -08:00
|
|
|
if (!ParseColorStop(cssGradient)) {
|
2009-08-01 08:53:40 -07:00
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aValue.SetGradientValue(cssGradient);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32
|
|
|
|
CSSParserImpl::ParseChoice(nsCSSValue aValues[],
|
|
|
|
const nsCSSProperty aPropIDs[], PRInt32 aNumIDs)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRInt32 found = 0;
|
|
|
|
nsAutoParseCompoundProperty compound(this);
|
|
|
|
|
|
|
|
PRInt32 loop;
|
|
|
|
for (loop = 0; loop < aNumIDs; loop++) {
|
|
|
|
// Try each property parser in order
|
|
|
|
PRInt32 hadFound = found;
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < aNumIDs; index++) {
|
|
|
|
PRInt32 bit = 1 << index;
|
|
|
|
if ((found & bit) == 0) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(aValues[index], aPropIDs[index])) {
|
2007-03-22 10:30:00 -07:00
|
|
|
found |= bit;
|
2009-01-22 17:28:13 -08:00
|
|
|
// It's more efficient to break since it will reset |hadFound|
|
|
|
|
// to |found|. Furthermore, ParseListStyle depends on our going
|
|
|
|
// through the properties in order for each value..
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found == hadFound) { // found nothing new
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Initial == aValues[0].GetUnit()) { // one initial, all initial
|
|
|
|
for (loop = 1; loop < aNumIDs; loop++) {
|
|
|
|
aValues[loop].SetInitialValue();
|
|
|
|
}
|
|
|
|
found = ((1 << aNumIDs) - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // more than one value, verify no inherits or initials
|
|
|
|
for (loop = 0; loop < aNumIDs; loop++) {
|
|
|
|
if (eCSSUnit_Inherit == aValues[loop].GetUnit()) {
|
|
|
|
found = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Initial == aValues[loop].GetUnit()) {
|
|
|
|
found = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::AppendValue(nsCSSProperty aPropID, const nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
mTempData.AddLonghandProperty(aPropID, aValue);
|
2007-03-22 10:30:00 -07: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
|
2008-09-09 21:38:14 -07:00
|
|
|
* existing values.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseBoxProperties(const nsCSSProperty aPropIDs[])
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get up to four values for the property
|
|
|
|
PRInt32 count = 0;
|
|
|
|
nsCSSRect result;
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_SIDES (index) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! ParseSingleValueProperty(result.*(nsCSSRect::sides[index]),
|
2007-03-22 10:30:00 -07:00
|
|
|
aPropIDs[index])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if ((count == 0) || (PR_FALSE == ExpectEndProperty())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 < count) { // verify no more than single inherit or initial
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_SIDES (index) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSUnit unit = (result.*(nsCSSRect::sides[index])).GetUnit();
|
|
|
|
if (eCSSUnit_Inherit == unit || eCSSUnit_Initial == unit) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide missing values by replicating some of the values found
|
|
|
|
switch (count) {
|
|
|
|
case 1: // Make right == top
|
|
|
|
result.mRight = result.mTop;
|
|
|
|
case 2: // Make bottom == top
|
|
|
|
result.mBottom = result.mTop;
|
|
|
|
case 3: // Make left == right
|
|
|
|
result.mLeft = result.mRight;
|
|
|
|
}
|
|
|
|
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_SIDES (index) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aPropIDs[index], result.*(nsCSSRect::sides[index]));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseDirectionalBoxProperty(nsCSSProperty aProperty,
|
|
|
|
PRInt32 aSourceType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsCSSProperty* subprops = nsCSSProps::SubpropertyEntryFor(aProperty);
|
|
|
|
NS_ASSERTION(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
|
|
|
nsCSSValue value;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseSingleValueProperty(value, subprops[0]) ||
|
|
|
|
!ExpectEndProperty())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
AppendValue(subprops[0], value);
|
|
|
|
nsCSSValue typeVal(aSourceType, eCSSUnit_Enumerated);
|
|
|
|
AppendValue(subprops[1], typeVal);
|
|
|
|
AppendValue(subprops[2], typeVal);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-30 22:50:52 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBoxCornerRadius(nsCSSProperty aPropID)
|
|
|
|
{
|
2008-09-30 22:51:40 -07:00
|
|
|
nsCSSValue dimenX, dimenY;
|
|
|
|
// required first value
|
2009-03-09 16:14:34 -07:00
|
|
|
if (! ParseNonNegativeVariant(dimenX, VARIANT_HLP, nsnull))
|
2008-09-30 22:50:52 -07:00
|
|
|
return PR_FALSE;
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2008-09-30 22:51:40 -07:00
|
|
|
// optional second value (forbidden if first value is inherit/initial)
|
2010-08-19 12:33:44 -07:00
|
|
|
if (dimenX.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
dimenX.GetUnit() != eCSSUnit_Initial) {
|
|
|
|
ParseNonNegativeVariant(dimenY, VARIANT_LP, nsnull);
|
|
|
|
}
|
2008-09-30 22:51:40 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (dimenX == dimenY || dimenY.GetUnit() == eCSSUnit_Null) {
|
|
|
|
AppendValue(aPropID, dimenX);
|
|
|
|
} else {
|
|
|
|
nsCSSValue value;
|
|
|
|
value.SetPairValue(dimenX, dimenY);
|
|
|
|
AppendValue(aPropID, value);
|
|
|
|
}
|
2008-09-30 22:50:52 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseBoxCornerRadii(const nsCSSProperty aPropIDs[])
|
2008-09-30 22:50:52 -07:00
|
|
|
{
|
2008-09-30 22:51:40 -07:00
|
|
|
// Rectangles are used as scratch storage.
|
|
|
|
// top => top-left, right => top-right,
|
|
|
|
// bottom => bottom-right, left => bottom-left.
|
|
|
|
nsCSSRect dimenX, dimenY;
|
|
|
|
PRInt32 countX = 0, countY = 0;
|
|
|
|
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_SIDES (side) {
|
2009-03-09 16:14:34 -07:00
|
|
|
if (! ParseNonNegativeVariant(dimenX.*nsCSSRect::sides[side],
|
|
|
|
side > 0 ? VARIANT_LP : VARIANT_HLP, nsnull))
|
2008-09-30 22:50:52 -07:00
|
|
|
break;
|
2008-09-30 22:51:40 -07:00
|
|
|
countX++;
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
2008-09-30 22:51:40 -07:00
|
|
|
if (countX == 0)
|
2008-09-30 22:50:52 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-09-30 22:51:40 -07:00
|
|
|
if (ExpectSymbol('/', PR_TRUE)) {
|
2008-09-30 22:50:52 -07:00
|
|
|
NS_FOR_CSS_SIDES (side) {
|
2009-03-09 16:14:34 -07:00
|
|
|
if (! ParseNonNegativeVariant(dimenY.*nsCSSRect::sides[side],
|
|
|
|
VARIANT_LP, nsnull))
|
2008-09-30 22:51:40 -07:00
|
|
|
break;
|
|
|
|
countY++;
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
2008-09-30 22:51:40 -07:00
|
|
|
if (countY == 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ExpectEndProperty())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// if 'initial' or 'inherit' was used, it must be the only value
|
|
|
|
if (countX > 1 || countY > 0) {
|
|
|
|
nsCSSUnit unit = dimenX.mTop.GetUnit();
|
|
|
|
if (eCSSUnit_Inherit == unit || eCSSUnit_Initial == unit)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we have no Y-values, use the X-values
|
|
|
|
if (countY == 0) {
|
|
|
|
dimenY = dimenX;
|
|
|
|
countY = countX;
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provide missing values by replicating some of the values found
|
2008-09-30 22:51:40 -07:00
|
|
|
switch (countX) {
|
|
|
|
case 1: dimenX.mRight = dimenX.mTop; // top-right same as top-left, and
|
|
|
|
case 2: dimenX.mBottom = dimenX.mTop; // bottom-right same as top-left, and
|
|
|
|
case 3: dimenX.mLeft = dimenX.mRight; // bottom-left same as top-right
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (countY) {
|
|
|
|
case 1: dimenY.mRight = dimenY.mTop; // top-right same as top-left, and
|
|
|
|
case 2: dimenY.mBottom = dimenY.mTop; // bottom-right same as top-left, and
|
|
|
|
case 3: dimenY.mLeft = dimenY.mRight; // bottom-left same as top-right
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue& x = dimenX.*nsCSSRect::sides[side];
|
|
|
|
nsCSSValue& y = dimenY.*nsCSSRect::sides[side];
|
|
|
|
|
|
|
|
if (x == y) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aPropIDs[side], x);
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue pair;
|
|
|
|
pair.SetPairValue(x, y);
|
|
|
|
AppendValue(aPropIDs[side], pair);
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These must be in CSS order (top,right,bottom,left) for indexing to work
|
|
|
|
static const nsCSSProperty kBorderStyleIDs[] = {
|
|
|
|
eCSSProperty_border_top_style,
|
|
|
|
eCSSProperty_border_right_style_value,
|
|
|
|
eCSSProperty_border_bottom_style,
|
|
|
|
eCSSProperty_border_left_style_value
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderWidthIDs[] = {
|
|
|
|
eCSSProperty_border_top_width,
|
|
|
|
eCSSProperty_border_right_width_value,
|
|
|
|
eCSSProperty_border_bottom_width,
|
|
|
|
eCSSProperty_border_left_width_value
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderColorIDs[] = {
|
|
|
|
eCSSProperty_border_top_color,
|
|
|
|
eCSSProperty_border_right_color_value,
|
|
|
|
eCSSProperty_border_bottom_color,
|
|
|
|
eCSSProperty_border_left_color_value
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kBorderRadiusIDs[] = {
|
|
|
|
eCSSProperty__moz_border_radius_topLeft,
|
|
|
|
eCSSProperty__moz_border_radius_topRight,
|
|
|
|
eCSSProperty__moz_border_radius_bottomRight,
|
|
|
|
eCSSProperty__moz_border_radius_bottomLeft
|
|
|
|
};
|
|
|
|
static const nsCSSProperty kOutlineRadiusIDs[] = {
|
|
|
|
eCSSProperty__moz_outline_radius_topLeft,
|
|
|
|
eCSSProperty__moz_outline_radius_topRight,
|
|
|
|
eCSSProperty__moz_outline_radius_bottomRight,
|
|
|
|
eCSSProperty__moz_outline_radius_bottomLeft
|
|
|
|
};
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseProperty(nsCSSProperty aPropID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-15 15:25:20 -07:00
|
|
|
NS_ASSERTION(aPropID < eCSSProperty_COUNT, "index out of range");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (aPropID) { // handle shorthand or multiple properties
|
|
|
|
case eCSSProperty_background:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBackground();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_background_position:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBackgroundPosition();
|
2009-02-19 21:29:21 -08:00
|
|
|
case eCSSProperty_background_attachment:
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_clip:
|
2009-02-19 21:29:21 -08:00
|
|
|
case eCSSProperty_background_image:
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_origin:
|
2009-02-19 21:29:21 -08:00
|
|
|
case eCSSProperty_background_repeat:
|
|
|
|
return ParseBackgroundList(aPropID);
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_size:
|
2009-05-28 11:09:05 -07:00
|
|
|
return ParseBackgroundSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderSide(kBorderTopIDs, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderColor();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_spacing:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderSpacing();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderStyle();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_bottom:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderSide(kBorderBottomIDs, PR_FALSE);
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBorderSide(kBorderEndIDs,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_left:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBorderSide(kBorderLeftIDs,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_right:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBorderSide(kBorderRightIDs,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_start:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBorderSide(kBorderStartIDs,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderSide(kBorderTopIDs, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_bottom_colors:
|
|
|
|
case eCSSProperty_border_left_colors:
|
|
|
|
case eCSSProperty_border_right_colors:
|
|
|
|
case eCSSProperty_border_top_colors:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBorderColors(aPropID);
|
2008-07-16 23:30:25 -07:00
|
|
|
case eCSSProperty_border_image:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderImage();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_width:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderWidth();
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_end_color,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_border_left_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_left_color,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_right_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_right_color,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_start_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_start_color,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_border_end_width:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_end_width,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_border_left_width:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_left_width,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_right_width:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_right_width,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_start_width:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_start_width,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_border_end_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_end_style,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_border_left_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_left_style,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_right_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_right_style,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_border_start_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_border_start_style,
|
2007-07-04 11:51:16 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_border_radius:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxCornerRadii(kBorderRadiusIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_outline_radius:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxCornerRadii(kOutlineRadiusIDs);
|
2008-09-30 22:50:52 -07: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:
|
|
|
|
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 ParseBoxCornerRadius(aPropID);
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
case eCSSProperty_box_shadow:
|
2010-08-19 12:33:44 -07:00
|
|
|
case eCSSProperty_text_shadow:
|
|
|
|
return ParseShadowList(aPropID);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_clip:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseRect(eCSSProperty_clip);
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseBorderSide(kColumnRuleIDs, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_content:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_counter_increment:
|
|
|
|
case eCSSProperty_counter_reset:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseCounterData(aPropID);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_cue:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseCue();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_cursor:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseCursor();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_font:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFont();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_image_region:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseRect(eCSSProperty_image_region);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_list_style:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseListStyle();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_margin:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseMargin();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_margin_end:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_margin_end,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_margin_left:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_margin_left,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_margin_right:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_margin_right,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_margin_start:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_margin_start,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_outline:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseOutline();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_overflow:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseOverflow();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_padding:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParsePadding();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_padding_end:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_padding_end,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_padding_left:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_padding_left,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_padding_right:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_padding_right,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_PHYSICAL);
|
|
|
|
case eCSSProperty_padding_start:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDirectionalBoxProperty(eCSSProperty_padding_start,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_BOXPROP_SOURCE_LOGICAL);
|
|
|
|
case eCSSProperty_pause:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParsePause();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_quotes:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseQuotes();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_size:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseSize();
|
2008-09-13 02:42:11 -07:00
|
|
|
case eCSSProperty__moz_transform:
|
|
|
|
return ParseMozTransform();
|
|
|
|
case eCSSProperty__moz_transform_origin:
|
|
|
|
return ParseMozTransformOrigin();
|
2009-08-20 14:52:47 -07:00
|
|
|
case eCSSProperty_transition:
|
|
|
|
return ParseTransition();
|
|
|
|
case eCSSProperty_transition_property:
|
|
|
|
return ParseTransitionProperty();
|
|
|
|
case eCSSProperty_transition_timing_function:
|
|
|
|
return ParseTransitionTimingFunction();
|
|
|
|
case eCSSProperty_transition_duration:
|
|
|
|
case eCSSProperty_transition_delay:
|
|
|
|
return ParseTransitionTime(aPropID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_fill:
|
|
|
|
case eCSSProperty_stroke:
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParsePaint(aPropID);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_stroke_dasharray:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseDasharray();
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marker:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseMarker();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-04-15 15:25:20 -07:00
|
|
|
// Strip out properties we use internally.
|
2007-06-12 11:28:56 -07:00
|
|
|
case eCSSProperty__x_system_font:
|
2007-03-22 10:30:00 -07: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:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_color_value:
|
|
|
|
case eCSSProperty_border_left_color_value:
|
|
|
|
case eCSSProperty_border_right_color_value:
|
|
|
|
case eCSSProperty_border_start_color_value:
|
|
|
|
case eCSSProperty_border_left_color_ltr_source:
|
|
|
|
case eCSSProperty_border_left_color_rtl_source:
|
|
|
|
case eCSSProperty_border_right_color_ltr_source:
|
|
|
|
case eCSSProperty_border_right_color_rtl_source:
|
|
|
|
case eCSSProperty_border_end_style_value:
|
|
|
|
case eCSSProperty_border_left_style_value:
|
|
|
|
case eCSSProperty_border_right_style_value:
|
|
|
|
case eCSSProperty_border_start_style_value:
|
|
|
|
case eCSSProperty_border_left_style_ltr_source:
|
|
|
|
case eCSSProperty_border_left_style_rtl_source:
|
|
|
|
case eCSSProperty_border_right_style_ltr_source:
|
|
|
|
case eCSSProperty_border_right_style_rtl_source:
|
|
|
|
case eCSSProperty_border_end_width_value:
|
|
|
|
case eCSSProperty_border_left_width_value:
|
|
|
|
case eCSSProperty_border_right_width_value:
|
|
|
|
case eCSSProperty_border_start_width_value:
|
|
|
|
case eCSSProperty_border_left_width_ltr_source:
|
|
|
|
case eCSSProperty_border_left_width_rtl_source:
|
|
|
|
case eCSSProperty_border_right_width_ltr_source:
|
|
|
|
case eCSSProperty_border_right_width_rtl_source:
|
2007-03-22 10:30:00 -07:00
|
|
|
// The user can't use these
|
|
|
|
REPORT_UNEXPECTED(PEInaccessibleProperty2);
|
|
|
|
return PR_FALSE;
|
|
|
|
default: // must be single property
|
|
|
|
{
|
|
|
|
nsCSSValue value;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(value, aPropID)) {
|
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(aPropID, value);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// XXX Report errors?
|
|
|
|
}
|
|
|
|
// XXX Report errors?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bits used in determining which background position info we have
|
2007-04-18 13:41:14 -07:00
|
|
|
#define BG_CENTER NS_STYLE_BG_POSITION_CENTER
|
|
|
|
#define BG_TOP NS_STYLE_BG_POSITION_TOP
|
|
|
|
#define BG_BOTTOM NS_STYLE_BG_POSITION_BOTTOM
|
|
|
|
#define BG_LEFT NS_STYLE_BG_POSITION_LEFT
|
|
|
|
#define BG_RIGHT NS_STYLE_BG_POSITION_RIGHT
|
2007-03-22 10:30:00 -07:00
|
|
|
#define BG_CTB (BG_CENTER | BG_TOP | BG_BOTTOM)
|
|
|
|
#define BG_CLR (BG_CENTER | BG_LEFT | BG_RIGHT)
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseSingleValueProperty(nsCSSValue& aValue,
|
|
|
|
nsCSSProperty aPropID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
switch (aPropID) {
|
|
|
|
case eCSSProperty_UNKNOWN:
|
|
|
|
case eCSSProperty_background:
|
|
|
|
case eCSSProperty_background_position:
|
|
|
|
case eCSSProperty_border:
|
|
|
|
case eCSSProperty_border_color:
|
|
|
|
case eCSSProperty_border_bottom_colors:
|
2008-07-16 23:30:25 -07:00
|
|
|
case eCSSProperty_border_image:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_left_colors:
|
|
|
|
case eCSSProperty_border_right_colors:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_color:
|
|
|
|
case eCSSProperty_border_left_color:
|
|
|
|
case eCSSProperty_border_right_color:
|
|
|
|
case eCSSProperty_border_start_color:
|
|
|
|
case eCSSProperty_border_end_style:
|
|
|
|
case eCSSProperty_border_left_style:
|
|
|
|
case eCSSProperty_border_right_style:
|
|
|
|
case eCSSProperty_border_start_style:
|
|
|
|
case eCSSProperty_border_end_width:
|
|
|
|
case eCSSProperty_border_left_width:
|
|
|
|
case eCSSProperty_border_right_width:
|
|
|
|
case eCSSProperty_border_start_width:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top_colors:
|
|
|
|
case eCSSProperty_border_spacing:
|
|
|
|
case eCSSProperty_border_style:
|
|
|
|
case eCSSProperty_border_bottom:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_left:
|
|
|
|
case eCSSProperty_border_right:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_start:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_width:
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_size:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_border_radius:
|
2008-09-30 22:50:52 -07: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:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty_box_shadow:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_clip:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_content:
|
|
|
|
case eCSSProperty_counter_increment:
|
|
|
|
case eCSSProperty_counter_reset:
|
|
|
|
case eCSSProperty_cue:
|
|
|
|
case eCSSProperty_cursor:
|
|
|
|
case eCSSProperty_font:
|
|
|
|
case eCSSProperty_image_region:
|
|
|
|
case eCSSProperty_list_style:
|
|
|
|
case eCSSProperty_margin:
|
|
|
|
case eCSSProperty_margin_end:
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_start:
|
|
|
|
case eCSSProperty_outline:
|
|
|
|
case eCSSProperty__moz_outline_radius:
|
2008-09-30 22:50:52 -07: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:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_overflow:
|
|
|
|
case eCSSProperty_padding:
|
|
|
|
case eCSSProperty_padding_end:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_start:
|
|
|
|
case eCSSProperty_pause:
|
|
|
|
case eCSSProperty_quotes:
|
|
|
|
case eCSSProperty_size:
|
|
|
|
case eCSSProperty_text_shadow:
|
2008-09-13 02:42:11 -07:00
|
|
|
case eCSSProperty__moz_transform:
|
|
|
|
case eCSSProperty__moz_transform_origin:
|
2009-08-20 14:52:47 -07:00
|
|
|
case eCSSProperty_transition:
|
|
|
|
case eCSSProperty_transition_property:
|
|
|
|
case eCSSProperty_transition_timing_function:
|
|
|
|
case eCSSProperty_transition_duration:
|
|
|
|
case eCSSProperty_transition_delay:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_COUNT:
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_fill:
|
|
|
|
case eCSSProperty_stroke:
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
|
|
|
case eCSSProperty_marker:
|
|
|
|
#endif
|
2009-08-20 14:52:47 -07:00
|
|
|
case eCSSPropertyExtra_no_properties:
|
|
|
|
case eCSSPropertyExtra_all_properties:
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ERROR("not a single value property");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-06-12 11:28:56 -07:00
|
|
|
case eCSSProperty__x_system_font:
|
2007-03-22 10:30:00 -07: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:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_left_color_ltr_source:
|
|
|
|
case eCSSProperty_border_left_color_rtl_source:
|
|
|
|
case eCSSProperty_border_right_color_ltr_source:
|
|
|
|
case eCSSProperty_border_right_color_rtl_source:
|
|
|
|
case eCSSProperty_border_left_style_ltr_source:
|
|
|
|
case eCSSProperty_border_left_style_rtl_source:
|
|
|
|
case eCSSProperty_border_right_style_ltr_source:
|
|
|
|
case eCSSProperty_border_right_style_rtl_source:
|
|
|
|
case eCSSProperty_border_left_width_ltr_source:
|
|
|
|
case eCSSProperty_border_left_width_rtl_source:
|
|
|
|
case eCSSProperty_border_right_width_ltr_source:
|
|
|
|
case eCSSProperty_border_right_width_rtl_source:
|
2008-01-09 01:38:28 -08:00
|
|
|
#ifdef MOZ_MATHML
|
|
|
|
case eCSSProperty_script_size_multiplier:
|
|
|
|
case eCSSProperty_script_min_size:
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ERROR("not currently parsed here");
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
case eCSSProperty_appearance:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kAppearanceKTable);
|
|
|
|
case eCSSProperty_azimuth:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseAzimuth(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_background_attachment:
|
2009-02-19 21:29:21 -08:00
|
|
|
// Used only internally.
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_KEYWORD,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBackgroundAttachmentKTable);
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_clip:
|
2009-02-19 21:29:21 -08:00
|
|
|
// Used only internally.
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_KEYWORD,
|
2010-06-08 18:44:32 -07:00
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
2009-06-16 08:00:20 -07:00
|
|
|
case eCSSProperty_background_color:
|
|
|
|
return ParseVariant(aValue, VARIANT_HC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_background_image:
|
2009-02-19 21:29:21 -08:00
|
|
|
// Used only internally.
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_IMAGE, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_background_inline_policy:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBackgroundInlinePolicyKTable);
|
2010-06-08 18:44:33 -07:00
|
|
|
case eCSSProperty_background_origin:
|
2009-02-19 21:29:21 -08:00
|
|
|
// Used only internally.
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_KEYWORD,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBackgroundOriginKTable);
|
|
|
|
case eCSSProperty_background_repeat:
|
2009-02-19 21:29:21 -08:00
|
|
|
// Used only internally.
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_KEYWORD,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBackgroundRepeatKTable);
|
|
|
|
case eCSSProperty_binding:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_collapse:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBorderCollapseKTable);
|
|
|
|
case eCSSProperty_border_bottom_color:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_color_value: // for internal use
|
|
|
|
case eCSSProperty_border_left_color_value: // for internal use
|
|
|
|
case eCSSProperty_border_right_color_value: // for internal use
|
|
|
|
case eCSSProperty_border_start_color_value: // for internal use
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top_color:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBorderColorKTable);
|
|
|
|
case eCSSProperty_border_bottom_style:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_style_value: // for internal use
|
|
|
|
case eCSSProperty_border_left_style_value: // for internal use
|
|
|
|
case eCSSProperty_border_right_style_value: // for internal use
|
|
|
|
case eCSSProperty_border_start_style_value: // for internal use
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top_style:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule_style:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBorderStyleKTable);
|
|
|
|
case eCSSProperty_border_bottom_width:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_end_width_value: // for internal use
|
|
|
|
case eCSSProperty_border_left_width_value: // for internal use
|
|
|
|
case eCSSProperty_border_right_width_value: // for internal use
|
|
|
|
case eCSSProperty_border_start_width_value: // for internal use
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top_width:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule_width:
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HKL | VARIANT_CALC,
|
2009-03-09 16:14:34 -07:00
|
|
|
nsCSSProps::kBorderWidthKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_column_count:
|
2009-03-09 16:14:34 -07:00
|
|
|
// Need to reject 0 in addition to negatives. If we accept 0, we
|
|
|
|
// need to change NS_STYLE_COLUMN_COUNT_AUTO to something else.
|
|
|
|
return ParsePositiveNonZeroVariant(aValue, VARIANT_AHI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_column_width:
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_AHL | VARIANT_CALC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty__moz_column_gap:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HL | VARIANT_NORMAL, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_left:
|
|
|
|
case eCSSProperty_right:
|
2010-08-25 03:17:56 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_AHLP | VARIANT_CALC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_box_align:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBoxAlignKTable);
|
|
|
|
case eCSSProperty_box_direction:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBoxDirectionKTable);
|
|
|
|
case eCSSProperty_box_flex:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HN, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_box_orient:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBoxOrientKTable);
|
|
|
|
case eCSSProperty_box_pack:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBoxPackKTable);
|
|
|
|
case eCSSProperty_box_ordinal_group:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eCSSProperty_clip_path:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_clip_rule:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFillRuleKTable);
|
|
|
|
case eCSSProperty_color_interpolation:
|
|
|
|
case eCSSProperty_color_interpolation_filters:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kColorInterpolationKTable);
|
|
|
|
case eCSSProperty_dominant_baseline:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kDominantBaselineKTable);
|
|
|
|
case eCSSProperty_fill_opacity:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_fill_rule:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFillRuleKTable);
|
|
|
|
case eCSSProperty_filter:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_flood_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_flood_opacity:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull);
|
2009-03-21 08:36:38 -07:00
|
|
|
case eCSSProperty_image_rendering:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2009-03-21 08:36:38 -07:00
|
|
|
nsCSSProps::kImageRenderingKTable);
|
2007-07-25 23:57:42 -07:00
|
|
|
case eCSSProperty_lighting_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marker_end:
|
|
|
|
case eCSSProperty_marker_mid:
|
|
|
|
case eCSSProperty_marker_start:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_mask:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_shape_rendering:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kShapeRenderingKTable);
|
|
|
|
case eCSSProperty_stop_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HC,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stop_opacity:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_dashoffset:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HLPN,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_linecap:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kStrokeLinecapKTable);
|
|
|
|
case eCSSProperty_stroke_linejoin:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kStrokeLinejoinKTable);
|
|
|
|
case eCSSProperty_stroke_miterlimit:
|
2008-12-23 06:06:58 -08:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull) &&
|
|
|
|
// Enforce the restriction that the value is greater than 1.
|
|
|
|
(aValue.GetUnit() != eCSSUnit_Number ||
|
|
|
|
aValue.GetFloatValue() >= 1.0f);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_stroke_opacity:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_stroke_width:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HLPN, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_text_anchor:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kTextAnchorKTable);
|
|
|
|
case eCSSProperty_text_rendering:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kTextRenderingKTable);
|
|
|
|
#endif
|
|
|
|
case eCSSProperty_box_sizing:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kBoxSizingKTable);
|
|
|
|
case eCSSProperty_height:
|
2010-08-25 03:17:55 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_AHLP | VARIANT_CALC,
|
|
|
|
nsnull);
|
2007-05-03 16:11:00 -07:00
|
|
|
case eCSSProperty_width:
|
2010-08-11 12:32:53 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_AHKLP | VARIANT_CALC,
|
2009-03-09 16:14:34 -07:00
|
|
|
nsCSSProps::kWidthKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_force_broken_image_icon:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_caption_side:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kCaptionSideKTable);
|
|
|
|
case eCSSProperty_clear:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kClearKTable);
|
|
|
|
case eCSSProperty_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_cue_after:
|
|
|
|
case eCSSProperty_cue_before:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_direction:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kDirectionKTable);
|
|
|
|
case eCSSProperty_display:
|
2009-10-21 14:57:57 -07:00
|
|
|
if (ParseVariant(aValue, VARIANT_HK, nsCSSProps::kDisplayKTable)) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (aValue.GetUnit() == eCSSUnit_Enumerated) {
|
|
|
|
switch (aValue.GetIntValue()) {
|
|
|
|
case NS_STYLE_DISPLAY_MARKER: // bug 2055
|
|
|
|
case NS_STYLE_DISPLAY_RUN_IN: // bug 2056
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT: // bug 14983
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
2008-09-09 21:38:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
case eCSSProperty_elevation:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK | VARIANT_ANGLE,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kElevationKTable);
|
|
|
|
case eCSSProperty_empty_cells:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kEmptyCellsKTable);
|
|
|
|
case eCSSProperty_float:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFloatKTable);
|
|
|
|
case eCSSProperty_float_edge:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFloatEdgeKTable);
|
|
|
|
case eCSSProperty_font_family:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFamily(aValue);
|
2010-07-13 13:30:42 -07:00
|
|
|
case eCSSProperty_font_feature_settings:
|
|
|
|
case eCSSProperty_font_language_override:
|
|
|
|
return ParseVariant(aValue, VARIANT_NORMAL | VARIANT_INHERIT |
|
|
|
|
VARIANT_STRING, nsnull);
|
2008-09-09 21:38:14 -07:00
|
|
|
case eCSSProperty_font_size:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue,
|
2010-05-11 08:49:44 -07:00
|
|
|
VARIANT_HKLP | VARIANT_SYSFONT |
|
|
|
|
VARIANT_CALC,
|
2009-03-09 16:14:34 -07:00
|
|
|
nsCSSProps::kFontSizeKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_font_size_adjust:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HON | VARIANT_SYSFONT,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull);
|
|
|
|
case eCSSProperty_font_stretch:
|
2009-11-14 19:16:59 -08:00
|
|
|
return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFontStretchKTable);
|
|
|
|
case eCSSProperty_font_style:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFontStyleKTable);
|
|
|
|
case eCSSProperty_font_variant:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK | VARIANT_SYSFONT,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kFontVariantKTable);
|
|
|
|
case eCSSProperty_font_weight:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFontWeight(aValue);
|
2007-05-16 08:51:37 -07:00
|
|
|
case eCSSProperty_ime_mode:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-05-16 08:51:37 -07:00
|
|
|
nsCSSProps::kIMEModeKTable);
|
2009-09-26 13:23:47 -07:00
|
|
|
case eCSSProperty__moz_tab_size:
|
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_letter_spacing:
|
|
|
|
case eCSSProperty_word_spacing:
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HL | VARIANT_NORMAL | VARIANT_CALC,
|
|
|
|
nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_line_height:
|
2009-05-18 15:13:12 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HLPN | VARIANT_KEYWORD | VARIANT_NORMAL | VARIANT_SYSFONT, nsCSSProps::kLineHeightKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_list_style_image:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HUO, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_list_style_position:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK, nsCSSProps::kListStylePositionKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_list_style_type:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK, nsCSSProps::kListStyleKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_margin_bottom:
|
|
|
|
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
|
|
|
|
case eCSSProperty_margin_top:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_AHLP, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marker_offset:
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_AHL | VARIANT_CALC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marks:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseMarks(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_max_height:
|
2010-08-25 03:17:55 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HLPO | VARIANT_CALC,
|
|
|
|
nsnull);
|
2007-05-03 16:11:00 -07:00
|
|
|
case eCSSProperty_max_width:
|
2010-08-25 03:17:56 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HKLPO | VARIANT_CALC,
|
2009-03-09 16:14:34 -07:00
|
|
|
nsCSSProps::kWidthKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_min_height:
|
2010-08-25 03:17:55 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HLP | VARIANT_CALC,
|
|
|
|
nsnull);
|
2007-05-03 16:11:00 -07:00
|
|
|
case eCSSProperty_min_width:
|
2010-08-25 03:17:56 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HKLP | VARIANT_CALC,
|
2009-03-09 16:14:34 -07:00
|
|
|
nsCSSProps::kWidthKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_opacity:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_orphans:
|
|
|
|
case eCSSProperty_widows:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParsePositiveNonZeroVariant(aValue, VARIANT_HI, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_outline_color:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kOutlineColorKTable);
|
|
|
|
case eCSSProperty_outline_style:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kOutlineStyleKTable);
|
|
|
|
case eCSSProperty_outline_width:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HKL,
|
|
|
|
nsCSSProps::kBorderWidthKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_outline_offset:
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HL | VARIANT_CALC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_overflow_x:
|
|
|
|
case eCSSProperty_overflow_y:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kOverflowSubKTable);
|
|
|
|
case eCSSProperty_padding_bottom:
|
|
|
|
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
|
|
|
|
case eCSSProperty_padding_top:
|
2009-03-09 16:14:34 -07:00
|
|
|
return ParseNonNegativeVariant(aValue, VARIANT_HLP, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_page:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_AUTO | VARIANT_IDENTIFIER, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_page_break_after:
|
|
|
|
case eCSSProperty_page_break_before:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kPageBreakKTable);
|
|
|
|
case eCSSProperty_page_break_inside:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kPageBreakInsideKTable);
|
|
|
|
case eCSSProperty_pause_after:
|
|
|
|
case eCSSProperty_pause_before:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HTP, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_pitch:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HKF, nsCSSProps::kPitchKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_pitch_range:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull);
|
2009-08-26 20:53:35 -07:00
|
|
|
case eCSSProperty_pointer_events:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2009-08-26 20:53:35 -07:00
|
|
|
nsCSSProps::kPointerEventsKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_position:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK, nsCSSProps::kPositionKTable);
|
2010-03-19 04:49:33 -07:00
|
|
|
case eCSSProperty_resize:
|
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
|
|
|
nsCSSProps::kResizeKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_richness:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull);
|
2008-01-09 01:38:28 -08:00
|
|
|
#ifdef MOZ_MATHML
|
|
|
|
// script-level can take Integer or Number values, but only Integer ("relative")
|
|
|
|
// values can be specified in a style sheet. Also we only allow this property
|
|
|
|
// when unsafe rules are enabled, because otherwise it could interfere
|
|
|
|
// with rulenode optimizations if used in a non-MathML-enabled document.
|
|
|
|
case eCSSProperty_script_level:
|
|
|
|
if (!mUnsafeRulesEnabled)
|
|
|
|
return PR_FALSE;
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HI, nsnull);
|
2008-01-09 01:38:28 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_speak:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kSpeakKTable);
|
|
|
|
case eCSSProperty_speak_header:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kSpeakHeaderKTable);
|
|
|
|
case eCSSProperty_speak_numeral:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kSpeakNumeralKTable);
|
|
|
|
case eCSSProperty_speak_punctuation:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kSpeakPunctuationKTable);
|
|
|
|
case eCSSProperty_speech_rate:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN | VARIANT_KEYWORD,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kSpeechRateKTable);
|
2008-06-04 23:46:24 -07:00
|
|
|
case eCSSProperty_stack_sizing:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2008-06-04 23:46:24 -07:00
|
|
|
nsCSSProps::kStackSizingKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_stress:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HN, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_table_layout:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kTableLayoutKTable);
|
|
|
|
case eCSSProperty_text_align:
|
|
|
|
// When we support aligning on a string, we can parse text-align
|
|
|
|
// as a string....
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK /* | VARIANT_STRING */,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kTextAlignKTable);
|
|
|
|
case eCSSProperty_text_decoration:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseTextDecoration(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_text_indent:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HLP, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_text_transform:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kTextTransformKTable);
|
|
|
|
case eCSSProperty_unicode_bidi:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kUnicodeBidiKTable);
|
|
|
|
case eCSSProperty_user_focus:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kUserFocusKTable);
|
|
|
|
case eCSSProperty_user_input:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kUserInputKTable);
|
|
|
|
case eCSSProperty_user_modify:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kUserModifyKTable);
|
|
|
|
case eCSSProperty_user_select:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kUserSelectKTable);
|
|
|
|
case eCSSProperty_vertical_align:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HKLP,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kVerticalAlignKTable);
|
|
|
|
case eCSSProperty_visibility:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kVisibilityKTable);
|
|
|
|
case eCSSProperty_voice_family:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFamily(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_volume:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HPN | VARIANT_KEYWORD,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kVolumeKTable);
|
|
|
|
case eCSSProperty_white_space:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kWhitespaceKTable);
|
2008-10-14 07:44:25 -07:00
|
|
|
case eCSSProperty__moz_window_shadow:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2008-10-14 07:44:25 -07:00
|
|
|
nsCSSProps::kWindowShadowKTable);
|
2008-07-24 00:16:18 -07:00
|
|
|
case eCSSProperty_word_wrap:
|
2009-10-21 14:57:57 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_HK,
|
2008-07-24 00:16:18 -07:00
|
|
|
nsCSSProps::kWordwrapKTable);
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_z_index:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_AHI, nsnull);
|
2009-01-22 17:28:13 -08:00
|
|
|
case eCSSPropertyExtra_x_none_value:
|
|
|
|
return ParseVariant(aValue, VARIANT_NONE | VARIANT_INHERIT, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// explicitly do NOT have a default case to let the compiler
|
|
|
|
// help find missing properties
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
// nsFont::EnumerateFamilies callback for ParseFontDescriptorValue
|
|
|
|
struct NS_STACK_CLASS ExtractFirstFamilyData {
|
|
|
|
nsAutoString mFamilyName;
|
|
|
|
PRBool mGood;
|
|
|
|
ExtractFirstFamilyData() : mFamilyName(), mGood(PR_FALSE) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
ExtractFirstFamily(const nsString& aFamily,
|
|
|
|
PRBool aGeneric,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
ExtractFirstFamilyData* realData = (ExtractFirstFamilyData*) aData;
|
|
|
|
if (aGeneric || realData->mFamilyName.Length() > 0) {
|
|
|
|
realData->mGood = PR_FALSE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
realData->mFamilyName.Assign(aFamily);
|
|
|
|
realData->mGood = PR_TRUE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// font-descriptor: descriptor ':' value ';'
|
|
|
|
// caller has advanced mToken to point at the descriptor
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontDescriptorValue(nsCSSFontDesc aDescID,
|
2008-08-10 14:13:49 -07:00
|
|
|
nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
switch (aDescID) {
|
|
|
|
// These four are similar to the properties of the same name,
|
|
|
|
// possibly with more restrictions on the values they can take.
|
|
|
|
case eCSSFontDesc_Family: {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseFamily(aValue) ||
|
2009-03-05 20:05:01 -08:00
|
|
|
aValue.GetUnit() != eCSSUnit_Families)
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// the style parameters to the nsFont constructor are ignored,
|
|
|
|
// because it's only being used to call EnumerateFamilies
|
|
|
|
nsAutoString valueStr;
|
|
|
|
aValue.GetStringValue(valueStr);
|
2009-01-29 12:39:18 -08:00
|
|
|
nsFont font(valueStr, 0, 0, 0, 0, 0, 0);
|
2008-08-10 14:13:49 -07:00
|
|
|
ExtractFirstFamilyData dat;
|
|
|
|
|
|
|
|
font.EnumerateFamilies(ExtractFirstFamily, (void*) &dat);
|
|
|
|
if (!dat.mGood)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
aValue.SetStringValue(dat.mFamilyName, eCSSUnit_String);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eCSSFontDesc_Style:
|
|
|
|
// property is VARIANT_HMK|VARIANT_SYSFONT
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseVariant(aValue, VARIANT_KEYWORD | VARIANT_NORMAL,
|
2008-08-10 14:13:49 -07:00
|
|
|
nsCSSProps::kFontStyleKTable);
|
|
|
|
|
|
|
|
case eCSSFontDesc_Weight:
|
2008-09-09 21:38:14 -07:00
|
|
|
return (ParseFontWeight(aValue) &&
|
2008-08-10 14:13:49 -07:00
|
|
|
aValue.GetUnit() != eCSSUnit_Inherit &&
|
|
|
|
aValue.GetUnit() != eCSSUnit_Initial &&
|
|
|
|
(aValue.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
(aValue.GetIntValue() != NS_STYLE_FONT_WEIGHT_BOLDER &&
|
|
|
|
aValue.GetIntValue() != NS_STYLE_FONT_WEIGHT_LIGHTER)));
|
|
|
|
|
|
|
|
case eCSSFontDesc_Stretch:
|
2009-11-14 19:16:59 -08:00
|
|
|
// property is VARIANT_HK|VARIANT_SYSFONT
|
|
|
|
return (ParseVariant(aValue, VARIANT_KEYWORD,
|
2008-08-10 14:13:49 -07:00
|
|
|
nsCSSProps::kFontStretchKTable) &&
|
2009-11-14 19:16:59 -08:00
|
|
|
(aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_WIDER &&
|
|
|
|
aValue.GetIntValue() != NS_STYLE_FONT_STRETCH_NARROWER));
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
// These two are unique to @font-face and have their own special grammar.
|
|
|
|
case eCSSFontDesc_Src:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFontSrc(aValue);
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
case eCSSFontDesc_UnicodeRange:
|
2008-09-09 21:38:14 -07:00
|
|
|
return ParseFontRanges(aValue);
|
2008-08-10 14:13:49 -07:00
|
|
|
|
2010-07-13 13:30:42 -07:00
|
|
|
case eCSSFontDesc_FontFeatureSettings:
|
|
|
|
case eCSSFontDesc_FontLanguageOverride:
|
|
|
|
return ParseVariant(aValue, VARIANT_NORMAL | VARIANT_STRING, nsnull);
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
case eCSSFontDesc_UNKNOWN:
|
|
|
|
case eCSSFontDesc_COUNT:
|
|
|
|
NS_NOTREACHED("bad nsCSSFontDesc code");
|
|
|
|
}
|
|
|
|
// explicitly do NOT have a default case to let the compiler
|
|
|
|
// help find missing descriptors
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-04 11:51:16 -07:00
|
|
|
void
|
|
|
|
CSSParserImpl::InitBoxPropsAsPhysical(const nsCSSProperty *aSourceProperties)
|
|
|
|
{
|
|
|
|
nsCSSValue physical(NS_BOXPROP_SOURCE_PHYSICAL, eCSSUnit_Enumerated);
|
|
|
|
for (const nsCSSProperty *prop = aSourceProperties;
|
|
|
|
*prop != eCSSProperty_UNKNOWN; ++prop) {
|
|
|
|
AppendValue(*prop, physical);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseAzimuth(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseVariant(aValue, VARIANT_HK | VARIANT_ANGLE,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProps::kAzimuthKTable)) {
|
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
|
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
2008-09-09 21:38:14 -07:00
|
|
|
if ((NS_STYLE_AZIMUTH_LEFT_SIDE <= intValue) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(intValue <= NS_STYLE_AZIMUTH_BEHIND)) { // look for optional modifier
|
|
|
|
nsCSSValue modifier;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(modifier, nsCSSProps::kAzimuthKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 enumValue = modifier.GetIntValue();
|
2008-09-09 21:38:14 -07:00
|
|
|
if (((intValue == NS_STYLE_AZIMUTH_BEHIND) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(NS_STYLE_AZIMUTH_LEFT_SIDE <= enumValue) && (enumValue <= NS_STYLE_AZIMUTH_RIGHT_SIDE)) ||
|
2008-09-09 21:38:14 -07:00
|
|
|
((enumValue == NS_STYLE_AZIMUTH_BEHIND) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(NS_STYLE_AZIMUTH_LEFT_SIDE <= intValue) && (intValue <= NS_STYLE_AZIMUTH_RIGHT_SIDE))) {
|
|
|
|
aValue.SetIntValue(intValue | enumValue, eCSSUnit_Enumerated);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// Put the unknown identifier back and return
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCSSValue
|
2008-09-13 02:42:11 -07:00
|
|
|
BoxPositionMaskToCSSValue(PRInt32 aMask, PRBool isX)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-18 13:41:14 -07:00
|
|
|
PRInt32 val = NS_STYLE_BG_POSITION_CENTER;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isX) {
|
|
|
|
if (aMask & BG_LEFT) {
|
2007-04-18 13:41:14 -07:00
|
|
|
val = NS_STYLE_BG_POSITION_LEFT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aMask & BG_RIGHT) {
|
2007-04-18 13:41:14 -07:00
|
|
|
val = NS_STYLE_BG_POSITION_RIGHT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aMask & BG_TOP) {
|
2007-04-18 13:41:14 -07:00
|
|
|
val = NS_STYLE_BG_POSITION_TOP;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aMask & BG_BOTTOM) {
|
2007-04-18 13:41:14 -07:00
|
|
|
val = NS_STYLE_BG_POSITION_BOTTOM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-18 13:41:14 -07:00
|
|
|
return nsCSSValue(val, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBackground()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-15 15:25:20 -07:00
|
|
|
nsAutoParseCompoundProperty compound(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// background-color can only be set once, so it's not a list.
|
|
|
|
nsCSSValue color;
|
2009-05-28 11:09:05 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Check first for inherit/initial.
|
|
|
|
if (ParseVariant(color, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
for (const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_background);
|
|
|
|
*subprops != eCSSProperty_UNKNOWN; ++subprops) {
|
|
|
|
AppendValue(*subprops, color);
|
2009-05-28 11:09:05 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue image, repeat, attachment, clip, origin, position, size;
|
|
|
|
BackgroundParseState state = {
|
|
|
|
color,
|
|
|
|
image.SetListValue(),
|
|
|
|
repeat.SetListValue(),
|
|
|
|
attachment.SetListValue(),
|
|
|
|
clip.SetListValue(),
|
|
|
|
origin.SetListValue(),
|
|
|
|
position.SetPairListValue(),
|
|
|
|
size.SetPairListValue()
|
|
|
|
};
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseBackgroundItem(state)) {
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (CheckEndProperty()) {
|
2009-02-19 21:29:21 -08:00
|
|
|
break;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
// If we saw a color, this must be the last item.
|
|
|
|
if (color.GetUnit() != eCSSUnit_Null) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectEndValue);
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
// Otherwise, a comma is mandatory.
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
// Chain another entry on all the lists.
|
|
|
|
state.mImage->mNext = new nsCSSValueList;
|
|
|
|
state.mImage = state.mImage->mNext;
|
|
|
|
state.mRepeat->mNext = new nsCSSValueList;
|
|
|
|
state.mRepeat = state.mRepeat->mNext;
|
|
|
|
state.mAttachment->mNext = new nsCSSValueList;
|
|
|
|
state.mAttachment = state.mAttachment->mNext;
|
|
|
|
state.mClip->mNext = new nsCSSValueList;
|
|
|
|
state.mClip = state.mClip->mNext;
|
|
|
|
state.mOrigin->mNext = new nsCSSValueList;
|
|
|
|
state.mOrigin = state.mOrigin->mNext;
|
|
|
|
state.mPosition->mNext = new nsCSSValuePairList;
|
|
|
|
state.mPosition = state.mPosition->mNext;
|
|
|
|
state.mSize->mNext = new nsCSSValuePairList;
|
|
|
|
state.mSize = state.mSize->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get to this point without seeing a color, provide a default.
|
|
|
|
if (color.GetUnit() == eCSSUnit_Null) {
|
|
|
|
color.SetColorValue(NS_RGBA(0,0,0,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendValue(eCSSProperty_background_image, image);
|
|
|
|
AppendValue(eCSSProperty_background_repeat, repeat);
|
|
|
|
AppendValue(eCSSProperty_background_attachment, attachment);
|
|
|
|
AppendValue(eCSSProperty_background_clip, clip);
|
|
|
|
AppendValue(eCSSProperty_background_origin, origin);
|
|
|
|
AppendValue(eCSSProperty_background_position, position);
|
|
|
|
AppendValue(eCSSProperty_background_size, size);
|
|
|
|
AppendValue(eCSSProperty_background_color, color);
|
|
|
|
return PR_TRUE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse one item of the background shorthand property.
|
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseBackgroundItem(CSSParserImpl::BackgroundParseState& aState)
|
|
|
|
|
2009-02-19 21:29:21 -08:00
|
|
|
{
|
2007-04-15 15:25:20 -07:00
|
|
|
// Fill in the values that the shorthand will set if we don't find
|
|
|
|
// other values.
|
2010-08-19 12:33:44 -07:00
|
|
|
aState.mImage->mValue.SetNoneValue();
|
|
|
|
aState.mRepeat->mValue.SetIntValue(NS_STYLE_BG_REPEAT_XY,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
aState.mAttachment->mValue.SetIntValue(NS_STYLE_BG_ATTACHMENT_SCROLL,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
aState.mClip->mValue.SetIntValue(NS_STYLE_BG_CLIP_BORDER,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
aState.mOrigin->mValue.SetIntValue(NS_STYLE_BG_ORIGIN_PADDING,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
aState.mPosition->mXValue.SetPercentValue(0.0f);
|
|
|
|
aState.mPosition->mYValue.SetPercentValue(0.0f);
|
|
|
|
aState.mSize->mXValue.SetAutoValue();
|
|
|
|
aState.mSize->mYValue.SetAutoValue();
|
2007-04-15 15:25:20 -07:00
|
|
|
|
|
|
|
PRBool haveColor = PR_FALSE,
|
|
|
|
haveImage = PR_FALSE,
|
|
|
|
haveRepeat = PR_FALSE,
|
|
|
|
haveAttach = PR_FALSE,
|
2009-02-19 21:29:21 -08:00
|
|
|
havePosition = PR_FALSE,
|
2010-06-08 18:44:33 -07:00
|
|
|
haveOrigin = PR_FALSE,
|
2009-02-19 21:29:21 -08:00
|
|
|
haveSomething = PR_FALSE;
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
while (GetToken(PR_TRUE)) {
|
2007-04-15 15:25:20 -07:00
|
|
|
nsCSSTokenType tt = mToken.mType;
|
|
|
|
UngetToken(); // ...but we'll still cheat and use mToken
|
|
|
|
if (tt == eCSSToken_Symbol) {
|
|
|
|
// ExpectEndProperty only looks for symbols, and nothing else will
|
|
|
|
// show up as one.
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-15 15:25:20 -07:00
|
|
|
|
|
|
|
if (tt == eCSSToken_Ident) {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
|
|
|
|
PRInt32 dummy;
|
|
|
|
if (keyword == eCSSKeyword_inherit ||
|
|
|
|
keyword == eCSSKeyword__moz_initial) {
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2007-04-15 15:25:20 -07:00
|
|
|
} else if (keyword == eCSSKeyword_none) {
|
|
|
|
if (haveImage)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveImage = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mImage->mValue,
|
2007-04-15 15:25:20 -07:00
|
|
|
eCSSProperty_background_image)) {
|
|
|
|
NS_NOTREACHED("should be able to parse");
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-15 15:25:20 -07:00
|
|
|
} else if (nsCSSProps::FindKeyword(keyword,
|
|
|
|
nsCSSProps::kBackgroundAttachmentKTable, dummy)) {
|
|
|
|
if (haveAttach)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveAttach = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mAttachment->mValue,
|
2007-04-15 15:25:20 -07:00
|
|
|
eCSSProperty_background_attachment)) {
|
|
|
|
NS_NOTREACHED("should be able to parse");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::FindKeyword(keyword,
|
|
|
|
nsCSSProps::kBackgroundRepeatKTable, dummy)) {
|
|
|
|
if (haveRepeat)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveRepeat = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mRepeat->mValue,
|
2007-04-15 15:25:20 -07:00
|
|
|
eCSSProperty_background_repeat)) {
|
|
|
|
NS_NOTREACHED("should be able to parse");
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-15 15:25:20 -07:00
|
|
|
} else if (nsCSSProps::FindKeyword(keyword,
|
2007-04-18 13:41:14 -07:00
|
|
|
nsCSSProps::kBackgroundPositionKTable, dummy)) {
|
2007-04-15 15:25:20 -07:00
|
|
|
if (havePosition)
|
|
|
|
return PR_FALSE;
|
|
|
|
havePosition = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePair scratch;
|
|
|
|
if (!ParseBoxPositionValues(scratch, PR_FALSE)) {
|
2009-02-19 21:29:21 -08:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
aState.mPosition->mXValue = scratch.mXValue;
|
|
|
|
aState.mPosition->mYValue = scratch.mYValue;
|
2009-02-19 21:29:21 -08:00
|
|
|
} else if (nsCSSProps::FindKeyword(keyword,
|
2010-06-08 18:44:32 -07:00
|
|
|
nsCSSProps::kBackgroundOriginKTable, dummy)) {
|
2009-02-19 21:29:21 -08:00
|
|
|
if (haveOrigin)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveOrigin = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mOrigin->mValue,
|
2010-06-08 18:44:33 -07:00
|
|
|
eCSSProperty_background_origin)) {
|
2009-02-19 21:29:21 -08:00
|
|
|
NS_NOTREACHED("should be able to parse");
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-02-19 21:29:21 -08:00
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_BORDER ==
|
|
|
|
NS_STYLE_BG_ORIGIN_BORDER);
|
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_PADDING ==
|
|
|
|
NS_STYLE_BG_ORIGIN_PADDING);
|
2010-06-08 18:44:32 -07:00
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_CONTENT ==
|
|
|
|
NS_STYLE_BG_ORIGIN_CONTENT);
|
2010-08-19 12:33:44 -07:00
|
|
|
aState.mClip->mValue = aState.mOrigin->mValue;
|
2007-04-15 15:25:20 -07:00
|
|
|
} else {
|
|
|
|
if (haveColor)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveColor = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mColor,
|
2009-06-16 08:00:20 -07:00
|
|
|
eCSSProperty_background_color)) {
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else if (tt == eCSSToken_Function &&
|
2009-08-01 08:53:40 -07:00
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("url") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-linear-gradient") ||
|
2009-08-21 13:39:25 -07:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-radial-gradient") ||
|
2009-11-02 11:36:43 -08:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-repeating-linear-gradient") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-repeating-radial-gradient") ||
|
2010-08-13 06:33:37 -07:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-image-rect") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-element"))) {
|
2007-04-15 15:25:20 -07:00
|
|
|
if (haveImage)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveImage = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mImage->mValue,
|
2007-04-15 15:25:20 -07:00
|
|
|
eCSSProperty_background_image)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else if (tt == eCSSToken_Dimension ||
|
|
|
|
tt == eCSSToken_Number ||
|
2009-11-04 18:36:18 -08:00
|
|
|
tt == eCSSToken_Percentage) {
|
2007-04-15 15:25:20 -07:00
|
|
|
if (havePosition)
|
|
|
|
return PR_FALSE;
|
|
|
|
havePosition = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePair scratch;
|
|
|
|
if (!ParseBoxPositionValues(scratch, PR_FALSE)) {
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
aState.mPosition->mXValue = scratch.mXValue;
|
|
|
|
aState.mPosition->mYValue = scratch.mYValue;
|
2007-04-15 15:25:20 -07:00
|
|
|
} else {
|
|
|
|
if (haveColor)
|
|
|
|
return PR_FALSE;
|
|
|
|
haveColor = PR_TRUE;
|
2009-06-16 08:00:20 -07:00
|
|
|
// Note: This parses 'inherit' and 'initial', but
|
2009-02-19 21:29:21 -08:00
|
|
|
// we've already checked for them, so it's ok.
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseSingleValueProperty(aState.mColor,
|
2009-06-16 08:00:20 -07:00
|
|
|
eCSSProperty_background_color)) {
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-02-19 21:29:21 -08:00
|
|
|
haveSomething = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-19 21:29:21 -08:00
|
|
|
return haveSomething;
|
2009-02-19 12:33:09 -08:00
|
|
|
}
|
|
|
|
|
2009-05-28 11:09:05 -07:00
|
|
|
// This function is very similar to ParseBackgroundPosition and
|
|
|
|
// ParseBackgroundSize.
|
2009-02-19 12:33:09 -08:00
|
|
|
PRBool
|
2009-02-19 21:29:21 -08:00
|
|
|
CSSParserImpl::ParseBackgroundList(nsCSSProperty aPropID)
|
|
|
|
{
|
|
|
|
// aPropID is a single value prop-id
|
|
|
|
nsCSSValue value;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'initial' and 'inherit' stand alone, no list permitted.
|
2009-02-19 21:29:21 -08:00
|
|
|
if (!ExpectEndProperty()) {
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCSSValueList* item = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseSingleValueProperty(item->mValue, aPropID)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
item->mNext = new nsCSSValueList;
|
|
|
|
item = item->mNext;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aPropID, value);
|
|
|
|
return PR_TRUE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
|
2009-05-28 11:09:05 -07:00
|
|
|
// This function is very similar to ParseBackgroundList and ParseBackgroundSize.
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2009-02-19 21:29:21 -08:00
|
|
|
CSSParserImpl::ParseBackgroundPosition()
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'initial' and 'inherit' stand alone, no list permitted.
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValuePair valuePair;
|
|
|
|
if (!ParseBoxPositionValues(valuePair, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePairList* item = value.SetPairListValue();
|
|
|
|
for (;;) {
|
|
|
|
item->mXValue = valuePair.mXValue;
|
|
|
|
item->mYValue = valuePair.mYValue;
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ParseBoxPositionValues(valuePair, PR_FALSE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
item->mNext = new nsCSSValuePairList;
|
2010-08-19 12:33:44 -07:00
|
|
|
item = item->mNext;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_background_position, value);
|
|
|
|
return PR_TRUE;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses two values that correspond to positions in a box. These can be
|
|
|
|
* values corresponding to percentages of the box, raw offsets, or keywords
|
|
|
|
* like "top," "left center," etc.
|
|
|
|
*
|
2009-05-28 11:09:05 -07:00
|
|
|
* @param aOut The nsCSSValuePair in which to place the result.
|
2009-08-01 08:53:40 -07:00
|
|
|
* @param aAcceptsInherit If true, 'inherit' and 'initial' are legal values
|
2008-09-13 02:42:11 -07:00
|
|
|
* @return Whether or not the operation succeeded.
|
|
|
|
*/
|
2009-08-01 08:53:40 -07:00
|
|
|
PRBool CSSParserImpl::ParseBoxPositionValues(nsCSSValuePair &aOut,
|
|
|
|
PRBool aAcceptsInherit)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// First try a percentage or a length value
|
2008-09-13 02:42:11 -07:00
|
|
|
nsCSSValue &xValue = aOut.mXValue,
|
|
|
|
&yValue = aOut.mYValue;
|
2009-08-01 08:53:40 -07:00
|
|
|
PRInt32 variantMask = aAcceptsInherit ? VARIANT_HLP : VARIANT_LP;
|
|
|
|
if (ParseVariant(xValue, variantMask, nsnull)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSUnit_Inherit == xValue.GetUnit() ||
|
|
|
|
eCSSUnit_Initial == xValue.GetUnit()) { // both are inherited or both are set to initial
|
2007-04-15 15:25:20 -07:00
|
|
|
yValue = xValue;
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// We have one percentage/length. Get the optional second
|
|
|
|
// percentage/length/keyword.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseVariant(yValue, VARIANT_LP, nsnull)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We have two numbers
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(yValue, nsCSSProps::kBackgroundPositionKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 yVal = yValue.GetIntValue();
|
|
|
|
if (!(yVal & BG_CTB)) {
|
|
|
|
// The second keyword can only be 'center', 'top', or 'bottom'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
yValue = BoxPositionMaskToCSSValue(yVal, PR_FALSE);
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If only one percentage or length value is given, it sets the
|
|
|
|
// horizontal position only, and the vertical position will be 50%.
|
2007-04-15 15:25:20 -07:00
|
|
|
yValue.SetPercentValue(0.5f);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07: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;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(xValue, nsCSSProps::kBackgroundPositionKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 bit = xValue.GetIntValue();
|
|
|
|
mask |= bit;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(xValue, nsCSSProps::kBackgroundPositionKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseVariant(yValue, VARIANT_LP, nsnull)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(mask & BG_CLR)) {
|
|
|
|
// The first keyword can only be 'center', 'left', or 'right'
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
xValue = BoxPositionMaskToCSSValue(mask, PR_TRUE);
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-04-15 15:25:20 -07:00
|
|
|
// Create style values
|
2008-09-13 02:42:11 -07:00
|
|
|
xValue = BoxPositionMaskToCSSValue(mask, PR_TRUE);
|
|
|
|
yValue = BoxPositionMaskToCSSValue(mask, PR_FALSE);
|
2007-04-15 15:25:20 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-28 11:09:05 -07:00
|
|
|
// This function is very similar to ParseBackgroundList and
|
|
|
|
// ParseBackgroundPosition.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBackgroundSize()
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'initial' and 'inherit' stand alone, no list permitted.
|
|
|
|
if (!ExpectEndProperty()) {
|
2009-05-28 11:09:05 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValuePair valuePair;
|
2009-05-28 11:09:05 -07:00
|
|
|
if (!ParseBackgroundSizeValues(valuePair)) {
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2009-05-28 11:09:05 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePairList* item = value.SetPairListValue();
|
|
|
|
for (;;) {
|
|
|
|
item->mXValue = valuePair.mXValue;
|
|
|
|
item->mYValue = valuePair.mYValue;
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (!ParseBackgroundSizeValues(valuePair)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
item->mNext = new nsCSSValuePairList;
|
2010-08-19 12:33:44 -07:00
|
|
|
item = item->mNext;
|
2009-05-28 11:09:05 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_background_size, value);
|
|
|
|
return PR_TRUE;
|
2009-05-28 11:09:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-08 18:44:33 -07:00
|
|
|
* Parses two values that correspond to lengths for the background-size
|
2009-05-28 11:09:05 -07:00
|
|
|
* property. These can be one or two lengths (or the 'auto' keyword) or
|
|
|
|
* percentages corresponding to the element's dimensions or the single keywords
|
|
|
|
* 'contain' or 'cover'. 'initial' and 'inherit' must be handled by the caller
|
|
|
|
* if desired.
|
|
|
|
*
|
|
|
|
* @param aOut The nsCSSValuePair in which to place the result.
|
|
|
|
* @return Whether or not the operation succeeded.
|
|
|
|
*/
|
|
|
|
PRBool CSSParserImpl::ParseBackgroundSizeValues(nsCSSValuePair &aOut)
|
|
|
|
{
|
|
|
|
// First try a percentage or a length value
|
|
|
|
nsCSSValue &xValue = aOut.mXValue,
|
|
|
|
&yValue = aOut.mYValue;
|
|
|
|
if (ParseNonNegativeVariant(xValue, VARIANT_LP | VARIANT_AUTO, nsnull)) {
|
|
|
|
// We have one percentage/length/auto. Get the optional second
|
|
|
|
// percentage/length/keyword.
|
|
|
|
if (ParseNonNegativeVariant(yValue, VARIANT_LP | VARIANT_AUTO, nsnull)) {
|
|
|
|
// We have a second percentage/length/auto.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If only one percentage or length value is given, it sets the
|
|
|
|
// horizontal size only, and the vertical size will be as if by 'auto'.
|
|
|
|
yValue.SetAutoValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now address 'contain' and 'cover'.
|
|
|
|
if (!ParseEnum(xValue, nsCSSProps::kBackgroundSizeKTable))
|
|
|
|
return PR_FALSE;
|
|
|
|
yValue.Reset();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderColor()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kBorderColorSources[] = {
|
|
|
|
eCSSProperty_border_left_color_ltr_source,
|
|
|
|
eCSSProperty_border_left_color_rtl_source,
|
|
|
|
eCSSProperty_border_right_color_ltr_source,
|
|
|
|
eCSSProperty_border_right_color_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
// do this now, in case 4 values weren't specified
|
|
|
|
InitBoxPropsAsPhysical(kBorderColorSources);
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxProperties(kBorderColorIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderImage()
|
2008-07-16 23:30:25 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue val;
|
|
|
|
if (ParseVariant(val, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
AppendValue(eCSSProperty_border_image, val);
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// <uri> [<number> | <percentage>]{1,4}
|
|
|
|
// [ / <border-width>{1,4} ]? [stretch | repeat | round]{0,2}
|
2008-07-16 23:30:25 -07:00
|
|
|
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(11);
|
|
|
|
if (!arr) {
|
2008-09-09 21:38:14 -07:00
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
nsCSSValue& url = arr->Item(0);
|
|
|
|
nsCSSValue& splitTop = arr->Item(1);
|
|
|
|
nsCSSValue& splitRight = arr->Item(2);
|
|
|
|
nsCSSValue& splitBottom = arr->Item(3);
|
|
|
|
nsCSSValue& splitLeft = arr->Item(4);
|
|
|
|
nsCSSValue& borderWidthTop = arr->Item(5);
|
|
|
|
nsCSSValue& borderWidthRight = arr->Item(6);
|
|
|
|
nsCSSValue& borderWidthBottom = arr->Item(7);
|
|
|
|
nsCSSValue& borderWidthLeft = arr->Item(8);
|
|
|
|
nsCSSValue& horizontalKeyword = arr->Item(9);
|
|
|
|
nsCSSValue& verticalKeyword = arr->Item(10);
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
// <uri>
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseVariant(url, VARIANT_URL, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
// [<number> | <percentage>]{1,4}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(splitTop,
|
|
|
|
VARIANT_NUMBER | VARIANT_PERCENT, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(splitRight,
|
|
|
|
VARIANT_NUMBER | VARIANT_PERCENT, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
splitRight = splitTop;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(splitBottom,
|
|
|
|
VARIANT_NUMBER | VARIANT_PERCENT, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
splitBottom = splitTop;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(splitLeft,
|
|
|
|
VARIANT_NUMBER | VARIANT_PERCENT, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
splitLeft = splitRight;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
// [ / <border-width>{1,4} ]?
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('/', PR_TRUE)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
// if have '/', at least one value is required
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(borderWidthTop, VARIANT_LENGTH, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(borderWidthRight, VARIANT_LENGTH, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
borderWidthRight = borderWidthTop;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(borderWidthBottom, VARIANT_LENGTH, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
borderWidthBottom = borderWidthTop;
|
|
|
|
}
|
2009-03-09 16:14:34 -07:00
|
|
|
if (!ParseNonNegativeVariant(borderWidthLeft, VARIANT_LENGTH, nsnull)) {
|
2008-07-16 23:30:25 -07:00
|
|
|
borderWidthLeft = borderWidthRight;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
// [stretch | repeat | round]{0,2}
|
|
|
|
// missing keywords are handled in nsRuleNode::ComputeBorderData()
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(horizontalKeyword, nsCSSProps::kBorderImageKTable)) {
|
2010-03-11 22:50:10 -08:00
|
|
|
(void)ParseEnum(verticalKeyword, nsCSSProps::kBorderImageKTable);
|
2008-07-16 23:30:25 -07:00
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
|
|
|
if (!ExpectEndProperty()) {
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
val.SetArrayValue(arr, eCSSUnit_Array);
|
|
|
|
AppendValue(eCSSProperty_border_image, val);
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderSpacing()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue xValue, yValue;
|
|
|
|
if (!ParseNonNegativeVariant(xValue, VARIANT_HL | VARIANT_CALC, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// If we have one length, get the optional second length.
|
|
|
|
// set the second value equal to the first.
|
|
|
|
if (xValue.IsLengthUnit() || xValue.IsCalcUnit()) {
|
|
|
|
ParseNonNegativeVariant(yValue, VARIANT_LENGTH | VARIANT_CALC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yValue == xValue || yValue.GetUnit() == eCSSUnit_Null) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_border_spacing, xValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue pair;
|
|
|
|
pair.SetPairValue(xValue, yValue);
|
|
|
|
AppendValue(eCSSProperty_border_spacing, pair);
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderSide(const nsCSSProperty aPropIDs[],
|
|
|
|
PRBool aSetAllSides)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
nsCSSValue values[numProps];
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32 found = ParseChoice(values, aPropIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((found & 1) == 0) { // Provide default border-width
|
|
|
|
values[0].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
if ((found & 2) == 0) { // Provide default border-style
|
2009-10-21 14:57:57 -07:00
|
|
|
values[1].SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) { // text color will be used
|
|
|
|
values[2].SetIntValue(NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSetAllSides) {
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kBorderSources[] = {
|
|
|
|
eCSSProperty_border_left_color_ltr_source,
|
|
|
|
eCSSProperty_border_left_color_rtl_source,
|
|
|
|
eCSSProperty_border_right_color_ltr_source,
|
|
|
|
eCSSProperty_border_right_color_rtl_source,
|
|
|
|
eCSSProperty_border_left_style_ltr_source,
|
|
|
|
eCSSProperty_border_left_style_rtl_source,
|
|
|
|
eCSSProperty_border_right_style_ltr_source,
|
|
|
|
eCSSProperty_border_right_style_rtl_source,
|
|
|
|
eCSSProperty_border_left_width_ltr_source,
|
|
|
|
eCSSProperty_border_left_width_rtl_source,
|
|
|
|
eCSSProperty_border_right_width_ltr_source,
|
|
|
|
eCSSProperty_border_right_width_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
InitBoxPropsAsPhysical(kBorderSources);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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]);
|
2008-09-09 21:38:14 -07:00
|
|
|
}
|
2010-02-26 10:35:09 -08:00
|
|
|
|
|
|
|
static const nsCSSProperty kBorderColorsProps[] = {
|
|
|
|
eCSSProperty_border_top_colors,
|
|
|
|
eCSSProperty_border_right_colors,
|
|
|
|
eCSSProperty_border_bottom_colors,
|
|
|
|
eCSSProperty_border_left_colors
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the other properties that the border shorthand sets to their
|
|
|
|
// initial values.
|
|
|
|
nsCSSValue extraValue;
|
|
|
|
switch (values[0].GetUnit()) {
|
|
|
|
case eCSSUnit_Inherit: extraValue.SetInheritValue(); break;
|
|
|
|
case eCSSUnit_Initial: extraValue.SetInitialValue(); break;
|
|
|
|
default: extraValue.SetNoneValue(); break;
|
|
|
|
}
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(kBorderColorsProps[side], extraValue);
|
2010-02-26 10:35:09 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_border_image, extraValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Just set our one side
|
|
|
|
for (PRInt32 index = 0; index < numProps; index++) {
|
|
|
|
AppendValue(aPropIDs[index], values[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseDirectionalBorderSide(const nsCSSProperty aPropIDs[],
|
|
|
|
PRInt32 aSourceType)
|
2007-07-04 11:51:16 -07:00
|
|
|
{
|
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
nsCSSValue values[numProps];
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32 found = ParseChoice(values, aPropIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty())) {
|
2007-07-04 11:51:16 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((found & 1) == 0) { // Provide default border-width
|
|
|
|
values[0].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
if ((found & 2) == 0) { // Provide default border-style
|
2009-10-21 14:57:57 -07:00
|
|
|
values[1].SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
2007-07-04 11:51:16 -07:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) { // text color will be used
|
|
|
|
values[2].SetIntValue(NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
for (PRInt32 index = 0; index < numProps; index++) {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aPropIDs[index + numProps]);
|
|
|
|
NS_ASSERTION(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
|
|
|
AppendValue(subprops[0], values[index]);
|
|
|
|
nsCSSValue typeVal(aSourceType, eCSSUnit_Enumerated);
|
|
|
|
AppendValue(subprops[1], typeVal);
|
|
|
|
AppendValue(subprops[2], typeVal);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderStyle()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kBorderStyleSources[] = {
|
|
|
|
eCSSProperty_border_left_style_ltr_source,
|
|
|
|
eCSSProperty_border_left_style_rtl_source,
|
|
|
|
eCSSProperty_border_right_style_ltr_source,
|
|
|
|
eCSSProperty_border_right_style_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
// do this now, in case 4 values weren't specified
|
|
|
|
InitBoxPropsAsPhysical(kBorderStyleSources);
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxProperties(kBorderStyleIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseBorderWidth()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kBorderWidthSources[] = {
|
|
|
|
eCSSProperty_border_left_width_ltr_source,
|
|
|
|
eCSSProperty_border_left_width_rtl_source,
|
|
|
|
eCSSProperty_border_right_width_ltr_source,
|
|
|
|
eCSSProperty_border_right_width_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
// do this now, in case 4 values weren't specified
|
|
|
|
InitBoxPropsAsPhysical(kBorderWidthSources);
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxProperties(kBorderWidthIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseBorderColors(nsCSSProperty aProperty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
// 'inherit', 'initial', and 'none' are only allowed on their own
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2008-12-23 06:06:56 -08:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList *cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_COLOR | VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kBorderColorKTable)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aProperty, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 21:18:56 -07:00
|
|
|
static PRBool
|
|
|
|
HasMinMax(const nsCSSValue::Array *aArray)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0, i_end = aArray->Count(); i != i_end; ++i) {
|
|
|
|
const nsCSSValue &v = aArray->Item(i);
|
|
|
|
if (v.IsCalcUnit() &&
|
|
|
|
(v.GetUnit() == eCSSUnit_Calc_Minimum ||
|
|
|
|
v.GetUnit() == eCSSUnit_Calc_Maximum ||
|
|
|
|
HasMinMax(v.GetArrayValue()))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
// Parse the top level of a calc() expression, which can be calc(),
|
|
|
|
// min(), or max().
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCalc(nsCSSValue &aValue, PRInt32 aVariantMask)
|
|
|
|
{
|
|
|
|
// Parsing calc expressions requires, in a number of cases, looking
|
|
|
|
// for a token that is *either* a value of the property or a number.
|
|
|
|
// This can be done without lookahead when we assume that the property
|
|
|
|
// values cannot themselves be numbers.
|
|
|
|
NS_ASSERTION(!(aVariantMask & VARIANT_NUMBER), "unexpected variant mask");
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
|
2010-07-02 21:18:56 -07:00
|
|
|
PRBool noMinMax = aVariantMask & VARIANT_CALC_NO_MIN_MAX;
|
|
|
|
aVariantMask &= ~VARIANT_CALC_NO_MIN_MAX;
|
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
nsCSSUnit unit;
|
|
|
|
if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-min")) {
|
|
|
|
unit = eCSSUnit_Calc_Minimum;
|
|
|
|
} else if (mToken.mIdent.LowerCaseEqualsLiteral("-moz-max")) {
|
|
|
|
unit = eCSSUnit_Calc_Maximum;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mToken.mIdent.LowerCaseEqualsLiteral("-moz-calc"),
|
|
|
|
"unexpected function");
|
|
|
|
unit = eCSSUnit_Calc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unit != eCSSUnit_Calc) {
|
2010-07-02 21:18:56 -07:00
|
|
|
if (noMinMax) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-05-11 08:49:43 -07:00
|
|
|
return ParseCalcMinMax(aValue, unit, aVariantMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// One-iteration loop so we can break to the error-handling case.
|
|
|
|
do {
|
|
|
|
// The toplevel of a calc() is always an nsCSSValue::Array of length 1.
|
|
|
|
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(1);
|
|
|
|
if (!arr) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ParseCalcAdditiveExpression(arr->Item(0), aVariantMask))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
2010-07-02 21:18:56 -07:00
|
|
|
if (noMinMax && HasMinMax(arr)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-11 08:49:43 -07:00
|
|
|
aValue.SetArrayValue(arr, eCSSUnit_Calc);
|
|
|
|
return PR_TRUE;
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We optimize away the <value-expression> production given that
|
|
|
|
// ParseVariant consumes initial whitespace and we call
|
|
|
|
// ExpectSymbol(')') with PR_TRUE for aSkipWS.
|
|
|
|
// * If aVariantMask is VARIANT_NUMBER, this function parses the
|
|
|
|
// <number-additive-expression> production.
|
|
|
|
// * If aVariantMask does not contain VARIANT_NUMBER, this function
|
|
|
|
// parses the <value-additive-expression> production.
|
|
|
|
// * Otherwise (VARIANT_NUMBER and other bits) this function parses
|
|
|
|
// whichever one of the productions matches ***and modifies
|
|
|
|
// aVariantMask*** to reflect which one it has parsed by either
|
|
|
|
// removing VARIANT_NUMBER or removing all other bits.
|
|
|
|
// It does so iteratively, but builds the correct recursive
|
|
|
|
// data structure.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCalcAdditiveExpression(nsCSSValue& aValue,
|
|
|
|
PRInt32& aVariantMask)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
nsCSSValue *storage = &aValue;
|
|
|
|
for (;;) {
|
|
|
|
PRBool haveWS;
|
|
|
|
if (!ParseCalcMultiplicativeExpression(*storage, aVariantMask, &haveWS))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (!haveWS || !GetToken(PR_FALSE))
|
|
|
|
return PR_TRUE;
|
|
|
|
nsCSSUnit unit;
|
|
|
|
if (mToken.IsSymbol('+')) {
|
|
|
|
unit = eCSSUnit_Calc_Plus;
|
|
|
|
} else if (mToken.IsSymbol('-')) {
|
|
|
|
unit = eCSSUnit_Calc_Minus;
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (!RequireWhitespace())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(2);
|
|
|
|
if (!arr) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
arr->Item(0) = aValue;
|
|
|
|
storage = &arr->Item(1);
|
|
|
|
aValue.SetArrayValue(arr, unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-02 21:18:55 -07:00
|
|
|
struct ReduceNumberCalcOps : public mozilla::css::BasicFloatCalcOps,
|
|
|
|
public mozilla::css::CSSValueInputCalcOps
|
2010-05-11 08:49:43 -07:00
|
|
|
{
|
2010-05-11 08:49:44 -07:00
|
|
|
result_type ComputeLeafValue(const nsCSSValue& aValue)
|
2010-05-11 08:49:43 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
|
|
|
|
return aValue.GetFloatValue();
|
|
|
|
}
|
|
|
|
|
2010-05-11 08:49:44 -07:00
|
|
|
float ComputeNumber(const nsCSSValue& aValue)
|
2010-05-11 08:49:43 -07:00
|
|
|
{
|
2010-05-11 08:49:44 -07:00
|
|
|
return mozilla::css::ComputeCalc(aValue, *this);
|
2010-05-11 08:49:43 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// * If aVariantMask is VARIANT_NUMBER, this function parses the
|
|
|
|
// <number-multiplicative-expression> production.
|
|
|
|
// * If aVariantMask does not contain VARIANT_NUMBER, this function
|
|
|
|
// parses the <value-multiplicative-expression> production.
|
|
|
|
// * Otherwise (VARIANT_NUMBER and other bits) this function parses
|
|
|
|
// whichever one of the productions matches ***and modifies
|
|
|
|
// aVariantMask*** to reflect which one it has parsed by either
|
|
|
|
// removing VARIANT_NUMBER or removing all other bits.
|
|
|
|
// It does so iteratively, but builds the correct recursive data
|
|
|
|
// structure.
|
|
|
|
// This function always consumes *trailing* whitespace when it returns
|
|
|
|
// true; whether there was any such whitespace is returned in the
|
|
|
|
// aHadFinalWS parameter.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCalcMultiplicativeExpression(nsCSSValue& aValue,
|
|
|
|
PRInt32& aVariantMask,
|
|
|
|
PRBool *aHadFinalWS)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
PRBool gotValue = PR_FALSE; // already got the part with the unit
|
|
|
|
PRBool afterDivision = PR_FALSE;
|
|
|
|
|
|
|
|
nsCSSValue *storage = &aValue;
|
|
|
|
for (;;) {
|
|
|
|
PRInt32 variantMask;
|
|
|
|
if (afterDivision || gotValue) {
|
|
|
|
variantMask = VARIANT_NUMBER;
|
|
|
|
} else {
|
|
|
|
variantMask = aVariantMask | VARIANT_NUMBER;
|
|
|
|
}
|
|
|
|
if (!ParseCalcTerm(*storage, variantMask))
|
|
|
|
return PR_FALSE;
|
|
|
|
NS_ABORT_IF_FALSE(variantMask != 0,
|
|
|
|
"ParseCalcTerm did not set variantMask appropriately");
|
|
|
|
NS_ABORT_IF_FALSE(!(variantMask & VARIANT_NUMBER) ||
|
|
|
|
!(variantMask & ~PRInt32(VARIANT_NUMBER)),
|
|
|
|
"ParseCalcTerm did not set variantMask appropriately");
|
|
|
|
|
|
|
|
if (variantMask & VARIANT_NUMBER) {
|
|
|
|
// Simplify the value immediately so we can check for division by
|
|
|
|
// zero.
|
2010-05-11 08:49:44 -07:00
|
|
|
ReduceNumberCalcOps ops;
|
|
|
|
float number = mozilla::css::ComputeCalc(*storage, ops);
|
2010-05-11 08:49:43 -07:00
|
|
|
if (number == 0.0 && afterDivision)
|
|
|
|
return PR_FALSE;
|
|
|
|
storage->SetFloatValue(number, eCSSUnit_Number);
|
|
|
|
} else {
|
|
|
|
gotValue = PR_TRUE;
|
|
|
|
|
|
|
|
if (storage != &aValue) {
|
|
|
|
// Simplify any numbers in the Times_L position (which are
|
|
|
|
// not simplified by the check above).
|
|
|
|
NS_ABORT_IF_FALSE(storage == &aValue.GetArrayValue()->Item(1),
|
|
|
|
"unexpected relationship to current storage");
|
|
|
|
nsCSSValue &leftValue = aValue.GetArrayValue()->Item(0);
|
2010-05-11 08:49:44 -07:00
|
|
|
ReduceNumberCalcOps ops;
|
|
|
|
float number = mozilla::css::ComputeCalc(leftValue, ops);
|
2010-05-11 08:49:43 -07:00
|
|
|
leftValue.SetFloatValue(number, eCSSUnit_Number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool hadWS = RequireWhitespace();
|
|
|
|
if (!GetToken(PR_FALSE)) {
|
|
|
|
*aHadFinalWS = hadWS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCSSUnit unit;
|
|
|
|
if (mToken.IsSymbol('*')) {
|
|
|
|
unit = gotValue ? eCSSUnit_Calc_Times_R : eCSSUnit_Calc_Times_L;
|
|
|
|
afterDivision = PR_FALSE;
|
|
|
|
} else if (mToken.IsSymbol('/')) {
|
|
|
|
unit = eCSSUnit_Calc_Divided;
|
|
|
|
afterDivision = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
*aHadFinalWS = hadWS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(2);
|
|
|
|
if (!arr) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
arr->Item(0) = aValue;
|
|
|
|
storage = &arr->Item(1);
|
|
|
|
aValue.SetArrayValue(arr, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust aVariantMask (see comments above function) to reflect which
|
|
|
|
// option we took.
|
|
|
|
if (aVariantMask & VARIANT_NUMBER) {
|
|
|
|
if (gotValue) {
|
|
|
|
aVariantMask &= ~PRInt32(VARIANT_NUMBER);
|
|
|
|
} else {
|
|
|
|
aVariantMask = VARIANT_NUMBER;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!gotValue) {
|
|
|
|
// We had to find a value, but we didn't.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// * If aVariantMask is VARIANT_NUMBER, this function parses the
|
|
|
|
// <number-term> production.
|
|
|
|
// * If aVariantMask does not contain VARIANT_NUMBER, this function
|
|
|
|
// parses the <value-term> production.
|
|
|
|
// * Otherwise (VARIANT_NUMBER and other bits) this function parses
|
|
|
|
// whichever one of the productions matches ***and modifies
|
|
|
|
// aVariantMask*** to reflect which one it has parsed by either
|
|
|
|
// removing VARIANT_NUMBER or removing all other bits.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCalcTerm(nsCSSValue& aValue, PRInt32& aVariantMask)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
if (!GetToken(PR_TRUE))
|
|
|
|
return PR_FALSE;
|
|
|
|
// Either an additive expression in parentheses...
|
|
|
|
if (mToken.IsSymbol('(')) {
|
|
|
|
if (!ParseCalcAdditiveExpression(aValue, aVariantMask) ||
|
|
|
|
!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// ... or a min() or max() expression
|
|
|
|
if (mToken.mType == eCSSToken_Function &&
|
|
|
|
(mToken.mIdent.LowerCaseEqualsLiteral("min") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("max"))) {
|
|
|
|
nsCSSUnit unit = mToken.mIdent.LowerCaseEqualsLiteral("min")
|
|
|
|
? eCSSUnit_Calc_Minimum : eCSSUnit_Calc_Maximum;
|
|
|
|
return ParseCalcMinMax(aValue, unit, aVariantMask);
|
|
|
|
}
|
|
|
|
// ... or just a value
|
|
|
|
UngetToken();
|
|
|
|
if (!ParseVariant(aValue, aVariantMask, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// If we did the value parsing, we need to adjust aVariantMask to
|
|
|
|
// reflect which option we took (see above).
|
|
|
|
if (aVariantMask & VARIANT_NUMBER) {
|
|
|
|
if (aValue.GetUnit() == eCSSUnit_Number) {
|
|
|
|
aVariantMask = VARIANT_NUMBER;
|
|
|
|
} else {
|
|
|
|
aVariantMask &= ~PRInt32(VARIANT_NUMBER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function handles and modifies aVariantMask exactly as
|
|
|
|
// described for ParcCalcTerm above.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCalcMinMax(nsCSSValue& aValue, nsCSSUnit aUnit,
|
|
|
|
PRInt32& aVariantMask)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
NS_ASSERTION(aUnit == eCSSUnit_Calc_Minimum ||
|
|
|
|
aUnit == eCSSUnit_Calc_Maximum,
|
|
|
|
"unexpected unit");
|
|
|
|
NS_ASSERTION(mToken.mType == eCSSToken_Function, "unexpected current token");
|
|
|
|
NS_ASSERTION(aUnit != eCSSUnit_Calc_Minimum ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("min") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-min"),
|
|
|
|
"unexpected current token");
|
|
|
|
NS_ASSERTION(aUnit != eCSSUnit_Calc_Maximum ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("max") ||
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("-moz-max"),
|
|
|
|
"unexpected current token");
|
|
|
|
|
|
|
|
nsAutoTArray<nsCSSValue, 4> values;
|
|
|
|
for (;;) {
|
|
|
|
nsCSSValue *v = values.AppendElement();
|
|
|
|
if (!v) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ParseCalcAdditiveExpression(*v, aVariantMask))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!(aVariantMask & VARIANT_NUMBER) ||
|
|
|
|
!(aVariantMask & ~PRInt32(VARIANT_NUMBER)),
|
|
|
|
"parsing additive expr did not adjust variant mask");
|
|
|
|
NS_ABORT_IF_FALSE(aVariantMask != 0, "unexpected variant mask");
|
|
|
|
|
|
|
|
if (ExpectSymbol(',', PR_TRUE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ExpectSymbol(')', PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We allow min() and max() to take 1 or more arguments; the code
|
|
|
|
// above already ensures that.
|
|
|
|
NS_ABORT_IF_FALSE(values.Length() > 0, "unexpected length");
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(values.Length());
|
|
|
|
if (!arr) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
for (PRUint32 i = 0, i_end = values.Length(); i < i_end; ++i) {
|
|
|
|
arr->Item(i) = values[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
aValue.SetArrayValue(arr, aUnit);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function consumes all consecutive whitespace and returns whether
|
|
|
|
// there was any.
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::RequireWhitespace()
|
|
|
|
{
|
|
|
|
if (!GetToken(PR_FALSE))
|
|
|
|
return PR_FALSE;
|
|
|
|
if (mToken.mType != eCSSToken_WhiteSpace) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// Skip any additional whitespace tokens.
|
|
|
|
if (GetToken(PR_TRUE)) {
|
|
|
|
UngetToken();
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseRect(nsCSSProperty aPropID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! GetToken(PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
|
|
|
|
nsCSSValue val;
|
|
|
|
|
|
|
|
if (mToken.mType == eCSSToken_Ident) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
|
|
|
|
switch (keyword) {
|
|
|
|
case eCSSKeyword_auto:
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
val.SetAutoValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eCSSKeyword_inherit:
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
val.SetInheritValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eCSSKeyword__moz_initial:
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
val.SetInitialValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UngetToken();
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else if (mToken.mType == eCSSToken_Function &&
|
2007-03-22 10:30:00 -07:00
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("rect")) {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSRect& rect = val.SetRectValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2010-08-19 12:33:44 -07:00
|
|
|
if (! ParseVariant(rect.*(nsCSSRect::sides[side]),
|
2007-03-22 10:30:00 -07:00
|
|
|
VARIANT_AL, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (side < 3) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// skip optional commas between elements
|
2010-03-11 22:50:10 -08:00
|
|
|
(void)ExpectSymbol(',', PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
|
|
|
|
AppendValue(aPropID, val);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define VARIANT_CONTENT (VARIANT_STRING | VARIANT_URL | VARIANT_COUNTER | VARIANT_ATTR | \
|
|
|
|
VARIANT_KEYWORD)
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseContent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
// We need to divide the 'content' keywords into two classes for
|
|
|
|
// ParseVariant's sake, so we can't just use nsCSSProps::kContentKTable.
|
|
|
|
static const PRInt32 kContentListKWs[] = {
|
|
|
|
eCSSKeyword_open_quote, NS_STYLE_CONTENT_OPEN_QUOTE,
|
|
|
|
eCSSKeyword_close_quote, NS_STYLE_CONTENT_CLOSE_QUOTE,
|
|
|
|
eCSSKeyword_no_open_quote, NS_STYLE_CONTENT_NO_OPEN_QUOTE,
|
|
|
|
eCSSKeyword_no_close_quote, NS_STYLE_CONTENT_NO_CLOSE_QUOTE,
|
|
|
|
eCSSKeyword_UNKNOWN,-1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const PRInt32 kContentSolitaryKWs[] = {
|
|
|
|
eCSSKeyword__moz_alt_content, NS_STYLE_CONTENT_ALT_CONTENT,
|
|
|
|
eCSSKeyword_UNKNOWN,-1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that these two lists add up to the size of
|
|
|
|
// nsCSSProps::kContentKTable.
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::kContentKTable[
|
|
|
|
NS_ARRAY_LENGTH(kContentListKWs) +
|
|
|
|
NS_ARRAY_LENGTH(kContentSolitaryKWs) - 4] ==
|
|
|
|
eCSSKeyword_UNKNOWN &&
|
|
|
|
nsCSSProps::kContentKTable[
|
|
|
|
NS_ARRAY_LENGTH(kContentListKWs) +
|
|
|
|
NS_ARRAY_LENGTH(kContentSolitaryKWs) - 3] == -1,
|
|
|
|
"content keyword tables out of sync");
|
|
|
|
|
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_HMK | VARIANT_NONE,
|
|
|
|
kContentSolitaryKWs)) {
|
|
|
|
// 'inherit', 'initial', 'normal', 'none', and 'alt-content' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_CONTENT, kContentListKWs)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (CheckEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_content, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseCounterData(nsCSSProperty aPropID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (!ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
if (!GetToken(PR_TRUE) || mToken.mType != eCSSToken_Ident) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePairList *cur = value.SetPairListValue();
|
|
|
|
for (;;) {
|
|
|
|
cur->mXValue.SetStringValue(mToken.mIdent, eCSSUnit_Ident);
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mToken.mType == eCSSToken_Number && mToken.mIntegerValid) {
|
|
|
|
cur->mYValue.SetIntValue(mToken.mInteger, eCSSUnit_Integer);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (CheckEndProperty()) {
|
2010-08-19 12:33:44 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!GetToken(PR_TRUE) || mToken.mType != eCSSToken_Ident) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cur->mNext = new nsCSSValuePairList;
|
2010-08-19 12:33:44 -07:00
|
|
|
cur = cur->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aPropID, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCue()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSValue before;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(before, eCSSProperty_cue_before)) {
|
2007-04-20 17:16:52 -07:00
|
|
|
if (eCSSUnit_Inherit != before.GetUnit() &&
|
|
|
|
eCSSUnit_Initial != before.GetUnit()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSValue after;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(after, eCSSProperty_cue_after)) {
|
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_cue_before, before);
|
|
|
|
AppendValue(eCSSProperty_cue_after, after);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_cue_before, before);
|
|
|
|
AppendValue(eCSSProperty_cue_after, before);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseCursor()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'inherit' and 'initial' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_UK, nsCSSProps::kCursorKTable)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (cur->mValue.GetUnit() != eCSSUnit_URL) { // keyword must be last
|
|
|
|
if (ExpectEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// We have a URL, so make a value array with three values.
|
|
|
|
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(3);
|
|
|
|
val->Item(0) = cur->mValue;
|
|
|
|
|
|
|
|
// Parse optional x and y position of cursor hotspot (css3-ui).
|
|
|
|
if (ParseVariant(val->Item(1), VARIANT_NUMBER, nsnull)) {
|
|
|
|
// If we have one number, we must have two.
|
|
|
|
if (!ParseVariant(val->Item(2), VARIANT_NUMBER, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cur->mValue.SetArrayValue(val, eCSSUnit_Array);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) { // url must not be last
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_cursor, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseFont()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const nsCSSProperty fontIDs[] = {
|
|
|
|
eCSSProperty_font_style,
|
|
|
|
eCSSProperty_font_variant,
|
|
|
|
eCSSProperty_font_weight
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCSSValue family;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseVariant(family, VARIANT_HK, nsCSSProps::kFontKTable)) {
|
|
|
|
if (ExpectEndProperty()) {
|
2007-05-14 22:13:49 -07:00
|
|
|
if (eCSSUnit_Inherit == family.GetUnit() ||
|
|
|
|
eCSSUnit_Initial == family.GetUnit()) {
|
2007-06-12 11:28:56 -07:00
|
|
|
AppendValue(eCSSProperty__x_system_font, nsCSSValue(eCSSUnit_None));
|
2007-03-22 10:30:00 -07: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);
|
2010-07-13 13:30:42 -07:00
|
|
|
AppendValue(eCSSProperty_font_feature_settings, family);
|
|
|
|
AppendValue(eCSSProperty_font_language_override, family);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-06-12 11:28:56 -07:00
|
|
|
AppendValue(eCSSProperty__x_system_font, family);
|
|
|
|
nsCSSValue systemFont(eCSSUnit_System_Font);
|
|
|
|
AppendValue(eCSSProperty_font_family, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_style, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_variant, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_weight, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_size, systemFont);
|
|
|
|
AppendValue(eCSSProperty_line_height, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_stretch, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_size_adjust, systemFont);
|
2010-07-13 13:30:42 -07:00
|
|
|
AppendValue(eCSSProperty_font_feature_settings, systemFont);
|
|
|
|
AppendValue(eCSSProperty_font_language_override, systemFont);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get optional font-style, font-variant and font-weight (in any order)
|
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
nsCSSValue values[numProps];
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32 found = ParseChoice(values, fontIDs, numProps);
|
|
|
|
if ((found < 0) || (eCSSUnit_Inherit == values[0].GetUnit()) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(eCSSUnit_Initial == values[0].GetUnit())) { // illegal data
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if ((found & 1) == 0) {
|
|
|
|
// Provide default font-style
|
2009-10-21 17:05:07 -07:00
|
|
|
values[0].SetIntValue(NS_FONT_STYLE_NORMAL, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if ((found & 2) == 0) {
|
|
|
|
// Provide default font-variant
|
2009-10-21 17:05:07 -07:00
|
|
|
values[1].SetIntValue(NS_FONT_VARIANT_NORMAL, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) {
|
|
|
|
// Provide default font-weight
|
2009-11-14 19:16:59 -08:00
|
|
|
values[2].SetIntValue(NS_FONT_WEIGHT_NORMAL, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get mandatory font-size
|
|
|
|
nsCSSValue size;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (! ParseVariant(size, VARIANT_KEYWORD | VARIANT_LP, nsCSSProps::kFontSizeKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get optional "/" line-height
|
|
|
|
nsCSSValue lineHeight;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectSymbol('/', PR_TRUE)) {
|
2009-03-09 16:14:34 -07:00
|
|
|
if (! ParseNonNegativeVariant(lineHeight,
|
|
|
|
VARIANT_NUMBER | VARIANT_LP | VARIANT_NORMAL,
|
|
|
|
nsnull)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lineHeight.SetNormalValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get final mandatory font-family
|
2007-06-12 11:28:56 -07:00
|
|
|
nsAutoParseCompoundProperty compound(this);
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseFamily(family)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((eCSSUnit_Inherit != family.GetUnit()) && (eCSSUnit_Initial != family.GetUnit()) &&
|
2008-09-09 21:38:14 -07:00
|
|
|
ExpectEndProperty()) {
|
2007-06-12 11:28:56 -07:00
|
|
|
AppendValue(eCSSProperty__x_system_font, nsCSSValue(eCSSUnit_None));
|
2007-03-22 10:30:00 -07: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);
|
2009-11-14 19:16:59 -08:00
|
|
|
AppendValue(eCSSProperty_font_stretch,
|
|
|
|
nsCSSValue(NS_FONT_STRETCH_NORMAL, eCSSUnit_Enumerated));
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_font_size_adjust, nsCSSValue(eCSSUnit_None));
|
2010-07-13 13:30:42 -07:00
|
|
|
AppendValue(eCSSProperty_font_feature_settings, nsCSSValue(eCSSUnit_Normal));
|
|
|
|
AppendValue(eCSSProperty_font_language_override, nsCSSValue(eCSSUnit_Normal));
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseFontWeight(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-14 19:16:59 -08:00
|
|
|
if (ParseVariant(aValue, VARIANT_HKI | VARIANT_SYSFONT,
|
|
|
|
nsCSSProps::kFontWeightKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSUnit_Integer == aValue.GetUnit()) { // ensure unit value
|
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
|
|
|
if ((100 <= intValue) &&
|
|
|
|
(intValue <= 900) &&
|
|
|
|
(0 == (intValue % 100))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseOneFamily(nsAString& aFamily)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSToken* tk = &mToken;
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
if (eCSSToken_Ident == tk->mType) {
|
|
|
|
aFamily.Append(tk->mIdent);
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_FALSE))
|
2008-08-10 14:13:49 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (eCSSToken_Ident == tk->mType) {
|
|
|
|
aFamily.Append(tk->mIdent);
|
|
|
|
} else if (eCSSToken_WhiteSpace == tk->mType) {
|
|
|
|
// Lookahead one token and drop whitespace if we are ending the
|
|
|
|
// font name.
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
UngetToken();
|
|
|
|
if (eCSSToken_Ident == tk->mType)
|
|
|
|
aFamily.Append(PRUnichar(' '));
|
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-08-10 14:13:49 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
2008-08-09 16:07:59 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
} else if (eCSSToken_String == tk->mType) {
|
|
|
|
aFamily.Append(tk->mSymbol); // replace the quotes
|
|
|
|
aFamily.Append(tk->mIdent); // XXX What if it had escaped quotes?
|
|
|
|
aFamily.Append(tk->mSymbol);
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// -moz-transform Parsing Implementation
|
|
|
|
|
|
|
|
/* Reads a function list of arguments. Do not call this function
|
|
|
|
* directly; it's mean to be caled from ParseFunction.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseFunctionInternals(const PRInt32 aVariantMask[],
|
|
|
|
PRUint16 aMinElems,
|
|
|
|
PRUint16 aMaxElems,
|
|
|
|
nsTArray<nsCSSValue> &aOutput)
|
|
|
|
{
|
|
|
|
for (PRUint16 index = 0; index < aMaxElems; ++index) {
|
|
|
|
nsCSSValue newValue;
|
|
|
|
if (!ParseVariant(newValue, aVariantMask[index], nsnull))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (!aOutput.AppendElement(newValue)) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See whether to continue or whether to look for end of function.
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
// We need to read the closing parenthesis, and also must take care
|
|
|
|
// that we haven't read too few symbols.
|
|
|
|
return ExpectSymbol(')', PR_TRUE) && (index + 1) >= aMinElems;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're here, we finished looping without hitting the end, so we read too
|
|
|
|
// many elements.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parses a function [ input of the form (a [, b]*) ] and stores it
|
|
|
|
* as an nsCSSValue that holds a function of the form
|
|
|
|
* function-name arg1 arg2 ... argN
|
|
|
|
*
|
|
|
|
* On error, the return value is PR_FALSE.
|
|
|
|
*
|
|
|
|
* @param aFunction The name of the function that we're reading.
|
|
|
|
* @param aAllowedTypes An array of values corresponding to the legal
|
|
|
|
* types for each element in the function. The zeroth element in the
|
|
|
|
* array corresponds to the first function parameter, etc. The length
|
|
|
|
* of this array _must_ be greater than or equal to aMaxElems or the
|
|
|
|
* behavior is undefined.
|
|
|
|
* @param aMinElems Minimum number of elements to read. Reading fewer than
|
|
|
|
* this many elements will result in the function failing.
|
|
|
|
* @param aMaxElems Maximum number of elements to read. Reading more than
|
|
|
|
* this many elements will result in the function failing.
|
|
|
|
* @param aValue (out) The value that was parsed.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseFunction(const nsString &aFunction,
|
|
|
|
const PRInt32 aAllowedTypes[],
|
|
|
|
PRUint16 aMinElems, PRUint16 aMaxElems,
|
|
|
|
nsCSSValue &aValue)
|
|
|
|
{
|
|
|
|
typedef nsTArray<nsCSSValue>::size_type arrlen_t;
|
|
|
|
|
|
|
|
/* 2^16 - 2, so that if we have 2^16 - 2 transforms, we have 2^16 - 1
|
|
|
|
* elements stored in the the nsCSSValue::Array.
|
|
|
|
*/
|
|
|
|
static const arrlen_t MAX_ALLOWED_ELEMS = 0xFFFE;
|
|
|
|
|
|
|
|
/* Make a copy of the function name, since the reference is _probably_ to
|
|
|
|
* mToken.mIdent, which is going to get overwritten during the course of this
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
nsString functionName(aFunction);
|
|
|
|
|
|
|
|
/* Read in a list of values as an nsTArray, failing if we can't or if
|
|
|
|
* it's out of bounds.
|
|
|
|
*/
|
|
|
|
nsTArray<nsCSSValue> foundValues;
|
|
|
|
if (!ParseFunctionInternals(aAllowedTypes, aMinElems, aMaxElems,
|
|
|
|
foundValues))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
/* Now, convert this nsTArray into an nsCSSValue::Array object.
|
|
|
|
* We'll need N + 1 spots, one for the function name and the rest for the
|
|
|
|
* arguments. In case the user has given us more than 2^16 - 2 arguments,
|
|
|
|
* we'll truncate them at 2^16 - 2 arguments.
|
|
|
|
*/
|
|
|
|
PRUint16 numElements = (foundValues.Length() <= MAX_ALLOWED_ELEMS ?
|
|
|
|
foundValues.Length() + 1 : MAX_ALLOWED_ELEMS);
|
|
|
|
nsRefPtr<nsCSSValue::Array> convertedArray =
|
2008-10-20 05:07:09 -07:00
|
|
|
nsCSSValue::Array::Create(numElements);
|
2008-09-13 02:42:11 -07:00
|
|
|
if (!convertedArray) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy things over. */
|
2009-03-05 20:05:01 -08:00
|
|
|
convertedArray->Item(0).SetStringValue(functionName, eCSSUnit_Ident);
|
2008-09-13 02:42:11 -07:00
|
|
|
for (PRUint16 index = 0; index + 1 < numElements; ++index)
|
|
|
|
convertedArray->Item(index + 1) = foundValues[static_cast<arrlen_t>(index)];
|
|
|
|
|
|
|
|
/* Fill in the outparam value with the array. */
|
|
|
|
aValue.SetArrayValue(convertedArray, eCSSUnit_Function);
|
|
|
|
|
|
|
|
/* Return it! */
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a token, determines the minimum and maximum number of function
|
|
|
|
* parameters to read, along with the mask that should be used to read
|
|
|
|
* those function parameters. If the token isn't a transform function,
|
|
|
|
* returns an error.
|
|
|
|
*
|
|
|
|
* @param aToken The token identifying the function.
|
|
|
|
* @param aMinElems [out] The minimum number of elements to read.
|
|
|
|
* @param aMaxElems [out] The maximum number of elements to read
|
|
|
|
* @param aVariantMask [out] The variant mask to use during parsing
|
|
|
|
* @return Whether the information was loaded successfully.
|
|
|
|
*/
|
|
|
|
static PRBool GetFunctionParseInformation(nsCSSKeyword aToken,
|
|
|
|
PRUint16 &aMinElems,
|
|
|
|
PRUint16 &aMaxElems,
|
|
|
|
const PRInt32 *& aVariantMask)
|
|
|
|
{
|
|
|
|
/* These types represent the common variant masks that will be used to
|
|
|
|
* parse out the individual functions. The order in the enumeration
|
|
|
|
* must match the order in which the masks are declared.
|
|
|
|
*/
|
2010-07-02 21:18:56 -07:00
|
|
|
enum { eLengthPercentCalc,
|
|
|
|
eTwoLengthPercentCalcs,
|
2008-09-13 02:42:11 -07:00
|
|
|
eAngle,
|
2008-09-20 09:39:12 -07:00
|
|
|
eTwoAngles,
|
2008-09-13 02:42:11 -07:00
|
|
|
eNumber,
|
|
|
|
eTwoNumbers,
|
|
|
|
eMatrix,
|
|
|
|
eNumVariantMasks };
|
|
|
|
static const PRInt32 kMaxElemsPerFunction = 6;
|
|
|
|
static const PRInt32 kVariantMasks[eNumVariantMasks][kMaxElemsPerFunction] = {
|
2010-07-02 21:18:56 -07:00
|
|
|
{VARIANT_TRANSFORM_LPCALC},
|
|
|
|
{VARIANT_TRANSFORM_LPCALC, VARIANT_TRANSFORM_LPCALC},
|
2009-11-04 18:36:18 -08:00
|
|
|
{VARIANT_ANGLE_OR_ZERO},
|
|
|
|
{VARIANT_ANGLE_OR_ZERO, VARIANT_ANGLE_OR_ZERO},
|
2008-09-13 02:42:11 -07:00
|
|
|
{VARIANT_NUMBER},
|
|
|
|
{VARIANT_NUMBER, VARIANT_NUMBER},
|
|
|
|
{VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER,
|
2010-07-02 21:18:56 -07:00
|
|
|
VARIANT_TRANSFORM_LPCALC, VARIANT_TRANSFORM_LPCALC}};
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const PRUint8 kVariantMaskLengths[eNumVariantMasks] =
|
2008-09-20 09:39:12 -07:00
|
|
|
{1, 2, 1, 2, 1, 2, 6};
|
2008-09-13 02:42:11 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PRInt32 variantIndex = eNumVariantMasks;
|
|
|
|
|
|
|
|
switch (aToken) {
|
|
|
|
case eCSSKeyword_translatex:
|
|
|
|
case eCSSKeyword_translatey:
|
|
|
|
/* Exactly one length or percent. */
|
2010-07-02 21:18:56 -07:00
|
|
|
variantIndex = eLengthPercentCalc;
|
2008-09-13 02:42:11 -07:00
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_scalex:
|
|
|
|
/* Exactly one scale factor. */
|
|
|
|
variantIndex = eNumber;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_scaley:
|
|
|
|
/* Exactly one scale factor. */
|
|
|
|
variantIndex = eNumber;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_rotate:
|
|
|
|
/* Exactly one angle. */
|
|
|
|
variantIndex = eAngle;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_translate:
|
|
|
|
/* One or two lengths or percents. */
|
2010-07-02 21:18:56 -07:00
|
|
|
variantIndex = eTwoLengthPercentCalcs;
|
2008-09-13 02:42:11 -07:00
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 2U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_skew:
|
2008-09-20 09:39:12 -07:00
|
|
|
/* Exactly one or two angles. */
|
|
|
|
variantIndex = eTwoAngles;
|
2008-09-13 02:42:11 -07:00
|
|
|
aMinElems = 1U;
|
2008-09-20 09:39:12 -07:00
|
|
|
aMaxElems = 2U;
|
2008-09-13 02:42:11 -07:00
|
|
|
break;
|
|
|
|
case eCSSKeyword_scale:
|
|
|
|
/* One or two scale factors. */
|
|
|
|
variantIndex = eTwoNumbers;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 2U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_skewx:
|
|
|
|
/* Exactly one angle. */
|
|
|
|
variantIndex = eAngle;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_skewy:
|
|
|
|
/* Exactly one angle. */
|
|
|
|
variantIndex = eAngle;
|
|
|
|
aMinElems = 1U;
|
|
|
|
aMaxElems = 1U;
|
|
|
|
break;
|
|
|
|
case eCSSKeyword_matrix:
|
|
|
|
/* Six values, which can be numbers, lengths, or percents. */
|
|
|
|
variantIndex = eMatrix;
|
|
|
|
aMinElems = 6U;
|
|
|
|
aMaxElems = 6U;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Oh dear, we didn't match. Report an error. */
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aMinElems > 0, "Didn't update minimum elements!");
|
|
|
|
NS_ASSERTION(aMaxElems > 0, "Didn't update maximum elements!");
|
|
|
|
NS_ASSERTION(aMinElems <= aMaxElems, "aMinElems > aMaxElems!");
|
|
|
|
NS_ASSERTION(variantIndex >= 0, "Invalid variant mask!");
|
|
|
|
NS_ASSERTION(variantIndex < eNumVariantMasks, "Invalid variant mask!");
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(aMaxElems <= kVariantMaskLengths[variantIndex],
|
|
|
|
"Invalid aMaxElems for this variant mask.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Convert the index into a mask.
|
|
|
|
aVariantMask = kVariantMasks[variantIndex];
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads a single transform function from the tokenizer stream, reporting an
|
|
|
|
* error if something goes wrong.
|
|
|
|
*/
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseSingleTransform(nsCSSValue& aValue)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
|
|
|
if (!GetToken(PR_TRUE))
|
|
|
|
return PR_FALSE;
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
if (mToken.mType != eCSSToken_Function) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRInt32* variantMask;
|
|
|
|
PRUint16 minElems, maxElems;
|
|
|
|
if (!GetFunctionParseInformation(nsCSSKeywords::LookupKeyword(mToken.mIdent),
|
|
|
|
minElems, maxElems, variantMask))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseFunction(mToken.mIdent, variantMask, minElems, maxElems, aValue);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parses a -moz-transform property list by continuously reading in properties
|
|
|
|
* and constructing a matrix from it.
|
|
|
|
*/
|
|
|
|
PRBool CSSParserImpl::ParseMozTransform()
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
// 'inherit', 'initial', and 'none' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
2008-09-13 02:42:11 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseSingleTransform(cur->mValue)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty__moz_transform, value);
|
2008-09-13 02:42:11 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool CSSParserImpl::ParseMozTransformOrigin()
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValuePair position;
|
|
|
|
if (!ParseBoxPositionValues(position, PR_TRUE) || !ExpectEndProperty())
|
2008-09-13 02:42:11 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Unlike many other uses of pairs, this position should always be stored
|
|
|
|
// as a pair, even if the values are the same, so it always serializes as
|
|
|
|
// a pair, and to keep the computation code simple.
|
|
|
|
if (position.mXValue.GetUnit() == eCSSUnit_Inherit ||
|
|
|
|
position.mXValue.GetUnit() == eCSSUnit_Initial) {
|
|
|
|
NS_ABORT_IF_FALSE(position.mXValue == position.mYValue,
|
|
|
|
"inherit/initial only half?");
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty__moz_transform_origin, position.mXValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue pair;
|
|
|
|
pair.SetPairValue(&position);
|
|
|
|
AppendValue(eCSSProperty__moz_transform_origin, pair);
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseFamily(nsCSSValue& aValue)
|
2008-08-10 14:13:49 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (eCSSToken_Ident == mToken.mType) {
|
|
|
|
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(mToken.mIdent);
|
|
|
|
if (keyword == eCSSKeyword_inherit) {
|
|
|
|
aValue.SetInheritValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (keyword == eCSSKeyword__moz_initial) {
|
|
|
|
aValue.SetInitialValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (keyword == eCSSKeyword__moz_use_system_font &&
|
|
|
|
!IsParsingCompoundProperty()) {
|
|
|
|
aValue.SetSystemFontValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UngetToken();
|
|
|
|
|
|
|
|
nsAutoString family;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseOneFamily(family))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(',', PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
family.Append(PRUnichar(','));
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (family.IsEmpty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-03-05 20:05:01 -08:00
|
|
|
aValue.SetStringValue(family, eCSSUnit_Families);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
// src: ( uri-src | local-src ) (',' ( uri-src | local-src ) )*
|
|
|
|
// uri-src: uri [ 'format(' string ( ',' string )* ')' ]
|
|
|
|
// local-src: 'local(' ( string | ident ) ')'
|
|
|
|
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontSrc(nsCSSValue& aValue)
|
2008-08-10 14:13:49 -07:00
|
|
|
{
|
|
|
|
// could we maybe turn nsCSSValue::Array into nsTArray<nsCSSValue>?
|
|
|
|
nsTArray<nsCSSValue> values;
|
|
|
|
nsCSSValue cur;
|
|
|
|
for (;;) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (mToken.mType == eCSSToken_Function &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("url")) {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseURL(cur))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
values.AppendElement(cur);
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ParseFontSrcFormat(values))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
} else if (mToken.mType == eCSSToken_Function &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("local")) {
|
|
|
|
// css3-fonts does not specify a formal grammar for local().
|
|
|
|
// The text permits both unquoted identifiers and quoted
|
|
|
|
// strings. We resolve this ambiguity in the spec by
|
|
|
|
// assuming that the appropriate production is a single
|
|
|
|
// <family-name>, possibly surrounded by whitespace.
|
|
|
|
|
|
|
|
nsAutoString family;
|
2009-08-20 14:52:47 -07:00
|
|
|
if (!ParseOneFamily(family)) {
|
|
|
|
SkipUntil(')');
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
SkipUntil(')');
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
// the style parameters to the nsFont constructor are ignored,
|
|
|
|
// because it's only being used to call EnumerateFamilies
|
2009-01-29 12:39:18 -08:00
|
|
|
nsFont font(family, 0, 0, 0, 0, 0, 0);
|
2008-08-10 14:13:49 -07:00
|
|
|
ExtractFirstFamilyData dat;
|
|
|
|
|
|
|
|
font.EnumerateFamilies(ExtractFirstFamily, (void*) &dat);
|
|
|
|
if (!dat.mGood)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
cur.SetStringValue(dat.mFamilyName, eCSSUnit_Local_Font);
|
|
|
|
values.AppendElement(cur);
|
|
|
|
} else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectSymbol(',', PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
if (values.Length() == 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-08-10 14:13:49 -07:00
|
|
|
nsRefPtr<nsCSSValue::Array> srcVals
|
|
|
|
= nsCSSValue::Array::Create(values.Length());
|
2009-08-20 14:52:47 -07:00
|
|
|
if (!srcVals) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < values.Length(); i++)
|
|
|
|
srcVals->Item(i) = values[i];
|
|
|
|
aValue.SetArrayValue(srcVals, eCSSUnit_Array);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontSrcFormat(nsTArray<nsCSSValue> & values)
|
2008-08-10 14:13:49 -07:00
|
|
|
{
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_TRUE; // EOF harmless here
|
|
|
|
if (mToken.mType != eCSSToken_Function ||
|
|
|
|
!mToken.mIdent.LowerCaseEqualsLiteral("format")) {
|
|
|
|
UngetToken();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!GetToken(PR_TRUE))
|
2009-08-20 14:52:47 -07:00
|
|
|
return PR_FALSE; // EOF - no need for SkipUntil
|
2008-08-10 14:13:49 -07:00
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
if (mToken.mType != eCSSToken_String) {
|
2010-01-27 16:20:04 -08:00
|
|
|
UngetToken();
|
2009-08-20 14:52:47 -07:00
|
|
|
SkipUntil(')');
|
2008-08-10 14:13:49 -07:00
|
|
|
return PR_FALSE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
2008-08-10 14:13:49 -07:00
|
|
|
|
|
|
|
nsCSSValue cur(mToken.mIdent, eCSSUnit_Font_Format);
|
|
|
|
values.AppendElement(cur);
|
2008-09-09 21:38:14 -07:00
|
|
|
} while (ExpectSymbol(',', PR_TRUE));
|
2008-08-10 14:13:49 -07:00
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
if (!ExpectSymbol(')', PR_TRUE)) {
|
|
|
|
SkipUntil(')');
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
2008-08-10 14:13:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// font-ranges: urange ( ',' urange )*
|
|
|
|
PRBool
|
2008-09-09 21:38:14 -07:00
|
|
|
CSSParserImpl::ParseFontRanges(nsCSSValue& aValue)
|
2008-08-10 14:13:49 -07:00
|
|
|
{
|
2009-08-20 14:52:47 -07:00
|
|
|
nsTArray<PRUint32> ranges;
|
|
|
|
for (;;) {
|
|
|
|
if (!GetToken(PR_TRUE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (mToken.mType != eCSSToken_URange) {
|
|
|
|
UngetToken();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// An invalid range token is a parsing error, causing the entire
|
|
|
|
// descriptor to be ignored.
|
|
|
|
if (!mToken.mIntegerValid)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRUint32 low = mToken.mInteger;
|
|
|
|
PRUint32 high = mToken.mInteger2;
|
|
|
|
|
|
|
|
// A range that descends, or a range that is entirely outside the
|
|
|
|
// current range of Unicode (U+0-10FFFF) is ignored, but does not
|
|
|
|
// invalidate the descriptor. A range that straddles the high end
|
|
|
|
// is clipped.
|
|
|
|
if (low <= 0x10FFFF && low <= high) {
|
|
|
|
if (high > 0x10FFFF)
|
|
|
|
high = 0x10FFFF;
|
|
|
|
|
|
|
|
ranges.AppendElement(low);
|
|
|
|
ranges.AppendElement(high);
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ranges.Length() == 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSValue::Array> srcVals
|
|
|
|
= nsCSSValue::Array::Create(ranges.Length());
|
|
|
|
if (!srcVals) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < ranges.Length(); i++)
|
|
|
|
srcVals->Item(i).SetIntValue(ranges[i], eCSSUnit_Integer);
|
|
|
|
aValue.SetArrayValue(srcVals, eCSSUnit_Array);
|
|
|
|
return PR_TRUE;
|
2008-08-10 14:13:49 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseListStyle()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-22 17:28:13 -08:00
|
|
|
// 'list-style' can accept 'none' for two different subproperties,
|
|
|
|
// 'list-style-type' and 'list-style-position'. In order to accept
|
|
|
|
// 'none' as the value of either but still allow another value for
|
|
|
|
// either, we need to ensure that the first 'none' we find gets
|
|
|
|
// allocated to a dummy property instead.
|
2007-03-22 10:30:00 -07:00
|
|
|
static const nsCSSProperty listStyleIDs[] = {
|
2009-01-22 17:28:13 -08:00
|
|
|
eCSSPropertyExtra_x_none_value,
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSProperty_list_style_type,
|
|
|
|
eCSSProperty_list_style_position,
|
|
|
|
eCSSProperty_list_style_image
|
|
|
|
};
|
|
|
|
|
2009-01-22 17:28:13 -08:00
|
|
|
nsCSSValue values[NS_ARRAY_LENGTH(listStyleIDs)];
|
|
|
|
PRInt32 found =
|
|
|
|
ParseChoice(values, listStyleIDs, NS_ARRAY_LENGTH(listStyleIDs));
|
|
|
|
if (found < 1 || !ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-22 17:28:13 -08:00
|
|
|
if ((found & (1|2|8)) == (1|2|8)) {
|
|
|
|
if (values[0].GetUnit() == eCSSUnit_None) {
|
|
|
|
// We found a 'none' plus another value for both of
|
|
|
|
// 'list-style-type' and 'list-style-image'. This is a parse
|
|
|
|
// error, since the 'none' has to count for at least one of them.
|
|
|
|
return PR_FALSE;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(found == (1|2|4|8) && values[0] == values[1] &&
|
|
|
|
values[0] == values[2] && values[0] == values[3],
|
|
|
|
"should be a special value");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-22 17:28:13 -08:00
|
|
|
|
|
|
|
// Provide default values
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((found & 2) == 0) {
|
2009-01-22 17:28:13 -08:00
|
|
|
if (found & 1) {
|
2009-10-21 14:57:57 -07:00
|
|
|
values[1].SetIntValue(NS_STYLE_LIST_STYLE_NONE, eCSSUnit_Enumerated);
|
2009-01-22 17:28:13 -08:00
|
|
|
} else {
|
|
|
|
values[1].SetIntValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if ((found & 4) == 0) {
|
2009-01-22 17:28:13 -08:00
|
|
|
values[2].SetIntValue(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
if ((found & 8) == 0) {
|
|
|
|
values[3].SetNoneValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-22 17:28:13 -08:00
|
|
|
// Start at 1 to avoid appending fake value.
|
|
|
|
for (PRUint32 index = 1; index < NS_ARRAY_LENGTH(listStyleIDs); ++index) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(listStyleIDs[index], values[index]);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMargin()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const nsCSSProperty kMarginSideIDs[] = {
|
|
|
|
eCSSProperty_margin_top,
|
|
|
|
eCSSProperty_margin_right_value,
|
|
|
|
eCSSProperty_margin_bottom,
|
|
|
|
eCSSProperty_margin_left_value
|
|
|
|
};
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kMarginSources[] = {
|
|
|
|
eCSSProperty_margin_left_ltr_source,
|
|
|
|
eCSSProperty_margin_left_rtl_source,
|
|
|
|
eCSSProperty_margin_right_ltr_source,
|
|
|
|
eCSSProperty_margin_right_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// do this now, in case 4 values weren't specified
|
2007-07-04 11:51:16 -07:00
|
|
|
InitBoxPropsAsPhysical(kMarginSources);
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxProperties(kMarginSideIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMarks(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-21 14:57:57 -07:00
|
|
|
if (ParseVariant(aValue, VARIANT_HK, nsCSSProps::kPageMarksKTable)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
|
2009-10-21 14:57:57 -07:00
|
|
|
if (NS_STYLE_PAGE_MARKS_NONE != aValue.GetIntValue() &&
|
|
|
|
PR_FALSE == CheckEndProperty()) {
|
|
|
|
nsCSSValue second;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseEnum(second, nsCSSProps::kPageMarksKTable)) {
|
2009-10-21 14:57:57 -07:00
|
|
|
// 'none' keyword in conjuction with others is not allowed
|
|
|
|
if (NS_STYLE_PAGE_MARKS_NONE != second.GetIntValue()) {
|
|
|
|
aValue.SetIntValue(aValue.GetIntValue() | second.GetIntValue(),
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseOutline()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const PRInt32 numProps = 3;
|
|
|
|
static const nsCSSProperty kOutlineIDs[] = {
|
|
|
|
eCSSProperty_outline_color,
|
|
|
|
eCSSProperty_outline_style,
|
|
|
|
eCSSProperty_outline_width
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCSSValue values[numProps];
|
2008-09-09 21:38:14 -07:00
|
|
|
PRInt32 found = ParseChoice(values, kOutlineIDs, numProps);
|
|
|
|
if ((found < 1) || (PR_FALSE == ExpectEndProperty())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide default values
|
2009-10-21 14:57:57 -07:00
|
|
|
if ((found & 1) == 0) { // Provide default outline-color
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef GFX_HAS_INVERT
|
|
|
|
values[0].SetIntValue(NS_STYLE_COLOR_INVERT, eCSSUnit_Enumerated);
|
|
|
|
#else
|
|
|
|
values[0].SetIntValue(NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR, eCSSUnit_Enumerated);
|
|
|
|
#endif
|
|
|
|
}
|
2009-10-21 14:57:57 -07:00
|
|
|
if ((found & 2) == 0) { // Provide default outline-style
|
|
|
|
values[1].SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-21 14:57:57 -07:00
|
|
|
if ((found & 4) == 0) { // Provide default outline-width
|
2007-03-22 10:30:00 -07:00
|
|
|
values[2].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < numProps; index++) {
|
|
|
|
AppendValue(kOutlineIDs[index], values[index]);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseOverflow()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSValue overflow;
|
2009-10-21 14:57:57 -07:00
|
|
|
if (!ParseVariant(overflow, VARIANT_HK,
|
|
|
|
nsCSSProps::kOverflowKTable) ||
|
2008-09-09 21:38:14 -07:00
|
|
|
!ExpectEndProperty())
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParsePadding()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const nsCSSProperty kPaddingSideIDs[] = {
|
|
|
|
eCSSProperty_padding_top,
|
|
|
|
eCSSProperty_padding_right_value,
|
|
|
|
eCSSProperty_padding_bottom,
|
|
|
|
eCSSProperty_padding_left_value
|
|
|
|
};
|
2007-07-04 11:51:16 -07:00
|
|
|
static const nsCSSProperty kPaddingSources[] = {
|
|
|
|
eCSSProperty_padding_left_ltr_source,
|
|
|
|
eCSSProperty_padding_left_rtl_source,
|
|
|
|
eCSSProperty_padding_right_ltr_source,
|
|
|
|
eCSSProperty_padding_right_rtl_source,
|
|
|
|
eCSSProperty_UNKNOWN
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// do this now, in case 4 values weren't specified
|
2007-07-04 11:51:16 -07:00
|
|
|
InitBoxPropsAsPhysical(kPaddingSources);
|
2010-08-19 12:33:44 -07:00
|
|
|
return ParseBoxProperties(kPaddingSideIDs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParsePause()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSValue before;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(before, eCSSProperty_pause_before)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eCSSUnit_Inherit != before.GetUnit() && eCSSUnit_Initial != before.GetUnit()) {
|
|
|
|
nsCSSValue after;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(after, eCSSProperty_pause_after)) {
|
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_pause_before, before);
|
|
|
|
AppendValue(eCSSProperty_pause_after, after);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_pause_before, before);
|
|
|
|
AppendValue(eCSSProperty_pause_after, before);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseQuotes()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (!ParseVariant(value, VARIANT_HOS, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (value.GetUnit() != eCSSUnit_String) {
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCSSValue open = value;
|
|
|
|
nsCSSValuePairList* quotes = value.SetPairListValue();
|
|
|
|
for (;;) {
|
|
|
|
quotes->mXValue = open;
|
|
|
|
// get mandatory close
|
|
|
|
if (!ParseVariant(quotes->mYValue, VARIANT_STRING, nsnull)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (CheckEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
// look for another open
|
|
|
|
if (!ParseVariant(open, VARIANT_STRING, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
quotes->mNext = new nsCSSValuePairList;
|
2010-08-19 12:33:44 -07:00
|
|
|
quotes = quotes->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_quotes, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseSize()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue width, height;
|
|
|
|
if (!ParseVariant(width, VARIANT_AHKL, nsCSSProps::kPageSizeKTable)) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (width.IsLengthUnit()) {
|
|
|
|
ParseVariant(height, VARIANT_LENGTH, nsnull);
|
|
|
|
}
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width == height || height.GetUnit() == eCSSUnit_Null) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_size, width);
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue pair;
|
|
|
|
pair.SetPairValue(width, height);
|
|
|
|
AppendValue(eCSSProperty_size, pair);
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTextDecoration(nsCSSValue& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-21 14:57:57 -07:00
|
|
|
if (ParseVariant(aValue, VARIANT_HK, nsCSSProps::kTextDecorationKTable)) {
|
|
|
|
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 intValue = aValue.GetIntValue();
|
2009-10-21 14:57:57 -07:00
|
|
|
if (intValue != NS_STYLE_TEXT_DECORATION_NONE) {
|
|
|
|
// look for more keywords
|
|
|
|
nsCSSValue keyword;
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < 3; index++) {
|
|
|
|
if (ParseEnum(keyword, nsCSSProps::kTextDecorationKTable)) {
|
|
|
|
PRInt32 newValue = keyword.GetIntValue();
|
|
|
|
if (newValue == NS_STYLE_TEXT_DECORATION_NONE ||
|
|
|
|
newValue & intValue) {
|
|
|
|
// 'none' keyword in conjuction with others is not allowed, and
|
|
|
|
// duplicate keyword is not allowed.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
intValue |= newValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
2008-12-23 06:06:58 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-21 14:57:57 -07:00
|
|
|
aValue.SetIntValue(intValue, eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransitionTime(nsCSSProperty aPropID)
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'inherit' and 'initial' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
2009-08-20 14:52:47 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_TIME, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(aPropID, value);
|
|
|
|
return PR_TRUE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransitionProperty()
|
|
|
|
{
|
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE | VARIANT_ALL,
|
|
|
|
nsnull)) {
|
2010-08-19 12:33:44 -07:00
|
|
|
// 'inherit', 'initial', 'none', and 'all' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
2009-08-20 14:52:47 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
// Accept a list of arbitrary identifiers. They should be
|
|
|
|
// CSS properties, but we want to accept any so that we
|
|
|
|
// accept properties that we don't know about yet, e.g.
|
|
|
|
// transition-property: invalid-property, left, opacity;
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_IDENTIFIER, nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsDependentString str(cur->mValue.GetStringBufferValue());
|
|
|
|
// Exclude 'none' and 'all' and 'inherit' and 'initial'
|
|
|
|
// according to the same rules as for 'counter-reset' in CSS 2.1
|
|
|
|
// (except 'counter-reset' doesn't exclude 'all' since it
|
|
|
|
// doesn't support 'all' as a special value).
|
|
|
|
if (str.LowerCaseEqualsLiteral("none") ||
|
|
|
|
str.LowerCaseEqualsLiteral("all") ||
|
|
|
|
str.LowerCaseEqualsLiteral("inherit") ||
|
|
|
|
str.LowerCaseEqualsLiteral("initial")) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
REPORT_UNEXPECTED_TOKEN(PEExpectedComma);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_transition_property, value);
|
|
|
|
return PR_TRUE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransitionTimingFunction()
|
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT, nsnull)) {
|
|
|
|
// 'inherit' and 'initial' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
2009-08-20 14:52:47 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseVariant(cur->mValue, VARIANT_TIMING_FUNCTION,
|
|
|
|
nsCSSProps::kTransitionTimingFunctionKTable)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_transition_timing_function, value);
|
|
|
|
return PR_TRUE;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransitionTimingFunctionValues(nsCSSValue& aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mHavePushBack &&
|
|
|
|
mToken.mType == eCSSToken_Function &&
|
|
|
|
mToken.mIdent.LowerCaseEqualsLiteral("cubic-bezier"),
|
|
|
|
"unexpected initial state");
|
|
|
|
|
|
|
|
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(4);
|
|
|
|
if (!val) {
|
|
|
|
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x1, x2, y1, y2;
|
2010-08-11 12:32:52 -07:00
|
|
|
if (!ParseTransitionTimingFunctionValueComponent(x1, ',', PR_TRUE) ||
|
|
|
|
!ParseTransitionTimingFunctionValueComponent(y1, ',', PR_FALSE) ||
|
|
|
|
!ParseTransitionTimingFunctionValueComponent(x2, ',', PR_TRUE) ||
|
|
|
|
!ParseTransitionTimingFunctionValueComponent(y2, ')', PR_FALSE)) {
|
2009-08-20 14:52:47 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
val->Item(0).SetFloatValue(x1, eCSSUnit_Number);
|
|
|
|
val->Item(1).SetFloatValue(y1, eCSSUnit_Number);
|
|
|
|
val->Item(2).SetFloatValue(x2, eCSSUnit_Number);
|
|
|
|
val->Item(3).SetFloatValue(y2, eCSSUnit_Number);
|
|
|
|
|
|
|
|
aValue.SetArrayValue(val, eCSSUnit_Cubic_Bezier);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransitionTimingFunctionValueComponent(float& aComponent,
|
2010-08-11 12:32:52 -07:00
|
|
|
char aStop,
|
|
|
|
PRBool aCheckRange)
|
2009-08-20 14:52:47 -07:00
|
|
|
{
|
|
|
|
if (!GetToken(PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsCSSToken* tk = &mToken;
|
|
|
|
if (tk->mType == eCSSToken_Number) {
|
2010-08-11 12:32:52 -07:00
|
|
|
float num = tk->mNumber;
|
|
|
|
if (aCheckRange && (num < 0.0 || num > 1.0)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
aComponent = num;
|
2009-08-20 14:52:47 -07:00
|
|
|
if (ExpectSymbol(aStop, PR_TRUE)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
static nsCSSValueList*
|
|
|
|
AppendValueToList(nsCSSValue& aContainer,
|
|
|
|
nsCSSValueList* aTail,
|
|
|
|
const nsCSSValue& aValue)
|
2009-08-20 14:52:47 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValueList* entry;
|
|
|
|
if (aContainer.GetUnit() == eCSSUnit_Null) {
|
|
|
|
NS_ABORT_IF_FALSE(!aTail, "should not have an entry");
|
|
|
|
entry = aContainer.SetListValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(!aTail->mNext, "should not have a next entry");
|
|
|
|
NS_ABORT_IF_FALSE(aContainer.GetUnit() == eCSSUnit_List, "not a list");
|
|
|
|
entry = new nsCSSValueList;
|
|
|
|
aTail->mNext = entry;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
entry->mValue = aValue;
|
2010-08-19 12:33:44 -07:00
|
|
|
return entry;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseTransition()
|
|
|
|
{
|
|
|
|
static const nsCSSProperty kTransitionProperties[] = {
|
|
|
|
eCSSProperty_transition_duration,
|
|
|
|
eCSSProperty_transition_timing_function,
|
|
|
|
// Must check 'transition-delay' after 'transition-duration', since
|
|
|
|
// that's our assumption about what the spec means for the shorthand
|
|
|
|
// syntax (the first time given is the duration, and the second
|
|
|
|
// given is the delay).
|
|
|
|
eCSSProperty_transition_delay,
|
|
|
|
// Must check 'transition-property' after
|
|
|
|
// 'transition-timing-function' since 'transition-property' accepts
|
|
|
|
// any keyword.
|
|
|
|
eCSSProperty_transition_property
|
|
|
|
};
|
|
|
|
static const PRUint32 numProps = NS_ARRAY_LENGTH(kTransitionProperties);
|
|
|
|
// this is a shorthand property that accepts -property, -delay,
|
|
|
|
// -duration, and -timing-function with some components missing.
|
|
|
|
// there can be multiple transitions, separated with commas
|
|
|
|
|
|
|
|
nsCSSValue tempValue;
|
|
|
|
// first see if 'inherit' or '-moz-initial' is specified. If one is,
|
|
|
|
// it can be the only thing specified, so don't attempt to parse any
|
|
|
|
// additional properties
|
|
|
|
if (ParseVariant(tempValue, VARIANT_INHERIT, nsnull)) {
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(kTransitionProperties[i], tempValue);
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue values[numProps];
|
|
|
|
nsCSSValueList *cur[numProps] = { nsnull, nsnull, nsnull, nsnull };
|
2009-08-20 14:52:47 -07:00
|
|
|
PRBool atEOP = PR_FALSE; // at end of property?
|
|
|
|
for (;;) { // loop over comma-separated transitions
|
|
|
|
// whether a particular subproperty was specified for this transition
|
|
|
|
PRBool parsedProperty[numProps] =
|
|
|
|
{ PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE };
|
|
|
|
for (;;) { // loop over values within a transition
|
|
|
|
PRBool foundProperty = PR_FALSE;
|
|
|
|
// check to see if we're at the end of one full transition definition
|
|
|
|
// (either because we hit a comma or because we hit the end of the
|
|
|
|
// property definition)
|
|
|
|
if (ExpectSymbol(',', PR_TRUE))
|
|
|
|
break;
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
atEOP = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// else, try to parse the next transition sub-property
|
|
|
|
for (PRUint32 i = 0; !foundProperty && i < numProps; ++i) {
|
|
|
|
if (!parsedProperty[i]) {
|
|
|
|
// if we haven't found this property yet, try to parse it
|
|
|
|
PRInt32 variantMask;
|
|
|
|
const PRInt32* table = nsnull;
|
|
|
|
switch (kTransitionProperties[i]) {
|
|
|
|
case eCSSProperty_transition_property:
|
|
|
|
variantMask = VARIANT_IDENTIFIER | VARIANT_NONE | VARIANT_ALL;
|
|
|
|
break;
|
|
|
|
case eCSSProperty_transition_duration:
|
|
|
|
case eCSSProperty_transition_delay:
|
|
|
|
variantMask = VARIANT_TIME;
|
|
|
|
break;
|
|
|
|
case eCSSProperty_transition_timing_function:
|
|
|
|
variantMask = VARIANT_TIMING_FUNCTION;
|
|
|
|
table = nsCSSProps::kTransitionTimingFunctionKTable;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "Invalid transition property");
|
|
|
|
}
|
|
|
|
if (ParseVariant(tempValue, variantMask, table)) {
|
|
|
|
parsedProperty[i] = PR_TRUE;
|
2010-08-19 12:33:44 -07:00
|
|
|
cur[i] = AppendValueToList(values[i], cur[i], tempValue);
|
2009-08-20 14:52:47 -07:00
|
|
|
foundProperty = PR_TRUE;
|
|
|
|
break; // out of inner loop; continue looking for next sub-property
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!foundProperty) {
|
|
|
|
// We're not at a ',' or at the end of the property, but we couldn't
|
|
|
|
// parse any of the sub-properties, so the declaration is invalid.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We hit the end of the property or the end of one transition
|
|
|
|
// definition, add its components to the list.
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
|
|
|
// If all of the subproperties were not explicitly specified, fill
|
|
|
|
// in the missing ones with initial values.
|
|
|
|
if (!parsedProperty[i]) {
|
|
|
|
switch (kTransitionProperties[i]) {
|
|
|
|
case eCSSProperty_transition_property:
|
|
|
|
tempValue.SetAllValue();
|
|
|
|
break;
|
|
|
|
case eCSSProperty_transition_duration:
|
|
|
|
case eCSSProperty_transition_delay:
|
|
|
|
tempValue.SetFloatValue(0.0, eCSSUnit_Seconds);
|
|
|
|
break;
|
|
|
|
case eCSSProperty_transition_timing_function:
|
|
|
|
tempValue.SetIntValue(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "Invalid transition property");
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
cur[i] = AppendValueToList(values[i], cur[i], tempValue);
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atEOP)
|
|
|
|
break;
|
|
|
|
// else we just hit a ',' so continue parsing the next compound transition
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make two checks on the list for 'transition-property':
|
|
|
|
// + If there is more than one item, then none of the items can be
|
|
|
|
// 'none' or 'all'.
|
|
|
|
// + None of the items can be 'inherit' or 'initial' (this is the case,
|
|
|
|
// like with counter-reset &c., where CSS 2.1 specifies 'initial', so
|
|
|
|
// we should check it without the -moz- prefix).
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(kTransitionProperties[3] ==
|
|
|
|
eCSSProperty_transition_property,
|
|
|
|
"array index mismatch");
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValueList *l = values[3].GetListValue();
|
2009-08-20 14:52:47 -07:00
|
|
|
PRBool multipleItems = !!l->mNext;
|
|
|
|
do {
|
|
|
|
const nsCSSValue& val = l->mValue;
|
|
|
|
if (val.GetUnit() != eCSSUnit_Ident) {
|
|
|
|
NS_ABORT_IF_FALSE(val.GetUnit() == eCSSUnit_None ||
|
|
|
|
val.GetUnit() == eCSSUnit_All, "unexpected unit");
|
|
|
|
if (multipleItems) {
|
|
|
|
// This is a syntax error.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
|
|
|
|
// Unbox a solitary 'none' or 'all'.
|
|
|
|
if (val.GetUnit() == eCSSUnit_None) {
|
|
|
|
values[3].SetNoneValue();
|
|
|
|
} else {
|
|
|
|
values[3].SetAllValue();
|
|
|
|
}
|
|
|
|
break;
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
nsDependentString str(val.GetStringBufferValue());
|
|
|
|
if (str.EqualsLiteral("inherit") || str.EqualsLiteral("initial")) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} while ((l = l->mNext));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save all parsed transition sub-properties in mTempData
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(kTransitionProperties[i], values[i]);
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseShadowItem(nsCSSValue& aValue, PRBool aIsBoxShadow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
// A shadow list item is an array, with entries in this sequence:
|
2007-03-22 10:30:00 -07:00
|
|
|
enum {
|
|
|
|
IndexX,
|
|
|
|
IndexY,
|
|
|
|
IndexRadius,
|
2010-08-19 12:33:44 -07:00
|
|
|
IndexSpread, // only for box-shadow
|
2009-02-10 00:45:13 -08:00
|
|
|
IndexColor,
|
2010-08-19 12:33:44 -07:00
|
|
|
IndexInset // only for box-shadow
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(6);
|
2009-02-10 00:45:13 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (aIsBoxShadow) {
|
|
|
|
// Optional inset keyword (ignore errors)
|
|
|
|
ParseVariant(val->Item(IndexInset), VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kBoxShadowTypeKTable);
|
|
|
|
}
|
2009-02-10 00:45:13 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue xOrColor;
|
|
|
|
PRBool haveColor = PR_FALSE;
|
|
|
|
if (!ParseVariant(xOrColor, VARIANT_COLOR | VARIANT_LENGTH | VARIANT_CALC,
|
|
|
|
nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (xOrColor.IsLengthUnit() || xOrColor.IsCalcUnit()) {
|
|
|
|
val->Item(IndexX) = xOrColor;
|
|
|
|
} else {
|
|
|
|
// Must be a color (as string or color value)
|
|
|
|
NS_ASSERTION(xOrColor.GetUnit() == eCSSUnit_Ident ||
|
|
|
|
xOrColor.GetUnit() == eCSSUnit_Color ||
|
|
|
|
xOrColor.GetUnit() == eCSSUnit_EnumColor,
|
|
|
|
"Must be a color value");
|
|
|
|
val->Item(IndexColor) = xOrColor;
|
|
|
|
haveColor = PR_TRUE;
|
|
|
|
|
|
|
|
// X coordinate mandatory after color
|
|
|
|
if (!ParseVariant(val->Item(IndexX), VARIANT_LENGTH | VARIANT_CALC,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsnull)) {
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Y coordinate; mandatory
|
|
|
|
if (!ParseVariant(val->Item(IndexY), VARIANT_LENGTH | VARIANT_CALC,
|
|
|
|
nsnull)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-02-10 00:45:13 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Optional radius. Ignore errors except if they pass a negative
|
|
|
|
// value which we must reject. If we use ParseNonNegativeVariant
|
|
|
|
// we can't tell the difference between an unspecified radius
|
|
|
|
// and a negative radius.
|
|
|
|
if (ParseVariant(val->Item(IndexRadius), VARIANT_LENGTH | VARIANT_CALC,
|
|
|
|
nsnull) &&
|
|
|
|
val->Item(IndexRadius).IsLengthUnit() &&
|
|
|
|
val->Item(IndexRadius).GetFloatValue() < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (aIsBoxShadow) {
|
|
|
|
// Optional spread
|
|
|
|
ParseVariant(val->Item(IndexSpread), VARIANT_LENGTH | VARIANT_CALC, nsnull);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!haveColor) {
|
|
|
|
// Optional color
|
|
|
|
ParseVariant(val->Item(IndexColor), VARIANT_COLOR, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-07 17:56:52 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (aIsBoxShadow && val->Item(IndexInset).GetUnit() == eCSSUnit_Null) {
|
|
|
|
// Optional inset keyword
|
|
|
|
ParseVariant(val->Item(IndexInset), VARIANT_KEYWORD,
|
|
|
|
nsCSSProps::kBoxShadowTypeKTable);
|
|
|
|
}
|
2008-07-07 17:56:52 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
aValue.SetArrayValue(val, eCSSUnit_Array);
|
2008-07-07 17:56:52 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParseShadowList(nsCSSProperty aProperty)
|
2008-07-07 17:56:52 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsAutoParseCompoundProperty compound(this);
|
|
|
|
PRBool isBoxShadow = aProperty == eCSSProperty_box_shadow;
|
2008-07-07 17:56:52 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue value;
|
|
|
|
if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
// 'inherit', 'initial', and 'none' must be alone
|
|
|
|
if (!ExpectEndProperty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCSSValueList* cur = value.SetListValue();
|
|
|
|
for (;;) {
|
|
|
|
if (!ParseShadowItem(cur->mValue, isBoxShadow)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (CheckEndProperty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ExpectSymbol(',', PR_TRUE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppendValue(aProperty, value);
|
2008-07-07 17:56:52 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
PRInt32
|
|
|
|
CSSParserImpl::GetNamespaceIdForPrefix(const nsString& aPrefix)
|
2008-07-21 17:55:52 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aPrefix.IsEmpty(), "Must have a prefix here");
|
2008-09-09 21:38:14 -07:00
|
|
|
|
2008-07-21 17:55:52 -07:00
|
|
|
PRInt32 nameSpaceID = kNameSpaceID_Unknown;
|
|
|
|
if (mNameSpaceMap) {
|
|
|
|
// user-specified identifiers are case-sensitive (bug 416106)
|
|
|
|
nsCOMPtr<nsIAtom> prefix = do_GetAtom(aPrefix);
|
|
|
|
nameSpaceID = mNameSpaceMap->FindNameSpaceID(prefix);
|
|
|
|
}
|
|
|
|
// else no declared namespaces
|
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
if (nameSpaceID == kNameSpaceID_Unknown) { // unknown prefix, dump it
|
2008-07-21 17:55:52 -07:00
|
|
|
const PRUnichar *params[] = {
|
|
|
|
aPrefix.get()
|
|
|
|
};
|
|
|
|
REPORT_UNEXPECTED_P(PEUnknownNamespacePrefix, params);
|
2010-03-05 10:43:50 -08:00
|
|
|
mFoundUnresolvablePrefix = PR_TRUE;
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
|
|
|
|
2010-03-05 10:43:50 -08:00
|
|
|
return nameSpaceID;
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSParserImpl::SetDefaultNamespaceOnSelector(nsCSSSelector& aSelector)
|
|
|
|
{
|
2008-10-15 13:23:21 -07:00
|
|
|
if (mNameSpaceMap) {
|
|
|
|
aSelector.SetNameSpace(mNameSpaceMap->FindNameSpaceID(nsnull));
|
|
|
|
} else {
|
|
|
|
aSelector.SetNameSpace(kNameSpaceID_Unknown); // wildcard
|
2008-07-21 17:55:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_SVG
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSParserImpl::ParsePaint(nsCSSProperty aPropID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
nsCSSValue x, y;
|
|
|
|
if (!ParseVariant(x, VARIANT_HC | VARIANT_NONE | VARIANT_URL, nsnull))
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (x.GetUnit() == eCSSUnit_URL) {
|
|
|
|
if (!ParseVariant(y, VARIANT_COLOR | VARIANT_NONE, nsnull))
|
|
|
|
y.SetColorValue(NS_RGB(0, 0, 0));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-09 21:38:14 -07:00
|
|
|
if (!ExpectEndProperty())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (x.GetUnit() != eCSSUnit_URL) {
|
|
|
|
AppendValue(aPropID, x);
|
|
|
|
} else {
|
|
|
|
nsCSSValue val;
|
|
|
|
val.SetPairValue(x, y);
|
|
|
|
AppendValue(aPropID, val);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseDasharray()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSValue value;
|
2010-08-19 12:33:44 -07:00
|
|
|
if (ParseVariant(value, VARIANT_INHERIT | VARIANT_NONE, nsnull)) {
|
|
|
|
// 'inherit', 'initial', and 'none' are only allowed on their own
|
|
|
|
if (!ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
nsCSSValueList *cur = value.SetListValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (;;) {
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!ParseVariant(cur->mValue,
|
|
|
|
VARIANT_LENGTH | VARIANT_PERCENT | VARIANT_NUMBER,
|
|
|
|
nsnull)) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (CheckEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2010-08-19 12:33:44 -07:00
|
|
|
}
|
2010-03-11 22:50:10 -08:00
|
|
|
// skip optional commas between elements
|
|
|
|
(void)ExpectSymbol(',', PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
cur->mNext = new nsCSSValueList;
|
|
|
|
cur = cur->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
AppendValue(eCSSProperty_stroke_dasharray, value);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:38:14 -07:00
|
|
|
PRBool
|
|
|
|
CSSParserImpl::ParseMarker()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSValue marker;
|
2008-09-09 21:38:14 -07:00
|
|
|
if (ParseSingleValueProperty(marker, eCSSProperty_marker_end)) {
|
|
|
|
if (ExpectEndProperty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValue(eCSSProperty_marker_end, marker);
|
|
|
|
AppendValue(eCSSProperty_marker_mid, marker);
|
|
|
|
AppendValue(eCSSProperty_marker_start, marker);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// Recycling of parser implementation objects
|
|
|
|
|
|
|
|
static CSSParserImpl* gFreeList = nsnull;
|
|
|
|
|
2010-03-02 13:00:53 -08:00
|
|
|
nsCSSParser::nsCSSParser(mozilla::css::Loader* aLoader,
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSStyleSheet* aSheet)
|
2010-03-02 12:59:32 -08:00
|
|
|
{
|
|
|
|
CSSParserImpl *impl = gFreeList;
|
|
|
|
if (impl) {
|
|
|
|
gFreeList = impl->mNextFree;
|
|
|
|
impl->mNextFree = nsnull;
|
|
|
|
} else {
|
|
|
|
impl = new CSSParserImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLoader) {
|
|
|
|
impl->SetChildLoader(aLoader);
|
|
|
|
impl->SetQuirkMode(aLoader->GetCompatibilityMode() ==
|
|
|
|
eCompatibility_NavQuirks);
|
|
|
|
}
|
|
|
|
if (aSheet) {
|
|
|
|
impl->SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
mImpl = static_cast<void*>(impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSParser::~nsCSSParser()
|
|
|
|
{
|
|
|
|
CSSParserImpl *impl = static_cast<CSSParserImpl*>(mImpl);
|
|
|
|
impl->Reset();
|
|
|
|
impl->mNextFree = gFreeList;
|
|
|
|
gFreeList = impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsCSSParser::Shutdown()
|
|
|
|
{
|
|
|
|
CSSParserImpl *tofree = gFreeList;
|
|
|
|
CSSParserImpl *next;
|
|
|
|
while (tofree)
|
|
|
|
{
|
|
|
|
next = tofree->mNextFree;
|
|
|
|
delete tofree;
|
|
|
|
tofree = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper methods
|
|
|
|
|
|
|
|
nsresult
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSParser::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2010-03-02 12:59:32 -08:00
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::SetQuirkMode(PRBool aQuirkMode)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
SetQuirkMode(aQuirkMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::SetSVGMode(PRBool aSVGMode)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
SetSVGMode(aSVGMode);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
2010-03-02 13:00:53 -08:00
|
|
|
nsCSSParser::SetChildLoader(mozilla::css::Loader* aChildLoader)
|
2010-03-02 12:59:32 -08:00
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
SetChildLoader(aChildLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::Parse(nsIUnicharInputStream* aInput,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
PRBool aAllowUnsafeRules)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
Parse(aInput, aSheetURI, aBaseURI, aSheetPrincipal, aLineNumber,
|
|
|
|
aAllowUnsafeRules);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aDocURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aNodePrincipal,
|
|
|
|
nsICSSStyleRule** aResult)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseStyleAttribute(aAttributeValue, aDocURI, aBaseURI,
|
|
|
|
aNodePrincipal, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-07-23 11:00:19 -07:00
|
|
|
nsCSSParser::ParseDeclarations(const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
css::Declaration* aDeclaration,
|
|
|
|
PRBool* aChanged)
|
2010-03-02 12:59:32 -08:00
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
2010-07-23 11:00:19 -07:00
|
|
|
ParseDeclarations(aBuffer, aSheetURI, aBaseURI, aSheetPrincipal,
|
|
|
|
aDeclaration, aChanged);
|
2010-03-02 12:59:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCOMArray<nsICSSRule>& aResult)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseRule(aRule, aSheetURI, aBaseURI, aSheetPrincipal, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURI,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-28 15:49:35 -07:00
|
|
|
css::Declaration* aDeclaration,
|
2010-04-01 23:07:40 -07:00
|
|
|
PRBool* aChanged,
|
|
|
|
PRBool aIsImportant)
|
2010-03-02 12:59:32 -08:00
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseProperty(aPropID, aPropValue, aSheetURI, aBaseURI,
|
2010-04-01 23:07:40 -07:00
|
|
|
aSheetPrincipal, aDeclaration, aChanged, aIsImportant);
|
2010-03-02 12:59:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURI,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseMediaList(aBuffer, aURI, aLineNumber, aMediaList, aHTMLMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURI,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nscolor* aColor)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseColorString(aBuffer, aURI, aLineNumber, aColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSParser::ParseSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURI,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsCSSSelectorList** aSelectorList)
|
|
|
|
{
|
|
|
|
return static_cast<CSSParserImpl*>(mImpl)->
|
|
|
|
ParseSelectorString(aSelectorString, aURI, aLineNumber, aSelectorList);
|
|
|
|
}
|