| 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 * |
| 11 * This library is free software; you can redistribute it and/or | 11 * This library is free software; you can redistribute it and/or |
| 12 * modify it under the terms of the GNU Library General Public | 12 * modify it under the terms of the GNU Library General Public |
| 13 * License as published by the Free Software Foundation; either | 13 * License as published by the Free Software Foundation; either |
| 14 * version 2 of the License, or (at your option) any later version. | 14 * version 2 of the License, or (at your option) any later version. |
| 15 * | 15 * |
| 16 * This library is distributed in the hope that it will be useful, | 16 * This library is distributed in the hope that it will be useful, |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 * Library General Public License for more details. | 19 * Library General Public License for more details. |
| 20 * | 20 * |
| 21 * You should have received a copy of the GNU Library General Public License | 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 | 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 "core/dom/DocumentStyleSheetCollection.h" | 27 #include "core/dom/DocumentStyleSheetCollection.h" |
| 28 | 28 |
| 29 #include "core/css/StyleSheetContents.h" |
| 29 #include "core/css/resolver/StyleResolver.h" | 30 #include "core/css/resolver/StyleResolver.h" |
| 31 #include "core/css/resolver/ViewportStyleResolver.h" |
| 30 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 31 #include "core/dom/DocumentStyleSheetCollector.h" | 33 #include "core/dom/DocumentStyleSheetCollector.h" |
| 32 #include "core/dom/ProcessingInstruction.h" | 34 #include "core/dom/ProcessingInstruction.h" |
| 33 #include "core/dom/StyleChangeReason.h" | 35 #include "core/dom/StyleChangeReason.h" |
| 34 #include "core/dom/StyleEngine.h" | 36 #include "core/dom/StyleEngine.h" |
| 35 #include "core/dom/StyleSheetCandidate.h" | 37 #include "core/dom/StyleSheetCandidate.h" |
| 36 #include "platform/RuntimeEnabledFeatures.h" | 38 #include "platform/RuntimeEnabledFeatures.h" |
| 37 | 39 |
| 38 namespace blink { | 40 namespace blink { |
| 39 | 41 |
| 40 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) | 42 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) |
| 41 : TreeScopeStyleSheetCollection(treeScope) | 43 : TreeScopeStyleSheetCollection(treeScope) |
| 42 { | 44 { |
| 43 DCHECK_EQ(treeScope.rootNode(), treeScope.rootNode().document()); | 45 DCHECK_EQ(treeScope.rootNode(), treeScope.rootNode().document()); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(StyleEngine&
engine, DocumentStyleSheetCollector& collector) | 48 void DocumentStyleSheetCollection::updateViewport() |
| 49 { |
| 50 ViewportStyleResolver& resolver = document().styleEngine().ensureViewportSty
leResolver(); |
| 51 |
| 52 resolver.reset(); |
| 53 resolver.collectViewportRulesFromUASheets(); |
| 54 |
| 55 for (Node* node : m_styleSheetCandidateNodes) { |
| 56 StyleSheetCandidate candidate(*node); |
| 57 |
| 58 if (candidate.isImport()) |
| 59 continue; |
| 60 StyleSheet* sheet = candidate.sheet(); |
| 61 if (!sheet) |
| 62 continue; |
| 63 if (!candidate.canBeActivated(document().styleEngine().preferredStyleshe
etSetName())) |
| 64 continue; |
| 65 resolver.collectViewportRulesFromAuthorSheet(*toCSSStyleSheet(sheet)); |
| 66 } |
| 67 |
| 68 resolver.resolve(); |
| 69 } |
| 70 |
| 71 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(DocumentStyl
eSheetCollector& collector) |
| 47 { | 72 { |
| 48 for (Node* n : m_styleSheetCandidateNodes) { | 73 for (Node* n : m_styleSheetCandidateNodes) { |
| 49 StyleSheetCandidate candidate(*n); | 74 StyleSheetCandidate candidate(*n); |
| 50 | 75 |
| 51 DCHECK(!candidate.isXSL()); | 76 DCHECK(!candidate.isXSL()); |
| 52 if (candidate.isImport()) { | 77 if (candidate.isImport()) { |
| 53 Document* document = candidate.importedDocument(); | 78 Document* document = candidate.importedDocument(); |
| 54 if (!document) | 79 if (!document) |
| 55 continue; | 80 continue; |
| 56 if (collector.hasVisited(document)) | 81 if (collector.hasVisited(document)) |
| 57 continue; | 82 continue; |
| 58 collector.willVisit(document); | 83 collector.willVisit(document); |
| 59 document->styleEngine().updateStyleSheetsInImport(collector); | 84 document->styleEngine().updateStyleSheetsInImport(collector); |
| 60 continue; | 85 continue; |
| 61 } | 86 } |
| 62 | 87 |
| 63 if (candidate.isEnabledAndLoading()) { | 88 if (candidate.isEnabledAndLoading()) |
| 64 // it is loading but we should still decide which style sheet set to
use | |
| 65 if (candidate.hasPreferrableName()) | |
| 66 engine.setPreferredStylesheetSetNameIfNotSet(candidate.title()); | |
| 67 continue; | 89 continue; |
| 68 } | |
| 69 | 90 |
| 70 StyleSheet* sheet = candidate.sheet(); | 91 StyleSheet* sheet = candidate.sheet(); |
| 71 if (!sheet) | 92 if (!sheet) |
| 72 continue; | 93 continue; |
| 73 | 94 |
| 74 if (candidate.hasPreferrableName()) | |
| 75 engine.setPreferredStylesheetSetNameIfNotSet(candidate.title()); | |
| 76 collector.appendSheetForList(sheet); | 95 collector.appendSheetForList(sheet); |
| 77 if (candidate.canBeActivated(engine.preferredStylesheetSetName())) | 96 |
| 78 collector.appendActiveStyleSheet(toCSSStyleSheet(sheet)); | 97 if (!candidate.canBeActivated(document().styleEngine().preferredStyleshe
etSetName())) |
| 98 continue; |
| 99 |
| 100 CSSStyleSheet* cssSheet = toCSSStyleSheet(sheet); |
| 101 collector.appendActiveStyleSheet(std::make_pair(cssSheet, &document().st
yleEngine().ensureRuleSetForSheet(*cssSheet))); |
| 79 } | 102 } |
| 80 } | 103 } |
| 81 | 104 |
| 82 void DocumentStyleSheetCollection::collectStyleSheets(StyleEngine& engine, Docum
entStyleSheetCollector& collector) | 105 void DocumentStyleSheetCollection::collectStyleSheets(DocumentStyleSheetCollecto
r& collector) |
| 83 { | 106 { |
| 84 DCHECK_EQ(&document().styleEngine(), &engine); | 107 for (auto& sheet : document().styleEngine().injectedAuthorStyleSheets()) |
| 85 collector.appendActiveStyleSheets(engine.injectedAuthorStyleSheets()); | 108 collector.appendActiveStyleSheet(std::make_pair(sheet, &document().style
Engine().ensureRuleSetForSheet(*sheet))); |
| 86 collectStyleSheetsFromCandidates(engine, collector); | 109 |
| 110 collectStyleSheetsFromCandidates(collector); |
| 87 } | 111 } |
| 88 | 112 |
| 89 void DocumentStyleSheetCollection::updateActiveStyleSheets(StyleEngine& engine,
StyleResolverUpdateMode updateMode) | 113 void DocumentStyleSheetCollection::updateActiveStyleSheets() |
| 90 { | 114 { |
| 91 StyleSheetCollection collection; | 115 StyleSheetCollection collection; |
| 92 ActiveDocumentStyleSheetCollector collector(collection); | 116 ActiveDocumentStyleSheetCollector collector(collection); |
| 93 collectStyleSheets(engine, collector); | 117 collectStyleSheets(collector); |
| 94 | 118 applyActiveStyleSheetChanges(collection); |
| 95 StyleSheetChange change; | |
| 96 analyzeStyleSheetChange(updateMode, collection, change); | |
| 97 | |
| 98 if (change.styleResolverUpdateType == Reconstruct) { | |
| 99 engine.clearMasterResolver(); | |
| 100 // TODO(rune@opera.com): The following depends on whether StyleRuleFontF
ace was modified or not. | |
| 101 // We should only remove modified/removed @font-face rules, or @font-fac
e rules from removed | |
| 102 // stylesheets. We currently avoid clearing the font cache when we have
had an analyzed update | |
| 103 // and no @font-face rules were removed, in which case requiresFullStyle
Recalc will be false. | |
| 104 if (change.requiresFullStyleRecalc) | |
| 105 engine.clearFontCache(); | |
| 106 } else if (StyleResolver* styleResolver = engine.resolver()) { | |
| 107 if (change.styleResolverUpdateType != Additive) { | |
| 108 DCHECK_EQ(change.styleResolverUpdateType, Reset); | |
| 109 styleResolver->resetAuthorStyle(treeScope()); | |
| 110 engine.removeFontFaceRules(change.fontFaceRulesToRemove); | |
| 111 styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleShe
ets); | |
| 112 styleResolver->lazyAppendAuthorStyleSheets(0, collection.activeAutho
rStyleSheets()); | |
| 113 } else { | |
| 114 styleResolver->lazyAppendAuthorStyleSheets(m_activeAuthorStyleSheets
.size(), collection.activeAuthorStyleSheets()); | |
| 115 } | |
| 116 } | |
| 117 if (change.requiresFullStyleRecalc) | |
| 118 document().setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForT
racing::create(StyleChangeReason::ActiveStylesheetsUpdate)); | |
| 119 | |
| 120 collection.swap(*this); | |
| 121 } | 119 } |
| 122 | 120 |
| 123 DEFINE_TRACE_WRAPPERS(DocumentStyleSheetCollection) | 121 DEFINE_TRACE_WRAPPERS(DocumentStyleSheetCollection) |
| 124 { | 122 { |
| 125 for (auto sheet : m_styleSheetsForStyleSheetList) { | 123 for (auto sheet : m_styleSheetsForStyleSheetList) { |
| 126 visitor->traceWrappers(sheet); | 124 visitor->traceWrappers(sheet); |
| 127 } | 125 } |
| 128 } | 126 } |
| 129 } // namespace blink | 127 } // namespace blink |
| OLD | NEW |