1 /*
2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "config.h"
21 
22 #if ENABLE(SVG)
23 #include "SVGShadowTreeElements.h"
24 
25 #include "Document.h"
26 #include "FloatSize.h"
27 #include "RenderObject.h"
28 #include "SVGNames.h"
29 #include "SVGUseElement.h"
30 
31 namespace WebCore {
32 
33 // SVGShadowTreeContainerElement
34 
SVGShadowTreeContainerElement(Document * document)35 SVGShadowTreeContainerElement::SVGShadowTreeContainerElement(Document* document)
36     : SVGGElement(SVGNames::gTag, document)
37 {
38 }
39 
create(Document * document)40 PassRefPtr<SVGShadowTreeContainerElement> SVGShadowTreeContainerElement::create(Document* document)
41 {
42     return adoptRef(new SVGShadowTreeContainerElement(document));
43 }
44 
containerTranslation() const45 FloatSize SVGShadowTreeContainerElement::containerTranslation() const
46 {
47     return FloatSize(m_xOffset.value(this), m_yOffset.value(this));
48 }
49 
cloneElementWithoutAttributesAndChildren() const50 PassRefPtr<Element> SVGShadowTreeContainerElement::cloneElementWithoutAttributesAndChildren() const
51 {
52     return adoptRef(new SVGShadowTreeContainerElement(document()));
53 }
54 // SVGShadowTreeRootElement
55 
SVGShadowTreeRootElement(Document * document,SVGUseElement * host)56 inline SVGShadowTreeRootElement::SVGShadowTreeRootElement(Document* document, SVGUseElement* host)
57     : SVGShadowTreeContainerElement(document)
58 {
59     setParent(host);
60     setInDocument();
61 }
62 
create(Document * document,SVGUseElement * host)63 PassRefPtr<SVGShadowTreeRootElement> SVGShadowTreeRootElement::create(Document* document, SVGUseElement* host)
64 {
65     return adoptRef(new SVGShadowTreeRootElement(document, host));
66 }
67 
attachElement(PassRefPtr<RenderStyle> style,RenderArena * arena)68 void SVGShadowTreeRootElement::attachElement(PassRefPtr<RenderStyle> style, RenderArena* arena)
69 {
70     ASSERT(svgShadowHost());
71 
72     // Create the renderer with the specified style
73     RenderObject* renderer = createRenderer(arena, style.get());
74     if (renderer) {
75         setRenderer(renderer);
76         renderer->setStyle(style);
77     }
78 
79     // Set these explicitly since this normally happens during an attach()
80     setAttached();
81 
82     // Add the renderer to the render tree
83     if (renderer)
84         svgShadowHost()->renderer()->addChild(renderer);
85 }
86 
clearSVGShadowHost()87 void SVGShadowTreeRootElement::clearSVGShadowHost()
88 {
89     setParent(0);
90 }
91 
92 }
93 
94 #endif
95