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

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

Issue 2487653002: Moved applyRuleSetChanges functions to StyleEngine. (Closed)
Patch Set: Added comment Created 4 years, 1 month 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/StyleEngine.h ('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) 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1022
1023 PassRefPtr<ComputedStyle> StyleEngine::findSharedStyle( 1023 PassRefPtr<ComputedStyle> StyleEngine::findSharedStyle(
1024 const ElementResolveContext& elementResolveContext) { 1024 const ElementResolveContext& elementResolveContext) {
1025 DCHECK(m_resolver); 1025 DCHECK(m_resolver);
1026 return SharedStyleFinder( 1026 return SharedStyleFinder(
1027 elementResolveContext, m_globalRuleSet.ruleFeatureSet(), 1027 elementResolveContext, m_globalRuleSet.ruleFeatureSet(),
1028 m_globalRuleSet.siblingRuleSet(), 1028 m_globalRuleSet.siblingRuleSet(),
1029 m_globalRuleSet.uncommonAttributeRuleSet(), *m_resolver) 1029 m_globalRuleSet.uncommonAttributeRuleSet(), *m_resolver)
1030 .findSharedStyle(); 1030 .findSharedStyle();
1031 } 1031 }
1032 namespace {
1033
1034 enum RuleSetFlags {
1035 FontFaceRules = 1 << 0,
1036 KeyframesRules = 1 << 1,
1037 FullRecalcRules = 1 << 2
1038 };
1039
1040 unsigned getRuleSetFlags(const HeapVector<Member<RuleSet>> ruleSets) {
1041 unsigned flags = 0;
1042 for (auto& ruleSet : ruleSets) {
1043 ruleSet->compactRulesIfNeeded();
1044 if (!ruleSet->keyframesRules().isEmpty())
1045 flags |= KeyframesRules;
1046 if (!ruleSet->fontFaceRules().isEmpty())
1047 flags |= FontFaceRules;
1048 if (ruleSet->needsFullRecalcForRuleSetInvalidation())
1049 flags |= FullRecalcRules;
1050 }
1051 return flags;
1052 }
1053
1054 } // namespace
1055
1056 void StyleEngine::applyRuleSetChanges(
1057 TreeScope& treeScope,
1058 const ActiveStyleSheetVector& oldStyleSheets,
1059 const ActiveStyleSheetVector& newStyleSheets) {
1060 HeapVector<Member<RuleSet>> changedRuleSets;
1061
1062 ActiveSheetsChange change =
1063 compareActiveStyleSheets(oldStyleSheets, newStyleSheets, changedRuleSets);
1064 if (change == NoActiveSheetsChanged)
1065 return;
1066
1067 // With rules added or removed, we need to re-aggregate rule meta data.
1068 m_globalRuleSet.markDirty();
1069
1070 unsigned changedRuleFlags = getRuleSetFlags(changedRuleSets);
1071 bool fontsChanged = treeScope.rootNode().isDocumentNode() &&
1072 (changedRuleFlags & FontFaceRules);
1073 unsigned appendStartIndex = 0;
1074
1075 // We don't need to clear the font cache if new sheets are appended.
1076 if (fontsChanged && change == ActiveSheetsChanged)
1077 clearFontCache();
1078
1079 // - If all sheets were removed, we remove the ScopedStyleResolver.
1080 // - If new sheets were appended to existing ones, start appending after the
1081 // common prefix.
1082 // - For other diffs, reset author style and re-add all sheets for the
1083 // TreeScope.
1084 if (treeScope.scopedStyleResolver()) {
1085 if (newStyleSheets.isEmpty())
1086 resetAuthorStyle(treeScope);
1087 else if (change == ActiveSheetsAppended)
1088 appendStartIndex = oldStyleSheets.size();
1089 else
1090 treeScope.scopedStyleResolver()->resetAuthorStyle();
1091 }
1092
1093 if (!newStyleSheets.isEmpty()) {
1094 treeScope.ensureScopedStyleResolver().appendActiveStyleSheets(
1095 appendStartIndex, newStyleSheets);
1096 }
1097
1098 if (treeScope.document().hasPendingForcedStyleRecalc())
1099 return;
1100
1101 if (!treeScope.document().body() ||
1102 treeScope.document().hasNodesWithPlaceholderStyle()) {
1103 treeScope.document().setNeedsStyleRecalc(
1104 SubtreeStyleChange, StyleChangeReasonForTracing::create(
1105 StyleChangeReason::CleanupPlaceholderStyles));
1106 return;
1107 }
1108
1109 if (changedRuleFlags & KeyframesRules)
1110 ScopedStyleResolver::keyframesRulesAdded(treeScope);
1111
1112 if (fontsChanged || (changedRuleFlags & FullRecalcRules)) {
1113 ScopedStyleResolver::invalidationRootForTreeScope(treeScope)
1114 .setNeedsStyleRecalc(SubtreeStyleChange,
1115 StyleChangeReasonForTracing::create(
1116 StyleChangeReason::ActiveStylesheetsUpdate));
1117 return;
1118 }
1119
1120 scheduleInvalidationsForRuleSets(treeScope, changedRuleSets);
1121 }
1032 1122
1033 DEFINE_TRACE(StyleEngine) { 1123 DEFINE_TRACE(StyleEngine) {
1034 visitor->trace(m_document); 1124 visitor->trace(m_document);
1035 visitor->trace(m_injectedAuthorStyleSheets); 1125 visitor->trace(m_injectedAuthorStyleSheets);
1036 visitor->trace(m_inspectorStyleSheet); 1126 visitor->trace(m_inspectorStyleSheet);
1037 visitor->trace(m_documentStyleSheetCollection); 1127 visitor->trace(m_documentStyleSheetCollection);
1038 visitor->trace(m_styleSheetCollectionMap); 1128 visitor->trace(m_styleSheetCollectionMap);
1039 visitor->trace(m_dirtyTreeScopes); 1129 visitor->trace(m_dirtyTreeScopes);
1040 visitor->trace(m_activeTreeScopes); 1130 visitor->trace(m_activeTreeScopes);
1041 visitor->trace(m_treeBoundaryCrossingScopes); 1131 visitor->trace(m_treeBoundaryCrossingScopes);
1042 visitor->trace(m_globalRuleSet); 1132 visitor->trace(m_globalRuleSet);
1043 visitor->trace(m_resolver); 1133 visitor->trace(m_resolver);
1044 visitor->trace(m_viewportResolver); 1134 visitor->trace(m_viewportResolver);
1045 visitor->trace(m_styleInvalidator); 1135 visitor->trace(m_styleInvalidator);
1046 visitor->trace(m_fontSelector); 1136 visitor->trace(m_fontSelector);
1047 visitor->trace(m_textToSheetCache); 1137 visitor->trace(m_textToSheetCache);
1048 visitor->trace(m_sheetToTextCache); 1138 visitor->trace(m_sheetToTextCache);
1049 visitor->trace(m_tracker); 1139 visitor->trace(m_tracker);
1050 CSSFontSelectorClient::trace(visitor); 1140 CSSFontSelectorClient::trace(visitor);
1051 } 1141 }
1052 1142
1053 DEFINE_TRACE_WRAPPERS(StyleEngine) { 1143 DEFINE_TRACE_WRAPPERS(StyleEngine) {
1054 for (auto sheet : m_injectedAuthorStyleSheets) { 1144 for (auto sheet : m_injectedAuthorStyleSheets) {
1055 visitor->traceWrappers(sheet); 1145 visitor->traceWrappers(sheet);
1056 } 1146 }
1057 visitor->traceWrappers(m_documentStyleSheetCollection); 1147 visitor->traceWrappers(m_documentStyleSheetCollection);
1058 } 1148 }
1059 1149
1060 } // namespace blink 1150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/StyleEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698