2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
|
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
#ifndef nsCSSParser_h___
|
|
|
|
#define nsCSSParser_h___
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
#include "nsAString.h"
|
2004-06-08 05:32:29 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2005-04-18 06:51:40 +04:00
|
|
|
#include "nsColor.h"
|
2005-10-16 00:21:20 +04:00
|
|
|
#include "nsCOMArray.h"
|
2002-08-24 18:41:28 +04:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsICSSRule;
|
2003-10-30 04:40:33 +03:00
|
|
|
class nsICSSStyleRule;
|
1998-11-26 04:34:53 +03:00
|
|
|
class nsICSSStyleSheet;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsIPrincipal;
|
1999-06-23 07:29:44 +04:00
|
|
|
class nsIURI;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsIUnicharInputStream;
|
2002-01-16 01:43:37 +03:00
|
|
|
class nsCSSDeclaration;
|
2008-07-22 04:55:52 +04:00
|
|
|
struct nsCSSSelectorList;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsMediaList;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class Loader;
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
// Interface to the css parser.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
class NS_STACK_CLASS nsCSSParser {
|
|
|
|
public:
|
2010-04-07 01:52:17 +04:00
|
|
|
nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
|
|
|
|
nsICSSStyleSheet* aSheet = nsnull);
|
|
|
|
~nsCSSParser();
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// not to be implemented
|
|
|
|
nsCSSParser(nsCSSParser const&);
|
|
|
|
nsCSSParser& operator=(nsCSSParser const&);
|
2001-09-06 17:14:35 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
2010-03-02 23:59:32 +03:00
|
|
|
// If this is false, memory allocation failed in the constructor
|
|
|
|
// and all other methods will crash.
|
2010-04-07 01:52:17 +04:00
|
|
|
operator bool() const
|
2010-03-02 23:59:32 +03:00
|
|
|
{ return !!mImpl; }
|
1999-06-30 23:47:42 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Set a style sheet for the parser to fill in. The style sheet must
|
2008-02-15 07:21:57 +03:00
|
|
|
// implement the nsICSSStyleSheet interface. Null can be passed in to clear
|
|
|
|
// out an existing stylesheet reference.
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult SetStyleSheet(nsICSSStyleSheet* aSheet);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-07 05:28:04 +04:00
|
|
|
// Set whether or not to emulate Nav quirks
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult SetQuirkMode(PRBool aQuirkMode);
|
1999-07-07 05:28:04 +04:00
|
|
|
|
2004-08-10 04:02:47 +04:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
// Set whether or not we are in an SVG element
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult SetSVGMode(PRBool aSVGMode);
|
2004-08-10 04:02:47 +04:00
|
|
|
#endif
|
|
|
|
|
1999-05-19 03:09:47 +04:00
|
|
|
// Set loader to use for child sheets
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
|
1999-05-19 03:09:47 +04:00
|
|
|
|
2006-06-15 07:20:19 +04:00
|
|
|
/**
|
2008-02-15 07:21:57 +03: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 23:59:32 +03:00
|
|
|
* @param aLineNumber the line number of the first line of the sheet.
|
2006-06-15 07:20:19 +04:00
|
|
|
* @param aAllowUnsafeRules see aEnableUnsafeRules in
|
2010-03-03 00:00:53 +03:00
|
|
|
* mozilla::css::Loader::LoadSheetSync
|
2006-06-15 07:20:19 +04:00
|
|
|
*/
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult Parse(nsIUnicharInputStream* aInput,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
PRBool aAllowUnsafeRules);
|
1998-05-28 22:39:08 +04:00
|
|
|
|
2001-09-18 03:59:30 +04: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-07 01:52:17 +04:00
|
|
|
nsresult ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aNodePrincipal,
|
|
|
|
nsICSSStyleRule** aResult);
|
|
|
|
|
|
|
|
nsresult ParseAndAppendDeclaration(const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool aParseOnlyOneDecl,
|
|
|
|
PRBool* aChanged,
|
|
|
|
PRBool aClearOldDecl);
|
|
|
|
|
|
|
|
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,
|
|
|
|
nsCSSDeclaration* aDeclaration,
|
|
|
|
PRBool* aChanged,
|
|
|
|
PRBool aIsImportant);
|
2005-03-30 04:36:57 +04: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 23:59:32 +03:00
|
|
|
* parentheses and strings more important than commas. |aURL| and
|
|
|
|
* |aLineNumber| are used for error reporting.
|
2005-03-30 04:36:57 +04:00
|
|
|
*/
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHTMLMode);
|
2005-04-18 06:51:40 +04:00
|
|
|
|
|
|
|
/**
|
2008-02-21 11:37:27 +03: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 06:51:40 +04: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-07 01:52:17 +04:00
|
|
|
nsresult ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nscolor* aColor);
|
2008-07-22 04:55:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse aBuffer into a selector list. On success, caller must
|
|
|
|
* delete *aSelectorList when done with it.
|
|
|
|
*/
|
2010-04-07 01:52:17 +04:00
|
|
|
nsresult ParseSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsCSSSelectorList** aSelectorList);
|
2010-03-02 23:59:32 +03: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-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
#endif /* nsCSSParser_h___ */
|