Changeset 288134 in webkit


Ignore:
Timestamp:
Jan 18, 2022 11:59:53 AM (6 months ago)
Author:
weinig@apple.com
Message:

Canvas functions that take colors as strings don't support all the syntax that CSS supports
https://bugs.webkit.org/show_bug.cgi?id=235269

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Update expected results now that the test is passing.

  • web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.fillStyle.toStringFunctionCallback-expected.txt:

Source/WebCore:

Add a variant of CSSParser::parseColor() that takes a CSSParserContext
and use it (and parser context created from a document) to get the parser
to respect the settings. Rename the existing CSSParser::parseColor() to
CSSParser::parseColorWithoutContext() and add a comment indicating all
uses should eventually be removed.

Offscreen canvas and custom paint canvas are using the old path with https://webkit.org/b/235270
tracking finding a solution for them.

  • Modules/applicationmanifest/ApplicationManifestParser.cpp:

(WebCore::ApplicationManifestParser::parseColor):

  • css/StyleProperties.cpp:

(WebCore::StyleProperties::propertyAsColor const):

  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseColor):
(WebCore::CSSParser::parseColorWithoutContext):

  • css/parser/CSSParser.h:
  • editing/EditingStyle.cpp:

(WebCore::cssValueToColor):

  • html/HTMLBodyElement.cpp:

(WebCore::HTMLBodyElement::parseAttribute):

  • html/HTMLMetaElement.cpp:

(WebCore::HTMLMetaElement::contentColor):

  • html/canvas/CanvasStyle.cpp:

(WebCore::parseColor):
(WebCore::currentColor):

  • svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
  • svg/properties/SVGPropertyTraits.h:

(WebCore::SVGPropertyTraits<Color>::fromString):
(WebCore::SVGPropertyTraits<Color>::parse):

Source/WebKit:

Update for rename of CSSParser::parseColor() to CSSParser::parseColorWithoutContext().

  • UIProcess/API/wpe/WebKitColor.cpp:

(webkit_color_parse):

  • WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:

(WKBundlePageSetComposition):

LayoutTests:

  • fast/canvas/canvas-color-serialization.html:

Update doctype to set the correct CSS parsing mode which now needs to be set correctly for canvas color setting functions.

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r288132 r288134  
     12022-01-18  Sam Weinig  <weinig@apple.com>
     2
     3        Canvas functions that take colors as strings don't support all the syntax that CSS supports
     4        https://bugs.webkit.org/show_bug.cgi?id=235269
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/canvas/canvas-color-serialization.html:
     9        Update doctype to set the correct CSS parsing mode which now needs to be set correctly for canvas color setting functions.
     10
    1112022-01-18  Patrick Griffis  <pgriffis@igalia.com>
    212
  • trunk/LayoutTests/fast/canvas/canvas-color-serialization.html

    r267645 r288134  
    1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     1<!DOCTYPE HTML>
    22<html>
    33<head>
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r288132 r288134  
     12022-01-18  Sam Weinig  <weinig@apple.com>
     2
     3        Canvas functions that take colors as strings don't support all the syntax that CSS supports
     4        https://bugs.webkit.org/show_bug.cgi?id=235269
     5
     6        Reviewed by Darin Adler.
     7
     8        Update expected results now that the test is passing.
     9
     10        * web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.fillStyle.toStringFunctionCallback-expected.txt:
     11
    1122022-01-18  Patrick Griffis  <pgriffis@igalia.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.fillStyle.toStringFunctionCallback-expected.txt

    r279427 r288134  
    33Actual output:
    44
    5 FAIL Passing a function in to ctx.fillStyle or ctx.strokeStyle with a toString callback works as specified assert_equals: ctx.fillStyle === "#008000" (got #800000[string], expected #008000[string]) expected "#008000" but got "#800000"
     5PASS Passing a function in to ctx.fillStyle or ctx.strokeStyle with a toString callback works as specified
    66
  • trunk/Source/WebCore/ChangeLog

    r288133 r288134  
     12022-01-18  Sam Weinig  <weinig@apple.com>
     2
     3        Canvas functions that take colors as strings don't support all the syntax that CSS supports
     4        https://bugs.webkit.org/show_bug.cgi?id=235269
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a variant of CSSParser::parseColor() that takes a CSSParserContext
     9        and use it (and parser context created from a document) to get the parser
     10        to respect the settings. Rename the existing CSSParser::parseColor() to
     11        CSSParser::parseColorWithoutContext() and add a comment indicating all
     12        uses should eventually be removed.
     13
     14        Offscreen canvas and custom paint canvas are using the old path with https://webkit.org/b/235270
     15        tracking finding a solution for them.
     16
     17        * Modules/applicationmanifest/ApplicationManifestParser.cpp:
     18        (WebCore::ApplicationManifestParser::parseColor):
     19        * css/StyleProperties.cpp:
     20        (WebCore::StyleProperties::propertyAsColor const):
     21        * css/parser/CSSParser.cpp:
     22        (WebCore::CSSParser::parseColor):
     23        (WebCore::CSSParser::parseColorWithoutContext):
     24        * css/parser/CSSParser.h:
     25        * editing/EditingStyle.cpp:
     26        (WebCore::cssValueToColor):
     27        * html/HTMLBodyElement.cpp:
     28        (WebCore::HTMLBodyElement::parseAttribute):
     29        * html/HTMLMetaElement.cpp:
     30        (WebCore::HTMLMetaElement::contentColor):
     31        * html/canvas/CanvasStyle.cpp:
     32        (WebCore::parseColor):
     33        (WebCore::currentColor):
     34        * svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
     35        * svg/properties/SVGPropertyTraits.h:
     36        (WebCore::SVGPropertyTraits<Color>::fromString):
     37        (WebCore::SVGPropertyTraits<Color>::parse):
     38
    1392022-01-18  Alex Christensen  <achristensen@webkit.org>
    240
  • trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp

    r286073 r288134  
    321321Color ApplicationManifestParser::parseColor(const JSON::Object& manifest, const String& propertyName)
    322322{
    323     return CSSParser::parseColor(parseGenericString(manifest, propertyName));
     323    return CSSParser::parseColorWithoutContext(parseGenericString(manifest, propertyName));
    324324}
    325325
  • trunk/Source/WebCore/css/StyleProperties.cpp

    r287909 r288134  
    348348
    349349    auto& primitiveColor = downcast<CSSPrimitiveValue>(*colorValue);
    350     return primitiveColor.isRGBColor() ? primitiveColor.color() : CSSParser::parseColor(colorValue->cssText());
     350    return primitiveColor.isRGBColor() ? primitiveColor.color() : CSSParser::parseColorWithoutContext(colorValue->cssText());
    351351}
    352352
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r284095 r288134  
    9595}
    9696
    97 Color CSSParser::parseColor(const String& string, bool strict)
     97Color CSSParser::parseColor(const String& string, const CSSParserContext& context)
     98{
     99    bool strict = !isQuirksModeBehavior(context.mode);
     100    if (auto color = CSSParserFastPaths::parseSimpleColor(string, strict))
     101        return *color;
     102    auto value = parseSingleValue(CSSPropertyColor, string, context);
     103    if (!is<CSSPrimitiveValue>(value))
     104        return { };
     105    auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
     106    if (!primitiveValue.isRGBColor())
     107        return { };
     108    return primitiveValue.color();
     109}
     110
     111Color CSSParser::parseColorWithoutContext(const String& string, bool strict)
    98112{
    99113    if (auto color = CSSParserFastPaths::parseSimpleColor(string, strict))
  • trunk/Source/WebCore/css/parser/CSSParser.h

    r281426 r288134  
    8989    RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, Style::BuilderState&);
    9090
    91     WEBCORE_EXPORT static Color parseColor(const String&, bool strict = false);
     91    WEBCORE_EXPORT static Color parseColor(const String&, const CSSParserContext&);
     92    // FIXME: All callers are not getting the right Settings for parsing due to lack of CSSParserContext and should switch to the parseColor function above.
     93    WEBCORE_EXPORT static Color parseColorWithoutContext(const String&, bool strict = false);
    9294    static Color parseSystemColor(StringView);
    9395    static std::optional<SRGBA<uint8_t>> parseNamedColor(StringView);
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r287138 r288134  
    440440        return primitiveColor.color();
    441441   
    442     return CSSParser::parseColor(colorValue->cssText());
     442    return CSSParser::parseColorWithoutContext(colorValue->cssText());
    443443}
    444444
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r287089 r288134  
    124124                document().resetActiveLinkColor();
    125125        } else {
    126             Color color = CSSParser::parseColor(value, !document().inQuirksMode());
     126            Color color = CSSParser::parseColorWithoutContext(value, !document().inQuirksMode());
    127127            if (color.isValid()) {
    128128                if (name == linkAttr)
  • trunk/Source/WebCore/html/HTMLMetaElement.cpp

    r283851 r288134  
    8686{
    8787    if (!m_contentColor)
    88         m_contentColor = CSSParser::parseColor(content());
     88        m_contentColor = CSSParser::parseColorWithoutContext(content());
    8989    return *m_contentColor;
    9090}
  • trunk/Source/WebCore/html/canvas/CanvasStyle.cpp

    r284095 r288134  
    4545#endif
    4646
    47 #if USE(CG)
    48 #include <CoreGraphics/CGContext.h>
    49 #endif
    50 
    5147namespace WebCore {
    5248
     
    5955{
    6056#if ENABLE(OFFSCREEN_CANVAS)
    61     if (canvasBase.isOffscreenCanvas())
     57    if (is<OffscreenCanvas>(canvasBase))
    6258        return CSSPropertyParserWorkerSafe::parseColor(colorString);
    63 #else
    64     UNUSED_PARAM(canvasBase);
    6559#endif
    66     Color color = CSSParser::parseColor(colorString);
     60
     61    Color color;
     62    if (is<HTMLCanvasElement>(canvasBase))
     63        color = CSSParser::parseColor(colorString, CSSParserContext { downcast<HTMLCanvasElement>(canvasBase).document() });
     64    else
     65        color = CSSParser::parseColorWithoutContext(colorString);
     66
    6767    if (color.isValid())
    6868        return color;
     
    7878    if (!canvas.isConnected() || !canvas.inlineStyle())
    7979        return Color::black;
    80     Color color = CSSParser::parseColor(canvas.inlineStyle()->getPropertyValue(CSSPropertyColor));
     80    Color color = CSSParser::parseColorWithoutContext(canvas.inlineStyle()->getPropertyValue(CSSPropertyColor));
    8181    if (!color.isValid())
    8282        return Color::black;
  • trunk/Source/WebCore/svg/properties/SVGAnimationAdditiveValueFunctionImpl.h

    r287552 r288134  
    9797    std::optional<float> calculateDistance(SVGElement&, const String& from, const String& to) const override
    9898    {
    99         Color fromColor = CSSParser::parseColor(from.stripWhiteSpace());
     99        Color fromColor = CSSParser::parseColorWithoutContext(from.stripWhiteSpace());
    100100        if (!fromColor.isValid())
    101101            return { };
    102         Color toColor = CSSParser::parseColor(to.stripWhiteSpace());
     102        Color toColor = CSSParser::parseColorWithoutContext(to.stripWhiteSpace());
    103103        if (!toColor.isValid())
    104104            return { };
  • trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h

    r287731 r288134  
    4646struct SVGPropertyTraits<Color> {
    4747    static Color initialValue() { return Color(); }
    48     static Color fromString(const String& string) { return CSSParser::parseColor(string.stripWhiteSpace()); }
     48    static Color fromString(const String& string) { return CSSParser::parseColorWithoutContext(string.stripWhiteSpace()); }
    4949    static std::optional<Color> parse(const QualifiedName&, const String& string)
    5050    {
    51         Color color = CSSParser::parseColor(string.stripWhiteSpace());
     51        Color color = CSSParser::parseColorWithoutContext(string.stripWhiteSpace());
    5252        if (!color.isValid())
    5353            return std::nullopt;
  • trunk/Source/WebKit/ChangeLog

    r288128 r288134  
     12022-01-18  Sam Weinig  <weinig@apple.com>
     2
     3        Canvas functions that take colors as strings don't support all the syntax that CSS supports
     4        https://bugs.webkit.org/show_bug.cgi?id=235269
     5
     6        Reviewed by Darin Adler.
     7
     8        Update for rename of CSSParser::parseColor() to CSSParser::parseColorWithoutContext().
     9
     10        * UIProcess/API/wpe/WebKitColor.cpp:
     11        (webkit_color_parse):
     12        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
     13        (WKBundlePageSetComposition):
     14
    1152022-01-18  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp

    r287552 r288134  
    109109    g_return_val_if_fail(colorString, FALSE);
    110110
    111     auto webCoreColor = WebCore::CSSParser::parseColor({ colorString });
     111    auto webCoreColor = WebCore::CSSParser::parseColorWithoutContext({ colorString });
    112112    if (!webCoreColor.isValid())
    113113        return FALSE;
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp

    r286767 r288134  
    627627                static_cast<unsigned>(startOffset),
    628628                static_cast<unsigned>(startOffset + static_cast<API::UInt64*>(dictionary->get("length"))->value()),
    629                 WebCore::CSSParser::parseColor(static_cast<API::String*>(dictionary->get("color"))->string())
     629                WebCore::CSSParser::parseColorWithoutContext(static_cast<API::String*>(dictionary->get("color"))->string())
    630630            });
    631631        }
Note: See TracChangeset for help on using the changeset viewer.