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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "config.h" | 21 #include "config.h" |
| 22 #include "core/css/StyleSheetContents.h" | 22 #include "core/css/StyleSheetContents.h" |
| 23 | 23 |
| 24 #include "core/css/parser/BisonCSSParser.h" | 24 #include "core/css/parser/BisonCSSParser.h" |
| 25 #include "core/css/CSSStyleSheet.h" | 25 #include "core/css/CSSStyleSheet.h" |
| 26 #include "core/css/MediaList.h" | 26 #include "core/css/MediaList.h" |
| 27 #include "core/css/StylePropertySet.h" | 27 #include "core/css/StylePropertySet.h" |
| 28 #include "core/css/StyleRule.h" | 28 #include "core/css/StyleRule.h" |
| 29 #include "core/css/StyleRuleImport.h" | 29 #include "core/css/StyleRuleImport.h" |
| 30 #include "core/css/resolver/StyleResolver.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/Node.h" | 31 #include "core/dom/Node.h" |
| 32 #include "core/dom/StyleEngine.h" | 32 #include "core/dom/StyleEngine.h" |
| 33 #include "core/fetch/CSSStyleSheetResource.h" | 33 #include "core/fetch/CSSStyleSheetResource.h" |
| 34 #include "core/frame/UseCounter.h" | 34 #include "core/frame/UseCounter.h" |
| 35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
| 37 #include "wtf/Deque.h" | 37 #include "wtf/Deque.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 259 } |
| 260 // Inserting @import rule after a non-import rule is not allowed. | 260 // Inserting @import rule after a non-import rule is not allowed. |
| 261 if (rule->isImportRule()) | 261 if (rule->isImportRule()) |
| 262 return false; | 262 return false; |
| 263 | 263 |
| 264 if (rule->isMediaRule()) | 264 if (rule->isMediaRule()) |
| 265 setHasMediaQueries(); | 265 setHasMediaQueries(); |
| 266 | 266 |
| 267 childVectorIndex -= m_importRules.size(); | 267 childVectorIndex -= m_importRules.size(); |
| 268 | 268 |
| 269 if (rule->isFontFaceRule()) | |
| 270 setHasFontFaceRule(true); | |
| 269 m_childRules.insert(childVectorIndex, rule); | 271 m_childRules.insert(childVectorIndex, rule); |
| 270 return true; | 272 return true; |
| 271 } | 273 } |
| 272 | 274 |
| 273 void StyleSheetContents::wrapperDeleteRule(unsigned index) | 275 void StyleSheetContents::wrapperDeleteRule(unsigned index) |
| 274 { | 276 { |
| 275 ASSERT(m_isMutable); | 277 ASSERT(m_isMutable); |
| 276 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 278 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
| 277 | 279 |
| 278 unsigned childVectorIndex = index; | 280 unsigned childVectorIndex = index; |
| 279 if (hasCharsetRule()) { | 281 if (hasCharsetRule()) { |
| 280 if (childVectorIndex == 0) { | 282 if (childVectorIndex == 0) { |
| 281 clearCharsetRule(); | 283 clearCharsetRule(); |
| 282 return; | 284 return; |
| 283 } | 285 } |
| 284 --childVectorIndex; | 286 --childVectorIndex; |
| 285 } | 287 } |
| 286 if (childVectorIndex < m_importRules.size()) { | 288 if (childVectorIndex < m_importRules.size()) { |
| 287 m_importRules[childVectorIndex]->clearParentStyleSheet(); | 289 m_importRules[childVectorIndex]->clearParentStyleSheet(); |
| 290 if (m_importRules[childVectorIndex]->isFontFaceRule()) | |
| 291 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[childVect orIndex].get())); | |
| 288 m_importRules.remove(childVectorIndex); | 292 m_importRules.remove(childVectorIndex); |
| 289 return; | 293 return; |
| 290 } | 294 } |
| 291 childVectorIndex -= m_importRules.size(); | 295 childVectorIndex -= m_importRules.size(); |
| 292 | 296 |
| 297 if (m_childRules[childVectorIndex]->isFontFaceRule()) | |
| 298 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[childVectorInd ex].get())); | |
| 293 m_childRules.remove(childVectorIndex); | 299 m_childRules.remove(childVectorIndex); |
| 294 } | 300 } |
| 295 | 301 |
| 296 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) | 302 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) |
| 297 { | 303 { |
| 298 if (uri.isNull() || prefix.isNull()) | 304 if (uri.isNull() || prefix.isNull()) |
| 299 return; | 305 return; |
| 300 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); | 306 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); |
| 301 if (result.isNewEntry) | 307 if (result.isNewEntry) |
| 302 return; | 308 return; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 | 573 |
| 568 // Clearing the ruleSet means we need to recreate the styleResolver data str uctures. | 574 // Clearing the ruleSet means we need to recreate the styleResolver data str uctures. |
| 569 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. | 575 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. |
| 570 for (size_t i = 0; i < m_clients.size(); ++i) { | 576 for (size_t i = 0; i < m_clients.size(); ++i) { |
| 571 if (Document* document = m_clients[i]->ownerDocument()) | 577 if (Document* document = m_clients[i]->ownerDocument()) |
| 572 document->styleEngine()->clearResolver(); | 578 document->styleEngine()->clearResolver(); |
| 573 } | 579 } |
| 574 m_ruleSet.clear(); | 580 m_ruleSet.clear(); |
| 575 } | 581 } |
| 576 | 582 |
| 583 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF aceRule) | |
| 584 { | |
| 585 StyleSheetContents* root = rootStyleSheet(); | |
| 586 if (root->m_clients.isEmpty()) | |
|
eseidel
2014/02/14 05:39:15
This is redundant with the for loop.
tasak
2014/02/14 08:27:46
Done.
| |
| 587 return; | |
| 588 | |
| 589 for (unsigned i = 0; i < root->m_clients.size(); ++i) { | |
| 590 if (Node* ownerNode = root->m_clients[0]->ownerNode()) | |
| 591 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<cons t StyleRuleFontFace*>(1, fontFaceRule)); | |
| 592 } | |
| 593 } | |
| 594 | |
| 595 static void findFontFaceRulesFromRules(const Vector<RefPtr<StyleRuleBase> >& rul es, Vector<const StyleRuleFontFace*>& fontFaceRules) | |
| 596 { | |
| 597 for (unsigned i = 0; i < rules.size(); ++i) { | |
| 598 StyleRuleBase* rule = rules[i].get(); | |
| 599 | |
| 600 if (rule->isFontFaceRule()) { | |
| 601 fontFaceRules.append(toStyleRuleFontFace(rule)); | |
| 602 } else if (rule->isMediaRule()) { | |
| 603 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule); | |
|
eseidel
2014/02/14 05:39:15
I'm surprised we don't have a toStyleRuleMedia() h
tasak
2014/02/14 08:27:46
Sorry. I missed the helper. Done.
| |
| 604 // We cannot know whether the media rule matches or not, but | |
| 605 // for safety, remove @font-face in the media rule (if exists). | |
| 606 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); | |
| 607 } | |
| 608 } | |
| 609 } | |
| 610 | |
| 611 void StyleSheetContents::findFontFaceRules(Vector<const StyleRuleFontFace*>& fon tFaceRules) | |
| 612 { | |
| 613 for (unsigned i = 0; i < m_importRules.size(); ++i) { | |
| 614 if (!m_importRules[i]->styleSheet()) | |
| 615 continue; | |
| 616 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules); | |
| 617 } | |
| 618 | |
| 619 findFontFaceRulesFromRules(childRules(), fontFaceRules); | |
| 620 } | |
| 577 | 621 |
| 578 void StyleSheetContents::trace(Visitor*) | 622 void StyleSheetContents::trace(Visitor*) |
| 579 { | 623 { |
| 580 } | 624 } |
| 581 | 625 |
| 582 } | 626 } |
| OLD | NEW |