1/*
2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Rob Buis <buis@kde.org>
5 * Copyright (C) 2009 Google, Inc.
6 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB.  If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef RenderSVGImage_h
25#define RenderSVGImage_h
26
27#if ENABLE(SVG)
28#include "AffineTransform.h"
29#include "FloatRect.h"
30#include "RenderSVGModelObject.h"
31#include "SVGPreserveAspectRatio.h"
32#include "SVGRenderSupport.h"
33
34namespace WebCore {
35
36class RenderImageResource;
37class SVGImageElement;
38
39class RenderSVGImage : public RenderSVGModelObject {
40public:
41    RenderSVGImage(SVGImageElement*);
42    virtual ~RenderSVGImage();
43
44    bool updateImageViewport();
45    virtual void setNeedsBoundariesUpdate() { m_needsBoundariesUpdate = true; }
46    virtual bool needsBoundariesUpdate() OVERRIDE { return m_needsBoundariesUpdate; }
47    virtual void setNeedsTransformUpdate() { m_needsTransformUpdate = true; }
48
49    RenderImageResource* imageResource() { return m_imageResource.get(); }
50    const RenderImageResource* imageResource() const { return m_imageResource.get(); }
51
52    // Note: Assumes the PaintInfo context has had all local transforms applied.
53    void paintForeground(PaintInfo&);
54
55private:
56    virtual const char* renderName() const { return "RenderSVGImage"; }
57    virtual bool isSVGImage() const OVERRIDE { return true; }
58
59    virtual const AffineTransform& localToParentTransform() const { return m_localTransform; }
60
61    virtual FloatRect objectBoundingBox() const { return m_objectBoundingBox; }
62    virtual FloatRect strokeBoundingBox() const { return m_objectBoundingBox; }
63    virtual FloatRect repaintRectInLocalCoordinates() const { return m_repaintBoundingBox; }
64    virtual FloatRect repaintRectInLocalCoordinatesExcludingSVGShadow() const OVERRIDE { return m_repaintBoundingBoxExcludingShadow; }
65
66    virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
67
68    virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
69
70    virtual void layout();
71    virtual void paint(PaintInfo&, const LayoutPoint&);
72
73    void invalidateBufferedForeground();
74
75    virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
76
77    virtual AffineTransform localTransform() const { return m_localTransform; }
78    void calculateImageViewport();
79
80    bool m_needsBoundariesUpdate : 1;
81    bool m_needsTransformUpdate : 1;
82    AffineTransform m_localTransform;
83    FloatRect m_objectBoundingBox;
84    FloatRect m_repaintBoundingBox;
85    FloatRect m_repaintBoundingBoxExcludingShadow;
86    OwnPtr<RenderImageResource> m_imageResource;
87
88    OwnPtr<ImageBuffer> m_bufferedForeground;
89};
90
91inline RenderSVGImage* toRenderSVGImage(RenderObject* object)
92{
93    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGImage());
94    return static_cast<RenderSVGImage*>(object);
95}
96
97inline const RenderSVGImage* toRenderSVGImage(const RenderObject* object)
98{
99    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGImage());
100    return static_cast<const RenderSVGImage*>(object);
101}
102
103// This will catch anyone doing an unnecessary cast.
104void toRenderSVGImage(const RenderSVGImage*);
105
106} // namespace WebCore
107
108#endif // ENABLE(SVG)
109#endif // RenderSVGImage_h
110