OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 12 matching lines...) Expand all Loading... |
23 * You should have received a copy of the GNU Library General Public License | 23 * You should have received a copy of the GNU Library General Public License |
24 * along with this library; see the file COPYING.LIB. If not, write to | 24 * along with this library; see the file COPYING.LIB. If not, write to |
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/css/CSSDefaultStyleSheets.h" | 30 #include "core/css/CSSDefaultStyleSheets.h" |
31 | 31 |
32 #include "core/MathMLNames.h" | 32 #include "core/MathMLNames.h" |
33 #include "core/UserAgentStyleSheets.h" | |
34 #include "core/css/MediaQueryEvaluator.h" | 33 #include "core/css/MediaQueryEvaluator.h" |
35 #include "core/css/RuleSet.h" | 34 #include "core/css/RuleSet.h" |
36 #include "core/css/StyleSheetContents.h" | 35 #include "core/css/StyleSheetContents.h" |
37 #include "core/dom/Fullscreen.h" | 36 #include "core/dom/Fullscreen.h" |
38 #include "core/html/HTMLAnchorElement.h" | 37 #include "core/html/HTMLAnchorElement.h" |
39 #include "core/html/HTMLHtmlElement.h" | 38 #include "core/html/HTMLHtmlElement.h" |
40 #include "core/rendering/RenderTheme.h" | 39 #include "core/rendering/RenderTheme.h" |
| 40 #include "platform/PlatformResourceLoader.h" |
41 #include "wtf/LeakAnnotations.h" | 41 #include "wtf/LeakAnnotations.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 using namespace HTMLNames; | 45 using namespace HTMLNames; |
46 | 46 |
47 CSSDefaultStyleSheets& CSSDefaultStyleSheets::instance() | 47 CSSDefaultStyleSheets& CSSDefaultStyleSheets::instance() |
48 { | 48 { |
49 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSDefaultStyleSheets>, cssDefaul
tStyleSheets, (adoptPtrWillBeNoop(new CSSDefaultStyleSheets()))); | 49 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSDefaultStyleSheets>, cssDefaul
tStyleSheets, (adoptPtrWillBeNoop(new CSSDefaultStyleSheets()))); |
50 return *cssDefaultStyleSheets; | 50 return *cssDefaultStyleSheets; |
(...skipping 14 matching lines...) Expand all Loading... |
65 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const String& str
) | 65 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const String& str
) |
66 { | 66 { |
67 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(CS
SParserContext(UASheetMode, 0)); | 67 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(CS
SParserContext(UASheetMode, 0)); |
68 sheet->parseString(str); | 68 sheet->parseString(str); |
69 // User Agent stylesheets are parsed once for the lifetime of the renderer | 69 // User Agent stylesheets are parsed once for the lifetime of the renderer |
70 // and are intentionally leaked. | 70 // and are intentionally leaked. |
71 WTF_ANNOTATE_LEAKING_OBJECT_PTR(sheet.get()); | 71 WTF_ANNOTATE_LEAKING_OBJECT_PTR(sheet.get()); |
72 return sheet.release(); | 72 return sheet.release(); |
73 } | 73 } |
74 | 74 |
75 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const char* chara
cters, unsigned size) | |
76 { | |
77 return parseUASheet(String(characters, size)); | |
78 } | |
79 | |
80 CSSDefaultStyleSheets::CSSDefaultStyleSheets() | 75 CSSDefaultStyleSheets::CSSDefaultStyleSheets() |
81 : m_defaultStyle(nullptr) | 76 : m_defaultStyle(nullptr) |
82 , m_defaultViewportStyle(nullptr) | 77 , m_defaultViewportStyle(nullptr) |
83 , m_defaultQuirksStyle(nullptr) | 78 , m_defaultQuirksStyle(nullptr) |
84 , m_defaultPrintStyle(nullptr) | 79 , m_defaultPrintStyle(nullptr) |
85 , m_defaultViewSourceStyle(nullptr) | 80 , m_defaultViewSourceStyle(nullptr) |
86 , m_defaultXHTMLMobileProfileStyle(nullptr) | 81 , m_defaultXHTMLMobileProfileStyle(nullptr) |
87 , m_defaultTransitionStyle(nullptr) | 82 , m_defaultTransitionStyle(nullptr) |
88 , m_defaultStyleSheet(nullptr) | 83 , m_defaultStyleSheet(nullptr) |
89 , m_viewportStyleSheet(nullptr) | 84 , m_viewportStyleSheet(nullptr) |
90 , m_quirksStyleSheet(nullptr) | 85 , m_quirksStyleSheet(nullptr) |
91 , m_svgStyleSheet(nullptr) | 86 , m_svgStyleSheet(nullptr) |
92 , m_mathmlStyleSheet(nullptr) | 87 , m_mathmlStyleSheet(nullptr) |
93 , m_mediaControlsStyleSheet(nullptr) | 88 , m_mediaControlsStyleSheet(nullptr) |
94 , m_fullscreenStyleSheet(nullptr) | 89 , m_fullscreenStyleSheet(nullptr) |
95 { | 90 { |
96 m_defaultStyle = RuleSet::create(); | 91 m_defaultStyle = RuleSet::create(); |
97 m_defaultViewportStyle = RuleSet::create(); | 92 m_defaultViewportStyle = RuleSet::create(); |
98 m_defaultPrintStyle = RuleSet::create(); | 93 m_defaultPrintStyle = RuleSet::create(); |
99 m_defaultQuirksStyle = RuleSet::create(); | 94 m_defaultQuirksStyle = RuleSet::create(); |
100 | 95 |
101 // Strict-mode rules. | 96 // Strict-mode rules. |
102 String defaultRules = String(htmlCss, sizeof(htmlCss)) + RenderTheme::theme(
).extraDefaultStyleSheet(); | 97 String defaultRules = loadResourceAsASCIIString("html.css") + RenderTheme::t
heme().extraDefaultStyleSheet(); |
103 m_defaultStyleSheet = parseUASheet(defaultRules); | 98 m_defaultStyleSheet = parseUASheet(defaultRules); |
104 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); | 99 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); |
105 #if OS(ANDROID) | 100 #if OS(ANDROID) |
106 String viewportRules(viewportAndroidCss, sizeof(viewportAndroidCss)); | 101 String viewportRules = loadResourceAsASCIIString("viewportAndroid.css"); |
107 #else | 102 #else |
108 String viewportRules; | 103 String viewportRules; |
109 #endif | 104 #endif |
110 m_viewportStyleSheet = parseUASheet(viewportRules); | 105 m_viewportStyleSheet = parseUASheet(viewportRules); |
111 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); | 106 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); |
112 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); | 107 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); |
113 | 108 |
114 // Quirks-mode rules. | 109 // Quirks-mode rules. |
115 String quirksRules = String(quirksCss, sizeof(quirksCss)) + RenderTheme::the
me().extraQuirksStyleSheet(); | 110 String quirksRules = loadResourceAsASCIIString("quirks.css") + RenderTheme::
theme().extraQuirksStyleSheet(); |
116 m_quirksStyleSheet = parseUASheet(quirksRules); | 111 m_quirksStyleSheet = parseUASheet(quirksRules); |
117 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); | 112 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); |
118 } | 113 } |
119 | 114 |
120 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() | 115 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() |
121 { | 116 { |
122 if (!m_defaultViewSourceStyle) { | 117 if (!m_defaultViewSourceStyle) { |
123 m_defaultViewSourceStyle = RuleSet::create(); | 118 m_defaultViewSourceStyle = RuleSet::create(); |
124 // Loaded stylesheet is leaked on purpose. | 119 // Loaded stylesheet is leaked on purpose. |
125 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(viewSou
rceCss, sizeof(viewSourceCss)); | 120 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("view-source.css")); |
126 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 121 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
127 } | 122 } |
128 return m_defaultViewSourceStyle.get(); | 123 return m_defaultViewSourceStyle.get(); |
129 } | 124 } |
130 | 125 |
131 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() | 126 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() |
132 { | 127 { |
133 if (!m_defaultTransitionStyle) { | 128 if (!m_defaultTransitionStyle) { |
134 m_defaultTransitionStyle = RuleSet::create(); | 129 m_defaultTransitionStyle = RuleSet::create(); |
135 // Loaded stylesheet is leaked on purpose. | 130 // Loaded stylesheet is leaked on purpose. |
136 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat
ionTransitionsCss, sizeof(navigationTransitionsCss)); | 131 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("navigationTransitions.css")); |
137 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 132 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
138 } | 133 } |
139 return m_defaultTransitionStyle.get(); | 134 return m_defaultTransitionStyle.get(); |
140 } | 135 } |
141 | 136 |
142 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() | 137 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() |
143 { | 138 { |
144 if (!m_defaultXHTMLMobileProfileStyle) { | 139 if (!m_defaultXHTMLMobileProfileStyle) { |
145 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); | 140 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); |
146 // Loaded stylesheet is leaked on purpose. | 141 // Loaded stylesheet is leaked on purpose. |
147 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp
Css, sizeof(xhtmlmpCss)); | 142 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("xhtmlmp.css")); |
148 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); | 143 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); |
149 } | 144 } |
150 return m_defaultXHTMLMobileProfileStyle.get(); | 145 return m_defaultXHTMLMobileProfileStyle.get(); |
151 } | 146 } |
152 | 147 |
153 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) | 148 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) |
154 { | 149 { |
155 // FIXME: We should assert that the sheet only styles SVG elements. | 150 // FIXME: We should assert that the sheet only styles SVG elements. |
156 if (element->isSVGElement() && !m_svgStyleSheet) { | 151 if (element->isSVGElement() && !m_svgStyleSheet) { |
157 m_svgStyleSheet = parseUASheet(svgCss, sizeof(svgCss)); | 152 m_svgStyleSheet = parseUASheet(loadResourceAsASCIIString("svg.css")); |
158 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); | 153 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); |
159 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); | 154 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); |
160 changedDefaultStyle = true; | 155 changedDefaultStyle = true; |
161 } | 156 } |
162 | 157 |
163 // FIXME: We should assert that the sheet only styles MathML elements. | 158 // FIXME: We should assert that the sheet only styles MathML elements. |
164 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI | 159 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI |
165 && !m_mathmlStyleSheet) { | 160 && !m_mathmlStyleSheet) { |
166 m_mathmlStyleSheet = parseUASheet(mathmlCss, sizeof(mathmlCss)); | 161 m_mathmlStyleSheet = parseUASheet(loadResourceAsASCIIString("mathml.css"
)); |
167 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); | 162 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); |
168 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); | 163 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); |
169 changedDefaultStyle = true; | 164 changedDefaultStyle = true; |
170 } | 165 } |
171 | 166 |
172 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. | 167 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. |
173 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { | 168 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { |
174 String mediaRules = String(mediaControlsCss, sizeof(mediaControlsCss)) +
RenderTheme::theme().extraMediaControlsStyleSheet(); | 169 String mediaRules = loadResourceAsASCIIString("mediaControls.css") + Ren
derTheme::theme().extraMediaControlsStyleSheet(); |
175 m_mediaControlsStyleSheet = parseUASheet(mediaRules); | 170 m_mediaControlsStyleSheet = parseUASheet(mediaRules); |
176 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); | 171 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); |
177 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); | 172 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); |
178 changedDefaultStyle = true; | 173 changedDefaultStyle = true; |
179 } | 174 } |
180 | 175 |
181 // FIXME: This only works because we Force recalc the entire document so the
new sheet | 176 // FIXME: This only works because we Force recalc the entire document so the
new sheet |
182 // is loaded for <html> and the correct styles apply to everyone. | 177 // is loaded for <html> and the correct styles apply to everyone. |
183 if (!m_fullscreenStyleSheet && Fullscreen::isFullScreen(element->document())
) { | 178 if (!m_fullscreenStyleSheet && Fullscreen::isFullScreen(element->document())
) { |
184 String fullscreenRules = String(fullscreenCss, sizeof(fullscreenCss)) +
RenderTheme::theme().extraFullScreenStyleSheet(); | 179 String fullscreenRules = loadResourceAsASCIIString("fullscreen.css") + R
enderTheme::theme().extraFullScreenStyleSheet(); |
185 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); | 180 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); |
186 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); | 181 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); |
187 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); | 182 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); |
188 changedDefaultStyle = true; | 183 changedDefaultStyle = true; |
189 } | 184 } |
190 | 185 |
191 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); | 186 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); |
192 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); | 187 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); |
193 } | 188 } |
194 | 189 |
195 void CSSDefaultStyleSheets::trace(Visitor* visitor) | 190 void CSSDefaultStyleSheets::trace(Visitor* visitor) |
196 { | 191 { |
197 visitor->trace(m_defaultStyle); | 192 visitor->trace(m_defaultStyle); |
198 visitor->trace(m_defaultViewportStyle); | 193 visitor->trace(m_defaultViewportStyle); |
199 visitor->trace(m_defaultQuirksStyle); | 194 visitor->trace(m_defaultQuirksStyle); |
200 visitor->trace(m_defaultPrintStyle); | 195 visitor->trace(m_defaultPrintStyle); |
201 visitor->trace(m_defaultViewSourceStyle); | 196 visitor->trace(m_defaultViewSourceStyle); |
202 visitor->trace(m_defaultXHTMLMobileProfileStyle); | 197 visitor->trace(m_defaultXHTMLMobileProfileStyle); |
203 visitor->trace(m_defaultTransitionStyle); | 198 visitor->trace(m_defaultTransitionStyle); |
204 visitor->trace(m_defaultStyleSheet); | 199 visitor->trace(m_defaultStyleSheet); |
205 visitor->trace(m_viewportStyleSheet); | 200 visitor->trace(m_viewportStyleSheet); |
206 visitor->trace(m_quirksStyleSheet); | 201 visitor->trace(m_quirksStyleSheet); |
207 visitor->trace(m_svgStyleSheet); | 202 visitor->trace(m_svgStyleSheet); |
208 visitor->trace(m_mathmlStyleSheet); | 203 visitor->trace(m_mathmlStyleSheet); |
209 visitor->trace(m_mediaControlsStyleSheet); | 204 visitor->trace(m_mediaControlsStyleSheet); |
210 visitor->trace(m_fullscreenStyleSheet); | 205 visitor->trace(m_fullscreenStyleSheet); |
211 } | 206 } |
212 | 207 |
213 } // namespace blink | 208 } // namespace blink |
OLD | NEW |