1/*
2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef SVGImage_h
28#define SVGImage_h
29
30#include "Image.h"
31#include "URL.h"
32
33namespace WebCore {
34
35class Element;
36class FrameView;
37class ImageBuffer;
38class Page;
39class RenderBox;
40class SVGImageChromeClient;
41class SVGImageForContainer;
42
43class SVGImage final : public Image {
44public:
45    static PassRefPtr<SVGImage> create(ImageObserver* observer)
46    {
47        return adoptRef(new SVGImage(observer));
48    }
49
50    RenderBox* embeddedContentBox() const;
51    FrameView* frameView() const;
52
53    virtual bool isSVGImage() const override { return true; }
54    virtual FloatSize size() const override { return m_intrinsicSize; }
55
56    void setURL(const URL& url) { m_url = url; }
57
58    virtual bool hasSingleSecurityOrigin() const override;
59
60    virtual bool hasRelativeWidth() const override;
61    virtual bool hasRelativeHeight() const override;
62
63    virtual void startAnimation(CatchUpAnimation = CatchUp) override;
64    virtual void stopAnimation() override;
65    virtual void resetAnimation() override;
66
67#if USE(CAIRO)
68    virtual PassNativeImagePtr nativeImageForCurrentFrame() override;
69#endif
70
71private:
72    friend class SVGImageChromeClient;
73    friend class SVGImageForContainer;
74
75    virtual ~SVGImage();
76
77    virtual String filenameExtension() const override;
78
79    virtual void setContainerSize(const FloatSize&) override;
80    IntSize containerSize() const;
81    virtual bool usesContainerSize() const override { return true; }
82    virtual void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) override;
83
84    virtual bool dataChanged(bool allDataReceived) override;
85
86    // FIXME: SVGImages will be unable to prune because this function is not implemented yet.
87    virtual void destroyDecodedData(bool) override { }
88
89    // FIXME: Implement this to be less conservative.
90    virtual bool currentFrameKnownToBeOpaque() override { return false; }
91
92    SVGImage(ImageObserver*);
93    virtual void draw(GraphicsContext*, const FloatRect& fromRect, const FloatRect& toRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, ImageOrientationDescription) override;
94    void drawForContainer(GraphicsContext*, const FloatSize, float, const FloatRect&, const FloatRect&, ColorSpace, CompositeOperator, BlendMode);
95    void drawPatternForContainer(GraphicsContext*, const FloatSize, float, const FloatRect&, const AffineTransform&, const FloatPoint&, ColorSpace,
96        CompositeOperator, const FloatRect&, BlendMode);
97
98    std::unique_ptr<SVGImageChromeClient> m_chromeClient;
99    std::unique_ptr<Page> m_page;
100    FloatSize m_intrinsicSize;
101    URL m_url;
102};
103
104bool isInSVGImage(const Element*);
105
106IMAGE_TYPE_CASTS(SVGImage)
107
108}
109
110#endif // SVGImage_h
111