| 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 17 matching lines...) Expand all Loading... |
| 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 "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/CustomElementCallbackQueue.h" | 32 #include "core/dom/CustomElementCallbackQueue.h" |
| 33 | 33 |
| 34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 PassOwnPtr<CustomElementCallbackQueue> CustomElementCallbackQueue::create(PassRe
fPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element) | 38 PassOwnPtr<CustomElementCallbackQueue> CustomElementCallbackQueue::create(PassRe
fPtr<Element> element) |
| 39 { | 39 { |
| 40 return adoptPtr(new CustomElementCallbackQueue(callbacks, element)); | 40 return adoptPtr(new CustomElementCallbackQueue(element)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 CustomElementCallbackQueue::CustomElementCallbackQueue(PassRefPtr<CustomElementL
ifecycleCallbacks> callbacks, PassRefPtr<Element> element) | 43 CustomElementCallbackQueue::CustomElementCallbackQueue(PassRefPtr<Element> eleme
nt) |
| 44 : m_callbacks(callbacks) | 44 : m_element(element) |
| 45 , m_element(element) | |
| 46 , m_owner(-1) | 45 , m_owner(-1) |
| 47 , m_index(0) | 46 , m_index(0) |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void CustomElementCallbackQueue::processInElementQueue(ElementQueue caller) | 50 void CustomElementCallbackQueue::processInElementQueue(ElementQueue caller) |
| 52 { | 51 { |
| 53 for (; m_index < m_queue.size() && owner() == caller; m_index++) { | 52 while (m_index < m_queue.size() && owner() == caller) { |
| 54 // dispatch() may cause recursion which steals this callback | 53 // dispatch() may cause recursion which steals this callback |
| 55 // queue and reenters processInQueue. owner() == caller | 54 // queue and reenters processInQueue. owner() == caller |
| 56 // detects this recursion and cedes processing. | 55 // detects this recursion and cedes processing. |
| 57 m_queue[m_index]->dispatch(m_callbacks.get(), m_element.get()); | 56 m_queue[m_index++]->dispatch(m_element.get()); |
| 58 } | 57 } |
| 59 | 58 |
| 60 if (owner() == caller && m_index == m_queue.size()) { | 59 if (owner() == caller && m_index == m_queue.size()) { |
| 61 // This processInQueue exhausted the queue; shrink it. | 60 // This processInQueue exhausted the queue; shrink it. |
| 62 m_index = 0; | 61 m_index = 0; |
| 63 m_queue.resize(0); | 62 m_queue.resize(0); |
| 64 m_owner = -1; | 63 m_owner = -1; |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 | 66 |
| 68 } // namespace WebCore | 67 } // namespace WebCore |
| OLD | NEW |