• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005, 2007 Rob Buis <buis@kde.org>
4                   2007 Eric Seidel <eric@webkit.org>
5                   2009 Google, Inc.
6 
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.
11 
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.
16 
17     You should have received a copy of the GNU Library General Public License
18     aint 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.
21 */
22 
23 #include "config.h"
24 
25 #if ENABLE(SVG)
26 #include "RenderSVGViewportContainer.h"
27 
28 #include "GraphicsContext.h"
29 
30 #include "RenderView.h"
31 #include "SVGMarkerElement.h"
32 #include "SVGSVGElement.h"
33 
34 namespace WebCore {
35 
RenderSVGViewportContainer(SVGStyledElement * node)36 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGStyledElement* node)
37     : RenderSVGContainer(node)
38 {
39 }
40 
paint(PaintInfo & paintInfo,int parentX,int parentY)41 void RenderSVGViewportContainer::paint(PaintInfo& paintInfo, int parentX, int parentY)
42 {
43     // FIXME: The if statement here evaluates to false. isEmpty() is exactly the same
44     // as what is on the right side, so it's basically !isEmpty && isEmpty. So this
45     // function does nothing.
46 
47     // A value of zero disables rendering of the element.
48     if (!m_viewport.isEmpty() && (m_viewport.width() <= 0. || m_viewport.height() <= 0.))
49         return;
50 
51     RenderSVGContainer::paint(paintInfo, parentX, parentY);
52 }
53 
applyViewportClip(PaintInfo & paintInfo)54 void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo)
55 {
56     if (style()->overflowX() != OVISIBLE)
57         paintInfo.context->clip(enclosingIntRect(m_viewport)); // FIXME: Eventually we'll want float-precision clipping
58 }
59 
calcViewport()60 void RenderSVGViewportContainer::calcViewport()
61 {
62     SVGElement* svgelem = static_cast<SVGElement*>(node());
63     if (svgelem->hasTagName(SVGNames::svgTag)) {
64         SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
65 
66         if (!selfNeedsLayout() && !svg->hasRelativeValues())
67             return;
68 
69         float x = svg->x().value(svg);
70         float y = svg->y().value(svg);
71         float w = svg->width().value(svg);
72         float h = svg->height().value(svg);
73         m_viewport = FloatRect(x, y, w, h);
74     } else if (svgelem->hasTagName(SVGNames::markerTag)) {
75         if (!selfNeedsLayout())
76             return;
77 
78         SVGMarkerElement* svg = static_cast<SVGMarkerElement*>(node());
79         float w = svg->markerWidth().value(svg);
80         float h = svg->markerHeight().value(svg);
81         m_viewport = FloatRect(0, 0, w, h);
82     }
83 }
84 
viewportTransform() const85 TransformationMatrix RenderSVGViewportContainer::viewportTransform() const
86 {
87     if (node()->hasTagName(SVGNames::svgTag)) {
88         SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
89         return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
90     } else if (node()->hasTagName(SVGNames::markerTag)) {
91         SVGMarkerElement* marker = static_cast<SVGMarkerElement*>(node());
92         return marker->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
93     }
94 
95     return TransformationMatrix();
96 }
97 
localToParentTransform() const98 TransformationMatrix RenderSVGViewportContainer::localToParentTransform() const
99 {
100     TransformationMatrix viewportTranslation;
101     viewportTranslation.translate(m_viewport.x(), m_viewport.y());
102     return viewportTransform() * viewportTranslation;
103     // If this class were ever given a localTransform(), then the above would read:
104     // return viewportTransform() * localTransform() * viewportTranslation;
105 }
106 
107 // FIXME: This method should be removed as soon as callers to RenderBox::absoluteTransform() can be removed.
absoluteTransform() const108 TransformationMatrix RenderSVGViewportContainer::absoluteTransform() const
109 {
110     // This would apply localTransform() twice if localTransform() were not the identity.
111     return localToParentTransform() * RenderSVGContainer::absoluteTransform();
112 }
113 
pointIsInsideViewportClip(const FloatPoint & pointInParent)114 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
115 {
116     // Respect the viewport clip (which is in parent coords).  SVG does not support separate x/y overflow rules.
117     if (style()->overflowX() == OHIDDEN) {
118         ASSERT(style()->overflowY() == OHIDDEN);
119         if (!m_viewport.contains(pointInParent))
120             return false;
121     }
122     return true;
123 }
124 
125 }
126 
127 #endif // ENABLE(SVG)
128 
129 // vim:ts=4:noet
130