| 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 "sky/engine/config.h" | 27 #include "sky/engine/config.h" |
| 28 #include "sky/engine/core/dom/TreeScopeStyleSheetCollection.h" | 28 #include "sky/engine/core/dom/TreeScopeStyleSheetCollection.h" |
| 29 | 29 |
| 30 #include "sky/engine/core/css/CSSStyleSheet.h" | 30 #include "sky/engine/core/css/CSSStyleSheet.h" |
| 31 #include "sky/engine/core/css/StyleSheetContents.h" | 31 #include "sky/engine/core/css/StyleSheetContents.h" |
| 32 #include "sky/engine/core/css/invalidation/StyleSheetInvalidationAnalysis.h" | |
| 33 #include "sky/engine/core/css/resolver/StyleResolver.h" | 32 #include "sky/engine/core/css/resolver/StyleResolver.h" |
| 34 #include "sky/engine/core/dom/Element.h" | 33 #include "sky/engine/core/dom/Element.h" |
| 35 #include "sky/engine/core/dom/StyleEngine.h" | 34 #include "sky/engine/core/dom/StyleEngine.h" |
| 36 #include "sky/engine/core/html/HTMLStyleElement.h" | 35 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 37 | 36 |
| 38 namespace blink { | 37 namespace blink { |
| 39 | 38 |
| 40 TreeScopeStyleSheetCollection::TreeScopeStyleSheetCollection(TreeScope& treeScop
e) | 39 TreeScopeStyleSheetCollection::TreeScopeStyleSheetCollection(TreeScope& treeScop
e) |
| 41 : m_treeScope(treeScope) | 40 : m_treeScope(treeScope) |
| 42 , m_usesRemUnits(false) | 41 , m_usesRemUnits(false) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 // (and thus can shift to end up before dynamically added DOM content that i
s also | 52 // (and thus can shift to end up before dynamically added DOM content that i
s also |
| 54 // outside the body). | 53 // outside the body). |
| 55 m_styleSheetCandidateNodes.add(node); | 54 m_styleSheetCandidateNodes.add(node); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void TreeScopeStyleSheetCollection::removeStyleSheetCandidateNode(Node* node, Co
ntainerNode* scopingNode) | 57 void TreeScopeStyleSheetCollection::removeStyleSheetCandidateNode(Node* node, Co
ntainerNode* scopingNode) |
| 59 { | 58 { |
| 60 m_styleSheetCandidateNodes.remove(node); | 59 m_styleSheetCandidateNodes.remove(node); |
| 61 } | 60 } |
| 62 | 61 |
| 63 TreeScopeStyleSheetCollection::StyleResolverUpdateType TreeScopeStyleSheetCollec
tion::compareStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& oldStyleSheets, c
onst Vector<RefPtr<CSSStyleSheet> >& newStylesheets, Vector<RawPtr<StyleSheetCon
tents> >& addedSheets) | |
| 64 { | |
| 65 unsigned newStyleSheetCount = newStylesheets.size(); | |
| 66 unsigned oldStyleSheetCount = oldStyleSheets.size(); | |
| 67 ASSERT(newStyleSheetCount >= oldStyleSheetCount); | |
| 68 | |
| 69 if (!newStyleSheetCount) | |
| 70 return Reconstruct; | |
| 71 | |
| 72 unsigned newIndex = 0; | |
| 73 for (unsigned oldIndex = 0; oldIndex < oldStyleSheetCount; ++oldIndex) { | |
| 74 while (oldStyleSheets[oldIndex] != newStylesheets[newIndex]) { | |
| 75 addedSheets.append(newStylesheets[newIndex]->contents()); | |
| 76 if (++newIndex == newStyleSheetCount) | |
| 77 return Reconstruct; | |
| 78 } | |
| 79 if (++newIndex == newStyleSheetCount) | |
| 80 return Reconstruct; | |
| 81 } | |
| 82 bool hasInsertions = !addedSheets.isEmpty(); | |
| 83 while (newIndex < newStyleSheetCount) { | |
| 84 addedSheets.append(newStylesheets[newIndex]->contents()); | |
| 85 ++newIndex; | |
| 86 } | |
| 87 // If all new sheets were added at the end of the list we can just add them
to existing StyleResolver. | |
| 88 // If there were insertions we need to re-add all the stylesheets so rules a
re ordered correctly. | |
| 89 return hasInsertions ? Reset : Additive; | |
| 90 } | |
| 91 | |
| 92 static bool findFontFaceRulesFromStyleSheetContents(const Vector<RawPtr<StyleShe
etContents> >& sheets, Vector<RawPtr<const StyleRuleFontFace> >& fontFaceRules) | |
| 93 { | |
| 94 bool hasFontFaceRule = false; | |
| 95 | |
| 96 for (unsigned i = 0; i < sheets.size(); ++i) { | |
| 97 ASSERT(sheets[i]); | |
| 98 if (sheets[i]->hasFontFaceRule()) { | |
| 99 // FIXME: We don't need this for styles in shadow tree. | |
| 100 sheets[i]->findFontFaceRules(fontFaceRules); | |
| 101 hasFontFaceRule = true; | |
| 102 } | |
| 103 } | |
| 104 return hasFontFaceRule; | |
| 105 } | |
| 106 | |
| 107 void TreeScopeStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateM
ode updateMode, const StyleSheetCollection& newCollection, StyleSheetChange& cha
nge) | |
| 108 { | |
| 109 if (updateMode != AnalyzedStyleUpdate) | |
| 110 return; | |
| 111 | |
| 112 // Find out which stylesheets are new. | |
| 113 Vector<RawPtr<StyleSheetContents> > addedSheets; | |
| 114 if (m_activeAuthorStyleSheets.size() <= newCollection.activeAuthorStyleSheet
s().size()) { | |
| 115 change.styleResolverUpdateType = compareStyleSheets(m_activeAuthorStyleS
heets, newCollection.activeAuthorStyleSheets(), addedSheets); | |
| 116 } else { | |
| 117 StyleResolverUpdateType updateType = compareStyleSheets(newCollection.ac
tiveAuthorStyleSheets(), m_activeAuthorStyleSheets, addedSheets); | |
| 118 if (updateType != Additive) { | |
| 119 change.styleResolverUpdateType = updateType; | |
| 120 } else { | |
| 121 change.styleResolverUpdateType = Reset; | |
| 122 // If @font-face is removed, needs full style recalc. | |
| 123 if (findFontFaceRulesFromStyleSheetContents(addedSheets, change.font
FaceRulesToRemove)) | |
| 124 return; | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 // FIXME: If styleResolverUpdateType is Reconstruct, we should return early
here since | |
| 129 // we need to recalc the whole document. It's wrong to use StyleSheetInvalid
ationAnalysis since | |
| 130 // it only looks at the addedSheets. | |
| 131 | |
| 132 // No point in doing the analysis work if we're just going to recalc the who
le document anyways. | |
| 133 // This needs to be done after the compareStyleSheets calls above to ensure
we don't throw away | |
| 134 // the StyleResolver if we don't need to. | |
| 135 if (document().hasPendingForcedStyleRecalc()) | |
| 136 return; | |
| 137 | |
| 138 // If we are already parsing the body and so may have significant amount of
elements, put some effort into trying to avoid style recalcs. | |
| 139 if (document().hasNodesWithPlaceholderStyle()) | |
| 140 return; | |
| 141 StyleSheetInvalidationAnalysis invalidationAnalysis(addedSheets); | |
| 142 if (invalidationAnalysis.dirtiesAllStyle()) | |
| 143 return; | |
| 144 invalidationAnalysis.invalidateStyle(document()); | |
| 145 change.requiresFullStyleRecalc = false; | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 void TreeScopeStyleSheetCollection::clearMediaQueryRuleSetStyleSheets() | 62 void TreeScopeStyleSheetCollection::clearMediaQueryRuleSetStyleSheets() |
| 150 { | 63 { |
| 151 for (size_t i = 0; i < m_activeAuthorStyleSheets.size(); ++i) { | 64 for (size_t i = 0; i < m_activeAuthorStyleSheets.size(); ++i) { |
| 152 StyleSheetContents* contents = m_activeAuthorStyleSheets[i]->contents(); | 65 StyleSheetContents* contents = m_activeAuthorStyleSheets[i]->contents(); |
| 153 if (contents->hasMediaQueries()) | 66 if (contents->hasMediaQueries()) |
| 154 contents->clearRuleSet(); | 67 contents->clearRuleSet(); |
| 155 } | 68 } |
| 156 } | 69 } |
| 157 | 70 |
| 158 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) | 71 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) |
| 159 { | 72 { |
| 160 for (unsigned i = 0; i < sheets.size(); ++i) { | 73 for (unsigned i = 0; i < sheets.size(); ++i) { |
| 161 if (sheets[i]->contents()->usesRemUnits()) | 74 if (sheets[i]->contents()->usesRemUnits()) |
| 162 return true; | 75 return true; |
| 163 } | 76 } |
| 164 return false; | 77 return false; |
| 165 } | 78 } |
| 166 | 79 |
| 167 void TreeScopeStyleSheetCollection::updateUsesRemUnits() | 80 void TreeScopeStyleSheetCollection::updateUsesRemUnits() |
| 168 { | 81 { |
| 169 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); | 82 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); |
| 170 } | 83 } |
| 171 | 84 |
| 172 } | 85 } |
| OLD | NEW |