Chromium Code Reviews| 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 { |
|
kochi
2016/04/28 08:36:36
Looks you need to update this as well.
| |
| 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) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 DCHECK_EQ(type(), ShadowRootType::V0); | 96 DCHECK_EQ(type(), ShadowRootType::V0); |
| 96 ensureShadowRootRareDataV0().setYoungerShadowRoot(root); | 97 ensureShadowRootRareDataV0().setYoungerShadowRoot(root); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) | 100 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root) |
| 100 { | 101 { |
| 101 DCHECK_EQ(type(), ShadowRootType::V0); | 102 DCHECK_EQ(type(), ShadowRootType::V0); |
| 102 ensureShadowRootRareDataV0().setOlderShadowRoot(root); | 103 ensureShadowRootRareDataV0().setOlderShadowRoot(root); |
| 103 } | 104 } |
| 104 | 105 |
| 106 SlotAssignment& ShadowRoot::ensureSlotAssignment() | |
| 107 { | |
| 108 if (!m_slotAssignment) | |
| 109 m_slotAssignment = SlotAssignment::create(); | |
| 110 return *m_slotAssignment; | |
| 111 } | |
| 112 | |
| 113 HTMLSlotElement* ShadowRoot::assignedSlotFor(const Node& node) const | |
| 114 { | |
| 115 DCHECK(m_slotAssignment); | |
| 116 return m_slotAssignment->assignedSlotFor(node); | |
| 117 } | |
| 118 | |
| 105 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) | 119 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) |
| 106 { | 120 { |
| 107 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no t clonable."); | 121 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no t clonable."); |
| 108 return nullptr; | 122 return nullptr; |
| 109 } | 123 } |
| 110 | 124 |
| 111 String ShadowRoot::innerHTML() const | 125 String ShadowRoot::innerHTML() const |
| 112 { | 126 { |
| 113 return createMarkup(this, ChildrenOnly); | 127 return createMarkup(this, ChildrenOnly); |
| 114 } | 128 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 { | 216 { |
| 203 ++m_numberOfStyles; | 217 ++m_numberOfStyles; |
| 204 } | 218 } |
| 205 | 219 |
| 206 void ShadowRoot::unregisterScopedHTMLStyleChild() | 220 void ShadowRoot::unregisterScopedHTMLStyleChild() |
| 207 { | 221 { |
| 208 DCHECK_GT(m_numberOfStyles, 0u); | 222 DCHECK_GT(m_numberOfStyles, 0u); |
| 209 --m_numberOfStyles; | 223 --m_numberOfStyles; |
| 210 } | 224 } |
| 211 | 225 |
| 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() | 226 ShadowRootRareDataV0& ShadowRoot::ensureShadowRootRareDataV0() |
| 222 { | 227 { |
| 223 if (m_shadowRootRareDataV0) | 228 if (m_shadowRootRareDataV0) |
| 224 return *m_shadowRootRareDataV0; | 229 return *m_shadowRootRareDataV0; |
| 225 | 230 |
| 226 m_shadowRootRareDataV0 = new ShadowRootRareDataV0; | 231 m_shadowRootRareDataV0 = new ShadowRootRareDataV0; |
| 227 return *m_shadowRootRareDataV0; | 232 return *m_shadowRootRareDataV0; |
| 228 } | 233 } |
| 229 | 234 |
| 230 bool ShadowRoot::containsShadowElements() const | 235 bool ShadowRoot::containsShadowElements() const |
| 231 { | 236 { |
| 232 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen ts() : false; | 237 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen ts() : false; |
| 233 } | 238 } |
| 234 | 239 |
| 235 bool ShadowRoot::containsContentElements() const | 240 bool ShadowRoot::containsContentElements() const |
| 236 { | 241 { |
| 237 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme nts() : false; | 242 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme nts() : false; |
| 238 } | 243 } |
| 239 | 244 |
| 240 bool ShadowRoot::containsShadowRoots() const | |
| 241 { | |
| 242 return m_shadowRootRareData ? m_shadowRootRareData->containsShadowRoots() : false; | |
| 243 } | |
| 244 | |
| 245 unsigned ShadowRoot::descendantShadowElementCount() const | 245 unsigned ShadowRoot::descendantShadowElementCount() const |
| 246 { | 246 { |
| 247 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->descendantShadowElem entCount() : 0; | 247 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->descendantShadowElem entCount() : 0; |
| 248 } | 248 } |
| 249 | 249 |
| 250 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const | 250 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const |
| 251 { | 251 { |
| 252 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint OfYoungerShadowRoot() : nullptr; | 252 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint OfYoungerShadowRoot() : nullptr; |
| 253 } | 253 } |
| 254 | 254 |
| 255 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s hadowInsertionPoint) | 255 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s hadowInsertionPoint) |
| 256 { | 256 { |
| 257 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint) | 257 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint) |
| 258 return; | 258 return; |
| 259 ensureShadowRootRareDataV0().setShadowInsertionPointOfYoungerShadowRoot(shad owInsertionPoint); | 259 ensureShadowRootRareDataV0().setShadowInsertionPointOfYoungerShadowRoot(shad owInsertionPoint); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) | 262 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) |
| 263 { | 263 { |
| 264 ensureShadowRootRareDataV0().didAddInsertionPoint(insertionPoint); | 264 ensureShadowRootRareDataV0().didAddInsertionPoint(insertionPoint); |
| 265 invalidateDescendantInsertionPoints(); | 265 invalidateDescendantInsertionPoints(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) | 268 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) |
| 269 { | 269 { |
| 270 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint); | 270 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint); |
| 271 invalidateDescendantInsertionPoints(); | 271 invalidateDescendantInsertionPoints(); |
| 272 } | 272 } |
| 273 | 273 |
| 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() | 274 void ShadowRoot::invalidateDescendantInsertionPoints() |
| 293 { | 275 { |
| 294 m_descendantInsertionPointsIsValid = false; | 276 m_descendantInsertionPointsIsValid = false; |
| 295 m_shadowRootRareDataV0->clearDescendantInsertionPoints(); | 277 m_shadowRootRareDataV0->clearDescendantInsertionPoints(); |
| 296 } | 278 } |
| 297 | 279 |
| 298 const HeapVector<Member<InsertionPoint>>& ShadowRoot::descendantInsertionPoints( ) | 280 const HeapVector<Member<InsertionPoint>>& ShadowRoot::descendantInsertionPoints( ) |
| 299 { | 281 { |
| 300 DEFINE_STATIC_LOCAL(HeapVector<Member<InsertionPoint>>, emptyList, (new Heap Vector<Member<InsertionPoint>>)); | 282 DEFINE_STATIC_LOCAL(HeapVector<Member<InsertionPoint>>, emptyList, (new Heap Vector<Member<InsertionPoint>>)); |
| 301 if (m_shadowRootRareDataV0 && m_descendantInsertionPointsIsValid) | 283 if (m_shadowRootRareDataV0 && m_descendantInsertionPointsIsValid) |
| 302 return m_shadowRootRareDataV0->descendantInsertionPoints(); | 284 return m_shadowRootRareDataV0->descendantInsertionPoints(); |
| 303 | 285 |
| 304 m_descendantInsertionPointsIsValid = true; | 286 m_descendantInsertionPointsIsValid = true; |
| 305 | 287 |
| 306 if (!containsInsertionPoints()) | 288 if (!containsInsertionPoints()) |
| 307 return emptyList; | 289 return emptyList; |
| 308 | 290 |
| 309 HeapVector<Member<InsertionPoint>> insertionPoints; | 291 HeapVector<Member<InsertionPoint>> insertionPoints; |
| 310 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants Of(*this)) | 292 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants Of(*this)) |
| 311 insertionPoints.append(&insertionPoint); | 293 insertionPoints.append(&insertionPoint); |
| 312 | 294 |
| 313 ensureShadowRootRareDataV0().setDescendantInsertionPoints(insertionPoints); | 295 ensureShadowRootRareDataV0().setDescendantInsertionPoints(insertionPoints); |
| 314 | 296 |
| 315 return m_shadowRootRareDataV0->descendantInsertionPoints(); | 297 return m_shadowRootRareDataV0->descendantInsertionPoints(); |
| 316 } | 298 } |
| 317 | 299 |
| 318 StyleSheetList* ShadowRoot::styleSheets() | 300 StyleSheetList& ShadowRoot::styleSheets() |
| 319 { | 301 { |
| 320 if (!ensureShadowRootRareData().styleSheets()) | 302 if (!m_styleSheetList) |
| 321 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this)); | 303 setStyleSheets(StyleSheetList::create(this)); |
| 322 | 304 return *m_styleSheetList; |
| 323 return m_shadowRootRareData->styleSheets(); | |
| 324 } | 305 } |
| 325 | 306 |
| 326 void ShadowRoot::didAddSlot() | 307 void ShadowRoot::didAddSlot() |
| 327 { | 308 { |
| 328 ensureShadowRootRareData().didAddSlot(); | 309 ensureSlotAssignment().didAddSlot(); |
| 329 invalidateDescendantSlots(); | 310 invalidateDescendantSlots(); |
| 330 } | 311 } |
| 331 | 312 |
| 332 void ShadowRoot::didRemoveSlot() | 313 void ShadowRoot::didRemoveSlot() |
| 333 { | 314 { |
| 334 DCHECK(m_shadowRootRareData); | 315 DCHECK(m_slotAssignment); |
| 335 m_shadowRootRareData->didRemoveSlot(); | 316 m_slotAssignment->didRemoveSlot(); |
| 336 invalidateDescendantSlots(); | 317 invalidateDescendantSlots(); |
| 337 } | 318 } |
| 338 | 319 |
| 339 void ShadowRoot::invalidateDescendantSlots() | 320 void ShadowRoot::invalidateDescendantSlots() |
| 340 { | 321 { |
| 322 DCHECK(m_slotAssignment); | |
| 341 m_descendantSlotsIsValid = false; | 323 m_descendantSlotsIsValid = false; |
| 342 m_shadowRootRareData->clearDescendantSlots(); | 324 m_slotAssignment->clearDescendantSlots(); |
| 343 } | 325 } |
| 344 | 326 |
| 345 unsigned ShadowRoot::descendantSlotCount() const | 327 unsigned ShadowRoot::descendantSlotCount() const |
| 346 { | 328 { |
| 347 return m_shadowRootRareData ? m_shadowRootRareData->descendantSlotCount() : 0; | 329 return m_slotAssignment ? m_slotAssignment->descendantSlotCount() : 0; |
| 348 } | 330 } |
| 349 | 331 |
| 350 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots() | 332 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots() |
| 351 { | 333 { |
| 352 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea pVector<Member<HTMLSlotElement>>)); | 334 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea pVector<Member<HTMLSlotElement>>)); |
| 353 if (m_descendantSlotsIsValid) { | 335 if (m_descendantSlotsIsValid) { |
| 354 DCHECK(m_shadowRootRareData); | 336 DCHECK(m_slotAssignment); |
| 355 return m_shadowRootRareData->descendantSlots(); | 337 return m_slotAssignment->descendantSlots(); |
| 356 } | 338 } |
| 357 if (descendantSlotCount() == 0) | 339 if (descendantSlotCount() == 0) |
| 358 return emptyList; | 340 return emptyList; |
| 359 | 341 |
| 360 DCHECK(m_shadowRootRareData); | 342 DCHECK(m_slotAssignment); |
| 361 HeapVector<Member<HTMLSlotElement>> slots; | 343 HeapVector<Member<HTMLSlotElement>> slots; |
| 362 slots.reserveCapacity(descendantSlotCount()); | 344 slots.reserveCapacity(descendantSlotCount()); |
| 363 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN ode())) | 345 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN ode())) |
| 364 slots.append(&slot); | 346 slots.append(&slot); |
| 365 m_shadowRootRareData->setDescendantSlots(slots); | 347 m_slotAssignment->setDescendantSlots(slots); |
| 366 m_descendantSlotsIsValid = true; | 348 m_descendantSlotsIsValid = true; |
| 367 return m_shadowRootRareData->descendantSlots(); | 349 return m_slotAssignment->descendantSlots(); |
| 368 } | 350 } |
| 369 | 351 |
| 370 void ShadowRoot::assignV1() | 352 void ShadowRoot::assignV1() |
| 371 { | 353 { |
| 372 if (!m_slotAssignment) | 354 if (!m_slotAssignment) |
| 373 m_slotAssignment = SlotAssignment::create(); | 355 m_slotAssignment = SlotAssignment::create(); |
| 374 m_slotAssignment->resolveAssignment(*this); | 356 m_slotAssignment->resolveAssignment(*this); |
| 375 } | 357 } |
| 376 | 358 |
| 377 void ShadowRoot::distributeV1() | 359 void ShadowRoot::distributeV1() |
| 378 { | 360 { |
| 379 if (!m_slotAssignment) | 361 if (!m_slotAssignment) |
| 380 m_slotAssignment = SlotAssignment::create(); | 362 m_slotAssignment = SlotAssignment::create(); |
| 381 m_slotAssignment->resolveDistribution(*this); | 363 m_slotAssignment->resolveDistribution(*this); |
| 382 } | 364 } |
| 383 | 365 |
| 384 DEFINE_TRACE(ShadowRoot) | 366 DEFINE_TRACE(ShadowRoot) |
| 385 { | 367 { |
| 386 visitor->trace(m_shadowRootRareData); | |
| 387 visitor->trace(m_shadowRootRareDataV0); | 368 visitor->trace(m_shadowRootRareDataV0); |
| 388 visitor->trace(m_slotAssignment); | 369 visitor->trace(m_slotAssignment); |
| 370 visitor->trace(m_styleSheetList); | |
| 389 TreeScope::trace(visitor); | 371 TreeScope::trace(visitor); |
| 390 DocumentFragment::trace(visitor); | 372 DocumentFragment::trace(visitor); |
| 391 } | 373 } |
| 392 | 374 |
| 393 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type) | 375 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type) |
| 394 { | 376 { |
| 395 switch (type) { | 377 switch (type) { |
| 396 case ShadowRootType::UserAgent: | 378 case ShadowRootType::UserAgent: |
| 397 ostream << "ShadowRootType::UserAgent"; | 379 ostream << "ShadowRootType::UserAgent"; |
| 398 break; | 380 break; |
| 399 case ShadowRootType::V0: | 381 case ShadowRootType::V0: |
| 400 ostream << "ShadowRootType::V0"; | 382 ostream << "ShadowRootType::V0"; |
| 401 break; | 383 break; |
| 402 case ShadowRootType::Open: | 384 case ShadowRootType::Open: |
| 403 ostream << "ShadowRootType::Open"; | 385 ostream << "ShadowRootType::Open"; |
| 404 break; | 386 break; |
| 405 case ShadowRootType::Closed: | 387 case ShadowRootType::Closed: |
| 406 ostream << "ShadowRootType::Closed"; | 388 ostream << "ShadowRootType::Closed"; |
| 407 break; | 389 break; |
| 408 } | 390 } |
| 409 return ostream; | 391 return ostream; |
| 410 } | 392 } |
| 411 | 393 |
| 412 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |