| 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..3b288046f08b16aebd1ce76bceb43e52362b4511
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp
|
| @@ -0,0 +1,119 @@
|
| +/*
|
| + * Copyright (C) 2015 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#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.isEmpty() || name.isNull()) && !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
|
|
|