2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2016-08-17 04:37:48 +03:00
|
|
|
#include "nsCSSPropertyID.h"
|
2014-03-15 23:00:17 +04:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2014-06-06 10:09:23 +04:00
|
|
|
#include "gfxFontFamilyList.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2015-09-29 05:20:14 +03:00
|
|
|
#include "nsStyleStruct.h"
|
2015-11-28 03:56:33 +03:00
|
|
|
#include "nsCRT.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 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;
|
2018-04-29 14:34:52 +03:00
|
|
|
struct nsCSSKTableEntry;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct nsCSSValueList;
|
2001-02-19 15:10:13 +03:00
|
|
|
|
2018-04-23 17:52:20 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class FontSlantStyle;
|
2018-06-15 04:12:02 +03:00
|
|
|
namespace dom {
|
2019-05-22 02:14:27 +03:00
|
|
|
class Document;
|
2018-06-15 04:12:02 +03:00
|
|
|
class Element;
|
2019-05-25 20:46:15 +03:00
|
|
|
} // namespace dom
|
2018-04-23 17:52:20 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
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
|
|
|
|
2017-06-20 12:19:52 +03:00
|
|
|
static bool ValueIncludes(const nsAString& aValueList,
|
|
|
|
const nsAString& aValue,
|
2016-06-30 23:37:08 +03:00
|
|
|
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
|
2016-01-05 23:05:23 +03:00
|
|
|
// identifier. An exception is if aIdent contains U+0000, which
|
|
|
|
// will be escaped as U+FFFD and then reparsed back to U+FFFD.
|
|
|
|
static void AppendEscapedCSSIdent(const nsAString& aIdent,
|
2010-02-04 23:49:29 +03:00
|
|
|
nsAString& aResult);
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2018-04-23 17:52:20 +03:00
|
|
|
static void AppendFontSlantStyle(const mozilla::FontSlantStyle&,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
2017-10-02 05:24:25 +03:00
|
|
|
public:
|
2009-10-22 01:57:57 +04:00
|
|
|
// Append a bitmask-valued property's value(s) (space-separated) to aResult.
|
2018-04-29 14:34:52 +03:00
|
|
|
static void AppendBitmaskCSSValue(const nsCSSKTableEntry aTable[],
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMaskedValue, int32_t aFirstMask,
|
2009-10-22 01:57:57 +04:00
|
|
|
int32_t aLastMask, nsAString& aResult);
|
|
|
|
|
2013-01-13 03:27:53 +04:00
|
|
|
static void AppendPaintOrderValue(uint8_t aValue, nsAString& aResult);
|
|
|
|
|
2013-11-21 05:00:57 +04:00
|
|
|
static void AppendCSSNumber(float aNumber, nsAString& aResult) {
|
|
|
|
aResult.AppendFloat(aNumber);
|
|
|
|
}
|
|
|
|
|
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");
|
2019-04-02 20:00:49 +03:00
|
|
|
return static_cast<uint8_t>(NSToIntRound(aAlpha * 255));
|
2007-03-08 21:44:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
Bug 998941 - part 1-7: Make HTMLEditor set InputEvent.data to serialized color value when InputEvent.inputType is "formatBackColor" or "formatForeColor" r=smaug,m_kato,emilio
Although neither Chrome nor Safari does not set InputEvent.data when the event
is caused by `document.execCommand()` with `backColor`, `foreColor` nor
`hiliteColor`, Safari supports styling color with touchbar and in that case,
Safari sets it (*1).
Additionally, currently Safari uses `rgb()` to represents a color value and
using same rule to serializing color value for CSS OM matches Safari's behavior
and can represent any valid color values.
This patch makes given color value parsed and then serialized with same code
in style system. If the value is `currentcolor`, `inherit`, `initial` or `reset`, sets
the value as-is for now. Additionally, when given value is invalid, sets the value
as-is for forward compatibility.
Note that automated tests will be added into input-events-exec-command.html
by the last patch.
1. https://github.com/w3c/input-events/issues/94#issuecomment-461061517
Differential Revision: https://phabricator.services.mozilla.com/D19295
--HG--
extra : moz-landing-system : lando
2019-02-19 09:31:28 +03:00
|
|
|
/**
|
|
|
|
* GetSerializedColorValue() computes serialized color value of aColor and
|
|
|
|
* returns it with aSerializedColor.
|
|
|
|
* https://drafts.csswg.org/cssom/#serialize-a-css-component-value
|
|
|
|
*/
|
|
|
|
static void GetSerializedColorValue(nscolor aColor,
|
|
|
|
nsAString& aSerializedColor);
|
|
|
|
|
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,
|
2018-02-28 04:54:01 +03:00
|
|
|
bool aWhitespaceIsSignificant);
|
2017-03-17 00:10:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Thread-safe version of IsSignificantChild()
|
|
|
|
*/
|
|
|
|
static bool ThreadSafeIsSignificantChild(const nsIContent* aChild,
|
|
|
|
bool aWhitespaceIsSignificant);
|
2014-11-15 03:45:23 +03:00
|
|
|
/**
|
|
|
|
* Returns true if our object-fit & object-position properties might cause
|
|
|
|
* a replaced element's contents to overflow its content-box (requiring
|
|
|
|
* clipping), or false if we can be sure that this won't happen.
|
|
|
|
*
|
|
|
|
* This lets us optimize by skipping clipping when we can tell it's
|
|
|
|
* unnecessary (particularly with the default values of these properties).
|
|
|
|
*
|
|
|
|
* @param aStylePos The nsStylePosition whose object-fit & object-position
|
|
|
|
* properties should be checked for potential overflow.
|
|
|
|
* @return false if we can be sure that the object-fit & object-position
|
|
|
|
* properties on 'aStylePos' cannot cause a replaced element's
|
|
|
|
* contents to overflow its content-box. Otherwise (if overflow is
|
|
|
|
* is possible), returns true.
|
|
|
|
*/
|
|
|
|
static bool ObjectPropsMightCauseOverflow(const nsStylePosition* aStylePos);
|
|
|
|
|
2012-08-30 21:58:24 +04:00
|
|
|
/*
|
2019-05-22 02:14:27 +03:00
|
|
|
* Does the document 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).
|
2019-05-22 02:14:27 +03:00
|
|
|
* @param aDocument
|
|
|
|
* The document containing the inline style (for querying the CSP);
|
2017-11-05 23:19:34 +03:00
|
|
|
* @param aTriggeringPrincipal
|
|
|
|
* The principal of the scripted caller which added the inline
|
|
|
|
* stylesheet, or null if no scripted caller can be identified.
|
2013-11-09 03:44:39 +04:00
|
|
|
* @param aLineNumber
|
|
|
|
* Line number of inline style element in the containing document (for
|
|
|
|
* reporting violations)
|
2018-07-05 09:21:04 +03:00
|
|
|
* @param aColumnNumber
|
|
|
|
* Column number of inline style element in the containing document (for
|
|
|
|
* reporting violations)
|
2013-11-09 03:44:39 +04:00
|
|
|
* @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
|
|
|
*/
|
2017-12-07 21:13:50 +03:00
|
|
|
static bool CSPAllowsInlineStyle(mozilla::dom::Element* aContent,
|
2019-05-22 02:14:27 +03:00
|
|
|
mozilla::dom::Document* aDocument,
|
2017-11-05 23:19:34 +03:00
|
|
|
nsIPrincipal* aTriggeringPrincipal,
|
2019-05-22 02:14:27 +03:00
|
|
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& aStyleText, nsresult* aRv);
|
2012-08-30 21:58:24 +04:00
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
template <size_t N>
|
|
|
|
static bool MatchesLanguagePrefix(const char16_t* aLang, size_t aLen,
|
|
|
|
const char16_t (&aPrefix)[N]) {
|
2018-01-09 17:49:37 +03:00
|
|
|
return !NS_strncmp(aLang, aPrefix, N - 1) &&
|
2015-11-28 03:56:33 +03:00
|
|
|
(aLen == N - 1 || aLang[N - 1] == '-');
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
2017-10-03 01:05:19 +03:00
|
|
|
static bool MatchesLanguagePrefix(const nsAtom* aLang,
|
2015-11-28 03:56:33 +03:00
|
|
|
const char16_t (&aPrefix)[N]) {
|
|
|
|
MOZ_ASSERT(aLang);
|
|
|
|
return MatchesLanguagePrefix(aLang->GetUTF16String(), aLang->GetLength(),
|
|
|
|
aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
static bool MatchesLanguagePrefix(const nsAString& aLang,
|
|
|
|
const char16_t (&aPrefix)[N]) {
|
|
|
|
return MatchesLanguagePrefix(aLang.Data(), aLang.Length(), aPrefix);
|
|
|
|
}
|
2001-02-19 15:10:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsStyleUtil_h___ */
|