Chromium Code Reviews| 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, 2010, 2012 Apple Inc. All r ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 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) 2010 Nokia Corporation and/or its subsidiary(-ies) | 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 9 * Copyright (C) 2013 Google Inc. All rights reserved. | 9 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 10 * | 10 * |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * along with this library; see the file COPYING.LIB. If not, write to | 22 * along with this library; see the file COPYING.LIB. If not, write to |
| 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 * Boston, MA 02110-1301, USA. | 24 * Boston, MA 02110-1301, USA. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/dom/StyleSheetCollection.h" | 28 #include "core/dom/StyleSheetCollection.h" |
| 29 | 29 |
| 30 #include "core/css/CSSStyleSheet.h" | 30 #include "core/css/CSSStyleSheet.h" |
| 31 #include "core/css/StyleInvalidationAnalysis.h" | 31 #include "core/css/StyleInvalidationAnalysis.h" |
| 32 #include "core/css/StyleRuleImport.h" | |
| 32 #include "core/css/StyleSheetContents.h" | 33 #include "core/css/StyleSheetContents.h" |
| 33 #include "core/css/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
| 34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 35 #include "core/dom/Element.h" | 36 #include "core/dom/Element.h" |
| 36 #include "core/dom/StyleEngine.h" | 37 #include "core/dom/StyleEngine.h" |
| 37 #include "core/html/HTMLStyleElement.h" | 38 #include "core/html/HTMLStyleElement.h" |
| 38 #include "core/page/Settings.h" | 39 #include "core/page/Settings.h" |
| 39 | 40 |
| 40 namespace WebCore { | 41 namespace WebCore { |
| 41 | 42 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 hasActiveLoadingStylesheet = true; | 114 hasActiveLoadingStylesheet = true; |
| 114 } | 115 } |
| 115 if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) { | 116 if (m_hadActiveLoadingStylesheet && !hasActiveLoadingStylesheet) { |
| 116 m_hadActiveLoadingStylesheet = false; | 117 m_hadActiveLoadingStylesheet = false; |
| 117 return true; | 118 return true; |
| 118 } | 119 } |
| 119 m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet; | 120 m_hadActiveLoadingStylesheet = hasActiveLoadingStylesheet; |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| 123 void StyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMode updat eMode, const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, const Vector<RefPtr <CSSStyleSheet> >& newStyleSheets, StyleResolverUpdateType& styleResolverUpdateT ype, bool& requiresFullStyleRecalc) | 124 static bool rulesHaveFontFaceRule(const Vector<RefPtr<StyleRuleBase> >& rules) |
| 125 { | |
| 126 for (unsigned i = 0; i < rules.size(); ++i) { | |
| 127 StyleRuleBase* rule = rules[i].get(); | |
| 128 ASSERT(rule); | |
| 129 if (rule->isFontFaceRule()) | |
| 130 return true; | |
| 131 } | |
| 132 return false; | |
| 133 } | |
| 134 | |
| 135 static bool styleSheetContentsHasFontFaceRule(StyleSheetContents* sheet) | |
| 136 { | |
| 137 if (!sheet) | |
| 138 return false; | |
| 139 | |
| 140 if (sheet->importRules().size() > 0) { | |
| 141 const Vector<RefPtr<StyleRuleImport> >& importRules = sheet->importRules (); | |
| 142 for (unsigned i = 0; i < importRules.size(); ++i) { | |
| 143 StyleRuleImport* importRule = importRules[i].get(); | |
| 144 if (styleSheetContentsHasFontFaceRule(importRule->styleSheet())) | |
| 145 return true; | |
| 146 } | |
| 147 } | |
| 148 return rulesHaveFontFaceRule(sheet->childRules()); | |
| 149 } | |
| 150 | |
| 151 static bool styleSheetContentsHasFontFaceRule(Vector<StyleSheetContents*> sheets ) | |
| 152 { | |
| 153 for (unsigned i = 0; i < sheets.size(); ++i) { | |
| 154 if (styleSheetContentsHasFontFaceRule(sheets[i])) | |
| 155 return true; | |
| 156 } | |
| 157 return false; | |
| 158 } | |
| 159 | |
| 160 void StyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMode updat eMode, const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, const Vector<RefPtr <CSSStyleSheet> >& newStyleSheets, StyleResolverUpdateType& styleResolverUpdateT ype, bool& requiresFullStyleRecalc, bool& requiresResetFontSelector) | |
| 124 { | 161 { |
| 125 styleResolverUpdateType = Reconstruct; | 162 styleResolverUpdateType = Reconstruct; |
| 126 requiresFullStyleRecalc = true; | 163 requiresFullStyleRecalc = true; |
| 164 requiresResetFontSelector = true; | |
| 127 | 165 |
| 128 if (activeLoadingStyleSheetLoaded(newStyleSheets)) | 166 if (activeLoadingStyleSheetLoaded(newStyleSheets)) |
| 129 return; | 167 return; |
| 130 | 168 |
| 131 if (updateMode != AnalyzedStyleUpdate) | 169 if (updateMode != AnalyzedStyleUpdate) |
| 132 return; | 170 return; |
| 133 if (!document()->styleResolverIfExists()) | 171 if (!document()->styleResolverIfExists()) |
| 134 return; | 172 return; |
| 135 | 173 |
| 136 // Find out which stylesheets are new. | 174 // Find out which stylesheets are new. |
| 137 Vector<StyleSheetContents*> addedSheets; | 175 Vector<StyleSheetContents*> addedSheets; |
| 138 if (oldStyleSheets.size() <= newStyleSheets.size()) { | 176 if (oldStyleSheets.size() <= newStyleSheets.size()) { |
| 139 styleResolverUpdateType = compareStyleSheets(oldStyleSheets, newStyleShe ets, addedSheets); | 177 styleResolverUpdateType = compareStyleSheets(oldStyleSheets, newStyleShe ets, addedSheets); |
| 178 requiresResetFontSelector = false; | |
| 140 } else { | 179 } else { |
| 141 StyleResolverUpdateType updateType = compareStyleSheets(newStyleSheets, oldStyleSheets, addedSheets); | 180 StyleResolverUpdateType updateType = compareStyleSheets(newStyleSheets, oldStyleSheets, addedSheets); |
| 142 styleResolverUpdateType = updateType != Additive ? updateType : Reset; | 181 styleResolverUpdateType = updateType != Additive ? updateType : Reset; |
| 182 requiresResetFontSelector = updateType != Additive ? true : styleSheetCo ntentsHasFontFaceRule(addedSheets); | |
|
dglazkov
2013/11/08 18:05:34
I am not super-thrilled about adding this recursiv
tasak
2013/11/12 04:13:11
Done.
| |
| 143 } | 183 } |
| 144 | 184 |
| 145 // FIXME: If styleResolverUpdateType is still Reconstruct, we could return e arly here | 185 // FIXME: If styleResolverUpdateType is still Reconstruct, we could return e arly here |
| 146 // as destroying the StyleResolver will recalc the whole document anyway? | 186 // as destroying the StyleResolver will recalc the whole document anyway? |
| 147 | 187 |
| 148 // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs. | 188 // If we are already parsing the body and so may have significant amount of elements, put some effort into trying to avoid style recalcs. |
| 149 if (!document()->body() || document()->hasNodesWithPlaceholderStyle()) | 189 if (!document()->body() || document()->hasNodesWithPlaceholderStyle()) |
| 150 return; | 190 return; |
| 151 StyleInvalidationAnalysis invalidationAnalysis(addedSheets); | 191 StyleInvalidationAnalysis invalidationAnalysis(addedSheets); |
| 152 if (invalidationAnalysis.dirtiesAllStyle()) | 192 if (invalidationAnalysis.dirtiesAllStyle()) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 177 } | 217 } |
| 178 return false; | 218 return false; |
| 179 } | 219 } |
| 180 | 220 |
| 181 void StyleSheetCollection::updateUsesRemUnits() | 221 void StyleSheetCollection::updateUsesRemUnits() |
| 182 { | 222 { |
| 183 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); | 223 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); |
| 184 } | 224 } |
| 185 | 225 |
| 186 } | 226 } |
| OLD | NEW |