Log Message
Prepare for adding relative color support https://bugs.webkit.org/show_bug.cgi?id=221881
Reviewed by Darin Adler. Source/WebCore: In preparation for adding experimental relative color support a little cleanup is in order. This change: - Threads a CSSParserContext through the color parsing functions. This will be needed to check if the feature is enabled or not. - Does a small cleanup of CSSParserContext, sorting features and using the initialization list in the constructor. - Refactors some of the color parsing helpers to extract more helpers. These clarify the code better and will be shared by the relative parsers. - Move normalization of components to after parsing to avoid unnecessary work in the case of failure and separate the phases a bit more. - Removes some unnecessary ValueRangeAll parameters that were already the default. - Switch HSLA and HWBA to stop storing their components in a 0-1 normalization and instead use values that match the input, 0-360 for hue, and 0-100 for the the remaining two components. This seems more natural, and will simplify future color function work that expects the values in this form. * css/parser/CSSParser.cpp: (WebCore::CSSParser::parseColorWorkerSafe): * css/parser/CSSParserContext.cpp: (WebCore::shouldEnableLegacyOverflowScrollingTouch): (WebCore::CSSParserContext::CSSParserContext): (WebCore::operator==): * css/parser/CSSParserContext.h: (WebCore::CSSParserContextHash::hash): * css/parser/CSSPropertyParser.cpp: (WebCore::consumeShadow): (WebCore::consumeCaretColor): (WebCore::consumeOutlineColor): (WebCore::consumePaintStroke): (WebCore::consumeBackgroundComponent): (WebCore::CSSPropertyParser::parseSingleValue): (WebCore::CSSPropertyParser::consumeBorder): * css/parser/CSSPropertyParserHelpers.cpp: (WebCore::CSSPropertyParserHelpers::consumeOptionalAlpha): (WebCore::CSSPropertyParserHelpers::consumeHue): (WebCore::CSSPropertyParserHelpers::normalizeHue): (WebCore::CSSPropertyParserHelpers::clampRGBComponent): (WebCore::CSSPropertyParserHelpers::parseRGBParameters): (WebCore::CSSPropertyParserHelpers::parseHSLParameters): (WebCore::CSSPropertyParserHelpers::normalizeWhitenessBlackness): (WebCore::CSSPropertyParserHelpers::parseHWBParameters): (WebCore::CSSPropertyParserHelpers::parseLabParameters): (WebCore::CSSPropertyParserHelpers::parseLCHParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes): (WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunction): (WebCore::CSSPropertyParserHelpers::consumeColorWorkerSafe): (WebCore::CSSPropertyParserHelpers::consumeColor): (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientStopColor): (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientColorStop): (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradient): (WebCore::CSSPropertyParserHelpers::consumeGradientColorStops): (WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient): (WebCore::CSSPropertyParserHelpers::consumeRadialGradient): (WebCore::CSSPropertyParserHelpers::consumeLinearGradient): (WebCore::CSSPropertyParserHelpers::consumeConicGradient): (WebCore::CSSPropertyParserHelpers::consumeImageOrNone): (WebCore::CSSPropertyParserHelpers::consumeCrossFade): (WebCore::CSSPropertyParserHelpers::consumeGeneratedImage): (WebCore::CSSPropertyParserHelpers::consumeFilterFunction): (WebCore::CSSPropertyParserHelpers::consumeSingleShadow): (WebCore::CSSPropertyParserHelpers::consumeImage): (WebCore::CSSPropertyParserHelpers::parseOptionalAlpha): Deleted. * css/parser/CSSPropertyParserHelpers.h: (WebCore::CSSPropertyParserHelpers::consumeImage): * editing/cocoa/DataDetection.mm: (WebCore::DataDetection::detectContentInRange): * platform/graphics/ColorConversion.cpp: (WebCore::calculateHSLHue): (WebCore::SRGBA<float>>::convert): (WebCore::HSLA<float>>::convert): (WebCore::HWBA<float>>::convert): * platform/graphics/ColorModels.h: * rendering/RenderTheme.cpp: (WebCore::RenderTheme::datePlaceholderTextColor const): Tools: * TestWebKitAPI/Tests/WebCore/ColorTests.cpp: Update HSLA tests to account for HSLA now using 0-360, 0-100, 0-100 bounds rather than 0-1, 0-1, 0-1.
Modified Paths
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/css/parser/CSSParser.cpp
- trunk/Source/WebCore/css/parser/CSSParserContext.cpp
- trunk/Source/WebCore/css/parser/CSSParserContext.h
- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp
- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h
- trunk/Source/WebCore/editing/cocoa/DataDetection.mm
- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp
- trunk/Source/WebCore/platform/graphics/ColorModels.h
- trunk/Source/WebCore/rendering/RenderTheme.cpp
- trunk/Tools/ChangeLog
- trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp
Diff
Modified: trunk/Source/WebCore/ChangeLog (272869 => 272870)
--- trunk/Source/WebCore/ChangeLog 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/ChangeLog 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1,3 +1,88 @@
+2021-02-15 Sam Weinig <wei...@apple.com>
+
+ Prepare for adding relative color support
+ https://bugs.webkit.org/show_bug.cgi?id=221881
+
+ Reviewed by Darin Adler.
+
+ In preparation for adding experimental relative color support a little cleanup
+ is in order. This change:
+
+ - Threads a CSSParserContext through the color parsing functions. This will be
+ needed to check if the feature is enabled or not.
+ - Does a small cleanup of CSSParserContext, sorting features and using the initialization
+ list in the constructor.
+ - Refactors some of the color parsing helpers to extract more helpers. These clarify
+ the code better and will be shared by the relative parsers.
+ - Move normalization of components to after parsing to avoid unnecessary work
+ in the case of failure and separate the phases a bit more.
+ - Removes some unnecessary ValueRangeAll parameters that were already the default.
+ - Switch HSLA and HWBA to stop storing their components in a 0-1 normalization
+ and instead use values that match the input, 0-360 for hue, and 0-100 for the
+ the remaining two components. This seems more natural, and will simplify
+ future color function work that expects the values in this form.
+
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParser::parseColorWorkerSafe):
+ * css/parser/CSSParserContext.cpp:
+ (WebCore::shouldEnableLegacyOverflowScrollingTouch):
+ (WebCore::CSSParserContext::CSSParserContext):
+ (WebCore::operator==):
+ * css/parser/CSSParserContext.h:
+ (WebCore::CSSParserContextHash::hash):
+ * css/parser/CSSPropertyParser.cpp:
+ (WebCore::consumeShadow):
+ (WebCore::consumeCaretColor):
+ (WebCore::consumeOutlineColor):
+ (WebCore::consumePaintStroke):
+ (WebCore::consumeBackgroundComponent):
+ (WebCore::CSSPropertyParser::parseSingleValue):
+ (WebCore::CSSPropertyParser::consumeBorder):
+ * css/parser/CSSPropertyParserHelpers.cpp:
+ (WebCore::CSSPropertyParserHelpers::consumeOptionalAlpha):
+ (WebCore::CSSPropertyParserHelpers::consumeHue):
+ (WebCore::CSSPropertyParserHelpers::normalizeHue):
+ (WebCore::CSSPropertyParserHelpers::clampRGBComponent):
+ (WebCore::CSSPropertyParserHelpers::parseRGBParameters):
+ (WebCore::CSSPropertyParserHelpers::parseHSLParameters):
+ (WebCore::CSSPropertyParserHelpers::normalizeWhitenessBlackness):
+ (WebCore::CSSPropertyParserHelpers::parseHWBParameters):
+ (WebCore::CSSPropertyParserHelpers::parseLabParameters):
+ (WebCore::CSSPropertyParserHelpers::parseLCHParameters):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZParameters):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunction):
+ (WebCore::CSSPropertyParserHelpers::consumeColorWorkerSafe):
+ (WebCore::CSSPropertyParserHelpers::consumeColor):
+ (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientStopColor):
+ (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradientColorStop):
+ (WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradient):
+ (WebCore::CSSPropertyParserHelpers::consumeGradientColorStops):
+ (WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient):
+ (WebCore::CSSPropertyParserHelpers::consumeRadialGradient):
+ (WebCore::CSSPropertyParserHelpers::consumeLinearGradient):
+ (WebCore::CSSPropertyParserHelpers::consumeConicGradient):
+ (WebCore::CSSPropertyParserHelpers::consumeImageOrNone):
+ (WebCore::CSSPropertyParserHelpers::consumeCrossFade):
+ (WebCore::CSSPropertyParserHelpers::consumeGeneratedImage):
+ (WebCore::CSSPropertyParserHelpers::consumeFilterFunction):
+ (WebCore::CSSPropertyParserHelpers::consumeSingleShadow):
+ (WebCore::CSSPropertyParserHelpers::consumeImage):
+ (WebCore::CSSPropertyParserHelpers::parseOptionalAlpha): Deleted.
+ * css/parser/CSSPropertyParserHelpers.h:
+ (WebCore::CSSPropertyParserHelpers::consumeImage):
+ * editing/cocoa/DataDetection.mm:
+ (WebCore::DataDetection::detectContentInRange):
+ * platform/graphics/ColorConversion.cpp:
+ (WebCore::calculateHSLHue):
+ (WebCore::SRGBA<float>>::convert):
+ (WebCore::HSLA<float>>::convert):
+ (WebCore::HWBA<float>>::convert):
+ * platform/graphics/ColorModels.h:
+ * rendering/RenderTheme.cpp:
+ (WebCore::RenderTheme::datePlaceholderTextColor const):
+
2021-02-15 Antoine Quint <grao...@webkit.org>
Getting the computed style should resolve animations using the last style change event style
Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSParser.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -117,7 +117,7 @@
CSSParserTokenRange range(tokenizer.tokenRange());
range.consumeWhitespace();
- return CSSPropertyParserHelpers::consumeColorWorkerSafe(range, HTMLStandardMode);
+ return CSSPropertyParserHelpers::consumeColorWorkerSafe(range, strictCSSParserContext());
}
Color CSSParser::parseSystemColor(StringView string)
Modified: trunk/Source/WebCore/css/parser/CSSParserContext.cpp (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSParserContext.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -47,39 +47,46 @@
{
}
-CSSParserContext::CSSParserContext(const Document& document, const URL& sheetBaseURL, const String& charset)
- : baseURL(sheetBaseURL.isNull() ? document.baseURL() : sheetBaseURL)
- , charset(charset)
- , mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode)
- , isHTMLDocument(document.isHTMLDocument())
- , hasDocumentSecurityOrigin(sheetBaseURL.isNull() || document.securityOrigin().canRequest(baseURL))
+#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
+static bool shouldEnableLegacyOverflowScrollingTouch(const Document& document)
{
- enforcesCSSMIMETypeInNoQuirksMode = document.settings().enforceCSSMIMETypeInNoQuirksMode();
- useLegacyBackgroundSizeShorthandBehavior = document.settings().useLegacyBackgroundSizeShorthandBehavior();
-#if ENABLE(TEXT_AUTOSIZING)
- textAutosizingEnabled = document.settings().textAutosizingEnabled();
-#endif
-#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
- legacyOverflowScrollingTouchEnabled = document.settings().legacyOverflowScrollingTouchEnabled();
// The legacy -webkit-overflow-scrolling: touch behavior may have been disabled through the website policy,
// in that case we want to disable the legacy behavior regardless of what the setting says.
if (auto* loader = document.loader()) {
if (loader->legacyOverflowScrollingTouchPolicy() == LegacyOverflowScrollingTouchPolicy::Disable)
- legacyOverflowScrollingTouchEnabled = false;
+ return false;
}
+ return document.settings().legacyOverflowScrollingTouchEnabled();
+}
#endif
- springTimingFunctionEnabled = document.settings().springTimingFunctionEnabled();
- constantPropertiesEnabled = document.settings().constantPropertiesEnabled();
- colorFilterEnabled = document.settings().colorFilterEnabled();
+
+CSSParserContext::CSSParserContext(const Document& document, const URL& sheetBaseURL, const String& charset)
+ : baseURL { sheetBaseURL.isNull() ? document.baseURL() : sheetBaseURL }
+ , charset { charset }
+ , mode { document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode }
+ , isHTMLDocument { document.isHTMLDocument() }
+ , hasDocumentSecurityOrigin { sheetBaseURL.isNull() || document.securityOrigin().canRequest(baseURL) }
+ , useSystemAppearance { document.page() ? document.page()->useSystemAppearance() : false }
+ , aspectRatioEnabled { document.settings().aspectRatioEnabled() }
+ , colorFilterEnabled { document.settings().colorFilterEnabled() }
+ , constantPropertiesEnabled { document.settings().constantPropertiesEnabled() }
+ , deferredCSSParserEnabled { document.settings().deferredCSSParserEnabled() }
+ , enforcesCSSMIMETypeInNoQuirksMode { document.settings().enforceCSSMIMETypeInNoQuirksMode() }
+ , individualTransformPropertiesEnabled { document.settings().cssIndividualTransformPropertiesEnabled() }
+#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
+ , legacyOverflowScrollingTouchEnabled { shouldEnableLegacyOverflowScrollingTouch(document) }
+#endif
+ , overscrollBehaviorEnabled { document.settings().overscrollBehaviorEnabled() }
+ , scrollBehaviorEnabled { document.settings().CSSOMViewSmoothScrollingEnabled() }
+ , springTimingFunctionEnabled { document.settings().springTimingFunctionEnabled() }
+#if ENABLE(TEXT_AUTOSIZING)
+ , textAutosizingEnabled { document.settings().textAutosizingEnabled() }
+#endif
+ , useLegacyBackgroundSizeShorthandBehavior { document.settings().useLegacyBackgroundSizeShorthandBehavior() }
#if ENABLE(ATTACHMENT_ELEMENT)
- attachmentEnabled = RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled();
+ , attachmentEnabled { RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() }
#endif
- deferredCSSParserEnabled = document.settings().deferredCSSParserEnabled();
- scrollBehaviorEnabled = document.settings().CSSOMViewSmoothScrollingEnabled();
- overscrollBehaviorEnabled = document.settings().overscrollBehaviorEnabled();
- useSystemAppearance = document.page() ? document.page()->useSystemAppearance() : false;
- individualTransformPropertiesEnabled = document.settings().cssIndividualTransformPropertiesEnabled();
- aspectRatioEnabled = document.settings().aspectRatioEnabled();
+{
}
bool operator==(const CSSParserContext& a, const CSSParserContext& b)
@@ -87,28 +94,31 @@
return a.baseURL == b.baseURL
&& a.charset == b.charset
&& a.mode == b.mode
+ && a.enclosingRuleType == b.enclosingRuleType
&& a.isHTMLDocument == b.isHTMLDocument
+ && a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin
+ && a.isContentOpaque == b.isContentOpaque
+ && a.useSystemAppearance == b.useSystemAppearance
+ && a.aspectRatioEnabled == b.aspectRatioEnabled
+ && a.colorFilterEnabled == b.colorFilterEnabled
+ && a.constantPropertiesEnabled == b.constantPropertiesEnabled
+ && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled
+ && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
+ && a.individualTransformPropertiesEnabled == b.individualTransformPropertiesEnabled
+#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
+ && a.legacyOverflowScrollingTouchEnabled == b.legacyOverflowScrollingTouchEnabled
+#endif
+ && a.overscrollBehaviorEnabled == b.overscrollBehaviorEnabled
+ && a.scrollBehaviorEnabled == b.scrollBehaviorEnabled
+ && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
#if ENABLE(TEXT_AUTOSIZING)
&& a.textAutosizingEnabled == b.textAutosizingEnabled
#endif
-#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
- && a.legacyOverflowScrollingTouchEnabled == b.legacyOverflowScrollingTouchEnabled
-#endif
- && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
&& a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior
- && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
- && a.constantPropertiesEnabled == b.constantPropertiesEnabled
- && a.colorFilterEnabled == b.colorFilterEnabled
#if ENABLE(ATTACHMENT_ELEMENT)
&& a.attachmentEnabled == b.attachmentEnabled
#endif
- && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled
- && a.scrollBehaviorEnabled == b.scrollBehaviorEnabled
- && a.individualTransformPropertiesEnabled == b.individualTransformPropertiesEnabled
- && a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin
- && a.useSystemAppearance == b.useSystemAppearance
- && a.aspectRatioEnabled == b.aspectRatioEnabled
- && a.overscrollBehaviorEnabled == b.overscrollBehaviorEnabled;
+ ;
}
URL CSSParserContext::completeURL(const String& url) const
Modified: trunk/Source/WebCore/css/parser/CSSParserContext.h (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSParserContext.h 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSParserContext.h 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,7 +41,6 @@
struct CSSParserContext {
WTF_MAKE_FAST_ALLOCATED;
public:
-
CSSParserContext(CSSParserMode, const URL& baseURL = URL());
WEBCORE_EXPORT CSSParserContext(const Document&, const URL& baseURL = URL(), const String& charset = emptyString());
@@ -50,36 +49,37 @@
CSSParserMode mode { HTMLStandardMode };
Optional<StyleRuleType> enclosingRuleType;
bool isHTMLDocument { false };
+
+ // This is only needed to support getMatchedCSSRules.
+ bool hasDocumentSecurityOrigin { false };
+
+ bool isContentOpaque { false };
+ bool useSystemAppearance { false };
+
+ // Settings.
+ bool aspectRatioEnabled { false };
+ bool colorFilterEnabled { false };
+ bool constantPropertiesEnabled { false };
+ bool deferredCSSParserEnabled { false };
+ bool enforcesCSSMIMETypeInNoQuirksMode { true };
+ bool individualTransformPropertiesEnabled { false };
+#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
+ bool legacyOverflowScrollingTouchEnabled { false };
+#endif
+ bool overscrollBehaviorEnabled { false };
+ bool scrollBehaviorEnabled { false };
+ bool springTimingFunctionEnabled { false };
#if ENABLE(TEXT_AUTOSIZING)
bool textAutosizingEnabled { false };
#endif
-#if ENABLE(OVERFLOW_SCROLLING_TOUCH)
- bool legacyOverflowScrollingTouchEnabled { false };
-#endif
- bool enforcesCSSMIMETypeInNoQuirksMode { true };
bool useLegacyBackgroundSizeShorthandBehavior { false };
- bool springTimingFunctionEnabled { false };
- bool constantPropertiesEnabled { false };
- bool colorFilterEnabled { false };
+
+ // RuntimeEnabledFeatures.
#if ENABLE(ATTACHMENT_ELEMENT)
bool attachmentEnabled { false };
#endif
- bool deferredCSSParserEnabled { false };
- bool scrollBehaviorEnabled { false };
- bool individualTransformPropertiesEnabled { false };
- bool overscrollBehaviorEnabled { false };
-
- // This is only needed to support getMatchedCSSRules.
- bool hasDocumentSecurityOrigin { false };
-
- bool useSystemAppearance { false };
-
URL completeURL(const String& url) const;
-
- bool isContentOpaque { false };
-
- bool aspectRatioEnabled { false };
};
bool operator==(const CSSParserContext&, const CSSParserContext&);
@@ -90,6 +90,8 @@
struct CSSParserContextHash {
static unsigned hash(const CSSParserContext& key)
{
+ // FIXME: Convert this to use WTF::Hasher.
+
unsigned hash = 0;
if (!key.baseURL.isNull())
hash ^= WTF::URLHash::hash(key.baseURL);
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1726,7 +1726,7 @@
return consumeInteger(range);
}
-static RefPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool isBoxShadowProperty)
+static RefPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, const CSSParserContext& context, bool isBoxShadowProperty)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
@@ -1733,8 +1733,8 @@
RefPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
do {
- if (RefPtr<CSSShadowValue> shadowValue = consumeSingleShadow(range, cssParserMode, isBoxShadowProperty, isBoxShadowProperty))
- shadowValueList->append(*shadowValue);
+ if (auto shadowValue = consumeSingleShadow(range, context, isBoxShadowProperty, isBoxShadowProperty))
+ shadowValueList->append(shadowValue.releaseNonNull());
else
return nullptr;
} while (consumeCommaIncludingWhitespace(range));
@@ -1813,19 +1813,19 @@
return nullptr;
}
-static RefPtr<CSSPrimitiveValue> consumeCaretColor(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static RefPtr<CSSPrimitiveValue> consumeCaretColor(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
- return consumeColor(range, cssParserMode);
+ return consumeColor(range, context);
}
-static RefPtr<CSSValue> consumeOutlineColor(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static RefPtr<CSSValue> consumeOutlineColor(CSSParserTokenRange& range, const CSSParserContext& context)
{
// Allow the special focus color even in HTML Standard parsing mode.
if (range.peek().id() == CSSValueWebkitFocusRingColor)
return consumeIdent(range);
- return consumeColor(range, cssParserMode);
+ return consumeColor(range, context);
}
static RefPtr<CSSPrimitiveValue> consumeLineWidth(CSSParserTokenRange& range, CSSParserMode cssParserMode, UnitlessQuirk unitless)
@@ -2228,7 +2228,7 @@
return consumePositionLonghand<CSSValueTop, CSSValueBottom>(range, cssParserMode);
}
-static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static RefPtr<CSSValue> consumePaintStroke(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
@@ -2238,7 +2238,7 @@
if (range.peek().id() == CSSValueNone)
parsedValue = consumeIdent(range);
else
- parsedValue = consumeColor(range, cssParserMode);
+ parsedValue = consumeColor(range, context);
if (parsedValue) {
RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
values->append(url.releaseNonNull());
@@ -2247,7 +2247,7 @@
}
return url;
}
- return consumeColor(range, cssParserMode);
+ return consumeColor(range, context);
}
static RefPtr<CSSValue> consumeGlyphOrientation(CSSParserTokenRange& range, CSSParserMode mode, CSSPropertyID property)
@@ -3258,7 +3258,7 @@
case CSSPropertyWebkitMaskSize:
return consumeBackgroundSize(property, range, context.mode);
case CSSPropertyBackgroundColor:
- return consumeColor(range, context.mode);
+ return consumeColor(range, context);
default:
break;
};
@@ -4241,7 +4241,7 @@
case CSSPropertyWidows:
return consumePositiveInteger(m_range);
case CSSPropertyTextDecorationColor:
- return consumeColor(m_range, m_context.mode);
+ return consumeColor(m_range, m_context);
case CSSPropertyTextDecorationSkip:
return consumeTextDecorationSkip(m_range);
case CSSPropertyWebkitTextStrokeWidth:
@@ -4261,12 +4261,12 @@
case CSSPropertyFloodColor:
case CSSPropertyLightingColor:
case CSSPropertyColumnRuleColor:
- return consumeColor(m_range, m_context.mode);
+ return consumeColor(m_range, m_context);
case CSSPropertyCaretColor:
- return consumeCaretColor(m_range, m_context.mode);
+ return consumeCaretColor(m_range, m_context);
case CSSPropertyColor:
case CSSPropertyBackgroundColor:
- return consumeColor(m_range, m_context.mode, inQuirksMode());
+ return consumeColor(m_range, m_context, inQuirksMode());
case CSSPropertyBorderInlineStartWidth:
case CSSPropertyBorderInlineEndWidth:
case CSSPropertyBorderBlockStartWidth:
@@ -4278,7 +4278,7 @@
case CSSPropertyBorderTopColor: {
bool allowQuirkyColors = inQuirksMode()
&& (currentShorthand == CSSPropertyInvalid || currentShorthand == CSSPropertyBorderColor);
- return consumeColor(m_range, m_context.mode, allowQuirkyColors);
+ return consumeColor(m_range, m_context, allowQuirkyColors);
}
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth:
@@ -4294,7 +4294,7 @@
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
case CSSPropertyBoxShadow:
case CSSPropertyWebkitBoxShadow:
- return consumeShadow(m_range, m_context.mode, property == CSSPropertyBoxShadow || property == CSSPropertyWebkitBoxShadow);
+ return consumeShadow(m_range, m_context, property == CSSPropertyBoxShadow || property == CSSPropertyWebkitBoxShadow);
case CSSPropertyFilter:
#if ENABLE(FILTERS_LEVEL_2)
case CSSPropertyWebkitBackdropFilter:
@@ -4342,7 +4342,7 @@
return consumeRotate(m_range, m_context.mode);
case CSSPropertyFill:
case CSSPropertyStroke:
- return consumePaintStroke(m_range, m_context.mode);
+ return consumePaintStroke(m_range, m_context);
case CSSPropertyGlyphOrientationVertical:
case CSSPropertyGlyphOrientationHorizontal:
return consumeGlyphOrientation(m_range, m_context.mode, property);
@@ -5093,7 +5093,7 @@
continue;
}
if (!color) {
- color = consumeColor(m_range, m_context.mode);
+ color = consumeColor(m_range, m_context);
if (color)
continue;
}
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -690,167 +690,205 @@
return CSSValuePool::singleton().createValue(url.toString(), CSSUnitType::CSS_URI);
}
-static uint8_t clampRGBComponent(double value, bool isPercentage)
+static Optional<double> consumeOptionalAlpha(CSSParserTokenRange& range)
{
- if (isPercentage)
+ if (!consumeSlashIncludingWhitespace(range))
+ return 1.0;
+
+ if (auto alphaParameter = consumeNumberOrPercentDividedBy100Raw(range))
+ return clampTo(*alphaParameter, 0.0, 1.0);
+
+ return WTF::nullopt;
+}
+
+static Optional<double> consumeHue(CSSParserTokenRange& range, const CSSParserContext& context)
+{
+ if (auto angle = consumeAngleRaw(range, context.mode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Forbid))
+ return CSSPrimitiveValue::computeDegrees(angle->type, angle->value);
+
+ return consumeNumberRaw(range);
+}
+
+static double normalizeHue(double hue)
+{
+ return std::fmod(std::fmod(hue, 360.0) + 360.0, 360.0);
+}
+
+enum class RGBComponentType { Number, Percentage };
+
+static uint8_t clampRGBComponent(double value, RGBComponentType componentType)
+{
+ if (componentType == RGBComponentType::Percentage)
value = value / 100.0 * 255.0;
return convertPrescaledSRGBAFloatToSRGBAByte(value);
}
-static Color parseRGBParameters(CSSParserTokenRange& range)
+enum class RGBOrHSLSeparatorSyntax { Commas, WhitespaceSlash };
+
+static bool consumeRGBOrHSLSeparator(CSSParserTokenRange& args, RGBOrHSLSeparatorSyntax syntax)
{
+ if (syntax == RGBOrHSLSeparatorSyntax::Commas)
+ return consumeCommaIncludingWhitespace(args);
+ return true;
+}
+
+static bool consumeRGBOrHSLAlphaSeparator(CSSParserTokenRange& args, RGBOrHSLSeparatorSyntax syntax)
+{
+ if (syntax == RGBOrHSLSeparatorSyntax::Commas)
+ return consumeCommaIncludingWhitespace(args);
+ return consumeSlashIncludingWhitespace(args);
+}
+
+static Optional<double> consumeRGBOrHSLOptionalAlpha(CSSParserTokenRange& args, RGBOrHSLSeparatorSyntax syntax)
+{
+ if (!consumeRGBOrHSLAlphaSeparator(args, syntax))
+ return 1.0;
+
+ return consumeNumberOrPercentDividedBy100Raw(args);
+}
+
+static Color parseRGBParameters(CSSParserTokenRange& range, const CSSParserContext&)
+{
ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);
auto args = consumeFunction(range);
- bool isPercentage = false;
- double colorParameter;
- if (auto number = consumeNumberRaw(args))
- colorParameter = *number;
- else if (auto percent = consumePercentRaw(args)) {
- colorParameter = *percent;
- isPercentage = true;
- } else
- return { };
+ struct InitialComponent {
+ double value;
+ RGBComponentType type;
+ };
- enum class ColorSyntax {
- Commas,
- WhitespaceSlash,
+ auto consumeInitialComponent = [](auto& args) -> Optional<InitialComponent> {
+ if (auto number = consumeNumberRaw(args))
+ return { { *number, RGBComponentType::Number } };
+ if (auto percent = consumePercentRaw(args))
+ return { { *percent, RGBComponentType::Percentage } };
+ return WTF::nullopt;
};
- ColorSyntax syntax = ColorSyntax::Commas;
- auto consumeSeparator = [&] {
- if (syntax == ColorSyntax::Commas)
- return consumeCommaIncludingWhitespace(args);
-
- return true;
+ auto consumeComponent = [](auto& args, auto componentType) {
+ switch (componentType) {
+ case RGBComponentType::Percentage:
+ return consumePercentRaw(args);
+ case RGBComponentType::Number:
+ return consumeNumberRaw(args);
+ }
};
- uint8_t colorArray[3];
- colorArray[0] = clampRGBComponent(colorParameter, isPercentage);
- for (int i = 1; i < 3; i++) {
- if (i == 1)
- syntax = consumeCommaIncludingWhitespace(args) ? ColorSyntax::Commas : ColorSyntax::WhitespaceSlash;
- else if (!consumeSeparator())
- return { };
+ auto initialComponent = consumeInitialComponent(args);
+ if (!initialComponent)
+ return { };
- if (isPercentage) {
- auto percent = consumePercentRaw(args);
- if (!percent)
- return { };
- colorArray[i] = clampRGBComponent(*percent, true);
- } else {
- auto number = consumeNumberRaw(args);
- if (!number)
- return { };
- colorArray[i] = clampRGBComponent(*number, false);
- }
- }
+ auto componentType = initialComponent->type;
+ auto red = initialComponent->value;
- // Historically, alpha was only parsed for rgba(), but css-color-4 specifies that rgba() is a simple alias for rgb().
- auto consumeAlphaSeparator = [&] {
- if (syntax == ColorSyntax::Commas)
- return consumeCommaIncludingWhitespace(args);
-
- return consumeSlashIncludingWhitespace(args);
- };
+ auto syntax = consumeCommaIncludingWhitespace(args) ? RGBOrHSLSeparatorSyntax::Commas : RGBOrHSLSeparatorSyntax::WhitespaceSlash;
+
+ auto green = consumeComponent(args, componentType);
+ if (!green)
+ return { };
- uint8_t alphaComponent = 255;
- if (consumeAlphaSeparator()) {
- auto alpha = consumeNumberOrPercentDividedBy100Raw(args);
- if (!alpha)
- return { };
- alphaComponent = convertFloatAlphaTo<uint8_t>(*alpha);
- }
+ if (!consumeRGBOrHSLSeparator(args, syntax))
+ return { };
+ auto blue = consumeComponent(args, componentType);
+ if (!blue)
+ return { };
+
+ auto alpha = consumeRGBOrHSLOptionalAlpha(args, syntax);
+ if (!alpha)
+ return { };
+
if (!args.atEnd())
return { };
- return SRGBA<uint8_t> { colorArray[0], colorArray[1], colorArray[2], alphaComponent };
+ auto normalizedRed = clampRGBComponent(red, componentType);
+ auto normalizedGreen = clampRGBComponent(*green, componentType);
+ auto normalizedBlue = clampRGBComponent(*blue, componentType);
+ auto normalizedAlpha = convertFloatAlphaTo<uint8_t>(*alpha);
+
+ return SRGBA<uint8_t> { normalizedRed, normalizedGreen, normalizedBlue, normalizedAlpha };
}
-static Color parseHSLParameters(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static Color parseHSLParameters(CSSParserTokenRange& range, const CSSParserContext& context)
{
ASSERT(range.peek().functionId() == CSSValueHsl || range.peek().functionId() == CSSValueHsla);
auto args = consumeFunction(range);
- double hueAngleInDegrees;
- if (auto angle = consumeAngleRaw(args, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Forbid))
- hueAngleInDegrees = CSSPrimitiveValue::computeDegrees(angle->type, angle->value);
- else if (auto number = consumeNumberRaw(args))
- hueAngleInDegrees = *number;
- else
+ auto hue = consumeHue(args, context);
+ if (!hue)
return { };
- double colorArray[3];
- colorArray[0] = fmod(fmod(hueAngleInDegrees, 360.0) + 360.0, 360.0) / 360.0;
+ auto syntax = consumeCommaIncludingWhitespace(args) ? RGBOrHSLSeparatorSyntax::Commas : RGBOrHSLSeparatorSyntax::WhitespaceSlash;
- bool requiresCommas = false;
- for (int i = 1; i < 3; i++) {
- if (consumeCommaIncludingWhitespace(args)) {
- if (i != 1 && !requiresCommas)
- return { };
- requiresCommas = true;
- } else if (requiresCommas || args.atEnd() || (&args.peek() - 1)->type() != WhitespaceToken)
- return { };
- auto percent = consumePercentRaw(args);
- if (!percent)
- return { };
- colorArray[i] = clampTo<double>(*percent, 0.0, 100.0) / 100.0; // Needs to be value between 0 and 1.0.
- }
+ auto saturation = consumePercentRaw(args);
+ if (!saturation)
+ return { };
- bool commaConsumed = consumeCommaIncludingWhitespace(args);
- bool slashConsumed = consumeSlashIncludingWhitespace(args);
- if ((commaConsumed && !requiresCommas) || (slashConsumed && requiresCommas))
+ if (!consumeRGBOrHSLSeparator(args, syntax))
return { };
- double alpha = 1.0;
- if (commaConsumed || slashConsumed) {
- auto alphaParameter = consumeNumberOrPercentDividedBy100Raw(args);
- if (!alphaParameter)
- return { };
- alpha = clampTo<double>(*alphaParameter, 0.0, 1.0);
- }
+ auto lightness = consumePercentRaw(args);
+ if (!lightness)
+ return { };
+ auto alpha = consumeRGBOrHSLOptionalAlpha(args, syntax);
+ if (!alpha)
+ return { };
+
if (!args.atEnd())
return { };
- return convertColor<SRGBA<uint8_t>>(HSLA<float> { static_cast<float>(colorArray[0]), static_cast<float>(colorArray[1]), static_cast<float>(colorArray[2]), static_cast<float>(alpha) });
+ auto normalizedHue = normalizeHue(*hue);
+ auto normalizedSaturation = clampTo<double>(*saturation, 0.0, 100.0);
+ auto normalizedLightness = clampTo<double>(*lightness, 0.0, 100.0);
+ auto normalizedAlpha = clampTo<double>(*alpha, 0.0, 1.0);
+
+ return convertColor<SRGBA<uint8_t>>(HSLA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedSaturation), static_cast<float>(normalizedLightness), static_cast<float>(normalizedAlpha) });
}
-static Optional<float> parseOptionalAlpha(CSSParserTokenRange& range)
+struct WhitenessBlackness {
+ double whiteness;
+ double blackness;
+};
+static WhitenessBlackness normalizeWhitenessBlackness(double whiteness, double blackness)
{
- if (!consumeSlashIncludingWhitespace(range))
- return 1.0f;
+ WhitenessBlackness result;
- if (auto alphaParameter = consumeNumberOrPercentDividedBy100Raw(range))
- return clampTo<float>(*alphaParameter, 0.0, 1.0);
+ // Values outside of these ranges are not invalid, but are clamped to the
+ // ranges defined here at computed-value time.
+ result.whiteness = clampTo<double>(whiteness, 0, 100);
+ result.blackness = clampTo<double>(blackness, 0, 100);
- return WTF::nullopt;
+ // If the sum of these two arguments is greater than 100%, then at
+ // computed-value time they are further normalized to add up to 100%, with
+ // the same relative ratio.
+ if (auto sum = result.whiteness + result.blackness; sum >= 100) {
+ result.whiteness *= 100.0 / sum;
+ result.blackness *= 100.0 / sum;
+ }
+
+ return result;
}
-static Color parseHWBParameters(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static Color parseHWBParameters(CSSParserTokenRange& range, const CSSParserContext& context)
{
ASSERT(range.peek().functionId() == CSSValueHwb);
auto args = consumeFunction(range);
- double hueAngleInDegrees;
- if (auto angle = consumeAngleRaw(args, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Forbid))
- hueAngleInDegrees = CSSPrimitiveValue::computeDegrees(angle->type, angle->value);
- else if (auto number = consumeNumberRaw(args))
- hueAngleInDegrees = *number;
- else
+ auto hue = consumeHue(args, context);
+ if (!hue)
return { };
- auto whiteness = consumePercentRaw(args, ValueRangeAll);
+ auto whiteness = consumePercentRaw(args);
if (!whiteness)
return { };
- auto blackness = consumePercentRaw(args, ValueRangeAll);
+ auto blackness = consumePercentRaw(args);
if (!blackness)
return { };
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
@@ -857,55 +895,30 @@
if (!args.atEnd())
return { };
- // Normalize hue.
+ auto normalizedHue = normalizeHue(*hue);
+ auto [normalizedWhitness, normalizedBlackness] = normalizeWhitenessBlackness(*whiteness, *blackness);
- hueAngleInDegrees = std::fmod(hueAngleInDegrees, 360.0);
- if (hueAngleInDegrees < 0.0)
- hueAngleInDegrees += 360.0;
-
- // Convert angle to normalized form from 0 - 1.
- auto normalizedHue = hueAngleInDegrees / 360.0;
-
- // Normalize whiteness/blackness.
-
- // Values outside of these ranges are not invalid, but are clamped to the
- // ranges defined here at computed-value time.
- auto nomalizedWhiteness = clampTo<double>(*whiteness, 0, 100);
- auto nomalizedBlackness = clampTo<double>(*blackness, 0, 100);
-
- // If the sum of these two arguments is greater than 100%, then at
- // computed-value time they are further normalized to add up to 100%, with
- // the same relative ratio.
- if (auto sum = nomalizedWhiteness + nomalizedBlackness; sum >= 100) {
- nomalizedWhiteness *= 100.0 / sum;
- nomalizedBlackness *= 100.0 / sum;
- }
-
- // Convert to normalized form from 0 - 1.
- nomalizedWhiteness /= 100.0;
- nomalizedBlackness /= 100.0;
-
- return convertColor<SRGBA<uint8_t>>(HWBA<float> { static_cast<float>(normalizedHue), static_cast<float>(nomalizedWhiteness), static_cast<float>(nomalizedBlackness), static_cast<float>(*alpha) });
+ return convertColor<SRGBA<uint8_t>>(HWBA<float> { static_cast<float>(normalizedHue), static_cast<float>(normalizedWhitness), static_cast<float>(normalizedBlackness), static_cast<float>(*alpha) });
}
-static Color parseLabParameters(CSSParserTokenRange& range)
+static Color parseLabParameters(CSSParserTokenRange& range, const CSSParserContext&)
{
ASSERT(range.peek().functionId() == CSSValueLab);
auto args = consumeFunction(range);
- auto lightness = consumePercentRaw(args, ValueRangeAll);
+ auto lightness = consumePercentRaw(args);
if (!lightness)
return { };
- auto aValue = consumeNumberRaw(args, ValueRangeAll);
+ auto aValue = consumeNumberRaw(args);
if (!aValue)
return { };
- auto bValue = consumeNumberRaw(args, ValueRangeAll);
+ auto bValue = consumeNumberRaw(args);
if (!bValue)
return { };
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
@@ -912,35 +925,27 @@
if (!args.atEnd())
return { };
- return Lab<float> { static_cast<float>(*lightness), static_cast<float>(*aValue), static_cast<float>(*bValue), *alpha };
+ return Lab<float> { static_cast<float>(*lightness), static_cast<float>(*aValue), static_cast<float>(*bValue), static_cast<float>(*alpha) };
}
-static Color parseLCHParameters(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static Color parseLCHParameters(CSSParserTokenRange& range, const CSSParserContext& context)
{
ASSERT(range.peek().functionId() == CSSValueLch);
auto args = consumeFunction(range);
- auto lightness = consumePercentRaw(args, ValueRangeAll);
+ auto lightness = consumePercentRaw(args);
if (!lightness)
return { };
- auto chromaValue = consumeNumberRaw(args, ValueRangeAll);
- if (!chromaValue)
+ auto chroma = consumeNumberRaw(args);
+ if (!chroma)
return { };
- double hueAngleInDegrees;
- if (auto angle = consumeAngleRaw(args, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Forbid))
- hueAngleInDegrees = CSSPrimitiveValue::computeDegrees(angle->type, angle->value);
- else if (auto number = consumeNumberRaw(args, ValueRangeAll))
- hueAngleInDegrees = *number;
- else
+ auto hue = consumeHue(args, context);
+ if (!hue)
return { };
- hueAngleInDegrees = fmod(hueAngleInDegrees, 360.0);
- if (hueAngleInDegrees < 0.0)
- hueAngleInDegrees += 360.0;
-
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
@@ -947,11 +952,12 @@
if (!args.atEnd())
return { };
- return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(*lightness), static_cast<float>(*chromaValue), static_cast<float>(hueAngleInDegrees), *alpha });
+ auto normalizedHue = normalizeHue(*hue);
+
+ return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(*lightness), static_cast<float>(*chroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) });
}
-template<typename ColorType>
-static Color parseColorFunctionForRGBTypes(CSSParserTokenRange& args)
+template<typename ColorType> static Color parseColorFunctionForRGBTypes(CSSParserTokenRange& args)
{
ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB);
consumeIdentRaw(args);
@@ -964,11 +970,11 @@
channels[i] = *value;
}
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
- return ColorType { clampTo<float>(channels[0], 0.0, 1.0), clampTo<float>(channels[1], 0.0, 1.0), clampTo<float>(channels[2], 0.0, 1.0), *alpha };
+ return ColorType { clampTo<float>(channels[0], 0.0, 1.0), clampTo<float>(channels[1], 0.0, 1.0), clampTo<float>(channels[2], 0.0, 1.0), static_cast<float>(*alpha) };
}
static Color parseColorFunctionForLabParameters(CSSParserTokenRange& args)
@@ -978,27 +984,27 @@
double channels[3] = { 0, 0, 0 };
[&] {
- auto lightness = consumePercentRaw(args, ValueRangeAll);
+ auto lightness = consumePercentRaw(args);
if (!lightness)
return;
channels[0] = *lightness;
- auto aValue = consumeNumberRaw(args, ValueRangeAll);
+ auto aValue = consumeNumberRaw(args);
if (!aValue)
return;
channels[1] = *aValue;
- auto bValue = consumeNumberRaw(args, ValueRangeAll);
+ auto bValue = consumeNumberRaw(args);
if (!bValue)
return;
channels[2] = *bValue;
}();
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
- return Lab<float> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), *alpha };
+ return Lab<float> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) };
}
static Color parseColorFunctionForXYZParameters(CSSParserTokenRange& args)
@@ -1008,27 +1014,27 @@
double channels[3] = { 0, 0, 0 };
[&] {
- auto x = consumeNumberRaw(args, ValueRangeAll);
+ auto x = consumeNumberRaw(args);
if (!x)
return;
channels[0] = *x;
- auto y = consumeNumberRaw(args, ValueRangeAll);
+ auto y = consumeNumberRaw(args);
if (!y)
return;
channels[1] = *y;
- auto z = consumeNumberRaw(args, ValueRangeAll);
+ auto z = consumeNumberRaw(args);
if (!z)
return;
channels[2] = *z;
}();
- auto alpha = parseOptionalAlpha(args);
+ auto alpha = consumeOptionalAlpha(args);
if (!alpha)
return { };
- return XYZA<float, WhitePoint::D50> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), *alpha };
+ return XYZA<float, WhitePoint::D50> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) };
}
static Color parseColorFunctionParameters(CSSParserTokenRange& range)
@@ -1111,7 +1117,7 @@
return *result;
}
-static Color parseColorFunction(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+static Color parseColorFunction(CSSParserTokenRange& range, const CSSParserContext& context)
{
CSSParserTokenRange colorRange = range;
CSSValueID functionId = range.peek().functionId();
@@ -1119,20 +1125,20 @@
switch (functionId) {
case CSSValueRgb:
case CSSValueRgba:
- color = parseRGBParameters(colorRange);
+ color = parseRGBParameters(colorRange, context);
break;
case CSSValueHsl:
case CSSValueHsla:
- color = parseHSLParameters(colorRange, cssParserMode);
+ color = parseHSLParameters(colorRange, context);
break;
case CSSValueHwb:
- color = parseHWBParameters(colorRange, cssParserMode);
+ color = parseHWBParameters(colorRange, context);
break;
case CSSValueLab:
- color = parseLabParameters(colorRange);
+ color = parseLabParameters(colorRange, context);
break;
case CSSValueLch:
- color = parseLCHParameters(colorRange, cssParserMode);
+ color = parseLCHParameters(colorRange, context);
break;
case CSSValueColor:
color = parseColorFunctionParameters(colorRange);
@@ -1145,7 +1151,7 @@
return color;
}
-Color consumeColorWorkerSafe(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+Color consumeColorWorkerSafe(CSSParserTokenRange& range, const CSSParserContext& context)
{
Color result;
auto keyword = range.peek().id();
@@ -1154,7 +1160,7 @@
// For now, we detect the system color, but then intentionally fail parsing.
if (StyleColor::isSystemColor(keyword))
return { };
- if (!isValueAllowedInMode(keyword, cssParserMode))
+ if (!isValueAllowedInMode(keyword, context.mode))
return { };
result = StyleColor::colorFromKeyword(keyword, { });
range.consumeIncludingWhitespace();
@@ -1163,7 +1169,7 @@
if (auto parsedColor = parseHexColor(range, false))
result = *parsedColor;
else
- result = parseColorFunction(range, cssParserMode);
+ result = parseColorFunction(range, context);
if (!range.atEnd())
return { };
@@ -1171,11 +1177,11 @@
return result;
}
-RefPtr<CSSPrimitiveValue> consumeColor(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool acceptQuirkyColors)
+RefPtr<CSSPrimitiveValue> consumeColor(CSSParserTokenRange& range, const CSSParserContext& context, bool acceptQuirkyColors)
{
auto keyword = range.peek().id();
if (StyleColor::isColorKeyword(keyword)) {
- if (!isValueAllowedInMode(keyword, cssParserMode))
+ if (!isValueAllowedInMode(keyword, context.mode))
return nullptr;
return consumeIdent(range);
}
@@ -1183,7 +1189,7 @@
if (auto parsedColor = parseHexColor(range, acceptQuirkyColors))
color = *parsedColor;
else {
- color = parseColorFunction(range, cssParserMode);
+ color = parseColorFunction(range, context);
if (!color.isValid())
return nullptr;
}
@@ -1413,14 +1419,14 @@
}
// Used to parse colors for -webkit-gradient(...).
-static RefPtr<CSSPrimitiveValue> consumeDeprecatedGradientStopColor(CSSParserTokenRange& args, CSSParserMode cssParserMode)
+static RefPtr<CSSPrimitiveValue> consumeDeprecatedGradientStopColor(CSSParserTokenRange& args, const CSSParserContext& context)
{
if (args.peek().id() == CSSValueCurrentcolor)
return nullptr;
- return consumeColor(args, cssParserMode);
+ return consumeColor(args, context);
}
-static bool consumeDeprecatedGradientColorStop(CSSParserTokenRange& range, CSSGradientColorStop& stop, CSSParserMode cssParserMode)
+static bool consumeDeprecatedGradientColorStop(CSSParserTokenRange& range, CSSGradientColorStop& stop, const CSSParserContext& context)
{
CSSValueID id = range.peek().functionId();
if (id != CSSValueFrom && id != CSSValueTo && id != CSSValueColorStop)
@@ -1442,11 +1448,11 @@
}
stop.position = CSSValuePool::singleton().createValue(position, CSSUnitType::CSS_NUMBER);
- stop.color = consumeDeprecatedGradientStopColor(args, cssParserMode);
+ stop.color = consumeDeprecatedGradientStopColor(args, context);
return stop.color && args.atEnd();
}
-static RefPtr<CSSValue> consumeDeprecatedGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode)
+static RefPtr<CSSValue> consumeDeprecatedGradient(CSSParserTokenRange& args, const CSSParserContext& context)
{
RefPtr<CSSGradientValue> result;
CSSValueID id = args.consumeIncludingWhitespace().id();
@@ -1499,7 +1505,7 @@
CSSGradientColorStop stop;
while (consumeCommaIncludingWhitespace(args)) {
- if (!consumeDeprecatedGradientColorStop(args, stop, cssParserMode))
+ if (!consumeDeprecatedGradientColorStop(args, stop, context))
return nullptr;
result->addStop(WTFMove(stop));
}
@@ -1508,20 +1514,20 @@
return result;
}
-static bool consumeGradientColorStops(CSSParserTokenRange& range, CSSParserMode mode, CSSGradientValue& gradient)
+static bool consumeGradientColorStops(CSSParserTokenRange& range, const CSSParserContext& context, CSSGradientValue& gradient)
{
bool supportsColorHints = gradient.gradientType() == CSSLinearGradient || gradient.gradientType() == CSSRadialGradient || gradient.gradientType() == CSSConicGradient;
auto consumeStopPosition = [&] {
return gradient.gradientType() == CSSConicGradient
- ? consumeAngleOrPercent(range, mode, ValueRangeAll, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow)
- : consumeLengthOrPercent(range, mode, ValueRangeAll);
+ ? consumeAngleOrPercent(range, context.mode, ValueRangeAll, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow)
+ : consumeLengthOrPercent(range, context.mode, ValueRangeAll);
};
// The first color stop cannot be a color hint.
bool previousStopWasColorHint = true;
do {
- CSSGradientColorStop stop { consumeColor(range, mode), consumeStopPosition(), { } };
+ CSSGradientColorStop stop { consumeColor(range, context), consumeStopPosition(), { } };
if (!stop.color && !stop.position)
return false;
@@ -1552,11 +1558,11 @@
return true;
}
-static RefPtr<CSSValue> consumeDeprecatedRadialGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating)
+static RefPtr<CSSValue> consumeDeprecatedRadialGradient(CSSParserTokenRange& args, const CSSParserContext& context, CSSGradientRepeat repeating)
{
auto result = CSSRadialGradientValue::create(repeating, CSSPrefixedRadialGradient);
- auto centerCoordinate = consumeOneOrTwoValuedPositionCoordinates(args, cssParserMode, UnitlessQuirk::Forbid);
+ auto centerCoordinate = consumeOneOrTwoValuedPositionCoordinates(args, context.mode, UnitlessQuirk::Forbid);
if (centerCoordinate && !consumeCommaIncludingWhitespace(args))
return nullptr;
@@ -1567,10 +1573,10 @@
// Or, two lengths or percentages
if (!shape && !sizeKeyword) {
- auto horizontalSize = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
+ auto horizontalSize = consumeLengthOrPercent(args, context.mode, ValueRangeNonNegative);
RefPtr<CSSPrimitiveValue> verticalSize;
if (horizontalSize) {
- verticalSize = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
+ verticalSize = consumeLengthOrPercent(args, context.mode, ValueRangeNonNegative);
if (!verticalSize)
return nullptr;
consumeCommaIncludingWhitespace(args);
@@ -1581,7 +1587,7 @@
consumeCommaIncludingWhitespace(args);
}
- if (!consumeGradientColorStops(args, cssParserMode, result))
+ if (!consumeGradientColorStops(args, context, result))
return nullptr;
if (centerCoordinate) {
@@ -1596,7 +1602,7 @@
return result;
}
-static RefPtr<CSSValue> consumeRadialGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating)
+static RefPtr<CSSValue> consumeRadialGradient(CSSParserTokenRange& args, const CSSParserContext& context, CSSGradientRepeat repeating)
{
RefPtr<CSSRadialGradientValue> result = CSSRadialGradientValue::create(repeating, CSSRadialGradient);
@@ -1624,13 +1630,13 @@
break;
}
} else {
- auto center = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
+ auto center = consumeLengthOrPercent(args, context.mode, ValueRangeNonNegative);
if (!center)
break;
if (horizontalSize)
return nullptr;
horizontalSize = center;
- center = consumeLengthOrPercent(args, cssParserMode, ValueRangeNonNegative);
+ center = consumeLengthOrPercent(args, context.mode, ValueRangeNonNegative);
if (center) {
verticalSize = center;
++i;
@@ -1659,7 +1665,7 @@
if (args.peek().id() == CSSValueAt) {
args.consumeIncludingWhitespace();
- auto centerCoordinate = consumePositionCoordinates(args, cssParserMode, UnitlessQuirk::Forbid, PositionSyntax::Position);
+ auto centerCoordinate = consumePositionCoordinates(args, context.mode, UnitlessQuirk::Forbid, PositionSyntax::Position);
if (!centerCoordinate)
return nullptr;
@@ -1676,7 +1682,7 @@
if ((shape || sizeKeyword || horizontalSize || centerX || centerY) && !consumeCommaIncludingWhitespace(args))
return nullptr;
- if (!consumeGradientColorStops(args, cssParserMode, *result))
+ if (!consumeGradientColorStops(args, context, *result))
return nullptr;
result->setShape(WTFMove(shape));
@@ -1687,12 +1693,12 @@
return result;
}
-static RefPtr<CSSValue> consumeLinearGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating, CSSGradientType gradientType)
+static RefPtr<CSSValue> consumeLinearGradient(CSSParserTokenRange& args, const CSSParserContext& context, CSSGradientRepeat repeating, CSSGradientType gradientType)
{
RefPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repeating, gradientType);
bool expectComma = true;
- RefPtr<CSSPrimitiveValue> angle = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow);
+ RefPtr<CSSPrimitiveValue> angle = consumeAngle(args, context.mode, UnitlessQuirk::Forbid, UnitlessZeroQuirk::Allow);
if (angle)
result->setAngle(angle.releaseNonNull());
else if (gradientType == CSSPrefixedLinearGradient || consumeIdent<CSSValueTo>(args)) {
@@ -1715,12 +1721,12 @@
if (expectComma && !consumeCommaIncludingWhitespace(args))
return nullptr;
- if (!consumeGradientColorStops(args, cssParserMode, *result))
+ if (!consumeGradientColorStops(args, context, *result))
return nullptr;
return result;
}
-static RefPtr<CSSValue> consumeConicGradient(CSSParserTokenRange& args, CSSParserContext context, CSSGradientRepeat repeating)
+static RefPtr<CSSValue> consumeConicGradient(CSSParserTokenRange& args, const CSSParserContext& context, CSSGradientRepeat repeating)
{
#if ENABLE(CSS_CONIC_GRADIENTS)
RefPtr<CSSConicGradientValue> result = CSSConicGradientValue::create(repeating);
@@ -1754,7 +1760,7 @@
if (expectComma && !consumeCommaIncludingWhitespace(args))
return nullptr;
- if (!consumeGradientColorStops(args, context.mode, *result))
+ if (!consumeGradientColorStops(args, context, *result))
return nullptr;
return result;
#else
@@ -1765,7 +1771,7 @@
#endif
}
-RefPtr<CSSValue> consumeImageOrNone(CSSParserTokenRange& range, CSSParserContext context)
+RefPtr<CSSValue> consumeImageOrNone(CSSParserTokenRange& range, const CSSParserContext& context)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
@@ -1772,7 +1778,7 @@
return consumeImage(range, context);
}
-static RefPtr<CSSValue> consumeCrossFade(CSSParserTokenRange& args, CSSParserContext context, bool prefixed)
+static RefPtr<CSSValue> consumeCrossFade(CSSParserTokenRange& args, const CSSParserContext& context, bool prefixed)
{
auto fromImageValue = consumeImageOrNone(args, context);
if (!fromImageValue || !consumeCommaIncludingWhitespace(args))
@@ -1848,7 +1854,7 @@
}
#endif
-static RefPtr<CSSValue> consumeGeneratedImage(CSSParserTokenRange& range, CSSParserContext context)
+static RefPtr<CSSValue> consumeGeneratedImage(CSSParserTokenRange& range, const CSSParserContext& context)
{
CSSValueID id = range.peek().functionId();
CSSParserTokenRange rangeCopy = range;
@@ -1855,23 +1861,23 @@
CSSParserTokenRange args = consumeFunction(rangeCopy);
RefPtr<CSSValue> result;
if (id == CSSValueRadialGradient)
- result = consumeRadialGradient(args, context.mode, NonRepeating);
+ result = consumeRadialGradient(args, context, NonRepeating);
else if (id == CSSValueRepeatingRadialGradient)
- result = consumeRadialGradient(args, context.mode, Repeating);
+ result = consumeRadialGradient(args, context, Repeating);
else if (id == CSSValueWebkitLinearGradient)
- result = consumeLinearGradient(args, context.mode, NonRepeating, CSSPrefixedLinearGradient);
+ result = consumeLinearGradient(args, context, NonRepeating, CSSPrefixedLinearGradient);
else if (id == CSSValueWebkitRepeatingLinearGradient)
- result = consumeLinearGradient(args, context.mode, Repeating, CSSPrefixedLinearGradient);
+ result = consumeLinearGradient(args, context, Repeating, CSSPrefixedLinearGradient);
else if (id == CSSValueRepeatingLinearGradient)
- result = consumeLinearGradient(args, context.mode, Repeating, CSSLinearGradient);
+ result = consumeLinearGradient(args, context, Repeating, CSSLinearGradient);
else if (id == CSSValueLinearGradient)
- result = consumeLinearGradient(args, context.mode, NonRepeating, CSSLinearGradient);
+ result = consumeLinearGradient(args, context, NonRepeating, CSSLinearGradient);
else if (id == CSSValueWebkitGradient)
- result = consumeDeprecatedGradient(args, context.mode);
+ result = consumeDeprecatedGradient(args, context);
else if (id == CSSValueWebkitRadialGradient)
- result = consumeDeprecatedRadialGradient(args, context.mode, NonRepeating);
+ result = consumeDeprecatedRadialGradient(args, context, NonRepeating);
else if (id == CSSValueWebkitRepeatingRadialGradient)
- result = consumeDeprecatedRadialGradient(args, context.mode, Repeating);
+ result = consumeDeprecatedRadialGradient(args, context, Repeating);
else if (id == CSSValueConicGradient)
result = consumeConicGradient(args, context, NonRepeating);
else if (id == CSSValueRepeatingConicGradient)
@@ -2017,7 +2023,7 @@
RefPtr<CSSValue> parsedValue;
if (filterType == CSSValueDropShadow)
- parsedValue = consumeSingleShadow(args, context.mode, false, false);
+ parsedValue = consumeSingleShadow(args, context, false, false);
else {
if (args.atEnd())
return filterValue;
@@ -2064,7 +2070,7 @@
return list.ptr();
}
-RefPtr<CSSShadowValue> consumeSingleShadow(CSSParserTokenRange& range, CSSParserMode cssParserMode, bool allowInset, bool allowSpread)
+RefPtr<CSSShadowValue> consumeSingleShadow(CSSParserTokenRange& range, const CSSParserContext& context, bool allowInset, bool allowSpread)
{
RefPtr<CSSPrimitiveValue> style;
RefPtr<CSSPrimitiveValue> color;
@@ -2089,7 +2095,7 @@
continue;
}
- auto maybeColor = consumeColor(range, cssParserMode);
+ auto maybeColor = consumeColor(range, context);
if (maybeColor) {
// If we just parsed a color but already had one, the given token range is not a valid <shadow>.
if (color)
@@ -2103,10 +2109,10 @@
// If we've already parsed these lengths, the given value is invalid as there cannot be two lengths components in a single <shadow> value.
return nullptr;
}
- horizontalOffset = consumeLength(range, cssParserMode, ValueRangeAll);
+ horizontalOffset = consumeLength(range, context.mode, ValueRangeAll);
if (!horizontalOffset)
return nullptr;
- verticalOffset = consumeLength(range, cssParserMode, ValueRangeAll);
+ verticalOffset = consumeLength(range, context.mode, ValueRangeAll);
if (!verticalOffset)
return nullptr;
@@ -2113,13 +2119,13 @@
const CSSParserToken& token = range.peek();
// The explicit check for calc() is unfortunate. This is ensuring that we only fail parsing if there is a length, but it fails the range check.
if (token.type() == DimensionToken || token.type() == NumberToken || (token.type() == FunctionToken && CSSCalcValue::isCalcFunction(token.functionId()))) {
- blurRadius = consumeLength(range, cssParserMode, ValueRangeNonNegative);
+ blurRadius = consumeLength(range, context.mode, ValueRangeNonNegative);
if (!blurRadius)
return nullptr;
}
if (blurRadius && allowSpread)
- spreadDistance = consumeLength(range, cssParserMode, ValueRangeAll);
+ spreadDistance = consumeLength(range, context.mode, ValueRangeAll);
}
// In order for this to be a valid <shadow>, at least these lengths must be present.
@@ -2128,7 +2134,7 @@
return CSSShadowValue::create(WTFMove(horizontalOffset), WTFMove(verticalOffset), WTFMove(blurRadius), WTFMove(spreadDistance), WTFMove(style), WTFMove(color));
}
-RefPtr<CSSValue> consumeImage(CSSParserTokenRange& range, CSSParserContext context, OptionSet<AllowedImageType> allowedImageTypes)
+RefPtr<CSSValue> consumeImage(CSSParserTokenRange& range, const CSSParserContext& context, OptionSet<AllowedImageType> allowedImageTypes)
{
if ((range.peek().type() == StringToken) && (allowedImageTypes.contains(AllowedImageType::RawStringAsURL))) {
auto urlStringView = range.consumeIncludingWhitespace().value();
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (272869 => 272870)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h 2021-02-15 19:24:12 UTC (rev 272870)
@@ -102,8 +102,8 @@
StringView consumeUrlAsStringView(CSSParserTokenRange&);
RefPtr<CSSPrimitiveValue> consumeUrl(CSSParserTokenRange&);
-Color consumeColorWorkerSafe(CSSParserTokenRange&, CSSParserMode);
-RefPtr<CSSPrimitiveValue> consumeColor(CSSParserTokenRange&, CSSParserMode, bool acceptQuirkyColors = false);
+Color consumeColorWorkerSafe(CSSParserTokenRange&, const CSSParserContext&);
+RefPtr<CSSPrimitiveValue> consumeColor(CSSParserTokenRange&, const CSSParserContext&, bool acceptQuirkyColors = false);
enum class PositionSyntax {
Position, // <position>
@@ -126,10 +126,9 @@
GeneratedImage = 1 << 3
};
-RefPtr<CSSValue> consumeImage(CSSParserTokenRange&, CSSParserContext, OptionSet<AllowedImageType> = { AllowedImageType::URLFunction, AllowedImageType::ImageSet, AllowedImageType::GeneratedImage });
+RefPtr<CSSValue> consumeImage(CSSParserTokenRange&, const CSSParserContext&, OptionSet<AllowedImageType> = { AllowedImageType::URLFunction, AllowedImageType::ImageSet, AllowedImageType::GeneratedImage });
+RefPtr<CSSValue> consumeImageOrNone(CSSParserTokenRange&, const CSSParserContext&);
-RefPtr<CSSValue> consumeImageOrNone(CSSParserTokenRange&, CSSParserContext);
-
enum class AllowedFilterFunctions {
PixelFilters,
ColorFilters
@@ -136,7 +135,7 @@
};
RefPtr<CSSValue> consumeFilter(CSSParserTokenRange&, const CSSParserContext&, AllowedFilterFunctions);
-RefPtr<CSSShadowValue> consumeSingleShadow(CSSParserTokenRange&, CSSParserMode, bool allowInset, bool allowSpread);
+RefPtr<CSSShadowValue> consumeSingleShadow(CSSParserTokenRange&, const CSSParserContext&, bool allowInset, bool allowSpread);
struct FontStyleRaw {
CSSValueID style;
Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (272869 => 272870)
--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2021-02-15 19:24:12 UTC (rev 272870)
@@ -600,7 +600,7 @@
// Force the lightness of the underline color to the middle, and multiply the alpha by 38%,
// so the color will appear on light and dark backgrounds, since only one color can be specified.
- hsla.lightness = 0.5f;
+ hsla.lightness = 50.0f;
hsla.alpha *= 0.38f;
// FIXME: Consider keeping color in LCHA (if that change is made) or converting back to the initial underlying color type to avoid unnecessarily clamping colors outside of sRGB.
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (272869 => 272870)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -58,8 +58,6 @@
if (hue >= 360.0f)
hue -= 360.0f;
- hue /= 360.0f;
-
return { hue, min, max, chroma };
}
@@ -69,14 +67,14 @@
auto [r, g, b, alpha] = color;
auto [hue, min, max, chroma] = calculateHSLHue(color);
- float lightness = 0.5f * (max + min);
+ float lightness = (0.5f * (max + min)) * 100.0f;
float saturation;
if (!chroma)
saturation = 0;
- else if (lightness <= 0.5f)
- saturation = (chroma / (max + min));
+ else if (lightness <= 50.0f)
+ saturation = (chroma / (max + min)) * 100.0f;
else
- saturation = (chroma / (2.0f - (max + min)));
+ saturation = (chroma / (2.0f - (max + min))) * 100.0f;
return { hue, saturation, lightness, alpha };
}
@@ -86,12 +84,27 @@
// https://drafts.csswg.org/css-color-4/#hsl-to-rgb
auto [hue, saturation, lightness, alpha] = color;
- if (!saturation)
- return { lightness, lightness, lightness, alpha };
+ if (!saturation) {
+ auto grey = lightness / 100.0f;
+ return { grey, grey, grey, alpha };
+ }
+
+ // hueToRGB() wants hue in the 0-6 range.
+ auto normalizedHue = (hue / 360.0f) * 6.0f;
+ auto normalizedLightness = lightness / 100.0f;
+ auto normalizedSaturation = saturation / 100.0f;
+
+ auto hueForRed = normalizedHue + 2.0f;
+ auto hueForGreen = normalizedHue;
+ auto hueForBlue = normalizedHue - 2.0f;
+ if (hueForRed > 6.0f)
+ hueForRed -= 6.0f;
+ else if (hueForBlue < 0.0f)
+ hueForBlue += 6.0f;
+
+ float temp2 = normalizedLightness <= 0.5f ? normalizedLightness * (1.0f + normalizedSaturation) : normalizedLightness + normalizedSaturation - normalizedLightness * normalizedSaturation;
+ float temp1 = 2.0f * normalizedLightness - temp2;
- float temp2 = lightness <= 0.5f ? lightness * (1.0f + saturation) : lightness + saturation - lightness * saturation;
- float temp1 = 2.0f * lightness - temp2;
-
// Hue is in the range 0-6, other args in 0-1.
auto hueToRGB = [](float temp1, float temp2, float hue) {
if (hue < 1.0f)
@@ -103,17 +116,6 @@
return temp1;
};
- // hueToRGB() wants hue in the 0-6 range.
- hue *= 6.0f;
-
- auto hueForRed = hue + 2.0f;
- auto hueForGreen = hue;
- auto hueForBlue = hue - 2.0f;
- if (hueForRed > 6.0f)
- hueForRed -= 6.0f;
- else if (hueForBlue < 0.0f)
- hueForBlue += 6.0f;
-
return {
hueToRGB(temp1, temp2, hueForRed),
hueToRGB(temp1, temp2, hueForGreen),
@@ -128,8 +130,8 @@
{
// https://drafts.csswg.org/css-color-4/#rgb-to-hwb
auto [hue, min, max, chroma] = calculateHSLHue(color);
- auto whiteness = min;
- auto blackness = 1.0f - max;
+ auto whiteness = min * 100.0f;
+ auto blackness = (1.0f - max) * 100.0f;
return { hue, whiteness, blackness, color.alpha };
}
@@ -139,9 +141,25 @@
// https://drafts.csswg.org/css-color-4/#hwb-to-rgb
auto [hue, whiteness, blackness, alpha] = color;
- if (whiteness + blackness == 1.0f)
- return { whiteness, whiteness, whiteness, alpha };
+ if (whiteness + blackness == 100.0f) {
+ auto grey = whiteness / 100.0f;
+ return { grey, grey, grey, alpha };
+ }
+ // hueToRGB() wants hue in the 0-6 range.
+ auto normalizedHue = (hue / 360.0f) * 6.0f;
+
+ auto hueForRed = normalizedHue + 2.0f;
+ auto hueForGreen = normalizedHue;
+ auto hueForBlue = normalizedHue - 2.0f;
+ if (hueForRed > 6.0f)
+ hueForRed -= 6.0f;
+ else if (hueForBlue < 0.0f)
+ hueForBlue += 6.0f;
+
+ auto normalizedWhiteness = whiteness / 100.0f;
+ auto normalizedBlackness = blackness / 100.0f;
+
// This is the hueToRGB function in convertColor<SRGBA<float>>(const HSLA&) with temp1 == 0
// and temp2 == 1 strength reduced through it.
auto hueToRGB = [](float hue) {
@@ -154,25 +172,14 @@
return 0.0f;
};
- auto applyWhitenessBlackness = [&](float component) {
- return (component * (1.0f - color.whiteness - color.blackness)) + color.whiteness;
+ auto applyWhitenessBlackness = [](float component, auto whiteness, auto blackness) {
+ return (component * (1.0f - whiteness - blackness)) + whiteness;
};
- // hueToRGB() wants hue in the 0-6 range.
- hue *= 6.0f;
-
- auto hueForRed = hue + 2.0f;
- auto hueForGreen = hue;
- auto hueForBlue = hue - 2.0f;
- if (hueForRed > 6.0f)
- hueForRed -= 6.0f;
- else if (hueForBlue < 0.0f)
- hueForBlue += 6.0f;
-
return {
- applyWhitenessBlackness(hueToRGB(hueForRed)),
- applyWhitenessBlackness(hueToRGB(hueForGreen)),
- applyWhitenessBlackness(hueToRGB(hueForBlue)),
+ applyWhitenessBlackness(hueToRGB(hueForRed), normalizedWhiteness, normalizedBlackness),
+ applyWhitenessBlackness(hueToRGB(hueForGreen), normalizedWhiteness, normalizedBlackness),
+ applyWhitenessBlackness(hueToRGB(hueForBlue), normalizedWhiteness, normalizedBlackness),
alpha
};
}
Modified: trunk/Source/WebCore/platform/graphics/ColorModels.h (272869 => 272870)
--- trunk/Source/WebCore/platform/graphics/ColorModels.h 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/platform/graphics/ColorModels.h 2021-02-15 19:24:12 UTC (rev 272870)
@@ -67,9 +67,9 @@
template<> struct HSLModel<float> {
static constexpr std::array<ColorComponentRange<float>, 3> ranges { {
- { 0, 1 },
- { 0, 1 },
- { 0, 1 }
+ { 0, 360 },
+ { 0, 100 },
+ { 0, 100 }
} };
static constexpr bool isInvertible = false;
};
@@ -76,9 +76,9 @@
template<> struct HWBModel<float> {
static constexpr std::array<ColorComponentRange<float>, 3> ranges { {
- { 0, 1 },
- { 0, 1 },
- { 0, 1 }
+ { 0, 360 },
+ { 0, 100 },
+ { 0, 100 }
} };
static constexpr bool isInvertible = false;
};
Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (272869 => 272870)
--- trunk/Source/WebCore/rendering/RenderTheme.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1422,7 +1422,7 @@
// FIXME: Consider using LCHA<float> rather than HSLA<float> for better perceptual results and to avoid clamping to sRGB gamut, which is what HSLA does.
auto hsla = textColor.toColorTypeLossy<HSLA<float>>();
if (textColor.luminance() < backgroundColor.luminance())
- hsla.lightness += datePlaceholderColorLightnessAdjustmentFactor * (1.0f - hsla.lightness);
+ hsla.lightness += datePlaceholderColorLightnessAdjustmentFactor * (100.0f - hsla.lightness);
else
hsla.lightness *= datePlaceholderColorLightnessAdjustmentFactor;
Modified: trunk/Tools/ChangeLog (272869 => 272870)
--- trunk/Tools/ChangeLog 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Tools/ChangeLog 2021-02-15 19:24:12 UTC (rev 272870)
@@ -1,3 +1,13 @@
+2021-02-15 Sam Weinig <wei...@apple.com>
+
+ Prepare for adding relative color support
+ https://bugs.webkit.org/show_bug.cgi?id=221881
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
+ Update HSLA tests to account for HSLA now using 0-360, 0-100, 0-100 bounds rather than 0-1, 0-1, 0-1.
+
2021-02-15 Adam Roben <aro...@apple.com>
Add `git commit -v` support to commit-log-editor
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp (272869 => 272870)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp 2021-02-15 19:21:59 UTC (rev 272869)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp 2021-02-15 19:24:12 UTC (rev 272870)
@@ -42,9 +42,9 @@
EXPECT_FLOAT_EQ(0, hslaColor.hue);
EXPECT_FLOAT_EQ(0, hslaColor.saturation);
- EXPECT_FLOAT_EQ(1, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(100, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -60,7 +60,7 @@
EXPECT_FLOAT_EQ(0, hslaColor.saturation);
EXPECT_FLOAT_EQ(0, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -73,10 +73,10 @@
auto hslaColor = color.toColorTypeLossy<HSLA<float>>();
EXPECT_FLOAT_EQ(0, hslaColor.hue);
- EXPECT_FLOAT_EQ(1, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.5, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(100, hslaColor.saturation);
+ EXPECT_FLOAT_EQ(50, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -88,11 +88,11 @@
auto hslaColor = color.toColorTypeLossy<HSLA<float>>();
- EXPECT_FLOAT_EQ(0.33333334, hslaColor.hue);
- EXPECT_FLOAT_EQ(1, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.5, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(120, hslaColor.hue);
+ EXPECT_FLOAT_EQ(100, hslaColor.saturation);
+ EXPECT_FLOAT_EQ(50, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -104,11 +104,11 @@
auto hslaColor = color.toColorTypeLossy<HSLA<float>>();
- EXPECT_FLOAT_EQ(0.66666669, hslaColor.hue);
- EXPECT_FLOAT_EQ(1, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.5, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(240, hslaColor.hue);
+ EXPECT_FLOAT_EQ(100, hslaColor.saturation);
+ EXPECT_FLOAT_EQ(50, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -122,9 +122,9 @@
EXPECT_FLOAT_EQ(0, hslaColor.hue);
EXPECT_FLOAT_EQ(0, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.50196078431372548, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(50.196083, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -138,9 +138,9 @@
EXPECT_FLOAT_EQ(0, hslaColor.hue);
EXPECT_FLOAT_EQ(0, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.62745098039215685, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(62.745102, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
@@ -154,9 +154,9 @@
EXPECT_FLOAT_EQ(0, hslaColor.hue);
EXPECT_FLOAT_EQ(0, hslaColor.saturation);
- EXPECT_FLOAT_EQ(0.75294117647058822, hslaColor.lightness);
+ EXPECT_FLOAT_EQ(75.294121, hslaColor.lightness);
- EXPECT_FLOAT_EQ(color.lightness(), hslaColor.lightness);
+ EXPECT_FLOAT_EQ(color.lightness() * 100, hslaColor.lightness);
auto roundTrippedColor = convertColor<SRGBA<uint8_t>>(hslaColor);
EXPECT_EQ(color, roundTrippedColor);
_______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-changes