Changeset 262128 in webkit


Ignore:
Timestamp:
May 25, 2020 11:30:16 AM (4 years ago)
Author:
weinig@apple.com
Message:

Extended Color Cleanup: Use the name SimpleColor consistently
https://bugs.webkit.org/show_bug.cgi?id=212337

Reviewed by Anders Carlsson.
Source/WebCore:


  • Removes RGBA32 type alias, updating all remaining users of it.
  • Renames functions that take/return SimpleColor to use the name SimpleColor rather than RGB (e.g. makeRGBA -> makeSimpleColor)
  • Moves hex color parsing from Color to SimpleColor, as that is the type it returns. Also took the opportunity to make it return an Optional<SimpleColor> instead of using a bool/out parameter.
  • Move Color::compositionFill to editing/CompositionHighlight.h It makes no real sense to keep it in Color.h
  • Replaces rgb() function in Color with asSimpleColor() for symmetry with asExtended().
  • Replaced std::max(a, std::min(value, b)) with std::clamp(value, a, b) for clarity.
  • css/parser/CSSParserFastPaths.cpp:

(WebCore::fastParseColorInternal):
(WebCore::CSSParserFastPaths::parseColor):

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::parseRGBParameters):
(WebCore::CSSPropertyParserHelpers::parseHSLParameters):
(WebCore::CSSPropertyParserHelpers::parseHexColor):

  • editing/CompositionHighlight.h:
  • editing/cocoa/DataDetection.mm:

(WebCore::DataDetection::detectContentInRange):

  • html/ColorInputType.cpp:

(WebCore::parseSimpleColorValue):

  • html/HTMLElement.cpp:

(WebCore::parseColorStringWithCrazyLegacyRules):

  • platform/adwaita/ScrollbarThemeAdwaita.cpp:
  • platform/adwaita/ThemeAdwaita.cpp:

(WebCore::ThemeAdwaita::activeSelectionForegroundColor const):
(WebCore::ThemeAdwaita::activeSelectionBackgroundColor const):
(WebCore::ThemeAdwaita::inactiveSelectionForegroundColor const):

  • platform/graphics/Color.cpp:

(WebCore::differenceSquared):
(WebCore::Color::Color):
(WebCore::Color::operator=):
(WebCore::Color::serialized const):
(WebCore::Color::cssText const):
(WebCore::Color::nameForRenderTreeAsText const):
(WebCore::Color::light const):
(WebCore::Color::dark const):
(WebCore::Color::blend const):
(WebCore::Color::blendWithWhite const):
(WebCore::Color::colorWithAlpha const):
(WebCore::Color::colorWithAlphaUsingAlternativeRounding const):
(WebCore::Color::invertedColorWithAlpha const):
(WebCore::Color::colorSpaceAndComponents const):
(WebCore::Color::toSRGBASimpleColorLossy const):
(WebCore::blend):
(WebCore::Color::tagAsValid):
(WebCore::parseHexColorInternal): Deleted.
(WebCore::Color::parseHexColor): Deleted.
(WebCore::Color::asExtended const): Deleted.

  • platform/graphics/Color.h:

(WebCore::Color::Color):
(WebCore::Color::isHashTableDeletedValue const):
(WebCore::Color::isValid const):
(WebCore::Color::isOpaque const):
(WebCore::Color::isVisible const):
(WebCore::Color::alpha const):
(WebCore::Color::alphaAsFloat const):
(WebCore::Color::isSemantic const):
(WebCore::Color::isExtended const):
(WebCore::Color::setIsSemantic):
(WebCore::operator==):
(WebCore::equalIgnoringSemanticColor):
(WebCore::Color::hash const):
(WebCore::Color::asExtended const):
(WebCore::Color::asSimpleColor const):
(WebCore::Color::setSimpleColor):
(WebCore::Color::isBlackColor):
(WebCore::Color::isWhiteColor):
(WebCore::Color::encode const):
(WebCore::Color::decode):
(WebCore::Color::setRGB): Deleted.
(WebCore::Color::rgb const): Deleted.

  • platform/graphics/ColorUtilities.h:

(WebCore::clampedColorComponent):

  • platform/graphics/ImageBackingStore.h:

(WebCore::ImageBackingStore::blendPixel):
(WebCore::ImageBackingStore::pixelValue const):

  • platform/graphics/SimpleColor.cpp:

(WebCore::makePremultipliedSimpleColor):
(WebCore::makeUnpremultipliedSimpleColor):
(WebCore::makeSimpleColorFromFloats):
(WebCore::makeSimpleColorFromHSLA):
(WebCore::makeSimpleColorFromCMYKA):
(WebCore::parseHexColorInternal):
(WebCore::SimpleColor::parseHexColor):
(WebCore::makePremultipliedRGBA): Deleted.
(WebCore::makeUnPremultipliedRGBA): Deleted.
(WebCore::makeRGBA32FromFloats): Deleted.
(WebCore::makeRGBAFromHSLA): Deleted.
(WebCore::makeRGBAFromCMYKA): Deleted.

  • platform/graphics/SimpleColor.h:

(WebCore::roundAndClampColorChannel):
(WebCore::colorFloatToSimpleColorByte):
(WebCore::makeSimpleColor):
(WebCore::colorFloatToRGBAByte): Deleted.
(WebCore::makeRGB): Deleted.
(WebCore::makeRGBA): Deleted.

  • platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:

(WebCore::makeSimpleColorFromARGBCFArray):
(WebCore::InbandTextTrackPrivateAVF::processCueAttributes):
(WebCore::makeRGBA32FromARGBCFArray): Deleted.

  • platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:

(WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):

  • platform/graphics/cairo/NativeImageCairo.cpp:

(WebCore::nativeImageSinglePixelSolidColor):

  • platform/graphics/cg/ColorCG.cpp:

(WebCore::makeSimpleColorFromCGColor):
(WebCore::Color::Color):
(WebCore::cachedCGColor):
(WebCore::makeRGBAFromCGColor): Deleted.

  • platform/graphics/gtk/ColorGtk.cpp:

(WebCore::Color::Color):

  • platform/graphics/mac/ColorMac.mm:

(WebCore::makeSimpleColorFromNSColor):
(WebCore::colorFromNSColor):
(WebCore::semanticColorFromNSColor):
(WebCore::makeRGBAFromNSColor): Deleted.

  • platform/graphics/win/ColorDirect2D.cpp:

(WebCore::Color::Color):

  • platform/graphics/win/GraphicsContextCGWin.cpp:

(WebCore::GraphicsContext::drawDotsForDocumentMarker):

  • platform/graphics/win/PlatformContextDirect2D.cpp:

(WebCore::PlatformContextDirect2D::brushWithColor):

  • platform/ios/ColorIOS.mm:

(WebCore::colorFromUIColor):

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paintCompositionBackground):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::paintResizer):

  • rendering/RenderLayerBacking.cpp:

(WebCore::patternForTouchAction):
(WebCore::patternForEventListenerRegionType):

  • rendering/RenderThemeAdwaita.cpp:
  • rendering/RenderThemeMac.mm:

(WebCore::menuBackgroundColor):

Source/WebKit:

  • UIProcess/ios/WKContentViewInteraction.mm:

(compositionHighlights):
Update for new name of CompositionHighlight::defaultCompositionFillColor.

Tools:

  • TestWebKitAPI/Tests/WebCore/ColorTests.cpp:

(TestWebKitAPI::TEST):
Update test for rename of makeRGBAFromHSLA to makeSimpleColorFromHSLA.

Location:
trunk
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r262127 r262128  
     12020-05-24  Sam Weinig  <weinig@apple.com>
     2
     3        Extended Color Cleanup: Use the name SimpleColor consistently
     4        https://bugs.webkit.org/show_bug.cgi?id=212337
     5
     6        Reviewed by Anders Carlsson.
     7       
     8        - Removes RGBA32 type alias, updating all remaining users of it.
     9        - Renames functions that take/return SimpleColor to use the name
     10          SimpleColor rather than RGB (e.g. makeRGBA -> makeSimpleColor)
     11        - Moves hex color parsing from Color to SimpleColor, as that is
     12          the type it returns. Also took the opportunity to make it return
     13          an Optional<SimpleColor> instead of using a bool/out parameter.
     14        - Move Color::compositionFill to editing/CompositionHighlight.h
     15          It makes no real sense to keep it in Color.h
     16        - Replaces rgb() function in Color with asSimpleColor() for
     17          symmetry with asExtended().
     18        - Replaced std::max(a, std::min(value, b)) with std::clamp(value, a, b)
     19          for clarity.
     20
     21        * css/parser/CSSParserFastPaths.cpp:
     22        (WebCore::fastParseColorInternal):
     23        (WebCore::CSSParserFastPaths::parseColor):
     24        * css/parser/CSSPropertyParserHelpers.cpp:
     25        (WebCore::CSSPropertyParserHelpers::parseRGBParameters):
     26        (WebCore::CSSPropertyParserHelpers::parseHSLParameters):
     27        (WebCore::CSSPropertyParserHelpers::parseHexColor):
     28        * editing/CompositionHighlight.h:
     29        * editing/cocoa/DataDetection.mm:
     30        (WebCore::DataDetection::detectContentInRange):
     31        * html/ColorInputType.cpp:
     32        (WebCore::parseSimpleColorValue):
     33        * html/HTMLElement.cpp:
     34        (WebCore::parseColorStringWithCrazyLegacyRules):
     35        * platform/adwaita/ScrollbarThemeAdwaita.cpp:
     36        * platform/adwaita/ThemeAdwaita.cpp:
     37        (WebCore::ThemeAdwaita::activeSelectionForegroundColor const):
     38        (WebCore::ThemeAdwaita::activeSelectionBackgroundColor const):
     39        (WebCore::ThemeAdwaita::inactiveSelectionForegroundColor const):
     40        * platform/graphics/Color.cpp:
     41        (WebCore::differenceSquared):
     42        (WebCore::Color::Color):
     43        (WebCore::Color::operator=):
     44        (WebCore::Color::serialized const):
     45        (WebCore::Color::cssText const):
     46        (WebCore::Color::nameForRenderTreeAsText const):
     47        (WebCore::Color::light const):
     48        (WebCore::Color::dark const):
     49        (WebCore::Color::blend const):
     50        (WebCore::Color::blendWithWhite const):
     51        (WebCore::Color::colorWithAlpha const):
     52        (WebCore::Color::colorWithAlphaUsingAlternativeRounding const):
     53        (WebCore::Color::invertedColorWithAlpha const):
     54        (WebCore::Color::colorSpaceAndComponents const):
     55        (WebCore::Color::toSRGBASimpleColorLossy const):
     56        (WebCore::blend):
     57        (WebCore::Color::tagAsValid):
     58        (WebCore::parseHexColorInternal): Deleted.
     59        (WebCore::Color::parseHexColor): Deleted.
     60        (WebCore::Color::asExtended const): Deleted.
     61        * platform/graphics/Color.h:
     62        (WebCore::Color::Color):
     63        (WebCore::Color::isHashTableDeletedValue const):
     64        (WebCore::Color::isValid const):
     65        (WebCore::Color::isOpaque const):
     66        (WebCore::Color::isVisible const):
     67        (WebCore::Color::alpha const):
     68        (WebCore::Color::alphaAsFloat const):
     69        (WebCore::Color::isSemantic const):
     70        (WebCore::Color::isExtended const):
     71        (WebCore::Color::setIsSemantic):
     72        (WebCore::operator==):
     73        (WebCore::equalIgnoringSemanticColor):
     74        (WebCore::Color::hash const):
     75        (WebCore::Color::asExtended const):
     76        (WebCore::Color::asSimpleColor const):
     77        (WebCore::Color::setSimpleColor):
     78        (WebCore::Color::isBlackColor):
     79        (WebCore::Color::isWhiteColor):
     80        (WebCore::Color::encode const):
     81        (WebCore::Color::decode):
     82        (WebCore::Color::setRGB): Deleted.
     83        (WebCore::Color::rgb const): Deleted.
     84        * platform/graphics/ColorUtilities.h:
     85        (WebCore::clampedColorComponent):
     86        * platform/graphics/ImageBackingStore.h:
     87        (WebCore::ImageBackingStore::blendPixel):
     88        (WebCore::ImageBackingStore::pixelValue const):
     89        * platform/graphics/SimpleColor.cpp:
     90        (WebCore::makePremultipliedSimpleColor):
     91        (WebCore::makeUnpremultipliedSimpleColor):
     92        (WebCore::makeSimpleColorFromFloats):
     93        (WebCore::makeSimpleColorFromHSLA):
     94        (WebCore::makeSimpleColorFromCMYKA):
     95        (WebCore::parseHexColorInternal):
     96        (WebCore::SimpleColor::parseHexColor):
     97        (WebCore::makePremultipliedRGBA): Deleted.
     98        (WebCore::makeUnPremultipliedRGBA): Deleted.
     99        (WebCore::makeRGBA32FromFloats): Deleted.
     100        (WebCore::makeRGBAFromHSLA): Deleted.
     101        (WebCore::makeRGBAFromCMYKA): Deleted.
     102        * platform/graphics/SimpleColor.h:
     103        (WebCore::roundAndClampColorChannel):
     104        (WebCore::colorFloatToSimpleColorByte):
     105        (WebCore::makeSimpleColor):
     106        (WebCore::colorFloatToRGBAByte): Deleted.
     107        (WebCore::makeRGB): Deleted.
     108        (WebCore::makeRGBA): Deleted.
     109        * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
     110        (WebCore::makeSimpleColorFromARGBCFArray):
     111        (WebCore::InbandTextTrackPrivateAVF::processCueAttributes):
     112        (WebCore::makeRGBA32FromARGBCFArray): Deleted.
     113        * platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
     114        (WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):
     115        * platform/graphics/cairo/NativeImageCairo.cpp:
     116        (WebCore::nativeImageSinglePixelSolidColor):
     117        * platform/graphics/cg/ColorCG.cpp:
     118        (WebCore::makeSimpleColorFromCGColor):
     119        (WebCore::Color::Color):
     120        (WebCore::cachedCGColor):
     121        (WebCore::makeRGBAFromCGColor): Deleted.
     122        * platform/graphics/gtk/ColorGtk.cpp:
     123        (WebCore::Color::Color):
     124        * platform/graphics/mac/ColorMac.mm:
     125        (WebCore::makeSimpleColorFromNSColor):
     126        (WebCore::colorFromNSColor):
     127        (WebCore::semanticColorFromNSColor):
     128        (WebCore::makeRGBAFromNSColor): Deleted.
     129        * platform/graphics/win/ColorDirect2D.cpp:
     130        (WebCore::Color::Color):
     131        * platform/graphics/win/GraphicsContextCGWin.cpp:
     132        (WebCore::GraphicsContext::drawDotsForDocumentMarker):
     133        * platform/graphics/win/PlatformContextDirect2D.cpp:
     134        (WebCore::PlatformContextDirect2D::brushWithColor):
     135        * platform/ios/ColorIOS.mm:
     136        (WebCore::colorFromUIColor):
     137        * rendering/InlineTextBox.cpp:
     138        (WebCore::InlineTextBox::paintCompositionBackground):
     139        * rendering/RenderLayer.cpp:
     140        (WebCore::RenderLayer::paintResizer):
     141        * rendering/RenderLayerBacking.cpp:
     142        (WebCore::patternForTouchAction):
     143        (WebCore::patternForEventListenerRegionType):
     144        * rendering/RenderThemeAdwaita.cpp:
     145        * rendering/RenderThemeMac.mm:
     146        (WebCore::menuBackgroundColor):
     147
    11482020-05-25  Zalan Bujtas  <zalan@apple.com>
    2149
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r259585 r262128  
    410410
    411411template <typename CharacterType>
    412 static Color fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
     412static Optional<SimpleColor> fastParseColorInternal(const CharacterType* characters, unsigned length, bool quirksMode)
    413413{
    414414    CSSUnitType expect = CSSUnitType::CSS_UNKNOWN;
    415415
    416416    if (length >= 4 && characters[0] == '#') {
    417         RGBA32 rgb;
    418         if (Color::parseHexColor(characters + 1, length - 1, rgb))
    419             return Color(rgb);
     417        if (auto color = SimpleColor::parseHexColor(characters + 1, length - 1))
     418            return color;
    420419    }
    421420
    422421    if (quirksMode && (length == 3 || length == 6)) {
    423         RGBA32 rgb;
    424         if (Color::parseHexColor(characters, length, rgb))
    425             return Color(rgb);
     422        if (auto color = SimpleColor::parseHexColor(characters, length))
     423            return color;
    426424    }
    427425
     
    436434
    437435        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    438             return Color();
     436            return WTF::nullopt;
    439437        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    440             return Color();
     438            return WTF::nullopt;
    441439        if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
    442             return Color();
     440            return WTF::nullopt;
    443441        if (!parseAlphaValue(current, end, ')', alpha))
    444             return Color();
     442            return WTF::nullopt;
    445443        if (current != end)
    446             return Color();
    447         return Color(makeRGBA(red, green, blue, alpha));
     444            return WTF::nullopt;
     445        return makeSimpleColor(red, green, blue, alpha);
    448446    }
    449447
     
    456454        int blue;
    457455        if (!parseColorIntOrPercentage(current, end, ',', expect, red))
    458             return Color();
     456            return WTF::nullopt;
    459457        if (!parseColorIntOrPercentage(current, end, ',', expect, green))
    460             return Color();
     458            return WTF::nullopt;
    461459        if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
    462             return Color();
     460            return WTF::nullopt;
    463461        if (current != end)
    464             return Color();
    465         return Color(makeRGB(red, green, blue));
    466     }
    467 
    468     return Color();
     462            return WTF::nullopt;
     463        return makeSimpleColor(red, green, blue);
     464    }
     465
     466    return WTF::nullopt;
    469467}
    470468
     
    482480
    483481    // Fast path for hex colors and rgb()/rgba() colors
    484     Color color;
     482    Optional<SimpleColor> color;
    485483    if (string.is8Bit())
    486484        color = fastParseColorInternal(string.characters8(), string.length(), quirksMode);
    487485    else
    488486        color = fastParseColorInternal(string.characters16(), string.length(), quirksMode);
    489     if (!color.isValid())
     487    if (!color)
    490488        return nullptr;
    491     return valuePool.createColorValue(color);
     489    return valuePool.createColorValue(*color);
    492490}
    493491
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r259703 r262128  
    530530{
    531531    ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);
    532     Color result;
    533532    CSSParserTokenRange args = consumeFunction(range);
    534533    RefPtr<CSSPrimitiveValue> colorParameter = consumeNumber(args, ValueRangeAll);
     
    589588    };
    590589
    591     result = Color(makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent));
    592 
    593590    if (!args.atEnd())
    594591        return Color();
    595592
    596     return result;
     593    return makeSimpleColor(colorArray[0], colorArray[1], colorArray[2], alphaComponent);
    597594}
    598595
     
    646643        return Color();
    647644
    648     return Color(makeRGBAFromHSLA(static_cast<float>(colorArray[0]), static_cast<float>(colorArray[1]), static_cast<float>(colorArray[2]), static_cast<float>(alpha)));
     645    return makeSimpleColorFromHSLA(static_cast<float>(colorArray[0]), static_cast<float>(colorArray[1]), static_cast<float>(colorArray[2]), static_cast<float>(alpha));
    649646}
    650647
     
    696693static Color parseHexColor(CSSParserTokenRange& range, bool acceptQuirkyColors)
    697694{
    698     RGBA32 result;
     695    SimpleColor result;
    699696    const CSSParserToken& token = range.peek();
    700697    if (token.type() == HashToken) {
    701         if (!Color::parseHexColor(token.value(), result))
     698        auto simpleColor = SimpleColor::parseHexColor(token.value());
     699        if (!simpleColor)
    702700            return Color();
     701        result = *simpleColor;
    703702    } else if (acceptQuirkyColors) {
    704703        String color;
     
    719718        if (length != 3 && length != 6)
    720719            return Color();
    721         if (!Color::parseHexColor(color, result))
     720        auto simpleColor = SimpleColor::parseHexColor(color);
     721        if (!simpleColor)
    722722            return Color();
     723        result = *simpleColor;
    723724    } else {
    724725        return Color();
    725726    }
    726727    range.consumeIncludingWhitespace();
    727     return Color(result);
     728    return result;
    728729}
    729730
  • trunk/Source/WebCore/editing/CompositionHighlight.h

    r255532 r262128  
    4040    }
    4141
     42#if PLATFORM(IOS_FAMILY)
     43    static constexpr SimpleColor defaultCompositionFillColor { 0x3CAFC0E3 };
     44#else
     45    static constexpr SimpleColor defaultCompositionFillColor { 0xFFE1DD55 };
     46#endif
     47
    4248    unsigned startOffset { 0 };
    4349    unsigned endOffset { 0 };
    44     Color color { Color::compositionFill };
     50    Color color { defaultCompositionFillColor };
    4551
    4652    template<class Encoder> void encode(Encoder&) const;
  • trunk/Source/WebCore/editing/cocoa/DataDetection.mm

    r261967 r262128  
    626626                        double overrideLightness = 0.5;
    627627                        double overrideAlphaMultiplier = 0.38;
    628                         auto underlineColor = Color(makeRGBAFromHSLA(hue, saturation, overrideLightness, overrideAlphaMultiplier * alpha));
     628                        auto underlineColor = makeSimpleColorFromHSLA(hue, saturation, overrideLightness, overrideAlphaMultiplier * alpha);
    629629
    630630                        anchorElement->setInlineStyleProperty(CSSPropertyColor, CSSValueCurrentcolor);
    631                         anchorElement->setInlineStyleProperty(CSSPropertyTextDecorationColor, underlineColor.cssText());
     631                        anchorElement->setInlineStyleProperty(CSSPropertyTextDecorationColor, underlineColor.serializationForCSS());
    632632                    }
    633633                }
  • trunk/Source/WebCore/html/ColorInputType.cpp

    r261013 r262128  
    6969
    7070// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-simple-colour-values
    71 static Optional<RGBA32> parseSimpleColorValue(StringView string)
     71static Optional<SimpleColor> parseSimpleColorValue(StringView string)
    7272{
    7373    if (!isValidSimpleColor(string))
    7474        return WTF::nullopt;
    75     return makeRGB(toASCIIHexValue(string[1], string[2]), toASCIIHexValue(string[3], string[4]), toASCIIHexValue(string[5], string[6]));
     75    return makeSimpleColor(toASCIIHexValue(string[1], string[2]), toASCIIHexValue(string[3], string[4]), toASCIIHexValue(string[5], string[6]));
    7676}
    7777
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r262035 r262128  
    974974}
    975975
    976 static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString)
     976static SimpleColor parseColorStringWithCrazyLegacyRules(const String& colorString)
    977977{
    978978    // Per spec, only look at the first 128 digits of the string.
     
    10031003
    10041004    if (digitBuffer.size() < 6)
    1005         return makeRGB(toASCIIHexValue(digitBuffer[0]), toASCIIHexValue(digitBuffer[1]), toASCIIHexValue(digitBuffer[2]));
     1005        return makeSimpleColor(toASCIIHexValue(digitBuffer[0]), toASCIIHexValue(digitBuffer[1]), toASCIIHexValue(digitBuffer[2]));
    10061006
    10071007    // Split the digits into three components, then search the last 8 digits of each component.
     
    10271027    int greenValue = toASCIIHexValue(digitBuffer[greenIndex], digitBuffer[greenIndex + 1]);
    10281028    int blueValue = toASCIIHexValue(digitBuffer[blueIndex], digitBuffer[blueIndex + 1]);
    1029     return makeRGB(redValue, greenValue, blueValue);
     1029    return makeSimpleColor(redValue, greenValue, blueValue);
    10301030}
    10311031
  • trunk/Source/WebCore/platform/adwaita/ScrollbarThemeAdwaita.cpp

    r260071 r262128  
    4444static const unsigned thumbSize = 6;
    4545static const double scrollbarOpacity = 0.8;
    46 static const Color scrollbarBackgroundColor = makeRGB(252, 252, 252);
    47 static const Color scrollbarBorderColor = makeRGB(220, 223, 227);
    48 static const Color overlayThumbBorderColor = makeRGBA(255, 255, 255, 100);
    49 static const Color overlayThumbColor = makeRGBA(46, 52, 54, 100);
    50 static const Color thumbHoveredColor = makeRGB(86, 91, 92);
    51 static const Color thumbPressedColor = makeRGB(27, 106, 203);
    52 static const Color thumbColor = makeRGB(126, 129, 130);
     46static const Color scrollbarBackgroundColor = makeSimpleColor(252, 252, 252);
     47static const Color scrollbarBorderColor = makeSimpleColor(220, 223, 227);
     48static const Color overlayThumbBorderColor = makeSimpleColor(255, 255, 255, 100);
     49static const Color overlayThumbColor = makeSimpleColor(46, 52, 54, 100);
     50static const Color thumbHoveredColor = makeSimpleColor(86, 91, 92);
     51static const Color thumbPressedColor = makeSimpleColor(27, 106, 203);
     52static const Color thumbColor = makeSimpleColor(126, 129, 130);
    5353
    5454bool ScrollbarThemeAdwaita::usesOverlayScrollbars() const
  • trunk/Source/WebCore/platform/adwaita/ThemeAdwaita.cpp

    r260058 r262128  
    3737
    3838static const unsigned focusLineWidth = 1;
    39 static const Color focusRingColor = makeRGBA(46, 52, 54, 150);
     39static const Color focusRingColor = makeSimpleColor(46, 52, 54, 150);
    4040static const unsigned arrowSize = 16;
    41 static const Color arrowColor = makeRGB(46, 52, 54);
     41static const Color arrowColor = makeSimpleColor(46, 52, 54);
    4242static const int buttonFocusOffset = -3;
    4343static const unsigned buttonPadding = 5;
    4444static const int buttonBorderSize = 1; // Keep in sync with menuListButtonBorderSize in RenderThemeAdwaita.
    45 static const Color buttonBorderColor = makeRGB(205, 199, 194);
    46 static const Color buttonBackgroundColor = makeRGB(244, 242, 241);
    47 static const Color buttonBackgroundPressedColor = makeRGB(214, 209, 205);
    48 static const Color buttonBackgroundHoveredColor = makeRGB(248, 248, 247);
    49 static const Color buttonBackgroundDisabledColor = makeRGB(246, 246, 244);
    50 static const Color toggleBackgroundColor = makeRGB(255, 255, 255);
    51 static const Color toggleBackgroundHoveredColor = makeRGB(242, 242, 242);
    52 static const Color toggleBackgroundDisabledColor = makeRGB(252, 252, 252);
     45static const Color buttonBorderColor = makeSimpleColor(205, 199, 194);
     46static const Color buttonBackgroundColor = makeSimpleColor(244, 242, 241);
     47static const Color buttonBackgroundPressedColor = makeSimpleColor(214, 209, 205);
     48static const Color buttonBackgroundHoveredColor = makeSimpleColor(248, 248, 247);
     49static const Color buttonBackgroundDisabledColor = makeSimpleColor(246, 246, 244);
     50static const Color toggleBackgroundColor = makeSimpleColor(255, 255, 255);
     51static const Color toggleBackgroundHoveredColor = makeSimpleColor(242, 242, 242);
     52static const Color toggleBackgroundDisabledColor = makeSimpleColor(252, 252, 252);
    5353static const double toggleSize = 14.;
    5454static const int toggleFocusOffset = 2;
    55 static const Color toggleColor = makeRGB(46, 52, 54);
    56 static const Color toggleDisabledColor = makeRGB(160, 160, 160);
    57 static const Color spinButtonBorderColor = makeRGB(220, 223, 227);
    58 static const Color spinButtonBackgroundColor = makeRGB(252, 252, 252);
    59 static const Color spinButtonBackgroundHoveredColor = makeRGBA(46, 52, 54, 50);
    60 static const Color spinButtonBackgroundPressedColor = makeRGBA(46, 52, 54, 70);
     55static const Color toggleColor = makeSimpleColor(46, 52, 54);
     56static const Color toggleDisabledColor = makeSimpleColor(160, 160, 160);
     57static const Color spinButtonBorderColor = makeSimpleColor(220, 223, 227);
     58static const Color spinButtonBackgroundColor = makeSimpleColor(252, 252, 252);
     59static const Color spinButtonBackgroundHoveredColor = makeSimpleColor(46, 52, 54, 50);
     60static const Color spinButtonBackgroundPressedColor = makeSimpleColor(46, 52, 54, 70);
    6161
    6262#if !PLATFORM(GTK) || USE(GTK4)
     
    7070Color ThemeAdwaita::activeSelectionForegroundColor() const
    7171{
    72     return makeRGB(255, 255, 255);
     72    return makeSimpleColor(255, 255, 255);
    7373}
    7474
    7575Color ThemeAdwaita::activeSelectionBackgroundColor() const
    7676{
    77     return makeRGB(52, 132, 228);
     77    return makeSimpleColor(52, 132, 228);
    7878}
    7979
    8080Color ThemeAdwaita::inactiveSelectionForegroundColor() const
    8181{
    82     return makeRGB(252, 252, 252);
     82    return makeSimpleColor(252, 252, 252);
    8383}
    8484
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r262110 r262128  
    3131#include "HashTools.h"
    3232#include <wtf/Assertions.h>
    33 #include <wtf/HexNumber.h>
    3433#include <wtf/MathExtras.h>
    3534#include <wtf/text/StringBuilder.h>
     
    4039static constexpr SimpleColor lightenedBlack { 0xFF545454 };
    4140static constexpr SimpleColor darkenedWhite { 0xFFABABAB };
    42 
    43 // originally moved here from the CSS parser
    44 template <typename CharacterType>
    45 static inline bool parseHexColorInternal(const CharacterType* name, unsigned length, RGBA32& rgb)
    46 {
    47     if (length != 3 && length != 4 && length != 6 && length != 8)
    48         return false;
    49     unsigned value = 0;
    50     for (unsigned i = 0; i < length; ++i) {
    51         if (!isASCIIHexDigit(name[i]))
    52             return false;
    53         value <<= 4;
    54         value |= toASCIIHexValue(name[i]);
    55     }
    56     if (length == 6) {
    57         rgb = { 0xFF000000 | value };
    58         return true;
    59     }
    60     if (length == 8) {
    61         // We parsed the values into RGBA order, but the RGBA32 type
    62         // expects them to be in ARGB order, so we right rotate eight bits.
    63         rgb = { value << 24 | value >> 8 };
    64         return true;
    65     }
    66     if (length == 4) {
    67         // #abcd converts to ddaabbcc in RGBA32.
    68         rgb = { (value & 0xF) << 28 | (value & 0xF) << 24
    69             | (value & 0xF000) << 8 | (value & 0xF000) << 4
    70             | (value & 0xF00) << 4 | (value & 0xF00)
    71             | (value & 0xF0) | (value & 0xF0) >> 4 };
    72         return true;
    73     }
    74     // #abc converts to #aabbcc
    75     rgb = { 0xFF000000
    76         | (value & 0xF00) << 12 | (value & 0xF00) << 8
    77         | (value & 0xF0) << 8 | (value & 0xF0) << 4
    78         | (value & 0xF) << 4 | (value & 0xF) };
    79     return true;
    80 }
    81 
    82 bool Color::parseHexColor(const LChar* name, unsigned length, RGBA32& rgb)
    83 {
    84     return parseHexColorInternal(name, length, rgb);
    85 }
    86 
    87 bool Color::parseHexColor(const UChar* name, unsigned length, RGBA32& rgb)
    88 {
    89     return parseHexColorInternal(name, length, rgb);
    90 }
    91 
    92 bool Color::parseHexColor(const String& name, RGBA32& rgb)
    93 {
    94     unsigned length = name.length();
    95     if (!length)
    96         return false;
    97     if (name.is8Bit())
    98         return parseHexColor(name.characters8(), name.length(), rgb);
    99     return parseHexColor(name.characters16(), name.length(), rgb);
    100 }
    101 
    102 bool Color::parseHexColor(const StringView& name, RGBA32& rgb)
    103 {
    104     unsigned length = name.length();
    105     if (!length)
    106         return false;
    107     if (name.is8Bit())
    108         return parseHexColor(name.characters8(), name.length(), rgb);
    109     return parseHexColor(name.characters16(), name.length(), rgb);
    110 }
    11141
    11242int differenceSquared(const Color& c1, const Color& c2)
     
    11646    // sites have picked comparison values based on feel. We'd need to break out
    11747    // our logarithm tables to change them :)
    118     int c1Red = c1.isExtended() ? c1.asExtended().red() * 255 : c1.rgb().redComponent();
    119     int c1Green = c1.isExtended() ? c1.asExtended().green() * 255 : c1.rgb().greenComponent();
    120     int c1Blue = c1.isExtended() ? c1.asExtended().blue() * 255 : c1.rgb().blueComponent();
    121     int c2Red = c2.isExtended() ? c2.asExtended().red() * 255 : c2.rgb().redComponent();
    122     int c2Green = c2.isExtended() ? c2.asExtended().green() * 255 : c2.rgb().greenComponent();
    123     int c2Blue = c2.isExtended() ? c2.asExtended().blue() * 255 : c2.rgb().blueComponent();
     48    int c1Red = c1.isExtended() ? c1.asExtended().red() * 255 : c1.asSimpleColor().redComponent();
     49    int c1Green = c1.isExtended() ? c1.asExtended().green() * 255 : c1.asSimpleColor().greenComponent();
     50    int c1Blue = c1.isExtended() ? c1.asExtended().blue() * 255 : c1.asSimpleColor().blueComponent();
     51    int c2Red = c2.isExtended() ? c2.asExtended().red() * 255 : c2.asSimpleColor().redComponent();
     52    int c2Green = c2.isExtended() ? c2.asExtended().green() * 255 : c2.asSimpleColor().greenComponent();
     53    int c2Blue = c2.isExtended() ? c2.asExtended().blue() * 255 : c2.asSimpleColor().blueComponent();
    12454    int dR = c1Red - c2Red;
    12555    int dG = c1Green - c2Green;
     
    14777{
    14878    if (name[0] == '#') {
    149         RGBA32 color;
    150         bool valid;
    151 
     79        Optional<SimpleColor> color;
    15280        if (name.is8Bit())
    153             valid = parseHexColor(name.characters8() + 1, name.length() - 1, color);
     81            color = SimpleColor::parseHexColor(name.characters8() + 1, name.length() - 1);
    15482        else
    155             valid = parseHexColor(name.characters16() + 1, name.length() - 1, color);
    156 
    157         if (valid)
    158             setRGB(color);
     83            color = SimpleColor::parseHexColor(name.characters16() + 1, name.length() - 1);
     84
     85        if (color)
     86            setSimpleColor(*color);
    15987    } else {
    16088        if (auto* foundColor = findNamedColor(name))
    161             setRGB({ foundColor->ARGBValue });
     89            setSimpleColor({ foundColor->ARGBValue });
    16290    }
    16391}
     
    16694{
    16795    if (name[0] == '#') {
    168         SimpleColor color;
    169         if (parseHexColor(reinterpret_cast<const LChar*>(&name[1]), std::strlen(&name[1]), color))
    170             setRGB(color);
     96        auto color = SimpleColor::parseHexColor(reinterpret_cast<const LChar*>(&name[1]), std::strlen(&name[1]));
     97        if (color)
     98            setSimpleColor(*color);
    17199    } else if (auto* foundColor = findColor(name, strlen(name)))
    172         setRGB({ foundColor->ARGBValue });
     100        setSimpleColor({ foundColor->ARGBValue });
    173101}
    174102
     
    193121{
    194122    // Zero the union, just in case a 32-bit system only assigns the
    195     // top 32 bits when copying the extendedColor pointer below.
    196     m_colorData.rgbaAndFlags = 0;
     123    // top 32 bits when copying the ExtendedColor pointer below.
     124    m_colorData.simpleColorAndFlags = 0;
    197125    m_colorData.extendedColor = &extendedColor.leakRef();
    198126    ASSERT(isExtended());
     
    223151
    224152    m_colorData = other.m_colorData;
    225     other.m_colorData.rgbaAndFlags = invalidRGBAColor;
     153    other.m_colorData.simpleColorAndFlags = invalidSimpleColor;
    226154
    227155    return *this;
     
    232160    if (isExtended())
    233161        return asExtended().cssText();
    234     return rgb().serializationForHTML();
     162    return asSimpleColor().serializationForHTML();
    235163}
    236164
     
    239167    if (isExtended())
    240168        return asExtended().cssText();
    241     return rgb().serializationForCSS();
     169    return asSimpleColor().serializationForCSS();
    242170}
    243171
    244172String Color::nameForRenderTreeAsText() const
    245173{
    246     // FIXME: Handle extended colors.
    247     return rgb().serializationForRenderTreeAsText();
     174    return asSimpleColor().serializationForRenderTreeAsText();
    248175}
    249176
     
    251178{
    252179    // Hardcode this common case for speed.
    253     if (rgb() == black)
     180    if (asSimpleColor() == black)
    254181        return lightenedBlack;
    255182   
     
    276203{
    277204    // Hardcode this common case for speed.
    278     if (rgb() == white)
     205    if (asSimpleColor() == white)
    279206        return darkenedWhite;
    280207   
     
    325252    int b = (selfB * selfA * (0xFF - sourceA) + 0xFF * sourceA * sourceB) / d;
    326253
    327     return makeRGBA(r, g, b, a);
     254    return makeSimpleColor(r, g, b, a);
    328255}
    329256
     
    355282        int b = blendComponent(existingB, alpha);
    356283       
    357         result = makeRGBA(r, g, b, alpha);
     284        result = makeSimpleColor(r, g, b, alpha);
    358285
    359286        if (r >= 0 && g >= 0 && b >= 0)
     
    389316    uint8_t newAlpha = alpha * 0xFF;
    390317
    391     Color result = rgb().colorWithAlpha(newAlpha);
     318    Color result = asSimpleColor().colorWithAlpha(newAlpha);
    392319    if (isSemantic())
    393320        result.setIsSemantic();
     
    403330
    404331    // FIXME: This is where this function differs from colorWithAlphaUsing.
    405     uint8_t newAlpha = colorFloatToRGBAByte(alpha);
    406 
    407     Color result = rgb().colorWithAlpha(newAlpha);
     332    uint8_t newAlpha = colorFloatToSimpleColorByte(alpha);
     333
     334    Color result = asSimpleColor().colorWithAlpha(newAlpha);
    408335    if (isSemantic())
    409336        result.setIsSemantic();
     
    416343        return Color { asExtended().invertedColorWithAlpha(alpha) };
    417344
    418     auto [r, g, b, existingAlpha] = rgb();
    419     return { 0xFF - r, 0xFF - g, 0xFF - b, colorFloatToRGBAByte(alpha) };
     345    auto [r, g, b, existingAlpha] = asSimpleColor();
     346    return { 0xFF - r, 0xFF - g, 0xFF - b, colorFloatToSimpleColorByte(alpha) };
    420347}
    421348
     
    435362    }
    436363
    437     auto [r, g, b, a] = rgb();
     364    auto [r, g, b, a] = asSimpleColor();
    438365    return { ColorSpace::SRGB, FloatComponents { r / 255.0f, g / 255.0f, b / 255.0f,  a / 255.0f } };
    439366}
     
    441368SimpleColor Color::toSRGBASimpleColorLossy() const
    442369{
    443     if (!isExtended())
    444         return rgb();
    445 
    446     auto [r, g, b, a] = toSRGBAComponentsLossy();
    447     return makeRGBA32FromFloats(r, g, b, a);
     370    if (isExtended()) {
     371        auto [r, g, b, a] = toSRGBAComponentsLossy();
     372        return makeSimpleColorFromFloats(r, g, b, a);
     373    }
     374
     375    return asSimpleColor();
    448376}
    449377
     
    477405    // We need to preserve the state of the valid flag at the end of the animation
    478406    if (progress == 1 && !to.isValid())
    479         return Color();
    480 
    481     // Since makePremultipliedRGBA() bails on zero alpha, special-case that.
    482     auto premultFrom = from.alpha() ? makePremultipliedRGBA(from.toSRGBASimpleColorLossy()) : Color::transparent;
    483     auto premultTo = to.alpha() ? makePremultipliedRGBA(to.toSRGBASimpleColorLossy()) : Color::transparent;
    484 
    485     RGBA32 premultBlended = makeRGBA(
     407        return { };
     408
     409    // Since makePremultipliedSimpleColor() bails on zero alpha, special-case that.
     410    auto premultFrom = from.alpha() ? makePremultipliedSimpleColor(from.toSRGBASimpleColorLossy()) : Color::transparent;
     411    auto premultTo = to.alpha() ? makePremultipliedSimpleColor(to.toSRGBASimpleColorLossy()) : Color::transparent;
     412
     413    SimpleColor premultBlended = makeSimpleColor(
    486414        WebCore::blend(premultFrom.redComponent(), premultTo.redComponent(), progress),
    487415        WebCore::blend(premultFrom.greenComponent(), premultTo.greenComponent(), progress),
     
    490418    );
    491419
    492     return makeUnPremultipliedRGBA(premultBlended);
     420    return makeUnpremultipliedSimpleColor(premultBlended);
    493421}
    494422
     
    513441void Color::tagAsValid()
    514442{
    515     m_colorData.rgbaAndFlags |= validRGBAColor;
    516 }
    517 
    518 const ExtendedColor& Color::asExtended() const
    519 {
    520     ASSERT(isExtended());
    521     return *m_colorData.extendedColor;
     443    m_colorData.simpleColorAndFlags |= validSimpleColor;
    522444}
    523445
  • trunk/Source/WebCore/platform/graphics/Color.h

    r262110 r262128  
    2929#include "ExtendedColor.h"
    3030#include "SimpleColor.h"
    31 #include <algorithm>
    32 #include <cmath>
    33 #include <unicode/uchar.h>
    3431#include <wtf/Forward.h>
    3532#include <wtf/HashFunctions.h>
    3633#include <wtf/Optional.h>
    37 #include <wtf/text/LChar.h>
    3834
    3935#if USE(CG)
     
    6561    // FIXME: Remove all these constructors and creation functions and replace the ones that are still needed with free functions.
    6662
    67     Color(RGBA32 color, bool valid = true)
     63    Color(SimpleColor color, bool valid = true)
    6864    {
    6965        if (valid)
    70             setRGB(color);
     66            setSimpleColor(color);
    7167    }
    7268
    7369    enum SemanticTag { Semantic };
    74     Color(RGBA32 color, SemanticTag)
    75     {
    76         setRGB(color);
     70    Color(SimpleColor color, SemanticTag)
     71    {
     72        setSimpleColor(color);
    7773        setIsSemantic();
    7874    }
     
    8076    Color(int r, int g, int b)
    8177    {
    82         setRGB(r, g, b);
     78        setSimpleColor(makeSimpleColor(r, g, b));
    8379    }
    8480
    8581    Color(int r, int g, int b, int a)
    8682    {
    87         setRGB(makeRGBA(r, g, b, a));
     83        setSimpleColor(makeSimpleColor(r, g, b, a));
    8884    }
    8985
    9086    Color(float r, float g, float b, float a)
    9187    {
    92         setRGB(makeRGBA32FromFloats(r, g, b, a));
     88        setSimpleColor(makeSimpleColorFromFloats(r, g, b, a));
    9389    }
    9490
     
    9692    Color(float c, float m, float y, float k, float a)
    9793    {
    98         setRGB(makeRGBAFromCMYKA(c, m, y, k, a));
     94        setSimpleColor(makeSimpleColorFromCMYKA(c, m, y, k, a));
    9995    }
    10096
     
    104100    explicit Color(WTF::HashTableDeletedValueType)
    105101    {
    106         static_assert(deletedHashValue & invalidRGBAColor, "Color's deleted hash value must not look like an ExtendedColor");
    107         static_assert(!(deletedHashValue & validRGBAColorBit), "Color's deleted hash value must not look like a valid RGBA32 Color");
    108         static_assert(deletedHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an RGBA32 Color wouldn't have");
    109         m_colorData.rgbaAndFlags = deletedHashValue;
     102        static_assert(deletedHashValue & invalidSimpleColor, "Color's deleted hash value must not look like an ExtendedColor");
     103        static_assert(!(deletedHashValue & validSimpleColorBit), "Color's deleted hash value must not look like a valid SimpleColor");
     104        static_assert(deletedHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an SimpleColor wouldn't have");
     105        m_colorData.simpleColorAndFlags = deletedHashValue;
    110106        ASSERT(!isExtended());
    111107    }
     
    113109    bool isHashTableDeletedValue() const
    114110    {
    115         return m_colorData.rgbaAndFlags == deletedHashValue;
     111        return m_colorData.simpleColorAndFlags == deletedHashValue;
    116112    }
    117113
    118114    explicit Color(WTF::HashTableEmptyValueType)
    119115    {
    120         static_assert(emptyHashValue & invalidRGBAColor, "Color's empty hash value must not look like an ExtendedColor");
    121         static_assert(emptyHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an RGBA32 Color wouldn't have");
    122         m_colorData.rgbaAndFlags = emptyHashValue;
     116        static_assert(emptyHashValue & invalidSimpleColor, "Color's empty hash value must not look like an ExtendedColor");
     117        static_assert(emptyHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an SimpleColor wouldn't have");
     118        m_colorData.simpleColorAndFlags = emptyHashValue;
    123119        ASSERT(!isExtended());
    124120    }
     
    148144    String nameForRenderTreeAsText() const;
    149145
    150     bool isValid() const { return isExtended() || (m_colorData.rgbaAndFlags & validRGBAColorBit); }
    151 
    152     bool isOpaque() const { return isExtended() ? asExtended().alpha() == 1.0 : rgb().isOpaque(); }
    153     bool isVisible() const { return isExtended() ? asExtended().alpha() > 0.0 : rgb().isVisible(); }
    154 
    155     int alpha() const { return isExtended() ? asExtended().alpha() * 255 : rgb().alphaComponent(); }
    156     float alphaAsFloat() const { return isExtended() ? asExtended().alpha() : rgb().alphaComponentAsFloat(); }
     146    bool isValid() const { return isExtended() || (m_colorData.simpleColorAndFlags & validSimpleColorBit); }
     147
     148    bool isOpaque() const { return isExtended() ? asExtended().alpha() == 1.0 : asSimpleColor().isOpaque(); }
     149    bool isVisible() const { return isExtended() ? asExtended().alpha() > 0.0 : asSimpleColor().isVisible(); }
     150
     151    int alpha() const { return isExtended() ? asExtended().alpha() * 255 : asSimpleColor().alphaComponent(); }
     152    float alphaAsFloat() const { return isExtended() ? asExtended().alpha() : asSimpleColor().alphaComponentAsFloat(); }
    157153
    158154    unsigned hash() const;
     
    192188
    193189    // True if the color originated from a CSS semantic color name.
    194     bool isSemantic() const { return !isExtended() && (m_colorData.rgbaAndFlags & isSemanticRBGAColorBit); }
     190    bool isSemantic() const { return !isExtended() && (m_colorData.simpleColorAndFlags & isSemanticSimpleColorBit); }
    195191
    196192#if PLATFORM(GTK)
     
    210206    WEBCORE_EXPORT operator D2D1_VECTOR_4F() const;
    211207#endif
    212 
    213     static bool parseHexColor(const String&, RGBA32&);
    214     static bool parseHexColor(const StringView&, RGBA32&);
    215     static bool parseHexColor(const LChar*, unsigned, RGBA32&);
    216     static bool parseHexColor(const UChar*, unsigned, RGBA32&);
    217208
    218209    static constexpr SimpleColor black { 0xFF000000 };
     
    225216    static constexpr SimpleColor yellow { 0xFFFFFF00 };
    226217
    227 #if PLATFORM(IOS_FAMILY)
    228     static constexpr SimpleColor compositionFill { 0x3CAFC0E3 };
    229 #else
    230     static constexpr SimpleColor compositionFill { 0xFFE1DD55 };
    231 #endif
    232 
    233218    bool isExtended() const
    234219    {
    235         return !(m_colorData.rgbaAndFlags & invalidRGBAColor);
    236     }
    237     WEBCORE_EXPORT const ExtendedColor& asExtended() const;
     220        return !(m_colorData.simpleColorAndFlags & invalidSimpleColor);
     221    }
     222    const ExtendedColor& asExtended() const;
    238223
    239224    WEBCORE_EXPORT Color& operator=(const Color&);
     
    253238
    254239private:
    255     RGBA32 rgb() const;
    256     void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
    257     void setRGB(RGBA32);
    258     void setIsSemantic() { m_colorData.rgbaAndFlags |= isSemanticRBGAColorBit; }
     240    const SimpleColor asSimpleColor() const;
     241
     242    void setSimpleColor(SimpleColor);
     243    void setIsSemantic() { m_colorData.simpleColorAndFlags |= isSemanticSimpleColorBit; }
    259244
    260245    // 0x_______00 is an ExtendedColor pointer.
    261     // 0x_______01 is an invalid RGBA32.
    262     // 0x_______11 is a valid RGBA32.
     246    // 0x_______01 is an invalid SimpleColor.
     247    // 0x_______11 is a valid SimpleColor.
    263248    static const uint64_t extendedColor = 0x0;
    264     static const uint64_t invalidRGBAColor = 0x1;
    265     static const uint64_t validRGBAColorBit = 0x2;
    266     static const uint64_t validRGBAColor = 0x3;
    267     static const uint64_t isSemanticRBGAColorBit = 0x4;
     249    static const uint64_t invalidSimpleColor = 0x1;
     250    static const uint64_t validSimpleColorBit = 0x2;
     251    static const uint64_t validSimpleColor = 0x3;
     252    static const uint64_t isSemanticSimpleColorBit = 0x4;
    268253
    269254    static const uint64_t deletedHashValue = 0xFFFFFFFFFFFFFFFD;
     
    273258
    274259    union {
    275         uint64_t rgbaAndFlags { invalidRGBAColor };
     260        uint64_t simpleColorAndFlags { invalidSimpleColor };
    276261        ExtendedColor* extendedColor;
    277262    } m_colorData;
     
    301286        return extendedColorsEqual(a, b);
    302287
    303     return a.m_colorData.rgbaAndFlags == b.m_colorData.rgbaAndFlags;
     288    return a.m_colorData.simpleColorAndFlags == b.m_colorData.simpleColorAndFlags;
    304289}
    305290
     
    313298    if (a.isExtended() || b.isExtended())
    314299        return extendedColorsEqual(a, b);
    315     return (a.m_colorData.rgbaAndFlags & ~Color::isSemanticRBGAColorBit) == (b.m_colorData.rgbaAndFlags & ~Color::isSemanticRBGAColorBit);
     300    return (a.m_colorData.simpleColorAndFlags & ~Color::isSemanticSimpleColorBit) == (b.m_colorData.simpleColorAndFlags & ~Color::isSemanticSimpleColorBit);
    316301}
    317302
     
    320305    if (isExtended())
    321306        return asExtended().hash();
    322 
    323     return WTF::intHash(m_colorData.rgbaAndFlags);
     307    return WTF::intHash(m_colorData.simpleColorAndFlags);
    324308}
    325309
     
    334318}
    335319
    336 inline RGBA32 Color::rgb() const
    337 {
    338     // FIXME: We should ASSERT(!isExtended()) here, or produce
    339     // an RGBA32 equivalent for an ExtendedColor. Ideally the former,
    340     // so we can audit all the rgb() call sites to handle extended.
    341     return { static_cast<uint32_t>(m_colorData.rgbaAndFlags >> 32) };
    342 }
    343 
    344 inline void Color::setRGB(RGBA32 rgb)
    345 {
    346     m_colorData.rgbaAndFlags = static_cast<uint64_t>(rgb.value()) << 32;
     320inline const ExtendedColor& Color::asExtended() const
     321{
     322    ASSERT(isExtended());
     323    return *m_colorData.extendedColor;
     324}
     325
     326inline const SimpleColor Color::asSimpleColor() const
     327{
     328    // FIXME: We should ASSERT(!isExtended()) here once we have verified all
     329    // call sites are checking isExtended().
     330    return { static_cast<uint32_t>(m_colorData.simpleColorAndFlags >> 32) };
     331}
     332
     333inline void Color::setSimpleColor(SimpleColor simpleColor)
     334{
     335    m_colorData.simpleColorAndFlags = static_cast<uint64_t>(simpleColor.value()) << 32;
    347336    tagAsValid();
    348337}
     
    355344    }
    356345
    357     return color.rgb() == Color::black;
     346    return color.asSimpleColor() == Color::black;
    358347}
    359348
     
    365354    }
    366355   
    367     return color.rgb() == Color::white;
     356    return color.asSimpleColor() == Color::white;
    368357}
    369358
     
    390379    // FIXME: This should encode whether the color is semantic.
    391380
    392     uint32_t value = rgb().value();
    393 
    394381    encoder << true;
    395     encoder << value;
     382    encoder << asSimpleColor().value();
    396383}
    397384
     
    419406        if (!decoder.decode(colorSpace))
    420407            return WTF::nullopt;
    421         return Color(red, green, blue, alpha, colorSpace);
     408        return Color { red, green, blue, alpha, colorSpace };
    422409    }
    423410
     
    427414
    428415    if (!isValid)
    429         return Color();
     416        return Color { };
    430417
    431418    uint32_t value;
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r262070 r262128  
    166166{
    167167    // See also colorFloatToRGBAByte().
    168     return std::max(0, std::min(static_cast<int>(lroundf(255.0f * f)), 255));
     168    return std::clamp(static_cast<int>(lroundf(255.0f * f)), 0, 255);
    169169}
    170170
  • trunk/Source/WebCore/platform/graphics/ImageBackingStore.h

    r255785 r262128  
    161161
    162162        if (!m_premultiplyAlpha)
    163             pixel = makePremultipliedRGBA(pixel.redComponent(), pixel.greenComponent(), pixel.blueComponent(), pixel.alphaComponent(), false);
     163            pixel = makePremultipliedSimpleColor(pixel.redComponent(), pixel.greenComponent(), pixel.blueComponent(), pixel.alphaComponent(), false);
    164164
    165165        unsigned d = 255 - a;
     
    171171
    172172        if (m_premultiplyAlpha)
    173             *dest = makeRGBA(r, g, b, a).value();
     173            *dest = makeSimpleColor(r, g, b, a).value();
    174174        else
    175             *dest = makeUnPremultipliedRGBA(r, g, b, a).value();
     175            *dest = makeUnpremultipliedSimpleColor(r, g, b, a).value();
    176176    }
    177177
     
    226226
    227227        if (m_premultiplyAlpha && a < 255)
    228             return makePremultipliedRGBA(r, g, b, a, false).value();
    229 
    230         return makeRGBA(r, g, b, a).value();
     228            return makePremultipliedSimpleColor(r, g, b, a, false).value();
     229
     230        return makeSimpleColor(r, g, b, a).value();
    231231    }
    232232
  • trunk/Source/WebCore/platform/graphics/SimpleColor.cpp

    r262110 r262128  
    4444}
    4545
    46 RGBA32 makePremultipliedRGBA(int r, int g, int b, int a, bool ceiling)
    47 {
    48     return makeRGBA(premultipliedChannel(r, a, ceiling), premultipliedChannel(g, a, ceiling), premultipliedChannel(b, a, ceiling), a);
    49 }
    50 
    51 RGBA32 makePremultipliedRGBA(RGBA32 pixelColor)
     46SimpleColor makePremultipliedSimpleColor(int r, int g, int b, int a, bool ceiling)
     47{
     48    return makeSimpleColor(premultipliedChannel(r, a, ceiling), premultipliedChannel(g, a, ceiling), premultipliedChannel(b, a, ceiling), a);
     49}
     50
     51SimpleColor makePremultipliedSimpleColor(SimpleColor pixelColor)
    5252{
    5353    if (pixelColor.isOpaque())
    5454        return pixelColor;
    55     return makePremultipliedRGBA(pixelColor.redComponent(), pixelColor.greenComponent(), pixelColor.blueComponent(), pixelColor.alphaComponent());
    56 }
    57 
    58 RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a)
    59 {
    60     return makeRGBA(unpremultipliedChannel(r, a), unpremultipliedChannel(g, a), unpremultipliedChannel(b, a), a);
    61 }
    62 
    63 RGBA32 makeUnPremultipliedRGBA(RGBA32 pixelColor)
     55    return makePremultipliedSimpleColor(pixelColor.redComponent(), pixelColor.greenComponent(), pixelColor.blueComponent(), pixelColor.alphaComponent());
     56}
     57
     58SimpleColor makeUnpremultipliedSimpleColor(int r, int g, int b, int a)
     59{
     60    return makeSimpleColor(unpremultipliedChannel(r, a), unpremultipliedChannel(g, a), unpremultipliedChannel(b, a), a);
     61}
     62
     63SimpleColor makeUnpremultipliedSimpleColor(SimpleColor pixelColor)
    6464{
    6565    if (pixelColor.isVisible() && !pixelColor.isOpaque())
    66         return makeUnPremultipliedRGBA(pixelColor.redComponent(), pixelColor.greenComponent(), pixelColor.blueComponent(), pixelColor.alphaComponent());
     66        return makeUnpremultipliedSimpleColor(pixelColor.redComponent(), pixelColor.greenComponent(), pixelColor.blueComponent(), pixelColor.alphaComponent());
    6767    return pixelColor;
    6868}
    6969
    70 RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a)
    71 {
    72     return makeRGBA(colorFloatToRGBAByte(r), colorFloatToRGBAByte(g), colorFloatToRGBAByte(b), colorFloatToRGBAByte(a));
    73 }
    74 
    75 RGBA32 makeRGBAFromHSLA(float hue, float saturation, float lightness, float alpha)
     70SimpleColor makeSimpleColorFromFloats(float r, float g, float b, float a)
     71{
     72    return makeSimpleColor(colorFloatToSimpleColorByte(r), colorFloatToSimpleColorByte(g), colorFloatToSimpleColorByte(b), colorFloatToSimpleColorByte(a));
     73}
     74
     75SimpleColor makeSimpleColorFromHSLA(float hue, float saturation, float lightness, float alpha)
    7676{
    7777    const float scaleFactor = 255.0;
    7878    FloatComponents floatResult = hslToSRGB({ hue, saturation, lightness, alpha });
    79     return makeRGBA(
     79    return makeSimpleColor(
    8080        round(floatResult.components[0] * scaleFactor),
    8181        round(floatResult.components[1] * scaleFactor),
     
    8484}
    8585
    86 RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a)
     86SimpleColor makeSimpleColorFromCMYKA(float c, float m, float y, float k, float a)
    8787{
    8888    double colors = 1 - k;
     
    9090    int g = static_cast<int>(nextafter(256, 0) * (colors * (1 - m)));
    9191    int b = static_cast<int>(nextafter(256, 0) * (colors * (1 - y)));
    92     return makeRGBA(r, g, b, static_cast<float>(nextafter(256, 0) * a));
     92    return makeSimpleColor(r, g, b, static_cast<float>(nextafter(256, 0) * a));
    9393}
    9494
     
    136136}
    137137
     138// originally moved here from the CSS parser
     139template <typename CharacterType>
     140static inline Optional<SimpleColor> parseHexColorInternal(const CharacterType* name, unsigned length)
     141{
     142    if (length != 3 && length != 4 && length != 6 && length != 8)
     143        return WTF::nullopt;
     144    unsigned value = 0;
     145    for (unsigned i = 0; i < length; ++i) {
     146        if (!isASCIIHexDigit(name[i]))
     147            return WTF::nullopt;
     148        value <<= 4;
     149        value |= toASCIIHexValue(name[i]);
     150    }
     151    if (length == 6)
     152        return SimpleColor { 0xFF000000 | value };
     153    if (length == 8) {
     154        // We parsed the values into RGBA order, but the SimpleColor type
     155        // expects them to be in ARGB order, so we right rotate eight bits.
     156        return SimpleColor { value << 24 | value >> 8 };
     157    }
     158    if (length == 4) {
     159        // #abcd converts to ddaabbcc in SimpleColor.
     160        return SimpleColor {
     161              (value & 0xF) << 28 | (value & 0xF) << 24
     162            | (value & 0xF000) << 8 | (value & 0xF000) << 4
     163            | (value & 0xF00) << 4 | (value & 0xF00)
     164            | (value & 0xF0) | (value & 0xF0) >> 4
     165        };
     166    }
     167    // #abc converts to #aabbcc
     168    return SimpleColor {
     169          (0xFF000000)
     170        | (value & 0xF00) << 12 | (value & 0xF00) << 8
     171        | (value & 0xF0) << 8 | (value & 0xF0) << 4
     172        | (value & 0xF) << 4 | (value & 0xF)
     173    };
     174}
     175
     176Optional<SimpleColor> SimpleColor::parseHexColor(const LChar* name, unsigned length)
     177{
     178    return parseHexColorInternal(name, length);
     179}
     180
     181Optional<SimpleColor> SimpleColor::parseHexColor(const UChar* name, unsigned length)
     182{
     183    return parseHexColorInternal(name, length);
     184}
     185
     186Optional<SimpleColor> SimpleColor::parseHexColor(const String& name)
     187{
     188    unsigned length = name.length();
     189    if (!length)
     190        return WTF::nullopt;
     191    if (name.is8Bit())
     192        return parseHexColor(name.characters8(), name.length());
     193    return parseHexColor(name.characters16(), name.length());
     194}
     195
     196Optional<SimpleColor> SimpleColor::parseHexColor(const StringView& name)
     197{
     198    unsigned length = name.length();
     199    if (!length)
     200        return WTF::nullopt;
     201    if (name.is8Bit())
     202        return parseHexColor(name.characters8(), name.length());
     203    return parseHexColor(name.characters16(), name.length());
     204}
     205
     206
    138207} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/SimpleColor.h

    r262110 r262128  
    2929#include <algorithm>
    3030#include <cmath>
     31#include <unicode/uchar.h>
    3132#include <wtf/Forward.h>
     33#include <wtf/Optional.h>
     34#include <wtf/text/LChar.h>
    3235
    3336namespace WebCore {
     
    3538// Color value with 8-bit components for red, green, blue, and alpha.
    3639// For historical reasons, stored as a 32-bit integer, with alpha in the high bits: ARGB.
     40// FIXME: This class should be consolidated with ColorComponents.
    3741class SimpleColor {
    3842public:
     
    7175    }
    7276
     77    static Optional<SimpleColor> parseHexColor(const String&);
     78    static Optional<SimpleColor> parseHexColor(const StringView&);
     79    static Optional<SimpleColor> parseHexColor(const LChar*, unsigned);
     80    static Optional<SimpleColor> parseHexColor(const UChar*, unsigned);
     81
    7382private:
    7483    uint32_t m_value { 0 };
     
    7887bool operator!=(SimpleColor, SimpleColor);
    7988
    80 // FIXME: Remove this after migrating to the new name.
    81 using RGBA32 = SimpleColor;
     89constexpr SimpleColor makeSimpleColor(int r, int g, int b);
     90constexpr SimpleColor makeSimpleColor(int r, int g, int b, int a);
    8291
    83 constexpr RGBA32 makeRGB(int r, int g, int b);
    84 constexpr RGBA32 makeRGBA(int r, int g, int b, int a);
     92SimpleColor makePremultipliedSimpleColor(int r, int g, int b, int a, bool ceiling = true);
     93SimpleColor makePremultipliedSimpleColor(SimpleColor);
     94SimpleColor makeUnpremultipliedSimpleColor(int r, int g, int b, int a);
     95SimpleColor makeUnpremultipliedSimpleColor(SimpleColor);
    8596
    86 RGBA32 makePremultipliedRGBA(int r, int g, int b, int a, bool ceiling = true);
    87 RGBA32 makePremultipliedRGBA(RGBA32);
    88 RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a);
    89 RGBA32 makeUnPremultipliedRGBA(RGBA32);
    90 
    91 WEBCORE_EXPORT RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a);
    92 WEBCORE_EXPORT RGBA32 makeRGBAFromHSLA(float h, float s, float l, float a);
    93 RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a);
     97WEBCORE_EXPORT SimpleColor makeSimpleColorFromFloats(float r, float g, float b, float a);
     98WEBCORE_EXPORT SimpleColor makeSimpleColorFromHSLA(float h, float s, float l, float a);
     99SimpleColor makeSimpleColorFromCMYKA(float c, float m, float y, float k, float a);
    94100
    95101uint8_t roundAndClampColorChannel(int);
     
    99105uint16_t fastDivideBy255(uint16_t);
    100106
    101 uint8_t colorFloatToRGBAByte(float);
     107uint8_t colorFloatToSimpleColorByte(float);
    102108
    103109inline bool operator==(SimpleColor a, SimpleColor b)
     
    113119inline uint8_t roundAndClampColorChannel(int value)
    114120{
    115     return std::max(0, std::min(255, value));
     121    return std::clamp(value, 0, 255);
    116122}
    117123
    118124inline uint8_t roundAndClampColorChannel(float value)
    119125{
    120     return std::max(0.f, std::min(255.f, std::round(value)));
     126    return std::clamp(std::round(value), 0.f, 255.f);
    121127}
    122128
     
    135141}
    136142
    137 inline uint8_t colorFloatToRGBAByte(float f)
     143inline uint8_t colorFloatToSimpleColorByte(float f)
    138144{
    139145    // FIXME: Consolidate with clampedColorComponent().
    140146    // We use lroundf and 255 instead of nextafterf(256, 0) to match CG's rounding
    141     return std::max(0, std::min(static_cast<int>(lroundf(255.0f * f)), 255));
     147    return std::clamp(static_cast<int>(lroundf(255.0f * f)), 0, 255);
    142148}
    143149
    144 constexpr RGBA32 makeRGB(int r, int g, int b)
     150constexpr SimpleColor makeSimpleColor(int r, int g, int b)
    145151{
    146     return makeRGBA(r, g, b, 0xFF);
     152    return makeSimpleColor(r, g, b, 0xFF);
    147153}
    148154
    149 constexpr RGBA32 makeRGBA(int r, int g, int b, int a)
     155constexpr SimpleColor makeSimpleColor(int r, int g, int b, int a)
    150156{
    151     return { static_cast<unsigned>(std::max(0, std::min(a, 0xFF)) << 24 | std::max(0, std::min(r, 0xFF)) << 16 | std::max(0, std::min(g, 0xFF)) << 8 | std::max(0, std::min(b, 0xFF))) };
     157    return { static_cast<unsigned>(std::clamp(a, 0, 0xFF) << 24 | std::clamp(r, 0, 0xFF) << 16 | std::clamp(g, 0, 0xFF) << 8 | std::clamp(b, 0, 0xFF)) };
    152158}
    153159
  • trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp

    r262108 r262128  
    6565}
    6666
    67 static Optional<SimpleColor> makeRGBA32FromARGBCFArray(CFArrayRef colorArray)
     67static Optional<SimpleColor> makeSimpleColorFromARGBCFArray(CFArrayRef colorArray)
    6868{
    6969    if (CFArrayGetCount(colorArray) < 4)
     
    8181    }
    8282
    83     return makeRGBA32FromFloats(componentArray[1], componentArray[2], componentArray[3], componentArray[0]);
     83    return makeSimpleColorFromFloats(componentArray[1], componentArray[2], componentArray[3], componentArray[0]);
    8484}
    8585
     
    268268                    continue;
    269269               
    270                 auto color = makeRGBA32FromARGBCFArray(arrayValue);
     270                auto color = makeSimpleColorFromARGBCFArray(arrayValue);
    271271                if (!color)
    272272                    continue;
     
    280280                    continue;
    281281               
    282                 auto color = makeRGBA32FromARGBCFArray(arrayValue);
     282                auto color = makeSimpleColorFromARGBCFArray(arrayValue);
    283283                if (!color)
    284284                    continue;
     
    292292                    continue;
    293293               
    294                 auto color = makeRGBA32FromARGBCFArray(arrayValue);
     294                auto color = makeSimpleColorFromARGBCFArray(arrayValue);
    295295                if (!color)
    296296                    continue;
  • trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp

    r262070 r262128  
    8181        for (int x = 0; x < m_logicalSize.width(); x++) {
    8282            unsigned* pixel = row + x;
    83             auto pixelColor = makeUnPremultipliedRGBA(*pixel);
    84             pixelColor = makeRGBA(lookUpTable[pixelColor.redComponent()], lookUpTable[pixelColor.greenComponent()], lookUpTable[pixelColor.blueComponent()], pixelColor.alphaComponent());
    85             *pixel = makePremultipliedRGBA(pixelColor).value();
     83            auto pixelColor = makeUnpremultipliedSimpleColor(*pixel);
     84            pixelColor = makeSimpleColor(lookUpTable[pixelColor.redComponent()], lookUpTable[pixelColor.greenComponent()], lookUpTable[pixelColor.blueComponent()], pixelColor.alphaComponent());
     85            *pixel = makePremultipliedSimpleColor(pixelColor).value();
    8686        }
    8787    }
  • trunk/Source/WebCore/platform/graphics/cairo/NativeImageCairo.cpp

    r262070 r262128  
    5454        return Color();
    5555
    56     RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
    57     return makeUnPremultipliedRGBA(*pixel);
     56    SimpleColor* pixel = reinterpret_cast_ptr<SimpleColor*>(cairo_image_surface_get_data(image.get()));
     57    return makeUnpremultipliedSimpleColor(*pixel);
    5858}
    5959
  • trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp

    r261901 r262128  
    5252namespace WebCore {
    5353
    54 static RGBA32 makeRGBAFromCGColor(CGColorRef color)
     54static SimpleColor makeSimpleColorFromCGColor(CGColorRef color)
    5555{
     56    // FIXME: ExtendedColor - needs to handle color spaces.
     57
    5658    size_t numComponents = CGColorGetNumberOfComponents(color);
    5759    const CGFloat* components = CGColorGetComponents(color);
     
    7880
    7981    static const double scaleFactor = nextafter(256.0, 0.0);
    80     return makeRGBA(r * scaleFactor, g * scaleFactor, b * scaleFactor, a * scaleFactor);
     82    return makeSimpleColor(r * scaleFactor, g * scaleFactor, b * scaleFactor, a * scaleFactor);
    8183}
    8284
    8385Color::Color(CGColorRef color)
    8486{
     87    // FIXME: ExtendedColor - needs to handle color spaces.
     88
    8589    if (!color) {
    86         m_colorData.rgbaAndFlags = invalidRGBAColor;
     90        m_colorData.simpleColorAndFlags = invalidSimpleColor;
    8791        return;
    8892    }
    8993
    90     setRGB(makeRGBAFromCGColor(color));
     94    setSimpleColor(makeSimpleColorFromCGColor(color));
    9195}
    9296
    9397Color::Color(CGColorRef color, SemanticTag)
    9498{
     99    // FIXME: ExtendedColor - needs to handle color spaces.
     100
    95101    if (!color) {
    96         m_colorData.rgbaAndFlags = invalidRGBAColor;
     102        m_colorData.simpleColorAndFlags = invalidSimpleColor;
    97103        return;
    98104    }
    99105
    100     setRGB(makeRGBAFromCGColor(color));
     106    setSimpleColor(makeSimpleColorFromCGColor(color));
    101107    setIsSemantic();
    102108}
     
    125131{
    126132    if (!color.isExtended()) {
    127         switch (color.rgb().value()) {
     133        switch (color.asSimpleColor().value()) {
    128134        case Color::transparent.value(): {
    129135            static CGColorRef transparentCGColor = leakCGColor(color);
     
    141147    }
    142148
    143     ASSERT(color.isExtended() || color.rgb().value());
     149    ASSERT(color.isExtended() || color.asSimpleColor().value());
    144150
    145151    static NeverDestroyed<TinyLRUCache<Color, RetainPtr<CGColorRef>, 32>> cache;
  • trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp

    r261901 r262128  
    2929Color::Color(const GdkRGBA& c)
    3030{
    31     setRGB(makeRGBA(static_cast<int>(c.red * 255),
     31    setSimpleColor(makeSimpleColor(
     32        static_cast<int>(c.red * 255),
    3233        static_cast<int>(c.green * 255),
    3334        static_cast<int>(c.blue * 255),
    34         static_cast<int>(c.alpha * 255)));
     35        static_cast<int>(c.alpha * 255)
     36    ));
    3537}
    3638
  • trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm

    r255785 r262128  
    5454}
    5555
    56 static RGBA32 makeRGBAFromNSColor(NSColor *color)
     56static SimpleColor makeSimpleColorFromNSColor(NSColor *color)
    5757{
     58    // FIXME: ExtendedColor - needs to handle color spaces.
     59
    5860    ASSERT_ARG(color, color);
    5961
     
    8183        [offscreenRep getPixel:pixel atX:0 y:0];
    8284
    83         return makeRGBA(pixel[0], pixel[1], pixel[2], pixel[3]);
     85        return makeSimpleColor(pixel[0], pixel[1], pixel[2], pixel[3]);
    8486    }
    8587
     
    8890
    8991    static const double scaleFactor = nextafter(256.0, 0.0);
    90     return makeRGBA(scaleFactor * redComponent, scaleFactor * greenComponent, scaleFactor * blueComponent, scaleFactor * alpha);
     92    return makeSimpleColor(scaleFactor * redComponent, scaleFactor * greenComponent, scaleFactor * blueComponent, scaleFactor * alpha);
    9193}
    9294
    9395Color colorFromNSColor(NSColor *color)
    9496{
    95     return Color(makeRGBAFromNSColor(color));
     97    // FIXME: ExtendedColor - needs to handle color spaces.
     98
     99    return Color(makeSimpleColorFromNSColor(color));
    96100}
    97101
    98102Color semanticColorFromNSColor(NSColor *color)
    99103{
    100     return Color(makeRGBAFromNSColor(color), Color::Semantic);
     104    // FIXME: ExtendedColor - needs to handle color spaces.
     105
     106    return Color(makeSimpleColorFromNSColor(color), Color::Semantic);
    101107}
    102108
  • trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp

    r262035 r262128  
    3737Color::Color(D2D1_COLOR_F color)
    3838{
    39     setRGB(makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255));
     39    setSimpleColor(makeSimpleColor(color.r * 255, color.g * 255, color.b * 255, color.a * 255));
    4040}
    4141
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp

    r261901 r262128  
    199199    CGContextSaveGState(context);
    200200
    201     static constexpr SimpleColor spellingPatternColor { makeRGB(255, 0, 0) };
    202     static constexpr SimpleColor grammarPatternColor { makeRGB(0, 128, 0) };
     201    static constexpr SimpleColor spellingPatternColor { makeSimpleColor(255, 0, 0) };
     202    static constexpr SimpleColor grammarPatternColor { makeSimpleColor(0, 128, 0) };
    203203
    204204    const SimpleColor& patternColor = style.mode == DocumentMarkerLineStyle::Mode::Grammar ? grammarPatternColor : spellingPatternColor;
  • trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp

    r254087 r262128  
    133133COMPtr<ID2D1SolidColorBrush> PlatformContextDirect2D::brushWithColor(const D2D1_COLOR_F& color)
    134134{
    135     RGBA32 colorKey = makeRGBA32FromFloats(color.r, color.g, color.b, color.a);
     135    SimpleColor colorKey = makeSimpleColorFromFloats(color.r, color.g, color.b, color.a);
    136136
    137137    if (!colorKey) {
  • trunk/Source/WebCore/platform/ios/ColorIOS.mm

    r240174 r262128  
    3535Color colorFromUIColor(UIColor *color)
    3636{
     37    // FIXME: ExtendedColor - needs to handle color spaces.
     38
    3739    // FIXME: Make this work for a UIColor that was created from a pattern or a DispayP3 color.
    3840    CGFloat redComponent;
     
    4446
    4547    static const double scaleFactor = nextafter(256.0, 0.0);
    46     return makeRGBA(scaleFactor * redComponent, scaleFactor * greenComponent, scaleFactor * blueComponent, scaleFactor * alpha);
     48    return makeSimpleColor(scaleFactor * redComponent, scaleFactor * greenComponent, scaleFactor * blueComponent, scaleFactor * alpha);
    4749}
    4850
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r262108 r262128  
    12491249{
    12501250    if (!renderer().frame().editor().compositionUsesCustomHighlights()) {
    1251         paintMarkedTextBackground(paintInfo, boxOrigin, Color::compositionFill, clampedOffset(renderer().frame().editor().compositionStart()), clampedOffset(renderer().frame().editor().compositionEnd()));
     1251        paintMarkedTextBackground(paintInfo, boxOrigin, CompositionHighlight::defaultCompositionFillColor, clampedOffset(renderer().frame().editor().compositionStart()), clampedOffset(renderer().frame().editor().compositionEnd()));
    12521252        return;
    12531253    }
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r261774 r262128  
    40804080        LayoutRect largerCorner = resizerAbsRect;
    40814081        largerCorner.setSize(LayoutSize(largerCorner.width() + 1_lu, largerCorner.height() + 1_lu));
    4082         context.setStrokeColor(Color(makeRGB(217, 217, 217)));
     4082        context.setStrokeColor(makeSimpleColor(217, 217, 217));
    40834083        context.setStrokeThickness(1.0f);
    40844084        context.setFillColor(Color::transparent);
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r261742 r262128  
    30863086    ASCIILiteral name;
    30873087    FloatSize phase;
    3088     RGBA32 fillColor;
     3088    SimpleColor fillColor;
    30893089};
    30903090
     
    31463146    };
    31473147
    3148     constexpr auto fillColor = makeRGBA(0, 0, 0, 128);
     3148    constexpr auto fillColor = makeSimpleColor(0, 0, 0, 128);
    31493149
    31503150    static const PatternDescription patternDescriptions[] = {
     
    31663166static RefPtr<Pattern> patternForEventListenerRegionType(EventListenerRegionType type, FloatSize contentOffset, GraphicsContext& destContext)
    31673167{
    3168     constexpr auto fillColor = makeRGBA(0, 128, 0, 128);
     3168    constexpr auto fillColor = makeSimpleColor(0, 128, 0, 128);
    31693169
    31703170    auto patternAndPhase = [&]() -> PatternDescription {
  • trunk/Source/WebCore/rendering/RenderThemeAdwaita.cpp

    r259435 r262128  
    4646
    4747static const int textFieldBorderSize = 1;
    48 static const Color textFieldBorderColor = makeRGB(205, 199, 194);
    49 static const Color textFieldBorderDisabledColor = makeRGB(213, 208, 204);
    50 static const Color textFieldBackgroundColor = makeRGB(255, 255, 255);
    51 static const Color textFieldBackgroundDisabledColor = makeRGB(252, 252, 252);
     48static const Color textFieldBorderColor = makeSimpleColor(205, 199, 194);
     49static const Color textFieldBorderDisabledColor = makeSimpleColor(213, 208, 204);
     50static const Color textFieldBackgroundColor = makeSimpleColor(255, 255, 255);
     51static const Color textFieldBackgroundDisabledColor = makeSimpleColor(252, 252, 252);
    5252static const unsigned menuListButtonArrowSize = 16;
    5353static const int menuListButtonFocusOffset = -3;
     
    5858static const Seconds progressAnimationFrameRate = 33_ms; // 30fps.
    5959static const unsigned progressBarSize = 6;
    60 static const Color progressBarBorderColor = makeRGB(205, 199, 194);
    61 static const Color progressBarBackgroundColor = makeRGB(225, 222, 219);
     60static const Color progressBarBorderColor = makeSimpleColor(205, 199, 194);
     61static const Color progressBarBackgroundColor = makeSimpleColor(225, 222, 219);
    6262static const unsigned sliderTrackSize = 6;
    6363static const int sliderTrackBorderSize = 1;
    64 static const Color sliderTrackBorderColor = makeRGB(205, 199, 194);
    65 static const Color sliderTrackBackgroundColor = makeRGB(225, 222, 219);
     64static const Color sliderTrackBorderColor = makeSimpleColor(205, 199, 194);
     65static const Color sliderTrackBackgroundColor = makeSimpleColor(225, 222, 219);
    6666static const int sliderTrackFocusOffset = 2;
    6767static const int sliderThumbSize = 20;
    6868static const int sliderThumbBorderSize = 1;
    69 static const Color sliderThumbBorderColor = makeRGB(205, 199, 194);
    70 static const Color sliderThumbBackgroundColor = makeRGB(244, 242, 241);
    71 static const Color sliderThumbBackgroundHoveredColor = makeRGB(248, 248, 247);
    72 static const Color sliderThumbBackgroundDisabledColor = makeRGB(244, 242, 241);
     69static const Color sliderThumbBorderColor = makeSimpleColor(205, 199, 194);
     70static const Color sliderThumbBackgroundColor = makeSimpleColor(244, 242, 241);
     71static const Color sliderThumbBackgroundHoveredColor = makeSimpleColor(248, 248, 247);
     72static const Color sliderThumbBackgroundDisabledColor = makeSimpleColor(244, 242, 241);
    7373#if ENABLE(VIDEO)
    74 static const Color mediaSliderTrackBackgroundcolor = makeRGB(77, 77, 77);
    75 static const Color mediaSliderTrackBufferedColor = makeRGB(173, 173, 173);
    76 static const Color mediaSliderTrackActiveColor = makeRGB(252, 252, 252);
     74static const Color mediaSliderTrackBackgroundcolor = makeSimpleColor(77, 77, 77);
     75static const Color mediaSliderTrackBufferedColor = makeSimpleColor(173, 173, 173);
     76static const Color mediaSliderTrackActiveColor = makeSimpleColor(252, 252, 252);
    7777#endif
    7878
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r262035 r262128  
    552552}
    553553
    554 static RGBA32 menuBackgroundColor()
     554static SimpleColor menuBackgroundColor()
    555555{
    556556    RetainPtr<NSBitmapImageRep> offscreenRep = adoptNS([[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil pixelsWide:1 pixelsHigh:1
     
    569569    [offscreenRep getPixel:pixel atX:0 y:0];
    570570
    571     return makeRGBA(pixel[0], pixel[1], pixel[2], pixel[3]);
     571    return makeSimpleColor(pixel[0], pixel[1], pixel[2], pixel[3]);
    572572}
    573573
  • trunk/Source/WebKit/ChangeLog

    r262112 r262128  
     12020-05-24  Sam Weinig  <weinig@apple.com>
     2
     3        Extended Color Cleanup: Use the name SimpleColor consistently
     4        https://bugs.webkit.org/show_bug.cgi?id=212337
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/ios/WKContentViewInteraction.mm:
     9        (compositionHighlights):
     10        Update for new name of CompositionHighlight::defaultCompositionFillColor.
     11
    1122020-05-24  Rob Buis  <rbuis@igalia.com>
    213
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r261978 r262128  
    46254625            return;
    46264626
    4627         WebCore::Color highlightColor { WebCore::Color::compositionFill };
     4627        WebCore::Color highlightColor { WebCore::CompositionHighlight::defaultCompositionFillColor };
    46284628        if (UIColor *uiColor = attributes[NSBackgroundColorAttributeName])
    46294629            highlightColor = WebCore::colorFromUIColor(uiColor);
  • trunk/Tools/ChangeLog

    r262121 r262128  
     12020-05-24  Sam Weinig  <weinig@apple.com>
     2
     3        Extended Color Cleanup: Use the name SimpleColor consistently
     4        https://bugs.webkit.org/show_bug.cgi?id=212337
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
     9        (TestWebKitAPI::TEST):
     10        Update test for rename of makeRGBAFromHSLA to makeSimpleColorFromHSLA.
     11
    1122020-05-25  Víctor Manuel Jáquez Leal  <vjaquez@igalia.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp

    r262108 r262128  
    4646    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    4747   
    48     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     48    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    4949    EXPECT_EQ(color, roundTrippedColor);
    5050}
     
    6262    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    6363
    64     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     64    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    6565    EXPECT_EQ(color, roundTrippedColor);
    6666}
     
    7878    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    7979
    80     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     80    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    8181    EXPECT_EQ(color, roundTrippedColor);
    8282}
     
    9494    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    9595
    96     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     96    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    9797    EXPECT_EQ(color, roundTrippedColor);
    9898}
     
    110110    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    111111
    112     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     112    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    113113    EXPECT_EQ(color, roundTrippedColor);
    114114}
     
    126126    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    127127
    128     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     128    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    129129    EXPECT_EQ(color, roundTrippedColor);
    130130}
     
    142142    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    143143
    144     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     144    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    145145    EXPECT_EQ(color, roundTrippedColor);
    146146}
     
    158158    EXPECT_FLOAT_EQ(color.lightness(), lightness);
    159159
    160     auto roundTrippedColor = Color(makeRGBAFromHSLA(hue, saturation, lightness, alpha));
     160    auto roundTrippedColor = Color(makeSimpleColorFromHSLA(hue, saturation, lightness, alpha));
    161161    EXPECT_EQ(color, roundTrippedColor);
    162162}
Note: See TracChangeset for help on using the changeset viewer.