OLD | NEW |
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 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 void StyleEngine::initialViewportChanged() { | 1029 void StyleEngine::initialViewportChanged() { |
1030 if (m_viewportResolver) | 1030 if (m_viewportResolver) |
1031 m_viewportResolver->initialViewportChanged(); | 1031 m_viewportResolver->initialViewportChanged(); |
1032 } | 1032 } |
1033 | 1033 |
1034 void StyleEngine::viewportRulesChanged() { | 1034 void StyleEngine::viewportRulesChanged() { |
1035 if (m_viewportResolver) | 1035 if (m_viewportResolver) |
1036 m_viewportResolver->setNeedsCollectRules(); | 1036 m_viewportResolver->setNeedsCollectRules(); |
1037 } | 1037 } |
1038 | 1038 |
| 1039 void StyleEngine::importRemoved() { |
| 1040 if (document().importLoader()) { |
| 1041 document().importsController()->master()->styleEngine().importRemoved(); |
| 1042 return; |
| 1043 } |
| 1044 |
| 1045 // When we remove an import link and re-insert it into the document, the |
| 1046 // import Document and CSSStyleSheet pointers are persisted. That means the |
| 1047 // comparison of active stylesheets is not able to figure out that the order |
| 1048 // of the stylesheets have changed after insertion. |
| 1049 // |
| 1050 // Fall back to re-add all sheets to the scoped resolver and recalculate style |
| 1051 // for the whole document if we remove an import in case it is re-inserted |
| 1052 // into the document. The assumption is that removing html imports is very |
| 1053 // rare. |
| 1054 if (ScopedStyleResolver* resolver = document().scopedStyleResolver()) { |
| 1055 resolver->setNeedsAppendAllSheets(); |
| 1056 document().setNeedsStyleRecalc( |
| 1057 SubtreeStyleChange, StyleChangeReasonForTracing::create( |
| 1058 StyleChangeReason::ActiveStylesheetsUpdate)); |
| 1059 } |
| 1060 } |
| 1061 |
1039 PassRefPtr<ComputedStyle> StyleEngine::findSharedStyle( | 1062 PassRefPtr<ComputedStyle> StyleEngine::findSharedStyle( |
1040 const ElementResolveContext& elementResolveContext) { | 1063 const ElementResolveContext& elementResolveContext) { |
1041 DCHECK(m_resolver); | 1064 DCHECK(m_resolver); |
1042 return SharedStyleFinder( | 1065 return SharedStyleFinder( |
1043 elementResolveContext, m_globalRuleSet.ruleFeatureSet(), | 1066 elementResolveContext, m_globalRuleSet.ruleFeatureSet(), |
1044 m_globalRuleSet.siblingRuleSet(), | 1067 m_globalRuleSet.siblingRuleSet(), |
1045 m_globalRuleSet.uncommonAttributeRuleSet(), *m_resolver) | 1068 m_globalRuleSet.uncommonAttributeRuleSet(), *m_resolver) |
1046 .findSharedStyle(); | 1069 .findSharedStyle(); |
1047 } | 1070 } |
1048 namespace { | 1071 namespace { |
(...skipping 19 matching lines...) Expand all Loading... |
1068 } | 1091 } |
1069 | 1092 |
1070 } // namespace | 1093 } // namespace |
1071 | 1094 |
1072 void StyleEngine::applyRuleSetChanges( | 1095 void StyleEngine::applyRuleSetChanges( |
1073 TreeScope& treeScope, | 1096 TreeScope& treeScope, |
1074 const ActiveStyleSheetVector& oldStyleSheets, | 1097 const ActiveStyleSheetVector& oldStyleSheets, |
1075 const ActiveStyleSheetVector& newStyleSheets) { | 1098 const ActiveStyleSheetVector& newStyleSheets) { |
1076 HeapVector<Member<RuleSet>> changedRuleSets; | 1099 HeapVector<Member<RuleSet>> changedRuleSets; |
1077 | 1100 |
| 1101 ScopedStyleResolver* scopedResolver = treeScope.scopedStyleResolver(); |
| 1102 bool appendAllSheets = |
| 1103 scopedResolver && scopedResolver->needsAppendAllSheets(); |
| 1104 |
1078 ActiveSheetsChange change = | 1105 ActiveSheetsChange change = |
1079 compareActiveStyleSheets(oldStyleSheets, newStyleSheets, changedRuleSets); | 1106 compareActiveStyleSheets(oldStyleSheets, newStyleSheets, changedRuleSets); |
1080 if (change == NoActiveSheetsChanged) | 1107 if (change == NoActiveSheetsChanged && !appendAllSheets) |
1081 return; | 1108 return; |
1082 | 1109 |
1083 // With rules added or removed, we need to re-aggregate rule meta data. | 1110 // With rules added or removed, we need to re-aggregate rule meta data. |
1084 m_globalRuleSet.markDirty(); | 1111 m_globalRuleSet.markDirty(); |
1085 | 1112 |
1086 unsigned changedRuleFlags = getRuleSetFlags(changedRuleSets); | 1113 unsigned changedRuleFlags = getRuleSetFlags(changedRuleSets); |
1087 bool fontsChanged = treeScope.rootNode().isDocumentNode() && | 1114 bool fontsChanged = treeScope.rootNode().isDocumentNode() && |
1088 (changedRuleFlags & FontFaceRules); | 1115 (changedRuleFlags & FontFaceRules); |
1089 unsigned appendStartIndex = 0; | 1116 unsigned appendStartIndex = 0; |
1090 | 1117 |
1091 // We don't need to clear the font cache if new sheets are appended. | 1118 // We don't need to clear the font cache if new sheets are appended. |
1092 if (fontsChanged && change == ActiveSheetsChanged) | 1119 if (fontsChanged && change == ActiveSheetsChanged) |
1093 clearFontCache(); | 1120 clearFontCache(); |
1094 | 1121 |
1095 // - If all sheets were removed, we remove the ScopedStyleResolver. | 1122 // - If all sheets were removed, we remove the ScopedStyleResolver. |
1096 // - If new sheets were appended to existing ones, start appending after the | 1123 // - If new sheets were appended to existing ones, start appending after the |
1097 // common prefix. | 1124 // common prefix. |
1098 // - For other diffs, reset author style and re-add all sheets for the | 1125 // - For other diffs, reset author style and re-add all sheets for the |
1099 // TreeScope. | 1126 // TreeScope. |
1100 if (treeScope.scopedStyleResolver()) { | 1127 if (treeScope.scopedStyleResolver()) { |
1101 if (newStyleSheets.isEmpty()) | 1128 if (newStyleSheets.isEmpty()) |
1102 resetAuthorStyle(treeScope); | 1129 resetAuthorStyle(treeScope); |
1103 else if (change == ActiveSheetsAppended) | 1130 else if (change == ActiveSheetsAppended && !appendAllSheets) |
1104 appendStartIndex = oldStyleSheets.size(); | 1131 appendStartIndex = oldStyleSheets.size(); |
1105 else | 1132 else |
1106 treeScope.scopedStyleResolver()->resetAuthorStyle(); | 1133 treeScope.scopedStyleResolver()->resetAuthorStyle(); |
1107 } | 1134 } |
1108 | 1135 |
1109 if (!newStyleSheets.isEmpty()) { | 1136 if (!newStyleSheets.isEmpty()) { |
1110 treeScope.ensureScopedStyleResolver().appendActiveStyleSheets( | 1137 treeScope.ensureScopedStyleResolver().appendActiveStyleSheets( |
1111 appendStartIndex, newStyleSheets); | 1138 appendStartIndex, newStyleSheets); |
1112 } | 1139 } |
1113 | 1140 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 } | 1184 } |
1158 | 1185 |
1159 DEFINE_TRACE_WRAPPERS(StyleEngine) { | 1186 DEFINE_TRACE_WRAPPERS(StyleEngine) { |
1160 for (auto sheet : m_injectedAuthorStyleSheets) { | 1187 for (auto sheet : m_injectedAuthorStyleSheets) { |
1161 visitor->traceWrappers(sheet); | 1188 visitor->traceWrappers(sheet); |
1162 } | 1189 } |
1163 visitor->traceWrappers(m_documentStyleSheetCollection); | 1190 visitor->traceWrappers(m_documentStyleSheetCollection); |
1164 } | 1191 } |
1165 | 1192 |
1166 } // namespace blink | 1193 } // namespace blink |
OLD | NEW |