layout/style/nsCSSParser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsCSSParser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,265 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
    1.10 +
    1.11 +#ifndef nsCSSParser_h___
    1.12 +#define nsCSSParser_h___
    1.13 +
    1.14 +#include "mozilla/Attributes.h"
    1.15 +
    1.16 +#include "nsCSSProperty.h"
    1.17 +#include "nsCSSScanner.h"
    1.18 +#include "nsCOMPtr.h"
    1.19 +#include "nsStringFwd.h"
    1.20 +#include "nsTArrayForwardDeclare.h"
    1.21 +
    1.22 +class nsCSSStyleSheet;
    1.23 +class nsIPrincipal;
    1.24 +class nsIURI;
    1.25 +struct nsCSSSelectorList;
    1.26 +class nsMediaList;
    1.27 +class nsCSSKeyframeRule;
    1.28 +class nsCSSValue;
    1.29 +class nsRuleData;
    1.30 +
    1.31 +namespace mozilla {
    1.32 +class CSSVariableValues;
    1.33 +namespace css {
    1.34 +class Rule;
    1.35 +class Declaration;
    1.36 +class Loader;
    1.37 +class StyleRule;
    1.38 +}
    1.39 +}
    1.40 +
    1.41 +// Interface to the css parser.
    1.42 +
    1.43 +class MOZ_STACK_CLASS nsCSSParser {
    1.44 +public:
    1.45 +  nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
    1.46 +              nsCSSStyleSheet* aSheet = nullptr);
    1.47 +  ~nsCSSParser();
    1.48 +
    1.49 +  static void Shutdown();
    1.50 +
    1.51 +private:
    1.52 +  nsCSSParser(nsCSSParser const&) MOZ_DELETE;
    1.53 +  nsCSSParser& operator=(nsCSSParser const&) MOZ_DELETE;
    1.54 +
    1.55 +public:
    1.56 +  // Set a style sheet for the parser to fill in. The style sheet must
    1.57 +  // implement the nsCSSStyleSheet interface.  Null can be passed in to clear
    1.58 +  // out an existing stylesheet reference.
    1.59 +  nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
    1.60 +
    1.61 +  // Set whether or not to emulate Nav quirks
    1.62 +  nsresult SetQuirkMode(bool aQuirkMode);
    1.63 +
    1.64 +  // Set loader to use for child sheets
    1.65 +  nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
    1.66 +
    1.67 +  /**
    1.68 +   * Parse aInput into the stylesheet that was previously set by calling
    1.69 +   * SetStyleSheet.  Calling this method without calling SetStyleSheet first is
    1.70 +   * an error.
    1.71 +   *
    1.72 +   * @param aInput the data to parse
    1.73 +   * @param aSheetURL the URI to use as the sheet URI (for error reporting).
    1.74 +   *                  This must match the URI of the sheet passed to
    1.75 +   *                  SetStyleSheet.
    1.76 +   * @param aBaseURI the URI to use for relative URI resolution
    1.77 +   * @param aSheetPrincipal the principal of the stylesheet.  This must match
    1.78 +   *                        the principal of the sheet passed to SetStyleSheet.
    1.79 +   * @param aLineNumber the line number of the first line of the sheet.
    1.80 +   * @param aAllowUnsafeRules see aEnableUnsafeRules in
    1.81 +   *                          mozilla::css::Loader::LoadSheetSync
    1.82 +   */
    1.83 +  nsresult ParseSheet(const nsAString& aInput,
    1.84 +                      nsIURI*          aSheetURL,
    1.85 +                      nsIURI*          aBaseURI,
    1.86 +                      nsIPrincipal*    aSheetPrincipal,
    1.87 +                      uint32_t         aLineNumber,
    1.88 +                      bool             aAllowUnsafeRules);
    1.89 +
    1.90 +  // Parse HTML style attribute or its equivalent in other markup
    1.91 +  // languages.  aBaseURL is the base url to use for relative links in
    1.92 +  // the declaration.
    1.93 +  nsresult ParseStyleAttribute(const nsAString&  aAttributeValue,
    1.94 +                               nsIURI*           aDocURL,
    1.95 +                               nsIURI*           aBaseURL,
    1.96 +                               nsIPrincipal*     aNodePrincipal,
    1.97 +                               mozilla::css::StyleRule** aResult);
    1.98 +
    1.99 +  // Parse the body of a declaration block.  Very similar to
   1.100 +  // ParseStyleAttribute, but used under different circumstances.
   1.101 +  // The contents of aDeclaration will be erased and replaced with the
   1.102 +  // results of parsing; aChanged will be set true if the aDeclaration
   1.103 +  // argument was modified.
   1.104 +  nsresult ParseDeclarations(const nsAString&  aBuffer,
   1.105 +                             nsIURI*           aSheetURL,
   1.106 +                             nsIURI*           aBaseURL,
   1.107 +                             nsIPrincipal*     aSheetPrincipal,
   1.108 +                             mozilla::css::Declaration* aDeclaration,
   1.109 +                             bool*           aChanged);
   1.110 +
   1.111 +  nsresult ParseRule(const nsAString&        aRule,
   1.112 +                     nsIURI*                 aSheetURL,
   1.113 +                     nsIURI*                 aBaseURL,
   1.114 +                     nsIPrincipal*           aSheetPrincipal,
   1.115 +                     mozilla::css::Rule**    aResult);
   1.116 +
   1.117 +  // Parse the value of a single CSS property, and add or replace that
   1.118 +  // property in aDeclaration.
   1.119 +  //
   1.120 +  // SVG "mapped attributes" (which correspond directly to CSS
   1.121 +  // properties) are parsed slightly differently from regular CSS; in
   1.122 +  // particular, units may be omitted from <length>.  The 'aIsSVGMode'
   1.123 +  // argument controls this quirk.  Note that this *only* applies to
   1.124 +  // mapped attributes, not inline styles or full style sheets in SVG.
   1.125 +  nsresult ParseProperty(const nsCSSProperty aPropID,
   1.126 +                         const nsAString&    aPropValue,
   1.127 +                         nsIURI*             aSheetURL,
   1.128 +                         nsIURI*             aBaseURL,
   1.129 +                         nsIPrincipal*       aSheetPrincipal,
   1.130 +                         mozilla::css::Declaration* aDeclaration,
   1.131 +                         bool*               aChanged,
   1.132 +                         bool                aIsImportant,
   1.133 +                         bool                aIsSVGMode = false);
   1.134 +
   1.135 +  // The same as ParseProperty but for a variable.
   1.136 +  nsresult ParseVariable(const nsAString&    aVariableName,
   1.137 +                         const nsAString&    aPropValue,
   1.138 +                         nsIURI*             aSheetURL,
   1.139 +                         nsIURI*             aBaseURL,
   1.140 +                         nsIPrincipal*       aSheetPrincipal,
   1.141 +                         mozilla::css::Declaration* aDeclaration,
   1.142 +                         bool*               aChanged,
   1.143 +                         bool                aIsImportant);
   1.144 +  /**
   1.145 +   * Parse aBuffer into a media list |aMediaList|, which must be
   1.146 +   * non-null, replacing its current contents.  If aHTMLMode is true,
   1.147 +   * parse according to HTML rules, with commas as the most important
   1.148 +   * delimiter.  Otherwise, parse according to CSS rules, with
   1.149 +   * parentheses and strings more important than commas.  |aURL| and
   1.150 +   * |aLineNumber| are used for error reporting.
   1.151 +   */
   1.152 +  void ParseMediaList(const nsSubstring& aBuffer,
   1.153 +                      nsIURI*            aURL,
   1.154 +                      uint32_t           aLineNumber,
   1.155 +                      nsMediaList*       aMediaList,
   1.156 +                      bool               aHTMLMode);
   1.157 +
   1.158 +  /**
   1.159 +   * Parse aBuffer into a nsCSSValue |aValue|. Will return false
   1.160 +   * if aBuffer is not a valid CSS color specification.
   1.161 +   * One can use nsRuleNode::ComputeColor to compute an nscolor from
   1.162 +   * the returned nsCSSValue.
   1.163 +   */
   1.164 +  bool ParseColorString(const nsSubstring& aBuffer,
   1.165 +                        nsIURI*            aURL,
   1.166 +                        uint32_t           aLineNumber,
   1.167 +                        nsCSSValue&        aValue);
   1.168 +
   1.169 +  /**
   1.170 +   * Parse aBuffer into a selector list.  On success, caller must
   1.171 +   * delete *aSelectorList when done with it.
   1.172 +   */
   1.173 +  nsresult ParseSelectorString(const nsSubstring&  aSelectorString,
   1.174 +                               nsIURI*             aURL,
   1.175 +                               uint32_t            aLineNumber,
   1.176 +                               nsCSSSelectorList** aSelectorList);
   1.177 +
   1.178 +  /*
   1.179 +   * Parse a keyframe rule (which goes inside an @keyframes rule).
   1.180 +   * Return it if the parse was successful.
   1.181 +   */
   1.182 +  already_AddRefed<nsCSSKeyframeRule>
   1.183 +  ParseKeyframeRule(const nsSubstring& aBuffer,
   1.184 +                    nsIURI*            aURL,
   1.185 +                    uint32_t           aLineNumber);
   1.186 +
   1.187 +  /*
   1.188 +   * Parse a selector list for a keyframe rule.  Return whether
   1.189 +   * the parse succeeded.
   1.190 +   */
   1.191 +  bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
   1.192 +                                   nsIURI*            aURL,
   1.193 +                                   uint32_t           aLineNumber,
   1.194 +                                   InfallibleTArray<float>& aSelectorList);
   1.195 +
   1.196 +  /**
   1.197 +   * Parse a property and value and return whether the property/value pair
   1.198 +   * is supported.
   1.199 +   */
   1.200 +  bool EvaluateSupportsDeclaration(const nsAString& aProperty,
   1.201 +                                   const nsAString& aValue,
   1.202 +                                   nsIURI* aDocURL,
   1.203 +                                   nsIURI* aBaseURL,
   1.204 +                                   nsIPrincipal* aDocPrincipal);
   1.205 +
   1.206 +  /**
   1.207 +   * Parse an @supports condition and returns the result of evaluating the
   1.208 +   * condition.
   1.209 +   */
   1.210 +  bool EvaluateSupportsCondition(const nsAString& aCondition,
   1.211 +                                 nsIURI* aDocURL,
   1.212 +                                 nsIURI* aBaseURL,
   1.213 +                                 nsIPrincipal* aDocPrincipal);
   1.214 +
   1.215 +  typedef void (*VariableEnumFunc)(const nsAString&, void*);
   1.216 +
   1.217 +  /**
   1.218 +   * Parses aPropertyValue as a property value and calls aFunc for each
   1.219 +   * variable reference that is found.  Returns false if there was
   1.220 +   * a syntax error in the use of variable references.
   1.221 +   */
   1.222 +  bool EnumerateVariableReferences(const nsAString& aPropertyValue,
   1.223 +                                   VariableEnumFunc aFunc,
   1.224 +                                   void* aData);
   1.225 +
   1.226 +  /**
   1.227 +   * Parses aPropertyValue as a property value and resolves variable references
   1.228 +   * using the values in aVariables.
   1.229 +   */
   1.230 +  bool ResolveVariableValue(const nsAString& aPropertyValue,
   1.231 +                            const mozilla::CSSVariableValues* aVariables,
   1.232 +                            nsString& aResult,
   1.233 +                            nsCSSTokenSerializationType& aFirstToken,
   1.234 +                            nsCSSTokenSerializationType& aLastToken);
   1.235 +
   1.236 +  /**
   1.237 +   * Parses a string as a CSS token stream value for particular property,
   1.238 +   * resolving any variable references.  The parsed property value is stored
   1.239 +   * in the specified nsRuleData object.  If aShorthandPropertyID has a value
   1.240 +   * other than eCSSProperty_UNKNOWN, this is the property that will be parsed;
   1.241 +   * otherwise, aPropertyID will be parsed.  Either way, only aPropertyID,
   1.242 +   * a longhand property, will be copied over to the rule data.
   1.243 +   *
   1.244 +   * If the property cannot be parsed, it will be treated as if 'initial' or
   1.245 +   * 'inherit' were specified, for non-inherited and inherited properties
   1.246 +   * respectively.
   1.247 +   */
   1.248 +  void ParsePropertyWithVariableReferences(
   1.249 +                                   nsCSSProperty aPropertyID,
   1.250 +                                   nsCSSProperty aShorthandPropertyID,
   1.251 +                                   const nsAString& aValue,
   1.252 +                                   const mozilla::CSSVariableValues* aVariables,
   1.253 +                                   nsRuleData* aRuleData,
   1.254 +                                   nsIURI* aDocURL,
   1.255 +                                   nsIURI* aBaseURL,
   1.256 +                                   nsIPrincipal* aDocPrincipal,
   1.257 +                                   nsCSSStyleSheet* aSheet,
   1.258 +                                   uint32_t aLineNumber,
   1.259 +                                   uint32_t aLineOffset);
   1.260 +
   1.261 +protected:
   1.262 +  // This is a CSSParserImpl*, but if we expose that type name in this
   1.263 +  // header, we can't put the type definition (in nsCSSParser.cpp) in
   1.264 +  // the anonymous namespace.
   1.265 +  void* mImpl;
   1.266 +};
   1.267 +
   1.268 +#endif /* nsCSSParser_h___ */

mercurial