Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 { | 45 { |
| 46 DEFINE_STATIC_LOCAL(CustomElementCallbackDispatcher, instance, ()); | 46 DEFINE_STATIC_LOCAL(CustomElementCallbackDispatcher, instance, ()); |
| 47 return instance; | 47 return instance; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void CustomElementCallbackDispatcher::enqueueAttributeChangedCallback(PassRefPtr <CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) | 50 void CustomElementCallbackDispatcher::enqueueAttributeChangedCallback(PassRefPtr <CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 51 { | 51 { |
| 52 if (!callbacks->hasAttributeChanged()) | 52 if (!callbacks->hasAttributeChanged()) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 CustomElementCallbackQueue* queue = ensureCallbackQueue(callbacks, element); | 55 CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element); |
| 56 bool isInCurrentQueue = queue->owner() == currentElementQueue(); | 56 queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocat ion(callbacks, name, oldValue, newValue)); |
| 57 if (!isInCurrentQueue) { | |
| 58 queue->setOwner(currentElementQueue()); | |
| 59 m_flattenedProcessingStack.append(queue); | |
| 60 s_elementQueueEnd++; | |
| 61 } | |
| 62 | |
| 63 queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocat ion(name, oldValue, newValue)); | |
| 64 } | 57 } |
| 65 | 58 |
| 66 void CustomElementCallbackDispatcher::enqueueCreatedCallback(PassRefPtr<CustomEl ementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) | 59 void CustomElementCallbackDispatcher::enqueueCreatedCallback(PassRefPtr<CustomEl ementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) |
| 67 { | 60 { |
| 68 if (!callbacks->hasCreated()) | 61 if (!callbacks->hasCreated()) |
| 69 return; | 62 return; |
| 70 | 63 |
| 71 CustomElementCallbackQueue* queue = createCallbackQueue(callbacks, element); | 64 CustomElementCallbackQueue* queue = createCallbackQueue(element); |
| 72 queue->setOwner(currentElementQueue()); | 65 queue->setOwner(currentElementQueue()); |
| 73 | 66 |
| 74 // The created callback is unique in being prepended to the front | 67 // The created callback is unique in being prepended to the front |
| 75 // of the element queue | 68 // of the element queue |
| 76 m_flattenedProcessingStack.insert(inCallbackDeliveryScope() ? s_elementQueue Start : /* skip null sentinel */ 1, queue); | 69 m_flattenedProcessingStack.insert(inCallbackDeliveryScope() ? s_elementQueue Start : /* skip null sentinel */ 1, queue); |
| 77 s_elementQueueEnd++; | 70 s_elementQueueEnd++; |
| 78 | 71 |
| 79 queue->append(CustomElementCallbackInvocation::createCreatedInvocation()); | 72 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Created)); |
| 73 } | |
| 74 | |
| 75 void CustomElementCallbackDispatcher::enqueueEnteredDocumentCallback(PassRefPtr< CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) | |
| 76 { | |
| 77 if (!callbacks->hasEnteredDocument()) | |
| 78 return; | |
| 79 | |
| 80 CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element); | |
| 81 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::EnteredDocument)); | |
| 82 } | |
| 83 | |
| 84 void CustomElementCallbackDispatcher::enqueueLeftDocumentCallback(PassRefPtr<Cus tomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) | |
| 85 { | |
| 86 if (!callbacks->hasLeftDocument()) | |
| 87 return; | |
| 88 | |
| 89 CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element); | |
| 90 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::LeftDocument)); | |
| 80 } | 91 } |
| 81 | 92 |
| 82 // Dispatches callbacks at microtask checkpoint. | 93 // Dispatches callbacks at microtask checkpoint. |
| 83 bool CustomElementCallbackDispatcher::dispatch() | 94 bool CustomElementCallbackDispatcher::dispatch() |
| 84 { | 95 { |
| 85 ASSERT(isMainThread()); | 96 ASSERT(isMainThread()); |
| 86 if (inCallbackDeliveryScope()) | 97 if (inCallbackDeliveryScope()) |
| 87 return false; | 98 return false; |
| 88 | 99 |
| 89 size_t start = 1; // skip null sentinel | 100 size_t start = 1; // skip null sentinel |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 139 } |
| 129 | 140 |
| 130 // Pop the element queue from the processing stack | 141 // Pop the element queue from the processing stack |
| 131 m_flattenedProcessingStack.resize(start); | 142 m_flattenedProcessingStack.resize(start); |
| 132 s_elementQueueEnd = start; | 143 s_elementQueueEnd = start; |
| 133 | 144 |
| 134 if (start == /* allow sentinel */ 1) | 145 if (start == /* allow sentinel */ 1) |
| 135 m_elementCallbackQueueMap.clear(); | 146 m_elementCallbackQueueMap.clear(); |
| 136 } | 147 } |
| 137 | 148 |
| 138 CustomElementCallbackQueue* CustomElementCallbackDispatcher::createCallbackQueue (PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> elem ent) | 149 CustomElementCallbackQueue* CustomElementCallbackDispatcher::createCallbackQueue (PassRefPtr<Element> element) |
| 139 { | 150 { |
| 140 Element* key = element.get(); | 151 Element* key = element.get(); |
| 141 ElementCallbackQueueMap::AddResult result = m_elementCallbackQueueMap.add(ke y, CustomElementCallbackQueue::create(callbacks, element)); | 152 ElementCallbackQueueMap::AddResult result = m_elementCallbackQueueMap.add(ke y, CustomElementCallbackQueue::create(element)); |
| 142 ASSERT(result.isNewEntry); | 153 ASSERT(result.isNewEntry); |
| 143 return result.iterator->value.get(); | 154 return result.iterator->value.get(); |
| 144 } | 155 } |
| 145 | 156 |
| 146 CustomElementCallbackQueue* CustomElementCallbackDispatcher::ensureCallbackQueue (PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> elem ent) | 157 CustomElementCallbackQueue* CustomElementCallbackDispatcher::ensureCallbackQueue (PassRefPtr<Element> element) |
| 147 { | 158 { |
| 148 Element* key = element.get(); | 159 Element* key = element.get(); |
| 149 ElementCallbackQueueMap::iterator it = m_elementCallbackQueueMap.find(key); | 160 ElementCallbackQueueMap::iterator it = m_elementCallbackQueueMap.find(key); |
| 150 if (it == m_elementCallbackQueueMap.end()) | 161 if (it == m_elementCallbackQueueMap.end()) |
| 151 it = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::crea te(callbacks, element)).iterator; | 162 it = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::crea te(element)).iterator; |
| 152 return it->value.get(); | 163 return it->value.get(); |
| 153 } | 164 } |
| 154 | 165 |
| 166 CustomElementCallbackQueue* CustomElementCallbackDispatcher::scheduleInCurrentEl ementQueue(PassRefPtr<Element> element) | |
|
Yuta Kitamura
2013/07/08 03:40:49
I would appreciate if you can write some commentar
| |
| 167 { | |
| 168 CustomElementCallbackQueue* queue = ensureCallbackQueue(element); | |
| 169 bool isInCurrentQueue = queue->owner() == currentElementQueue(); | |
| 170 if (!isInCurrentQueue) { | |
| 171 queue->setOwner(currentElementQueue()); | |
| 172 m_flattenedProcessingStack.append(queue); | |
| 173 s_elementQueueEnd++; | |
|
Yuta Kitamura
2013/07/08 03:40:49
nit: Prefixed operator++ is better.
| |
| 174 } | |
| 175 return queue; | |
| 176 } | |
| 177 | |
| 155 } // namespace WebCore | 178 } // namespace WebCore |
| OLD | NEW |