Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/core/svg/animation/SVGSMILElement.cpp

Issue 2739893002: Store element reference for event-bases too (Closed)
Patch Set: Fix order Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 : m_type(type), 137 : m_type(type),
138 m_beginOrEnd(beginOrEnd), 138 m_beginOrEnd(beginOrEnd),
139 m_baseID(baseID), 139 m_baseID(baseID),
140 m_name(name), 140 m_name(name),
141 m_offset(offset), 141 m_offset(offset),
142 m_repeat(repeat) {} 142 m_repeat(repeat) {}
143 143
144 SVGSMILElement::Condition::~Condition() = default; 144 SVGSMILElement::Condition::~Condition() = default;
145 145
146 DEFINE_TRACE(SVGSMILElement::Condition) { 146 DEFINE_TRACE(SVGSMILElement::Condition) {
147 visitor->trace(m_syncBase); 147 visitor->trace(m_baseElement);
148 visitor->trace(m_eventListener); 148 visitor->trace(m_eventListener);
149 } 149 }
150 150
151 void SVGSMILElement::Condition::connectSyncBase(SVGSMILElement& timedElement) { 151 void SVGSMILElement::Condition::connectSyncBase(SVGSMILElement& timedElement) {
152 DCHECK(!m_baseID.isEmpty()); 152 DCHECK(!m_baseID.isEmpty());
153 DCHECK_EQ(m_type, Syncbase);
153 Element* element = timedElement.treeScope().getElementById(m_baseID); 154 Element* element = timedElement.treeScope().getElementById(m_baseID);
154 if (!element || !isSVGSMILElement(*element)) { 155 if (!element || !isSVGSMILElement(*element)) {
155 m_syncBase = nullptr; 156 m_baseElement = nullptr;
156 return; 157 return;
157 } 158 }
158 m_syncBase = toSVGSMILElement(element); 159 m_baseElement = toSVGSMILElement(element);
159 m_syncBase->addSyncBaseDependent(timedElement); 160 toSVGSMILElement(*element).addSyncBaseDependent(timedElement);
160 } 161 }
161 162
162 void SVGSMILElement::Condition::disconnectSyncBase( 163 void SVGSMILElement::Condition::disconnectSyncBase(
163 SVGSMILElement& timedElement) { 164 SVGSMILElement& timedElement) {
164 if (!m_syncBase) 165 DCHECK_EQ(m_type, Syncbase);
166 if (!m_baseElement)
165 return; 167 return;
166 m_syncBase->removeSyncBaseDependent(timedElement); 168 toSVGSMILElement(*m_baseElement).removeSyncBaseDependent(timedElement);
167 m_syncBase = nullptr; 169 m_baseElement = nullptr;
168 } 170 }
169 171
170 SVGElement* SVGSMILElement::Condition::lookupEventBase( 172 SVGElement* SVGSMILElement::Condition::lookupEventBase(
171 SVGSMILElement& timedElement) const { 173 SVGSMILElement& timedElement) const {
172 Element* eventBase = m_baseID.isEmpty() 174 Element* eventBase = m_baseID.isEmpty()
173 ? timedElement.targetElement() 175 ? timedElement.targetElement()
174 : timedElement.treeScope().getElementById(m_baseID); 176 : timedElement.treeScope().getElementById(m_baseID);
175 if (!eventBase || !eventBase->isSVGElement()) 177 if (!eventBase || !eventBase->isSVGElement())
176 return nullptr; 178 return nullptr;
177 return toSVGElement(eventBase); 179 return toSVGElement(eventBase);
178 } 180 }
179 181
180 void SVGSMILElement::Condition::connectEventBase(SVGSMILElement& timedElement) { 182 void SVGSMILElement::Condition::connectEventBase(SVGSMILElement& timedElement) {
181 DCHECK(!m_syncBase); 183 DCHECK_EQ(m_type, EventBase);
184 DCHECK(!m_baseElement);
182 SVGElement* eventBase = lookupEventBase(timedElement); 185 SVGElement* eventBase = lookupEventBase(timedElement);
183 if (!eventBase) { 186 if (!eventBase) {
184 if (m_baseID.isEmpty()) 187 if (m_baseID.isEmpty())
185 return; 188 return;
186 SVGTreeScopeResources& treeScopeResources = 189 SVGTreeScopeResources& treeScopeResources =
187 timedElement.treeScope().ensureSVGTreeScopedResources(); 190 timedElement.treeScope().ensureSVGTreeScopedResources();
188 if (!treeScopeResources.isElementPendingResource(timedElement, m_baseID)) 191 if (!treeScopeResources.isElementPendingResource(timedElement, m_baseID))
189 treeScopeResources.addPendingResource(m_baseID, timedElement); 192 treeScopeResources.addPendingResource(m_baseID, timedElement);
190 return; 193 return;
191 } 194 }
192 DCHECK(!m_eventListener); 195 DCHECK(!m_eventListener);
193 m_eventListener = ConditionEventListener::create(&timedElement, this); 196 m_eventListener = ConditionEventListener::create(&timedElement, this);
194 eventBase->addEventListener(m_name, m_eventListener, false); 197 m_baseElement = eventBase;
195 timedElement.addReferenceTo(eventBase); 198 m_baseElement->addEventListener(m_name, m_eventListener, false);
199 timedElement.addReferenceTo(m_baseElement);
196 } 200 }
197 201
198 void SVGSMILElement::Condition::disconnectEventBase( 202 void SVGSMILElement::Condition::disconnectEventBase(
199 SVGSMILElement& timedElement) { 203 SVGSMILElement& timedElement) {
200 DCHECK(!m_syncBase); 204 DCHECK_EQ(m_type, EventBase);
201 if (!m_eventListener) 205 if (!m_eventListener)
202 return; 206 return;
203 // Note: It's a memory optimization to try to remove our condition event 207 m_baseElement->removeEventListener(m_name, m_eventListener, false);
204 // listener, but it's not guaranteed to work, since we have no guarantee that 208 m_baseElement = nullptr;
205 // we will be able to find our condition's original eventBase. So, we also
206 // have to disconnect ourselves from our condition event listener, in case it
207 // later fires.
208 if (SVGElement* eventBase = lookupEventBase(timedElement))
209 eventBase->removeEventListener(m_name, m_eventListener, false);
210 m_eventListener->disconnectAnimation(); 209 m_eventListener->disconnectAnimation();
211 m_eventListener = nullptr; 210 m_eventListener = nullptr;
212 } 211 }
213 212
214 SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document& doc) 213 SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document& doc)
215 : SVGElement(tagName, doc), 214 : SVGElement(tagName, doc),
216 SVGTests(this), 215 SVGTests(this),
217 m_attributeName(anyQName()), 216 m_attributeName(anyQName()),
218 m_targetElement(nullptr), 217 m_targetElement(nullptr),
219 m_syncBaseConditionsConnected(false), 218 m_syncBaseConditionsConnected(false),
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 DEFINE_TRACE(SVGSMILElement) { 1290 DEFINE_TRACE(SVGSMILElement) {
1292 visitor->trace(m_targetElement); 1291 visitor->trace(m_targetElement);
1293 visitor->trace(m_timeContainer); 1292 visitor->trace(m_timeContainer);
1294 visitor->trace(m_conditions); 1293 visitor->trace(m_conditions);
1295 visitor->trace(m_syncBaseDependents); 1294 visitor->trace(m_syncBaseDependents);
1296 SVGElement::trace(visitor); 1295 SVGElement::trace(visitor);
1297 SVGTests::trace(visitor); 1296 SVGTests::trace(visitor);
1298 } 1297 }
1299 1298
1300 } // namespace blink 1299 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698