diff options
author | Kristian Monsen <kristianm@google.com> | 2010-07-30 10:46:49 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-08-04 13:01:34 +0100 |
commit | 0617145a89917ae7735fe1c9538688ab9a577df5 (patch) | |
tree | 56206078694427c37ed7bdf27eb5221398b833c0 /WebCore/rendering/RenderSVGResourceContainer.cpp | |
parent | ef1adcdfc805d4d13103f6f15cc5b4d96828a60f (diff) | |
download | external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.zip external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.gz external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.bz2 |
Merge WebKit at r64264 : Initial merge by git.
Change-Id: Ic42bef02efef8217a0f84c47176a9c617c28d1f1
Diffstat (limited to 'WebCore/rendering/RenderSVGResourceContainer.cpp')
-rw-r--r-- | WebCore/rendering/RenderSVGResourceContainer.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/WebCore/rendering/RenderSVGResourceContainer.cpp b/WebCore/rendering/RenderSVGResourceContainer.cpp new file mode 100644 index 0000000..3707797 --- /dev/null +++ b/WebCore/rendering/RenderSVGResourceContainer.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "RenderSVGResourceContainer.h" + +#include "RenderSVGShadowTreeRootContainer.h" +#include "SVGStyledTransformableElement.h" + +namespace WebCore { + +RenderSVGResourceContainer::RenderSVGResourceContainer(SVGStyledElement* node) + : RenderSVGHiddenContainer(node) + , RenderSVGResource() + , m_id(node->hasID() ? node->getIdAttribute() : nullAtom) +{ + ASSERT(node->document()); + node->document()->accessSVGExtensions()->addResource(m_id, this); +} + +RenderSVGResourceContainer::~RenderSVGResourceContainer() +{ + ASSERT(node()); + ASSERT(node()->document()); + node()->document()->accessSVGExtensions()->removeResource(m_id); +} + +void RenderSVGResourceContainer::idChanged() +{ + ASSERT(node()); + ASSERT(node()->document()); + SVGDocumentExtensions* extensions = node()->document()->accessSVGExtensions(); + + // Remove old id, that is guaranteed to be present in cache + extensions->removeResource(m_id); + m_id = static_cast<Element*>(node())->getIdAttribute(); + + // It's possible that an element is referencing us with the new id, and has to be notified that we're existing now + if (extensions->isPendingResource(m_id)) { + OwnPtr<HashSet<SVGStyledElement*> > clients(extensions->removePendingResource(m_id)); + if (clients->isEmpty()) + return; + + HashSet<SVGStyledElement*>::const_iterator it = clients->begin(); + const HashSet<SVGStyledElement*>::const_iterator end = clients->end(); + + for (; it != end; ++it) { + if (RenderObject* renderer = (*it)->renderer()) + renderer->setNeedsLayout(true); + } + } + + // Recache us with the new id + extensions->addResource(m_id, this); +} + +AffineTransform RenderSVGResourceContainer::transformOnNonScalingStroke(RenderObject* object, const AffineTransform& resourceTransform) +{ + if (!object->isRenderPath()) + return resourceTransform; + + SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(object->node()); + AffineTransform transform = resourceTransform; + transform.multiply(element->getScreenCTM()); + return transform; +} + +bool RenderSVGResourceContainer::containsCyclicReference(const Node* startNode) const +{ + ASSERT(startNode->document()); + + for (Node* node = startNode->firstChild(); node; node = node->nextSibling()) { + if (!node->isSVGElement()) + continue; + + RenderObject* renderer = node->renderer(); + if (!renderer) + continue; + + RenderStyle* style = renderer->style(); + if (!style) + continue; + + const SVGRenderStyle* svgStyle = style->svgStyle(); + ASSERT(svgStyle); + + // Let the class inheriting from us decide whether the child element references ourselves. + if (childElementReferencesResource(svgStyle, m_id)) + return true; + + // Dive into shadow tree to check for cycles there. + if (node->hasTagName(SVGNames::useTag)) { + ASSERT(renderer->isSVGShadowTreeRootContainer()); + if (Node* shadowRoot = static_cast<RenderSVGShadowTreeRootContainer*>(renderer)->rootElement()) { + if (containsCyclicReference(shadowRoot)) + return true; + } + + } + + if (node->hasChildNodes()) { + if (containsCyclicReference(node)) + return true; + } + } + + return false; +} + +} + +#endif |