Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 return m_distributedNodes; | 76 return m_distributedNodes; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void HTMLSlotElement::appendAssignedNode(Node& node) | 79 void HTMLSlotElement::appendAssignedNode(Node& node) |
| 80 { | 80 { |
| 81 m_assignedNodes.append(&node); | 81 m_assignedNodes.append(&node); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void HTMLSlotElement::appendDistributedNode(Node& node) | 84 void HTMLSlotElement::appendDistributedNode(Node& node) |
| 85 { | 85 { |
| 86 size_t size = m_distributedNodes.size(); | |
| 86 m_distributedNodes.append(&node); | 87 m_distributedNodes.append(&node); |
| 88 m_distributedIndices.set(&node, size); | |
| 87 } | 89 } |
| 88 | 90 |
| 89 void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other) | 91 void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other) |
| 90 { | 92 { |
| 93 size_t index = m_distributedNodes.size(); | |
| 91 m_distributedNodes.appendVector(other.m_distributedNodes); | 94 m_distributedNodes.appendVector(other.m_distributedNodes); |
| 95 for (const auto& it : other.m_distributedIndices) { | |
| 96 const Node* node = it.key; | |
| 97 m_distributedIndices.set(node, index++); | |
| 98 } | |
| 92 } | 99 } |
| 93 | 100 |
| 94 void HTMLSlotElement::clearDistribution() | 101 void HTMLSlotElement::clearDistribution() |
| 95 { | 102 { |
| 96 m_assignedNodes.clear(); | 103 m_assignedNodes.clear(); |
| 97 m_distributedNodes.clear(); | 104 m_distributedNodes.clear(); |
| 105 m_distributedIndices.clear(); | |
| 98 } | 106 } |
| 99 | 107 |
| 100 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const | 108 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const |
| 101 { | 109 { |
| 102 size_t index = m_distributedNodes.find(&node); | 110 const auto& it = m_distributedIndices.find(&node); |
|
kochi
2016/02/01 06:12:15
Yeah, 'const auto&' is better than 'const auto'.
| |
| 103 if (index == kNotFound || index + 1 == m_distributedNodes.size()) | 111 if (it == m_distributedIndices.end()) |
| 112 return nullptr; | |
| 113 size_t index = it->value; | |
| 114 if (index + 1 == m_distributedNodes.size()) | |
| 104 return nullptr; | 115 return nullptr; |
| 105 return m_distributedNodes[index + 1].get(); | 116 return m_distributedNodes[index + 1].get(); |
| 106 } | 117 } |
| 107 | 118 |
| 108 Node* HTMLSlotElement::distributedNodePreviousTo(const Node& node) const | 119 Node* HTMLSlotElement::distributedNodePreviousTo(const Node& node) const |
| 109 { | 120 { |
| 110 size_t index = m_distributedNodes.find(&node); | 121 const auto& it = m_distributedIndices.find(&node); |
| 111 if (index == kNotFound || index == 0) | 122 if (it == m_distributedIndices.end()) |
| 123 return nullptr; | |
| 124 size_t index = it->value; | |
| 125 if (index == 0) | |
| 112 return nullptr; | 126 return nullptr; |
| 113 return m_distributedNodes[index - 1].get(); | 127 return m_distributedNodes[index - 1].get(); |
| 114 } | 128 } |
| 115 | 129 |
| 116 void HTMLSlotElement::attach(const AttachContext& context) | 130 void HTMLSlotElement::attach(const AttachContext& context) |
| 117 { | 131 { |
| 118 for (auto& node : m_distributedNodes) { | 132 for (auto& node : m_distributedNodes) { |
| 119 if (node->needsAttach()) | 133 if (node->needsAttach()) |
| 120 node->attach(context); | 134 node->attach(context); |
| 121 } | 135 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 continue; | 209 continue; |
| 196 if (isHTMLSlotElement(child)) | 210 if (isHTMLSlotElement(child)) |
| 197 appendDistributedNodesFrom(toHTMLSlotElement(child)); | 211 appendDistributedNodesFrom(toHTMLSlotElement(child)); |
| 198 else | 212 else |
| 199 appendDistributedNode(child); | 213 appendDistributedNode(child); |
| 200 } | 214 } |
| 201 } | 215 } |
| 202 | 216 |
| 203 DEFINE_TRACE(HTMLSlotElement) | 217 DEFINE_TRACE(HTMLSlotElement) |
| 204 { | 218 { |
| 219 #if ENABLE(OILPAN) | |
| 205 visitor->trace(m_assignedNodes); | 220 visitor->trace(m_assignedNodes); |
| 206 visitor->trace(m_distributedNodes); | 221 visitor->trace(m_distributedNodes); |
| 222 visitor->trace(m_distributedIndices); | |
| 223 #endif | |
| 207 HTMLElement::trace(visitor); | 224 HTMLElement::trace(visitor); |
| 208 } | 225 } |
| 209 | 226 |
| 210 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |