Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/Source/core/dom/shadow/ShadowRoot.cpp

Issue 1995203002: Rewrite Shadow DOM distribution engine to support partial synchronous distribution for v1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return m_shadowRootRareDataV0->descendantInsertionPoints(); 291 return m_shadowRootRareDataV0->descendantInsertionPoints();
299 } 292 }
300 293
301 StyleSheetList& ShadowRoot::styleSheets() 294 StyleSheetList& ShadowRoot::styleSheets()
302 { 295 {
303 if (!m_styleSheetList) 296 if (!m_styleSheetList)
304 setStyleSheets(StyleSheetList::create(this)); 297 setStyleSheets(StyleSheetList::create(this));
305 return *m_styleSheetList; 298 return *m_styleSheetList;
306 } 299 }
307 300
308 void ShadowRoot::didAddSlot()
309 {
310 ensureSlotAssignment().didAddSlot();
311 invalidateDescendantSlots();
312 }
313
314 void ShadowRoot::didRemoveSlot()
315 {
316 DCHECK(m_slotAssignment);
317 m_slotAssignment->didRemoveSlot();
318 invalidateDescendantSlots();
319 }
320
321 void ShadowRoot::invalidateDescendantSlots()
322 {
323 DCHECK(m_slotAssignment);
324 m_descendantSlotsIsValid = false;
325 m_slotAssignment->clearDescendantSlots();
326 }
327
328 unsigned ShadowRoot::descendantSlotCount() const
329 {
330 return m_slotAssignment ? m_slotAssignment->descendantSlotCount() : 0;
331 }
332
333 const HeapVector<Member<HTMLSlotElement>>& ShadowRoot::descendantSlots()
334 {
335 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLSlotElement>>, emptyList, (new Hea pVector<Member<HTMLSlotElement>>));
336 if (m_descendantSlotsIsValid) {
337 DCHECK(m_slotAssignment);
338 return m_slotAssignment->descendantSlots();
339 }
340 if (descendantSlotCount() == 0)
341 return emptyList;
342
343 DCHECK(m_slotAssignment);
344 HeapVector<Member<HTMLSlotElement>> slots;
345 slots.reserveCapacity(descendantSlotCount());
346 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(rootN ode()))
347 slots.append(&slot);
348 m_slotAssignment->setDescendantSlots(slots);
349 m_descendantSlotsIsValid = true;
350 return m_slotAssignment->descendantSlots();
351 }
352
353 void ShadowRoot::assignV1()
354 {
355 if (!m_slotAssignment)
356 m_slotAssignment = SlotAssignment::create();
357 m_slotAssignment->resolveAssignment(*this);
358 }
359
360 void ShadowRoot::distributeV1() 301 void ShadowRoot::distributeV1()
361 { 302 {
362 if (!m_slotAssignment) 303 ensureSlotAssignment().resolveDistribution();
363 m_slotAssignment = SlotAssignment::create();
364 m_slotAssignment->resolveDistribution(*this);
365 } 304 }
366 305
367 DEFINE_TRACE(ShadowRoot) 306 DEFINE_TRACE(ShadowRoot)
368 { 307 {
369 visitor->trace(m_shadowRootRareDataV0); 308 visitor->trace(m_shadowRootRareDataV0);
370 visitor->trace(m_slotAssignment); 309 visitor->trace(m_slotAssignment);
371 visitor->trace(m_styleSheetList); 310 visitor->trace(m_styleSheetList);
372 TreeScope::trace(visitor); 311 TreeScope::trace(visitor);
373 DocumentFragment::trace(visitor); 312 DocumentFragment::trace(visitor);
374 } 313 }
(...skipping 17 matching lines...) Expand all
392 ostream << "ShadowRootType::Open"; 331 ostream << "ShadowRootType::Open";
393 break; 332 break;
394 case ShadowRootType::Closed: 333 case ShadowRootType::Closed:
395 ostream << "ShadowRootType::Closed"; 334 ostream << "ShadowRootType::Closed";
396 break; 335 break;
397 } 336 }
398 return ostream; 337 return ostream;
399 } 338 }
400 339
401 } // namespace blink 340 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698