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

Side by Side 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: wip 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #include "core/dom/shadow/SlotAssignment.h"
34
35 #include "core/HTMLNames.h"
36 #include "core/dom/ElementTraversal.h"
37 #include "core/dom/NodeTraversal.h"
38 #include "core/dom/shadow/InsertionPoint.h"
39 #include "core/dom/shadow/ShadowRoot.h"
40 #include "core/html/HTMLSlotElement.h"
41
42 namespace blink {
43
44 HTMLSlotElement* SlotAssignment::assignedSlotFor(const Node& node) const
45 {
46 return m_assignment.get(const_cast<Node*>(&node));
47 }
48
49 static void detachNotAssignedNode(Node& node)
50 {
51 if (node.layoutObject())
52 node.lazyReattachIfAttached();
53 }
54
55 void SlotAssignment::resolveAssignment(const ShadowRoot& shadowRoot)
56 {
57 m_assignment.clear();
58
59 using Name2Slot = HashMap<AtomicString, HTMLSlotElement*>;
60 Name2Slot name2slot;
61 HTMLSlotElement* defaultSlot = nullptr;
62
63 // TODO(hayato): Cache slots elements so that we do not have to travese the shadow tree. See ShadowRoot::descendantInsertionPoints()
64 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(shado wRoot)) {
65 slot.clearDistribution();
66
67 AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr);
68 if ((name.isEmpty() || name.isNull()) && !defaultSlot) {
kochi 2015/12/09 08:57:34 no {} for this if-else as each clause is one-liner
hayato 2015/12/09 10:25:40 Done. BTW, it's permitted according to blink style
69 defaultSlot = &slot;
70 } else {
71 name2slot.add(name, &slot);
72 }
73 }
74
75 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) {
76 if (child.isElementNode()) {
77 if (isActiveInsertionPoint(child)) {
78 // TODO(hayato): Support re-distribution across v0 and v1 shadow trees
79 detachNotAssignedNode(child);
80 continue;
81 }
82 AtomicString slotName = toElement(child).fastGetAttribute(HTMLNames: :slotAttr);
83 if (slotName.isNull() || slotName.isEmpty()) {
84 if (defaultSlot) {
kochi 2015/12/09 08:57:34 No {} for this if-else.
hayato 2015/12/09 10:25:40 Done.
85 assign(child, *defaultSlot);
86 } else {
87 detachNotAssignedNode(child);
88 }
89 } else {
90 HTMLSlotElement* slot = name2slot.get(slotName);
91 if (slot) {
kochi 2015/12/09 08:57:34 No {} for this if-else.
hayato 2015/12/09 10:25:40 Done.
92 assign(child, *slot);
93 } else {
94 detachNotAssignedNode(child);
95 }
96 }
97 } else if (defaultSlot) {
98 assign(child, *defaultSlot);
99 } else {
100 detachNotAssignedNode(child);
101 }
102 }
103 }
104
105 void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot)
106 {
107 m_assignment.add(&hostChild, &slot);
108 slot.appendAssignedNode(hostChild);
109 if (isHTMLSlotElement(hostChild)) {
kochi 2015/12/09 08:57:34 No {} for this if-else.
hayato 2015/12/09 10:25:40 Done.
110 slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedN odes());
111 } else {
112 slot.appendDistributedNode(hostChild);
113 }
114 }
115
116 DEFINE_TRACE(SlotAssignment)
117 {
118 #if ENABLE(OILPAN)
119 visitor->trace(m_assignment);
120 #endif
121 }
122
123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698