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

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

Issue 2884993002: Don't trigger full active style update on styleSheets access. (Closed)
Patch Set: Not clearing document_scope_dirty_ flag in import styleSheets anymore. Created 3 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) 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 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 inline Document* StyleEngine::Master() { 87 inline Document* StyleEngine::Master() {
88 if (IsMaster()) 88 if (IsMaster())
89 return document_; 89 return document_;
90 HTMLImportsController* import = GetDocument().ImportsController(); 90 HTMLImportsController* import = GetDocument().ImportsController();
91 // Document::import() can return null while executing its destructor. 91 // Document::import() can return null while executing its destructor.
92 if (!import) 92 if (!import)
93 return nullptr; 93 return nullptr;
94 return import->Master(); 94 return import->Master();
95 } 95 }
96 96
97 TreeScopeStyleSheetCollection* StyleEngine::EnsureStyleSheetCollectionFor( 97 TreeScopeStyleSheetCollection& StyleEngine::EnsureStyleSheetCollectionFor(
98 TreeScope& tree_scope) { 98 TreeScope& tree_scope) {
99 if (tree_scope == document_) 99 if (tree_scope == document_)
100 return &GetDocumentStyleSheetCollection(); 100 return GetDocumentStyleSheetCollection();
101 101
102 StyleSheetCollectionMap::AddResult result = 102 StyleSheetCollectionMap::AddResult result =
103 style_sheet_collection_map_.insert(&tree_scope, nullptr); 103 style_sheet_collection_map_.insert(&tree_scope, nullptr);
104 if (result.is_new_entry) 104 if (result.is_new_entry)
105 result.stored_value->value = 105 result.stored_value->value =
106 new ShadowTreeStyleSheetCollection(ToShadowRoot(tree_scope)); 106 new ShadowTreeStyleSheetCollection(ToShadowRoot(tree_scope));
107 return result.stored_value->value.Get(); 107 return *result.stored_value->value.Get();
108 } 108 }
109 109
110 TreeScopeStyleSheetCollection* StyleEngine::StyleSheetCollectionFor( 110 TreeScopeStyleSheetCollection* StyleEngine::StyleSheetCollectionFor(
111 TreeScope& tree_scope) { 111 TreeScope& tree_scope) {
112 if (tree_scope == document_) 112 if (tree_scope == document_)
113 return &GetDocumentStyleSheetCollection(); 113 return &GetDocumentStyleSheetCollection();
114 114
115 StyleSheetCollectionMap::iterator it = 115 StyleSheetCollectionMap::iterator it =
116 style_sheet_collection_map_.find(&tree_scope); 116 style_sheet_collection_map_.find(&tree_scope);
117 if (it == style_sheet_collection_map_.end()) 117 if (it == style_sheet_collection_map_.end())
118 return nullptr; 118 return nullptr;
119 return it->value.Get(); 119 return it->value.Get();
120 } 120 }
121 121
122 const HeapVector<TraceWrapperMember<StyleSheet>>& 122 const HeapVector<TraceWrapperMember<StyleSheet>>&
123 StyleEngine::StyleSheetsForStyleSheetList(TreeScope& tree_scope) { 123 StyleEngine::StyleSheetsForStyleSheetList(TreeScope& tree_scope) {
124 DCHECK(Master()); 124 DCHECK(Master());
125 TreeScopeStyleSheetCollection& collection =
126 EnsureStyleSheetCollectionFor(tree_scope);
125 if (Master()->IsActive()) { 127 if (Master()->IsActive()) {
126 if (IsMaster()) { 128 if (all_tree_scopes_dirty_) {
127 // TODO(rune@opera.com): Replace with UpdateStyleSheetList(). 129 // If all tree scopes are dirty, update all of active style. Otherwise, we
130 // would have to mark all tree scopes explicitly dirty for stylesheet list
131 // or repeatedly update the stylesheet list on styleSheets access. Note
132 // that this can only happen once if we kDidLayoutWithPendingSheets in
133 // Document::UpdateStyleAndLayoutTreeIgnoringPendingStyleSheets.
128 UpdateActiveStyle(); 134 UpdateActiveStyle();
129 } else { 135 } else {
130 UpdateStyleSheetList(tree_scope); 136 collection.UpdateStyleSheetList();
131 } 137 }
132 } 138 }
133 139 return collection.StyleSheetsForStyleSheetList();
134 if (tree_scope == document_)
135 return GetDocumentStyleSheetCollection().StyleSheetsForStyleSheetList();
136
137 DCHECK(IsMaster());
138 return EnsureStyleSheetCollectionFor(tree_scope)
139 ->StyleSheetsForStyleSheetList();
140 }
141
142 void StyleEngine::UpdateStyleSheetList(TreeScope& tree_scope) {
143 // TODO(rune@opera.com): currently only for import documents.
144 DCHECK(!IsMaster());
145 DCHECK(tree_scope.GetDocument() == GetDocument());
146
147 if (tree_scope != GetDocument())
148 return;
149 if (!ShouldUpdateDocumentStyleSheetCollection())
150 return;
151
152 GetDocumentStyleSheetCollection().CollectStyleSheetsForList();
153 // Avoid updating the styleSheets list repeatedly. Only safe for imports.
154 document_scope_dirty_ = false;
155 DCHECK(!all_tree_scopes_dirty_);
156 } 140 }
157 141
158 void StyleEngine::InjectAuthorSheet(StyleSheetContents* author_sheet) { 142 void StyleEngine::InjectAuthorSheet(StyleSheetContents* author_sheet) {
159 injected_author_style_sheets_.push_back(TraceWrapperMember<CSSStyleSheet>( 143 injected_author_style_sheets_.push_back(TraceWrapperMember<CSSStyleSheet>(
160 this, CSSStyleSheet::Create(author_sheet, *document_))); 144 this, CSSStyleSheet::Create(author_sheet, *document_)));
161 MarkDocumentDirty(); 145 MarkDocumentDirty();
162 } 146 }
163 147
164 CSSStyleSheet& StyleEngine::EnsureInspectorStyleSheet() { 148 CSSStyleSheet& StyleEngine::EnsureInspectorStyleSheet() {
165 if (inspector_style_sheet_) 149 if (inspector_style_sheet_)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (GetDocument().IsActive() || !IsMaster()) 203 if (GetDocument().IsActive() || !IsMaster())
220 MarkTreeScopeDirty(tree_scope); 204 MarkTreeScopeDirty(tree_scope);
221 } 205 }
222 206
223 void StyleEngine::AddStyleSheetCandidateNode(Node& node) { 207 void StyleEngine::AddStyleSheetCandidateNode(Node& node) {
224 if (!node.isConnected() || GetDocument().IsDetached()) 208 if (!node.isConnected() || GetDocument().IsDetached())
225 return; 209 return;
226 210
227 DCHECK(!IsXSLStyleSheet(node)); 211 DCHECK(!IsXSLStyleSheet(node));
228 TreeScope& tree_scope = node.GetTreeScope(); 212 TreeScope& tree_scope = node.GetTreeScope();
229 TreeScopeStyleSheetCollection* collection = 213 EnsureStyleSheetCollectionFor(tree_scope).AddStyleSheetCandidateNode(node);
230 EnsureStyleSheetCollectionFor(tree_scope);
231 DCHECK(collection);
232 collection->AddStyleSheetCandidateNode(node);
233 214
234 SetNeedsActiveStyleUpdate(tree_scope); 215 SetNeedsActiveStyleUpdate(tree_scope);
235 if (tree_scope != document_) 216 if (tree_scope != document_)
236 active_tree_scopes_.insert(&tree_scope); 217 active_tree_scopes_.insert(&tree_scope);
237 } 218 }
238 219
239 void StyleEngine::RemoveStyleSheetCandidateNode( 220 void StyleEngine::RemoveStyleSheetCandidateNode(
240 Node& node, 221 Node& node,
241 ContainerNode& insertion_point) { 222 ContainerNode& insertion_point) {
242 DCHECK(!IsXSLStyleSheet(node)); 223 DCHECK(!IsXSLStyleSheet(node));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 HeapVector<Member<StyleSheet>> sheets_for_list; 296 HeapVector<Member<StyleSheet>> sheets_for_list;
316 ImportedDocumentStyleSheetCollector subcollector(parent_collector, 297 ImportedDocumentStyleSheetCollector subcollector(parent_collector,
317 sheets_for_list); 298 sheets_for_list);
318 GetDocumentStyleSheetCollection().CollectStyleSheets(master_engine, 299 GetDocumentStyleSheetCollection().CollectStyleSheets(master_engine,
319 subcollector); 300 subcollector);
320 GetDocumentStyleSheetCollection().SwapSheetsForSheetList(sheets_for_list); 301 GetDocumentStyleSheetCollection().SwapSheetsForSheetList(sheets_for_list);
321 302
322 // all_tree_scopes_dirty_ should only be set on main documents, never html 303 // all_tree_scopes_dirty_ should only be set on main documents, never html
323 // imports. 304 // imports.
324 DCHECK(!all_tree_scopes_dirty_); 305 DCHECK(!all_tree_scopes_dirty_);
325 // Make sure we don't re-collect sheets for style sheet list. 306 // Mark false for consistency. It is never checked for import documents.
326 document_scope_dirty_ = false; 307 document_scope_dirty_ = false;
327 // Dirty tree scopes shadow trees do not affect the main document. Just leave
328 // them dirty here and re-collect when styleSheets is queried on shadow roots
329 // inside html import documents.
330 // tree_scopes_removed_ is irrelevant for html imports as the sheets do not
331 // affect style and removing a shadow tree is reflected directly in
332 // StyleSheetList accessing length or items.
333 } 308 }
334 309
335 void StyleEngine::UpdateActiveStyleSheetsInShadow( 310 void StyleEngine::UpdateActiveStyleSheetsInShadow(
336 TreeScope* tree_scope, 311 TreeScope* tree_scope,
337 UnorderedTreeScopeSet& tree_scopes_removed) { 312 UnorderedTreeScopeSet& tree_scopes_removed) {
338 DCHECK_NE(tree_scope, document_); 313 DCHECK_NE(tree_scope, document_);
339 ShadowTreeStyleSheetCollection* collection = 314 ShadowTreeStyleSheetCollection* collection =
340 ToShadowTreeStyleSheetCollection(StyleSheetCollectionFor(*tree_scope)); 315 ToShadowTreeStyleSheetCollection(StyleSheetCollectionFor(*tree_scope));
341 DCHECK(collection); 316 DCHECK(collection);
342 collection->UpdateActiveStyleSheets(*this); 317 collection->UpdateActiveStyleSheets(*this);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (resolver_) 513 if (resolver_)
539 resolver_->InvalidateMatchedPropertiesCache(); 514 resolver_->InvalidateMatchedPropertiesCache();
540 } 515 }
541 516
542 void StyleEngine::MarkTreeScopeDirty(TreeScope& scope) { 517 void StyleEngine::MarkTreeScopeDirty(TreeScope& scope) {
543 if (scope == document_) { 518 if (scope == document_) {
544 MarkDocumentDirty(); 519 MarkDocumentDirty();
545 return; 520 return;
546 } 521 }
547 522
548 DCHECK(style_sheet_collection_map_.Contains(&scope)); 523 TreeScopeStyleSheetCollection* collection = StyleSheetCollectionFor(scope);
524 DCHECK(collection);
525 collection->MarkSheetListDirty();
549 dirty_tree_scopes_.insert(&scope); 526 dirty_tree_scopes_.insert(&scope);
550 GetDocument().ScheduleLayoutTreeUpdateIfNeeded(); 527 GetDocument().ScheduleLayoutTreeUpdateIfNeeded();
551 } 528 }
552 529
553 void StyleEngine::MarkDocumentDirty() { 530 void StyleEngine::MarkDocumentDirty() {
554 document_scope_dirty_ = true; 531 document_scope_dirty_ = true;
532 document_style_sheet_collection_->MarkSheetListDirty();
555 if (RuntimeEnabledFeatures::cssViewportEnabled()) 533 if (RuntimeEnabledFeatures::cssViewportEnabled())
556 ViewportRulesChanged(); 534 ViewportRulesChanged();
557 if (GetDocument().ImportLoader()) 535 if (GetDocument().ImportLoader())
558 GetDocument() 536 GetDocument()
559 .ImportsController() 537 .ImportsController()
560 ->Master() 538 ->Master()
561 ->GetStyleEngine() 539 ->GetStyleEngine()
562 .MarkDocumentDirty(); 540 .MarkDocumentDirty();
563 else 541 else
564 GetDocument().ScheduleLayoutTreeUpdateIfNeeded(); 542 GetDocument().ScheduleLayoutTreeUpdateIfNeeded();
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 } 1208 }
1231 1209
1232 DEFINE_TRACE_WRAPPERS(StyleEngine) { 1210 DEFINE_TRACE_WRAPPERS(StyleEngine) {
1233 for (auto sheet : injected_author_style_sheets_) { 1211 for (auto sheet : injected_author_style_sheets_) {
1234 visitor->TraceWrappers(sheet); 1212 visitor->TraceWrappers(sheet);
1235 } 1213 }
1236 visitor->TraceWrappers(document_style_sheet_collection_); 1214 visitor->TraceWrappers(document_style_sheet_collection_);
1237 } 1215 }
1238 1216
1239 } // namespace blink 1217 } // 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