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/FullscreenElementStack.h" | 36 #include "core/dom/FullscreenElementStack.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 "public/platform/Platform.h" |
| 41 #include "public/platform/WebData.h" |
41 #include "wtf/LeakAnnotations.h" | 42 #include "wtf/LeakAnnotations.h" |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 using namespace HTMLNames; | 46 using namespace HTMLNames; |
46 | 47 |
47 CSSDefaultStyleSheets& CSSDefaultStyleSheets::instance() | 48 CSSDefaultStyleSheets& CSSDefaultStyleSheets::instance() |
48 { | 49 { |
49 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSDefaultStyleSheets>, cssDefaul
tStyleSheets, (adoptPtrWillBeNoop(new CSSDefaultStyleSheets()))); | 50 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSDefaultStyleSheets>, cssDefaul
tStyleSheets, (adoptPtrWillBeNoop(new CSSDefaultStyleSheets()))); |
50 return *cssDefaultStyleSheets; | 51 return *cssDefaultStyleSheets; |
(...skipping 14 matching lines...) Expand all Loading... |
65 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const String& str
) | 66 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const String& str
) |
66 { | 67 { |
67 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(CS
SParserContext(UASheetMode, 0)); | 68 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(CS
SParserContext(UASheetMode, 0)); |
68 sheet->parseString(str); | 69 sheet->parseString(str); |
69 // User Agent stylesheets are parsed once for the lifetime of the renderer | 70 // User Agent stylesheets are parsed once for the lifetime of the renderer |
70 // and are intentionally leaked. | 71 // and are intentionally leaked. |
71 WTF_ANNOTATE_LEAKING_OBJECT_PTR(sheet.get()); | 72 WTF_ANNOTATE_LEAKING_OBJECT_PTR(sheet.get()); |
72 return sheet.release(); | 73 return sheet.release(); |
73 } | 74 } |
74 | 75 |
75 static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const char* chara
cters, unsigned size) | |
76 { | |
77 return parseUASheet(String(characters, size)); | |
78 } | |
79 | |
80 CSSDefaultStyleSheets::CSSDefaultStyleSheets() | 76 CSSDefaultStyleSheets::CSSDefaultStyleSheets() |
81 : m_defaultStyle(nullptr) | 77 : m_defaultStyle(nullptr) |
82 , m_defaultViewportStyle(nullptr) | 78 , m_defaultViewportStyle(nullptr) |
83 , m_defaultQuirksStyle(nullptr) | 79 , m_defaultQuirksStyle(nullptr) |
84 , m_defaultPrintStyle(nullptr) | 80 , m_defaultPrintStyle(nullptr) |
85 , m_defaultViewSourceStyle(nullptr) | 81 , m_defaultViewSourceStyle(nullptr) |
86 , m_defaultXHTMLMobileProfileStyle(nullptr) | 82 , m_defaultXHTMLMobileProfileStyle(nullptr) |
87 , m_defaultTransitionStyle(nullptr) | 83 , m_defaultTransitionStyle(nullptr) |
88 , m_defaultStyleSheet(nullptr) | 84 , m_defaultStyleSheet(nullptr) |
89 , m_viewportStyleSheet(nullptr) | 85 , m_viewportStyleSheet(nullptr) |
90 , m_quirksStyleSheet(nullptr) | 86 , m_quirksStyleSheet(nullptr) |
91 , m_svgStyleSheet(nullptr) | 87 , m_svgStyleSheet(nullptr) |
92 , m_mathmlStyleSheet(nullptr) | 88 , m_mathmlStyleSheet(nullptr) |
93 , m_mediaControlsStyleSheet(nullptr) | 89 , m_mediaControlsStyleSheet(nullptr) |
94 , m_fullscreenStyleSheet(nullptr) | 90 , m_fullscreenStyleSheet(nullptr) |
95 { | 91 { |
96 m_defaultStyle = RuleSet::create(); | 92 m_defaultStyle = RuleSet::create(); |
97 m_defaultViewportStyle = RuleSet::create(); | 93 m_defaultViewportStyle = RuleSet::create(); |
98 m_defaultPrintStyle = RuleSet::create(); | 94 m_defaultPrintStyle = RuleSet::create(); |
99 m_defaultQuirksStyle = RuleSet::create(); | 95 m_defaultQuirksStyle = RuleSet::create(); |
100 | 96 |
101 // Strict-mode rules. | 97 // Strict-mode rules. |
102 String defaultRules = String(htmlCss, sizeof(htmlCss)) + RenderTheme::theme(
).extraDefaultStyleSheet(); | 98 const WebData& htmlCssResource = Platform::current()->loadResource("html.css
"); |
| 99 String defaultRules = htmlCssResource.toASCIIString(); |
| 100 ASSERT(!defaultRules.isEmpty()); |
| 101 defaultRules = defaultRules + RenderTheme::theme().extraDefaultStyleSheet(); |
103 m_defaultStyleSheet = parseUASheet(defaultRules); | 102 m_defaultStyleSheet = parseUASheet(defaultRules); |
104 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); | 103 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); |
105 #if OS(ANDROID) | 104 #if OS(ANDROID) |
106 String viewportRules(viewportAndroidCss, sizeof(viewportAndroidCss)); | 105 const WebData& viewportAndroidCssResource = Platform::current()->loadResourc
e("viewportAndroid.css"); |
| 106 String viewportRules = viewportAndroidCssResource.toASCIIString(); |
| 107 ASSERT(!viewportRules.isEmpty()); |
107 #else | 108 #else |
108 String viewportRules; | 109 String viewportRules; |
109 #endif | 110 #endif |
110 m_viewportStyleSheet = parseUASheet(viewportRules); | 111 m_viewportStyleSheet = parseUASheet(viewportRules); |
111 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); | 112 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); |
112 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); | 113 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); |
113 | 114 |
114 // Quirks-mode rules. | 115 // Quirks-mode rules. |
115 String quirksRules = String(quirksCss, sizeof(quirksCss)) + RenderTheme::the
me().extraQuirksStyleSheet(); | 116 const WebData& quirksCssResource = Platform::current()->loadResource("quirks
.css"); |
| 117 String quirksRules = quirksCssResource.toASCIIString(); |
| 118 ASSERT(!quirksRules.isEmpty()); |
| 119 quirksRules = quirksRules + RenderTheme::theme().extraQuirksStyleSheet(); |
116 m_quirksStyleSheet = parseUASheet(quirksRules); | 120 m_quirksStyleSheet = parseUASheet(quirksRules); |
117 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); | 121 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); |
118 } | 122 } |
119 | 123 |
120 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() | 124 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() |
121 { | 125 { |
122 if (!m_defaultViewSourceStyle) { | 126 if (!m_defaultViewSourceStyle) { |
123 m_defaultViewSourceStyle = RuleSet::create(); | 127 m_defaultViewSourceStyle = RuleSet::create(); |
124 // Loaded stylesheet is leaked on purpose. | 128 // Loaded stylesheet is leaked on purpose. |
125 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(viewSou
rceCss, sizeof(viewSourceCss)); | 129 const WebData& viewSourceCssResource = Platform::current()->loadResource
("view-source.css"); |
| 130 String viewSourceRules = viewSourceCssResource.toASCIIString(); |
| 131 ASSERT(!viewSourceRules.isEmpty()); |
| 132 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(viewSou
rceRules); |
126 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 133 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
127 } | 134 } |
128 return m_defaultViewSourceStyle.get(); | 135 return m_defaultViewSourceStyle.get(); |
129 } | 136 } |
130 | 137 |
131 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() | 138 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() |
132 { | 139 { |
133 if (!m_defaultTransitionStyle) { | 140 if (!m_defaultTransitionStyle) { |
134 m_defaultTransitionStyle = RuleSet::create(); | 141 m_defaultTransitionStyle = RuleSet::create(); |
135 // Loaded stylesheet is leaked on purpose. | 142 // Loaded stylesheet is leaked on purpose. |
136 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat
ionTransitionsCss, sizeof(navigationTransitionsCss)); | 143 const WebData& navigationTransitionsCssResource = Platform::current()->l
oadResource("navigationTransitions.css"); |
| 144 String navigationTransitionsRules = navigationTransitionsCssResource.toA
SCIIString(); |
| 145 ASSERT(!navigationTransitionsRules.isEmpty()); |
| 146 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat
ionTransitionsRules); |
137 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 147 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
138 } | 148 } |
139 return m_defaultTransitionStyle.get(); | 149 return m_defaultTransitionStyle.get(); |
140 } | 150 } |
141 | 151 |
142 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() | 152 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() |
143 { | 153 { |
144 if (!m_defaultXHTMLMobileProfileStyle) { | 154 if (!m_defaultXHTMLMobileProfileStyle) { |
145 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); | 155 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); |
146 // Loaded stylesheet is leaked on purpose. | 156 // Loaded stylesheet is leaked on purpose. |
147 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp
Css, sizeof(xhtmlmpCss)); | 157 const WebData& xhtmlmpCssResource = Platform::current()->loadResource("x
htmlmp.css"); |
| 158 String xhtmlmpRules = xhtmlmpCssResource.toASCIIString(); |
| 159 ASSERT(!xhtmlmpRules.isEmpty()); |
| 160 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp
Rules); |
148 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); | 161 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); |
149 } | 162 } |
150 return m_defaultXHTMLMobileProfileStyle.get(); | 163 return m_defaultXHTMLMobileProfileStyle.get(); |
151 } | 164 } |
152 | 165 |
153 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) | 166 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) |
154 { | 167 { |
155 // FIXME: We should assert that the sheet only styles SVG elements. | 168 // FIXME: We should assert that the sheet only styles SVG elements. |
156 if (element->isSVGElement() && !m_svgStyleSheet) { | 169 if (element->isSVGElement() && !m_svgStyleSheet) { |
157 m_svgStyleSheet = parseUASheet(svgCss, sizeof(svgCss)); | 170 const WebData& svgCssResource = Platform::current()->loadResource("svg.c
ss"); |
| 171 String svgRules = svgCssResource.toASCIIString(); |
| 172 ASSERT(!svgRules.isEmpty()); |
| 173 m_svgStyleSheet = parseUASheet(svgRules); |
158 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); | 174 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); |
159 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); | 175 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); |
160 changedDefaultStyle = true; | 176 changedDefaultStyle = true; |
161 } | 177 } |
162 | 178 |
163 // FIXME: We should assert that the sheet only styles MathML elements. | 179 // FIXME: We should assert that the sheet only styles MathML elements. |
164 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI | 180 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI |
165 && !m_mathmlStyleSheet) { | 181 && !m_mathmlStyleSheet) { |
166 m_mathmlStyleSheet = parseUASheet(mathmlCss, sizeof(mathmlCss)); | 182 const WebData& mathmlCssResource = Platform::current()->loadResource("ma
thml.css"); |
| 183 String mathmlRules = mathmlCssResource.toASCIIString(); |
| 184 ASSERT(!mathmlRules.isEmpty()); |
| 185 m_mathmlStyleSheet = parseUASheet(mathmlRules); |
167 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); | 186 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); |
168 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); | 187 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); |
169 changedDefaultStyle = true; | 188 changedDefaultStyle = true; |
170 } | 189 } |
171 | 190 |
172 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. | 191 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. |
173 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { | 192 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { |
174 String mediaRules = String(mediaControlsCss, sizeof(mediaControlsCss)) +
RenderTheme::theme().extraMediaControlsStyleSheet(); | 193 const WebData& mediaControlsCssResource = Platform::current()->loadResou
rce("mediaControls.css"); |
| 194 String mediaRules = mediaControlsCssResource.toASCIIString(); |
| 195 ASSERT(!mediaRules.isEmpty()); |
| 196 mediaRules = mediaRules + RenderTheme::theme().extraMediaControlsStyleSh
eet(); |
175 m_mediaControlsStyleSheet = parseUASheet(mediaRules); | 197 m_mediaControlsStyleSheet = parseUASheet(mediaRules); |
176 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); | 198 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); |
177 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); | 199 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); |
178 changedDefaultStyle = true; | 200 changedDefaultStyle = true; |
179 } | 201 } |
180 | 202 |
181 // FIXME: This only works because we Force recalc the entire document so the
new sheet | 203 // 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. | 204 // is loaded for <html> and the correct styles apply to everyone. |
183 if (!m_fullscreenStyleSheet && FullscreenElementStack::isFullScreen(element-
>document())) { | 205 if (!m_fullscreenStyleSheet && FullscreenElementStack::isFullScreen(element-
>document())) { |
184 String fullscreenRules = String(fullscreenCss, sizeof(fullscreenCss)) +
RenderTheme::theme().extraFullScreenStyleSheet(); | 206 const WebData& fullscreenCssResource = Platform::current()->loadResource
("fullscreen.css"); |
| 207 String fullscreenRules = fullscreenCssResource.toASCIIString(); |
| 208 ASSERT(!fullscreenRules.isEmpty()); |
| 209 fullscreenRules = fullscreenRules + RenderTheme::theme().extraFullScreen
StyleSheet(); |
185 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); | 210 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); |
186 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); | 211 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); |
187 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); | 212 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); |
188 changedDefaultStyle = true; | 213 changedDefaultStyle = true; |
189 } | 214 } |
190 | 215 |
191 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); | 216 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); |
192 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); | 217 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); |
193 } | 218 } |
194 | 219 |
195 void CSSDefaultStyleSheets::trace(Visitor* visitor) | 220 void CSSDefaultStyleSheets::trace(Visitor* visitor) |
196 { | 221 { |
197 visitor->trace(m_defaultStyle); | 222 visitor->trace(m_defaultStyle); |
198 visitor->trace(m_defaultViewportStyle); | 223 visitor->trace(m_defaultViewportStyle); |
199 visitor->trace(m_defaultQuirksStyle); | 224 visitor->trace(m_defaultQuirksStyle); |
200 visitor->trace(m_defaultPrintStyle); | 225 visitor->trace(m_defaultPrintStyle); |
201 visitor->trace(m_defaultViewSourceStyle); | 226 visitor->trace(m_defaultViewSourceStyle); |
202 visitor->trace(m_defaultXHTMLMobileProfileStyle); | 227 visitor->trace(m_defaultXHTMLMobileProfileStyle); |
203 visitor->trace(m_defaultTransitionStyle); | 228 visitor->trace(m_defaultTransitionStyle); |
204 visitor->trace(m_defaultStyleSheet); | 229 visitor->trace(m_defaultStyleSheet); |
205 visitor->trace(m_viewportStyleSheet); | 230 visitor->trace(m_viewportStyleSheet); |
206 visitor->trace(m_quirksStyleSheet); | 231 visitor->trace(m_quirksStyleSheet); |
207 visitor->trace(m_svgStyleSheet); | 232 visitor->trace(m_svgStyleSheet); |
208 visitor->trace(m_mathmlStyleSheet); | 233 visitor->trace(m_mathmlStyleSheet); |
209 visitor->trace(m_mediaControlsStyleSheet); | 234 visitor->trace(m_mediaControlsStyleSheet); |
210 visitor->trace(m_fullscreenStyleSheet); | 235 visitor->trace(m_fullscreenStyleSheet); |
211 } | 236 } |
212 | 237 |
213 } // namespace blink | 238 } // namespace blink |
OLD | NEW |