1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 5 * (C) 2006 Alexey Proskuryakov (ap (at) webkit.org) 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2013 Google Inc. All rights reserved. 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Library General Public 13 * License as published by the Free Software Foundation; either 14 * version 2 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Library General Public License for more details. 20 * 21 * You should have received a copy of the GNU Library General Public License 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, 24 * Boston, MA 02110-1301, USA. 25 */ 26 27 #include "config.h" 28 #include "core/dom/DocumentStyleSheetCollection.h" 29 30 #include "core/css/resolver/StyleResolver.h" 31 #include "core/dom/Document.h" 32 #include "core/dom/DocumentStyleSheetCollector.h" 33 #include "core/dom/ProcessingInstruction.h" 34 #include "core/dom/StyleEngine.h" 35 #include "core/dom/StyleSheetCandidate.h" 36 #include "platform/RuntimeEnabledFeatures.h" 37 38 namespace WebCore { 39 40 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) 41 : TreeScopeStyleSheetCollection(treeScope) 42 { 43 ASSERT(treeScope.rootNode() == treeScope.rootNode().document()); 44 } 45 46 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(StyleEngine* engine, DocumentStyleSheetCollector& collector) 47 { 48 DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin(); 49 DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end(); 50 for (DocumentOrderedList::iterator it = begin; it != end; ++it) { 51 Node* n = *it; 52 StyleSheetCandidate candidate(*n); 53 54 ASSERT(!candidate.isXSL()); 55 if (candidate.isImport()) { 56 Document* document = candidate.importedDocument(); 57 if (!document) 58 continue; 59 if (collector.hasVisited(document)) 60 continue; 61 collector.willVisit(document); 62 document->styleEngine()->updateStyleSheetsInImport(collector); 63 continue; 64 } 65 66 if (candidate.isEnabledAndLoading()) { 67 // it is loading but we should still decide which style sheet set to use 68 if (candidate.hasPreferrableName(engine->preferredStylesheetSetName())) 69 engine->selectStylesheetSetName(candidate.title()); 70 continue; 71 } 72 73 StyleSheet* sheet = candidate.sheet(); 74 if (!sheet) 75 continue; 76 77 if (candidate.hasPreferrableName(engine->preferredStylesheetSetName())) 78 engine->selectStylesheetSetName(candidate.title()); 79 collector.appendSheetForList(sheet); 80 if (candidate.canBeActivated(engine->preferredStylesheetSetName())) 81 collector.appendActiveStyleSheet(toCSSStyleSheet(sheet)); 82 } 83 } 84 85 void DocumentStyleSheetCollection::collectStyleSheets(StyleEngine* engine, DocumentStyleSheetCollector& collector) 86 { 87 ASSERT(document().styleEngine() == engine); 88 collector.appendActiveStyleSheets(engine->injectedAuthorStyleSheets()); 89 collector.appendActiveStyleSheets(engine->documentAuthorStyleSheets()); 90 collectStyleSheetsFromCandidates(engine, collector); 91 } 92 93 void DocumentStyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine, StyleResolverUpdateMode updateMode) 94 { 95 StyleSheetCollection collection; 96 ActiveDocumentStyleSheetCollector collector(collection); 97 collectStyleSheets(engine, collector); 98 99 StyleSheetChange change; 100 analyzeStyleSheetChange(updateMode, collection, change); 101 102 if (change.styleResolverUpdateType == Reconstruct) { 103 engine->clearMasterResolver(); 104 // FIMXE: The following depends on whether StyleRuleFontFace was modified or not. 105 // No need to always-clear font cache. 106 engine->clearFontCache(); 107 } else if (StyleResolver* styleResolver = engine->resolver()) { 108 // FIXME: We might have already had styles in child treescope. In this case, we cannot use buildScopedStyleTreeInDocumentOrder. 109 // Need to change "false" to some valid condition. 110 styleResolver->setBuildScopedStyleTreeInDocumentOrder(false); 111 if (change.styleResolverUpdateType != Additive) { 112 ASSERT(change.styleResolverUpdateType == Reset); 113 resetAllRuleSetsInTreeScope(styleResolver); 114 engine->removeFontFaceRules(change.fontFaceRulesToRemove); 115 styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets); 116 styleResolver->lazyAppendAuthorStyleSheets(0, collection.activeAuthorStyleSheets()); 117 } else { 118 styleResolver->lazyAppendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), collection.activeAuthorStyleSheets()); 119 } 120 } 121 if (change.requiresFullStyleRecalc) 122 document().setNeedsStyleRecalc(SubtreeStyleChange); 123 124 m_scopingNodesForStyleScoped.didRemoveScopingNodes(); 125 126 collection.swap(*this); 127 128 updateUsesRemUnits(); 129 } 130 131 } 132