1 /* 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) 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 24 #include "core/rendering/svg/RenderSVGTransformableContainer.h" 25 26 #include "SVGNames.h" 27 #include "core/rendering/svg/SVGRenderSupport.h" 28 #include "core/svg/SVGGraphicsElement.h" 29 #include "core/svg/SVGUseElement.h" 30 31 namespace WebCore { 32 33 RenderSVGTransformableContainer::RenderSVGTransformableContainer(SVGGraphicsElement* node) 34 : RenderSVGContainer(node) 35 , m_needsTransformUpdate(true) 36 , m_didTransformToRootUpdate(false) 37 { 38 } 39 40 bool RenderSVGTransformableContainer::calculateLocalTransform() 41 { 42 SVGGraphicsElement* element = toSVGGraphicsElement(this->element()); 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 = 0; 48 if (element->hasTagName(SVGNames::useTag)) 49 useElement = toSVGUseElement(element); 50 else if (element->isInShadowTree() && element->hasTagName(SVGNames::gTag)) { 51 SVGElement* correspondingElement = element->correspondingElement(); 52 if (correspondingElement && correspondingElement->hasTagName(SVGNames::useTag)) 53 useElement = toSVGUseElement(correspondingElement); 54 } 55 56 if (useElement) { 57 SVGLengthContext lengthContext(useElement); 58 FloatSize translation(useElement->xCurrentValue().value(lengthContext), useElement->yCurrentValue().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.width(), m_lastTranslation.height()); 70 m_needsTransformUpdate = false; 71 return true; 72 } 73 74 } 75