| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
| 30 #include "core/css/StyleSheetList.h" | 30 #include "core/css/StyleSheetList.h" |
| 31 #include "core/css/resolver/StyleResolver.h" | 31 #include "core/css/resolver/StyleResolver.h" |
| 32 #include "core/css/resolver/StyleSharingDepthScope.h" | 32 #include "core/css/resolver/StyleSharingDepthScope.h" |
| 33 #include "core/dom/ElementTraversal.h" | 33 #include "core/dom/ElementTraversal.h" |
| 34 #include "core/dom/StyleEngine.h" | 34 #include "core/dom/StyleEngine.h" |
| 35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 36 #include "core/dom/shadow/ElementShadow.h" | 36 #include "core/dom/shadow/ElementShadow.h" |
| 37 #include "core/dom/shadow/InsertionPoint.h" | 37 #include "core/dom/shadow/InsertionPoint.h" |
| 38 #include "core/dom/shadow/ShadowRootRareData.h" | |
| 39 #include "core/dom/shadow/ShadowRootRareDataV0.h" | 38 #include "core/dom/shadow/ShadowRootRareDataV0.h" |
| 39 #include "core/dom/shadow/SlotAssignment.h" |
| 40 #include "core/editing/serializers/Serialization.h" | 40 #include "core/editing/serializers/Serialization.h" |
| 41 #include "core/html/HTMLShadowElement.h" | 41 #include "core/html/HTMLShadowElement.h" |
| 42 #include "core/html/HTMLSlotElement.h" |
| 42 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope { | 47 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope { |
| 47 char emptyClassFieldsDueToGCMixinMarker[1]; | 48 char emptyClassFieldsDueToGCMixinMarker[1]; |
| 48 Member<void*> willbeMember[3]; | 49 Member<void*> willbeMember[3]; |
| 49 unsigned countersAndFlags[1]; | 50 unsigned countersAndFlags[1]; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "ShadowRoot sh
ould stay small"); | 53 static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "ShadowRoot sh
ould stay small"); |
| 53 | 54 |
| 54 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type) | 55 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type) |
| 55 : DocumentFragment(0, CreateShadowRoot) | 56 : DocumentFragment(0, CreateShadowRoot) |
| 56 , TreeScope(*this, document) | 57 , TreeScope(*this, document) |
| 57 , m_numberOfStyles(0) | 58 , m_numberOfStyles(0) |
| 59 , m_childShadowRootCount(0) |
| 58 , m_type(static_cast<unsigned>(type)) | 60 , m_type(static_cast<unsigned>(type)) |
| 59 , m_registeredWithParentShadowRoot(false) | 61 , m_registeredWithParentShadowRoot(false) |
| 60 , m_descendantInsertionPointsIsValid(false) | 62 , m_descendantInsertionPointsIsValid(false) |
| 61 , m_delegatesFocus(false) | 63 , m_delegatesFocus(false) |
| 62 , m_descendantSlotsIsValid(false) | 64 , m_descendantSlotsIsValid(false) |
| 63 { | 65 { |
| 64 } | 66 } |
| 65 | 67 |
| 66 ShadowRoot::~ShadowRoot() | 68 ShadowRoot::~ShadowRoot() |
| 67 { | 69 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 DCHECK_EQ(type(), ShadowRootType::V0); | 97 DCHECK_EQ(type(), ShadowRootType::V0); |
| 96 ensureShadowRootRareDataV0().setYoungerShadowRoot(root); | 98 ensureShadowRootRareDataV0().setYoungerShadowRoot(root); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) | 101 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) |
| 100 { | 102 { |
| 101 DCHECK_EQ(type(), ShadowRootType::V0); | 103 DCHECK_EQ(type(), ShadowRootType::V0); |
| 102 ensureShadowRootRareDataV0().setOlderShadowRoot(root); | 104 ensureShadowRootRareDataV0().setOlderShadowRoot(root); |
| 103 } | 105 } |
| 104 | 106 |
| 107 SlotAssignment& ShadowRoot::ensureSlotAssignment() |
| 108 { |
| 109 if (!m_slotAssignment) |
| 110 m_slotAssignment = SlotAssignment::create(); |
| 111 return *m_slotAssignment; |
| 112 } |
| 113 |
| 114 HTMLSlotElement* ShadowRoot::assignedSlotFor(const Node& node) const |
| 115 { |
| 116 DCHECK(m_slotAssignment); |
| 117 return m_slotAssignment->assignedSlotFor(node); |
| 118 } |
| 119 |
| 105 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) | 120 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) |
| 106 { | 121 { |
| 107 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no
t clonable."); | 122 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no
t clonable."); |
| 108 return nullptr; | 123 return nullptr; |
| 109 } | 124 } |
| 110 | 125 |
| 111 String ShadowRoot::innerHTML() const | 126 String ShadowRoot::innerHTML() const |
| 112 { | 127 { |
| 113 return createMarkup(this, ChildrenOnly); | 128 return createMarkup(this, ChildrenOnly); |
| 114 } | 129 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 { | 217 { |
| 203 ++m_numberOfStyles; | 218 ++m_numberOfStyles; |
| 204 } | 219 } |
| 205 | 220 |
| 206 void ShadowRoot::unregisterScopedHTMLStyleChild() | 221 void ShadowRoot::unregisterScopedHTMLStyleChild() |
| 207 { | 222 { |
| 208 DCHECK_GT(m_numberOfStyles, 0u); | 223 DCHECK_GT(m_numberOfStyles, 0u); |
| 209 --m_numberOfStyles; | 224 --m_numberOfStyles; |
| 210 } | 225 } |
| 211 | 226 |
| 212 ShadowRootRareData& ShadowRoot::ensureShadowRootRareData() | |
| 213 { | |
| 214 if (m_shadowRootRareData) | |
| 215 return *m_shadowRootRareData; | |
| 216 | |
| 217 m_shadowRootRareData = new ShadowRootRareData; | |
| 218 return *m_shadowRootRareData; | |
| 219 } | |
| 220 | |
| 221 ShadowRootRareDataV0& ShadowRoot::ensureShadowRootRareDataV0() | 227 ShadowRootRareDataV0& ShadowRoot::ensureShadowRootRareDataV0() |
| 222 { | 228 { |
| 223 if (m_shadowRootRareDataV0) | 229 if (m_shadowRootRareDataV0) |
| 224 return *m_shadowRootRareDataV0; | 230 return *m_shadowRootRareDataV0; |
| 225 | 231 |
| 226 m_shadowRootRareDataV0 = new ShadowRootRareDataV0; | 232 m_shadowRootRareDataV0 = new ShadowRootRareDataV0; |
| 227 return *m_shadowRootRareDataV0; | 233 return *m_shadowRootRareDataV0; |
| 228 } | 234 } |
| 229 | 235 |
| 230 bool ShadowRoot::containsShadowElements() const | 236 bool ShadowRoot::containsShadowElements() const |
| 231 { | 237 { |
| 232 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen
ts() : false; | 238 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen
ts() : false; |
| 233 } | 239 } |
| 234 | 240 |
| 235 bool ShadowRoot::containsContentElements() const | 241 bool ShadowRoot::containsContentElements() const |
| 236 { | 242 { |
| 237 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme
nts() : false; | 243 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme
nts() : false; |
| 238 } | 244 } |
| 239 | 245 |
| 240 bool ShadowRoot::containsShadowRoots() const | |
| 241 { | |
| 242 return m_shadowRootRareData ? m_shadowRootRareData->containsShadowRoots() :
false; | |
| 243 } | |
| 244 | |
| 245 unsigned ShadowRoot::descendantShadowElementCount() const | 246 unsigned ShadowRoot::descendantShadowElementCount() const |
| 246 { | 247 { |
| 247 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->descendantShadowElem
entCount() : 0; | 248 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->descendantShadowElem
entCount() : 0; |
| 248 } | 249 } |
| 249 | 250 |
| 250 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const | 251 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const |
| 251 { | 252 { |
| 252 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint
OfYoungerShadowRoot() : nullptr; | 253 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint
OfYoungerShadowRoot() : nullptr; |
| 253 } | 254 } |
| 254 | 255 |
| 255 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s
hadowInsertionPoint) | 256 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s
hadowInsertionPoint) |
| 256 { | 257 { |
| 257 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint) | 258 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint) |
| 258 return; | 259 return; |
| 259 ensureShadowRootRareDataV0().setShadowInsertionPointOfYoungerShadowRoot(shad
owInsertionPoint); | 260 ensureShadowRootRareDataV0().setShadowInsertionPointOfYoungerShadowRoot(shad
owInsertionPoint); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) | 263 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) |
| 263 { | 264 { |
| 264 ensureShadowRootRareDataV0().didAddInsertionPoint(insertionPoint); | 265 ensureShadowRootRareDataV0().didAddInsertionPoint(insertionPoint); |
| 265 invalidateDescendantInsertionPoints(); | 266 invalidateDescendantInsertionPoints(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) | 269 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) |
| 269 { | 270 { |
| 270 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint); | 271 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint); |
| 271 invalidateDescendantInsertionPoints(); | 272 invalidateDescendantInsertionPoints(); |
| 272 } | 273 } |
| 273 | 274 |
| 274 void ShadowRoot::addChildShadowRoot() | |
| 275 { | |
| 276 ensureShadowRootRareData().didAddChildShadowRoot(); | |
| 277 } | |
| 278 | |
| 279 void ShadowRoot::removeChildShadowRoot() | |
| 280 { | |
| 281 // FIXME: Why isn't this an ASSERT? | |
| 282 if (!m_shadowRootRareData) | |
| 283 return; | |
| 284 m_shadowRootRareData->didRemoveChildShadowRoot(); | |
| 285 } | |
| 286 | |
| 287 unsigned ShadowRoot::childShadowRootCount() const | |
| 288 { | |
| 289 return m_shadowRootRareData ? m_shadowRootRareData->childShadowRootCount() :
0; | |
| 290 } | |
| 291 | |
| 292 void ShadowRoot::invalidateDescendantInsertionPoints() | 275 void ShadowRoot::invalidateDescendantInsertionPoints() |
| 293 { | 276 { |
| 294 m_descendantInsertionPointsIsValid = false; | 277 m_descendantInsertionPointsIsValid = false; |
| 295 m_shadowRootRareDataV0->clearDescendantInsertionPoints(); | 278 m_shadowRootRareDataV0->clearDescendantInsertionPoints(); |
| 296 } | 279 } |
| 297 | 280 |
| 298 const HeapVector<Member<InsertionPoint>>& ShadowRoot::descendantInsertionPoints(
) | 281 const HeapVector<Member<InsertionPoint>>& ShadowRoot::descendantInsertionPoints(
) |
| 299 { | 282 { |
| 300 DEFINE_STATIC_LOCAL(HeapVector<Member<InsertionPoint>>, emptyList, (new Heap
Vector<Member<InsertionPoint>>)); | 283 DEFINE_STATIC_LOCAL(HeapVector<Member<InsertionPoint>>, emptyList, (new Heap
Vector<Member<InsertionPoint>>)); |
| 301 if (m_shadowRootRareDataV0 && m_descendantInsertionPointsIsValid) | 284 if (m_shadowRootRareDataV0 && m_descendantInsertionPointsIsValid) |
| 302 return m_shadowRootRareDataV0->descendantInsertionPoints(); | 285 return m_shadowRootRareDataV0->descendantInsertionPoints(); |
| 303 | 286 |
| 304 m_descendantInsertionPointsIsValid = true; | 287 m_descendantInsertionPointsIsValid = true; |
| 305 | 288 |
| 306 if (!containsInsertionPoints()) | 289 if (!containsInsertionPoints()) |
| 307 return emptyList; | 290 return emptyList; |
| 308 | 291 |
| 309 HeapVector<Member<InsertionPoint>> insertionPoints; | 292 HeapVector<Member<InsertionPoint>> insertionPoints; |
| 310 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants
Of(*this)) | 293 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants
Of(*this)) |
| 311 insertionPoints.append(&insertionPoint); | 294 insertionPoints.append(&insertionPoint); |
| 312 | 295 |
| 313 ensureShadowRootRareDataV0().setDescendantInsertionPoints(insertionPoints); | 296 ensureShadowRootRareDataV0().setDescendantInsertionPoints(insertionPoints); |
| 314 | 297 |
| 315 return m_shadowRootRareDataV0->descendantInsertionPoints(); | 298 return m_shadowRootRareDataV0->descendantInsertionPoints(); |
| 316 } | 299 } |
| 317 | 300 |
| 318 StyleSheetList* ShadowRoot::styleSheets() | 301 StyleSheetList& ShadowRoot::styleSheets() |
| 319 { | 302 { |
| 320 if (!ensureShadowRootRareData().styleSheets()) | 303 if (!m_styleSheetList) |
| 321 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this)); | 304 setStyleSheets(StyleSheetList::create(this)); |
| 322 | 305 return *m_styleSheetList; |
| 323 return m_shadowRootRareData->styleSheets(); | |
| 324 } | 306 } |
| 325 | 307 |
| 326 void ShadowRoot::didAddSlot() | 308 void ShadowRoot::didAddSlot() |
| 327 { | 309 { |
| 328 ensureShadowRootRareData().didAddSlot(); | 310 ensureSlotAssignment().didAddSlot(); |
| 329 invalidateDescendantSlots(); | 311 invalidateDescendantSlots(); |
| 330 } | 312 } |
| 331 | 313 |
| 332 void ShadowRoot::didRemoveSlot() | 314 void ShadowRoot::didRemoveSlot() |
| 333 { | 315 { |
| 334 DCHECK(m_shadowRootRareData); | 316 DCHECK(m_slotAssignment); |
| 335 m_shadowRootRareData->didRemoveSlot(); | 317 m_slotAssignment->didRemoveSlot(); |
| 336 invalidateDescendantSlots(); | 318 invalidateDescendantSlots(); |
| 337 } | 319 } |
| 338 | 320 |
| 339 void ShadowRoot::invalidateDescendantSlots() | 321 void ShadowRoot::invalidateDescendantSlots() |
| 340 { | 322 { |
| 323 DCHECK(m_slotAssignment); |
| 341 m_descendantSlotsIsValid = false; | 324 m_descendantSlotsIsValid = false; |
| 342 m_shadowRootRareData->clearDescendantSlots(); | 325 m_slotAssignment->clearDescendantSlots(); |
| 343 } | 326 } |
| 344 | 327 |
| 345 unsigned ShadowRoot::descendantSlotCount() const | 328 unsigned ShadowRoot::descendantSlotCount() const |
| 346 { | 329 { |
| 347 return m_shadowRootRareData ? m_shadowRootRareData->descendantSlotCount() :
0; | 330 return m_slotAssignment ? m_slotAssignment->descendantSlotCount() : 0; |
| 348 } | 331 } |
| 349 | 332 |
| 350 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots() | 333 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots() |
| 351 { | 334 { |
| 352 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea
pVector<Member<HTMLSlotElement>>)); | 335 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea
pVector<Member<HTMLSlotElement>>)); |
| 353 if (m_descendantSlotsIsValid) { | 336 if (m_descendantSlotsIsValid) { |
| 354 DCHECK(m_shadowRootRareData); | 337 DCHECK(m_slotAssignment); |
| 355 return m_shadowRootRareData->descendantSlots(); | 338 return m_slotAssignment->descendantSlots(); |
| 356 } | 339 } |
| 357 if (descendantSlotCount() == 0) | 340 if (descendantSlotCount() == 0) |
| 358 return emptyList; | 341 return emptyList; |
| 359 | 342 |
| 360 DCHECK(m_shadowRootRareData); | 343 DCHECK(m_slotAssignment); |
| 361 HeapVector<Member<HTMLSlotElement>> slots; | 344 HeapVector<Member<HTMLSlotElement>> slots; |
| 362 slots.reserveCapacity(descendantSlotCount()); | 345 slots.reserveCapacity(descendantSlotCount()); |
| 363 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN
ode())) | 346 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN
ode())) |
| 364 slots.append(&slot); | 347 slots.append(&slot); |
| 365 m_shadowRootRareData->setDescendantSlots(slots); | 348 m_slotAssignment->setDescendantSlots(slots); |
| 366 m_descendantSlotsIsValid = true; | 349 m_descendantSlotsIsValid = true; |
| 367 return m_shadowRootRareData->descendantSlots(); | 350 return m_slotAssignment->descendantSlots(); |
| 368 } | 351 } |
| 369 | 352 |
| 370 void ShadowRoot::assignV1() | 353 void ShadowRoot::assignV1() |
| 371 { | 354 { |
| 372 if (!m_slotAssignment) | 355 if (!m_slotAssignment) |
| 373 m_slotAssignment = SlotAssignment::create(); | 356 m_slotAssignment = SlotAssignment::create(); |
| 374 m_slotAssignment->resolveAssignment(*this); | 357 m_slotAssignment->resolveAssignment(*this); |
| 375 } | 358 } |
| 376 | 359 |
| 377 void ShadowRoot::distributeV1() | 360 void ShadowRoot::distributeV1() |
| 378 { | 361 { |
| 379 if (!m_slotAssignment) | 362 if (!m_slotAssignment) |
| 380 m_slotAssignment = SlotAssignment::create(); | 363 m_slotAssignment = SlotAssignment::create(); |
| 381 m_slotAssignment->resolveDistribution(*this); | 364 m_slotAssignment->resolveDistribution(*this); |
| 382 } | 365 } |
| 383 | 366 |
| 384 DEFINE_TRACE(ShadowRoot) | 367 DEFINE_TRACE(ShadowRoot) |
| 385 { | 368 { |
| 386 visitor->trace(m_shadowRootRareData); | |
| 387 visitor->trace(m_shadowRootRareDataV0); | 369 visitor->trace(m_shadowRootRareDataV0); |
| 388 visitor->trace(m_slotAssignment); | 370 visitor->trace(m_slotAssignment); |
| 371 visitor->trace(m_styleSheetList); |
| 389 TreeScope::trace(visitor); | 372 TreeScope::trace(visitor); |
| 390 DocumentFragment::trace(visitor); | 373 DocumentFragment::trace(visitor); |
| 391 } | 374 } |
| 392 | 375 |
| 393 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type) | 376 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type) |
| 394 { | 377 { |
| 395 switch (type) { | 378 switch (type) { |
| 396 case ShadowRootType::UserAgent: | 379 case ShadowRootType::UserAgent: |
| 397 ostream << "ShadowRootType::UserAgent"; | 380 ostream << "ShadowRootType::UserAgent"; |
| 398 break; | 381 break; |
| 399 case ShadowRootType::V0: | 382 case ShadowRootType::V0: |
| 400 ostream << "ShadowRootType::V0"; | 383 ostream << "ShadowRootType::V0"; |
| 401 break; | 384 break; |
| 402 case ShadowRootType::Open: | 385 case ShadowRootType::Open: |
| 403 ostream << "ShadowRootType::Open"; | 386 ostream << "ShadowRootType::Open"; |
| 404 break; | 387 break; |
| 405 case ShadowRootType::Closed: | 388 case ShadowRootType::Closed: |
| 406 ostream << "ShadowRootType::Closed"; | 389 ostream << "ShadowRootType::Closed"; |
| 407 break; | 390 break; |
| 408 } | 391 } |
| 409 return ostream; | 392 return ostream; |
| 410 } | 393 } |
| 411 | 394 |
| 412 } // namespace blink | 395 } // namespace blink |
| OLD | NEW |