Bug 227807 - SVGImageForContainer reports true for is<SVGImage>() but it doesn't inherit from SVGImage
Summary: SVGImageForContainer reports true for is<SVGImage>() but it doesn't inherit f...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-08 11:55 PDT by Myles C. Maxfield
Modified: 2021-07-09 13:06 PDT (History)
21 users (show)

See Also:


Attachments
Patch (26.13 KB, patch)
2021-07-08 11:58 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (25.83 KB, patch)
2021-07-08 12:15 PDT, Myles C. Maxfield
sabouhallawa: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>