OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/custom/CustomElementReactionStack.h" |
| 6 |
| 7 #include "core/dom/Element.h" |
| 8 #include "core/dom/custom/CustomElementReactionQueue.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 // TODO(dominicc): Consider using linked heap structures, avoiding |
| 13 // finalizers, to make short-lived entries fast. |
| 14 |
| 15 CustomElementReactionStack::CustomElementReactionStack() |
| 16 { |
| 17 } |
| 18 |
| 19 CustomElementReactionStack::~CustomElementReactionStack() |
| 20 { |
| 21 } |
| 22 |
| 23 DEFINE_TRACE(CustomElementReactionStack) |
| 24 { |
| 25 visitor->trace(m_map); |
| 26 visitor->trace(m_stack); |
| 27 } |
| 28 |
| 29 void CustomElementReactionStack::push() |
| 30 { |
| 31 m_stack.append(nullptr); |
| 32 } |
| 33 |
| 34 void CustomElementReactionStack::popInvokingReactions() |
| 35 { |
| 36 ElementQueue* queue = m_stack.last(); |
| 37 m_stack.removeLast(); |
| 38 if (!queue) |
| 39 return; |
| 40 for (auto& element : *queue) { |
| 41 if (CustomElementReactionQueue* reactions = m_map.get(element)) { |
| 42 reactions->invokeReactions(element); |
| 43 CHECK(reactions->isEmpty()); |
| 44 m_map.remove(element); |
| 45 } |
| 46 } |
| 47 } |
| 48 |
| 49 void CustomElementReactionStack::enqueue( |
| 50 Element* element, |
| 51 CustomElementReaction* reaction) |
| 52 { |
| 53 ElementQueue* queue = m_stack.last(); |
| 54 if (!queue) |
| 55 m_stack.last() = queue = new ElementQueue(); |
| 56 queue->append(element); |
| 57 |
| 58 CustomElementReactionQueue* reactions = m_map.get(element); |
| 59 if (!reactions) { |
| 60 reactions = new CustomElementReactionQueue(); |
| 61 m_map.add(element, reactions); |
| 62 } |
| 63 |
| 64 reactions->add(reaction); |
| 65 } |
| 66 |
| 67 } // namespace blink |
OLD | NEW |