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.
26 #include "RenderSVGViewportContainer.h"
28 #include "GraphicsContext.h"
29 #include "RenderView.h"
31 #include "SVGSVGElement.h"
35 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGStyledElement* node)
36 : RenderSVGContainer(node)
40 void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo)
42 if (SVGRenderSupport::isOverflowHidden(this))
43 paintInfo.context->clip(m_viewport);
46 void RenderSVGViewportContainer::calcViewport()
48 SVGElement* element = static_cast<SVGElement*>(node());
49 if (!element->hasTagName(SVGNames::svgTag))
51 SVGSVGElement* svg = static_cast<SVGSVGElement*>(element);
52 FloatRect oldViewport = m_viewport;
54 SVGLengthContext lengthContext(element);
55 m_viewport = FloatRect(svg->x().value(lengthContext), svg->y().value(lengthContext), svg->width().value(lengthContext), svg->height().value(lengthContext));
57 if (oldViewport != m_viewport)
58 setNeedsBoundariesUpdate();
61 AffineTransform RenderSVGViewportContainer::viewportTransform() const
63 if (node()->hasTagName(SVGNames::svgTag)) {
64 SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
65 return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
68 return AffineTransform();
71 const AffineTransform& RenderSVGViewportContainer::localToParentTransform() const
73 m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform();
74 return m_localToParentTransform;
75 // If this class were ever given a localTransform(), then the above would read:
76 // return viewportTranslation * localTransform() * viewportTransform()
79 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
81 // Respect the viewport clip (which is in parent coords)
82 if (!SVGRenderSupport::isOverflowHidden(this))
85 return m_viewport.contains(pointInParent);