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)
37 , m_isLayoutSizeChanged(false)
41 void RenderSVGViewportContainer::determineIfLayoutSizeChanged()
43 if (!node()->hasTagName(SVGNames::svgTag))
46 m_isLayoutSizeChanged = static_cast<SVGSVGElement*>(node())->hasRelativeLengths() && selfNeedsLayout();
49 void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo)
51 if (SVGRenderSupport::isOverflowHidden(this))
52 paintInfo.context->clip(m_viewport);
55 void RenderSVGViewportContainer::calcViewport()
57 SVGElement* element = static_cast<SVGElement*>(node());
58 if (!element->hasTagName(SVGNames::svgTag))
60 SVGSVGElement* svg = static_cast<SVGSVGElement*>(element);
61 FloatRect oldViewport = m_viewport;
63 SVGLengthContext lengthContext(element);
64 m_viewport = FloatRect(svg->x().value(lengthContext), svg->y().value(lengthContext), svg->width().value(lengthContext), svg->height().value(lengthContext));
66 if (oldViewport != m_viewport)
67 setNeedsBoundariesUpdate();
70 AffineTransform RenderSVGViewportContainer::viewportTransform() const
72 if (node()->hasTagName(SVGNames::svgTag)) {
73 SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
74 return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
77 return AffineTransform();
80 const AffineTransform& RenderSVGViewportContainer::localToParentTransform() const
82 m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform();
83 return m_localToParentTransform;
84 // If this class were ever given a localTransform(), then the above would read:
85 // return viewportTranslation * localTransform() * viewportTransform()
88 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
90 // Respect the viewport clip (which is in parent coords)
91 if (!SVGRenderSupport::isOverflowHidden(this))
94 return m_viewport.contains(pointInParent);