Skip to content

Commit

Permalink
Remove CSSColor4 preference
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264243
rdar://117988320

Reviewed by Tim Nguyen.

This has been stable for over two years. Let's simplify.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::parseHWBParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseLabParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseLCHParametersRaw):
(WebCore::CSSPropertyParserHelpers::parseRelativeColorFunctionForRGBTypes):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypesRaw):
(WebCore::CSSPropertyParserHelpers::parseRelativeColorFunctionForXYZTypes):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZTypesRaw):
(WebCore::CSSPropertyParserHelpers::parseRelativeColorFunctionParameters):
(WebCore::CSSPropertyParserHelpers::parseNonRelativeColorFunctionParameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParametersRaw):

Canonical link: https://commits.webkit.org/270265@main
  • Loading branch information
annevk committed Nov 6, 2023
1 parent 51cc3b7 commit 27c29b9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 81 deletions.
13 changes: 0 additions & 13 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -948,19 +948,6 @@ CSSCascadeLayersEnabled:
WebCore:
default: true

CSSColor4:
type: bool
status: mature
humanReadableName: "CSS Color 4 Color Types"
humanReadableDescription: "Enable support for CSS Color 4 Color Types"
defaultValue:
WebKitLegacy:
default: true
WebKit:
default: true
WebCore:
default: true

CSSColorContrastEnabled:
type: bool
status: testable
Expand Down
42 changes: 20 additions & 22 deletions Source/WebCore/css/parser/CSSParserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ CSSParserContext::CSSParserContext(const Document& document, const URL& sheetBas
, colorMixEnabled { document.settings().cssColorMixEnabled() }
, constantPropertiesEnabled { document.settings().constantPropertiesEnabled() }
, counterStyleAtRuleImageSymbolsEnabled { document.settings().cssCounterStyleAtRuleImageSymbolsEnabled() }
, cssColor4 { document.settings().cssColor4() }
, relativeColorSyntaxEnabled { document.settings().cssRelativeColorSyntaxEnabled() }
, springTimingFunctionEnabled { document.settings().springTimingFunctionEnabled() }
#if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
Expand Down Expand Up @@ -118,29 +117,28 @@ void add(Hasher& hasher, const CSSParserContext& context)
| context.colorContrastEnabled << 4
| context.colorMixEnabled << 5
| context.constantPropertiesEnabled << 6
| context.cssColor4 << 7
| context.relativeColorSyntaxEnabled << 8
| context.springTimingFunctionEnabled << 9
| context.relativeColorSyntaxEnabled << 7
| context.springTimingFunctionEnabled << 8
#if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
| context.transformStyleOptimized3DEnabled << 10
| context.transformStyleOptimized3DEnabled << 9
#endif
| context.useLegacyBackgroundSizeShorthandBehavior << 11
| context.focusVisibleEnabled << 12
| context.hasPseudoClassEnabled << 13
| context.cascadeLayersEnabled << 14
| context.overflowClipEnabled << 15
| context.gradientPremultipliedAlphaInterpolationEnabled << 16
| context.gradientInterpolationColorSpacesEnabled << 17
| context.subgridEnabled << 18
| context.masonryEnabled << 19
| context.cssNestingEnabled << 20
| context.cssPaintingAPIEnabled << 21
| context.cssTextUnderlinePositionLeftRightEnabled << 22
| context.cssWordBreakAutoPhraseEnabled << 23
| context.popoverAttributeEnabled << 24
| context.sidewaysWritingModesEnabled << 25
| context.cssTextWrapPrettyEnabled << 26
| (uint64_t)context.mode << 27; // This is multiple bits, so keep it last.
| context.useLegacyBackgroundSizeShorthandBehavior << 10
| context.focusVisibleEnabled << 11
| context.hasPseudoClassEnabled << 12
| context.cascadeLayersEnabled << 13
| context.overflowClipEnabled << 14
| context.gradientPremultipliedAlphaInterpolationEnabled << 15
| context.gradientInterpolationColorSpacesEnabled << 16
| context.subgridEnabled << 17
| context.masonryEnabled << 18
| context.cssNestingEnabled << 19
| context.cssPaintingAPIEnabled << 20
| context.cssTextUnderlinePositionLeftRightEnabled << 21
| context.cssWordBreakAutoPhraseEnabled << 22
| context.popoverAttributeEnabled << 23
| context.sidewaysWritingModesEnabled << 24
| context.cssTextWrapPrettyEnabled << 25
| (uint64_t)context.mode << 26; // This is multiple bits, so keep it last.
add(hasher, context.baseURL, context.charset, context.propertySettings, bits);
}

Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/css/parser/CSSParserContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ struct CSSParserContext {
bool colorMixEnabled { false };
bool constantPropertiesEnabled { false };
bool counterStyleAtRuleImageSymbolsEnabled { false };
bool cssColor4 { false };
bool relativeColorSyntaxEnabled { false };
bool springTimingFunctionEnabled { false };
#if ENABLE(CSS_TRANSFORM_STYLE_OPTIMIZED_3D)
Expand Down
67 changes: 22 additions & 45 deletions Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,9 +2269,6 @@ static Color parseHWBParametersRaw(CSSParserTokenRange& range, const CSSParserCo
{
ASSERT(range.peek().functionId() == CSSValueHwb);

if (!context.cssColor4)
return { };

auto args = consumeFunction(range);

if (context.relativeColorSyntaxEnabled && args.peek().id() == CSSValueFrom)
Expand Down Expand Up @@ -2482,9 +2479,6 @@ static Color parseLabParametersRaw(CSSParserTokenRange& range, const CSSParserCo
{
ASSERT(range.peek().functionId() == CSSValueLab || range.peek().functionId() == CSSValueOklab);

if (!context.cssColor4)
return { };

auto args = consumeFunction(range);

if (context.relativeColorSyntaxEnabled && args.peek().id() == CSSValueFrom)
Expand Down Expand Up @@ -2576,9 +2570,6 @@ static Color parseLCHParametersRaw(CSSParserTokenRange& range, const CSSParserCo
{
ASSERT(range.peek().functionId() == CSSValueLch || range.peek().functionId() == CSSValueOklch);

if (!context.cssColor4)
return { };

auto args = consumeFunction(range);

if (context.relativeColorSyntaxEnabled && args.peek().id() == CSSValueFrom)
Expand Down Expand Up @@ -2612,14 +2603,10 @@ static Color parseColorFunctionForRGBTypesRaw(CSSParserTokenRange& args, Consume
return { ColorType { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) }, Color::Flags::UseColorFunctionSerialization };
}

template<typename ColorType> static Color parseRelativeColorFunctionForRGBTypes(CSSParserTokenRange& args, Color originColor, const CSSParserContext& context)
template<typename ColorType> static Color parseRelativeColorFunctionForRGBTypes(CSSParserTokenRange& args, Color originColor)
{
ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB || args.peek().id() == CSSValueSrgbLinear);

// Support sRGB and Display-P3 regardless of the setting as we have shipped support for them for a while.
if (!context.cssColor4 && (args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSrgbLinear))
return { };

consumeIdentRaw(args);

auto originColorAsColorType = originColor.toColorTypeLossy<ColorType>().resolved();
Expand All @@ -2637,14 +2624,10 @@ template<typename ColorType> static Color parseRelativeColorFunctionForRGBTypes(
return parseColorFunctionForRGBTypesRaw<ColorType>(args, WTFMove(consumeRGB), WTFMove(consumeAlpha));
}

template<typename ColorType> static Color parseColorFunctionForRGBTypesRaw(CSSParserTokenRange& args, const CSSParserContext& context)
template<typename ColorType> static Color parseColorFunctionForRGBTypesRaw(CSSParserTokenRange& args)
{
ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB || args.peek().id() == CSSValueSrgbLinear);

// Support sRGB and Display-P3 regardless of the setting as we have shipped support for them for a while.
if (!context.cssColor4 && (args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSrgbLinear))
return { };

consumeIdentRaw(args);

auto consumeRGB = [](auto& args) { return consumeNumberOrPercentOrNoneRaw(args); };
Expand Down Expand Up @@ -2679,13 +2662,10 @@ static Color parseColorFunctionForXYZTypesRaw(CSSParserTokenRange& args, Consume
return { ColorType { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) }, Color::Flags::UseColorFunctionSerialization };
}

template<typename ColorType> static Color parseRelativeColorFunctionForXYZTypes(CSSParserTokenRange& args, Color originColor, const CSSParserContext& context)
template<typename ColorType> static Color parseRelativeColorFunctionForXYZTypes(CSSParserTokenRange& args, Color originColor)
{
ASSERT(args.peek().id() == CSSValueXyz || args.peek().id() == CSSValueXyzD50 || args.peek().id() == CSSValueXyzD65);

if (!context.cssColor4)
return { };

consumeIdentRaw(args);

auto originColorAsXYZ = originColor.toColorTypeLossy<ColorType>().resolved();
Expand All @@ -2703,13 +2683,10 @@ template<typename ColorType> static Color parseRelativeColorFunctionForXYZTypes(
return parseColorFunctionForXYZTypesRaw<ColorType>(args, WTFMove(consumeXYZ), WTFMove(consumeAlpha));
}

template<typename ColorType> static Color parseColorFunctionForXYZTypesRaw(CSSParserTokenRange& args, const CSSParserContext& context)
template<typename ColorType> static Color parseColorFunctionForXYZTypesRaw(CSSParserTokenRange& args)
{
ASSERT(args.peek().id() == CSSValueXyz || args.peek().id() == CSSValueXyzD50 || args.peek().id() == CSSValueXyzD65);

if (!context.cssColor4)
return { };

consumeIdentRaw(args);

auto consumeXYZ = [](auto& args) { return consumeNumberOrPercentOrNoneRaw(args); };
Expand All @@ -2729,22 +2706,22 @@ static Color parseRelativeColorFunctionParameters(CSSParserTokenRange& args, con

switch (args.peek().id()) {
case CSSValueA98Rgb:
return parseRelativeColorFunctionForRGBTypes<ExtendedA98RGB<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedA98RGB<float>>(args, WTFMove(originColor));
case CSSValueDisplayP3:
return parseRelativeColorFunctionForRGBTypes<ExtendedDisplayP3<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedDisplayP3<float>>(args, WTFMove(originColor));
case CSSValueProphotoRgb:
return parseRelativeColorFunctionForRGBTypes<ExtendedProPhotoRGB<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedProPhotoRGB<float>>(args, WTFMove(originColor));
case CSSValueRec2020:
return parseRelativeColorFunctionForRGBTypes<ExtendedRec2020<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedRec2020<float>>(args, WTFMove(originColor));
case CSSValueSRGB:
return parseRelativeColorFunctionForRGBTypes<ExtendedSRGBA<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedSRGBA<float>>(args, WTFMove(originColor));
case CSSValueSrgbLinear:
return parseRelativeColorFunctionForRGBTypes<ExtendedLinearSRGBA<float>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForRGBTypes<ExtendedLinearSRGBA<float>>(args, WTFMove(originColor));
case CSSValueXyzD50:
return parseRelativeColorFunctionForXYZTypes<XYZA<float, WhitePoint::D50>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForXYZTypes<XYZA<float, WhitePoint::D50>>(args, WTFMove(originColor));
case CSSValueXyz:
case CSSValueXyzD65:
return parseRelativeColorFunctionForXYZTypes<XYZA<float, WhitePoint::D65>>(args, WTFMove(originColor), context);
return parseRelativeColorFunctionForXYZTypes<XYZA<float, WhitePoint::D65>>(args, WTFMove(originColor));
default:
return { };
}
Expand All @@ -2753,26 +2730,26 @@ static Color parseRelativeColorFunctionParameters(CSSParserTokenRange& args, con
return { };
}

static Color parseNonRelativeColorFunctionParameters(CSSParserTokenRange& args, const CSSParserContext& context)
static Color parseNonRelativeColorFunctionParameters(CSSParserTokenRange& args)
{
switch (args.peek().id()) {
case CSSValueA98Rgb:
return parseColorFunctionForRGBTypesRaw<ExtendedA98RGB<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedA98RGB<float>>(args);
case CSSValueDisplayP3:
return parseColorFunctionForRGBTypesRaw<ExtendedDisplayP3<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedDisplayP3<float>>(args);
case CSSValueProphotoRgb:
return parseColorFunctionForRGBTypesRaw<ExtendedProPhotoRGB<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedProPhotoRGB<float>>(args);
case CSSValueRec2020:
return parseColorFunctionForRGBTypesRaw<ExtendedRec2020<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedRec2020<float>>(args);
case CSSValueSRGB:
return parseColorFunctionForRGBTypesRaw<ExtendedSRGBA<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedSRGBA<float>>(args);
case CSSValueSrgbLinear:
return parseColorFunctionForRGBTypesRaw<ExtendedLinearSRGBA<float>>(args, context);
return parseColorFunctionForRGBTypesRaw<ExtendedLinearSRGBA<float>>(args);
case CSSValueXyzD50:
return parseColorFunctionForXYZTypesRaw<XYZA<float, WhitePoint::D50>>(args, context);
return parseColorFunctionForXYZTypesRaw<XYZA<float, WhitePoint::D50>>(args);
case CSSValueXyz:
case CSSValueXyzD65:
return parseColorFunctionForXYZTypesRaw<XYZA<float, WhitePoint::D65>>(args, context);
return parseColorFunctionForXYZTypesRaw<XYZA<float, WhitePoint::D65>>(args);
default:
return { };
}
Expand All @@ -2789,7 +2766,7 @@ static Color parseColorFunctionParametersRaw(CSSParserTokenRange& range, const C
auto color = [&] {
if (context.relativeColorSyntaxEnabled && args.peek().id() == CSSValueFrom)
return parseRelativeColorFunctionParameters(args, context);
return parseNonRelativeColorFunctionParameters(args, context);
return parseNonRelativeColorFunctionParameters(args);
}();

ASSERT(!color.isValid() || color.usesColorFunctionSerialization());
Expand Down

0 comments on commit 27c29b9

Please sign in to comment.