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 "nsCSSProperty.h"
|
2013-12-11 18:09:41 -08:00
|
|
|
#include "nsCSSScanner.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-08 13:16:45 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-02 16:31:48 -08:00
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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;
|
2014-04-08 13:16:45 -07:00
|
|
|
class nsMediaQuery;
|
2011-04-11 23:18:43 -07:00
|
|
|
class nsCSSKeyframeRule;
|
2012-06-06 00:36:38 -07:00
|
|
|
class nsCSSValue;
|
2014-06-18 17:57:51 -07:00
|
|
|
struct nsRuleData;
|
2010-03-02 13:00:53 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-20 03:32:49 -07:00
|
|
|
class CSSStyleSheet;
|
2013-12-11 18:09:41 -08:00
|
|
|
class CSSVariableValues;
|
2010-03-02 13:00:53 -08:00
|
|
|
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
|
|
|
|
2013-04-11 20:20:45 -07:00
|
|
|
class MOZ_STACK_CLASS nsCSSParser {
|
2010-03-02 12:59:32 -08:00
|
|
|
public:
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
|
2014-06-20 03:32:49 -07:00
|
|
|
mozilla::CSSStyleSheet* aSheet = nullptr);
|
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
|
2014-06-20 03:32:49 -07:00
|
|
|
// implement the CSSStyleSheet interface. Null can be passed in to clear
|
2008-02-14 20:21:57 -08:00
|
|
|
// out an existing stylesheet reference.
|
2014-06-20 03:32:49 -07:00
|
|
|
nsresult SetStyleSheet(mozilla::CSSStyleSheet* 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 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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t 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,
|
2013-02-09 22:56:49 -08:00
|
|
|
mozilla::css::Rule** aResult);
|
2010-04-06 14:52:17 -07:00
|
|
|
|
2012-11-15 08:36:15 -08:00
|
|
|
// Parse the value of a single CSS property, and add or replace that
|
|
|
|
// property in aDeclaration.
|
|
|
|
//
|
|
|
|
// SVG "mapped attributes" (which correspond directly to CSS
|
|
|
|
// properties) are parsed slightly differently from regular CSS; in
|
|
|
|
// particular, units may be omitted from <length>. The 'aIsSVGMode'
|
|
|
|
// argument controls this quirk. Note that this *only* applies to
|
|
|
|
// mapped attributes, not inline styles or full style sheets in SVG.
|
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,
|
2012-11-15 08:36:15 -08:00
|
|
|
bool* aChanged,
|
|
|
|
bool aIsImportant,
|
|
|
|
bool aIsSVGMode = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-11 18:09:46 -08:00
|
|
|
// The same as ParseProperty but for a variable.
|
|
|
|
nsresult ParseVariable(const nsAString& aVariableName,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
mozilla::css::Declaration* aDeclaration,
|
|
|
|
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
|
|
|
*/
|
2013-11-10 23:57:34 -08:00
|
|
|
void ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
uint32_t aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
bool aHTMLMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-08 13:16:45 -07:00
|
|
|
/*
|
|
|
|
* Parse aBuffer into a list of media queries and their associated values,
|
|
|
|
* according to grammar:
|
|
|
|
* <source-size-list> = <source-size>#?
|
|
|
|
* <source-size> = <media-condition>? <length>
|
|
|
|
*
|
|
|
|
* Note that this grammar is top-level: The function expects to consume the
|
|
|
|
* entire input buffer.
|
|
|
|
*
|
|
|
|
* Output arrays overwritten (not appended) and are cleared in case of parse
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
bool ParseSourceSizeList(const nsAString& aBuffer,
|
|
|
|
nsIURI* aURI, // for error reporting
|
|
|
|
uint32_t aLineNumber, // for error reporting
|
|
|
|
InfallibleTArray< nsAutoPtr<nsMediaQuery> >& aQueries,
|
|
|
|
InfallibleTArray<nsCSSValue>& aValues,
|
|
|
|
bool aHTMLMode);
|
|
|
|
|
2014-06-05 23:09:23 -07:00
|
|
|
/**
|
|
|
|
* Parse aBuffer into a nsCSSValue |aValue|. Will return false
|
|
|
|
* if aBuffer is not a valid font family list.
|
|
|
|
*/
|
|
|
|
bool ParseFontFamilyListString(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
uint32_t aLineNumber,
|
|
|
|
nsCSSValue& aValue);
|
|
|
|
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber,
|
2014-07-17 07:08:07 -07:00
|
|
|
nsCSSValue& aValue,
|
|
|
|
bool aSuppressErrors = false);
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber,
|
2010-04-06 14:52:17 -07:00
|
|
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber);
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a selector list for a keyframe rule. Return whether
|
|
|
|
* the parse succeeded.
|
|
|
|
*/
|
|
|
|
bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
|
|
|
|
nsIURI* aURL,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber,
|
2011-05-28 15:38:48 -07:00
|
|
|
InfallibleTArray<float>& aSelectorList);
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2012-11-24 16:26:07 -08:00
|
|
|
/**
|
|
|
|
* Parse a property and value and return whether the property/value pair
|
|
|
|
* is supported.
|
|
|
|
*/
|
|
|
|
bool EvaluateSupportsDeclaration(const nsAString& aProperty,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aDocPrincipal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse an @supports condition and returns the result of evaluating the
|
|
|
|
* condition.
|
|
|
|
*/
|
|
|
|
bool EvaluateSupportsCondition(const nsAString& aCondition,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aDocPrincipal);
|
|
|
|
|
2013-12-11 18:09:41 -08:00
|
|
|
typedef void (*VariableEnumFunc)(const nsAString&, void*);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses aPropertyValue as a property value and calls aFunc for each
|
|
|
|
* variable reference that is found. Returns false if there was
|
|
|
|
* a syntax error in the use of variable references.
|
|
|
|
*/
|
|
|
|
bool EnumerateVariableReferences(const nsAString& aPropertyValue,
|
|
|
|
VariableEnumFunc aFunc,
|
|
|
|
void* aData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses aPropertyValue as a property value and resolves variable references
|
|
|
|
* using the values in aVariables.
|
|
|
|
*/
|
|
|
|
bool ResolveVariableValue(const nsAString& aPropertyValue,
|
|
|
|
const mozilla::CSSVariableValues* aVariables,
|
|
|
|
nsString& aResult,
|
|
|
|
nsCSSTokenSerializationType& aFirstToken,
|
|
|
|
nsCSSTokenSerializationType& aLastToken);
|
|
|
|
|
2013-12-11 18:09:44 -08:00
|
|
|
/**
|
|
|
|
* Parses a string as a CSS token stream value for particular property,
|
|
|
|
* resolving any variable references. The parsed property value is stored
|
|
|
|
* in the specified nsRuleData object. If aShorthandPropertyID has a value
|
|
|
|
* other than eCSSProperty_UNKNOWN, this is the property that will be parsed;
|
|
|
|
* otherwise, aPropertyID will be parsed. Either way, only aPropertyID,
|
|
|
|
* a longhand property, will be copied over to the rule data.
|
|
|
|
*
|
|
|
|
* If the property cannot be parsed, it will be treated as if 'initial' or
|
|
|
|
* 'inherit' were specified, for non-inherited and inherited properties
|
|
|
|
* respectively.
|
|
|
|
*/
|
|
|
|
void ParsePropertyWithVariableReferences(
|
|
|
|
nsCSSProperty aPropertyID,
|
|
|
|
nsCSSProperty aShorthandPropertyID,
|
|
|
|
const nsAString& aValue,
|
|
|
|
const mozilla::CSSVariableValues* aVariables,
|
|
|
|
nsRuleData* aRuleData,
|
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
2013-12-11 18:09:44 -08:00
|
|
|
nsIPrincipal* aDocPrincipal,
|
2014-06-20 03:32:49 -07:00
|
|
|
mozilla::CSSStyleSheet* aSheet,
|
2013-12-11 18:09:44 -08:00
|
|
|
uint32_t aLineNumber,
|
|
|
|
uint32_t aLineOffset);
|
2013-12-11 18:09:44 -08:00
|
|
|
|
2014-06-11 18:10:00 -07:00
|
|
|
bool ParseCounterStyleName(const nsAString& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
nsAString& aName);
|
|
|
|
|
|
|
|
bool ParseCounterDescriptor(nsCSSCounterDesc aDescID,
|
|
|
|
const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCSSValue& aValue);
|
|
|
|
|
2014-07-17 07:08:07 -07:00
|
|
|
// Check whether a given value can be applied to a property.
|
|
|
|
bool IsValueValidForProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue);
|
|
|
|
|
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___ */
|