2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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
|
|
|
|
2011-12-16 23:42:07 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
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"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2011-10-28 11:35:45 +04:00
|
|
|
#include "nsTArray.h"
|
2002-08-24 18:41:28 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
class nsCSSStyleSheet;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsIPrincipal;
|
1999-06-23 07:29:44 +04:00
|
|
|
class nsIURI;
|
2008-07-22 04:55:52 +04:00
|
|
|
struct nsCSSSelectorList;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsMediaList;
|
2011-04-12 10:18:43 +04:00
|
|
|
class nsCSSKeyframeRule;
|
2012-06-06 11:36:38 +04:00
|
|
|
class nsCSSValue;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2011-04-08 05:23:46 +04:00
|
|
|
class Rule;
|
2010-06-29 02:49:35 +04:00
|
|
|
class Declaration;
|
|
|
|
class Loader;
|
2011-03-11 05:48:57 +03:00
|
|
|
class StyleRule;
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
|
|
|
}
|
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:
|
2012-07-30 18:20:58 +04:00
|
|
|
nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
|
|
|
|
nsCSSStyleSheet* aSheet = nullptr);
|
2010-04-07 01:52:17 +04:00
|
|
|
~nsCSSParser();
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
2011-12-16 23:42:07 +04:00
|
|
|
nsCSSParser(nsCSSParser const&) MOZ_DELETE;
|
|
|
|
nsCSSParser& operator=(nsCSSParser const&) MOZ_DELETE;
|
2001-09-06 17:14:35 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
|
|
|
// Set a style sheet for the parser to fill in. The style sheet must
|
2010-05-12 00:41:47 +04:00
|
|
|
// implement the nsCSSStyleSheet interface. Null can be passed in to clear
|
2008-02-15 07:21:57 +03:00
|
|
|
// out an existing stylesheet reference.
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult SetStyleSheet(nsCSSStyleSheet* 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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult SetQuirkMode(bool aQuirkMode);
|
1999-07-07 05:28:04 +04:00
|
|
|
|
2004-08-10 04:02:47 +04:00
|
|
|
// Set whether or not we are in an SVG element
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult SetSVGMode(bool aSVGMode);
|
2004-08-10 04:02:47 +04:00
|
|
|
|
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
|
|
|
*/
|
2011-05-19 05:22:59 +04:00
|
|
|
nsresult ParseSheet(const nsAString& aInput,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool 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,
|
2011-03-11 05:48:57 +03:00
|
|
|
mozilla::css::StyleRule** aResult);
|
2010-04-07 01:52:17 +04:00
|
|
|
|
2010-07-23 22:00:19 +04: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 10:19:26 +04:00
|
|
|
bool* aChanged);
|
2010-04-07 01:52:17 +04:00
|
|
|
|
|
|
|
nsresult ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2011-04-08 05:23:46 +04:00
|
|
|
nsCOMArray<mozilla::css::Rule>& aResult);
|
2010-04-07 01:52:17 +04:00
|
|
|
|
|
|
|
nsresult ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-29 02:49:35 +04:00
|
|
|
mozilla::css::Declaration* aDeclaration,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aChanged,
|
|
|
|
bool 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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2010-04-07 01:52:17 +04:00
|
|
|
nsMediaList* aMediaList,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHTMLMode);
|
2005-04-18 06:51:40 +04:00
|
|
|
|
|
|
|
/**
|
2012-06-06 11:36:38 +04:00
|
|
|
* Parse aBuffer into a nsCSSValue |aValue|. Will return false
|
|
|
|
* if aBuffer is not a valid CSS color specification.
|
|
|
|
* One can use nsRuleNode::ComputeColor to compute an nscolor from
|
|
|
|
* the returned nsCSSValue.
|
2005-04-18 06:51:40 +04:00
|
|
|
*/
|
2012-06-06 11:36:38 +04:00
|
|
|
bool ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2012-06-06 11:36:38 +04:00
|
|
|
nsCSSValue& aValue);
|
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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2010-04-07 01:52:17 +04:00
|
|
|
nsCSSSelectorList** aSelectorList);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2011-04-12 10:18:43 +04: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,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber);
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a selector list for a keyframe rule. Return whether
|
|
|
|
* the parse succeeded.
|
|
|
|
*/
|
|
|
|
bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2011-05-29 02:38:48 +04:00
|
|
|
InfallibleTArray<float>& aSelectorList);
|
2011-04-12 10:18:43 +04:00
|
|
|
|
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___ */
|