File: SVGElementInstance.cpp

package info (click to toggle)
kde4libs 4%3A4.4.5-2%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 88,360 kB
  • ctags: 94,980
  • sloc: cpp: 721,043; xml: 146,205; ansic: 8,395; java: 4,060; perl: 3,118; yacc: 2,058; sh: 1,458; python: 1,050; ruby: 715; lex: 248; asm: 166; jsp: 128; haskell: 116; f90: 99; ml: 75; erlang: 54; awk: 38; tcl: 29; lisp: 24; makefile: 23; php: 9
file content (210 lines) | stat: -rw-r--r-- 5,723 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
    Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>

    This file is part of the KDE project

    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"
#include "wtf/Platform.h"

#if ENABLE(SVG)
#include "SVGElementInstance.h"

/*#include "Event.h"
#include "EventListener.h"*/
#include "SVGElementInstanceList.h"
#include "SVGUseElement.h"

#include <wtf/Assertions.h>

namespace WebCore {

SVGElementInstance::SVGElementInstance(SVGUseElement* useElement, PassRefPtr<SVGElement> originalElement)
    : m_refCount(0)
    , m_parent(0)
    , m_useElement(useElement)
    , m_element(originalElement)
    , m_shadowTreeElement(0)
    , m_previousSibling(0)
    , m_nextSibling(0)
    , m_firstChild(0)
    , m_lastChild(0)
{
    ASSERT(m_useElement);
    ASSERT(m_element);

    // Register as instance for passed element.
    m_element->document()->accessSVGExtensions()->mapInstanceToElement(this, m_element.get());
}

SVGElementInstance::~SVGElementInstance()
{
    for (RefPtr<SVGElementInstance> child = m_firstChild; child; child = child->m_nextSibling)
        child->setParent(0);

    // Deregister as instance for passed element.
    m_element->document()->accessSVGExtensions()->removeInstanceMapping(this, m_element.get());
}

SVGElement* SVGElementInstance::correspondingElement() const
{
    return m_element.get();
}

SVGUseElement* SVGElementInstance::correspondingUseElement() const
{
    return m_useElement;
}

SVGElementInstance* SVGElementInstance::parentNode() const
{
    return parent();
}

PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
{
    return SVGElementInstanceList::create(this);
}

SVGElementInstance* SVGElementInstance::previousSibling() const
{
    return m_previousSibling;
}

SVGElementInstance* SVGElementInstance::nextSibling() const
{
    return m_nextSibling;
}

SVGElementInstance* SVGElementInstance::firstChild() const
{
    return m_firstChild;
}

SVGElementInstance* SVGElementInstance::lastChild() const
{
    return m_lastChild;
}

SVGElement* SVGElementInstance::shadowTreeElement() const
{
    return m_shadowTreeElement;
}

void SVGElementInstance::setShadowTreeElement(SVGElement* element)
{
    ASSERT(element);
    m_shadowTreeElement = element;
}

void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
{
    child->setParent(this);

    if (m_lastChild) {
        child->m_previousSibling = m_lastChild;
        m_lastChild->m_nextSibling = child.get();
    } else
        m_firstChild = child.get();

    m_lastChild = child.get();
}

// Helper function for updateInstance
static bool containsUseChildNode(Node* start)
{
    if (start->hasTagName(SVGNames::useTag))
        return true;

    for (Node* current = start->firstChild(); current; current = current->nextSibling()) {
        if (containsUseChildNode(current))
            return true;
    }

    return false;
}

void SVGElementInstance::updateInstance(SVGElement* element)
{
    ASSERT(element == m_element);
    ASSERT(m_shadowTreeElement);

    // TODO: Eventually come up with a more optimized updating logic for the cases below:
    //
    // <symbol>: We can't just clone the original element, we need to apply
    // the same "replace by generated content" logic that SVGUseElement does.
    //
    // <svg>: <use> on <svg> is too rare to actually implement it faster.
    // If someone still wants to do it: recloning, adjusting width/height attributes is enough.
    //
    // <use>: Too hard to get it right in a fast way. Recloning seems the only option.

    if (m_element->hasTagName(SVGNames::symbolTag) ||
        m_element->hasTagName(SVGNames::svgTag) ||
        containsUseChildNode(m_element.get())) {
        m_useElement->buildPendingResource();
        return;
    }

    // For all other nodes this logic is sufficient.
    WTF::PassRefPtr<Node> clone = m_element->cloneNode(true);
    SVGUseElement::removeDisallowedElementsFromSubtree(clone.get());
    SVGElement* svgClone = 0;
    if (clone && clone->isSVGElement())
        svgClone = static_cast<SVGElement*>(clone.get());
    ASSERT(svgClone);

    // Replace node in the <use> shadow tree
    /*ExceptionCode*//*khtml*/int ec = 0;
    m_shadowTreeElement->parentNode()->replaceChild(clone.releaseRef(), m_shadowTreeElement, ec);
    ASSERT(ec == 0);

    m_shadowTreeElement = svgClone;
}

SVGElementInstance* SVGElementInstance::toSVGElementInstance()
{
    return this;
}

EventTargetNode* SVGElementInstance::toNode()
{
    return m_element.get();
}

void SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool useCapture)
{
    // FIXME!
}

void SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* eventListener, bool useCapture)
{
    // FIXME!
}

bool SVGElementInstance::dispatchEvent(PassRefPtr<Event>, ExceptionCode& ec, bool tempEvent)
{
    // FIXME!
    return false;
}
 
}

#endif // ENABLE(SVG)

// vim:ts=4:noet