layout/style/nsStyleUtil.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsStyleUtil.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     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 +#ifndef nsStyleUtil_h___
     1.9 +#define nsStyleUtil_h___
    1.10 +
    1.11 +#include "nsCoord.h"
    1.12 +#include "nsCSSProperty.h"
    1.13 +#include "nsString.h"
    1.14 +#include "nsTArrayForwardDeclare.h"
    1.15 +
    1.16 +class nsCSSValue;
    1.17 +class nsStringComparator;
    1.18 +class nsStyleCoord;
    1.19 +class nsIContent;
    1.20 +class nsIPrincipal;
    1.21 +class nsIURI;
    1.22 +struct gfxFontFeature;
    1.23 +struct gfxAlternateValue;
    1.24 +class nsCSSValueList;
    1.25 +
    1.26 +// Style utility functions
    1.27 +class nsStyleUtil {
    1.28 +public:
    1.29 +
    1.30 + static bool DashMatchCompare(const nsAString& aAttributeValue,
    1.31 +                                const nsAString& aSelectorValue,
    1.32 +                                const nsStringComparator& aComparator);
    1.33 +
    1.34 +  // Append a quoted (with 'quoteChar') and escaped version of aString
    1.35 +  // to aResult.  'quoteChar' must be ' or ".
    1.36 +  static void AppendEscapedCSSString(const nsAString& aString,
    1.37 +                                     nsAString& aResult,
    1.38 +                                     char16_t quoteChar = '"');
    1.39 +
    1.40 +  // Append the identifier given by |aIdent| to |aResult|, with
    1.41 +  // appropriate escaping so that it can be reparsed to the same
    1.42 +  // identifier.
    1.43 +  // Returns false if |aIdent| contains U+0000
    1.44 +  // Returns true for all other cases
    1.45 +  static bool AppendEscapedCSSIdent(const nsAString& aIdent,
    1.46 +                                    nsAString& aResult);
    1.47 +
    1.48 +  // Append a bitmask-valued property's value(s) (space-separated) to aResult.
    1.49 +  static void AppendBitmaskCSSValue(nsCSSProperty aProperty,
    1.50 +                                    int32_t aMaskedValue,
    1.51 +                                    int32_t aFirstMask,
    1.52 +                                    int32_t aLastMask,
    1.53 +                                    nsAString& aResult);
    1.54 +
    1.55 +  static void AppendAngleValue(const nsStyleCoord& aValue, nsAString& aResult);
    1.56 +
    1.57 +  static void AppendPaintOrderValue(uint8_t aValue, nsAString& aResult);
    1.58 +
    1.59 +  static void AppendFontFeatureSettings(const nsTArray<gfxFontFeature>& aFeatures,
    1.60 +                                        nsAString& aResult);
    1.61 +
    1.62 +  static void AppendFontFeatureSettings(const nsCSSValue& src,
    1.63 +                                        nsAString& aResult);
    1.64 +
    1.65 +  static void AppendCSSNumber(float aNumber, nsAString& aResult)
    1.66 +  {
    1.67 +    aResult.AppendFloat(aNumber);
    1.68 +  }
    1.69 +
    1.70 +  // convert bitmask value to keyword name for a functional alternate
    1.71 +  static void GetFunctionalAlternatesName(int32_t aFeature,
    1.72 +                                          nsAString& aFeatureName);
    1.73 +
    1.74 +  // Append functional font-variant-alternates values to string
    1.75 +  static void
    1.76 +  SerializeFunctionalAlternates(const nsTArray<gfxAlternateValue>& aAlternates,
    1.77 +                                nsAString& aResult);
    1.78 +
    1.79 +  // List of functional font-variant-alternates values to feature/value pairs
    1.80 +  static void
    1.81 +  ComputeFunctionalAlternates(const nsCSSValueList* aList,
    1.82 +                              nsTArray<gfxAlternateValue>& aAlternateValues);
    1.83 +
    1.84 +  /*
    1.85 +   * Convert an author-provided floating point number to an integer (0
    1.86 +   * ... 255) appropriate for use in the alpha component of a color.
    1.87 +   */
    1.88 +  static uint8_t FloatToColorComponent(float aAlpha)
    1.89 +  {
    1.90 +    NS_ASSERTION(0.0 <= aAlpha && aAlpha <= 1.0, "out of range");
    1.91 +    return NSToIntRound(aAlpha * 255);
    1.92 +  }
    1.93 +
    1.94 +  /*
    1.95 +   * Convert the alpha component of an nscolor (0 ... 255) to the
    1.96 +   * floating point number with the least accurate *decimal*
    1.97 +   * representation that is converted to that color.
    1.98 +   *
    1.99 +   * Should be used only by serialization code.
   1.100 +   */
   1.101 +  static float ColorComponentToFloat(uint8_t aAlpha);
   1.102 +
   1.103 +  /*
   1.104 +   * Does this child count as significant for selector matching?
   1.105 +   */
   1.106 +  static bool IsSignificantChild(nsIContent* aChild,
   1.107 +                                   bool aTextIsSignificant,
   1.108 +                                   bool aWhitespaceIsSignificant);
   1.109 +  /*
   1.110 +   *  Does this principal have a CSP that blocks the application of
   1.111 +   *  inline styles? Returns false if application of the style should
   1.112 +   *  be blocked.
   1.113 +   *
   1.114 +   *  @param aContent
   1.115 +   *      The <style> element that the caller wants to know whether to honor.
   1.116 +   *      Included to check the nonce attribute if one is provided. Allowed to
   1.117 +   *      be null, if this is for something other than a <style> element (in
   1.118 +   *      which case nonces won't be checked).
   1.119 +   *  @param aPrincipal
   1.120 +   *      The principal of the of the document (*not* of the style sheet).
   1.121 +   *      The document's principal is where any Content Security Policy that
   1.122 +   *      should be used to block or allow inline styles will be located.
   1.123 +   *  @param aSourceURI
   1.124 +   *      URI of document containing inline style (for reporting violations)
   1.125 +   *  @param aLineNumber
   1.126 +   *      Line number of inline style element in the containing document (for
   1.127 +   *      reporting violations)
   1.128 +   *  @param aStyleText
   1.129 +   *      Contents of the inline style element (for reporting violations)
   1.130 +   *  @param aRv
   1.131 +   *      Return error code in case of failure
   1.132 +   *  @return
   1.133 +   *      Does CSP allow application of the specified inline style?
   1.134 +   */
   1.135 +  static bool CSPAllowsInlineStyle(nsIContent* aContent,
   1.136 +                                   nsIPrincipal* aPrincipal,
   1.137 +                                   nsIURI* aSourceURI,
   1.138 +                                   uint32_t aLineNumber,
   1.139 +                                   const nsSubstring& aStyleText,
   1.140 +                                   nsresult* aRv);
   1.141 +
   1.142 +};
   1.143 +
   1.144 +
   1.145 +#endif /* nsStyleUtil_h___ */

mercurial