2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 05:47:31 +00:00
|
|
|
|
|
|
|
/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
|
|
|
|
|
2010-03-02 20:59:32 +00:00
|
|
|
#ifndef nsCSSParser_h___
|
|
|
|
#define nsCSSParser_h___
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2002-03-23 22:56:05 +00:00
|
|
|
#include "nsAString.h"
|
2004-06-08 01:32:29 +00:00
|
|
|
#include "nsCSSProperty.h"
|
2005-04-18 02:51:40 +00:00
|
|
|
#include "nsColor.h"
|
2005-10-15 20:21:20 +00:00
|
|
|
#include "nsCOMArray.h"
|
2011-04-12 06:18:43 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2011-10-28 07:35:45 +00:00
|
|
|
#include "nsTArray.h"
|
2002-08-24 14:41:28 +00:00
|
|
|
|
2010-05-11 20:41:47 +00:00
|
|
|
class nsCSSStyleSheet;
|
2010-03-02 21:00:53 +00:00
|
|
|
class nsIPrincipal;
|
1999-06-23 03:29:44 +00:00
|
|
|
class nsIURI;
|
2008-07-22 00:55:52 +00:00
|
|
|
struct nsCSSSelectorList;
|
2010-03-02 21:00:53 +00:00
|
|
|
class nsMediaList;
|
2011-04-12 06:18:43 +00:00
|
|
|
class nsCSSKeyframeRule;
|
2010-03-02 21:00:53 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2011-04-08 01:23:46 +00:00
|
|
|
class Rule;
|
2010-06-28 22:49:35 +00:00
|
|
|
class Declaration;
|
|
|
|
class Loader;
|
2011-03-11 02:48:57 +00:00
|
|
|
class StyleRule;
|
2010-03-02 21:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2010-03-02 20:59:32 +00:00
|
|
|
// Interface to the css parser.
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2010-03-02 20:59:32 +00:00
|
|
|
class NS_STACK_CLASS nsCSSParser {
|
|
|
|
public:
|
2010-04-06 21:52:17 +00:00
|
|
|
nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
|
2010-05-11 20:41:47 +00:00
|
|
|
nsCSSStyleSheet* aSheet = nsnull);
|
2010-04-06 21:52:17 +00:00
|
|
|
~nsCSSParser();
|
2010-03-02 20:59:32 +00:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// not to be implemented
|
|
|
|
nsCSSParser(nsCSSParser const&);
|
|
|
|
nsCSSParser& operator=(nsCSSParser const&);
|
2001-09-06 13:14:35 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
public:
|
|
|
|
// Set a style sheet for the parser to fill in. The style sheet must
|
2010-05-11 20:41:47 +00:00
|
|
|
// implement the nsCSSStyleSheet interface. Null can be passed in to clear
|
2008-02-15 04:21:57 +00:00
|
|
|
// out an existing stylesheet reference.
|
2010-05-11 20:41:47 +00:00
|
|
|
nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-07 01:28:04 +00:00
|
|
|
// Set whether or not to emulate Nav quirks
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult SetQuirkMode(bool aQuirkMode);
|
1999-07-07 01:28:04 +00:00
|
|
|
|
2004-08-10 00:02:47 +00:00
|
|
|
// Set whether or not we are in an SVG element
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult SetSVGMode(bool aSVGMode);
|
2004-08-10 00:02:47 +00:00
|
|
|
|
1999-05-18 23:09:47 +00:00
|
|
|
// Set loader to use for child sheets
|
2010-04-06 21:52:17 +00:00
|
|
|
nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
|
1999-05-18 23:09:47 +00:00
|
|
|
|
2006-06-15 03:20:19 +00:00
|
|
|
/**
|
2008-02-15 04:21:57 +00:00
|
|
|
* Parse aInput into the stylesheet that was previously set by calling
|
|
|
|
* SetStyleSheet. Calling this method without calling SetStyleSheet first is
|
|
|
|
* an error.
|
|
|
|
*
|
|
|
|
* @param aInput the data to parse
|
|
|
|
* @param aSheetURL the URI to use as the sheet URI (for error reporting).
|
|
|
|
* This must match the URI of the sheet passed to
|
|
|
|
* SetStyleSheet.
|
|
|
|
* @param aBaseURI the URI to use for relative URI resolution
|
|
|
|
* @param aSheetPrincipal the principal of the stylesheet. This must match
|
|
|
|
* the principal of the sheet passed to SetStyleSheet.
|
2010-03-02 20:59:32 +00:00
|
|
|
* @param aLineNumber the line number of the first line of the sheet.
|
2006-06-15 03:20:19 +00:00
|
|
|
* @param aAllowUnsafeRules see aEnableUnsafeRules in
|
2010-03-02 21:00:53 +00:00
|
|
|
* mozilla::css::Loader::LoadSheetSync
|
2006-06-15 03:20:19 +00:00
|
|
|
*/
|
2011-05-19 01:22:59 +00:00
|
|
|
nsresult ParseSheet(const nsAString& aInput,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
PRUint32 aLineNumber,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aAllowUnsafeRules);
|
1998-05-28 18:39:08 +00:00
|
|
|
|
2001-09-17 23:59:30 +00:00
|
|
|
// Parse HTML style attribute or its equivalent in other markup
|
|
|
|
// languages. aBaseURL is the base url to use for relative links in
|
|
|
|
// the declaration.
|
2010-04-06 21:52:17 +00:00
|
|
|
nsresult ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aNodePrincipal,
|
2011-03-11 02:48:57 +00:00
|
|
|
mozilla::css::StyleRule** aResult);
|
2010-04-06 21:52:17 +00:00
|
|
|
|
2010-07-23 18:00:19 +00:00
|
|
|
// Parse the body of a declaration block. Very similar to
|
|
|
|
// ParseStyleAttribute, but used under different circumstances.
|
|
|
|
// The contents of aDeclaration will be erased and replaced with the
|
|
|
|
// results of parsing; aChanged will be set true if the aDeclaration
|
|
|
|
// argument was modified.
|
|
|
|
nsresult ParseDeclarations(const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
mozilla::css::Declaration* aDeclaration,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aChanged);
|
2010-04-06 21:52:17 +00:00
|
|
|
|
|
|
|
nsresult ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2011-04-08 01:23:46 +00:00
|
|
|
nsCOMArray<mozilla::css::Rule>& aResult);
|
2010-04-06 21:52:17 +00:00
|
|
|
|
|
|
|
nsresult ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-28 22:49:35 +00:00
|
|
|
mozilla::css::Declaration* aDeclaration,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aChanged,
|
|
|
|
bool aIsImportant);
|
2005-03-30 00:36:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse aBuffer into a media list |aMediaList|, which must be
|
|
|
|
* non-null, replacing its current contents. If aHTMLMode is true,
|
|
|
|
* parse according to HTML rules, with commas as the most important
|
|
|
|
* delimiter. Otherwise, parse according to CSS rules, with
|
2010-03-02 20:59:32 +00:00
|
|
|
* parentheses and strings more important than commas. |aURL| and
|
|
|
|
* |aLineNumber| are used for error reporting.
|
2005-03-30 00:36:57 +00:00
|
|
|
*/
|
2010-04-06 21:52:17 +00:00
|
|
|
nsresult ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aHTMLMode);
|
2005-04-18 02:51:40 +00:00
|
|
|
|
|
|
|
/**
|
2008-02-21 08:37:27 +00:00
|
|
|
* Parse aBuffer into a nscolor |aColor|. The alpha component of the
|
|
|
|
* resulting aColor may vary due to rgba()/hsla(). Will return
|
|
|
|
* NS_ERROR_FAILURE if aBuffer is not a valid CSS color specification.
|
2005-04-18 02:51:40 +00:00
|
|
|
*
|
|
|
|
* Will also currently return NS_ERROR_FAILURE if it is not
|
|
|
|
* self-contained (i.e. doesn't reference any external style state,
|
|
|
|
* such as "initial" or "inherit").
|
|
|
|
*/
|
2010-04-06 21:52:17 +00:00
|
|
|
nsresult ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nscolor* aColor);
|
2008-07-22 00:55:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse aBuffer into a selector list. On success, caller must
|
|
|
|
* delete *aSelectorList when done with it.
|
|
|
|
*/
|
2010-04-06 21:52:17 +00:00
|
|
|
nsresult ParseSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsCSSSelectorList** aSelectorList);
|
2010-03-02 20:59:32 +00:00
|
|
|
|
2011-04-12 06:18:43 +00:00
|
|
|
/*
|
|
|
|
* Parse a keyframe rule (which goes inside an @keyframes rule).
|
|
|
|
* Return it if the parse was successful.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsCSSKeyframeRule>
|
|
|
|
ParseKeyframeRule(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a selector list for a keyframe rule. Return whether
|
|
|
|
* the parse succeeded.
|
|
|
|
*/
|
|
|
|
bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
2011-05-28 22:38:48 +00:00
|
|
|
InfallibleTArray<float>& aSelectorList);
|
2011-04-12 06:18:43 +00:00
|
|
|
|
2010-03-02 20:59:32 +00:00
|
|
|
protected:
|
|
|
|
// This is a CSSParserImpl*, but if we expose that type name in this
|
|
|
|
// header, we can't put the type definition (in nsCSSParser.cpp) in
|
|
|
|
// the anonymous namespace.
|
|
|
|
void* mImpl;
|
1998-04-13 20:24:54 +00:00
|
|
|
};
|
|
|
|
|
2010-03-02 20:59:32 +00:00
|
|
|
#endif /* nsCSSParser_h___ */
|