| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type) | 55 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type) |
| 56 : DocumentFragment(0, CreateShadowRoot) | 56 : DocumentFragment(0, CreateShadowRoot) |
| 57 , TreeScope(*this, document) | 57 , TreeScope(*this, document) |
| 58 , m_numberOfStyles(0) | 58 , m_numberOfStyles(0) |
| 59 , m_childShadowRootCount(0) | 59 , m_childShadowRootCount(0) |
| 60 , m_type(static_cast<unsigned>(type)) | 60 , m_type(static_cast<unsigned>(type)) |
| 61 , m_registeredWithParentShadowRoot(false) | 61 , m_registeredWithParentShadowRoot(false) |
| 62 , m_descendantInsertionPointsIsValid(false) | 62 , m_descendantInsertionPointsIsValid(false) |
| 63 , m_delegatesFocus(false) | 63 , m_delegatesFocus(false) |
| 64 , m_descendantSlotsIsValid(false) | |
| 65 { | 64 { |
| 66 } | 65 } |
| 67 | 66 |
| 68 ShadowRoot::~ShadowRoot() | 67 ShadowRoot::~ShadowRoot() |
| 69 { | 68 { |
| 70 } | 69 } |
| 71 | 70 |
| 72 ShadowRoot* ShadowRoot::youngerShadowRoot() const | 71 ShadowRoot* ShadowRoot::youngerShadowRoot() const |
| 73 { | 72 { |
| 74 if (type() == ShadowRootType::V0 && m_shadowRootRareDataV0) | 73 if (type() == ShadowRootType::V0 && m_shadowRootRareDataV0) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 100 | 99 |
| 101 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) | 100 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) |
| 102 { | 101 { |
| 103 DCHECK_EQ(type(), ShadowRootType::V0); | 102 DCHECK_EQ(type(), ShadowRootType::V0); |
| 104 ensureShadowRootRareDataV0().setOlderShadowRoot(root); | 103 ensureShadowRootRareDataV0().setOlderShadowRoot(root); |
| 105 } | 104 } |
| 106 | 105 |
| 107 SlotAssignment& ShadowRoot::ensureSlotAssignment() | 106 SlotAssignment& ShadowRoot::ensureSlotAssignment() |
| 108 { | 107 { |
| 109 if (!m_slotAssignment) | 108 if (!m_slotAssignment) |
| 110 m_slotAssignment = SlotAssignment::create(); | 109 m_slotAssignment = SlotAssignment::create(*this); |
| 111 return *m_slotAssignment; | 110 return *m_slotAssignment; |
| 112 } | 111 } |
| 113 | 112 |
| 114 HTMLSlotElement* ShadowRoot::assignedSlotFor(const Node& node) const | |
| 115 { | |
| 116 DCHECK(m_slotAssignment); | |
| 117 return m_slotAssignment->assignedSlotFor(node); | |
| 118 } | |
| 119 | |
| 120 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) | 113 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) |
| 121 { | 114 { |
| 122 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no
t clonable."); | 115 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no
t clonable."); |
| 123 return nullptr; | 116 return nullptr; |
| 124 } | 117 } |
| 125 | 118 |
| 126 String ShadowRoot::innerHTML() const | 119 String ShadowRoot::innerHTML() const |
| 127 { | 120 { |
| 128 return createMarkup(this, ChildrenOnly); | 121 return createMarkup(this, ChildrenOnly); |
| 129 } | 122 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 return m_shadowRootRareDataV0->descendantInsertionPoints(); | 286 return m_shadowRootRareDataV0->descendantInsertionPoints(); |
| 294 } | 287 } |
| 295 | 288 |
| 296 StyleSheetList& ShadowRoot::styleSheets() | 289 StyleSheetList& ShadowRoot::styleSheets() |
| 297 { | 290 { |
| 298 if (!m_styleSheetList) | 291 if (!m_styleSheetList) |
| 299 setStyleSheets(StyleSheetList::create(this)); | 292 setStyleSheets(StyleSheetList::create(this)); |
| 300 return *m_styleSheetList; | 293 return *m_styleSheetList; |
| 301 } | 294 } |
| 302 | 295 |
| 303 void ShadowRoot::didAddSlot() | |
| 304 { | |
| 305 ensureSlotAssignment().didAddSlot(); | |
| 306 invalidateDescendantSlots(); | |
| 307 } | |
| 308 | |
| 309 void ShadowRoot::didRemoveSlot() | |
| 310 { | |
| 311 DCHECK(m_slotAssignment); | |
| 312 m_slotAssignment->didRemoveSlot(); | |
| 313 invalidateDescendantSlots(); | |
| 314 } | |
| 315 | |
| 316 void ShadowRoot::invalidateDescendantSlots() | |
| 317 { | |
| 318 DCHECK(m_slotAssignment); | |
| 319 m_descendantSlotsIsValid = false; | |
| 320 m_slotAssignment->clearDescendantSlots(); | |
| 321 } | |
| 322 | |
| 323 unsigned ShadowRoot::descendantSlotCount() const | |
| 324 { | |
| 325 return m_slotAssignment ? m_slotAssignment->descendantSlotCount() : 0; | |
| 326 } | |
| 327 | |
| 328 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots() | |
| 329 { | |
| 330 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea
pVector<Member<HTMLSlotElement>>)); | |
| 331 if (m_descendantSlotsIsValid) { | |
| 332 DCHECK(m_slotAssignment); | |
| 333 return m_slotAssignment->descendantSlots(); | |
| 334 } | |
| 335 if (descendantSlotCount() == 0) | |
| 336 return emptyList; | |
| 337 | |
| 338 DCHECK(m_slotAssignment); | |
| 339 HeapVector<Member<HTMLSlotElement>> slots; | |
| 340 slots.reserveCapacity(descendantSlotCount()); | |
| 341 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN
ode())) | |
| 342 slots.append(&slot); | |
| 343 m_slotAssignment->setDescendantSlots(slots); | |
| 344 m_descendantSlotsIsValid = true; | |
| 345 return m_slotAssignment->descendantSlots(); | |
| 346 } | |
| 347 | |
| 348 void ShadowRoot::assignV1() | |
| 349 { | |
| 350 if (!m_slotAssignment) | |
| 351 m_slotAssignment = SlotAssignment::create(); | |
| 352 m_slotAssignment->resolveAssignment(*this); | |
| 353 } | |
| 354 | |
| 355 void ShadowRoot::distributeV1() | 296 void ShadowRoot::distributeV1() |
| 356 { | 297 { |
| 357 if (!m_slotAssignment) | 298 ensureSlotAssignment().resolveDistribution(); |
| 358 m_slotAssignment = SlotAssignment::create(); | |
| 359 m_slotAssignment->resolveDistribution(*this); | |
| 360 } | 299 } |
| 361 | 300 |
| 362 DEFINE_TRACE(ShadowRoot) | 301 DEFINE_TRACE(ShadowRoot) |
| 363 { | 302 { |
| 364 visitor->trace(m_shadowRootRareDataV0); | 303 visitor->trace(m_shadowRootRareDataV0); |
| 365 visitor->trace(m_slotAssignment); | 304 visitor->trace(m_slotAssignment); |
| 366 visitor->trace(m_styleSheetList); | 305 visitor->trace(m_styleSheetList); |
| 367 TreeScope::trace(visitor); | 306 TreeScope::trace(visitor); |
| 368 DocumentFragment::trace(visitor); | 307 DocumentFragment::trace(visitor); |
| 369 } | 308 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 387 ostream << "ShadowRootType::Open"; | 326 ostream << "ShadowRootType::Open"; |
| 388 break; | 327 break; |
| 389 case ShadowRootType::Closed: | 328 case ShadowRootType::Closed: |
| 390 ostream << "ShadowRootType::Closed"; | 329 ostream << "ShadowRootType::Closed"; |
| 391 break; | 330 break; |
| 392 } | 331 } |
| 393 return ostream; | 332 return ostream; |
| 394 } | 333 } |
| 395 | 334 |
| 396 } // namespace blink | 335 } // namespace blink |
| OLD | NEW |