| 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 r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 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) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| 11 * | 11 * |
| 12 * This library is free software; you can redistribute it and/or | 12 * This library is free software; you can redistribute it and/or |
| 13 * modify it under the terms of the GNU Library General Public | 13 * modify it under the terms of the GNU Library General Public |
| 14 * License as published by the Free Software Foundation; either | 14 * License as published by the Free Software Foundation; either |
| 15 * version 2 of the License, or (at your option) any later version. | 15 * version 2 of the License, or (at your option) any later version. |
| 16 * | 16 * |
| 17 * This library is distributed in the hope that it will be useful, | 17 * This library is distributed in the hope that it will be useful, |
| 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 * Library General Public License for more details. | 20 * Library General Public License for more details. |
| 21 * | 21 * |
| 22 * You should have received a copy of the GNU Library General Public License | 22 * You should have received a copy of the GNU Library General Public License |
| 23 * along with this library; see the file COPYING.LIB. If not, write to | 23 * along with this library; see the file COPYING.LIB. If not, write to |
| 24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 25 * Boston, MA 02110-1301, USA. | 25 * Boston, MA 02110-1301, USA. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/dom/StyleSheetCollections.h" | 29 #include "core/dom/StyleEngine.h" |
| 30 | 30 |
| 31 #include "HTMLNames.h" | 31 #include "HTMLNames.h" |
| 32 #include "SVGNames.h" | 32 #include "SVGNames.h" |
| 33 #include "core/css/CSSStyleSheet.h" | 33 #include "core/css/CSSStyleSheet.h" |
| 34 #include "core/css/StyleInvalidationAnalysis.h" | 34 #include "core/css/StyleInvalidationAnalysis.h" |
| 35 #include "core/css/StyleSheetContents.h" | 35 #include "core/css/StyleSheetContents.h" |
| 36 #include "core/css/resolver/StyleResolver.h" | 36 #include "core/css/resolver/StyleResolver.h" |
| 37 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 38 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
| 39 #include "core/dom/ProcessingInstruction.h" | 39 #include "core/dom/ProcessingInstruction.h" |
| 40 #include "core/dom/ShadowTreeStyleSheetCollection.h" | 40 #include "core/dom/ShadowTreeStyleSheetCollection.h" |
| 41 #include "core/dom/shadow/ShadowRoot.h" | 41 #include "core/dom/shadow/ShadowRoot.h" |
| 42 #include "core/html/HTMLIFrameElement.h" | 42 #include "core/html/HTMLIFrameElement.h" |
| 43 #include "core/html/HTMLLinkElement.h" | 43 #include "core/html/HTMLLinkElement.h" |
| 44 #include "core/html/HTMLStyleElement.h" | 44 #include "core/html/HTMLStyleElement.h" |
| 45 #include "core/page/Page.h" | 45 #include "core/page/Page.h" |
| 46 #include "core/page/PageGroup.h" | 46 #include "core/page/PageGroup.h" |
| 47 #include "core/page/Settings.h" | 47 #include "core/page/Settings.h" |
| 48 #include "core/page/UserContentURLPattern.h" | 48 #include "core/page/UserContentURLPattern.h" |
| 49 #include "core/svg/SVGStyleElement.h" | 49 #include "core/svg/SVGStyleElement.h" |
| 50 | 50 |
| 51 namespace WebCore { | 51 namespace WebCore { |
| 52 | 52 |
| 53 using namespace HTMLNames; | 53 using namespace HTMLNames; |
| 54 | 54 |
| 55 StyleSheetCollections::StyleSheetCollections(Document& document) | 55 StyleEngine::StyleEngine(Document& document) |
| 56 : m_document(document) | 56 : m_document(document) |
| 57 , m_pendingStylesheets(0) | 57 , m_pendingStylesheets(0) |
| 58 , m_injectedStyleSheetCacheValid(false) | 58 , m_injectedStyleSheetCacheValid(false) |
| 59 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) | 59 , m_needsUpdateActiveStylesheetsOnStyleRecalc(false) |
| 60 , m_usesSiblingRules(false) | 60 , m_usesSiblingRules(false) |
| 61 , m_usesSiblingRulesOverride(false) | 61 , m_usesSiblingRulesOverride(false) |
| 62 , m_usesFirstLineRules(false) | 62 , m_usesFirstLineRules(false) |
| 63 , m_usesFirstLetterRules(false) | 63 , m_usesFirstLetterRules(false) |
| 64 , m_usesRemUnits(false) | 64 , m_usesRemUnits(false) |
| 65 , m_documentStyleSheetCollection(document) | 65 , m_documentStyleSheetCollection(document) |
| 66 , m_needsDocumentStyleSheetsUpdate(true) | 66 , m_needsDocumentStyleSheetsUpdate(true) |
| 67 { | 67 { |
| 68 } | 68 } |
| 69 | 69 |
| 70 StyleSheetCollections::~StyleSheetCollections() | 70 StyleEngine::~StyleEngine() |
| 71 { | 71 { |
| 72 if (m_pageUserSheet) | 72 if (m_pageUserSheet) |
| 73 m_pageUserSheet->clearOwnerNode(); | 73 m_pageUserSheet->clearOwnerNode(); |
| 74 for (unsigned i = 0; i < m_injectedUserStyleSheets.size(); ++i) | 74 for (unsigned i = 0; i < m_injectedUserStyleSheets.size(); ++i) |
| 75 m_injectedUserStyleSheets[i]->clearOwnerNode(); | 75 m_injectedUserStyleSheets[i]->clearOwnerNode(); |
| 76 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) | 76 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) |
| 77 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); | 77 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); |
| 78 for (unsigned i = 0; i < m_userStyleSheets.size(); ++i) | 78 for (unsigned i = 0; i < m_userStyleSheets.size(); ++i) |
| 79 m_userStyleSheets[i]->clearOwnerNode(); | 79 m_userStyleSheets[i]->clearOwnerNode(); |
| 80 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | 80 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) |
| 81 m_authorStyleSheets[i]->clearOwnerNode(); | 81 m_authorStyleSheets[i]->clearOwnerNode(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void StyleSheetCollections::insertTreeScopeInDocumentOrder(TreeScopeSet& treeSco
pes, TreeScope* treeScope) | 84 void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeS
cope* treeScope) |
| 85 { | 85 { |
| 86 if (treeScopes.isEmpty()) { | 86 if (treeScopes.isEmpty()) { |
| 87 treeScopes.add(treeScope); | 87 treeScopes.add(treeScope); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 if (treeScopes.contains(treeScope)) | 90 if (treeScopes.contains(treeScope)) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 TreeScopeSet::iterator begin = treeScopes.begin(); | 93 TreeScopeSet::iterator begin = treeScopes.begin(); |
| 94 TreeScopeSet::iterator end = treeScopes.end(); | 94 TreeScopeSet::iterator end = treeScopes.end(); |
| 95 TreeScopeSet::iterator it = end; | 95 TreeScopeSet::iterator it = end; |
| 96 TreeScope* followingTreeScope = 0; | 96 TreeScope* followingTreeScope = 0; |
| 97 do { | 97 do { |
| 98 --it; | 98 --it; |
| 99 TreeScope* n = *it; | 99 TreeScope* n = *it; |
| 100 unsigned short position = n->comparePosition(*treeScope); | 100 unsigned short position = n->comparePosition(*treeScope); |
| 101 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { | 101 if (position & Node::DOCUMENT_POSITION_FOLLOWING) { |
| 102 treeScopes.insertBefore(followingTreeScope, treeScope); | 102 treeScopes.insertBefore(followingTreeScope, treeScope); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 followingTreeScope = n; | 105 followingTreeScope = n; |
| 106 } while (it != begin); | 106 } while (it != begin); |
| 107 | 107 |
| 108 treeScopes.insertBefore(followingTreeScope, treeScope); | 108 treeScopes.insertBefore(followingTreeScope, treeScope); |
| 109 } | 109 } |
| 110 | 110 |
| 111 StyleSheetCollection* StyleSheetCollections::ensureStyleSheetCollectionFor(TreeS
cope& treeScope) | 111 StyleSheetCollection* StyleEngine::ensureStyleSheetCollectionFor(TreeScope& tree
Scope) |
| 112 { | 112 { |
| 113 if (&treeScope == &m_document) | 113 if (&treeScope == &m_document) |
| 114 return &m_documentStyleSheetCollection; | 114 return &m_documentStyleSheetCollection; |
| 115 | 115 |
| 116 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::AddResult result = m_sty
leSheetCollectionMap.add(&treeScope, nullptr); | 116 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::AddResult result = m_sty
leSheetCollectionMap.add(&treeScope, nullptr); |
| 117 if (result.isNewEntry) | 117 if (result.isNewEntry) |
| 118 result.iterator->value = adoptPtr(new ShadowTreeStyleSheetCollection(toS
hadowRoot(treeScope))); | 118 result.iterator->value = adoptPtr(new ShadowTreeStyleSheetCollection(toS
hadowRoot(treeScope))); |
| 119 return result.iterator->value.get(); | 119 return result.iterator->value.get(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 StyleSheetCollection* StyleSheetCollections::styleSheetCollectionFor(TreeScope&
treeScope) | 122 StyleSheetCollection* StyleEngine::styleSheetCollectionFor(TreeScope& treeScope) |
| 123 { | 123 { |
| 124 if (&treeScope == &m_document) | 124 if (&treeScope == &m_document) |
| 125 return &m_documentStyleSheetCollection; | 125 return &m_documentStyleSheetCollection; |
| 126 | 126 |
| 127 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::iterator it = m_styleShe
etCollectionMap.find(&treeScope); | 127 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::iterator it = m_styleShe
etCollectionMap.find(&treeScope); |
| 128 if (it == m_styleSheetCollectionMap.end()) | 128 if (it == m_styleSheetCollectionMap.end()) |
| 129 return 0; | 129 return 0; |
| 130 return it->value.get(); | 130 return it->value.get(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 const Vector<RefPtr<StyleSheet> >& StyleSheetCollections::styleSheetsForStyleShe
etList() | 133 const Vector<RefPtr<StyleSheet> >& StyleEngine::styleSheetsForStyleSheetList() |
| 134 { | 134 { |
| 135 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); | 135 return m_documentStyleSheetCollection.styleSheetsForStyleSheetList(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::activeAuthorStyleSh
eets() const | 138 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::activeAuthorStyleSheets() con
st |
| 139 { | 139 { |
| 140 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); | 140 return m_documentStyleSheetCollection.activeAuthorStyleSheets(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void StyleSheetCollections::getActiveAuthorStyleSheets(Vector<const Vector<RefPt
r<CSSStyleSheet> >*>& activeAuthorStyleSheets) const | 143 void StyleEngine::getActiveAuthorStyleSheets(Vector<const Vector<RefPtr<CSSStyle
Sheet> >*>& activeAuthorStyleSheets) const |
| 144 { | 144 { |
| 145 activeAuthorStyleSheets.append(&m_documentStyleSheetCollection.activeAuthorS
tyleSheets()); | 145 activeAuthorStyleSheets.append(&m_documentStyleSheetCollection.activeAuthorS
tyleSheets()); |
| 146 | 146 |
| 147 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values b
egin = m_styleSheetCollectionMap.values().begin(); | 147 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values b
egin = m_styleSheetCollectionMap.values().begin(); |
| 148 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values e
nd = m_styleSheetCollectionMap.values().end(); | 148 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values e
nd = m_styleSheetCollectionMap.values().end(); |
| 149 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values i
t = begin; | 149 HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values i
t = begin; |
| 150 for (; it != end; ++it) { | 150 for (; it != end; ++it) { |
| 151 const StyleSheetCollection* collection = it->get(); | 151 const StyleSheetCollection* collection = it->get(); |
| 152 activeAuthorStyleSheets.append(&collection->activeAuthorStyleSheets()); | 152 activeAuthorStyleSheets.append(&collection->activeAuthorStyleSheets()); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 void StyleSheetCollections::combineCSSFeatureFlags(const RuleFeatureSet& feature
s) | 156 void StyleEngine::combineCSSFeatureFlags(const RuleFeatureSet& features) |
| 157 { | 157 { |
| 158 // Delay resetting the flags until after next style recalc since unapplying
the style may not work without these set (this is true at least with before/afte
r). | 158 // Delay resetting the flags until after next style recalc since unapplying
the style may not work without these set (this is true at least with before/afte
r). |
| 159 m_usesSiblingRules = m_usesSiblingRules || features.usesSiblingRules(); | 159 m_usesSiblingRules = m_usesSiblingRules || features.usesSiblingRules(); |
| 160 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules()
; | 160 m_usesFirstLineRules = m_usesFirstLineRules || features.usesFirstLineRules()
; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void StyleSheetCollections::resetCSSFeatureFlags(const RuleFeatureSet& features) | 163 void StyleEngine::resetCSSFeatureFlags(const RuleFeatureSet& features) |
| 164 { | 164 { |
| 165 m_usesSiblingRules = features.usesSiblingRules(); | 165 m_usesSiblingRules = features.usesSiblingRules(); |
| 166 m_usesFirstLineRules = features.usesFirstLineRules(); | 166 m_usesFirstLineRules = features.usesFirstLineRules(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 CSSStyleSheet* StyleSheetCollections::pageUserSheet() | 169 CSSStyleSheet* StyleEngine::pageUserSheet() |
| 170 { | 170 { |
| 171 if (m_pageUserSheet) | 171 if (m_pageUserSheet) |
| 172 return m_pageUserSheet.get(); | 172 return m_pageUserSheet.get(); |
| 173 | 173 |
| 174 Page* owningPage = m_document.page(); | 174 Page* owningPage = m_document.page(); |
| 175 if (!owningPage) | 175 if (!owningPage) |
| 176 return 0; | 176 return 0; |
| 177 | 177 |
| 178 String userSheetText = owningPage->userStyleSheet(); | 178 String userSheetText = owningPage->userStyleSheet(); |
| 179 if (userSheetText.isEmpty()) | 179 if (userSheetText.isEmpty()) |
| 180 return 0; | 180 return 0; |
| 181 | 181 |
| 182 // Parse the sheet and cache it. | 182 // Parse the sheet and cache it. |
| 183 m_pageUserSheet = CSSStyleSheet::createInline(&m_document, m_document.settin
gs()->userStyleSheetLocation()); | 183 m_pageUserSheet = CSSStyleSheet::createInline(&m_document, m_document.settin
gs()->userStyleSheetLocation()); |
| 184 m_pageUserSheet->contents()->setIsUserStyleSheet(true); | 184 m_pageUserSheet->contents()->setIsUserStyleSheet(true); |
| 185 m_pageUserSheet->contents()->parseString(userSheetText); | 185 m_pageUserSheet->contents()->parseString(userSheetText); |
| 186 return m_pageUserSheet.get(); | 186 return m_pageUserSheet.get(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void StyleSheetCollections::clearPageUserSheet() | 189 void StyleEngine::clearPageUserSheet() |
| 190 { | 190 { |
| 191 if (m_pageUserSheet) { | 191 if (m_pageUserSheet) { |
| 192 RefPtr<StyleSheet> removedSheet = m_pageUserSheet; | 192 RefPtr<StyleSheet> removedSheet = m_pageUserSheet; |
| 193 m_pageUserSheet = 0; | 193 m_pageUserSheet = 0; |
| 194 m_document.removedStyleSheet(removedSheet.get()); | 194 m_document.removedStyleSheet(removedSheet.get()); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void StyleSheetCollections::updatePageUserSheet() | 198 void StyleEngine::updatePageUserSheet() |
| 199 { | 199 { |
| 200 clearPageUserSheet(); | 200 clearPageUserSheet(); |
| 201 // FIXME: Why is this immediately and not defer? | 201 // FIXME: Why is this immediately and not defer? |
| 202 if (StyleSheet* addedSheet = pageUserSheet()) | 202 if (StyleSheet* addedSheet = pageUserSheet()) |
| 203 m_document.addedStyleSheet(addedSheet, RecalcStyleImmediately); | 203 m_document.addedStyleSheet(addedSheet, RecalcStyleImmediately); |
| 204 } | 204 } |
| 205 | 205 |
| 206 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedUserStyleSh
eets() const | 206 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedUserStyleSheets() con
st |
| 207 { | 207 { |
| 208 updateInjectedStyleSheetCache(); | 208 updateInjectedStyleSheetCache(); |
| 209 return m_injectedUserStyleSheets; | 209 return m_injectedUserStyleSheets; |
| 210 } | 210 } |
| 211 | 211 |
| 212 const Vector<RefPtr<CSSStyleSheet> >& StyleSheetCollections::injectedAuthorStyle
Sheets() const | 212 const Vector<RefPtr<CSSStyleSheet> >& StyleEngine::injectedAuthorStyleSheets() c
onst |
| 213 { | 213 { |
| 214 updateInjectedStyleSheetCache(); | 214 updateInjectedStyleSheetCache(); |
| 215 return m_injectedAuthorStyleSheets; | 215 return m_injectedAuthorStyleSheets; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void StyleSheetCollections::updateInjectedStyleSheetCache() const | 218 void StyleEngine::updateInjectedStyleSheetCache() const |
| 219 { | 219 { |
| 220 if (m_injectedStyleSheetCacheValid) | 220 if (m_injectedStyleSheetCacheValid) |
| 221 return; | 221 return; |
| 222 m_injectedStyleSheetCacheValid = true; | 222 m_injectedStyleSheetCacheValid = true; |
| 223 m_injectedUserStyleSheets.clear(); | 223 m_injectedUserStyleSheets.clear(); |
| 224 m_injectedAuthorStyleSheets.clear(); | 224 m_injectedAuthorStyleSheets.clear(); |
| 225 | 225 |
| 226 Page* owningPage = m_document.page(); | 226 Page* owningPage = m_document.page(); |
| 227 if (!owningPage) | 227 if (!owningPage) |
| 228 return; | 228 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 bool isUserStyleSheet = sheet->level() == UserStyleUserLevel; | 239 bool isUserStyleSheet = sheet->level() == UserStyleUserLevel; |
| 240 if (isUserStyleSheet) | 240 if (isUserStyleSheet) |
| 241 m_injectedUserStyleSheets.append(groupSheet); | 241 m_injectedUserStyleSheets.append(groupSheet); |
| 242 else | 242 else |
| 243 m_injectedAuthorStyleSheets.append(groupSheet); | 243 m_injectedAuthorStyleSheets.append(groupSheet); |
| 244 groupSheet->contents()->setIsUserStyleSheet(isUserStyleSheet); | 244 groupSheet->contents()->setIsUserStyleSheet(isUserStyleSheet); |
| 245 groupSheet->contents()->parseString(sheet->source()); | 245 groupSheet->contents()->parseString(sheet->source()); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void StyleSheetCollections::invalidateInjectedStyleSheetCache() | 249 void StyleEngine::invalidateInjectedStyleSheetCache() |
| 250 { | 250 { |
| 251 m_injectedStyleSheetCacheValid = false; | 251 m_injectedStyleSheetCacheValid = false; |
| 252 m_needsDocumentStyleSheetsUpdate = true; | 252 m_needsDocumentStyleSheetsUpdate = true; |
| 253 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets | 253 // FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollectio
n::updateActiveStyleSheets |
| 254 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). | 254 // and batch updates lots of sheets so we can't call addedStyleSheet() or re
movedStyleSheet(). |
| 255 m_document.styleResolverChanged(RecalcStyleDeferred); | 255 m_document.styleResolverChanged(RecalcStyleDeferred); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void StyleSheetCollections::addAuthorSheet(PassRefPtr<StyleSheetContents> author
Sheet) | 258 void StyleEngine::addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet) |
| 259 { | 259 { |
| 260 ASSERT(!authorSheet->isUserStyleSheet()); | 260 ASSERT(!authorSheet->isUserStyleSheet()); |
| 261 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, &m_document)); | 261 m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, &m_document)); |
| 262 m_document.addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); | 262 m_document.addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImme
diately); |
| 263 m_needsDocumentStyleSheetsUpdate = true; | 263 m_needsDocumentStyleSheetsUpdate = true; |
| 264 } | 264 } |
| 265 | 265 |
| 266 void StyleSheetCollections::addUserSheet(PassRefPtr<StyleSheetContents> userShee
t) | 266 void StyleEngine::addUserSheet(PassRefPtr<StyleSheetContents> userSheet) |
| 267 { | 267 { |
| 268 ASSERT(userSheet->isUserStyleSheet()); | 268 ASSERT(userSheet->isUserStyleSheet()); |
| 269 m_userStyleSheets.append(CSSStyleSheet::create(userSheet, &m_document)); | 269 m_userStyleSheets.append(CSSStyleSheet::create(userSheet, &m_document)); |
| 270 m_document.addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmedi
ately); | 270 m_document.addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmedi
ately); |
| 271 m_needsDocumentStyleSheetsUpdate = true; | 271 m_needsDocumentStyleSheetsUpdate = true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 // This method is called whenever a top-level stylesheet has finished loading. | 274 // This method is called whenever a top-level stylesheet has finished loading. |
| 275 void StyleSheetCollections::removePendingSheet(Node* styleSheetCandidateNode, Re
movePendingSheetNotificationType notification) | 275 void StyleEngine::removePendingSheet(Node* styleSheetCandidateNode, RemovePendin
gSheetNotificationType notification) |
| 276 { | 276 { |
| 277 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. | 277 // Make sure we knew this sheet was pending, and that our count isn't out of
sync. |
| 278 ASSERT(m_pendingStylesheets > 0); | 278 ASSERT(m_pendingStylesheets > 0); |
| 279 | 279 |
| 280 m_pendingStylesheets--; | 280 m_pendingStylesheets--; |
| 281 | 281 |
| 282 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? &styleS
heetCandidateNode->treeScope() : &m_document; | 282 TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? &styleS
heetCandidateNode->treeScope() : &m_document; |
| 283 if (treeScope == &m_document) | 283 if (treeScope == &m_document) |
| 284 m_needsDocumentStyleSheetsUpdate = true; | 284 m_needsDocumentStyleSheetsUpdate = true; |
| 285 else | 285 else |
| 286 m_dirtyTreeScopes.add(treeScope); | 286 m_dirtyTreeScopes.add(treeScope); |
| 287 | 287 |
| 288 if (m_pendingStylesheets) | 288 if (m_pendingStylesheets) |
| 289 return; | 289 return; |
| 290 | 290 |
| 291 if (notification == RemovePendingSheetNotifyLater) { | 291 if (notification == RemovePendingSheetNotifyLater) { |
| 292 m_document.setNeedsNotifyRemoveAllPendingStylesheet(); | 292 m_document.setNeedsNotifyRemoveAllPendingStylesheet(); |
| 293 return; | 293 return; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know | 296 // FIXME: We can't call addedStyleSheet or removedStyleSheet here because we
don't know |
| 297 // what's new. We should track that to tell the style system what changed. | 297 // what's new. We should track that to tell the style system what changed. |
| 298 m_document.didRemoveAllPendingStylesheet(); | 298 m_document.didRemoveAllPendingStylesheet(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void StyleSheetCollections::addStyleSheetCandidateNode(Node* node, bool createdB
yParser) | 301 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) |
| 302 { | 302 { |
| 303 if (!node->inDocument()) | 303 if (!node->inDocument()) |
| 304 return; | 304 return; |
| 305 | 305 |
| 306 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; | 306 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; |
| 307 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 307 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); |
| 308 | 308 |
| 309 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); | 309 StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); |
| 310 ASSERT(collection); | 310 ASSERT(collection); |
| 311 collection->addStyleSheetCandidateNode(node, createdByParser); | 311 collection->addStyleSheetCandidateNode(node, createdByParser); |
| 312 | 312 |
| 313 if (&treeScope == &m_document) { | 313 if (&treeScope == &m_document) { |
| 314 m_needsDocumentStyleSheetsUpdate = true; | 314 m_needsDocumentStyleSheetsUpdate = true; |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); | 318 insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); |
| 319 m_dirtyTreeScopes.add(&treeScope); | 319 m_dirtyTreeScopes.add(&treeScope); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void StyleSheetCollections::removeStyleSheetCandidateNode(Node* node, ContainerN
ode* scopingNode) | 322 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi
ngNode) |
| 323 { | 323 { |
| 324 TreeScope& treeScope = scopingNode ? scopingNode->treeScope() : m_document; | 324 TreeScope& treeScope = scopingNode ? scopingNode->treeScope() : m_document; |
| 325 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 325 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); |
| 326 | 326 |
| 327 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); | 327 StyleSheetCollection* collection = styleSheetCollectionFor(treeScope); |
| 328 ASSERT(collection); | 328 ASSERT(collection); |
| 329 collection->removeStyleSheetCandidateNode(node, scopingNode); | 329 collection->removeStyleSheetCandidateNode(node, scopingNode); |
| 330 | 330 |
| 331 if (&treeScope == &m_document) { | 331 if (&treeScope == &m_document) { |
| 332 m_needsDocumentStyleSheetsUpdate = true; | 332 m_needsDocumentStyleSheetsUpdate = true; |
| 333 return; | 333 return; |
| 334 } | 334 } |
| 335 m_dirtyTreeScopes.add(&treeScope); | 335 m_dirtyTreeScopes.add(&treeScope); |
| 336 m_activeTreeScopes.remove(&treeScope); | 336 m_activeTreeScopes.remove(&treeScope); |
| 337 } | 337 } |
| 338 | 338 |
| 339 void StyleSheetCollections::modifiedStyleSheetCandidateNode(Node* node) | 339 void StyleEngine::modifiedStyleSheetCandidateNode(Node* node) |
| 340 { | 340 { |
| 341 if (!node->inDocument()) | 341 if (!node->inDocument()) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; | 344 TreeScope& treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_docu
ment; |
| 345 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); | 345 ASSERT(isHTMLStyleElement(node) || &treeScope == &m_document); |
| 346 if (&treeScope == &m_document) { | 346 if (&treeScope == &m_document) { |
| 347 m_needsDocumentStyleSheetsUpdate = true; | 347 m_needsDocumentStyleSheetsUpdate = true; |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 m_dirtyTreeScopes.add(&treeScope); | 350 m_dirtyTreeScopes.add(&treeScope); |
| 351 } | 351 } |
| 352 | 352 |
| 353 bool StyleSheetCollections::shouldUpdateShadowTreeStyleSheetCollection(StyleReso
lverUpdateMode updateMode) | 353 bool StyleEngine::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdate
Mode updateMode) |
| 354 { | 354 { |
| 355 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; | 355 return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate; |
| 356 } | 356 } |
| 357 | 357 |
| 358 bool StyleSheetCollections::updateActiveStyleSheets(StyleResolverUpdateMode upda
teMode) | 358 bool StyleEngine::updateActiveStyleSheets(StyleResolverUpdateMode updateMode) |
| 359 { | 359 { |
| 360 if (m_document.inStyleRecalc()) { | 360 if (m_document.inStyleRecalc()) { |
| 361 // SVG <use> element may manage to invalidate style selector in the midd
le of a style recalc. | 361 // SVG <use> element may manage to invalidate style selector in the midd
le of a style recalc. |
| 362 // https://bugs.webkit.org/show_bug.cgi?id=54344 | 362 // https://bugs.webkit.org/show_bug.cgi?id=54344 |
| 363 // FIXME: This should be fixed in SVG and the call site replaced by ASSE
RT(!m_inStyleRecalc). | 363 // FIXME: This should be fixed in SVG and the call site replaced by ASSE
RT(!m_inStyleRecalc). |
| 364 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; | 364 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; |
| 365 return false; | 365 return false; |
| 366 | 366 |
| 367 } | 367 } |
| 368 if (!m_document.renderer() || !m_document.attached()) | 368 if (!m_document.renderer() || !m_document.attached()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); | 401 m_usesRemUnits = m_documentStyleSheetCollection.usesRemUnits(); |
| 402 | 402 |
| 403 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) { | 403 if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) { |
| 404 m_document.notifySeamlessChildDocumentsOfStylesheetUpdate(); | 404 m_document.notifySeamlessChildDocumentsOfStylesheetUpdate(); |
| 405 m_needsDocumentStyleSheetsUpdate = false; | 405 m_needsDocumentStyleSheetsUpdate = false; |
| 406 } | 406 } |
| 407 | 407 |
| 408 return requiresFullStyleRecalc; | 408 return requiresFullStyleRecalc; |
| 409 } | 409 } |
| 410 | 410 |
| 411 void StyleSheetCollections::activeStyleSheetsUpdatedForInspector() | 411 void StyleEngine::activeStyleSheetsUpdatedForInspector() |
| 412 { | 412 { |
| 413 if (m_activeTreeScopes.isEmpty()) { | 413 if (m_activeTreeScopes.isEmpty()) { |
| 414 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, m_docume
ntStyleSheetCollection.styleSheetsForStyleSheetList()); | 414 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, m_docume
ntStyleSheetCollection.styleSheetsForStyleSheetList()); |
| 415 return; | 415 return; |
| 416 } | 416 } |
| 417 Vector<RefPtr<StyleSheet> > activeStyleSheets; | 417 Vector<RefPtr<StyleSheet> > activeStyleSheets; |
| 418 | 418 |
| 419 activeStyleSheets.append(m_documentStyleSheetCollection.styleSheetsForStyleS
heetList()); | 419 activeStyleSheets.append(m_documentStyleSheetCollection.styleSheetsForStyleS
heetList()); |
| 420 | 420 |
| 421 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 421 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 422 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 422 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 423 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 423 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 424 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) | 424 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) |
| 425 activeStyleSheets.append(collection->styleSheetsForStyleSheetList())
; | 425 activeStyleSheets.append(collection->styleSheetsForStyleSheetList())
; |
| 426 } | 426 } |
| 427 | 427 |
| 428 // FIXME: Inspector needs a vector which has all active stylesheets. | 428 // FIXME: Inspector needs a vector which has all active stylesheets. |
| 429 // However, creating such a large vector might cause performance regression. | 429 // However, creating such a large vector might cause performance regression. |
| 430 // Need to implement some smarter solution. | 430 // Need to implement some smarter solution. |
| 431 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, activeStyleS
heets); | 431 InspectorInstrumentation::activeStyleSheetsUpdated(&m_document, activeStyleS
heets); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void StyleSheetCollections::didRemoveShadowRoot(ShadowRoot* shadowRoot) | 434 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot) |
| 435 { | 435 { |
| 436 m_styleSheetCollectionMap.remove(shadowRoot); | 436 m_styleSheetCollectionMap.remove(shadowRoot); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void StyleSheetCollections::appendActiveAuthorStyleSheets(StyleResolver* styleRe
solver) | 439 void StyleEngine::appendActiveAuthorStyleSheets(StyleResolver* styleResolver) |
| 440 { | 440 { |
| 441 ASSERT(styleResolver); | 441 ASSERT(styleResolver); |
| 442 | 442 |
| 443 styleResolver->setBuildScopedStyleTreeInDocumentOrder(true); | 443 styleResolver->setBuildScopedStyleTreeInDocumentOrder(true); |
| 444 styleResolver->appendAuthorStyleSheets(0, m_documentStyleSheetCollection.act
iveAuthorStyleSheets()); | 444 styleResolver->appendAuthorStyleSheets(0, m_documentStyleSheetCollection.act
iveAuthorStyleSheets()); |
| 445 | 445 |
| 446 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); | 446 TreeScopeSet::iterator begin = m_activeTreeScopes.begin(); |
| 447 TreeScopeSet::iterator end = m_activeTreeScopes.end(); | 447 TreeScopeSet::iterator end = m_activeTreeScopes.end(); |
| 448 for (TreeScopeSet::iterator it = begin; it != end; ++it) { | 448 for (TreeScopeSet::iterator it = begin; it != end; ++it) { |
| 449 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { | 449 if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it
)) { |
| 450 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); | 450 styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->s
copingNodesForStyleScoped()); |
| 451 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); | 451 styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorSt
yleSheets()); |
| 452 } | 452 } |
| 453 } | 453 } |
| 454 styleResolver->finishAppendAuthorStyleSheets(); | 454 styleResolver->finishAppendAuthorStyleSheets(); |
| 455 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); | 455 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); |
| 456 } | 456 } |
| 457 | 457 |
| 458 } | 458 } |
| OLD | NEW |