OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | |
3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | |
4 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Library General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Library General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Library General Public License | |
17 * along with this library; see the file COPYING.LIB. If not, write to | |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 * Boston, MA 02110-1301, USA. | |
20 */ | |
21 | |
22 #include "config.h" | |
23 | |
24 #include "core/svg/SVGElementInstance.h" | |
25 | |
26 #include "core/dom/ContainerNodeAlgorithms.h" | |
27 #include "core/events/Event.h" | |
28 #include "core/events/EventListener.h" | |
29 #include "core/svg/SVGElement.h" | |
30 #include "core/svg/SVGUseElement.h" | |
31 | |
32 #include "wtf/RefCountedLeakCounter.h" | |
33 | |
34 namespace WebCore { | |
35 | |
36 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, instanceCounter, ("WebCoreS
VGElementInstance")); | |
37 | |
38 PassRefPtrWillBeRawPtr<SVGElementInstance> SVGElementInstance::create(SVGUseElem
ent* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtrWillBeR
awPtr<SVGElement> originalElement) | |
39 { | |
40 return adoptRefWillBeRefCountedGarbageCollected(new SVGElementInstance(corre
spondingUseElement, directUseElement, originalElement)); | |
41 } | |
42 | |
43 SVGElementInstance::SVGElementInstance(SVGUseElement* correspondingUseElement, S
VGUseElement* directUseElement, PassRefPtrWillBeRawPtr<SVGElement> originalEleme
nt) | |
44 : m_parentInstance(nullptr) | |
45 , m_correspondingUseElement(correspondingUseElement) | |
46 , m_directUseElement(directUseElement) | |
47 , m_element(originalElement) | |
48 , m_previousSibling(nullptr) | |
49 , m_nextSibling(nullptr) | |
50 , m_firstChild(nullptr) | |
51 , m_lastChild(nullptr) | |
52 { | |
53 ASSERT(m_correspondingUseElement); | |
54 ASSERT(m_element); | |
55 ScriptWrappable::init(this); | |
56 | |
57 #ifndef NDEBUG | |
58 instanceCounter.increment(); | |
59 #endif | |
60 } | |
61 | |
62 SVGElementInstance::~SVGElementInstance() | |
63 { | |
64 #ifndef NDEBUG | |
65 instanceCounter.decrement(); | |
66 #endif | |
67 | |
68 #if !ENABLE(OILPAN) | |
69 // Call detach because we may be deleted directly if we are a child of a det
ached instance. | |
70 detach(); | |
71 m_element = nullptr; | |
72 #endif | |
73 } | |
74 | |
75 // It's important not to inline removedLastRef, because we don't want to inline
the code to | |
76 // delete an SVGElementInstance at each deref call site. | |
77 #if !ENABLE(OILPAN) | |
78 void SVGElementInstance::removedLastRef() | |
79 { | |
80 #if SECURITY_ASSERT_ENABLED | |
81 m_deletionHasBegun = true; | |
82 #endif | |
83 delete this; | |
84 } | |
85 #endif | |
86 | |
87 void SVGElementInstance::detach() | |
88 { | |
89 // Clear all pointers. When the node is detached from the shadow DOM it shou
ld be removed but, | |
90 // due to ref counting, it may not be. So clear everything to avoid dangling
pointers. | |
91 | |
92 for (SVGElementInstance* node = firstChild(); node; node = node->nextSibling
()) | |
93 node->detach(); | |
94 | |
95 // Deregister as instance for passed element, if we haven't already. | |
96 if (shadowTreeElement() && m_element->instancesForElement().contains(shadowT
reeElement())) | |
97 m_element->removeInstanceMapping(shadowTreeElement()); | |
98 | |
99 m_shadowTreeElement = nullptr; | |
100 | |
101 m_directUseElement = nullptr; | |
102 m_correspondingUseElement = nullptr; | |
103 | |
104 #if !ENABLE(OILPAN) | |
105 removeDetachedChildrenInContainer<SVGElementInstance, SVGElementInstance>(*t
his); | |
106 #endif | |
107 } | |
108 | |
109 void SVGElementInstance::setShadowTreeElement(SVGElement* element) | |
110 { | |
111 ASSERT(element); | |
112 m_shadowTreeElement = element; | |
113 // Register as instance for passed element. | |
114 m_element->mapInstanceToElement(shadowTreeElement()); | |
115 | |
116 } | |
117 | |
118 void SVGElementInstance::appendChild(PassRefPtrWillBeRawPtr<SVGElementInstance>
child) | |
119 { | |
120 appendChildToContainer<SVGElementInstance, SVGElementInstance>(*child, *this
); | |
121 } | |
122 | |
123 void SVGElementInstance::trace(Visitor* visitor) | |
124 { | |
125 visitor->trace(m_parentInstance); | |
126 visitor->trace(m_correspondingUseElement); | |
127 visitor->trace(m_directUseElement); | |
128 visitor->trace(m_element); | |
129 visitor->trace(m_shadowTreeElement); | |
130 visitor->trace(m_previousSibling); | |
131 visitor->trace(m_nextSibling); | |
132 visitor->trace(m_firstChild); | |
133 visitor->trace(m_lastChild); | |
134 } | |
135 | |
136 } | |
OLD | NEW |