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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "HTMLNames.h" | 30 #include "HTMLNames.h" |
31 #include "RuntimeEnabledFeatures.h" | 31 #include "RuntimeEnabledFeatures.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/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/dom/Element.h" | 36 #include "core/dom/Element.h" |
37 #include "core/dom/ProcessingInstruction.h" | 37 #include "core/dom/ProcessingInstruction.h" |
38 #include "core/dom/StyleEngine.h" | 38 #include "core/dom/StyleEngine.h" |
| 39 #include "core/dom/StyleSheetCandidate.h" |
39 #include "core/html/HTMLIFrameElement.h" | 40 #include "core/html/HTMLIFrameElement.h" |
40 #include "core/html/HTMLLinkElement.h" | 41 #include "core/html/HTMLLinkElement.h" |
41 #include "core/html/HTMLStyleElement.h" | 42 #include "core/html/HTMLStyleElement.h" |
42 #include "core/frame/Settings.h" | 43 #include "core/frame/Settings.h" |
43 #include "core/svg/SVGStyleElement.h" | 44 #include "core/svg/SVGStyleElement.h" |
44 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 using namespace HTMLNames; | 48 using namespace HTMLNames; |
48 | 49 |
49 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) | 50 DocumentStyleSheetCollection::DocumentStyleSheetCollection(TreeScope& treeScope) |
50 : StyleSheetCollection(treeScope) | 51 : StyleSheetCollection(treeScope) |
51 { | 52 { |
52 ASSERT(treeScope.rootNode() == treeScope.rootNode()->document()); | 53 ASSERT(treeScope.rootNode() == treeScope.rootNode()->document()); |
53 } | 54 } |
54 | 55 |
55 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(StyleEngine*
engine, StyleSheetCollectionBase& collection, DocumentStyleSheetCollection::Col
lectFor collectFor) | 56 void DocumentStyleSheetCollection::collectStyleSheetsFromCandidates(StyleEngine*
engine, StyleSheetCollectionBase& collection, DocumentStyleSheetCollection::Col
lectFor collectFor) |
56 { | 57 { |
57 DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin(); | 58 DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin(); |
58 DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end(); | 59 DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end(); |
59 for (DocumentOrderedList::iterator it = begin; it != end; ++it) { | 60 for (DocumentOrderedList::iterator it = begin; it != end; ++it) { |
60 Node* n = *it; | 61 Node* n = *it; |
61 StyleSheet* sheet = 0; | 62 StyleSheetCandidate candidate(*n); |
62 CSSStyleSheet* activeSheet = 0; | 63 |
63 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE && !document()->i
sHTMLDocument()) { | 64 if (candidate.isXSL()) { |
64 // Processing instruction (XML documents only). | 65 // Processing instruction (XML documents only). |
65 // We don't support linking to embedded CSS stylesheets, see <https:
//bugs.webkit.org/show_bug.cgi?id=49281> for discussion. | 66 // We don't support linking to embedded CSS stylesheets, see <https:
//bugs.webkit.org/show_bug.cgi?id=49281> for discussion. |
66 ProcessingInstruction* pi = toProcessingInstruction(n); | |
67 // Don't apply XSL transforms to already transformed documents -- <r
dar://problem/4132806> | 67 // Don't apply XSL transforms to already transformed documents -- <r
dar://problem/4132806> |
68 if (RuntimeEnabledFeatures::xsltEnabled() && pi->isXSL() && !documen
t()->transformSourceDocument()) { | 68 if (RuntimeEnabledFeatures::xsltEnabled() && !document()->transformS
ourceDocument()) { |
| 69 ProcessingInstruction* pi = toProcessingInstruction(n); |
69 // Don't apply XSL transforms until loading is finished. | 70 // Don't apply XSL transforms until loading is finished. |
70 if (!document()->parsing() && !pi->isLoading()) | 71 if (!document()->parsing() && !pi->isLoading()) |
71 document()->applyXSLTransform(pi); | 72 document()->applyXSLTransform(pi); |
72 return; | 73 return; |
73 } | 74 } |
74 sheet = pi->sheet(); | |
75 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet()) | |
76 activeSheet = toCSSStyleSheet(sheet); | |
77 } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagNa
me(styleTag))) || (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))) { | |
78 Element* e = toElement(n); | |
79 AtomicString title = e->getAttribute(titleAttr); | |
80 bool enabledViaScript = false; | |
81 if (e->hasLocalName(linkTag)) { | |
82 // <LINK> element | |
83 HTMLLinkElement* linkElement = toHTMLLinkElement(n); | |
84 enabledViaScript = linkElement->isEnabledViaScript(); | |
85 if (!linkElement->isDisabled() && linkElement->styleSheetIsLoadi
ng()) { | |
86 // it is loading but we should still decide which style shee
t set to use | |
87 if (!enabledViaScript && !title.isEmpty() && engine->preferr
edStylesheetSetName().isEmpty()) { | |
88 const AtomicString& rel = e->getAttribute(relAttr); | |
89 if (!rel.contains("alternate")) { | |
90 engine->setPreferredStylesheetSetName(title); | |
91 engine->setSelectedStylesheetSetName(title); | |
92 } | |
93 } | |
94 | 75 |
95 continue; | 76 continue; |
96 } | |
97 sheet = linkElement->sheet(); | |
98 if (!sheet) | |
99 title = nullAtom; | |
100 } else if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag)) { | |
101 sheet = toSVGStyleElement(n)->sheet(); | |
102 } else { | |
103 sheet = toHTMLStyleElement(n)->sheet(); | |
104 } | |
105 | |
106 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet()) | |
107 activeSheet = toCSSStyleSheet(sheet); | |
108 | |
109 // Check to see if this sheet belongs to a styleset | |
110 // (thus making it PREFERRED or ALTERNATE rather than | |
111 // PERSISTENT). | |
112 AtomicString rel = e->getAttribute(relAttr); | |
113 if (!enabledViaScript && sheet && !title.isEmpty()) { | |
114 // Yes, we have a title. | |
115 if (engine->preferredStylesheetSetName().isEmpty()) { | |
116 // No preferred set has been established. If | |
117 // we are NOT an alternate sheet, then establish | |
118 // us as the preferred set. Otherwise, just ignore | |
119 // this sheet. | |
120 if (e->hasLocalName(styleTag) || !rel.contains("alternate"))
{ | |
121 engine->setPreferredStylesheetSetName(title); | |
122 engine->setSelectedStylesheetSetName(title); | |
123 } | |
124 } | |
125 if (title != engine->preferredStylesheetSetName()) | |
126 activeSheet = 0; | |
127 } | |
128 | |
129 if (rel.contains("alternate") && title.isEmpty()) | |
130 activeSheet = 0; | |
131 } | 77 } |
132 | 78 |
133 if (sheet && collectFor == CollectForList) | 79 if (candidate.isEnabledAndLoading()) { |
| 80 // it is loading but we should still decide which style sheet set to
use |
| 81 if (candidate.hasPreferrableName(engine->preferredStylesheetSetName(
))) |
| 82 engine->selectStylesheetSetName(candidate.title()); |
| 83 continue; |
| 84 } |
| 85 |
| 86 StyleSheet* sheet = candidate.sheet(); |
| 87 if (!sheet) |
| 88 continue; |
| 89 |
| 90 if (candidate.hasPreferrableName(engine->preferredStylesheetSetName())) |
| 91 engine->selectStylesheetSetName(candidate.title()); |
| 92 if (collectFor == CollectForList) |
134 collection.appendSheetForList(sheet); | 93 collection.appendSheetForList(sheet); |
135 if (activeSheet) | 94 if (candidate.canBeActivated(engine->preferredStylesheetSetName())) |
136 collection.appendActiveStyleSheet(activeSheet); | 95 collection.appendActiveStyleSheet(toCSSStyleSheet(sheet)); |
137 } | 96 } |
138 } | 97 } |
139 | 98 |
140 static void collectActiveCSSStyleSheetsFromSeamlessParents(StyleSheetCollectionB
ase& collection, Document* document) | 99 static void collectActiveCSSStyleSheetsFromSeamlessParents(StyleSheetCollectionB
ase& collection, Document* document) |
141 { | 100 { |
142 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame(); | 101 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame(); |
143 if (!seamlessParentIFrame) | 102 if (!seamlessParentIFrame) |
144 return; | 103 return; |
145 collection.appendActiveStyleSheets(seamlessParentIFrame->document().styleEng
ine()->activeAuthorStyleSheets()); | 104 collection.appendActiveStyleSheets(seamlessParentIFrame->document().styleEng
ine()->activeAuthorStyleSheets()); |
146 } | 105 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 engine->resetFontSelector(); | 142 engine->resetFontSelector(); |
184 } | 143 } |
185 m_scopingNodesForStyleScoped.didRemoveScopingNodes(); | 144 m_scopingNodesForStyleScoped.didRemoveScopingNodes(); |
186 collection.swap(*this); | 145 collection.swap(*this); |
187 updateUsesRemUnits(); | 146 updateUsesRemUnits(); |
188 | 147 |
189 return change.requiresFullStyleRecalc; | 148 return change.requiresFullStyleRecalc; |
190 } | 149 } |
191 | 150 |
192 } | 151 } |
OLD | NEW |