Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: Source/core/css/StyleSheetContents.cpp

Issue 1321943002: Support for CSSOM CSSNamespaceRule interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per review comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/StyleSheetContents.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 , m_hasMediaQueries(false) 68 , m_hasMediaQueries(false)
69 , m_hasSingleOwnerDocument(true) 69 , m_hasSingleOwnerDocument(true)
70 , m_parserContext(context) 70 , m_parserContext(context)
71 { 71 {
72 } 72 }
73 73
74 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) 74 StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
75 : m_ownerRule(nullptr) 75 : m_ownerRule(nullptr)
76 , m_originalURL(o.m_originalURL) 76 , m_originalURL(o.m_originalURL)
77 , m_importRules(o.m_importRules.size()) 77 , m_importRules(o.m_importRules.size())
78 , m_namespaceRules(o.m_namespaceRules.size())
78 , m_childRules(o.m_childRules.size()) 79 , m_childRules(o.m_childRules.size())
79 , m_namespaces(o.m_namespaces) 80 , m_namespaces(o.m_namespaces)
80 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) 81 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader)
81 , m_didLoadErrorOccur(false) 82 , m_didLoadErrorOccur(false)
82 , m_isMutable(false) 83 , m_isMutable(false)
83 , m_isInMemoryCache(false) 84 , m_isInMemoryCache(false)
84 , m_hasFontFaceRule(o.m_hasFontFaceRule) 85 , m_hasFontFaceRule(o.m_hasFontFaceRule)
85 , m_hasMediaQueries(o.m_hasMediaQueries) 86 , m_hasMediaQueries(o.m_hasMediaQueries)
86 , m_hasSingleOwnerDocument(true) 87 , m_hasSingleOwnerDocument(true)
87 , m_parserContext(o.m_parserContext) 88 , m_parserContext(o.m_parserContext)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 StyleRuleImport* importRule = toStyleRuleImport(rule.get()); 150 StyleRuleImport* importRule = toStyleRuleImport(rule.get());
150 if (importRule->mediaQueries()) 151 if (importRule->mediaQueries())
151 setHasMediaQueries(); 152 setHasMediaQueries();
152 m_importRules.append(importRule); 153 m_importRules.append(importRule);
153 m_importRules.last()->setParentStyleSheet(this); 154 m_importRules.last()->setParentStyleSheet(this);
154 m_importRules.last()->requestStyleSheet(); 155 m_importRules.last()->requestStyleSheet();
155 return; 156 return;
156 } 157 }
157 158
158 if (rule->isNamespaceRule()) { 159 if (rule->isNamespaceRule()) {
159 // Parser enforces that @namespace rules come before anything else 160 // Parser enforces that @namespace rules come before all rules other tha n
161 // import/namespace/charset rules
Timothy Loh 2015/09/04 01:35:50 not sure you want to write namespace here
ramya.v 2015/09/07 09:06:28 Done.
160 ASSERT(m_childRules.isEmpty()); 162 ASSERT(m_childRules.isEmpty());
161 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); 163 StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule);
162 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); 164 parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
165 m_namespaceRules.append(&namespaceRule);
163 return; 166 return;
164 } 167 }
165 168
166 if (rule->isMediaRule()) 169 if (rule->isMediaRule())
167 setHasMediaQueries(); 170 setHasMediaQueries();
168 171
169 m_childRules.append(rule); 172 m_childRules.append(rule);
170 } 173 }
171 174
172 void StyleSheetContents::setHasMediaQueries() 175 void StyleSheetContents::setHasMediaQueries()
173 { 176 {
174 m_hasMediaQueries = true; 177 m_hasMediaQueries = true;
175 if (parentStyleSheet()) 178 if (parentStyleSheet())
176 parentStyleSheet()->setHasMediaQueries(); 179 parentStyleSheet()->setHasMediaQueries();
177 } 180 }
178 181
179 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const 182 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const
180 { 183 {
181 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); 184 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount());
182 185
183 if (index < m_importRules.size()) 186 if (index < m_importRules.size())
184 return m_importRules[index].get(); 187 return m_importRules[index].get();
185 188
186 index -= m_importRules.size(); 189 index -= m_importRules.size();
190
191 if (index < m_namespaceRules.size())
192 return m_namespaceRules[index].get();
193
194 index -= m_namespaceRules.size();
195
187 return m_childRules[index].get(); 196 return m_childRules[index].get();
188 } 197 }
189 198
190 unsigned StyleSheetContents::ruleCount() const 199 unsigned StyleSheetContents::ruleCount() const
191 { 200 {
192 return m_importRules.size() + m_childRules.size(); 201 return m_importRules.size() + m_namespaceRules.size() + m_childRules.size();
193 } 202 }
194 203
195 void StyleSheetContents::clearRules() 204 void StyleSheetContents::clearRules()
196 { 205 {
197 for (unsigned i = 0; i < m_importRules.size(); ++i) { 206 for (unsigned i = 0; i < m_importRules.size(); ++i) {
198 ASSERT(m_importRules.at(i)->parentStyleSheet() == this); 207 ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
199 m_importRules[i]->clearParentStyleSheet(); 208 m_importRules[i]->clearParentStyleSheet();
200 } 209 }
201 m_importRules.clear(); 210 m_importRules.clear();
211 m_namespaceRules.clear();
202 m_childRules.clear(); 212 m_childRules.clear();
203 } 213 }
204 214
205 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule, unsigned index) 215 bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule, unsigned index)
206 { 216 {
207 ASSERT(m_isMutable); 217 ASSERT(m_isMutable);
208 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); 218 ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount());
209 219
210 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) { 220 if (index < m_importRules.size() || (index == m_importRules.size() && rule-> isImportRule())) {
211 // Inserting non-import rule before @import is not allowed. 221 // Inserting non-import rule before @import is not allowed.
(...skipping 12 matching lines...) Expand all
224 } 234 }
225 // Inserting @import rule after a non-import rule is not allowed. 235 // Inserting @import rule after a non-import rule is not allowed.
226 if (rule->isImportRule()) 236 if (rule->isImportRule())
227 return false; 237 return false;
228 238
229 if (rule->isMediaRule()) 239 if (rule->isMediaRule())
230 setHasMediaQueries(); 240 setHasMediaQueries();
231 241
232 index -= m_importRules.size(); 242 index -= m_importRules.size();
233 243
244 if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) {
245 // Inserting non-namespace rules other than import rule before @namespac e is not allowed.
246 if (!rule->isNamespaceRule())
247 return false;
248 // Inserting @namespace rule when rules other than import/namespace/char set are present is not allowed.
249 if (m_childRules.size() > 0)
250 return false;
251
252 StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get());
253 m_namespaceRules.insert(index, namespaceRule);
254 parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri());
Timothy Loh 2015/09/04 01:35:50 parserAddNamespace won't do what you want here. If
ramya.v 2015/09/07 05:28:23 Hi Tim just one doubt. As per spec it was given If
255 return true;
256 }
257
258 if (rule->isNamespaceRule())
259 return false;
260
261 index -= m_namespaceRules.size();
262
234 if (rule->isFontFaceRule()) 263 if (rule->isFontFaceRule())
235 setHasFontFaceRule(true); 264 setHasFontFaceRule(true);
236 m_childRules.insert(index, rule); 265 m_childRules.insert(index, rule);
237 return true; 266 return true;
238 } 267 }
239 268
240 void StyleSheetContents::wrapperDeleteRule(unsigned index) 269 bool StyleSheetContents::wrapperDeleteRule(unsigned index)
241 { 270 {
242 ASSERT(m_isMutable); 271 ASSERT(m_isMutable);
243 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); 272 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount());
244 273
245 if (index < m_importRules.size()) { 274 if (index < m_importRules.size()) {
246 m_importRules[index]->clearParentStyleSheet(); 275 m_importRules[index]->clearParentStyleSheet();
247 if (m_importRules[index]->isFontFaceRule()) 276 if (m_importRules[index]->isFontFaceRule())
248 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge t())); 277 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].ge t()));
249 m_importRules.remove(index); 278 m_importRules.remove(index);
250 return; 279 return true;
251 } 280 }
252 index -= m_importRules.size(); 281 index -= m_importRules.size();
253 282
283 if (index < m_namespaceRules.size()) {
284 if (m_childRules.size() > 0)
Timothy Loh 2015/09/04 01:35:50 !m_childRules.isEmpty() probably reads better
ramya.v 2015/09/07 09:06:28 Done.
285 return false;
286 m_namespaceRules.remove(index);
287 return true;
288 }
289 index -= m_namespaceRules.size();
290
254 if (m_childRules[index]->isFontFaceRule()) 291 if (m_childRules[index]->isFontFaceRule())
255 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get())) ; 292 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get())) ;
256 m_childRules.remove(index); 293 m_childRules.remove(index);
294 return true;
257 } 295 }
258 296
259 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) 297 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri)
260 { 298 {
261 if (uri.isNull() || prefix.isNull()) 299 if (uri.isNull() || prefix.isNull())
262 return; 300 return;
263 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); 301 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri);
264 if (result.isNewEntry) 302 if (result.isNewEntry)
265 return; 303 return;
266 result.storedValue->value = uri; 304 result.storedValue->value = uri;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 655 }
618 656
619 findFontFaceRulesFromRules(childRules(), fontFaceRules); 657 findFontFaceRulesFromRules(childRules(), fontFaceRules);
620 } 658 }
621 659
622 DEFINE_TRACE(StyleSheetContents) 660 DEFINE_TRACE(StyleSheetContents)
623 { 661 {
624 #if ENABLE(OILPAN) 662 #if ENABLE(OILPAN)
625 visitor->trace(m_ownerRule); 663 visitor->trace(m_ownerRule);
626 visitor->trace(m_importRules); 664 visitor->trace(m_importRules);
665 visitor->trace(m_namespaceRules);
627 visitor->trace(m_childRules); 666 visitor->trace(m_childRules);
628 visitor->trace(m_loadingClients); 667 visitor->trace(m_loadingClients);
629 visitor->trace(m_completedClients); 668 visitor->trace(m_completedClients);
630 visitor->trace(m_ruleSet); 669 visitor->trace(m_ruleSet);
631 #endif 670 #endif
632 } 671 }
633 672
634 } 673 }
OLDNEW
« no previous file with comments | « Source/core/css/StyleSheetContents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698