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

Side by Side Diff: sky/engine/core/dom/MutationObserver.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « sky/engine/core/dom/MutationObserver.h ('k') | sky/engine/core/dom/MutationObserver.idl » ('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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/core/dom/MutationObserver.h" 32 #include "sky/engine/core/dom/MutationObserver.h"
33 33
34 #include <algorithm> 34 #include <algorithm>
35 #include "base/bind.h" 35 #include "base/bind.h"
36 #include "sky/engine/bindings/core/v8/Dictionary.h" 36 #include "sky/engine/bindings2/exception_state.h"
37 #include "sky/engine/bindings/core/v8/ExceptionState.h"
38 #include "sky/engine/core/dom/ExceptionCode.h" 37 #include "sky/engine/core/dom/ExceptionCode.h"
39 #include "sky/engine/core/dom/ExecutionContext.h" 38 #include "sky/engine/core/dom/ExecutionContext.h"
40 #include "sky/engine/core/dom/Microtask.h" 39 #include "sky/engine/core/dom/Microtask.h"
41 #include "sky/engine/core/dom/MutationCallback.h" 40 #include "sky/engine/core/dom/MutationCallback.h"
42 #include "sky/engine/core/dom/MutationObserverRegistration.h" 41 #include "sky/engine/core/dom/MutationObserverRegistration.h"
43 #include "sky/engine/core/dom/MutationRecord.h" 42 #include "sky/engine/core/dom/MutationRecord.h"
44 #include "sky/engine/core/dom/Node.h" 43 #include "sky/engine/core/dom/Node.h"
45 #include "sky/engine/wtf/MainThread.h" 44 #include "sky/engine/wtf/MainThread.h"
46 45
47 namespace blink { 46 namespace blink {
(...skipping 19 matching lines...) Expand all
67 { 66 {
68 } 67 }
69 68
70 MutationObserver::~MutationObserver() 69 MutationObserver::~MutationObserver()
71 { 70 {
72 #if !ENABLE(OILPAN) 71 #if !ENABLE(OILPAN)
73 ASSERT(m_registrations.isEmpty()); 72 ASSERT(m_registrations.isEmpty());
74 #endif 73 #endif
75 } 74 }
76 75
77 void MutationObserver::observe(Node* node, const Dictionary& optionsDictionary, ExceptionState& exceptionState) 76 void MutationObserver::observe(Node* node, ExceptionState& exceptionState)
78 { 77 {
79 if (!node) { 78 if (!node) {
80 exceptionState.throwDOMException(NotFoundError, "The provided node was n ull."); 79 exceptionState.ThrowDOMException(NotFoundError, "The provided node was n ull.");
81 return; 80 return;
82 } 81 }
83 82
83 // FIXME(Dictionary): Provide way to specify these.
84 MutationObserverOptions options = 0; 84 MutationObserverOptions options = 0;
85
86 bool attributeOldValue = false;
87 bool attributeOldValuePresent = DictionaryHelper::get(optionsDictionary, "at tributeOldValue", attributeOldValue);
88 if (attributeOldValue)
89 options |= AttributeOldValue;
90
91 HashSet<AtomicString> attributeFilter; 85 HashSet<AtomicString> attributeFilter;
92 bool attributeFilterPresent = DictionaryHelper::get(optionsDictionary, "attr ibuteFilter", attributeFilter);
93 if (attributeFilterPresent)
94 options |= AttributeFilter;
95
96 bool attributes = false;
97 bool attributesPresent = DictionaryHelper::get(optionsDictionary, "attribute s", attributes);
98 if (attributes || (!attributesPresent && (attributeOldValuePresent || attrib uteFilterPresent)))
99 options |= Attributes;
100
101 bool characterDataOldValue = false;
102 bool characterDataOldValuePresent = DictionaryHelper::get(optionsDictionary, "characterDataOldValue", characterDataOldValue);
103 if (characterDataOldValue)
104 options |= CharacterDataOldValue;
105
106 bool characterData = false;
107 bool characterDataPresent = DictionaryHelper::get(optionsDictionary, "charac terData", characterData);
108 if (characterData || (!characterDataPresent && characterDataOldValuePresent) )
109 options |= CharacterData;
110
111 bool childListValue = false;
112 if (DictionaryHelper::get(optionsDictionary, "childList", childListValue) && childListValue)
113 options |= ChildList;
114
115 bool subtreeValue = false;
116 if (DictionaryHelper::get(optionsDictionary, "subtree", subtreeValue) && sub treeValue)
117 options |= Subtree;
118
119 if (!(options & Attributes)) {
120 if (options & AttributeOldValue) {
121 exceptionState.throwTypeError("The options object may only set 'attr ibuteOldValue' to true when 'attributes' is true or not present.");
122 return;
123 }
124 if (options & AttributeFilter) {
125 exceptionState.throwTypeError("The options object may only set 'attr ibuteFilter' when 'attributes' is true or not present.");
126 return;
127 }
128 }
129 if (!((options & CharacterData) || !(options & CharacterDataOldValue))) {
130 exceptionState.throwTypeError("The options object may only set 'characte rDataOldValue' to true when 'characterData' is true or not present.");
131 return;
132 }
133
134 if (!(options & (Attributes | CharacterData | ChildList))) {
135 exceptionState.throwTypeError("The options object must set at least one of 'attributes', 'characterData', or 'childList' to true.");
136 return;
137 }
138
139 node->registerMutationObserver(*this, options, attributeFilter); 86 node->registerMutationObserver(*this, options, attributeFilter);
140 } 87 }
141 88
142 MutationRecordVector MutationObserver::takeRecords() 89 MutationRecordVector MutationObserver::takeRecords()
143 { 90 {
144 MutationRecordVector records; 91 MutationRecordVector records;
145 records.swap(m_records); 92 records.swap(m_records);
146 return records; 93 return records;
147 } 94 }
148 95
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 std::sort(observers.begin(), observers.end(), ObserverLessThan()); 208 std::sort(observers.begin(), observers.end(), ObserverLessThan());
262 for (size_t i = 0; i < observers.size(); ++i) { 209 for (size_t i = 0; i < observers.size(); ++i) {
263 if (observers[i]->canDeliver()) 210 if (observers[i]->canDeliver())
264 observers[i]->deliver(); 211 observers[i]->deliver();
265 else 212 else
266 suspendedMutationObservers().add(observers[i]); 213 suspendedMutationObservers().add(observers[i]);
267 } 214 }
268 } 215 }
269 216
270 } // namespace blink 217 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/dom/MutationObserver.h ('k') | sky/engine/core/dom/MutationObserver.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698