• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "config.h"
22 
23 #include "core/svg/SVGSwitchElement.h"
24 
25 #include "SVGNames.h"
26 #include "core/frame/UseCounter.h"
27 #include "core/rendering/svg/RenderSVGTransformableContainer.h"
28 
29 namespace WebCore {
30 
31 // Animated property definitions
DEFINE_ANIMATED_BOOLEAN(SVGSwitchElement,SVGNames::externalResourcesRequiredAttr,ExternalResourcesRequired,externalResourcesRequired)32 DEFINE_ANIMATED_BOOLEAN(SVGSwitchElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
33 
34 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSwitchElement)
35     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
36     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
37 END_REGISTER_ANIMATED_PROPERTIES
38 
39 inline SVGSwitchElement::SVGSwitchElement(Document& document)
40     : SVGGraphicsElement(SVGNames::switchTag, document)
41 {
42     ScriptWrappable::init(this);
43     registerAnimatedPropertiesForSVGSwitchElement();
44 
45     UseCounter::count(document, UseCounter::SVGSwitchElement);
46 }
47 
create(Document & document)48 PassRefPtr<SVGSwitchElement> SVGSwitchElement::create(Document& document)
49 {
50     return adoptRef(new SVGSwitchElement(document));
51 }
52 
childShouldCreateRenderer(const Node & child) const53 bool SVGSwitchElement::childShouldCreateRenderer(const Node& child) const
54 {
55     // FIXME: This function does not do what the comment below implies it does.
56     // It will create a renderer for any valid SVG element children, not just the first one.
57     bool shouldCreateRenderer = false;
58     for (Node* node = firstChild(); node; node = node->nextSibling()) {
59         if (!node->isSVGElement())
60             continue;
61 
62         SVGElement* element = toSVGElement(node);
63         if (!element || !element->isValid())
64             continue;
65 
66         shouldCreateRenderer = node == &child; // Only allow this child if it's the first valid child.
67         break;
68     }
69 
70     return shouldCreateRenderer && SVGGraphicsElement::childShouldCreateRenderer(child);
71 }
72 
createRenderer(RenderStyle *)73 RenderObject* SVGSwitchElement::createRenderer(RenderStyle*)
74 {
75     return new RenderSVGTransformableContainer(this);
76 }
77 
78 }
79