OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 , m_hasMediaQueries(false) | 69 , m_hasMediaQueries(false) |
70 , m_hasSingleOwnerDocument(true) | 70 , m_hasSingleOwnerDocument(true) |
71 , m_parserContext(context) | 71 , m_parserContext(context) |
72 { | 72 { |
73 } | 73 } |
74 | 74 |
75 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) | 75 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) |
76 : m_ownerRule(nullptr) | 76 : m_ownerRule(nullptr) |
77 , m_originalURL(o.m_originalURL) | 77 , m_originalURL(o.m_originalURL) |
78 , m_importRules(o.m_importRules.size()) | 78 , m_importRules(o.m_importRules.size()) |
| 79 , m_namespaceRules(o.m_namespaceRules.size()) |
79 , m_childRules(o.m_childRules.size()) | 80 , m_childRules(o.m_childRules.size()) |
80 , m_namespaces(o.m_namespaces) | 81 , m_namespaces(o.m_namespaces) |
81 , m_defaultNamespace(o.m_defaultNamespace) | 82 , m_defaultNamespace(o.m_defaultNamespace) |
82 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) | 83 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) |
83 , m_didLoadErrorOccur(false) | 84 , m_didLoadErrorOccur(false) |
84 , m_isMutable(false) | 85 , m_isMutable(false) |
85 , m_isInMemoryCache(false) | 86 , m_isInMemoryCache(false) |
86 , m_hasFontFaceRule(o.m_hasFontFaceRule) | 87 , m_hasFontFaceRule(o.m_hasFontFaceRule) |
87 , m_hasMediaQueries(o.m_hasMediaQueries) | 88 , m_hasMediaQueries(o.m_hasMediaQueries) |
88 , m_hasSingleOwnerDocument(true) | 89 , m_hasSingleOwnerDocument(true) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); | 152 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); |
152 if (importRule->mediaQueries()) | 153 if (importRule->mediaQueries()) |
153 setHasMediaQueries(); | 154 setHasMediaQueries(); |
154 m_importRules.append(importRule); | 155 m_importRules.append(importRule); |
155 m_importRules.last()->setParentStyleSheet(this); | 156 m_importRules.last()->setParentStyleSheet(this); |
156 m_importRules.last()->requestStyleSheet(); | 157 m_importRules.last()->requestStyleSheet(); |
157 return; | 158 return; |
158 } | 159 } |
159 | 160 |
160 if (rule->isNamespaceRule()) { | 161 if (rule->isNamespaceRule()) { |
161 // Parser enforces that @namespace rules come before anything else | 162 // Parser enforces that @namespace rules come before all rules other tha
n |
| 163 // import/charset rules |
162 ASSERT(m_childRules.isEmpty()); | 164 ASSERT(m_childRules.isEmpty()); |
163 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); | 165 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); |
164 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); | 166 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); |
| 167 m_namespaceRules.append(&namespaceRule); |
165 return; | 168 return; |
166 } | 169 } |
167 | 170 |
168 if (rule->isMediaRule()) | 171 if (rule->isMediaRule()) |
169 setHasMediaQueries(); | 172 setHasMediaQueries(); |
170 | 173 |
171 m_childRules.append(rule); | 174 m_childRules.append(rule); |
172 } | 175 } |
173 | 176 |
174 void StyleSheetContents::setHasMediaQueries() | 177 void StyleSheetContents::setHasMediaQueries() |
175 { | 178 { |
176 m_hasMediaQueries = true; | 179 m_hasMediaQueries = true; |
177 if (parentStyleSheet()) | 180 if (parentStyleSheet()) |
178 parentStyleSheet()->setHasMediaQueries(); | 181 parentStyleSheet()->setHasMediaQueries(); |
179 } | 182 } |
180 | 183 |
181 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const | 184 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const |
182 { | 185 { |
183 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 186 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
184 | 187 |
185 if (index < m_importRules.size()) | 188 if (index < m_importRules.size()) |
186 return m_importRules[index].get(); | 189 return m_importRules[index].get(); |
187 | 190 |
188 index -= m_importRules.size(); | 191 index -= m_importRules.size(); |
| 192 |
| 193 if (index < m_namespaceRules.size()) |
| 194 return m_namespaceRules[index].get(); |
| 195 |
| 196 index -= m_namespaceRules.size(); |
| 197 |
189 return m_childRules[index].get(); | 198 return m_childRules[index].get(); |
190 } | 199 } |
191 | 200 |
192 unsigned StyleSheetContents::ruleCount() const | 201 unsigned StyleSheetContents::ruleCount() const |
193 { | 202 { |
194 return m_importRules.size() + m_childRules.size(); | 203 return m_importRules.size() + m_namespaceRules.size() + m_childRules.size(); |
195 } | 204 } |
196 | 205 |
197 void StyleSheetContents::clearRules() | 206 void StyleSheetContents::clearRules() |
198 { | 207 { |
199 for (unsigned i = 0; i < m_importRules.size(); ++i) { | 208 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
200 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); | 209 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); |
201 m_importRules[i]->clearParentStyleSheet(); | 210 m_importRules[i]->clearParentStyleSheet(); |
202 } | 211 } |
203 m_importRules.clear(); | 212 m_importRules.clear(); |
| 213 m_namespaceRules.clear(); |
204 m_childRules.clear(); | 214 m_childRules.clear(); |
205 } | 215 } |
206 | 216 |
207 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule, unsigned index) | 217 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
rule, unsigned index) |
208 { | 218 { |
209 ASSERT(m_isMutable); | 219 ASSERT(m_isMutable); |
210 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); | 220 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); |
211 | 221 |
212 if (index < m_importRules.size() || (index == m_importRules.size() && rule->
isImportRule())) { | 222 if (index < m_importRules.size() || (index == m_importRules.size() && rule->
isImportRule())) { |
213 // Inserting non-import rule before @import is not allowed. | 223 // Inserting non-import rule before @import is not allowed. |
(...skipping 12 matching lines...) Expand all Loading... |
226 } | 236 } |
227 // Inserting @import rule after a non-import rule is not allowed. | 237 // Inserting @import rule after a non-import rule is not allowed. |
228 if (rule->isImportRule()) | 238 if (rule->isImportRule()) |
229 return false; | 239 return false; |
230 | 240 |
231 if (rule->isMediaRule()) | 241 if (rule->isMediaRule()) |
232 setHasMediaQueries(); | 242 setHasMediaQueries(); |
233 | 243 |
234 index -= m_importRules.size(); | 244 index -= m_importRules.size(); |
235 | 245 |
| 246 if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() &&
rule->isNamespaceRule())) { |
| 247 // Inserting non-namespace rules other than import rule before @namespac
e is not allowed. |
| 248 if (!rule->isNamespaceRule()) |
| 249 return false; |
| 250 // Inserting @namespace rule when rules other than import/namespace/char
set are present is not allowed. |
| 251 if (!m_childRules.isEmpty()) |
| 252 return false; |
| 253 |
| 254 StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get()); |
| 255 m_namespaceRules.insert(index, namespaceRule); |
| 256 // For now to be compatible with IE and Firefox if namespace rule with s
ame prefix is added |
| 257 // irrespective of adding the rule at any index, last added rule's value
is considered. |
| 258 // TODO (ramya.v@samsung.com): As per spec last valid rule should be con
sidered, |
| 259 // which means if namespace rule is added in the middle of existing name
space rules, |
| 260 // rule which comes later in rule list with same prefix needs to be cons
idered. |
| 261 parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri()); |
| 262 return true; |
| 263 } |
| 264 |
| 265 if (rule->isNamespaceRule()) |
| 266 return false; |
| 267 |
| 268 index -= m_namespaceRules.size(); |
| 269 |
236 if (rule->isFontFaceRule()) | 270 if (rule->isFontFaceRule()) |
237 setHasFontFaceRule(true); | 271 setHasFontFaceRule(true); |
238 m_childRules.insert(index, rule); | 272 m_childRules.insert(index, rule); |
239 return true; | 273 return true; |
240 } | 274 } |
241 | 275 |
242 void StyleSheetContents::wrapperDeleteRule(unsigned index) | 276 bool StyleSheetContents::wrapperDeleteRule(unsigned index) |
243 { | 277 { |
244 ASSERT(m_isMutable); | 278 ASSERT(m_isMutable); |
245 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 279 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
246 | 280 |
247 if (index < m_importRules.size()) { | 281 if (index < m_importRules.size()) { |
248 m_importRules[index]->clearParentStyleSheet(); | 282 m_importRules[index]->clearParentStyleSheet(); |
249 if (m_importRules[index]->isFontFaceRule()) | 283 if (m_importRules[index]->isFontFaceRule()) |
250 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge
t())); | 284 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge
t())); |
251 m_importRules.remove(index); | 285 m_importRules.remove(index); |
252 return; | 286 return true; |
253 } | 287 } |
254 index -= m_importRules.size(); | 288 index -= m_importRules.size(); |
255 | 289 |
| 290 if (index < m_namespaceRules.size()) { |
| 291 if (!m_childRules.isEmpty()) |
| 292 return false; |
| 293 m_namespaceRules.remove(index); |
| 294 return true; |
| 295 } |
| 296 index -= m_namespaceRules.size(); |
| 297 |
256 if (m_childRules[index]->isFontFaceRule()) | 298 if (m_childRules[index]->isFontFaceRule()) |
257 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get()))
; | 299 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get()))
; |
258 m_childRules.remove(index); | 300 m_childRules.remove(index); |
| 301 return true; |
259 } | 302 } |
260 | 303 |
261 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) | 304 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) |
262 { | 305 { |
263 ASSERT(!uri.isNull()); | 306 ASSERT(!uri.isNull()); |
264 if (prefix.isNull()) { | 307 if (prefix.isNull()) { |
265 m_defaultNamespace = uri; | 308 m_defaultNamespace = uri; |
266 return; | 309 return; |
267 } | 310 } |
268 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); | 311 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 } | 667 } |
625 | 668 |
626 findFontFaceRulesFromRules(childRules(), fontFaceRules); | 669 findFontFaceRulesFromRules(childRules(), fontFaceRules); |
627 } | 670 } |
628 | 671 |
629 DEFINE_TRACE(StyleSheetContents) | 672 DEFINE_TRACE(StyleSheetContents) |
630 { | 673 { |
631 #if ENABLE(OILPAN) | 674 #if ENABLE(OILPAN) |
632 visitor->trace(m_ownerRule); | 675 visitor->trace(m_ownerRule); |
633 visitor->trace(m_importRules); | 676 visitor->trace(m_importRules); |
| 677 visitor->trace(m_namespaceRules); |
634 visitor->trace(m_childRules); | 678 visitor->trace(m_childRules); |
635 visitor->trace(m_loadingClients); | 679 visitor->trace(m_loadingClients); |
636 visitor->trace(m_completedClients); | 680 visitor->trace(m_completedClients); |
637 visitor->trace(m_ruleSet); | 681 visitor->trace(m_ruleSet); |
638 #endif | 682 #endif |
639 } | 683 } |
640 | 684 |
641 } | 685 } |
OLD | NEW |