Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef nsStyleUtil_h___ |
michael@0 | 6 | #define nsStyleUtil_h___ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsCoord.h" |
michael@0 | 9 | #include "nsCSSProperty.h" |
michael@0 | 10 | #include "nsString.h" |
michael@0 | 11 | #include "nsTArrayForwardDeclare.h" |
michael@0 | 12 | |
michael@0 | 13 | class nsCSSValue; |
michael@0 | 14 | class nsStringComparator; |
michael@0 | 15 | class nsStyleCoord; |
michael@0 | 16 | class nsIContent; |
michael@0 | 17 | class nsIPrincipal; |
michael@0 | 18 | class nsIURI; |
michael@0 | 19 | struct gfxFontFeature; |
michael@0 | 20 | struct gfxAlternateValue; |
michael@0 | 21 | class nsCSSValueList; |
michael@0 | 22 | |
michael@0 | 23 | // Style utility functions |
michael@0 | 24 | class nsStyleUtil { |
michael@0 | 25 | public: |
michael@0 | 26 | |
michael@0 | 27 | static bool DashMatchCompare(const nsAString& aAttributeValue, |
michael@0 | 28 | const nsAString& aSelectorValue, |
michael@0 | 29 | const nsStringComparator& aComparator); |
michael@0 | 30 | |
michael@0 | 31 | // Append a quoted (with 'quoteChar') and escaped version of aString |
michael@0 | 32 | // to aResult. 'quoteChar' must be ' or ". |
michael@0 | 33 | static void AppendEscapedCSSString(const nsAString& aString, |
michael@0 | 34 | nsAString& aResult, |
michael@0 | 35 | char16_t quoteChar = '"'); |
michael@0 | 36 | |
michael@0 | 37 | // Append the identifier given by |aIdent| to |aResult|, with |
michael@0 | 38 | // appropriate escaping so that it can be reparsed to the same |
michael@0 | 39 | // identifier. |
michael@0 | 40 | // Returns false if |aIdent| contains U+0000 |
michael@0 | 41 | // Returns true for all other cases |
michael@0 | 42 | static bool AppendEscapedCSSIdent(const nsAString& aIdent, |
michael@0 | 43 | nsAString& aResult); |
michael@0 | 44 | |
michael@0 | 45 | // Append a bitmask-valued property's value(s) (space-separated) to aResult. |
michael@0 | 46 | static void AppendBitmaskCSSValue(nsCSSProperty aProperty, |
michael@0 | 47 | int32_t aMaskedValue, |
michael@0 | 48 | int32_t aFirstMask, |
michael@0 | 49 | int32_t aLastMask, |
michael@0 | 50 | nsAString& aResult); |
michael@0 | 51 | |
michael@0 | 52 | static void AppendAngleValue(const nsStyleCoord& aValue, nsAString& aResult); |
michael@0 | 53 | |
michael@0 | 54 | static void AppendPaintOrderValue(uint8_t aValue, nsAString& aResult); |
michael@0 | 55 | |
michael@0 | 56 | static void AppendFontFeatureSettings(const nsTArray<gfxFontFeature>& aFeatures, |
michael@0 | 57 | nsAString& aResult); |
michael@0 | 58 | |
michael@0 | 59 | static void AppendFontFeatureSettings(const nsCSSValue& src, |
michael@0 | 60 | nsAString& aResult); |
michael@0 | 61 | |
michael@0 | 62 | static void AppendCSSNumber(float aNumber, nsAString& aResult) |
michael@0 | 63 | { |
michael@0 | 64 | aResult.AppendFloat(aNumber); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | // convert bitmask value to keyword name for a functional alternate |
michael@0 | 68 | static void GetFunctionalAlternatesName(int32_t aFeature, |
michael@0 | 69 | nsAString& aFeatureName); |
michael@0 | 70 | |
michael@0 | 71 | // Append functional font-variant-alternates values to string |
michael@0 | 72 | static void |
michael@0 | 73 | SerializeFunctionalAlternates(const nsTArray<gfxAlternateValue>& aAlternates, |
michael@0 | 74 | nsAString& aResult); |
michael@0 | 75 | |
michael@0 | 76 | // List of functional font-variant-alternates values to feature/value pairs |
michael@0 | 77 | static void |
michael@0 | 78 | ComputeFunctionalAlternates(const nsCSSValueList* aList, |
michael@0 | 79 | nsTArray<gfxAlternateValue>& aAlternateValues); |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * Convert an author-provided floating point number to an integer (0 |
michael@0 | 83 | * ... 255) appropriate for use in the alpha component of a color. |
michael@0 | 84 | */ |
michael@0 | 85 | static uint8_t FloatToColorComponent(float aAlpha) |
michael@0 | 86 | { |
michael@0 | 87 | NS_ASSERTION(0.0 <= aAlpha && aAlpha <= 1.0, "out of range"); |
michael@0 | 88 | return NSToIntRound(aAlpha * 255); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | /* |
michael@0 | 92 | * Convert the alpha component of an nscolor (0 ... 255) to the |
michael@0 | 93 | * floating point number with the least accurate *decimal* |
michael@0 | 94 | * representation that is converted to that color. |
michael@0 | 95 | * |
michael@0 | 96 | * Should be used only by serialization code. |
michael@0 | 97 | */ |
michael@0 | 98 | static float ColorComponentToFloat(uint8_t aAlpha); |
michael@0 | 99 | |
michael@0 | 100 | /* |
michael@0 | 101 | * Does this child count as significant for selector matching? |
michael@0 | 102 | */ |
michael@0 | 103 | static bool IsSignificantChild(nsIContent* aChild, |
michael@0 | 104 | bool aTextIsSignificant, |
michael@0 | 105 | bool aWhitespaceIsSignificant); |
michael@0 | 106 | /* |
michael@0 | 107 | * Does this principal have a CSP that blocks the application of |
michael@0 | 108 | * inline styles? Returns false if application of the style should |
michael@0 | 109 | * be blocked. |
michael@0 | 110 | * |
michael@0 | 111 | * @param aContent |
michael@0 | 112 | * The <style> element that the caller wants to know whether to honor. |
michael@0 | 113 | * Included to check the nonce attribute if one is provided. Allowed to |
michael@0 | 114 | * be null, if this is for something other than a <style> element (in |
michael@0 | 115 | * which case nonces won't be checked). |
michael@0 | 116 | * @param aPrincipal |
michael@0 | 117 | * The principal of the of the document (*not* of the style sheet). |
michael@0 | 118 | * The document's principal is where any Content Security Policy that |
michael@0 | 119 | * should be used to block or allow inline styles will be located. |
michael@0 | 120 | * @param aSourceURI |
michael@0 | 121 | * URI of document containing inline style (for reporting violations) |
michael@0 | 122 | * @param aLineNumber |
michael@0 | 123 | * Line number of inline style element in the containing document (for |
michael@0 | 124 | * reporting violations) |
michael@0 | 125 | * @param aStyleText |
michael@0 | 126 | * Contents of the inline style element (for reporting violations) |
michael@0 | 127 | * @param aRv |
michael@0 | 128 | * Return error code in case of failure |
michael@0 | 129 | * @return |
michael@0 | 130 | * Does CSP allow application of the specified inline style? |
michael@0 | 131 | */ |
michael@0 | 132 | static bool CSPAllowsInlineStyle(nsIContent* aContent, |
michael@0 | 133 | nsIPrincipal* aPrincipal, |
michael@0 | 134 | nsIURI* aSourceURI, |
michael@0 | 135 | uint32_t aLineNumber, |
michael@0 | 136 | const nsSubstring& aStyleText, |
michael@0 | 137 | nsresult* aRv); |
michael@0 | 138 | |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | #endif /* nsStyleUtil_h___ */ |