2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
#ifndef nsCSSParser_h___
|
|
|
|
#define nsCSSParser_h___
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-16 11:42:07 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCSSProperty.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsCOMArray.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2011-10-28 00:35:45 -07:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-11 13:41:47 -07:00
|
|
|
class nsCSSStyleSheet;
|
2010-03-02 13:00:53 -08:00
|
|
|
class nsIPrincipal;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIURI;
|
2008-07-21 17:55:52 -07:00
|
|
|
struct nsCSSSelectorList;
|
2010-03-02 13:00:53 -08:00
|
|
|
class nsMediaList;
|
2011-04-11 23:18:43 -07:00
|
|
|
class nsCSSKeyframeRule;
|
2012-06-06 00:36:38 -07:00
|
|
|
class nsCSSValue;
|
2010-03-02 13:00:53 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2011-04-07 18:23:46 -07:00
|
|
|
class Rule;
|
2010-06-28 15:49:35 -07:00
|
|
|
class Declaration;
|
|
|
|
class Loader;
|
2011-03-10 18:48:57 -08:00
|
|
|
class StyleRule;
|
2010-03-02 13:00:53 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
// Interface to the css parser.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
class NS_STACK_CLASS nsCSSParser {
|
|
|
|
public:
|
2010-04-06 14:52:17 -07:00
|
|
|
nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSStyleSheet* aSheet = nsnull);
|
2010-04-06 14:52:17 -07:00
|
|
|
~nsCSSParser();
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
2011-12-16 11:42:07 -08:00
|
|
|
nsCSSParser(nsCSSParser const&) MOZ_DELETE;
|
|
|
|
nsCSSParser& operator=(nsCSSParser const&) MOZ_DELETE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Set a style sheet for the parser to fill in. The style sheet must
|
2010-05-11 13:41:47 -07:00
|
|
|
// implement the nsCSSStyleSheet interface. Null can be passed in to clear
|
2008-02-14 20:21:57 -08:00
|
|
|
// out an existing stylesheet reference.
|
2010-05-11 13:41:47 -07:00
|
|
|
nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set whether or not to emulate Nav quirks
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetQuirkMode(bool aQuirkMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set whether or not we are in an SVG element
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetSVGMode(bool aSVGMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set loader to use for child sheets
|
2010-04-06 14:52:17 -07:00
|
|
|
nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2008-02-14 20:21:57 -08: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 12:59:32 -08:00
|
|
|
* @param aLineNumber the line number of the first line of the sheet.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aAllowUnsafeRules see aEnableUnsafeRules in
|
2010-03-02 13:00:53 -08:00
|
|
|
* mozilla::css::Loader::LoadSheetSync
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-05-18 18:22:59 -07:00
|
|
|
nsresult ParseSheet(const nsAString& aInput,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURI,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
PRUint32 aLineNumber,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAllowUnsafeRules);
|
2007-03-22 10:30:00 -07: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 14:52:17 -07:00
|
|
|
nsresult ParseStyleAttribute(const nsAString& aAttributeValue,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aNodePrincipal,
|
2011-03-10 18:48:57 -08:00
|
|
|
mozilla::css::StyleRule** aResult);
|
2010-04-06 14:52:17 -07:00
|
|
|
|
2010-07-23 11:00:19 -07: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-28 23:19:26 -07:00
|
|
|
bool* aChanged);
|
2010-04-06 14:52:17 -07:00
|
|
|
|
|
|
|
nsresult ParseRule(const nsAString& aRule,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2011-04-07 18:23:46 -07:00
|
|
|
nsCOMArray<mozilla::css::Rule>& aResult);
|
2010-04-06 14:52:17 -07:00
|
|
|
|
|
|
|
nsresult ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
2010-06-28 15:49:35 -07:00
|
|
|
mozilla::css::Declaration* aDeclaration,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aChanged,
|
|
|
|
bool aIsImportant);
|
2007-03-22 10:30:00 -07: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 12:59:32 -08:00
|
|
|
* parentheses and strings more important than commas. |aURL| and
|
|
|
|
* |aLineNumber| are used for error reporting.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-04-06 14:52:17 -07:00
|
|
|
nsresult ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aHTMLMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2012-06-06 00:36:38 -07: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-06-06 00:36:38 -07:00
|
|
|
bool ParseColorString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsCSSValue& aValue);
|
2008-07-21 17:55:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse aBuffer into a selector list. On success, caller must
|
|
|
|
* delete *aSelectorList when done with it.
|
|
|
|
*/
|
2010-04-06 14:52:17 -07:00
|
|
|
nsresult ParseSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
nsCSSSelectorList** aSelectorList);
|
2010-03-02 12:59:32 -08:00
|
|
|
|
2011-04-11 23:18:43 -07: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 15:38:48 -07:00
|
|
|
InfallibleTArray<float>& aSelectorList);
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2010-03-02 12:59:32 -08: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
#endif /* nsCSSParser_h___ */
|