Chromium Code Reviews| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); | 149 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); |
| 150 if (importRule->mediaQueries()) | 150 if (importRule->mediaQueries()) |
| 151 setHasMediaQueries(); | 151 setHasMediaQueries(); |
| 152 m_importRules.append(importRule); | 152 m_importRules.append(importRule); |
| 153 m_importRules.last()->setParentStyleSheet(this); | 153 m_importRules.last()->setParentStyleSheet(this); |
| 154 m_importRules.last()->requestStyleSheet(); | 154 m_importRules.last()->requestStyleSheet(); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 if (rule->isNamespaceRule()) { | 158 if (rule->isNamespaceRule()) { |
| 159 // Parser enforces that @namespace rules come before anything else | 159 // Parser enforces that @namespace rules come before all rules except fo r import |
| 160 // or namespace rules | |
|
Timothy Loh
2015/09/02 04:45:14
namespace -> charset?
ramya.v
2015/09/02 09:20:54
Done.
| |
| 160 ASSERT(m_childRules.isEmpty()); | 161 ASSERT(m_childRules.isEmpty()); |
| 161 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); | 162 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); |
| 162 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); | 163 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); |
| 164 m_namespaceRules.append(&namespaceRule); | |
| 163 return; | 165 return; |
| 164 } | 166 } |
| 165 | 167 |
| 166 if (rule->isMediaRule()) | 168 if (rule->isMediaRule()) |
| 167 setHasMediaQueries(); | 169 setHasMediaQueries(); |
| 168 | 170 |
| 169 m_childRules.append(rule); | 171 m_childRules.append(rule); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void StyleSheetContents::setHasMediaQueries() | 174 void StyleSheetContents::setHasMediaQueries() |
| 173 { | 175 { |
| 174 m_hasMediaQueries = true; | 176 m_hasMediaQueries = true; |
| 175 if (parentStyleSheet()) | 177 if (parentStyleSheet()) |
| 176 parentStyleSheet()->setHasMediaQueries(); | 178 parentStyleSheet()->setHasMediaQueries(); |
| 177 } | 179 } |
| 178 | 180 |
| 179 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const | 181 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const |
| 180 { | 182 { |
| 181 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 183 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
| 182 | 184 |
| 183 if (index < m_importRules.size()) | 185 if (index < m_importRules.size()) |
| 184 return m_importRules[index].get(); | 186 return m_importRules[index].get(); |
| 185 | 187 |
| 186 index -= m_importRules.size(); | 188 index -= m_importRules.size(); |
| 189 | |
| 190 if (index < m_namespaceRules.size()) | |
| 191 return m_namespaceRules[index].get(); | |
| 192 | |
| 193 index -= m_namespaceRules.size(); | |
| 194 | |
| 187 return m_childRules[index].get(); | 195 return m_childRules[index].get(); |
| 188 } | 196 } |
| 189 | 197 |
| 190 unsigned StyleSheetContents::ruleCount() const | 198 unsigned StyleSheetContents::ruleCount() const |
| 191 { | 199 { |
| 192 return m_importRules.size() + m_childRules.size(); | 200 return m_importRules.size() + m_namespaceRules.size() + m_childRules.size(); |
| 193 } | 201 } |
| 194 | 202 |
| 195 void StyleSheetContents::clearRules() | 203 void StyleSheetContents::clearRules() |
| 196 { | 204 { |
| 197 for (unsigned i = 0; i < m_importRules.size(); ++i) { | 205 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
| 198 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); | 206 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); |
| 199 m_importRules[i]->clearParentStyleSheet(); | 207 m_importRules[i]->clearParentStyleSheet(); |
| 200 } | 208 } |
| 201 m_importRules.clear(); | 209 m_importRules.clear(); |
| 210 m_namespaceRules.clear(); | |
| 202 m_childRules.clear(); | 211 m_childRules.clear(); |
| 203 } | 212 } |
| 204 | 213 |
| 205 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule, unsigned index) | 214 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule, unsigned index) |
| 206 { | 215 { |
| 207 ASSERT(m_isMutable); | 216 ASSERT(m_isMutable); |
| 208 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); | 217 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); |
| 209 | 218 |
| 210 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) { | 219 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) { |
| 211 // Inserting non-import rule before @import is not allowed. | 220 // Inserting non-import rule before @import is not allowed. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 224 } | 233 } |
| 225 // Inserting @import rule after a non-import rule is not allowed. | 234 // Inserting @import rule after a non-import rule is not allowed. |
| 226 if (rule->isImportRule()) | 235 if (rule->isImportRule()) |
| 227 return false; | 236 return false; |
| 228 | 237 |
| 229 if (rule->isMediaRule()) | 238 if (rule->isMediaRule()) |
| 230 setHasMediaQueries(); | 239 setHasMediaQueries(); |
| 231 | 240 |
| 232 index -= m_importRules.size(); | 241 index -= m_importRules.size(); |
| 233 | 242 |
| 243 if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) { | |
| 244 // Inserting non-namespace rules other than import rule before @namespac e is not allowed. | |
| 245 if (!rule->isNamespaceRule()) | |
| 246 return false; | |
| 247 | |
| 248 StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get()); | |
| 249 m_namespaceRules.insert(index, namespaceRule); | |
|
Timothy Loh
2015/09/02 04:45:14
..don't we need to also update m_namespaces? Curre
ramya.v
2015/09/02 09:20:54
Done.
| |
| 250 return true; | |
| 251 } | |
| 252 | |
| 253 if (rule->isNamespaceRule()) | |
| 254 return false; | |
| 255 | |
| 256 index -= m_namespaceRules.size(); | |
| 257 | |
| 234 if (rule->isFontFaceRule()) | 258 if (rule->isFontFaceRule()) |
| 235 setHasFontFaceRule(true); | 259 setHasFontFaceRule(true); |
| 236 m_childRules.insert(index, rule); | 260 m_childRules.insert(index, rule); |
| 237 return true; | 261 return true; |
| 238 } | 262 } |
| 239 | 263 |
| 240 void StyleSheetContents::wrapperDeleteRule(unsigned index) | 264 void StyleSheetContents::wrapperDeleteRule(unsigned index) |
| 241 { | 265 { |
| 242 ASSERT(m_isMutable); | 266 ASSERT(m_isMutable); |
| 243 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 267 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
| 244 | 268 |
| 245 if (index < m_importRules.size()) { | 269 if (index < m_importRules.size()) { |
| 246 m_importRules[index]->clearParentStyleSheet(); | 270 m_importRules[index]->clearParentStyleSheet(); |
| 247 if (m_importRules[index]->isFontFaceRule()) | 271 if (m_importRules[index]->isFontFaceRule()) |
| 248 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge t())); | 272 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge t())); |
| 249 m_importRules.remove(index); | 273 m_importRules.remove(index); |
| 250 return; | 274 return; |
| 251 } | 275 } |
| 252 index -= m_importRules.size(); | 276 index -= m_importRules.size(); |
| 253 | 277 |
| 278 if (index < m_namespaceRules.size()) { | |
|
Timothy Loh
2015/09/02 04:45:14
From the spec:
If old rule is an @namespace at-rul
ramya.v
2015/09/02 09:20:54
Done.
| |
| 279 m_namespaceRules.remove(index); | |
| 280 return; | |
| 281 } | |
| 282 index -= m_namespaceRules.size(); | |
| 283 | |
| 254 if (m_childRules[index]->isFontFaceRule()) | 284 if (m_childRules[index]->isFontFaceRule()) |
| 255 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get())) ; | 285 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get())) ; |
| 256 m_childRules.remove(index); | 286 m_childRules.remove(index); |
| 257 } | 287 } |
| 258 | 288 |
| 259 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) | 289 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) |
| 260 { | 290 { |
| 261 if (uri.isNull() || prefix.isNull()) | 291 if (uri.isNull() || prefix.isNull()) |
| 262 return; | 292 return; |
| 263 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); | 293 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 } | 647 } |
| 618 | 648 |
| 619 findFontFaceRulesFromRules(childRules(), fontFaceRules); | 649 findFontFaceRulesFromRules(childRules(), fontFaceRules); |
| 620 } | 650 } |
| 621 | 651 |
| 622 DEFINE_TRACE(StyleSheetContents) | 652 DEFINE_TRACE(StyleSheetContents) |
| 623 { | 653 { |
| 624 #if ENABLE(OILPAN) | 654 #if ENABLE(OILPAN) |
| 625 visitor->trace(m_ownerRule); | 655 visitor->trace(m_ownerRule); |
| 626 visitor->trace(m_importRules); | 656 visitor->trace(m_importRules); |
| 657 visitor->trace(m_namespaceRules); | |
| 627 visitor->trace(m_childRules); | 658 visitor->trace(m_childRules); |
| 628 visitor->trace(m_loadingClients); | 659 visitor->trace(m_loadingClients); |
| 629 visitor->trace(m_completedClients); | 660 visitor->trace(m_completedClients); |
| 630 visitor->trace(m_ruleSet); | 661 visitor->trace(m_ruleSet); |
| 631 #endif | 662 #endif |
| 632 } | 663 } |
| 633 | 664 |
| 634 } | 665 } |
| OLD | NEW |