1 | /* |
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. |
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 | * 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. |
21 | */ |
22 | |
23 | #include "config.h" |
24 | #include "RenderSVGViewportContainer.h" |
25 | |
26 | #include "GraphicsContext.h" |
27 | #include "RenderView.h" |
28 | #include "SVGSVGElement.h" |
29 | #include <wtf/IsoMallocInlines.h> |
30 | |
31 | namespace WebCore { |
32 | |
33 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGViewportContainer); |
34 | |
35 | RenderSVGViewportContainer::RenderSVGViewportContainer(SVGSVGElement& element, RenderStyle&& style) |
36 | : RenderSVGContainer(element, WTFMove(style)) |
37 | , m_didTransformToRootUpdate(false) |
38 | , m_isLayoutSizeChanged(false) |
39 | , m_needsTransformUpdate(true) |
40 | { |
41 | } |
42 | |
43 | SVGSVGElement& RenderSVGViewportContainer::svgSVGElement() const |
44 | { |
45 | return downcast<SVGSVGElement>(RenderSVGContainer::element()); |
46 | } |
47 | |
48 | void RenderSVGViewportContainer::determineIfLayoutSizeChanged() |
49 | { |
50 | m_isLayoutSizeChanged = svgSVGElement().hasRelativeLengths() && selfNeedsLayout(); |
51 | } |
52 | |
53 | void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo) |
54 | { |
55 | if (SVGRenderSupport::isOverflowHidden(*this)) |
56 | paintInfo.context().clip(m_viewport); |
57 | } |
58 | |
59 | void RenderSVGViewportContainer::calcViewport() |
60 | { |
61 | SVGSVGElement& element = svgSVGElement(); |
62 | SVGLengthContext lengthContext(&element); |
63 | FloatRect newViewport(element.x().value(lengthContext), element.y().value(lengthContext), element.width().value(lengthContext), element.height().value(lengthContext)); |
64 | |
65 | if (m_viewport == newViewport) |
66 | return; |
67 | |
68 | m_viewport = newViewport; |
69 | |
70 | setNeedsBoundariesUpdate(); |
71 | setNeedsTransformUpdate(); |
72 | } |
73 | |
74 | bool RenderSVGViewportContainer::calculateLocalTransform() |
75 | { |
76 | m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::transformToRootChanged(parent()); |
77 | if (!m_needsTransformUpdate) |
78 | return false; |
79 | |
80 | m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform(); |
81 | m_needsTransformUpdate = false; |
82 | return true; |
83 | } |
84 | |
85 | AffineTransform RenderSVGViewportContainer::viewportTransform() const |
86 | { |
87 | return svgSVGElement().viewBoxToViewTransform(m_viewport.width(), m_viewport.height()); |
88 | } |
89 | |
90 | bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent) |
91 | { |
92 | // Respect the viewport clip (which is in parent coords) |
93 | if (!SVGRenderSupport::isOverflowHidden(*this)) |
94 | return true; |
95 | |
96 | return m_viewport.contains(pointInParent); |
97 | } |
98 | |
99 | void RenderSVGViewportContainer::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
100 | { |
101 | // An empty viewBox disables rendering. |
102 | if (svgSVGElement().hasEmptyViewBox()) |
103 | return; |
104 | |
105 | RenderSVGContainer::paint(paintInfo, paintOffset); |
106 | } |
107 | |
108 | } |
109 | |