[Webkit-unassigned] [Bug 244128] Add experimental feature to disable Bitmap image animations

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Sep 2 15:44:18 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=244128

--- Comment #48 from Said Abou-Hallawa <sabouhallawa at apple.com> ---
Comment on attachment 462100
  --> https://bugs.webkit.org/attachment.cgi?id=462100
Patch

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

> Source/WebCore/html/HTMLImageElement.cpp:790
> +void HTMLImageElement::resumeAnimation()
> +{
> +    if (auto* image = this->image()) {
> +        document().addAllowedAnimatedImageURL(image->sourceURL());
> +        image->startAnimation();
> +    }
> +}
> +
> +void HTMLImageElement::pauseAnimation()
> +{
> +    if (auto* image = this->image()) {
> +        document().removeAllowedAnimatedImageURL(image->sourceURL());
> +        image->stopAnimation();
> +    }
> +}

This interface is a little bit troublesome because we have a global setting and a local overriding. And they both need to interact clearly. How about this suggestion?

Image.h:

class Image {
public:
    std::optional<bool> allowsAnimation() const { return m_allowsAnimation; }
    void setAllowsAnimation(std::optional<bool> allowsAnimation) { m_allowsAnimation = allowsAnimation; }

private:
    // This is a tri-state flag:
    // std::nullopt (means follow the global setting)
    // false (means do not allow animation regardless of the global setting)
    // true (means allow animation regardless of the global setting)
    std::optional<bool> m_allowsAnimation;
}

HTMLImageElement:

class HTMLImageElement {
public:
    bool allowsAnimation() const;
    void setAllowsAnimation(bool);
    void resetAllowsAnimation(); // This will set Image::m_allowsAnimation to std::nullopt.
}

bool HTMLImageElement::allowsAnimation() const
{
    if (auto* image = this->image())
        return image->allowsAnimation().value_or(document().settings().imageAnimationEnabled());
    return false; 
}

Internal.cpp

void Internals::resumeImageAnimation(HTMLImageElement& element)
{
    element.setAllowsAnimation(true);
}

RenderImage.cpp

bool RenderImage::allowsAnimation(CachedImage& image) const
{
    if (is<HTMLImageElement>(element()))
        return downcast<HTMLImageElement>(*element()).allowsAnimation();
    return RenderReplaced::allowsAnimation(image);
}

> Source/WebCore/testing/Internals.cpp:1060
> +void Internals::resumeImageAnimation(HTMLImageElement& element)
> +{
> +    element.resumeAnimation();
> +}
> +
> +void Internals::pauseImageAnimation(HTMLImageElement& element)
> +{
> +    element.pauseAnimation();
> +}

This interface works only for HTMLImageElement but it does not work for css images 

<style>
    .box-with-animation {
        background-image: url("animated.gif");
    }
</style>

But this patch will disable the css animation if the same src is used by an HTMLImageElement:

<img id="image1" src="animated.gif">
<script>
    internals.pauseImageAnimation(image1);
<script>

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220902/791e7549/attachment-0001.htm>


More information about the webkit-unassigned mailing list