| 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 30 matching lines...) Expand all Loading... |
| 41 #include "core/dom/custom/CustomElementMicrotaskResolutionStep.h" | 41 #include "core/dom/custom/CustomElementMicrotaskResolutionStep.h" |
| 42 #include "core/dom/custom/CustomElementRegistrationContext.h" | 42 #include "core/dom/custom/CustomElementRegistrationContext.h" |
| 43 #include "core/html/imports/HTMLImportChild.h" | 43 #include "core/html/imports/HTMLImportChild.h" |
| 44 | 44 |
| 45 namespace WebCore { | 45 namespace WebCore { |
| 46 | 46 |
| 47 class HTMLImport; | 47 class HTMLImport; |
| 48 | 48 |
| 49 void CustomElementScheduler::scheduleCreatedCallback(PassRefPtr<CustomElementLif
ecycleCallbacks> callbacks, PassRefPtr<Element> element) | 49 void CustomElementScheduler::scheduleCreatedCallback(PassRefPtr<CustomElementLif
ecycleCallbacks> callbacks, PassRefPtr<Element> element) |
| 50 { | 50 { |
| 51 CustomElementCallbackQueue* queue = instance().schedule(element); | 51 CustomElementCallbackQueue& queue = instance().schedule(element); |
| 52 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C
ustomElementLifecycleCallbacks::Created)); | 52 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, Cu
stomElementLifecycleCallbacks::Created)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE
lementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicSt
ring& name, const AtomicString& oldValue, const AtomicString& newValue) | 55 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE
lementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicSt
ring& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 56 { | 56 { |
| 57 if (!callbacks->hasAttributeChangedCallback()) | 57 if (!callbacks->hasAttributeChangedCallback()) |
| 58 return; | 58 return; |
| 59 | 59 |
| 60 CustomElementCallbackQueue* queue = instance().schedule(element); | 60 CustomElementCallbackQueue& queue = instance().schedule(element); |
| 61 queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocat
ion(callbacks, name, oldValue, newValue)); | 61 queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocati
on(callbacks, name, oldValue, newValue)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi
fecycleCallbacks> callbacks, PassRefPtr<Element> element) | 64 void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi
fecycleCallbacks> callbacks, PassRefPtr<Element> element) |
| 65 { | 65 { |
| 66 if (!callbacks->hasAttachedCallback()) | 66 if (!callbacks->hasAttachedCallback()) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 CustomElementCallbackQueue* queue = instance().schedule(element); | 69 CustomElementCallbackQueue& queue = instance().schedule(element); |
| 70 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C
ustomElementLifecycleCallbacks::Attached)); | 70 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, Cu
stomElementLifecycleCallbacks::Attached)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi
fecycleCallbacks> callbacks, PassRefPtr<Element> element) | 73 void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi
fecycleCallbacks> callbacks, PassRefPtr<Element> element) |
| 74 { | 74 { |
| 75 if (!callbacks->hasDetachedCallback()) | 75 if (!callbacks->hasDetachedCallback()) |
| 76 return; | 76 return; |
| 77 | 77 |
| 78 CustomElementCallbackQueue* queue = instance().schedule(element); | 78 CustomElementCallbackQueue& queue = instance().schedule(element); |
| 79 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C
ustomElementLifecycleCallbacks::Detached)); | 79 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, Cu
stomElementLifecycleCallbacks::Detached)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElemen
tRegistrationContext> context, PassRefPtr<Element> element, const CustomElementD
escriptor& descriptor) | 82 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElemen
tRegistrationContext> context, PassRefPtr<Element> element, const CustomElementD
escriptor& descriptor) |
| 83 { | 83 { |
| 84 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { | 84 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { |
| 85 context->resolve(element.get(), descriptor); | 85 context->resolve(element.get(), descriptor); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 HTMLImport* import = element->document().import(); | 89 HTMLImport* import = element->document().import(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 | 105 |
| 106 return rawStep; | 106 return rawStep; |
| 107 } | 107 } |
| 108 | 108 |
| 109 CustomElementScheduler& CustomElementScheduler::instance() | 109 CustomElementScheduler& CustomElementScheduler::instance() |
| 110 { | 110 { |
| 111 DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ()); | 111 DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ()); |
| 112 return instance; | 112 return instance; |
| 113 } | 113 } |
| 114 | 114 |
| 115 CustomElementCallbackQueue* CustomElementScheduler::ensureCallbackQueue(PassRefP
tr<Element> element) | 115 CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefP
tr<Element> element) |
| 116 { | 116 { |
| 117 Element* key = element.get(); | 117 ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(eleme
nt.get(), nullptr).storedValue; |
| 118 ElementCallbackQueueMap::iterator it = m_elementCallbackQueueMap.find(key); | 118 if (!it->value) |
| 119 if (it == m_elementCallbackQueueMap.end()) | 119 it->value = CustomElementCallbackQueue::create(element); |
| 120 return m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::cr
eate(element)).storedValue->value.get(); | 120 return *it->value.get(); |
| 121 return it->value.get(); | |
| 122 } | 121 } |
| 123 | 122 |
| 124 void CustomElementScheduler::callbackDispatcherDidFinish() | 123 void CustomElementScheduler::callbackDispatcherDidFinish() |
| 125 { | 124 { |
| 126 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty()) | 125 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty()) |
| 127 instance().clearElementCallbackQueueMap(); | 126 instance().clearElementCallbackQueueMap(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void CustomElementScheduler::microtaskDispatcherDidFinish() | 129 void CustomElementScheduler::microtaskDispatcherDidFinish() |
| 131 { | 130 { |
| 132 ASSERT(!CustomElementCallbackDispatcher::inCallbackDeliveryScope()); | 131 ASSERT(!CustomElementCallbackDispatcher::inCallbackDeliveryScope()); |
| 133 instance().clearElementCallbackQueueMap(); | 132 instance().clearElementCallbackQueueMap(); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void CustomElementScheduler::clearElementCallbackQueueMap() | 135 void CustomElementScheduler::clearElementCallbackQueueMap() |
| 137 { | 136 { |
| 138 ElementCallbackQueueMap emptyMap; | 137 ElementCallbackQueueMap emptyMap; |
| 139 m_elementCallbackQueueMap.swap(emptyMap); | 138 m_elementCallbackQueueMap.swap(emptyMap); |
| 140 } | 139 } |
| 141 | 140 |
| 142 // Finds or creates the callback queue for element. | 141 // Finds or creates the callback queue for element. |
| 143 CustomElementCallbackQueue* CustomElementScheduler::schedule(PassRefPtr<Element>
passElement) | 142 CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtr<Element>
passElement) |
| 144 { | 143 { |
| 145 RefPtr<Element> element(passElement); | 144 RefPtr<Element> element(passElement); |
| 146 | 145 |
| 147 CustomElementCallbackQueue* callbackQueue = ensureCallbackQueue(element); | 146 CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element); |
| 148 if (callbackQueue->inCreatedCallback()) { | 147 if (callbackQueue.inCreatedCallback()) { |
| 149 // Don't move it. Authors use the createdCallback like a | 148 // Don't move it. Authors use the createdCallback like a |
| 150 // constructor. By not moving it, the createdCallback | 149 // constructor. By not moving it, the createdCallback |
| 151 // completes before any other callbacks are entered for this | 150 // completes before any other callbacks are entered for this |
| 152 // element. | 151 // element. |
| 153 return callbackQueue; | 152 return callbackQueue; |
| 154 } | 153 } |
| 155 | 154 |
| 156 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { | 155 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { |
| 157 // The processing stack is active. | 156 // The processing stack is active. |
| 158 CustomElementCallbackDispatcher::instance().enqueue(callbackQueue); | 157 CustomElementCallbackDispatcher::instance().enqueue(&callbackQueue); |
| 159 return callbackQueue; | 158 return callbackQueue; |
| 160 } | 159 } |
| 161 | 160 |
| 162 CustomElementMicrotaskDispatcher::instance().enqueue(callbackQueue); | 161 CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue); |
| 163 return callbackQueue; | 162 return callbackQueue; |
| 164 } | 163 } |
| 165 | 164 |
| 166 } // namespace WebCore | 165 } // namespace WebCore |
| OLD | NEW |