2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "core/rendering/svg/RenderSVGViewportContainer.h"
26 #include "core/paint/SVGContainerPainter.h"
27 #include "core/rendering/PaintInfo.h"
28 #include "core/rendering/svg/SVGRenderSupport.h"
29 #include "core/svg/SVGSVGElement.h"
30 #include "core/svg/SVGUseElement.h"
31 #include "platform/graphics/GraphicsContext.h"
35 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGElement* node)
36 : RenderSVGContainer(node)
37 , m_didTransformToRootUpdate(false)
38 , m_isLayoutSizeChanged(false)
39 , m_needsTransformUpdate(true)
43 void RenderSVGViewportContainer::determineIfLayoutSizeChanged()
46 if (!isSVGSVGElement(*element()))
49 m_isLayoutSizeChanged = toSVGSVGElement(element())->hasRelativeLengths() && selfNeedsLayout();
52 void RenderSVGViewportContainer::calcViewport()
54 SVGElement* element = this->element();
56 if (!isSVGSVGElement(*element))
58 SVGSVGElement* svg = toSVGSVGElement(element);
59 FloatRect oldViewport = m_viewport;
61 SVGLengthContext lengthContext(element);
62 m_viewport = FloatRect(svg->x()->currentValue()->value(lengthContext), svg->y()->currentValue()->value(lengthContext), svg->width()->currentValue()->value(lengthContext), svg->height()->currentValue()->value(lengthContext));
64 if (oldViewport != m_viewport) {
65 setNeedsBoundariesUpdate();
66 setNeedsTransformUpdate();
70 bool RenderSVGViewportContainer::calculateLocalTransform()
72 m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::transformToRootChanged(parent());
73 if (!m_needsTransformUpdate)
76 m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform();
77 m_needsTransformUpdate = false;
81 AffineTransform RenderSVGViewportContainer::viewportTransform() const
84 if (isSVGSVGElement(*element())) {
85 SVGSVGElement* svg = toSVGSVGElement(element());
86 return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
89 return AffineTransform();
92 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
94 // Respect the viewport clip (which is in parent coords)
95 if (!SVGRenderSupport::isOverflowHidden(this))
98 return m_viewport.contains(pointInParent);
101 void RenderSVGViewportContainer::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
103 SVGContainerPainter(*this).paint(paintInfo);