Bug 227807

Summary: SVGImageForContainer reports true for is<SVGImage>() but it doesn't inherit from SVGImage
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, apinheiro, cdumez, cfleizach, changseok, dino, dmazzoni, esprehn+autocc, ews-watchlist, fmalita, gyuyoung.kim, japhet, jcraig, jdiggs, kondapallykalyan, pdr, sabouhallawa, samuel_white, schenney, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch sabouhallawa: review+

Description Myles C. Maxfield 2021-07-08 11:55:47 PDT
SVGImageForContainer reports true for is<SVGImage>() but it doesn't inherit from SVGImage
Comment 1 Myles C. Maxfield 2021-07-08 11:58:37 PDT
Created attachment 433151 [details]
Patch
Comment 2 Said Abou-Hallawa 2021-07-08 12:04:19 PDT
Comment on attachment 433151 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433151&action=review

> Source/WebCore/platform/graphics/Image.h:100
> +    virtual bool actsLikeSVGImage() const { return false; }

This can be just

bool actsLikeSVGImage() const { return isSVGImage() || isSVGImageForContainer(); }
Comment 3 Myles C. Maxfield 2021-07-08 12:15:13 PDT
Created attachment 433153 [details]
Patch
Comment 4 Said Abou-Hallawa 2021-07-08 13:35:29 PDT
Comment on attachment 433153 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433153&action=review

> Source/WebCore/platform/graphics/Image.h:100
> +    bool actsLikeSVGImage() const { return isSVGImage() || isSVGImageForContainer(); }

This name does not seem like what the return value represents. Can't we choose a name which says "is the image to be drawn at the end an SVGImage"? Maybe isUnderlyingSVGImage(), isDrawingSVGImage() or something similar?

> Source/WebCore/platform/graphics/ImageObserver.h:30
> +#include <wtf/URL.h>
> +#include <wtf/text/WTFString.h>

There is no obvious reason for including these headers here especially URL.h includes WTFString.h

> Tools/ChangeLog:10
> +        * TestWebKitAPI/Tests/WebCore/SVGImageCasts.cpp: Added.
> +        (TestWebKitAPI::TEST):

I do not see what mistakes this test will prevent in the future. I can add a new superclass of Image which returns true for isSVGImage() or change an existing Image type to true for isSVGImage() and nothing will be caught.

> Tools/TestWebKitAPI/Tests/WebCore/SVGImageCasts.cpp:35
> +using namespace WebCore;
> +
> +namespace TestWebKitAPI {

I think we usually put the using statement inside the namespace.
Comment 5 Myles C. Maxfield 2021-07-09 12:51:47 PDT
Comment on attachment 433153 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433153&action=review

>> Source/WebCore/platform/graphics/Image.h:100
>> +    bool actsLikeSVGImage() const { return isSVGImage() || isSVGImageForContainer(); }
> 
> This name does not seem like what the return value represents. Can't we choose a name which says "is the image to be drawn at the end an SVGImage"? Maybe isUnderlyingSVGImage(), isDrawingSVGImage() or something similar?

Makes sense. I'll do "drawsSVGImage()."

>> Source/WebCore/platform/graphics/ImageObserver.h:30
>> +#include <wtf/text/WTFString.h>
> 
> There is no obvious reason for including these headers here especially URL.h includes WTFString.h

It's needed for the TestWebKitAPI test file which includes <WebCore/ImageObserver.h> as the first thing it includes. This file uses URL.h.

>> Tools/ChangeLog:10
>> +        (TestWebKitAPI::TEST):
> 
> I do not see what mistakes this test will prevent in the future. I can add a new superclass of Image which returns true for isSVGImage() or change an existing Image type to true for isSVGImage() and nothing will be caught.

The test catches what the ChangeLog says:

if (is<SVGImage>(image))
            downcast<SVGImage>(image).doSomething();

It tests this by making sure that is<SVGImage>() returns false for SVGImageForContainers.
Comment 6 Myles C. Maxfield 2021-07-09 13:05:48 PDT
Committed r279793 (239560@main): <https://commits.webkit.org/239560@main>
Comment 7 Radar WebKit Bug Importer 2021-07-09 13:06:17 PDT
<rdar://problem/80390790>