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" |
33 #include "core/css/MediaQueryEvaluator.h" | 34 #include "core/css/MediaQueryEvaluator.h" |
34 #include "core/css/RuleSet.h" | 35 #include "core/css/RuleSet.h" |
35 #include "core/css/StyleSheetContents.h" | 36 #include "core/css/StyleSheetContents.h" |
36 #include "core/dom/Fullscreen.h" | 37 #include "core/dom/Fullscreen.h" |
37 #include "core/html/HTMLAnchorElement.h" | 38 #include "core/html/HTMLAnchorElement.h" |
38 #include "core/html/HTMLHtmlElement.h" | 39 #include "core/html/HTMLHtmlElement.h" |
39 #include "core/rendering/RenderTheme.h" | 40 #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 |
75 CSSDefaultStyleSheets::CSSDefaultStyleSheets() | 80 CSSDefaultStyleSheets::CSSDefaultStyleSheets() |
76 : m_defaultStyle(nullptr) | 81 : m_defaultStyle(nullptr) |
77 , m_defaultViewportStyle(nullptr) | 82 , m_defaultViewportStyle(nullptr) |
78 , m_defaultQuirksStyle(nullptr) | 83 , m_defaultQuirksStyle(nullptr) |
79 , m_defaultPrintStyle(nullptr) | 84 , m_defaultPrintStyle(nullptr) |
80 , m_defaultViewSourceStyle(nullptr) | 85 , m_defaultViewSourceStyle(nullptr) |
81 , m_defaultXHTMLMobileProfileStyle(nullptr) | 86 , m_defaultXHTMLMobileProfileStyle(nullptr) |
82 , m_defaultTransitionStyle(nullptr) | 87 , m_defaultTransitionStyle(nullptr) |
83 , m_defaultStyleSheet(nullptr) | 88 , m_defaultStyleSheet(nullptr) |
84 , m_viewportStyleSheet(nullptr) | 89 , m_viewportStyleSheet(nullptr) |
85 , m_quirksStyleSheet(nullptr) | 90 , m_quirksStyleSheet(nullptr) |
86 , m_svgStyleSheet(nullptr) | 91 , m_svgStyleSheet(nullptr) |
87 , m_mathmlStyleSheet(nullptr) | 92 , m_mathmlStyleSheet(nullptr) |
88 , m_mediaControlsStyleSheet(nullptr) | 93 , m_mediaControlsStyleSheet(nullptr) |
89 , m_fullscreenStyleSheet(nullptr) | 94 , m_fullscreenStyleSheet(nullptr) |
90 { | 95 { |
91 m_defaultStyle = RuleSet::create(); | 96 m_defaultStyle = RuleSet::create(); |
92 m_defaultViewportStyle = RuleSet::create(); | 97 m_defaultViewportStyle = RuleSet::create(); |
93 m_defaultPrintStyle = RuleSet::create(); | 98 m_defaultPrintStyle = RuleSet::create(); |
94 m_defaultQuirksStyle = RuleSet::create(); | 99 m_defaultQuirksStyle = RuleSet::create(); |
95 | 100 |
96 // Strict-mode rules. | 101 // Strict-mode rules. |
97 String defaultRules = loadResourceAsASCIIString("html.css") + RenderTheme::t
heme().extraDefaultStyleSheet(); | 102 String defaultRules = String(htmlCss, sizeof(htmlCss)) + RenderTheme::theme(
).extraDefaultStyleSheet(); |
98 m_defaultStyleSheet = parseUASheet(defaultRules); | 103 m_defaultStyleSheet = parseUASheet(defaultRules); |
99 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); | 104 m_defaultStyle->addRulesFromSheet(defaultStyleSheet(), screenEval()); |
100 #if OS(ANDROID) | 105 #if OS(ANDROID) |
101 String viewportRules = loadResourceAsASCIIString("viewportAndroid.css"); | 106 String viewportRules(viewportAndroidCss, sizeof(viewportAndroidCss)); |
102 #else | 107 #else |
103 String viewportRules; | 108 String viewportRules; |
104 #endif | 109 #endif |
105 m_viewportStyleSheet = parseUASheet(viewportRules); | 110 m_viewportStyleSheet = parseUASheet(viewportRules); |
106 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); | 111 m_defaultViewportStyle->addRulesFromSheet(viewportStyleSheet(), screenEval()
); |
107 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); | 112 m_defaultPrintStyle->addRulesFromSheet(defaultStyleSheet(), printEval()); |
108 | 113 |
109 // Quirks-mode rules. | 114 // Quirks-mode rules. |
110 String quirksRules = loadResourceAsASCIIString("quirks.css") + RenderTheme::
theme().extraQuirksStyleSheet(); | 115 String quirksRules = String(quirksCss, sizeof(quirksCss)) + RenderTheme::the
me().extraQuirksStyleSheet(); |
111 m_quirksStyleSheet = parseUASheet(quirksRules); | 116 m_quirksStyleSheet = parseUASheet(quirksRules); |
112 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); | 117 m_defaultQuirksStyle->addRulesFromSheet(quirksStyleSheet(), screenEval()); |
113 } | 118 } |
114 | 119 |
115 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() | 120 RuleSet* CSSDefaultStyleSheets::defaultViewSourceStyle() |
116 { | 121 { |
117 if (!m_defaultViewSourceStyle) { | 122 if (!m_defaultViewSourceStyle) { |
118 m_defaultViewSourceStyle = RuleSet::create(); | 123 m_defaultViewSourceStyle = RuleSet::create(); |
119 // Loaded stylesheet is leaked on purpose. | 124 // Loaded stylesheet is leaked on purpose. |
120 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("view-source.css")); | 125 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(viewSou
rceCss, sizeof(viewSourceCss)); |
121 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 126 m_defaultViewSourceStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
122 } | 127 } |
123 return m_defaultViewSourceStyle.get(); | 128 return m_defaultViewSourceStyle.get(); |
124 } | 129 } |
125 | 130 |
126 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() | 131 RuleSet* CSSDefaultStyleSheets::defaultTransitionStyle() |
127 { | 132 { |
128 if (!m_defaultTransitionStyle) { | 133 if (!m_defaultTransitionStyle) { |
129 m_defaultTransitionStyle = RuleSet::create(); | 134 m_defaultTransitionStyle = RuleSet::create(); |
130 // Loaded stylesheet is leaked on purpose. | 135 // Loaded stylesheet is leaked on purpose. |
131 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("navigationTransitions.css")); | 136 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(navigat
ionTransitionsCss, sizeof(navigationTransitionsCss)); |
132 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); | 137 m_defaultTransitionStyle->addRulesFromSheet(stylesheet.release().leakRef
(), screenEval()); |
133 } | 138 } |
134 return m_defaultTransitionStyle.get(); | 139 return m_defaultTransitionStyle.get(); |
135 } | 140 } |
136 | 141 |
137 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() | 142 RuleSet* CSSDefaultStyleSheets::defaultXHTMLMobileProfileStyle() |
138 { | 143 { |
139 if (!m_defaultXHTMLMobileProfileStyle) { | 144 if (!m_defaultXHTMLMobileProfileStyle) { |
140 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); | 145 m_defaultXHTMLMobileProfileStyle = RuleSet::create(); |
141 // Loaded stylesheet is leaked on purpose. | 146 // Loaded stylesheet is leaked on purpose. |
142 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(loadRes
ourceAsASCIIString("xhtmlmp.css")); | 147 RefPtrWillBeRawPtr<StyleSheetContents> stylesheet = parseUASheet(xhtmlmp
Css, sizeof(xhtmlmpCss)); |
143 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); | 148 m_defaultXHTMLMobileProfileStyle->addRulesFromSheet(stylesheet.release()
.leakRef(), screenEval()); |
144 } | 149 } |
145 return m_defaultXHTMLMobileProfileStyle.get(); | 150 return m_defaultXHTMLMobileProfileStyle.get(); |
146 } | 151 } |
147 | 152 |
148 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) | 153 void CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(Element* element,
bool& changedDefaultStyle) |
149 { | 154 { |
150 // FIXME: We should assert that the sheet only styles SVG elements. | 155 // FIXME: We should assert that the sheet only styles SVG elements. |
151 if (element->isSVGElement() && !m_svgStyleSheet) { | 156 if (element->isSVGElement() && !m_svgStyleSheet) { |
152 m_svgStyleSheet = parseUASheet(loadResourceAsASCIIString("svg.css")); | 157 m_svgStyleSheet = parseUASheet(svgCss, sizeof(svgCss)); |
153 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); | 158 m_defaultStyle->addRulesFromSheet(svgStyleSheet(), screenEval()); |
154 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); | 159 m_defaultPrintStyle->addRulesFromSheet(svgStyleSheet(), printEval()); |
155 changedDefaultStyle = true; | 160 changedDefaultStyle = true; |
156 } | 161 } |
157 | 162 |
158 // FIXME: We should assert that the sheet only styles MathML elements. | 163 // FIXME: We should assert that the sheet only styles MathML elements. |
159 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI | 164 if (element->namespaceURI() == MathMLNames::mathmlNamespaceURI |
160 && !m_mathmlStyleSheet) { | 165 && !m_mathmlStyleSheet) { |
161 m_mathmlStyleSheet = parseUASheet(loadResourceAsASCIIString("mathml.css"
)); | 166 m_mathmlStyleSheet = parseUASheet(mathmlCss, sizeof(mathmlCss)); |
162 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); | 167 m_defaultStyle->addRulesFromSheet(mathmlStyleSheet(), screenEval()); |
163 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); | 168 m_defaultPrintStyle->addRulesFromSheet(mathmlStyleSheet(), printEval()); |
164 changedDefaultStyle = true; | 169 changedDefaultStyle = true; |
165 } | 170 } |
166 | 171 |
167 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. | 172 // FIXME: We should assert that this sheet only contains rules for <video> a
nd <audio>. |
168 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { | 173 if (!m_mediaControlsStyleSheet && (isHTMLVideoElement(*element) || isHTMLAud
ioElement(*element))) { |
169 String mediaRules = loadResourceAsASCIIString("mediaControls.css") + Ren
derTheme::theme().extraMediaControlsStyleSheet(); | 174 String mediaRules = String(mediaControlsCss, sizeof(mediaControlsCss)) +
RenderTheme::theme().extraMediaControlsStyleSheet(); |
170 m_mediaControlsStyleSheet = parseUASheet(mediaRules); | 175 m_mediaControlsStyleSheet = parseUASheet(mediaRules); |
171 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); | 176 m_defaultStyle->addRulesFromSheet(mediaControlsStyleSheet(), screenEval(
)); |
172 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); | 177 m_defaultPrintStyle->addRulesFromSheet(mediaControlsStyleSheet(), printE
val()); |
173 changedDefaultStyle = true; | 178 changedDefaultStyle = true; |
174 } | 179 } |
175 | 180 |
176 // FIXME: This only works because we Force recalc the entire document so the
new sheet | 181 // FIXME: This only works because we Force recalc the entire document so the
new sheet |
177 // is loaded for <html> and the correct styles apply to everyone. | 182 // is loaded for <html> and the correct styles apply to everyone. |
178 if (!m_fullscreenStyleSheet && Fullscreen::isFullScreen(element->document())
) { | 183 if (!m_fullscreenStyleSheet && Fullscreen::isFullScreen(element->document())
) { |
179 String fullscreenRules = loadResourceAsASCIIString("fullscreen.css") + R
enderTheme::theme().extraFullScreenStyleSheet(); | 184 String fullscreenRules = String(fullscreenCss, sizeof(fullscreenCss)) +
RenderTheme::theme().extraFullScreenStyleSheet(); |
180 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); | 185 m_fullscreenStyleSheet = parseUASheet(fullscreenRules); |
181 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); | 186 m_defaultStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEval()); |
182 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); | 187 m_defaultQuirksStyle->addRulesFromSheet(fullscreenStyleSheet(), screenEv
al()); |
183 changedDefaultStyle = true; | 188 changedDefaultStyle = true; |
184 } | 189 } |
185 | 190 |
186 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); | 191 ASSERT(!m_defaultStyle->features().hasIdsInSelectors()); |
187 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); | 192 ASSERT(m_defaultStyle->features().siblingRules.isEmpty()); |
188 } | 193 } |
189 | 194 |
190 void CSSDefaultStyleSheets::trace(Visitor* visitor) | 195 void CSSDefaultStyleSheets::trace(Visitor* visitor) |
191 { | 196 { |
192 visitor->trace(m_defaultStyle); | 197 visitor->trace(m_defaultStyle); |
193 visitor->trace(m_defaultViewportStyle); | 198 visitor->trace(m_defaultViewportStyle); |
194 visitor->trace(m_defaultQuirksStyle); | 199 visitor->trace(m_defaultQuirksStyle); |
195 visitor->trace(m_defaultPrintStyle); | 200 visitor->trace(m_defaultPrintStyle); |
196 visitor->trace(m_defaultViewSourceStyle); | 201 visitor->trace(m_defaultViewSourceStyle); |
197 visitor->trace(m_defaultXHTMLMobileProfileStyle); | 202 visitor->trace(m_defaultXHTMLMobileProfileStyle); |
198 visitor->trace(m_defaultTransitionStyle); | 203 visitor->trace(m_defaultTransitionStyle); |
199 visitor->trace(m_defaultStyleSheet); | 204 visitor->trace(m_defaultStyleSheet); |
200 visitor->trace(m_viewportStyleSheet); | 205 visitor->trace(m_viewportStyleSheet); |
201 visitor->trace(m_quirksStyleSheet); | 206 visitor->trace(m_quirksStyleSheet); |
202 visitor->trace(m_svgStyleSheet); | 207 visitor->trace(m_svgStyleSheet); |
203 visitor->trace(m_mathmlStyleSheet); | 208 visitor->trace(m_mathmlStyleSheet); |
204 visitor->trace(m_mediaControlsStyleSheet); | 209 visitor->trace(m_mediaControlsStyleSheet); |
205 visitor->trace(m_fullscreenStyleSheet); | 210 visitor->trace(m_fullscreenStyleSheet); |
206 } | 211 } |
207 | 212 |
208 } // namespace blink | 213 } // namespace blink |
OLD | NEW |