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

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp

Issue 2027513002: Add a stack of queues of elements with reaction queues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ce-element-queue
Patch Set: Rebase. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6d81441dce2701611a473290982a2ae093e51d48
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementReactionStack.cpp
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/custom/CustomElementReactionStack.h"
+
+#include "core/dom/Element.h"
+#include "core/dom/custom/CustomElementReactionQueue.h"
+
+namespace blink {
+
+// TODO(dominicc): Consider using linked heap structures, avoiding
+// finalizers, to make short-lived entries fast.
+
+CustomElementReactionStack::CustomElementReactionStack()
+{
+}
+
+CustomElementReactionStack::~CustomElementReactionStack()
+{
+}
+
+DEFINE_TRACE(CustomElementReactionStack)
+{
+ visitor->trace(m_map);
+ visitor->trace(m_stack);
+}
+
+void CustomElementReactionStack::push()
+{
+ m_stack.append(nullptr);
+}
+
+void CustomElementReactionStack::popInvokingReactions()
+{
+ ElementQueue* queue = m_stack.last();
+ m_stack.removeLast();
+ if (!queue)
+ return;
+ for (auto& element : *queue) {
+ if (CustomElementReactionQueue* reactions = m_map.get(element)) {
+ reactions->invokeReactions(element);
+ CHECK(reactions->isEmpty());
+ m_map.remove(element);
+ }
+ }
+}
+
+void CustomElementReactionStack::enqueue(
+ Element* element,
+ CustomElementReaction* reaction)
+{
+ ElementQueue* queue = m_stack.last();
+ if (!queue)
+ m_stack.last() = queue = new ElementQueue();
+ queue->append(element);
+
+ CustomElementReactionQueue* reactions = m_map.get(element);
+ if (!reactions) {
+ reactions = new CustomElementReactionQueue();
+ m_map.add(element, reactions);
+ }
+
+ reactions->add(reaction);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698