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"
|
2015-10-14 00:43:16 +03:00
|
|
|
#include "mozilla/css/Loader.h"
|
2011-12-16 23:42:07 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2013-12-12 06:09:41 +04:00
|
|
|
#include "nsCSSScanner.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-04-09 00:16:45 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2002-08-24 18:41:28 +04:00
|
|
|
|
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;
|
2014-04-09 00:16:45 +04:00
|
|
|
class nsMediaQuery;
|
2011-04-12 10:18:43 +04:00
|
|
|
class nsCSSKeyframeRule;
|
2012-06-06 11:36:38 +04:00
|
|
|
class nsCSSValue;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct nsRuleData;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-20 14:32:49 +04:00
|
|
|
class CSSStyleSheet;
|
2013-12-12 06:09:41 +04:00
|
|
|
class CSSVariableValues;
|
2010-03-03 00:00:53 +03:00
|
|
|
namespace css {
|
2011-04-08 05:23:46 +04:00
|
|
|
class Rule;
|
2010-06-29 02:49:35 +04:00
|
|
|
class Declaration;
|
2011-03-11 05:48:57 +03:00
|
|
|
class StyleRule;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
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
|
|
|
|
2013-04-12 07:20:45 +04:00
|
|
|
class MOZ_STACK_CLASS nsCSSParser {
|
2010-03-02 23:59:32 +03:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
|
|
|
|
mozilla::CSSStyleSheet* aSheet = nullptr);
|
2010-04-07 01:52:17 +04:00
|
|
|
~nsCSSParser();
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2015-02-26 20:02:19 +03:00
|
|
|
static void Startup();
|
2010-03-02 23:59:32 +03:00
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
nsCSSParser(nsCSSParser const&) = delete;
|
|
|
|
nsCSSParser& operator=(nsCSSParser const&) = delete;
|
2001-09-06 17:14:35 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
2006-06-15 07:20:19 +04:00
|
|
|
/**
|
2015-11-11 01:17:24 +03:00
|
|
|
* Parse aInput into the stylesheet that was previously passed to the
|
|
|
|
* constructor. Calling this method on an nsCSSParser that had nullptr
|
|
|
|
* passed in as the style sheet is an error.
|
2008-02-15 07:21:57 +03:00
|
|
|
*
|
|
|
|
* @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
|
2015-11-11 01:17:24 +03:00
|
|
|
* the constructor.
|
2008-02-15 07:21:57 +03:00
|
|
|
* @param aBaseURI the URI to use for relative URI resolution
|
|
|
|
* @param aSheetPrincipal the principal of the stylesheet. This must match
|
2015-11-11 01:17:24 +03:00
|
|
|
* the principal of the sheet passed to the
|
|
|
|
* constructor.
|
2010-03-02 23:59:32 +03:00
|
|
|
* @param aLineNumber the line number of the first line of the sheet.
|
2015-10-14 00:43:16 +03:00
|
|
|
* @param aParsingMode see SheetParsingMode in css/Loader.h
|
2015-09-18 08:27:00 +03:00
|
|
|
* @param aReusableSheets style sheets that can be reused by an @import.
|
|
|
|
* This can be nullptr.
|
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,
|
2015-10-14 00:43:16 +03:00
|
|
|
mozilla::css::SheetParsingMode aParsingMode,
|
2015-09-18 08:27:00 +03:00
|
|
|
mozilla::css::LoaderReusableStyleSheets* aReusableSheets =
|
|
|
|
nullptr);
|
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.
|
2015-11-09 10:57:16 +03:00
|
|
|
already_AddRefed<mozilla::css::Declaration>
|
|
|
|
ParseStyleAttribute(const nsAString& aAttributeValue,
|
2010-04-07 01:52:17 +04:00
|
|
|
nsIURI* aDocURL,
|
|
|
|
nsIURI* aBaseURL,
|
2015-11-09 10:57:16 +03:00
|
|
|
nsIPrincipal* aNodePrincipal);
|
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,
|
2013-02-10 10:56:49 +04:00
|
|
|
mozilla::css::Rule** aResult);
|
2010-04-07 01:52:17 +04:00
|
|
|
|
2012-11-15 20:36:15 +04: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.
|
2015-03-29 14:57:04 +03:00
|
|
|
void ParseProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
mozilla::css::Declaration* aDeclaration,
|
|
|
|
bool* aChanged,
|
|
|
|
bool aIsImportant,
|
|
|
|
bool aIsSVGMode = false);
|
2005-03-30 04:36:57 +04:00
|
|
|
|
2015-10-22 11:22:37 +03:00
|
|
|
// Same as ParseProperty but returns an nsCSSValue in aResult
|
|
|
|
// rather than storing the property in a Declaration. aPropID
|
|
|
|
// must be a longhand property.
|
|
|
|
void ParseLonghandProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCSSValue& aResult);
|
|
|
|
|
2013-12-12 06:09:46 +04:00
|
|
|
// The same as ParseProperty but for a variable.
|
2015-03-29 14:57:04 +03:00
|
|
|
void ParseVariable(const nsAString& aVariableName,
|
|
|
|
const nsAString& aPropValue,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
mozilla::css::Declaration* aDeclaration,
|
|
|
|
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
|
|
|
*/
|
2013-11-11 11:57:34 +04:00
|
|
|
void ParseMediaList(const nsSubstring& aBuffer,
|
|
|
|
nsIURI* aURL,
|
|
|
|
uint32_t aLineNumber,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
bool aHTMLMode);
|
2005-04-18 06:51:40 +04:00
|
|
|
|
2014-04-09 00:16:45 +04: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-06 10:09:23 +04: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);
|
|
|
|
|
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,
|
2014-07-17 18:08:07 +04:00
|
|
|
nsCSSValue& aValue,
|
|
|
|
bool aSuppressErrors = false);
|
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
|
|
|
|
2012-11-25 04:26:07 +04: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-12 06:09:41 +04: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-12 06:09:44 +04: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-12 06:09:44 +04:00
|
|
|
nsIPrincipal* aDocPrincipal,
|
2014-06-20 14:32:49 +04:00
|
|
|
mozilla::CSSStyleSheet* aSheet,
|
2013-12-12 06:09:44 +04:00
|
|
|
uint32_t aLineNumber,
|
|
|
|
uint32_t aLineOffset);
|
2013-12-12 06:09:44 +04:00
|
|
|
|
2014-06-12 05:10:00 +04: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-09-24 09:49:02 +04:00
|
|
|
bool ParseFontFaceDescriptor(nsCSSFontDesc aDescID,
|
|
|
|
const nsAString& aBuffer,
|
|
|
|
nsIURI* aSheetURL,
|
|
|
|
nsIURI* aBaseURL,
|
|
|
|
nsIPrincipal* aSheetPrincipal,
|
|
|
|
nsCSSValue& aValue);
|
|
|
|
|
2014-07-17 18:08:07 +04:00
|
|
|
// Check whether a given value can be applied to a property.
|
|
|
|
bool IsValueValidForProperty(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aPropValue);
|
|
|
|
|
2015-10-01 14:26:52 +03:00
|
|
|
// Return the default value to be used for -moz-control-character-visibility,
|
|
|
|
// from preferences (cached by our Startup(), so that both nsStyleText and
|
|
|
|
// nsRuleNode can have fast access to it).
|
|
|
|
static uint8_t ControlCharVisibilityDefault();
|
|
|
|
|
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___ */
|