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

Unified Diff: third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp

Issue 1489433002: Support the essential part of Shadow DOM v1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert Internals.* Created 5 years 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/shadow/SlotAssignment.cpp
diff --git a/third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp b/third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6c791be04e33e81dadf9e2aef9daf3cd07409966
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp
@@ -0,0 +1,94 @@
+// Copyright 2015 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 "config.h"
+#include "core/dom/shadow/SlotAssignment.h"
+
+#include "core/HTMLNames.h"
+#include "core/dom/ElementTraversal.h"
+#include "core/dom/NodeTraversal.h"
+#include "core/dom/shadow/InsertionPoint.h"
+#include "core/dom/shadow/ShadowRoot.h"
+#include "core/html/HTMLSlotElement.h"
+
+namespace blink {
+
+HTMLSlotElement* SlotAssignment::assignedSlotFor(const Node& node) const
+{
+ return m_assignment.get(const_cast<Node*>(&node));
+}
+
+static void detachNotAssignedNode(Node& node)
+{
+ if (node.layoutObject())
+ node.lazyReattachIfAttached();
+}
+
+void SlotAssignment::resolveAssignment(const ShadowRoot& shadowRoot)
+{
+ m_assignment.clear();
+
+ using Name2Slot = HashMap<AtomicString, HTMLSlotElement*>;
+ Name2Slot name2slot;
+ HTMLSlotElement* defaultSlot = nullptr;
+
+ // TODO(hayato): Cache slots elements so that we do not have to travese the shadow tree. See ShadowRoot::descendantInsertionPoints()
+ for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(shadowRoot)) {
+ slot.clearDistribution();
+
+ AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr);
+ if (name.isNull() || name.isEmpty()) {
+ if (!defaultSlot)
+ defaultSlot = &slot;
+ } else {
+ name2slot.add(name, &slot);
+ }
+ }
+
+ for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) {
+ if (child.isElementNode()) {
+ if (isActiveInsertionPoint(child)) {
+ // TODO(hayato): Support re-distribution across v0 and v1 shadow trees
+ detachNotAssignedNode(child);
+ continue;
+ }
+ AtomicString slotName = toElement(child).fastGetAttribute(HTMLNames::slotAttr);
+ if (slotName.isNull() || slotName.isEmpty()) {
+ if (defaultSlot)
+ assign(child, *defaultSlot);
+ else
+ detachNotAssignedNode(child);
+ } else {
+ HTMLSlotElement* slot = name2slot.get(slotName);
+ if (slot)
+ assign(child, *slot);
+ else
+ detachNotAssignedNode(child);
+ }
+ } else if (defaultSlot) {
+ assign(child, *defaultSlot);
+ } else {
+ detachNotAssignedNode(child);
+ }
+ }
+}
+
+void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot)
+{
+ m_assignment.add(&hostChild, &slot);
+ slot.appendAssignedNode(hostChild);
+ if (isHTMLSlotElement(hostChild))
+ slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedNodes());
+ else
+ slot.appendDistributedNode(hostChild);
+}
+
+DEFINE_TRACE(SlotAssignment)
+{
+#if ENABLE(OILPAN)
+ visitor->trace(m_assignment);
+#endif
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/shadow/SlotAssignment.h ('k') | third_party/WebKit/Source/core/editing/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698