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

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

Issue 27519002: Have Node::ensureRareData() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/html/LabelableElement.cpp » ('j') | 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 cache->remove(this); 320 cache->remove(this);
321 } 321 }
322 } 322 }
323 323
324 NodeRareData* Node::rareData() const 324 NodeRareData* Node::rareData() const
325 { 325 {
326 ASSERT_WITH_SECURITY_IMPLICATION(hasRareData()); 326 ASSERT_WITH_SECURITY_IMPLICATION(hasRareData());
327 return static_cast<NodeRareData*>(m_data.m_rareData); 327 return static_cast<NodeRareData*>(m_data.m_rareData);
328 } 328 }
329 329
330 NodeRareData* Node::ensureRareData() 330 NodeRareData& Node::ensureRareData()
331 { 331 {
332 if (hasRareData()) 332 if (hasRareData())
333 return rareData(); 333 return *rareData();
334 334
335 NodeRareData* data; 335 NodeRareData* data;
336 if (isElementNode()) 336 if (isElementNode())
337 data = ElementRareData::create(m_data.m_renderer).leakPtr(); 337 data = ElementRareData::create(m_data.m_renderer).leakPtr();
338 else 338 else
339 data = NodeRareData::create(m_data.m_renderer).leakPtr(); 339 data = NodeRareData::create(m_data.m_renderer).leakPtr();
340 ASSERT(data); 340 ASSERT(data);
341 341
342 m_data.m_rareData = data; 342 m_data.m_rareData = data;
343 setFlag(HasRareDataFlag); 343 setFlag(HasRareDataFlag);
344 return data; 344 return *data;
345 } 345 }
346 346
347 void Node::clearRareData() 347 void Node::clearRareData()
348 { 348 {
349 ASSERT(hasRareData()); 349 ASSERT(hasRareData());
350 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty()); 350 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty());
351 351
352 RenderObject* renderer = m_data.m_rareData->renderer(); 352 RenderObject* renderer = m_data.m_rareData->renderer();
353 if (isElementNode()) 353 if (isElementNode())
354 delete static_cast<ElementRareData*>(m_data.m_rareData); 354 delete static_cast<ElementRareData*>(m_data.m_rareData);
(...skipping 18 matching lines...) Expand all
373 return String(); 373 return String();
374 } 374 }
375 375
376 void Node::setNodeValue(const String&) 376 void Node::setNodeValue(const String&)
377 { 377 {
378 // By default, setting nodeValue has no effect. 378 // By default, setting nodeValue has no effect.
379 } 379 }
380 380
381 PassRefPtr<NodeList> Node::childNodes() 381 PassRefPtr<NodeList> Node::childNodes()
382 { 382 {
383 return ensureRareData()->ensureNodeLists()->ensureChildNodeList(this); 383 return ensureRareData().ensureNodeLists()->ensureChildNodeList(this);
384 } 384 }
385 385
386 Node *Node::lastDescendant() const 386 Node *Node::lastDescendant() const
387 { 387 {
388 Node *n = const_cast<Node *>(this); 388 Node *n = const_cast<Node *>(this);
389 while (n && n->lastChild()) 389 while (n && n->lastChild())
390 n = n->lastChild(); 390 n = n->lastChild();
391 return n; 391 return n;
392 } 392 }
393 393
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 } 1206 }
1207 1207
1208 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node. 1208 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node.
1209 1209
1210 PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName) 1210 PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName)
1211 { 1211 {
1212 if (localName.isNull()) 1212 if (localName.isNull())
1213 return 0; 1213 return 0;
1214 1214
1215 if (document().isHTMLDocument()) 1215 if (document().isHTMLDocument())
1216 return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<HTMLT agNodeList>(this, HTMLTagNodeListType, localName); 1216 return ensureRareData().ensureNodeLists()->addCacheWithAtomicName<HTMLTa gNodeList>(this, HTMLTagNodeListType, localName);
1217 return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<TagNodeLi st>(this, TagNodeListType, localName); 1217 return ensureRareData().ensureNodeLists()->addCacheWithAtomicName<TagNodeLis t>(this, TagNodeListType, localName);
1218 } 1218 }
1219 1219
1220 PassRefPtr<NodeList> Node::getElementsByTagNameNS(const AtomicString& namespaceU RI, const AtomicString& localName) 1220 PassRefPtr<NodeList> Node::getElementsByTagNameNS(const AtomicString& namespaceU RI, const AtomicString& localName)
1221 { 1221 {
1222 if (localName.isNull()) 1222 if (localName.isNull())
1223 return 0; 1223 return 0;
1224 1224
1225 if (namespaceURI == starAtom) 1225 if (namespaceURI == starAtom)
1226 return getElementsByTagName(localName); 1226 return getElementsByTagName(localName);
1227 1227
1228 return ensureRareData()->ensureNodeLists()->addCacheWithQualifiedName(this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localName); 1228 return ensureRareData().ensureNodeLists()->addCacheWithQualifiedName(this, n amespaceURI.isEmpty() ? nullAtom : namespaceURI, localName);
1229 } 1229 }
1230 1230
1231 PassRefPtr<NodeList> Node::getElementsByName(const String& elementName) 1231 PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
1232 { 1232 {
1233 return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<NameNodeL ist>(this, NameNodeListType, elementName); 1233 return ensureRareData().ensureNodeLists()->addCacheWithAtomicName<NameNodeLi st>(this, NameNodeListType, elementName);
1234 } 1234 }
1235 1235
1236 PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames) 1236 PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
1237 { 1237 {
1238 return ensureRareData()->ensureNodeLists()->addCacheWithName<ClassNodeList>( this, ClassNodeListType, classNames); 1238 return ensureRareData().ensureNodeLists()->addCacheWithName<ClassNodeList>(t his, ClassNodeListType, classNames);
1239 } 1239 }
1240 1240
1241 PassRefPtr<RadioNodeList> Node::radioNodeList(const AtomicString& name) 1241 PassRefPtr<RadioNodeList> Node::radioNodeList(const AtomicString& name)
1242 { 1242 {
1243 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); 1243 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
1244 return ensureRareData()->ensureNodeLists()->addCacheWithAtomicName<RadioNode List>(this, RadioNodeListType, name); 1244 return ensureRareData().ensureNodeLists()->addCacheWithAtomicName<RadioNodeL ist>(this, RadioNodeListType, name);
1245 } 1245 }
1246 1246
1247 PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, Exception State& es) 1247 PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, Exception State& es)
1248 { 1248 {
1249 if (selectors.isEmpty()) { 1249 if (selectors.isEmpty()) {
1250 es.throwDOMException(SyntaxError, ExceptionMessages::failedToExecute("qu erySelector", "Node", "The provided selector is empty.")); 1250 es.throwDOMException(SyntaxError, ExceptionMessages::failedToExecute("qu erySelector", "Node", "The provided selector is empty."));
1251 return 0; 1251 return 0;
1252 } 1252 }
1253 1253
1254 SelectorQuery* selectorQuery = document().selectorQueryCache()->add(selector s, document(), es); 1254 SelectorQuery* selectorQuery = document().selectorQueryCache()->add(selector s, document(), es);
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), this, type, attributeName); 2163 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), this, type, attributeName);
2164 for (Node* node = parentNode(); node; node = node->parentNode()) { 2164 for (Node* node = parentNode(); node; node = node->parentNode()) {
2165 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), this, type, attributeName); 2165 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), this, type, attributeName);
2166 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), this, type, attributeName); 2166 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), this, type, attributeName);
2167 } 2167 }
2168 } 2168 }
2169 2169
2170 void Node::registerMutationObserver(MutationObserver* observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) 2170 void Node::registerMutationObserver(MutationObserver* observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter)
2171 { 2171 {
2172 MutationObserverRegistration* registration = 0; 2172 MutationObserverRegistration* registration = 0;
2173 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData()-> ensureMutationObserverData()->registry; 2173 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData().e nsureMutationObserverData()->registry;
2174 for (size_t i = 0; i < registry.size(); ++i) { 2174 for (size_t i = 0; i < registry.size(); ++i) {
2175 if (registry[i]->observer() == observer) { 2175 if (registry[i]->observer() == observer) {
2176 registration = registry[i].get(); 2176 registration = registry[i].get();
2177 registration->resetObservation(options, attributeFilter); 2177 registration->resetObservation(options, attributeFilter);
2178 } 2178 }
2179 } 2179 }
2180 2180
2181 if (!registration) { 2181 if (!registration) {
2182 registry.append(MutationObserverRegistration::create(observer, this, opt ions, attributeFilter)); 2182 registry.append(MutationObserverRegistration::create(observer, this, opt ions, attributeFilter));
2183 registration = registry.last().get(); 2183 registration = registry.last().get();
(...skipping 16 matching lines...) Expand all
2200 2200
2201 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes 2201 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes
2202 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). 2202 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive).
2203 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. 2203 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans.
2204 RefPtr<Node> protect(this); 2204 RefPtr<Node> protect(this);
2205 registry->remove(index); 2205 registry->remove(index);
2206 } 2206 }
2207 2207
2208 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) 2208 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration)
2209 { 2209 {
2210 ensureRareData()->ensureMutationObserverData()->transientRegistry.add(regist ration); 2210 ensureRareData().ensureMutationObserverData()->transientRegistry.add(registr ation);
2211 } 2211 }
2212 2212
2213 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) 2213 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration)
2214 { 2214 {
2215 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio nObserverRegistry(); 2215 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio nObserverRegistry();
2216 ASSERT(transientRegistry); 2216 ASSERT(transientRegistry);
2217 if (!transientRegistry) 2217 if (!transientRegistry)
2218 return; 2218 return;
2219 2219
2220 ASSERT(transientRegistry->contains(registration)); 2220 ASSERT(transientRegistry->contains(registration));
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 } 2481 }
2482 2482
2483 unsigned Node::connectedSubframeCount() const 2483 unsigned Node::connectedSubframeCount() const
2484 { 2484 {
2485 return hasRareData() ? rareData()->connectedSubframeCount() : 0; 2485 return hasRareData() ? rareData()->connectedSubframeCount() : 0;
2486 } 2486 }
2487 2487
2488 void Node::incrementConnectedSubframeCount(unsigned amount) 2488 void Node::incrementConnectedSubframeCount(unsigned amount)
2489 { 2489 {
2490 ASSERT(isContainerNode()); 2490 ASSERT(isContainerNode());
2491 ensureRareData()->incrementConnectedSubframeCount(amount); 2491 ensureRareData().incrementConnectedSubframeCount(amount);
2492 } 2492 }
2493 2493
2494 void Node::decrementConnectedSubframeCount(unsigned amount) 2494 void Node::decrementConnectedSubframeCount(unsigned amount)
2495 { 2495 {
2496 rareData()->decrementConnectedSubframeCount(amount); 2496 rareData()->decrementConnectedSubframeCount(amount);
2497 } 2497 }
2498 2498
2499 void Node::updateAncestorConnectedSubframeCountForRemoval() const 2499 void Node::updateAncestorConnectedSubframeCountForRemoval() const
2500 { 2500 {
2501 unsigned count = connectedSubframeCount(); 2501 unsigned count = connectedSubframeCount();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 node->showTreeForThis(); 2634 node->showTreeForThis();
2635 } 2635 }
2636 2636
2637 void showNodePath(const WebCore::Node* node) 2637 void showNodePath(const WebCore::Node* node)
2638 { 2638 {
2639 if (node) 2639 if (node)
2640 node->showNodePathForThis(); 2640 node->showNodePathForThis();
2641 } 2641 }
2642 2642
2643 #endif 2643 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/html/LabelableElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698