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

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

Issue 178473026: Have MutationObserverRegistration deal with references instead of pointers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/MutationObserverRegistration.h ('k') | Source/core/dom/Node.h » ('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) 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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/dom/MutationObserverRegistration.h" 33 #include "core/dom/MutationObserverRegistration.h"
34 34
35 #include "core/dom/Node.h" 35 #include "core/dom/Node.h"
36 #include "core/dom/QualifiedName.h" 36 #include "core/dom/QualifiedName.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 PassOwnPtr<MutationObserverRegistration> MutationObserverRegistration::create(Pa ssRefPtr<MutationObserver> observer, Node* registrationNode, MutationObserverOpt ions options, const HashSet<AtomicString>& attributeFilter) 40 PassOwnPtr<MutationObserverRegistration> MutationObserverRegistration::create(Mu tationObserver& observer, Node& registrationNode, MutationObserverOptions option s, const HashSet<AtomicString>& attributeFilter)
41 { 41 {
42 return adoptPtr(new MutationObserverRegistration(observer, registrationNode, options, attributeFilter)); 42 return adoptPtr(new MutationObserverRegistration(observer, registrationNode, options, attributeFilter));
43 } 43 }
44 44
45 MutationObserverRegistration::MutationObserverRegistration(PassRefPtr<MutationOb server> observer, Node* registrationNode, MutationObserverOptions options, const HashSet<AtomicString>& attributeFilter) 45 MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs erver, Node& registrationNode, MutationObserverOptions options, const HashSet<At omicString>& attributeFilter)
46 : m_observer(observer) 46 : m_observer(observer)
47 , m_registrationNode(registrationNode) 47 , m_registrationNode(registrationNode)
48 , m_options(options) 48 , m_options(options)
49 , m_attributeFilter(attributeFilter) 49 , m_attributeFilter(attributeFilter)
50 { 50 {
51 m_observer->observationStarted(this); 51 m_observer->observationStarted(this);
52 } 52 }
53 53
54 MutationObserverRegistration::~MutationObserverRegistration() 54 MutationObserverRegistration::~MutationObserverRegistration()
55 { 55 {
56 clearTransientRegistrations(); 56 clearTransientRegistrations();
57 m_observer->observationEnded(this); 57 m_observer->observationEnded(this);
58 } 58 }
59 59
60 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter) 60 void MutationObserverRegistration::resetObservation(MutationObserverOptions opti ons, const HashSet<AtomicString>& attributeFilter)
61 { 61 {
62 clearTransientRegistrations(); 62 clearTransientRegistrations();
63 m_options = options; 63 m_options = options;
64 m_attributeFilter = attributeFilter; 64 m_attributeFilter = attributeFilter;
65 } 65 }
66 66
67 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node* node) 67 void MutationObserverRegistration::observedSubtreeNodeWillDetach(Node& node)
68 { 68 {
69 if (!isSubtree()) 69 if (!isSubtree())
70 return; 70 return;
71 71
72 node->registerTransientMutationObserver(this); 72 node.registerTransientMutationObserver(this);
73 m_observer->setHasTransientRegistration(); 73 m_observer->setHasTransientRegistration();
74 74
75 if (!m_transientRegistrationNodes) { 75 if (!m_transientRegistrationNodes) {
76 m_transientRegistrationNodes = adoptPtr(new NodeHashSet); 76 m_transientRegistrationNodes = adoptPtr(new NodeHashSet);
77 77
78 ASSERT(!m_registrationNodeKeepAlive); 78 ASSERT(!m_registrationNodeKeepAlive);
79 m_registrationNodeKeepAlive = m_registrationNode; // Balanced in clearTr ansientRegistrations. 79 m_registrationNodeKeepAlive = PassRefPtr<Node>(m_registrationNode); // B alanced in clearTransientRegistrations.
80 } 80 }
81 m_transientRegistrationNodes->add(node); 81 m_transientRegistrationNodes->add(&node);
82 } 82 }
83 83
84 void MutationObserverRegistration::clearTransientRegistrations() 84 void MutationObserverRegistration::clearTransientRegistrations()
85 { 85 {
86 if (!m_transientRegistrationNodes) { 86 if (!m_transientRegistrationNodes) {
87 ASSERT(!m_registrationNodeKeepAlive); 87 ASSERT(!m_registrationNodeKeepAlive);
88 return; 88 return;
89 } 89 }
90 90
91 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter) 91 for (NodeHashSet::iterator iter = m_transientRegistrationNodes->begin(); ite r != m_transientRegistrationNodes->end(); ++iter)
92 (*iter)->unregisterTransientMutationObserver(this); 92 (*iter)->unregisterTransientMutationObserver(this);
93 93
94 m_transientRegistrationNodes.clear(); 94 m_transientRegistrationNodes.clear();
95 95
96 ASSERT(m_registrationNodeKeepAlive); 96 ASSERT(m_registrationNodeKeepAlive);
97 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach. 97 m_registrationNodeKeepAlive = nullptr; // Balanced in observeSubtreeNodeWill Detach.
98 } 98 }
99 99
100 void MutationObserverRegistration::unregister() 100 void MutationObserverRegistration::unregister()
101 { 101 {
102 m_registrationNode->unregisterMutationObserver(this); 102 m_registrationNode.unregisterMutationObserver(this);
103 // The above line will cause this object to be deleted, so don't do any more in this function. 103 // The above line will cause this object to be deleted, so don't do any more in this function.
104 } 104 }
105 105
106 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node* node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const 106 bool MutationObserverRegistration::shouldReceiveMutationFrom(Node& node, Mutatio nObserver::MutationType type, const QualifiedName* attributeName) const
107 { 107 {
108 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 108 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
109 if (!(m_options & type)) 109 if (!(m_options & type))
110 return false; 110 return false;
111 111
112 if (m_registrationNode != node && !isSubtree()) 112 if (m_registrationNode != node && !isSubtree())
113 return false; 113 return false;
114 114
115 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter)) 115 if (type != MutationObserver::Attributes || !(m_options & MutationObserver:: AttributeFilter))
116 return true; 116 return true;
117 117
118 if (!attributeName->namespaceURI().isNull()) 118 if (!attributeName->namespaceURI().isNull())
119 return false; 119 return false;
120 120
121 return m_attributeFilter.contains(attributeName->localName()); 121 return m_attributeFilter.contains(attributeName->localName());
122 } 122 }
123 123
124 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const 124 void MutationObserverRegistration::addRegistrationNodesToSet(HashSet<Node*>& nod es) const
125 { 125 {
126 nodes.add(m_registrationNode); 126 nodes.add(&m_registrationNode);
127 if (!m_transientRegistrationNodes) 127 if (!m_transientRegistrationNodes)
128 return; 128 return;
129 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter) 129 for (NodeHashSet::const_iterator iter = m_transientRegistrationNodes->begin( ); iter != m_transientRegistrationNodes->end(); ++iter)
130 nodes.add(iter->get()); 130 nodes.add(iter->get());
131 } 131 }
132 132
133 } // namespace WebCore 133 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/MutationObserverRegistration.h ('k') | Source/core/dom/Node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698