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

Side by Side Diff: Source/core/dom/MutationObserver.cpp

Issue 257513002: Add synonyms for collection types over MutationObserver-related types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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 | « Source/core/dom/MutationObserver.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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 134
135 if (!(options & (Attributes | CharacterData | ChildList))) { 135 if (!(options & (Attributes | CharacterData | ChildList))) {
136 exceptionState.throwTypeError("The options object must set at least one of 'attributes', 'characterData', or 'childList' to true."); 136 exceptionState.throwTypeError("The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.");
137 return; 137 return;
138 } 138 }
139 139
140 node->registerMutationObserver(*this, options, attributeFilter); 140 node->registerMutationObserver(*this, options, attributeFilter);
141 } 141 }
142 142
143 WillBeHeapVector<RefPtrWillBeMember<MutationRecord> > MutationObserver::takeReco rds() 143 MutationRecordVector MutationObserver::takeRecords()
144 { 144 {
145 WillBeHeapVector<RefPtrWillBeMember<MutationRecord> > records; 145 MutationRecordVector records;
146 records.swap(m_records); 146 records.swap(m_records);
147 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo ntext(), this); 147 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo ntext(), this);
148 return records; 148 return records;
149 } 149 }
150 150
151 void MutationObserver::disconnect() 151 void MutationObserver::disconnect()
152 { 152 {
153 m_records.clear(); 153 m_records.clear();
154 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo ntext(), this); 154 InspectorInstrumentation::didClearAllMutationRecords(m_callback->executionCo ntext(), this);
155 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > registr ations(m_registrations); 155 MutationObserverRegistrationSet registrations(m_registrations);
156 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::i terator iter = registrations.begin(); iter != registrations.end(); ++iter) 156 for (MutationObserverRegistrationSet::iterator iter = registrations.begin(); iter != registrations.end(); ++iter)
157 (*iter)->unregister(); 157 (*iter)->unregister();
158 ASSERT(m_registrations.isEmpty()); 158 ASSERT(m_registrations.isEmpty());
159 } 159 }
160 160
161 void MutationObserver::observationStarted(MutationObserverRegistration* registra tion) 161 void MutationObserver::observationStarted(MutationObserverRegistration* registra tion)
162 { 162 {
163 ASSERT(!m_registrations.contains(registration)); 163 ASSERT(!m_registrations.contains(registration));
164 m_registrations.add(registration); 164 m_registrations.add(registration);
165 } 165 }
166 166
167 void MutationObserver::observationEnded(MutationObserverRegistration* registrati on) 167 void MutationObserver::observationEnded(MutationObserverRegistration* registrati on)
168 { 168 {
169 ASSERT(m_registrations.contains(registration)); 169 ASSERT(m_registrations.contains(registration));
170 m_registrations.remove(registration); 170 m_registrations.remove(registration);
171 } 171 }
172 172
173 typedef WillBeHeapHashSet<RefPtrWillBeMember<MutationObserver> > MutationObserve rSet;
174
175 static MutationObserverSet& activeMutationObservers() 173 static MutationObserverSet& activeMutationObservers()
176 { 174 {
177 #if ENABLE(OILPAN) 175 #if ENABLE(OILPAN)
178 DEFINE_STATIC_LOCAL(Persistent<MutationObserverSet>, activeObservers, (new M utationObserverSet())); 176 DEFINE_STATIC_LOCAL(Persistent<MutationObserverSet>, activeObservers, (new M utationObserverSet()));
179 return *activeObservers; 177 return *activeObservers;
180 #else 178 #else
181 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, ()); 179 DEFINE_STATIC_LOCAL(MutationObserverSet, activeObservers, ());
182 return activeObservers; 180 return activeObservers;
183 #endif 181 #endif
184 } 182 }
(...skipping 27 matching lines...) Expand all
212 210
213 void MutationObserver::setHasTransientRegistration() 211 void MutationObserver::setHasTransientRegistration()
214 { 212 {
215 ASSERT(isMainThread()); 213 ASSERT(isMainThread());
216 activateObserver(this); 214 activateObserver(this);
217 } 215 }
218 216
219 HashSet<Node*> MutationObserver::getObservedNodes() const 217 HashSet<Node*> MutationObserver::getObservedNodes() const
220 { 218 {
221 HashSet<Node*> observedNodes; 219 HashSet<Node*> observedNodes;
222 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::c onst_iterator iter = m_registrations.begin(); iter != m_registrations.end(); ++i ter) 220 for (MutationObserverRegistrationSet::const_iterator iter = m_registrations. begin(); iter != m_registrations.end(); ++iter)
223 (*iter)->addRegistrationNodesToSet(observedNodes); 221 (*iter)->addRegistrationNodesToSet(observedNodes);
224 return observedNodes; 222 return observedNodes;
225 } 223 }
226 224
227 bool MutationObserver::canDeliver() 225 bool MutationObserver::canDeliver()
228 { 226 {
229 return !m_callback->executionContext()->activeDOMObjectsAreSuspended(); 227 return !m_callback->executionContext()->activeDOMObjectsAreSuspended();
230 } 228 }
231 229
232 void MutationObserver::deliver() 230 void MutationObserver::deliver()
233 { 231 {
234 ASSERT(canDeliver()); 232 ASSERT(canDeliver());
235 233
236 // Calling clearTransientRegistrations() can modify m_registrations, so it's necessary 234 // Calling clearTransientRegistrations() can modify m_registrations, so it's necessary
237 // to make a copy of the transient registrations before operating on them. 235 // to make a copy of the transient registrations before operating on them.
238 WillBeHeapVector<RawPtrWillBeMember<MutationObserverRegistration>, 1> transi entRegistrations; 236 WillBeHeapVector<RawPtrWillBeMember<MutationObserverRegistration>, 1> transi entRegistrations;
239 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::i terator iter = m_registrations.begin(); iter != m_registrations.end(); ++iter) { 237 for (MutationObserverRegistrationSet::iterator iter = m_registrations.begin( ); iter != m_registrations.end(); ++iter) {
240 if ((*iter)->hasTransientRegistrations()) 238 if ((*iter)->hasTransientRegistrations())
241 transientRegistrations.append(*iter); 239 transientRegistrations.append(*iter);
242 } 240 }
243 for (size_t i = 0; i < transientRegistrations.size(); ++i) 241 for (size_t i = 0; i < transientRegistrations.size(); ++i)
244 transientRegistrations[i]->clearTransientRegistrations(); 242 transientRegistrations[i]->clearTransientRegistrations();
245 243
246 if (m_records.isEmpty()) 244 if (m_records.isEmpty())
247 return; 245 return;
248 246
249 WillBeHeapVector<RefPtrWillBeMember<MutationRecord> > records; 247 MutationRecordVector records;
250 records.swap(m_records); 248 records.swap(m_records);
251 249
252 InspectorInstrumentation::willDeliverMutationRecords(m_callback->executionCo ntext(), this); 250 InspectorInstrumentation::willDeliverMutationRecords(m_callback->executionCo ntext(), this);
253 m_callback->call(records, this); 251 m_callback->call(records, this);
254 InspectorInstrumentation::didDeliverMutationRecords(m_callback->executionCon text()); 252 InspectorInstrumentation::didDeliverMutationRecords(m_callback->executionCon text());
255 } 253 }
256 254
257 void MutationObserver::resumeSuspendedObservers() 255 void MutationObserver::resumeSuspendedObservers()
258 { 256 {
259 ASSERT(isMainThread()); 257 ASSERT(isMainThread());
260 if (suspendedMutationObservers().isEmpty()) 258 if (suspendedMutationObservers().isEmpty())
261 return; 259 return;
262 260
263 WillBeHeapVector<RefPtrWillBeMember<MutationObserver> > suspended; 261 MutationObserverVector suspended;
264 copyToVector(suspendedMutationObservers(), suspended); 262 copyToVector(suspendedMutationObservers(), suspended);
265 for (size_t i = 0; i < suspended.size(); ++i) { 263 for (size_t i = 0; i < suspended.size(); ++i) {
266 if (suspended[i]->canDeliver()) { 264 if (suspended[i]->canDeliver()) {
267 suspendedMutationObservers().remove(suspended[i]); 265 suspendedMutationObservers().remove(suspended[i]);
268 activateObserver(suspended[i]); 266 activateObserver(suspended[i]);
269 } 267 }
270 } 268 }
271 } 269 }
272 270
273 void MutationObserver::deliverMutations() 271 void MutationObserver::deliverMutations()
274 { 272 {
275 ASSERT(isMainThread()); 273 ASSERT(isMainThread());
276 WillBeHeapVector<RefPtrWillBeMember<MutationObserver> > observers; 274 MutationObserverVector observers;
277 copyToVector(activeMutationObservers(), observers); 275 copyToVector(activeMutationObservers(), observers);
278 activeMutationObservers().clear(); 276 activeMutationObservers().clear();
279 std::sort(observers.begin(), observers.end(), ObserverLessThan()); 277 std::sort(observers.begin(), observers.end(), ObserverLessThan());
280 for (size_t i = 0; i < observers.size(); ++i) { 278 for (size_t i = 0; i < observers.size(); ++i) {
281 if (observers[i]->canDeliver()) 279 if (observers[i]->canDeliver())
282 observers[i]->deliver(); 280 observers[i]->deliver();
283 else 281 else
284 suspendedMutationObservers().add(observers[i]); 282 suspendedMutationObservers().add(observers[i]);
285 } 283 }
286 } 284 }
287 285
288 void MutationObserver::trace(Visitor* visitor) 286 void MutationObserver::trace(Visitor* visitor)
289 { 287 {
290 visitor->trace(m_records); 288 visitor->trace(m_records);
291 visitor->trace(m_registrations); 289 visitor->trace(m_registrations);
292 } 290 }
293 291
294 } // namespace WebCore 292 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/MutationObserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698