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/. */
|
2001-02-19 15:10:13 +03:00
|
|
|
#ifndef nsStyleUtil_h___
|
|
|
|
#define nsStyleUtil_h___
|
|
|
|
|
|
|
|
#include "nsCoord.h"
|
2009-10-22 01:57:57 +04:00
|
|
|
#include "nsCSSProperty.h"
|
2013-11-22 18:08:35 +04:00
|
|
|
#include "nsString.h"
|
2014-03-15 23:00:17 +04:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2014-06-06 10:09:23 +04:00
|
|
|
#include "gfxFontFamilyList.h"
|
2001-02-19 15:10:13 +03:00
|
|
|
|
2013-03-03 04:31:48 +04:00
|
|
|
class nsCSSValue;
|
2010-04-11 00:10:12 +04:00
|
|
|
class nsStringComparator;
|
2013-08-29 02:39:06 +04:00
|
|
|
class nsStyleCoord;
|
2010-04-11 00:10:12 +04:00
|
|
|
class nsIContent;
|
2013-09-16 05:06:52 +04:00
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIURI;
|
2013-03-03 04:31:48 +04:00
|
|
|
struct gfxFontFeature;
|
2013-09-16 05:06:52 +04:00
|
|
|
struct gfxAlternateValue;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct nsCSSValueList;
|
2001-02-19 15:10:13 +03:00
|
|
|
|
|
|
|
// Style utility functions
|
|
|
|
class nsStyleUtil {
|
|
|
|
public:
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool DashMatchCompare(const nsAString& aAttributeValue,
|
2004-08-24 01:10:39 +04:00
|
|
|
const nsAString& aSelectorValue,
|
|
|
|
const nsStringComparator& aComparator);
|
2012-11-17 06:53:38 +04:00
|
|
|
|
|
|
|
// Append a quoted (with 'quoteChar') and escaped version of aString
|
|
|
|
// to aResult. 'quoteChar' must be ' or ".
|
|
|
|
static void AppendEscapedCSSString(const nsAString& aString,
|
|
|
|
nsAString& aResult,
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t quoteChar = '"');
|
2012-11-17 06:53:38 +04:00
|
|
|
|
2010-02-04 23:49:29 +03:00
|
|
|
// Append the identifier given by |aIdent| to |aResult|, with
|
|
|
|
// appropriate escaping so that it can be reparsed to the same
|
|
|
|
// identifier.
|
2014-03-21 07:19:43 +04:00
|
|
|
// Returns false if |aIdent| contains U+0000
|
|
|
|
// Returns true for all other cases
|
|
|
|
static bool AppendEscapedCSSIdent(const nsAString& aIdent,
|
2010-02-04 23:49:29 +03:00
|
|
|
nsAString& aResult);
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2014-06-06 10:09:23 +04:00
|
|
|
static void
|
|
|
|
AppendEscapedCSSFontFamilyList(const mozilla::FontFamilyList& aFamilyList,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
2009-10-22 01:57:57 +04:00
|
|
|
// Append a bitmask-valued property's value(s) (space-separated) to aResult.
|
|
|
|
static void AppendBitmaskCSSValue(nsCSSProperty aProperty,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMaskedValue,
|
|
|
|
int32_t aFirstMask,
|
|
|
|
int32_t aLastMask,
|
2009-10-22 01:57:57 +04:00
|
|
|
nsAString& aResult);
|
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
static void AppendAngleValue(const nsStyleCoord& aValue, nsAString& aResult);
|
|
|
|
|
2013-01-13 03:27:53 +04:00
|
|
|
static void AppendPaintOrderValue(uint8_t aValue, nsAString& aResult);
|
|
|
|
|
2012-04-26 10:24:26 +04:00
|
|
|
static void AppendFontFeatureSettings(const nsTArray<gfxFontFeature>& aFeatures,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
|
|
|
static void AppendFontFeatureSettings(const nsCSSValue& src,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
2014-07-04 05:19:33 +04:00
|
|
|
static void AppendUnicodeRange(const nsCSSValue& aValue, nsAString& aResult);
|
|
|
|
|
2013-11-21 05:00:57 +04:00
|
|
|
static void AppendCSSNumber(float aNumber, nsAString& aResult)
|
|
|
|
{
|
|
|
|
aResult.AppendFloat(aNumber);
|
|
|
|
}
|
|
|
|
|
2014-09-22 04:32:58 +04:00
|
|
|
static void AppendSerializedFontSrc(const nsCSSValue& aValue,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
// convert bitmask value to keyword name for a functional alternate
|
|
|
|
static void GetFunctionalAlternatesName(int32_t aFeature,
|
|
|
|
nsAString& aFeatureName);
|
|
|
|
|
|
|
|
// Append functional font-variant-alternates values to string
|
|
|
|
static void
|
|
|
|
SerializeFunctionalAlternates(const nsTArray<gfxAlternateValue>& aAlternates,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
|
|
|
// List of functional font-variant-alternates values to feature/value pairs
|
|
|
|
static void
|
|
|
|
ComputeFunctionalAlternates(const nsCSSValueList* aList,
|
|
|
|
nsTArray<gfxAlternateValue>& aAlternateValues);
|
|
|
|
|
2007-03-08 21:44:45 +03:00
|
|
|
/*
|
|
|
|
* Convert an author-provided floating point number to an integer (0
|
|
|
|
* ... 255) appropriate for use in the alpha component of a color.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint8_t FloatToColorComponent(float aAlpha)
|
2007-03-08 21:44:45 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(0.0 <= aAlpha && aAlpha <= 1.0, "out of range");
|
|
|
|
return NSToIntRound(aAlpha * 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the alpha component of an nscolor (0 ... 255) to the
|
|
|
|
* floating point number with the least accurate *decimal*
|
|
|
|
* representation that is converted to that color.
|
|
|
|
*
|
|
|
|
* Should be used only by serialization code.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static float ColorComponentToFloat(uint8_t aAlpha);
|
2007-03-08 21:44:45 +03:00
|
|
|
|
2008-02-19 09:17:07 +03:00
|
|
|
/*
|
|
|
|
* Does this child count as significant for selector matching?
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSignificantChild(nsIContent* aChild,
|
|
|
|
bool aTextIsSignificant,
|
|
|
|
bool aWhitespaceIsSignificant);
|
2014-08-08 09:11:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Should we treat the given "flex-basis" value as "main-size"?
|
|
|
|
*
|
|
|
|
* In a horizontal flex container, this is merely a check for whether
|
|
|
|
* aFlexBasis has the enumerated value NS_STYLE_FLEX_BASIS_MAIN_SIZE.
|
|
|
|
*
|
|
|
|
* In a vertical flex container, we *also* treat other enumerated
|
|
|
|
* values (like "NS_STYLE_WIDTH_MAX_CONTENT") as if they were "main-size"
|
|
|
|
* (and return true from this function), because we don't currently support
|
|
|
|
* those other values for vertical/height-flavored properties. So, if we
|
|
|
|
* encounter them, we fall back to behaving as if we had flex-basis's initial
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
static bool IsFlexBasisMainSize(const nsStyleCoord& aFlexBasis,
|
|
|
|
bool aIsMainAxisHorizontal);
|
|
|
|
|
2012-08-30 21:58:24 +04:00
|
|
|
/*
|
|
|
|
* Does this principal have a CSP that blocks the application of
|
2013-11-09 03:44:39 +04:00
|
|
|
* inline styles? Returns false if application of the style should
|
2012-08-30 21:58:24 +04:00
|
|
|
* be blocked.
|
|
|
|
*
|
2013-11-09 03:44:39 +04:00
|
|
|
* @param aContent
|
|
|
|
* The <style> element that the caller wants to know whether to honor.
|
|
|
|
* Included to check the nonce attribute if one is provided. Allowed to
|
|
|
|
* be null, if this is for something other than a <style> element (in
|
|
|
|
* which case nonces won't be checked).
|
|
|
|
* @param aPrincipal
|
|
|
|
* The principal of the of the document (*not* of the style sheet).
|
|
|
|
* The document's principal is where any Content Security Policy that
|
|
|
|
* should be used to block or allow inline styles will be located.
|
|
|
|
* @param aSourceURI
|
|
|
|
* URI of document containing inline style (for reporting violations)
|
|
|
|
* @param aLineNumber
|
|
|
|
* Line number of inline style element in the containing document (for
|
|
|
|
* reporting violations)
|
|
|
|
* @param aStyleText
|
|
|
|
* Contents of the inline style element (for reporting violations)
|
|
|
|
* @param aRv
|
|
|
|
* Return error code in case of failure
|
|
|
|
* @return
|
|
|
|
* Does CSP allow application of the specified inline style?
|
2012-08-30 21:58:24 +04:00
|
|
|
*/
|
2013-11-09 03:44:39 +04:00
|
|
|
static bool CSPAllowsInlineStyle(nsIContent* aContent,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2012-08-30 21:58:24 +04:00
|
|
|
nsIURI* aSourceURI,
|
|
|
|
uint32_t aLineNumber,
|
|
|
|
const nsSubstring& aStyleText,
|
|
|
|
nsresult* aRv);
|
|
|
|
|
2001-02-19 15:10:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* nsStyleUtil_h___ */
|