| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other) | 132 void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other) |
| 133 { | 133 { |
| 134 size_t index = m_distributedNodes.size(); | 134 size_t index = m_distributedNodes.size(); |
| 135 m_distributedNodes.appendVector(other.m_distributedNodes); | 135 m_distributedNodes.appendVector(other.m_distributedNodes); |
| 136 for (const auto& node : other.m_distributedNodes) | 136 for (const auto& node : other.m_distributedNodes) |
| 137 m_distributedIndices.set(node.get(), index++); | 137 m_distributedIndices.set(node.get(), index++); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void HTMLSlotElement::clearDistribution() | 140 void HTMLSlotElement::clearDistribution() |
| 141 { | 141 { |
| 142 // TODO(hayato): Figure out when to call lazyReattachDistributedNodesIfNeede
d() |
| 142 m_assignedNodes.clear(); | 143 m_assignedNodes.clear(); |
| 143 m_distributedNodes.clear(); | 144 m_distributedNodes.clear(); |
| 144 m_distributedIndices.clear(); | 145 m_distributedIndices.clear(); |
| 145 } | 146 } |
| 146 | 147 |
| 148 void HTMLSlotElement::saveAndClearDistribution() |
| 149 { |
| 150 m_oldDistributedNodes.swap(m_distributedNodes); |
| 151 clearDistribution(); |
| 152 } |
| 153 |
| 147 void HTMLSlotElement::dispatchSlotChangeEvent() | 154 void HTMLSlotElement::dispatchSlotChangeEvent() |
| 148 { | 155 { |
| 149 m_slotchangeEventEnqueued = false; | 156 m_slotchangeEventEnqueued = false; |
| 150 Event* event = Event::create(EventTypeNames::slotchange); | 157 Event* event = Event::create(EventTypeNames::slotchange); |
| 151 event->setTarget(this); | 158 event->setTarget(this); |
| 152 dispatchScopedEvent(event); | 159 dispatchScopedEvent(event); |
| 153 } | 160 } |
| 154 | 161 |
| 155 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const | 162 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const |
| 156 { | 163 { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 for (auto& child : NodeTraversal::childrenOf(*this)) { | 291 for (auto& child : NodeTraversal::childrenOf(*this)) { |
| 285 if (!child.isSlotable()) | 292 if (!child.isSlotable()) |
| 286 continue; | 293 continue; |
| 287 if (isHTMLSlotElement(child)) | 294 if (isHTMLSlotElement(child)) |
| 288 appendDistributedNodesFrom(toHTMLSlotElement(child)); | 295 appendDistributedNodesFrom(toHTMLSlotElement(child)); |
| 289 else | 296 else |
| 290 appendDistributedNode(child); | 297 appendDistributedNode(child); |
| 291 } | 298 } |
| 292 } | 299 } |
| 293 | 300 |
| 301 void HTMLSlotElement::lazyReattachDistributedNodesIfNeeded() |
| 302 { |
| 303 // TODO(hayato): Figure out an exact condition where reattach is required |
| 304 if (m_oldDistributedNodes != m_distributedNodes) { |
| 305 for (auto& node : m_oldDistributedNodes) |
| 306 node->lazyReattachIfAttached(); |
| 307 for (auto& node : m_distributedNodes) |
| 308 node->lazyReattachIfAttached(); |
| 309 } |
| 310 m_oldDistributedNodes.clear(); |
| 311 } |
| 312 |
| 294 void HTMLSlotElement::enqueueSlotChangeEvent() | 313 void HTMLSlotElement::enqueueSlotChangeEvent() |
| 295 { | 314 { |
| 296 if (!m_slotchangeEventEnqueued) { | 315 if (!m_slotchangeEventEnqueued) { |
| 297 Microtask::enqueueMicrotask(WTF::bind(&HTMLSlotElement::dispatchSlotChan
geEvent, Persistent<HTMLSlotElement>(this))); | 316 Microtask::enqueueMicrotask(WTF::bind(&HTMLSlotElement::dispatchSlotChan
geEvent, Persistent<HTMLSlotElement>(this))); |
| 298 m_slotchangeEventEnqueued = true; | 317 m_slotchangeEventEnqueued = true; |
| 299 } | 318 } |
| 300 | 319 |
| 301 ShadowRoot* root = containingShadowRoot(); | 320 ShadowRoot* root = containingShadowRoot(); |
| 302 DCHECK(root); | 321 DCHECK(root); |
| 303 DCHECK(root->isV1()); | 322 DCHECK(root->isV1()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 331 | 350 |
| 332 short HTMLSlotElement::tabIndex() const | 351 short HTMLSlotElement::tabIndex() const |
| 333 { | 352 { |
| 334 return Element::tabIndex(); | 353 return Element::tabIndex(); |
| 335 } | 354 } |
| 336 | 355 |
| 337 DEFINE_TRACE(HTMLSlotElement) | 356 DEFINE_TRACE(HTMLSlotElement) |
| 338 { | 357 { |
| 339 visitor->trace(m_assignedNodes); | 358 visitor->trace(m_assignedNodes); |
| 340 visitor->trace(m_distributedNodes); | 359 visitor->trace(m_distributedNodes); |
| 360 visitor->trace(m_oldDistributedNodes); |
| 341 visitor->trace(m_distributedIndices); | 361 visitor->trace(m_distributedIndices); |
| 342 HTMLElement::trace(visitor); | 362 HTMLElement::trace(visitor); |
| 343 } | 363 } |
| 344 | 364 |
| 345 } // namespace blink | 365 } // namespace blink |
| OLD | NEW |