michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsStyleUtil_h___ michael@0: #define nsStyleUtil_h___ michael@0: michael@0: #include "nsCoord.h" michael@0: #include "nsCSSProperty.h" michael@0: #include "nsString.h" michael@0: #include "nsTArrayForwardDeclare.h" michael@0: michael@0: class nsCSSValue; michael@0: class nsStringComparator; michael@0: class nsStyleCoord; michael@0: class nsIContent; michael@0: class nsIPrincipal; michael@0: class nsIURI; michael@0: struct gfxFontFeature; michael@0: struct gfxAlternateValue; michael@0: class nsCSSValueList; michael@0: michael@0: // Style utility functions michael@0: class nsStyleUtil { michael@0: public: michael@0: michael@0: static bool DashMatchCompare(const nsAString& aAttributeValue, michael@0: const nsAString& aSelectorValue, michael@0: const nsStringComparator& aComparator); michael@0: michael@0: // Append a quoted (with 'quoteChar') and escaped version of aString michael@0: // to aResult. 'quoteChar' must be ' or ". michael@0: static void AppendEscapedCSSString(const nsAString& aString, michael@0: nsAString& aResult, michael@0: char16_t quoteChar = '"'); michael@0: michael@0: // Append the identifier given by |aIdent| to |aResult|, with michael@0: // appropriate escaping so that it can be reparsed to the same michael@0: // identifier. michael@0: // Returns false if |aIdent| contains U+0000 michael@0: // Returns true for all other cases michael@0: static bool AppendEscapedCSSIdent(const nsAString& aIdent, michael@0: nsAString& aResult); michael@0: michael@0: // Append a bitmask-valued property's value(s) (space-separated) to aResult. michael@0: static void AppendBitmaskCSSValue(nsCSSProperty aProperty, michael@0: int32_t aMaskedValue, michael@0: int32_t aFirstMask, michael@0: int32_t aLastMask, michael@0: nsAString& aResult); michael@0: michael@0: static void AppendAngleValue(const nsStyleCoord& aValue, nsAString& aResult); michael@0: michael@0: static void AppendPaintOrderValue(uint8_t aValue, nsAString& aResult); michael@0: michael@0: static void AppendFontFeatureSettings(const nsTArray& aFeatures, michael@0: nsAString& aResult); michael@0: michael@0: static void AppendFontFeatureSettings(const nsCSSValue& src, michael@0: nsAString& aResult); michael@0: michael@0: static void AppendCSSNumber(float aNumber, nsAString& aResult) michael@0: { michael@0: aResult.AppendFloat(aNumber); michael@0: } michael@0: michael@0: // convert bitmask value to keyword name for a functional alternate michael@0: static void GetFunctionalAlternatesName(int32_t aFeature, michael@0: nsAString& aFeatureName); michael@0: michael@0: // Append functional font-variant-alternates values to string michael@0: static void michael@0: SerializeFunctionalAlternates(const nsTArray& aAlternates, michael@0: nsAString& aResult); michael@0: michael@0: // List of functional font-variant-alternates values to feature/value pairs michael@0: static void michael@0: ComputeFunctionalAlternates(const nsCSSValueList* aList, michael@0: nsTArray& aAlternateValues); michael@0: michael@0: /* michael@0: * Convert an author-provided floating point number to an integer (0 michael@0: * ... 255) appropriate for use in the alpha component of a color. michael@0: */ michael@0: static uint8_t FloatToColorComponent(float aAlpha) michael@0: { michael@0: NS_ASSERTION(0.0 <= aAlpha && aAlpha <= 1.0, "out of range"); michael@0: return NSToIntRound(aAlpha * 255); michael@0: } michael@0: michael@0: /* michael@0: * Convert the alpha component of an nscolor (0 ... 255) to the michael@0: * floating point number with the least accurate *decimal* michael@0: * representation that is converted to that color. michael@0: * michael@0: * Should be used only by serialization code. michael@0: */ michael@0: static float ColorComponentToFloat(uint8_t aAlpha); michael@0: michael@0: /* michael@0: * Does this child count as significant for selector matching? michael@0: */ michael@0: static bool IsSignificantChild(nsIContent* aChild, michael@0: bool aTextIsSignificant, michael@0: bool aWhitespaceIsSignificant); michael@0: /* michael@0: * Does this principal have a CSP that blocks the application of michael@0: * inline styles? Returns false if application of the style should michael@0: * be blocked. michael@0: * michael@0: * @param aContent michael@0: * The