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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 , m_mathmlStyleSheet(nullptr) | 93 , m_mathmlStyleSheet(nullptr) |
93 , m_mediaControlsStyleSheet(nullptr) | 94 , m_mediaControlsStyleSheet(nullptr) |
94 , m_fullscreenStyleSheet(nullptr) | 95 , m_fullscreenStyleSheet(nullptr) |
95 { | 96 { |
96 m_defaultStyle = RuleSet::create(); | 97 m_defaultStyle = RuleSet::create(); |
97 m_defaultViewportStyle = RuleSet::create(); | 98 m_defaultViewportStyle = RuleSet::create(); |
98 m_defaultPrintStyle = RuleSet::create(); | 99 m_defaultPrintStyle = RuleSet::create(); |
99 m_defaultQuirksStyle = RuleSet::create(); | 100 m_defaultQuirksStyle = RuleSet::create(); |
100 | 101 |
101 // Strict-mode rules. | 102 // Strict-mode rules. |
102 String defaultRules = String(htmlCss, sizeof(htmlCss)) + RenderTheme::theme( ).extraDefaultStyleSheet(); | 103 const blink::WebData& htmlCssResource = blink::Platform::current()->loadReso urce("html.css"); |
abarth-chromium
2014/08/01 19:15:15
No need for "blink::"
| |
104 String defaultRules = String(htmlCssResource.data(), htmlCssResource.size()) + RenderTheme::theme().extraDefaultStyleSheet(); | |
103 m_defaultStyleSheet = parseUASheet(defaultRules); | 105 m_defaultStyleSheet = parseUASheet(defaultRules); |
104 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); | 106 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); |
105 #if OS(ANDROID) | 107 #if OS(ANDROID) |
106 String viewportRules(viewportAndroidCss, sizeof(viewportAndroidCss)); | 108 const blink::WebData& viewportAndroidCssResource = blink::Platform::current( )->loadResource("viewportAndroid.css"); |
109 String viewportRules(viewportAndroidCssResource.data(), viewportAndroidCssRe source.size()); | |
107 #else | 110 #else |
108 String viewportRules; | 111 String viewportRules; |
109 #endif | 112 #endif |
110 m_viewportStyleSheet = parseUASheet(viewportRules); | 113 m_viewportStyleSheet = parseUASheet(viewportRules); |
111 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval() ); | 114 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval() ); |
112 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); | 115 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); |
113 | 116 |
114 // Quirks-mode rules. | 117 // Quirks-mode rules. |
115 String quirksRules = String(quirksCss, sizeof(quirksCss)) + RenderTheme::the me().extraQuirksStyleSheet(); | 118 const blink::WebData& quirksCssResource = blink::Platform::current()->loadRe source("quirks.css"); |
119 String quirksRules = String(quirksCssResource.data(), quirksCssResource.size ()) + 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 blink::WebData& viewSourceCssResource = blink::Platform::current() ->loadResource("view-source.css"); |
130 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(viewSou rceCssResource.data(), viewSourceCssResource.size()); | |
126 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef (), screenEval()); | 131 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef (), screenEval()); |
127 } | 132 } |
128 return m_defaultViewSourceStyle.get(); | 133 return m_defaultViewSourceStyle.get(); |
129 } | 134 } |
130 | 135 |
131 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() | 136 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() |
132 { | 137 { |
133 if (!m_defaultTransitionStyle) { | 138 if (!m_defaultTransitionStyle) { |
134 m_defaultTransitionStyle = RuleSet::create(); | 139 m_defaultTransitionStyle = RuleSet::create(); |
135 // Loaded stylesheet is leaked on purpose. | 140 // Loaded stylesheet is leaked on purpose. |
136 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat ionTransitionsCss, sizeof(navigationTransitionsCss)); | 141 const blink::WebData& navigationTransitionsCssResource = blink::Platform ::current()->loadResource("navigationTransitions.css"); |
142 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat ionTransitionsCssResource.data(), navigationTransitionsCssResource.size()); | |
137 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef (), screenEval()); | 143 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef (), screenEval()); |
138 } | 144 } |
139 return m_defaultTransitionStyle.get(); | 145 return m_defaultTransitionStyle.get(); |
140 } | 146 } |
141 | 147 |
142 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() | 148 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() |
143 { | 149 { |
144 if (!m_defaultXHTMLMobileProfileStyle) { | 150 if (!m_defaultXHTMLMobileProfileStyle) { |
145 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); | 151 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); |
146 // Loaded stylesheet is leaked on purpose. | 152 // Loaded stylesheet is leaked on purpose. |
147 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp Css, sizeof(xhtmlmpCss)); | 153 const blink::WebData& xhtmlmpCssResource = blink::Platform::current()->l oadResource("xhtmlmp.css"); |
154 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp CssResource.data(), xhtmlmpCssResource.size()); | |
148 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release() .leakRef(), screenEval()); | 155 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release() .leakRef(), screenEval()); |
149 } | 156 } |
150 return m_defaultXHTMLMobileProfileStyle.get(); | 157 return m_defaultXHTMLMobileProfileStyle.get(); |
151 } | 158 } |
152 | 159 |
153 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element, bool& changedDefaultStyle) | 160 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element, bool& changedDefaultStyle) |
154 { | 161 { |
155 // FIXME: We should assert that the sheet only styles SVG elements. | 162 // FIXME: We should assert that the sheet only styles SVG elements. |
156 if (element->isSVGElement() && !m_svgStyleSheet) { | 163 if (element->isSVGElement() && !m_svgStyleSheet) { |
157 m_svgStyleSheet = parseUASheet(svgCss, sizeof(svgCss)); | 164 const blink::WebData& svgCssResource = blink::Platform::current()->loadR esource("svg.css"); |
165 m_svgStyleSheet = parseUASheet(svgCssResource.data(), svgCssResource.siz e()); | |
158 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); | 166 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); |
159 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); | 167 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); |
160 changedDefaultStyle = true; | 168 changedDefaultStyle = true; |
161 } | 169 } |
162 | 170 |
163 // FIXME: We should assert that the sheet only styles MathML elements. | 171 // FIXME: We should assert that the sheet only styles MathML elements. |
164 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI | 172 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI |
165 && !m_mathmlStyleSheet) { | 173 && !m_mathmlStyleSheet) { |
166 m_mathmlStyleSheet = parseUASheet(mathmlCss, sizeof(mathmlCss)); | 174 const blink::WebData& mathmlCssResource = blink::Platform::current()->lo adResource("mathml.css"); |
175 m_mathmlStyleSheet = parseUASheet(mathmlCssResource.data(), mathmlCssRes ource.size()); | |
167 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); | 176 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); |
168 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); | 177 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); |
169 changedDefaultStyle = true; | 178 changedDefaultStyle = true; |
170 } | 179 } |
171 | 180 |
172 // FIXME: We should assert that this sheet only contains rules for <video> a nd <audio>. | 181 // FIXME: We should assert that this sheet only contains rules for <video> a nd <audio>. |
173 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud ioElement(*element))) { | 182 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud ioElement(*element))) { |
174 String mediaRules = String(mediaControlsCss, sizeof(mediaControlsCss)) + RenderTheme::theme().extraMediaControlsStyleSheet(); | 183 const blink::WebData& mediaControlsCssResource = blink::Platform::curren t()->loadResource("mediaControls.css"); |
184 String mediaRules = String(mediaControlsCssResource.data(), mediaControl sCssResource.size()) + RenderTheme::theme().extraMediaControlsStyleSheet(); | |
175 m_mediaControlsStyleSheet = parseUASheet(mediaRules); | 185 m_mediaControlsStyleSheet = parseUASheet(mediaRules); |
176 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval( )); | 186 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval( )); |
177 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE val()); | 187 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE val()); |
178 changedDefaultStyle = true; | 188 changedDefaultStyle = true; |
179 } | 189 } |
180 | 190 |
181 // FIXME: This only works because we Force recalc the entire document so the new sheet | 191 // 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. | 192 // is loaded for <html> and the correct styles apply to everyone. |
183 if (!m_fullscreenStyleSheet && FullscreenElementStack::isFullScreen(element- >document())) { | 193 if (!m_fullscreenStyleSheet && FullscreenElementStack::isFullScreen(element- >document())) { |
184 String fullscreenRules = String(fullscreenCss, sizeof(fullscreenCss)) + RenderTheme::theme().extraFullScreenStyleSheet(); | 194 const blink::WebData& fullscreenCssResource = blink::Platform::current() ->loadResource("fullscreen.css"); |
195 String fullscreenRules = String(fullscreenCssResource.data(), fullscreen CssResource.size()) + RenderTheme::theme().extraFullScreenStyleSheet(); | |
185 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); | 196 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); |
186 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); | 197 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); |
187 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv al()); | 198 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv al()); |
188 changedDefaultStyle = true; | 199 changedDefaultStyle = true; |
189 } | 200 } |
190 | 201 |
191 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); | 202 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); |
192 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); | 203 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); |
193 } | 204 } |
194 | 205 |
195 void CSSDefaultStyleSheets::trace(Visitor* visitor) | 206 void CSSDefaultStyleSheets::trace(Visitor* visitor) |
196 { | 207 { |
197 visitor->trace(m_defaultStyle); | 208 visitor->trace(m_defaultStyle); |
198 visitor->trace(m_defaultViewportStyle); | 209 visitor->trace(m_defaultViewportStyle); |
199 visitor->trace(m_defaultQuirksStyle); | 210 visitor->trace(m_defaultQuirksStyle); |
200 visitor->trace(m_defaultPrintStyle); | 211 visitor->trace(m_defaultPrintStyle); |
201 visitor->trace(m_defaultViewSourceStyle); | 212 visitor->trace(m_defaultViewSourceStyle); |
202 visitor->trace(m_defaultXHTMLMobileProfileStyle); | 213 visitor->trace(m_defaultXHTMLMobileProfileStyle); |
203 visitor->trace(m_defaultTransitionStyle); | 214 visitor->trace(m_defaultTransitionStyle); |
204 visitor->trace(m_defaultStyleSheet); | 215 visitor->trace(m_defaultStyleSheet); |
205 visitor->trace(m_viewportStyleSheet); | 216 visitor->trace(m_viewportStyleSheet); |
206 visitor->trace(m_quirksStyleSheet); | 217 visitor->trace(m_quirksStyleSheet); |
207 visitor->trace(m_svgStyleSheet); | 218 visitor->trace(m_svgStyleSheet); |
208 visitor->trace(m_mathmlStyleSheet); | 219 visitor->trace(m_mathmlStyleSheet); |
209 visitor->trace(m_mediaControlsStyleSheet); | 220 visitor->trace(m_mediaControlsStyleSheet); |
210 visitor->trace(m_fullscreenStyleSheet); | 221 visitor->trace(m_fullscreenStyleSheet); |
211 } | 222 } |
212 | 223 |
213 } // namespace blink | 224 } // namespace blink |
OLD | NEW |