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

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

Issue 1904923002: Reduce a shadow root object's size by not inheriting DoublyLinkedList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@raredatav0
Patch Set: fix typo Created 4 years, 8 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 25 matching lines...) Expand all
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" 38 #include "core/dom/shadow/ShadowRootRareData.h"
39 #include "core/dom/shadow/ShadowRootRareDataV0.h" 39 #include "core/dom/shadow/ShadowRootRareDataV0.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 "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> { 46 struct SameSizeAsShadowRoot : public DocumentFragment, public TreeScope {
47 char emptyClassFieldsDueToGCMixinMarker[1]; 47 char emptyClassFieldsDueToGCMixinMarker[1];
48 Member<void*> willbeMember[5]; 48 Member<void*> willbeMember[3];
49 unsigned countersAndFlags[1]; 49 unsigned countersAndFlags[1];
50 }; 50 };
51 51
52 static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "ShadowRoot sh ould stay small"); 52 static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "ShadowRoot sh ould stay small");
53 53
54 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type) 54 ShadowRoot::ShadowRoot(Document& document, ShadowRootType type)
55 : DocumentFragment(0, CreateShadowRoot) 55 : DocumentFragment(0, CreateShadowRoot)
56 , TreeScope(*this, document) 56 , TreeScope(*this, document)
57 , m_prev(nullptr)
58 , m_next(nullptr)
59 , m_slotAssignment(nullptr)
60 , m_numberOfStyles(0) 57 , m_numberOfStyles(0)
61 , m_type(static_cast<unsigned>(type)) 58 , m_type(static_cast<unsigned>(type))
62 , m_registeredWithParentShadowRoot(false) 59 , m_registeredWithParentShadowRoot(false)
63 , m_descendantInsertionPointsIsValid(false) 60 , m_descendantInsertionPointsIsValid(false)
64 , m_delegatesFocus(false) 61 , m_delegatesFocus(false)
65 , m_descendantSlotsIsValid(false) 62 , m_descendantSlotsIsValid(false)
66 { 63 {
67 } 64 }
68 65
69 ShadowRoot::~ShadowRoot() 66 ShadowRoot::~ShadowRoot()
70 { 67 {
71 } 68 }
72 69
70 ShadowRoot* ShadowRoot::youngerShadowRoot() const
71 {
72 if (type() == ShadowRootType::V0 && m_shadowRootRareDataV0)
73 return m_shadowRootRareDataV0->youngerShadowRoot();
74 return nullptr;
75 }
76
77 ShadowRoot* ShadowRoot::olderShadowRoot() const
78 {
79 if (type() == ShadowRootType::V0 && m_shadowRootRareDataV0)
80 return m_shadowRootRareDataV0->olderShadowRoot();
81 return nullptr;
82 }
83
73 ShadowRoot* ShadowRoot::olderShadowRootForBindings() const 84 ShadowRoot* ShadowRoot::olderShadowRootForBindings() const
74 { 85 {
75 ShadowRoot* older = olderShadowRoot(); 86 ShadowRoot* older = olderShadowRoot();
76 while (older && !older->isOpenOrV0()) 87 while (older && !older->isOpenOrV0())
77 older = older->olderShadowRoot(); 88 older = older->olderShadowRoot();
78 DCHECK(!older || older->isOpenOrV0()); 89 DCHECK(!older || older->isOpenOrV0());
79 return older; 90 return older;
80 } 91 }
81 92
93 void ShadowRoot::setYoungerShadowRoot(ShadowRoot& root)
94 {
95 DCHECK_EQ(type(), ShadowRootType::V0);
96 ensureShadowRootRareDataV0().setYoungerShadowRoot(root);
97 }
98
99 void ShadowRoot::setOlderShadowRoot(ShadowRoot& root)
100 {
101 DCHECK_EQ(type(), ShadowRootType::V0);
102 ensureShadowRootRareDataV0().setOlderShadowRoot(root);
103 }
104
82 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState) 105 Node* ShadowRoot::cloneNode(bool, ExceptionState& exceptionState)
83 { 106 {
84 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no t clonable."); 107 exceptionState.throwDOMException(NotSupportedError, "ShadowRoot nodes are no t clonable.");
85 return nullptr; 108 return nullptr;
86 } 109 }
87 110
88 String ShadowRoot::innerHTML() const 111 String ShadowRoot::innerHTML() const
89 { 112 {
90 return createMarkup(this, ChildrenOnly); 113 return createMarkup(this, ChildrenOnly);
91 } 114 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 { 202 {
180 ++m_numberOfStyles; 203 ++m_numberOfStyles;
181 } 204 }
182 205
183 void ShadowRoot::unregisterScopedHTMLStyleChild() 206 void ShadowRoot::unregisterScopedHTMLStyleChild()
184 { 207 {
185 DCHECK_GT(m_numberOfStyles, 0u); 208 DCHECK_GT(m_numberOfStyles, 0u);
186 --m_numberOfStyles; 209 --m_numberOfStyles;
187 } 210 }
188 211
189 ShadowRootRareData* ShadowRoot::ensureShadowRootRareData() 212 ShadowRootRareData& ShadowRoot::ensureShadowRootRareData()
190 { 213 {
191 if (m_shadowRootRareData) 214 if (m_shadowRootRareData)
192 return m_shadowRootRareData.get(); 215 return *m_shadowRootRareData;
193 216
194 m_shadowRootRareData = new ShadowRootRareData; 217 m_shadowRootRareData = new ShadowRootRareData;
195 return m_shadowRootRareData.get(); 218 return *m_shadowRootRareData;
196 } 219 }
197 220
198 ShadowRootRareDataV0* ShadowRoot::ensureShadowRootRareDataV0() 221 ShadowRootRareDataV0& ShadowRoot::ensureShadowRootRareDataV0()
199 { 222 {
200 if (m_shadowRootRareDataV0) 223 if (m_shadowRootRareDataV0)
201 return m_shadowRootRareDataV0.get(); 224 return *m_shadowRootRareDataV0;
202 225
203 m_shadowRootRareDataV0 = new ShadowRootRareDataV0; 226 m_shadowRootRareDataV0 = new ShadowRootRareDataV0;
204 return m_shadowRootRareDataV0.get(); 227 return *m_shadowRootRareDataV0;
205 } 228 }
206 229
207 bool ShadowRoot::containsShadowElements() const 230 bool ShadowRoot::containsShadowElements() const
208 { 231 {
209 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen ts() : false; 232 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsShadowElemen ts() : false;
210 } 233 }
211 234
212 bool ShadowRoot::containsContentElements() const 235 bool ShadowRoot::containsContentElements() const
213 { 236 {
214 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme nts() : false; 237 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->containsContentEleme nts() : false;
(...skipping 11 matching lines...) Expand all
226 249
227 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const 250 HTMLShadowElement* ShadowRoot::shadowInsertionPointOfYoungerShadowRoot() const
228 { 251 {
229 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint OfYoungerShadowRoot() : nullptr; 252 return m_shadowRootRareDataV0 ? m_shadowRootRareDataV0->shadowInsertionPoint OfYoungerShadowRoot() : nullptr;
230 } 253 }
231 254
232 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s hadowInsertionPoint) 255 void ShadowRoot::setShadowInsertionPointOfYoungerShadowRoot(HTMLShadowElement* s hadowInsertionPoint)
233 { 256 {
234 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint) 257 if (!m_shadowRootRareDataV0 && !shadowInsertionPoint)
235 return; 258 return;
236 ensureShadowRootRareDataV0()->setShadowInsertionPointOfYoungerShadowRoot(sha dowInsertionPoint); 259 ensureShadowRootRareDataV0().setShadowInsertionPointOfYoungerShadowRoot(shad owInsertionPoint);
237 } 260 }
238 261
239 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint) 262 void ShadowRoot::didAddInsertionPoint(InsertionPoint* insertionPoint)
240 { 263 {
241 ensureShadowRootRareDataV0()->didAddInsertionPoint(insertionPoint); 264 ensureShadowRootRareDataV0().didAddInsertionPoint(insertionPoint);
242 invalidateDescendantInsertionPoints(); 265 invalidateDescendantInsertionPoints();
243 } 266 }
244 267
245 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint) 268 void ShadowRoot::didRemoveInsertionPoint(InsertionPoint* insertionPoint)
246 { 269 {
247 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint); 270 m_shadowRootRareDataV0->didRemoveInsertionPoint(insertionPoint);
248 invalidateDescendantInsertionPoints(); 271 invalidateDescendantInsertionPoints();
249 } 272 }
250 273
251 void ShadowRoot::addChildShadowRoot() 274 void ShadowRoot::addChildShadowRoot()
252 { 275 {
253 ensureShadowRootRareData()->didAddChildShadowRoot(); 276 ensureShadowRootRareData().didAddChildShadowRoot();
254 } 277 }
255 278
256 void ShadowRoot::removeChildShadowRoot() 279 void ShadowRoot::removeChildShadowRoot()
257 { 280 {
258 // FIXME: Why isn't this an ASSERT? 281 // FIXME: Why isn't this an ASSERT?
259 if (!m_shadowRootRareData) 282 if (!m_shadowRootRareData)
260 return; 283 return;
261 m_shadowRootRareData->didRemoveChildShadowRoot(); 284 m_shadowRootRareData->didRemoveChildShadowRoot();
262 } 285 }
263 286
(...skipping 16 matching lines...) Expand all
280 303
281 m_descendantInsertionPointsIsValid = true; 304 m_descendantInsertionPointsIsValid = true;
282 305
283 if (!containsInsertionPoints()) 306 if (!containsInsertionPoints())
284 return emptyList; 307 return emptyList;
285 308
286 HeapVector<Member<InsertionPoint>> insertionPoints; 309 HeapVector<Member<InsertionPoint>> insertionPoints;
287 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants Of(*this)) 310 for (InsertionPoint& insertionPoint : Traversal<InsertionPoint>::descendants Of(*this))
288 insertionPoints.append(&insertionPoint); 311 insertionPoints.append(&insertionPoint);
289 312
290 ensureShadowRootRareDataV0()->setDescendantInsertionPoints(insertionPoints); 313 ensureShadowRootRareDataV0().setDescendantInsertionPoints(insertionPoints);
291 314
292 return m_shadowRootRareDataV0->descendantInsertionPoints(); 315 return m_shadowRootRareDataV0->descendantInsertionPoints();
293 } 316 }
294 317
295 StyleSheetList* ShadowRoot::styleSheets() 318 StyleSheetList* ShadowRoot::styleSheets()
296 { 319 {
297 if (!ensureShadowRootRareData()->styleSheets()) 320 if (!ensureShadowRootRareData().styleSheets())
298 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this)); 321 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this));
299 322
300 return m_shadowRootRareData->styleSheets(); 323 return m_shadowRootRareData->styleSheets();
301 } 324 }
302 325
303 void ShadowRoot::didAddSlot() 326 void ShadowRoot::didAddSlot()
304 { 327 {
305 ensureShadowRootRareData()->didAddSlot(); 328 ensureShadowRootRareData().didAddSlot();
306 invalidateDescendantSlots(); 329 invalidateDescendantSlots();
307 } 330 }
308 331
309 void ShadowRoot::didRemoveSlot() 332 void ShadowRoot::didRemoveSlot()
310 { 333 {
311 DCHECK(m_shadowRootRareData); 334 DCHECK(m_shadowRootRareData);
312 m_shadowRootRareData->didRemoveSlot(); 335 m_shadowRootRareData->didRemoveSlot();
313 invalidateDescendantSlots(); 336 invalidateDescendantSlots();
314 } 337 }
315 338
(...skipping 30 matching lines...) Expand all
346 369
347 void ShadowRoot::distributeV1() 370 void ShadowRoot::distributeV1()
348 { 371 {
349 if (!m_slotAssignment) 372 if (!m_slotAssignment)
350 m_slotAssignment = SlotAssignment::create(); 373 m_slotAssignment = SlotAssignment::create();
351 m_slotAssignment->resolveAssignment(*this); 374 m_slotAssignment->resolveAssignment(*this);
352 } 375 }
353 376
354 DEFINE_TRACE(ShadowRoot) 377 DEFINE_TRACE(ShadowRoot)
355 { 378 {
356 visitor->trace(m_prev);
357 visitor->trace(m_next);
358 visitor->trace(m_shadowRootRareData); 379 visitor->trace(m_shadowRootRareData);
359 visitor->trace(m_shadowRootRareDataV0); 380 visitor->trace(m_shadowRootRareDataV0);
360 visitor->trace(m_slotAssignment); 381 visitor->trace(m_slotAssignment);
361 TreeScope::trace(visitor); 382 TreeScope::trace(visitor);
362 DocumentFragment::trace(visitor); 383 DocumentFragment::trace(visitor);
363 } 384 }
364 385
365 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type) 386 std::ostream& operator<<(std::ostream& ostream, const ShadowRootType& type)
366 { 387 {
367 switch (type) { 388 switch (type) {
368 case ShadowRootType::UserAgent: 389 case ShadowRootType::UserAgent:
369 ostream << "ShadowRootType::UserAgent"; 390 ostream << "ShadowRootType::UserAgent";
370 break; 391 break;
371 case ShadowRootType::V0: 392 case ShadowRootType::V0:
372 ostream << "ShadowRootType::V0"; 393 ostream << "ShadowRootType::V0";
373 break; 394 break;
374 case ShadowRootType::Open: 395 case ShadowRootType::Open:
375 ostream << "ShadowRootType::Open"; 396 ostream << "ShadowRootType::Open";
376 break; 397 break;
377 case ShadowRootType::Closed: 398 case ShadowRootType::Closed:
378 ostream << "ShadowRootType::Closed"; 399 ostream << "ShadowRootType::Closed";
379 break; 400 break;
380 } 401 }
381 return ostream; 402 return ostream;
382 } 403 }
383 404
384 } // namespace blink 405 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698