1/*
2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2009 Google, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "config.h"
23#include "RenderSVGTransformableContainer.h"
24
25#include "SVGGElement.h"
26#include "SVGUseElement.h"
27#include <wtf/IsoMallocInlines.h>
28
29namespace WebCore {
30
31WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGTransformableContainer);
32
33RenderSVGTransformableContainer::RenderSVGTransformableContainer(SVGGraphicsElement& element, RenderStyle&& style)
34 : RenderSVGContainer(element, WTFMove(style))
35 , m_needsTransformUpdate(true)
36 , m_didTransformToRootUpdate(false)
37{
38}
39
40bool RenderSVGTransformableContainer::calculateLocalTransform()
41{
42 SVGGraphicsElement& element = graphicsElement();
43
44 // If we're either the renderer for a <use> element, or for any <g> element inside the shadow
45 // tree, that was created during the use/symbol/svg expansion in SVGUseElement. These containers
46 // need to respect the translations induced by their corresponding use elements x/y attributes.
47 SVGUseElement* useElement = nullptr;
48 if (is<SVGUseElement>(element))
49 useElement = &downcast<SVGUseElement>(element);
50 else if (element.isInShadowTree() && is<SVGGElement>(element)) {
51 SVGElement* correspondingElement = element.correspondingElement();
52 if (is<SVGUseElement>(correspondingElement))
53 useElement = downcast<SVGUseElement>(correspondingElement);
54 }
55
56 if (useElement) {
57 SVGLengthContext lengthContext(useElement);
58 FloatSize translation(useElement->x().value(lengthContext), useElement->y().value(lengthContext));
59 if (translation != m_lastTranslation)
60 m_needsTransformUpdate = true;
61 m_lastTranslation = translation;
62 }
63
64 m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::transformToRootChanged(parent());
65 if (!m_needsTransformUpdate)
66 return false;
67
68 m_localTransform = element.animatedLocalTransform();
69 m_localTransform.translate(m_lastTranslation);
70 m_needsTransformUpdate = false;
71 return true;
72}
73
74}
75