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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 2630293003: Do not allocate SlotAssignment unless a shadowroot has a slot (Closed)
Patch Set: renamed Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 node->lazyReattachIfAttached(); 197 node->lazyReattachIfAttached();
198 } 198 }
199 HTMLElement::detachLayoutTree(context); 199 HTMLElement::detachLayoutTree(context);
200 } 200 }
201 201
202 void HTMLSlotElement::attributeChanged( 202 void HTMLSlotElement::attributeChanged(
203 const AttributeModificationParams& params) { 203 const AttributeModificationParams& params) {
204 if (params.name == nameAttr) { 204 if (params.name == nameAttr) {
205 if (ShadowRoot* root = containingShadowRoot()) { 205 if (ShadowRoot* root = containingShadowRoot()) {
206 if (root->isV1() && params.oldValue != params.newValue) { 206 if (root->isV1() && params.oldValue != params.newValue) {
207 root->ensureSlotAssignment().slotRenamed( 207 root->slotAssignment().slotRenamed(normalizeSlotName(params.oldValue),
208 normalizeSlotName(params.oldValue), *this); 208 *this);
209 } 209 }
210 } 210 }
211 } 211 }
212 HTMLElement::attributeChanged(params); 212 HTMLElement::attributeChanged(params);
213 } 213 }
214 214
215 static bool wasInShadowTreeBeforeInserted(HTMLSlotElement& slot, 215 static bool wasInShadowTreeBeforeInserted(HTMLSlotElement& slot,
216 ContainerNode& insertionPoint) { 216 ContainerNode& insertionPoint) {
217 ShadowRoot* root1 = slot.containingShadowRoot(); 217 ShadowRoot* root1 = slot.containingShadowRoot();
218 ShadowRoot* root2 = insertionPoint.containingShadowRoot(); 218 ShadowRoot* root2 = insertionPoint.containingShadowRoot();
219 if (root1 && root2 && root1 == root2) 219 if (root1 && root2 && root1 == root2)
220 return false; 220 return false;
221 return root1; 221 return root1;
222 } 222 }
223 223
224 Node::InsertionNotificationRequest HTMLSlotElement::insertedInto( 224 Node::InsertionNotificationRequest HTMLSlotElement::insertedInto(
225 ContainerNode* insertionPoint) { 225 ContainerNode* insertionPoint) {
226 HTMLElement::insertedInto(insertionPoint); 226 HTMLElement::insertedInto(insertionPoint);
227 ShadowRoot* root = containingShadowRoot(); 227 ShadowRoot* root = containingShadowRoot();
228 if (root) { 228 if (root) {
229 DCHECK(root->owner()); 229 DCHECK(root->owner());
230 root->owner()->setNeedsDistributionRecalc(); 230 root->owner()->setNeedsDistributionRecalc();
231 // Relevant DOM Standard: https://dom.spec.whatwg.org/#concept-node-insert 231 // Relevant DOM Standard: https://dom.spec.whatwg.org/#concept-node-insert
232 // - 6.4: Run assign slotables for a tree with node's tree and a set 232 // - 6.4: Run assign slotables for a tree with node's tree and a set
233 // containing each inclusive descendant of node that is a slot. 233 // containing each inclusive descendant of node that is a slot.
234 if (root->isV1() && !wasInShadowTreeBeforeInserted(*this, *insertionPoint)) 234 if (root->isV1() && !wasInShadowTreeBeforeInserted(*this, *insertionPoint))
235 root->ensureSlotAssignment().slotAdded(*this); 235 root->didAddSlot(*this);
236 } 236 }
237 237
238 // We could have been distributed into in a detached subtree, make sure to 238 // We could have been distributed into in a detached subtree, make sure to
239 // clear the distribution when inserted again to avoid cycles. 239 // clear the distribution when inserted again to avoid cycles.
240 clearDistribution(); 240 clearDistribution();
241 241
242 return InsertionDone; 242 return InsertionDone;
243 } 243 }
244 244
245 static ShadowRoot* containingShadowRootBeforeRemoved( 245 static ShadowRoot* containingShadowRootBeforeRemoved(
(...skipping 19 matching lines...) Expand all
265 if (ElementShadow* rootOwner = root->owner()) 265 if (ElementShadow* rootOwner = root->owner())
266 rootOwner->setNeedsDistributionRecalc(); 266 rootOwner->setNeedsDistributionRecalc();
267 } 267 }
268 268
269 // Since this insertion point is no longer visible from the shadow subtree, it 269 // Since this insertion point is no longer visible from the shadow subtree, it
270 // need to clean itself up. 270 // need to clean itself up.
271 clearDistribution(); 271 clearDistribution();
272 272
273 if (root && root->isV1() && root == insertionPoint->treeScope().rootNode()) { 273 if (root && root->isV1() && root == insertionPoint->treeScope().rootNode()) {
274 // This slot was in a shadow tree and got disconnected from the shadow root. 274 // This slot was in a shadow tree and got disconnected from the shadow root.
275 root->ensureSlotAssignment().slotRemoved(*this); 275 root->slotAssignment().slotRemoved(*this);
276 } 276 }
277 277
278 HTMLElement::removedFrom(insertionPoint); 278 HTMLElement::removedFrom(insertionPoint);
279 } 279 }
280 280
281 void HTMLSlotElement::willRecalcStyle(StyleRecalcChange change) { 281 void HTMLSlotElement::willRecalcStyle(StyleRecalcChange change) {
282 if (change < IndependentInherit && getStyleChangeType() < SubtreeStyleChange) 282 if (change < IndependentInherit && getStyleChangeType() < SubtreeStyleChange)
283 return; 283 return;
284 284
285 for (auto& node : m_distributedNodes) 285 for (auto& node : m_distributedNodes)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return; 333 return;
334 Microtask::enqueueMicrotask(WTF::bind( 334 Microtask::enqueueMicrotask(WTF::bind(
335 &HTMLSlotElement::dispatchSlotChangeEvent, wrapPersistent(this))); 335 &HTMLSlotElement::dispatchSlotChangeEvent, wrapPersistent(this)));
336 m_slotchangeEventEnqueued = true; 336 m_slotchangeEventEnqueued = true;
337 } 337 }
338 338
339 bool HTMLSlotElement::hasAssignedNodesSlow() const { 339 bool HTMLSlotElement::hasAssignedNodesSlow() const {
340 ShadowRoot* root = containingShadowRoot(); 340 ShadowRoot* root = containingShadowRoot();
341 DCHECK(root); 341 DCHECK(root);
342 DCHECK(root->isV1()); 342 DCHECK(root->isV1());
343 SlotAssignment& assignment = root->ensureSlotAssignment(); 343 SlotAssignment& assignment = root->slotAssignment();
344 if (assignment.findSlotByName(name()) != this) 344 if (assignment.findSlotByName(name()) != this)
345 return false; 345 return false;
346 return assignment.findHostChildBySlotName(name()); 346 return assignment.findHostChildBySlotName(name());
347 } 347 }
348 348
349 bool HTMLSlotElement::findHostChildWithSameSlotName() const { 349 bool HTMLSlotElement::findHostChildWithSameSlotName() const {
350 ShadowRoot* root = containingShadowRoot(); 350 ShadowRoot* root = containingShadowRoot();
351 DCHECK(root); 351 DCHECK(root);
352 DCHECK(root->isV1()); 352 DCHECK(root->isV1());
353 SlotAssignment& assignment = root->ensureSlotAssignment(); 353 SlotAssignment& assignment = root->slotAssignment();
354 return assignment.findHostChildBySlotName(name()); 354 return assignment.findHostChildBySlotName(name());
355 } 355 }
356 356
357 int HTMLSlotElement::tabIndex() const { 357 int HTMLSlotElement::tabIndex() const {
358 return Element::tabIndex(); 358 return Element::tabIndex();
359 } 359 }
360 360
361 DEFINE_TRACE(HTMLSlotElement) { 361 DEFINE_TRACE(HTMLSlotElement) {
362 visitor->trace(m_assignedNodes); 362 visitor->trace(m_assignedNodes);
363 visitor->trace(m_distributedNodes); 363 visitor->trace(m_distributedNodes);
364 visitor->trace(m_oldDistributedNodes); 364 visitor->trace(m_oldDistributedNodes);
365 visitor->trace(m_distributedIndices); 365 visitor->trace(m_distributedIndices);
366 HTMLElement::trace(visitor); 366 HTMLElement::trace(visitor);
367 } 367 }
368 368
369 } // namespace blink 369 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/shadow/SlotAssignment.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698