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

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

Issue 2354773003: Make stylesheet owner node a reference instead of pointer. (Closed)
Patch Set: const Created 4 years, 3 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) 118 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features)
119 { 119 {
120 m_usesSiblingRules = features.usesSiblingRules(); 120 m_usesSiblingRules = features.usesSiblingRules();
121 m_usesFirstLineRules = features.usesFirstLineRules(); 121 m_usesFirstLineRules = features.usesFirstLineRules();
122 m_usesWindowInactiveSelector = features.usesWindowInactiveSelector(); 122 m_usesWindowInactiveSelector = features.usesWindowInactiveSelector();
123 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors(); 123 m_maxDirectAdjacentSelectors = features.maxDirectAdjacentSelectors();
124 } 124 }
125 125
126 void StyleEngine::injectAuthorSheet(StyleSheetContents* authorSheet) 126 void StyleEngine::injectAuthorSheet(StyleSheetContents* authorSheet)
127 { 127 {
128 m_injectedAuthorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_docu ment)); 128 m_injectedAuthorStyleSheets.append(CSSStyleSheet::create(authorSheet, *m_doc ument));
129 markDocumentDirty(); 129 markDocumentDirty();
130 resolverChanged(AnalyzedStyleUpdate); 130 resolverChanged(AnalyzedStyleUpdate);
131 } 131 }
132 132
133 CSSStyleSheet& StyleEngine::ensureInspectorStyleSheet() 133 CSSStyleSheet& StyleEngine::ensureInspectorStyleSheet()
134 { 134 {
135 if (m_inspectorStyleSheet) 135 if (m_inspectorStyleSheet)
136 return *m_inspectorStyleSheet; 136 return *m_inspectorStyleSheet;
137 137
138 StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(* m_document, nullptr)); 138 StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(* m_document, nullptr));
139 m_inspectorStyleSheet = CSSStyleSheet::create(contents, m_document); 139 m_inspectorStyleSheet = CSSStyleSheet::create(contents, *m_document);
140 markDocumentDirty(); 140 markDocumentDirty();
141 resolverChanged(AnalyzedStyleUpdate); 141 resolverChanged(AnalyzedStyleUpdate);
142 return *m_inspectorStyleSheet; 142 return *m_inspectorStyleSheet;
143 } 143 }
144 144
145 void StyleEngine::addPendingSheet(StyleEngineContext &context) 145 void StyleEngine::addPendingSheet(StyleEngineContext &context)
146 { 146 {
147 m_pendingScriptBlockingStylesheets++; 147 m_pendingScriptBlockingStylesheets++;
148 148
149 context.addingPendingSheet(document()); 149 context.addingPendingSheet(document());
150 if (context.addedPendingSheetBeforeBody()) 150 if (context.addedPendingSheetBeforeBody())
151 m_pendingRenderBlockingStylesheets++; 151 m_pendingRenderBlockingStylesheets++;
152 } 152 }
153 153
154 // This method is called whenever a top-level stylesheet has finished loading. 154 // This method is called whenever a top-level stylesheet has finished loading.
155 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, const StyleE ngineContext &context) 155 void StyleEngine::removePendingSheet(Node& styleSheetCandidateNode, const StyleE ngineContext &context)
156 { 156 {
157 DCHECK(styleSheetCandidateNode); 157 TreeScope* treeScope = isStyleElement(styleSheetCandidateNode) ? &styleSheet CandidateNode.treeScope() : m_document.get();
158 TreeScope* treeScope = isStyleElement(*styleSheetCandidateNode) ? &styleShee tCandidateNode->treeScope() : m_document.get(); 158 if (styleSheetCandidateNode.isConnected())
159 if (styleSheetCandidateNode->isConnected())
160 markTreeScopeDirty(*treeScope); 159 markTreeScopeDirty(*treeScope);
161 160
162 if (context.addedPendingSheetBeforeBody()) { 161 if (context.addedPendingSheetBeforeBody()) {
163 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0); 162 DCHECK_GT(m_pendingRenderBlockingStylesheets, 0);
164 m_pendingRenderBlockingStylesheets--; 163 m_pendingRenderBlockingStylesheets--;
165 } 164 }
166 165
167 // Make sure we knew this sheet was pending, and that our count isn't out of sync. 166 // Make sure we knew this sheet was pending, and that our count isn't out of sync.
168 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0); 167 DCHECK_GT(m_pendingScriptBlockingStylesheets, 0);
169 168
(...skipping 18 matching lines...) Expand all
188 if (node && node->isConnected()) { 187 if (node && node->isConnected()) {
189 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : * m_document; 188 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : * m_document;
190 DCHECK(isStyleElement(*node) || node->treeScope() == m_document); 189 DCHECK(isStyleElement(*node) || node->treeScope() == m_document);
191 markTreeScopeDirty(treeScope); 190 markTreeScopeDirty(treeScope);
192 } 191 }
193 } 192 }
194 193
195 resolverChanged(updateMode); 194 resolverChanged(updateMode);
196 } 195 }
197 196
198 void StyleEngine::addStyleSheetCandidateNode(Node* node) 197 void StyleEngine::addStyleSheetCandidateNode(Node& node)
199 { 198 {
200 if (!node->isConnected() || document().isDetached()) 199 if (!node.isConnected() || document().isDetached())
201 return; 200 return;
202 201
203 DCHECK(!isXSLStyleSheet(*node)); 202 DCHECK(!isXSLStyleSheet(node));
204 TreeScope& treeScope = node->treeScope(); 203 TreeScope& treeScope = node.treeScope();
205 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope); 204 TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(tr eeScope);
206 DCHECK(collection); 205 DCHECK(collection);
207 collection->addStyleSheetCandidateNode(node); 206 collection->addStyleSheetCandidateNode(node);
208 207
209 markTreeScopeDirty(treeScope); 208 markTreeScopeDirty(treeScope);
210 if (treeScope != m_document) 209 if (treeScope != m_document)
211 m_activeTreeScopes.add(&treeScope); 210 m_activeTreeScopes.add(&treeScope);
212 } 211 }
213 212
214 void StyleEngine::removeStyleSheetCandidateNode(Node* node) 213 void StyleEngine::removeStyleSheetCandidateNode(Node& node)
215 { 214 {
216 removeStyleSheetCandidateNode(node, *m_document); 215 removeStyleSheetCandidateNode(node, *m_document);
217 } 216 }
218 217
219 void StyleEngine::removeStyleSheetCandidateNode(Node* node, TreeScope& treeScope ) 218 void StyleEngine::removeStyleSheetCandidateNode(Node& node, TreeScope& treeScope )
220 { 219 {
221 DCHECK(isStyleElement(*node) || treeScope == m_document); 220 DCHECK(isStyleElement(node) || treeScope == m_document);
222 DCHECK(!isXSLStyleSheet(*node)); 221 DCHECK(!isXSLStyleSheet(node));
223 222
224 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e); 223 TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScop e);
225 // After detaching document, collection could be null. In the case, 224 // After detaching document, collection could be null. In the case,
226 // we should not update anything. Instead, just return. 225 // we should not update anything. Instead, just return.
227 if (!collection) 226 if (!collection)
228 return; 227 return;
229 collection->removeStyleSheetCandidateNode(node); 228 collection->removeStyleSheetCandidateNode(node);
230 229
231 markTreeScopeDirty(treeScope); 230 markTreeScopeDirty(treeScope);
232 } 231 }
233 232
234 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node) 233 void StyleEngine::modifiedStyleSheetCandidateNode(Node& node)
235 { 234 {
236 if (!node->isConnected()) 235 if (!node.isConnected())
237 return; 236 return;
238 237
239 TreeScope& treeScope = isStyleElement(*node) ? node->treeScope() : *m_docume nt; 238 TreeScope& treeScope = isStyleElement(node) ? node.treeScope() : *m_document ;
240 DCHECK(isStyleElement(*node) || treeScope == m_document); 239 DCHECK(isStyleElement(node) || treeScope == m_document);
241 markTreeScopeDirty(treeScope); 240 markTreeScopeDirty(treeScope);
242 resolverChanged(AnalyzedStyleUpdate); 241 resolverChanged(AnalyzedStyleUpdate);
243 } 242 }
244 243
245 void StyleEngine::watchedSelectorsChanged() 244 void StyleEngine::watchedSelectorsChanged()
246 { 245 {
247 if (m_resolver) { 246 if (m_resolver) {
248 m_resolver->initWatchedSelectorRules(); 247 m_resolver->initWatchedSelectorRules();
249 m_resolver->resetRuleFeatures(); 248 m_resolver->resetRuleFeatures();
250 } 249 }
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 m_dirtyTreeScopes.add(&scope); 497 m_dirtyTreeScopes.add(&scope);
499 } 498 }
500 499
501 void StyleEngine::markDocumentDirty() 500 void StyleEngine::markDocumentDirty()
502 { 501 {
503 m_documentScopeDirty = true; 502 m_documentScopeDirty = true;
504 if (document().importLoader()) 503 if (document().importLoader())
505 document().importsController()->master()->styleEngine().markDocumentDirt y(); 504 document().importsController()->master()->styleEngine().markDocumentDirt y();
506 } 505 }
507 506
508 CSSStyleSheet* StyleEngine::createSheet(Element* e, const String& text, TextPosi tion startPosition, StyleEngineContext &context) 507 CSSStyleSheet* StyleEngine::createSheet(Element& element, const String& text, Te xtPosition startPosition, StyleEngineContext &context)
509 { 508 {
509 DCHECK(element.document() == document());
510 CSSStyleSheet* styleSheet = nullptr; 510 CSSStyleSheet* styleSheet = nullptr;
511 511
512 e->document().styleEngine().addPendingSheet(context); 512 addPendingSheet(context);
513 513
514 AtomicString textContent(text); 514 AtomicString textContent(text);
515 515
516 auto result = m_textToSheetCache.add(textContent, nullptr); 516 auto result = m_textToSheetCache.add(textContent, nullptr);
517 StyleSheetContents* contents = result.storedValue->value; 517 StyleSheetContents* contents = result.storedValue->value;
518 if (result.isNewEntry || !contents || !contents->isCacheableForStyleElement( )) { 518 if (result.isNewEntry || !contents || !contents->isCacheableForStyleElement( )) {
519 result.storedValue->value = nullptr; 519 result.storedValue->value = nullptr;
520 styleSheet = StyleEngine::parseSheet(e, text, startPosition); 520 styleSheet = parseSheet(element, text, startPosition);
521 if (styleSheet->contents()->isCacheableForStyleElement()) { 521 if (styleSheet->contents()->isCacheableForStyleElement()) {
522 result.storedValue->value = styleSheet->contents(); 522 result.storedValue->value = styleSheet->contents();
523 m_sheetToTextCache.add(styleSheet->contents(), textContent); 523 m_sheetToTextCache.add(styleSheet->contents(), textContent);
524 } 524 }
525 } else { 525 } else {
526 DCHECK(contents); 526 DCHECK(contents);
527 DCHECK(contents->isCacheableForStyleElement()); 527 DCHECK(contents->isCacheableForStyleElement());
528 DCHECK(contents->hasSingleOwnerDocument()); 528 DCHECK(contents->hasSingleOwnerDocument());
529 contents->setIsUsedFromTextCache(); 529 contents->setIsUsedFromTextCache();
530 styleSheet = CSSStyleSheet::createInline(contents, e, startPosition); 530 styleSheet = CSSStyleSheet::createInline(contents, element, startPositio n);
531 } 531 }
532 532
533 DCHECK(styleSheet); 533 DCHECK(styleSheet);
534 if (!e->isInShadowTree()) { 534 if (!element.isInShadowTree()) {
535 styleSheet->setTitle(e->title()); 535 styleSheet->setTitle(element.title());
536 setPreferredStylesheetSetNameIfNotSet(e->title(), DontUpdateActiveSheets ); 536 setPreferredStylesheetSetNameIfNotSet(element.title(), DontUpdateActiveS heets);
537 } 537 }
538 return styleSheet; 538 return styleSheet;
539 } 539 }
540 540
541 CSSStyleSheet* StyleEngine::parseSheet(Element* e, const String& text, TextPosit ion startPosition) 541 CSSStyleSheet* StyleEngine::parseSheet(Element& element, const String& text, Tex tPosition startPosition)
542 { 542 {
543 CSSStyleSheet* styleSheet = nullptr; 543 CSSStyleSheet* styleSheet = nullptr;
544 styleSheet = CSSStyleSheet::createInline(e, KURL(), startPosition, e->docume nt().characterSet()); 544 styleSheet = CSSStyleSheet::createInline(element, KURL(), startPosition, doc ument().characterSet());
545 styleSheet->contents()->parseStringAtPosition(text, startPosition); 545 styleSheet->contents()->parseStringAtPosition(text, startPosition);
546 return styleSheet; 546 return styleSheet;
547 } 547 }
548 548
549 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const 549 void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
550 { 550 {
551 HeapHashSet<Member<const StyleSheetContents>> visitedSharedStyleSheetContent s; 551 HeapHashSet<Member<const StyleSheetContents>> visitedSharedStyleSheetContent s;
552 if (document().scopedStyleResolver()) 552 if (document().scopedStyleResolver())
553 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents); 553 document().scopedStyleResolver()->collectFeaturesTo(features, visitedSha redStyleSheetContents);
554 for (TreeScope* treeScope : m_activeTreeScopes) { 554 for (TreeScope* treeScope : m_activeTreeScopes) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 836
837 DEFINE_TRACE_WRAPPERS(StyleEngine) 837 DEFINE_TRACE_WRAPPERS(StyleEngine)
838 { 838 {
839 for (auto sheet : m_injectedAuthorStyleSheets) { 839 for (auto sheet : m_injectedAuthorStyleSheets) {
840 visitor->traceWrappers(sheet); 840 visitor->traceWrappers(sheet);
841 } 841 }
842 visitor->traceWrappers(m_documentStyleSheetCollection); 842 visitor->traceWrappers(m_documentStyleSheetCollection);
843 } 843 }
844 844
845 } // namespace blink 845 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.h ('k') | third_party/WebKit/Source/core/dom/StyleEngineTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698