tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / rendering / svg / SVGShadowTreeElements.cpp
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 "CSSStyleSelector.h"
26 #include "Document.h"
27 #include "FloatSize.h"
28 #include "RenderObject.h"
29 #include "SVGNames.h"
30 #include "SVGUseElement.h"
31
32 namespace WebCore {
33
34 // SVGShadowTreeContainerElement
35
36 SVGShadowTreeContainerElement::SVGShadowTreeContainerElement(Document* document, ConstructionType constructionType)
37     : SVGGElement(SVGNames::gTag, document, constructionType)
38     , m_containerOffsetChanged(false)
39 {
40 }
41
42 PassRefPtr<SVGShadowTreeContainerElement> SVGShadowTreeContainerElement::create(Document* document)
43 {
44     return adoptRef(new SVGShadowTreeContainerElement(document));
45 }
46
47 void SVGShadowTreeContainerElement::setContainerOffset(const SVGLength& x, const SVGLength& y)
48 {
49     m_containerOffsetChanged = true;
50     m_xOffset = x;
51     m_yOffset = y;
52 }
53
54 FloatSize SVGShadowTreeContainerElement::containerTranslation() const
55 {
56     SVGLengthContext lengthContext(this);
57     return FloatSize(m_xOffset.value(lengthContext), m_yOffset.value(lengthContext));
58 }
59
60 PassRefPtr<Element> SVGShadowTreeContainerElement::cloneElementWithoutAttributesAndChildren()
61 {
62     return adoptRef(new SVGShadowTreeContainerElement(document()));
63 }
64 // SVGShadowTreeRootElement
65
66 inline SVGShadowTreeRootElement::SVGShadowTreeRootElement(Document* document, SVGUseElement* host)
67     : SVGShadowTreeContainerElement(document, CreateSVGShadowRoot)
68 {
69     setParent(host);
70     setInDocument();
71 }
72
73 PassRefPtr<SVGShadowTreeRootElement> SVGShadowTreeRootElement::create(Document* document, SVGUseElement* host)
74 {
75     return adoptRef(new SVGShadowTreeRootElement(document, host));
76 }
77
78 void SVGShadowTreeRootElement::attachElement(PassRefPtr<RenderStyle> style, RenderArena* arena)
79 {
80     ASSERT(svgShadowHost());
81
82     // Create the renderer with the specified style
83     RenderObject* renderer = createRenderer(arena, style.get());
84     if (renderer) {
85         setRenderer(renderer);
86         renderer->setStyle(style);
87     }
88
89     // Set these explicitly since this normally happens during an attach()
90     setAttached();
91
92     // Add the renderer to the render tree
93     if (renderer)
94         svgShadowHost()->renderer()->addChild(renderer);
95 }
96
97 void SVGShadowTreeRootElement::clearSVGShadowHost()
98 {
99     setParent(0);
100 }
101
102 PassRefPtr<RenderStyle> SVGShadowTreeContainerElement::customStyleForRenderer()
103 {
104     return document()->styleSelector()->styleForElement(this, 0, true/*allowSharing*/);
105 }
106
107 }
108
109 #endif