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/. */
|
1998-07-23 22:04:24 +04:00
|
|
|
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "mozilla/ExpandedPrincipal.h"
|
2018-04-23 17:52:20 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2007-02-09 03:15:14 +03:00
|
|
|
#include "nsIContent.h"
|
2009-10-22 01:57:57 +04:00
|
|
|
#include "nsCSSProps.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "nsContentUtils.h"
|
2013-08-29 02:39:06 +04:00
|
|
|
#include "nsROCSSPrimitiveValue.h"
|
2014-11-15 03:45:23 +03:00
|
|
|
#include "nsStyleStruct.h"
|
2013-11-09 03:44:39 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
2012-08-30 21:58:24 +04:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsIURI.h"
|
2017-07-27 21:01:24 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2017-11-23 13:04:52 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-07-04 05:19:33 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2016-12-03 13:58:44 +03:00
|
|
|
#include <cctype>
|
2000-02-24 15:51:28 +03:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2000-02-24 15:51:28 +03:00
|
|
|
//------------------------------------------------------------------------------
|
2002-12-11 02:44:03 +03:00
|
|
|
// Font Algorithm Code
|
2000-02-24 15:51:28 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2004-08-24 01:10:39 +04:00
|
|
|
// Compare two language strings
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsStyleUtil::DashMatchCompare(const nsAString& aAttributeValue,
|
2004-08-24 01:10:39 +04:00
|
|
|
const nsAString& aSelectorValue,
|
|
|
|
const nsStringComparator& aComparator) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool result;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t selectorLen = aSelectorValue.Length();
|
|
|
|
uint32_t attributeLen = aAttributeValue.Length();
|
2004-08-24 01:10:39 +04:00
|
|
|
if (selectorLen > attributeLen) {
|
2011-10-17 18:59:28 +04:00
|
|
|
result = false;
|
2004-08-24 01:10:39 +04:00
|
|
|
} else {
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
if (selectorLen != attributeLen &&
|
|
|
|
*aAttributeValue.BeginReading(iter).advance(selectorLen) !=
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t('-')) {
|
2004-08-24 01:10:39 +04:00
|
|
|
// to match, the aAttributeValue must have a dash after the end of
|
|
|
|
// the aSelectorValue's text (unless the aSelectorValue and the
|
|
|
|
// aAttributeValue have the same text)
|
2011-10-17 18:59:28 +04:00
|
|
|
result = false;
|
2004-08-24 01:10:39 +04:00
|
|
|
} else {
|
|
|
|
result = StringBeginsWith(aAttributeValue, aSelectorValue, aComparator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2005-01-30 21:01:57 +03:00
|
|
|
|
2017-06-20 12:19:52 +03:00
|
|
|
bool nsStyleUtil::ValueIncludes(const nsAString& aValueList,
|
|
|
|
const nsAString& aValue,
|
2016-06-30 23:37:08 +03:00
|
|
|
const nsStringComparator& aComparator) {
|
|
|
|
const char16_t *p = aValueList.BeginReading(),
|
|
|
|
*p_end = aValueList.EndReading();
|
|
|
|
|
|
|
|
while (p < p_end) {
|
|
|
|
// skip leading space
|
|
|
|
while (p != p_end && nsContentUtils::IsHTMLWhitespace(*p)) ++p;
|
|
|
|
|
|
|
|
const char16_t* val_start = p;
|
|
|
|
|
|
|
|
// look for space or end
|
|
|
|
while (p != p_end && !nsContentUtils::IsHTMLWhitespace(*p)) ++p;
|
|
|
|
|
|
|
|
const char16_t* val_end = p;
|
|
|
|
|
|
|
|
if (val_start < val_end &&
|
|
|
|
aValue.Equals(Substring(val_start, val_end), aComparator))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
++p; // we know the next character is not whitespace
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-17 06:53:38 +04:00
|
|
|
void nsStyleUtil::AppendEscapedCSSString(const nsAString& aString,
|
|
|
|
nsAString& aReturn,
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t quoteChar) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(quoteChar == '\'' || quoteChar == '"',
|
|
|
|
"CSS strings must be quoted with ' or \"");
|
|
|
|
|
2012-11-17 06:53:38 +04:00
|
|
|
aReturn.Append(quoteChar);
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* in = aString.BeginReading();
|
|
|
|
const char16_t* const end = aString.EndReading();
|
2012-11-17 06:53:38 +04:00
|
|
|
for (; in != end; in++) {
|
2017-09-04 16:00:18 +03:00
|
|
|
if (*in < 0x20 || *in == 0x7F) {
|
|
|
|
// Escape U+0000 through U+001F and U+007F numerically.
|
2016-12-14 19:32:21 +03:00
|
|
|
aReturn.AppendPrintf("\\%x ", *in);
|
2012-11-17 06:53:38 +04:00
|
|
|
} else {
|
|
|
|
if (*in == '"' || *in == '\'' || *in == '\\') {
|
|
|
|
// Escape backslash and quote characters symbolically.
|
|
|
|
// It's not technically necessary to escape the quote
|
|
|
|
// character that isn't being used to delimit the string,
|
|
|
|
// but we do it anyway because that makes testing simpler.
|
2014-01-04 19:02:17 +04:00
|
|
|
aReturn.Append(char16_t('\\'));
|
2012-11-17 06:53:38 +04:00
|
|
|
}
|
|
|
|
aReturn.Append(*in);
|
2005-01-30 21:01:57 +03:00
|
|
|
}
|
|
|
|
}
|
2009-03-06 07:05:00 +03:00
|
|
|
|
2012-11-17 06:53:38 +04:00
|
|
|
aReturn.Append(quoteChar);
|
2005-01-30 21:01:57 +03:00
|
|
|
}
|
2007-03-08 21:44:45 +03:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void nsStyleUtil::AppendEscapedCSSIdent(const nsAString& aIdent,
|
|
|
|
nsAString& aReturn) {
|
2010-02-04 23:49:29 +03:00
|
|
|
// The relevant parts of the CSS grammar are:
|
2014-05-15 21:26:53 +04:00
|
|
|
// ident ([-]?{nmstart}|[-][-]){nmchar}*
|
2010-02-04 23:49:29 +03:00
|
|
|
// nmstart [_a-z]|{nonascii}|{escape}
|
|
|
|
// nmchar [_a-z0-9-]|{nonascii}|{escape}
|
|
|
|
// nonascii [^\0-\177]
|
|
|
|
// escape {unicode}|\\[^\n\r\f0-9a-f]
|
|
|
|
// unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
|
2014-05-15 21:26:53 +04:00
|
|
|
// from http://www.w3.org/TR/CSS21/syndata.html#tokenization but
|
|
|
|
// modified for idents by
|
|
|
|
// http://dev.w3.org/csswg/cssom/#serialize-an-identifier and
|
|
|
|
// http://dev.w3.org/csswg/css-syntax/#would-start-an-identifier
|
2010-02-04 23:49:29 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* in = aIdent.BeginReading();
|
|
|
|
const char16_t* const end = aIdent.EndReading();
|
2010-02-04 23:49:29 +03:00
|
|
|
|
2012-11-17 06:53:38 +04:00
|
|
|
if (in == end) return;
|
|
|
|
|
|
|
|
// A leading dash does not need to be escaped as long as it is not the
|
|
|
|
// *only* character in the identifier.
|
2014-05-15 21:26:53 +04:00
|
|
|
if (*in == '-') {
|
|
|
|
if (in + 1 == end) {
|
|
|
|
aReturn.Append(char16_t('\\'));
|
|
|
|
aReturn.Append(char16_t('-'));
|
2016-01-05 23:05:23 +03:00
|
|
|
return;
|
2014-05-15 21:26:53 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
aReturn.Append(char16_t('-'));
|
2010-02-04 23:49:29 +03:00
|
|
|
++in;
|
|
|
|
}
|
|
|
|
|
2012-11-17 06:53:38 +04:00
|
|
|
// Escape a digit at the start (including after a dash),
|
|
|
|
// numerically. If we didn't escape it numerically, it would get
|
|
|
|
// interpreted as a numeric escape for the wrong character.
|
2014-05-15 21:26:53 +04:00
|
|
|
if (in != end && ('0' <= *in && *in <= '9')) {
|
2016-12-14 19:32:21 +03:00
|
|
|
aReturn.AppendPrintf("\\%x ", *in);
|
2012-11-17 06:53:38 +04:00
|
|
|
++in;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; in != end; ++in) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *in;
|
2014-03-21 07:19:43 +04:00
|
|
|
if (ch == 0x00) {
|
2016-01-05 23:05:23 +03:00
|
|
|
aReturn.Append(char16_t(0xFFFD));
|
2017-09-04 16:00:18 +03:00
|
|
|
} else if (ch < 0x20 || 0x7F == ch) {
|
|
|
|
// Escape U+0000 through U+001F and U+007F numerically.
|
2016-12-14 19:32:21 +03:00
|
|
|
aReturn.AppendPrintf("\\%x ", *in);
|
2010-02-04 23:49:29 +03:00
|
|
|
} else {
|
2012-11-17 06:53:38 +04:00
|
|
|
// Escape ASCII non-identifier printables as a backslash plus
|
|
|
|
// the character.
|
|
|
|
if (ch < 0x7F && ch != '_' && ch != '-' && (ch < '0' || '9' < ch) &&
|
|
|
|
(ch < 'A' || 'Z' < ch) && (ch < 'a' || 'z' < ch)) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aReturn.Append(char16_t('\\'));
|
2010-02-04 23:49:29 +03:00
|
|
|
}
|
|
|
|
aReturn.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void nsStyleUtil::AppendBitmaskCSSValue(const nsCSSKTableEntry aTable[],
|
|
|
|
int32_t aMaskedValue,
|
|
|
|
int32_t aFirstMask, int32_t aLastMask,
|
|
|
|
nsAString& aResult) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t mask = aFirstMask; mask <= aLastMask; mask <<= 1) {
|
2009-10-22 01:57:57 +04:00
|
|
|
if (mask & aMaskedValue) {
|
2018-04-29 14:34:52 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(mask, aTable), aResult);
|
2009-10-22 01:57:57 +04:00
|
|
|
aMaskedValue &= ~mask;
|
|
|
|
if (aMaskedValue) { // more left
|
2014-01-04 19:02:17 +04:00
|
|
|
aResult.Append(char16_t(' '));
|
2009-10-22 01:57:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aMaskedValue == 0, "unexpected bit remaining in bitfield");
|
2009-10-22 01:57:57 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void nsStyleUtil::AppendPaintOrderValue(uint8_t aValue, nsAString& aResult) {
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(
|
2013-01-13 03:27:53 +04:00
|
|
|
NS_STYLE_PAINT_ORDER_BITWIDTH * NS_STYLE_PAINT_ORDER_LAST_VALUE <= 8,
|
|
|
|
"SVGStyleStruct::mPaintOrder and local variables not big enough");
|
|
|
|
|
|
|
|
if (aValue == NS_STYLE_PAINT_ORDER_NORMAL) {
|
|
|
|
aResult.AppendLiteral("normal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the minimal value necessary for the given paint order.
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(NS_STYLE_PAINT_ORDER_LAST_VALUE == 3,
|
|
|
|
"paint-order values added; check serialization");
|
2013-01-13 03:27:53 +04:00
|
|
|
|
|
|
|
// The following relies on the default order being the order of the
|
|
|
|
// constant values.
|
|
|
|
|
|
|
|
const uint8_t MASK = (1 << NS_STYLE_PAINT_ORDER_BITWIDTH) - 1;
|
|
|
|
|
|
|
|
uint32_t lastPositionToSerialize = 0;
|
|
|
|
for (uint32_t position = NS_STYLE_PAINT_ORDER_LAST_VALUE - 1; position > 0;
|
|
|
|
position--) {
|
|
|
|
uint8_t component =
|
|
|
|
(aValue >> (position * NS_STYLE_PAINT_ORDER_BITWIDTH)) & MASK;
|
|
|
|
uint8_t earlierComponent =
|
|
|
|
(aValue >> ((position - 1) * NS_STYLE_PAINT_ORDER_BITWIDTH)) & MASK;
|
|
|
|
if (component < earlierComponent) {
|
|
|
|
lastPositionToSerialize = position - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t position = 0; position <= lastPositionToSerialize; position++) {
|
|
|
|
if (position > 0) {
|
2014-05-22 07:48:51 +04:00
|
|
|
aResult.Append(' ');
|
2013-01-13 03:27:53 +04:00
|
|
|
}
|
|
|
|
uint8_t component = aValue & MASK;
|
|
|
|
switch (component) {
|
|
|
|
case NS_STYLE_PAINT_ORDER_FILL:
|
|
|
|
aResult.AppendLiteral("fill");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_PAINT_ORDER_STROKE:
|
|
|
|
aResult.AppendLiteral("stroke");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_PAINT_ORDER_MARKERS:
|
|
|
|
aResult.AppendLiteral("markers");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected paint-order component value");
|
2013-01-13 03:27:53 +04:00
|
|
|
}
|
|
|
|
aValue >>= NS_STYLE_PAINT_ORDER_BITWIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
float nsStyleUtil::ColorComponentToFloat(uint8_t aAlpha) {
|
2007-03-08 21:44:45 +03:00
|
|
|
// Alpha values are expressed as decimals, so we should convert
|
|
|
|
// back, using as few decimal places as possible for
|
|
|
|
// round-tripping.
|
|
|
|
// First try two decimal places:
|
|
|
|
float rounded = NS_roundf(float(aAlpha) * 100.0f / 255.0f) / 100.0f;
|
|
|
|
if (FloatToColorComponent(rounded) != aAlpha) {
|
|
|
|
// Use three decimal places.
|
|
|
|
rounded = NS_roundf(float(aAlpha) * 1000.0f / 255.0f) / 1000.0f;
|
|
|
|
}
|
|
|
|
return rounded;
|
|
|
|
}
|
2008-02-19 09:17:07 +03:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void nsStyleUtil::GetSerializedColorValue(nscolor aColor,
|
|
|
|
nsAString& aSerializedColor) {
|
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
|
|
|
MOZ_ASSERT(aSerializedColor.IsEmpty());
|
|
|
|
|
|
|
|
const bool hasAlpha = NS_GET_A(aColor) != 255;
|
|
|
|
if (hasAlpha) {
|
|
|
|
aSerializedColor.AppendLiteral("rgba(");
|
|
|
|
} else {
|
|
|
|
aSerializedColor.AppendLiteral("rgb(");
|
|
|
|
}
|
|
|
|
aSerializedColor.AppendInt(NS_GET_R(aColor));
|
|
|
|
aSerializedColor.AppendLiteral(", ");
|
|
|
|
aSerializedColor.AppendInt(NS_GET_G(aColor));
|
|
|
|
aSerializedColor.AppendLiteral(", ");
|
|
|
|
aSerializedColor.AppendInt(NS_GET_B(aColor));
|
|
|
|
if (hasAlpha) {
|
|
|
|
aSerializedColor.AppendLiteral(", ");
|
|
|
|
float alpha = nsStyleUtil::ColorComponentToFloat(NS_GET_A(aColor));
|
|
|
|
nsStyleUtil::AppendCSSNumber(alpha, aSerializedColor);
|
|
|
|
}
|
|
|
|
aSerializedColor.AppendLiteral(")");
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool nsStyleUtil::IsSignificantChild(nsIContent* aChild,
|
|
|
|
bool aWhitespaceIsSignificant) {
|
2018-04-13 01:41:00 +03:00
|
|
|
bool isText = aChild->IsText();
|
2008-02-19 09:17:07 +03:00
|
|
|
|
2018-04-15 16:04:07 +03:00
|
|
|
if (!isText && !aChild->IsComment() && !aChild->IsProcessingInstruction()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-02-19 09:17:07 +03:00
|
|
|
}
|
|
|
|
|
2018-02-28 04:54:01 +03:00
|
|
|
return isText && aChild->TextLength() != 0 &&
|
2008-02-19 09:17:07 +03:00
|
|
|
(aWhitespaceIsSignificant || !aChild->TextIsOnlyWhitespace());
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool nsStyleUtil::ThreadSafeIsSignificantChild(const nsIContent* aChild,
|
|
|
|
bool aWhitespaceIsSignificant) {
|
2018-04-13 01:41:00 +03:00
|
|
|
bool isText = aChild->IsText();
|
2017-03-17 00:10:22 +03:00
|
|
|
|
2018-04-15 16:04:07 +03:00
|
|
|
if (!isText && !aChild->IsComment() && !aChild->IsProcessingInstruction()) {
|
2017-03-17 00:10:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-28 04:54:01 +03:00
|
|
|
return isText && aChild->TextLength() != 0 &&
|
2017-03-17 00:10:22 +03:00
|
|
|
(aWhitespaceIsSignificant ||
|
|
|
|
!aChild->ThreadSafeTextIsOnlyWhitespace());
|
|
|
|
}
|
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
// For a replaced element whose concrete object size is no larger than the
|
|
|
|
// element's content-box, this method checks whether the given
|
|
|
|
// "object-position" coordinate might cause overflow in its dimension.
|
2016-08-25 12:59:51 +03:00
|
|
|
static bool ObjectPositionCoordMightCauseOverflow(
|
2019-02-12 23:45:29 +03:00
|
|
|
const LengthPercentage& aCoord) {
|
2014-11-15 03:45:23 +03:00
|
|
|
// Any nonzero length in "object-position" can push us to overflow
|
|
|
|
// (particularly if our concrete object size is exactly the same size as the
|
|
|
|
// replaced element's content-box).
|
2019-02-12 23:45:29 +03:00
|
|
|
if (aCoord.LengthInCSSPixels() != 0.) {
|
2014-11-15 03:45:23 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Percentages are interpreted as a fraction of the extra space. So,
|
|
|
|
// percentages in the 0-100% range are safe, but values outside of that
|
|
|
|
// range could cause overflow.
|
2019-02-12 23:45:29 +03:00
|
|
|
if (aCoord.HasPercent() &&
|
|
|
|
(aCoord.Percentage() < 0.0f || aCoord.Percentage() > 1.0f)) {
|
2014-11-15 03:45:23 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool nsStyleUtil::ObjectPropsMightCauseOverflow(
|
2014-11-15 03:45:23 +03:00
|
|
|
const nsStylePosition* aStylePos) {
|
|
|
|
auto objectFit = aStylePos->mObjectFit;
|
|
|
|
|
|
|
|
// "object-fit: cover" & "object-fit: none" can give us a render rect that's
|
|
|
|
// larger than our container element's content-box.
|
|
|
|
if (objectFit == NS_STYLE_OBJECT_FIT_COVER ||
|
|
|
|
objectFit == NS_STYLE_OBJECT_FIT_NONE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// (All other object-fit values produce a concrete object size that's no
|
|
|
|
// larger than the constraint region.)
|
|
|
|
|
|
|
|
// Check each of our "object-position" coords to see if it could cause
|
|
|
|
// overflow in its dimension:
|
2016-08-25 12:59:51 +03:00
|
|
|
const Position& objectPosistion = aStylePos->mObjectPosition;
|
2019-02-12 23:45:29 +03:00
|
|
|
if (ObjectPositionCoordMightCauseOverflow(objectPosistion.horizontal) ||
|
|
|
|
ObjectPositionCoordMightCauseOverflow(objectPosistion.vertical)) {
|
2014-11-15 03:45:23 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
2019-05-22 02:14:27 +03:00
|
|
|
bool nsStyleUtil::CSPAllowsInlineStyle(
|
|
|
|
Element* aElement, dom::Document* aDocument,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal, uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber, const nsAString& aStyleText, nsresult* aRv) {
|
2012-08-30 21:58:24 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (aRv) {
|
|
|
|
*aRv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
2019-05-22 02:14:27 +03:00
|
|
|
if (aTriggeringPrincipal && BasePrincipal::Cast(aTriggeringPrincipal)
|
|
|
|
->OverridesCSP(aDocument->NodePrincipal())) {
|
|
|
|
nsCOMPtr<nsIExpandedPrincipal> ep = do_QueryInterface(aTriggeringPrincipal);
|
|
|
|
if (ep) {
|
|
|
|
csp = ep->GetCsp();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
csp = aDocument->GetCsp();
|
2012-08-30 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
2013-11-12 02:25:55 +04:00
|
|
|
if (!csp) {
|
|
|
|
// No CSP --> the style is allowed
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-30 21:58:24 +04:00
|
|
|
|
2015-09-18 08:34:34 +03:00
|
|
|
// query the nonce
|
2013-11-12 02:25:55 +04:00
|
|
|
nsAutoString nonce;
|
2018-07-10 18:40:21 +03:00
|
|
|
if (aElement && aElement->NodeInfo()->NameAtom() == nsGkAtoms::style) {
|
2017-12-07 21:13:50 +03:00
|
|
|
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::nonce, nonce);
|
2013-11-12 02:25:55 +04:00
|
|
|
}
|
2013-11-09 03:44:39 +04:00
|
|
|
|
2015-09-18 08:34:34 +03:00
|
|
|
bool allowInlineStyle = true;
|
|
|
|
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_STYLESHEET, nonce,
|
2016-11-08 14:55:23 +03:00
|
|
|
false, // aParserCreated only applies to scripts
|
2018-10-23 09:17:13 +03:00
|
|
|
aElement, nullptr, // nsICSPEventListener
|
|
|
|
aStyleText, aLineNumber, aColumnNumber,
|
2015-09-18 08:34:34 +03:00
|
|
|
&allowInlineStyle);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2013-11-12 02:25:55 +04:00
|
|
|
|
2015-09-18 08:34:34 +03:00
|
|
|
return allowInlineStyle;
|
2012-08-30 21:58:24 +04:00
|
|
|
}
|
2018-04-23 17:52:20 +03:00
|
|
|
|
|
|
|
void nsStyleUtil::AppendFontSlantStyle(const FontSlantStyle& aStyle,
|
|
|
|
nsAString& aOut) {
|
|
|
|
if (aStyle.IsNormal()) {
|
|
|
|
aOut.AppendLiteral("normal");
|
|
|
|
} else if (aStyle.IsItalic()) {
|
|
|
|
aOut.AppendLiteral("italic");
|
|
|
|
} else {
|
|
|
|
aOut.AppendLiteral("oblique");
|
|
|
|
auto angle = aStyle.ObliqueAngle();
|
|
|
|
if (angle != FontSlantStyle::kDefaultAngle) {
|
|
|
|
aOut.AppendLiteral(" ");
|
2019-06-28 12:46:26 +03:00
|
|
|
AppendCSSNumber(angle, aOut);
|
|
|
|
aOut.AppendLiteral("deg");
|
2018-04-23 17:52:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|