| 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/dom/Document.h" | 30 #include "core/css/resolver/StyleResolver.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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 m_importRules[childVectorIndex]->setParentStyleSheet(this); | 238 m_importRules[childVectorIndex]->setParentStyleSheet(this); |
| 239 m_importRules[childVectorIndex]->requestStyleSheet(); | 239 m_importRules[childVectorIndex]->requestStyleSheet(); |
| 240 // FIXME: Stylesheet doesn't actually change meaningfully before the imp
orted sheets are loaded. | 240 // FIXME: Stylesheet doesn't actually change meaningfully before the imp
orted sheets are loaded. |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 // Inserting @import rule after a non-import rule is not allowed. | 243 // Inserting @import rule after a non-import rule is not allowed. |
| 244 if (rule->isImportRule()) | 244 if (rule->isImportRule()) |
| 245 return false; | 245 return false; |
| 246 childVectorIndex -= m_importRules.size(); | 246 childVectorIndex -= m_importRules.size(); |
| 247 | 247 |
| 248 if (rule->isFontFaceRule()) | |
| 249 setHasFontFaceRule(true); | |
| 250 m_childRules.insert(childVectorIndex, rule); | 248 m_childRules.insert(childVectorIndex, rule); |
| 251 return true; | 249 return true; |
| 252 } | 250 } |
| 253 | 251 |
| 254 void StyleSheetContents::wrapperDeleteRule(unsigned index) | 252 void StyleSheetContents::wrapperDeleteRule(unsigned index) |
| 255 { | 253 { |
| 256 ASSERT(m_isMutable); | 254 ASSERT(m_isMutable); |
| 257 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); | 255 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); |
| 258 | 256 |
| 259 unsigned childVectorIndex = index; | 257 unsigned childVectorIndex = index; |
| 260 if (hasCharsetRule()) { | 258 if (hasCharsetRule()) { |
| 261 if (childVectorIndex == 0) { | 259 if (childVectorIndex == 0) { |
| 262 clearCharsetRule(); | 260 clearCharsetRule(); |
| 263 return; | 261 return; |
| 264 } | 262 } |
| 265 --childVectorIndex; | 263 --childVectorIndex; |
| 266 } | 264 } |
| 267 if (childVectorIndex < m_importRules.size()) { | 265 if (childVectorIndex < m_importRules.size()) { |
| 268 m_importRules[childVectorIndex]->clearParentStyleSheet(); | 266 m_importRules[childVectorIndex]->clearParentStyleSheet(); |
| 269 if (m_importRules[childVectorIndex]->isFontFaceRule()) | |
| 270 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[childVect
orIndex].get())); | |
| 271 m_importRules.remove(childVectorIndex); | 267 m_importRules.remove(childVectorIndex); |
| 272 return; | 268 return; |
| 273 } | 269 } |
| 274 childVectorIndex -= m_importRules.size(); | 270 childVectorIndex -= m_importRules.size(); |
| 275 | 271 |
| 276 if (m_childRules[childVectorIndex]->isFontFaceRule()) | |
| 277 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[childVectorInd
ex].get())); | |
| 278 m_childRules.remove(childVectorIndex); | 272 m_childRules.remove(childVectorIndex); |
| 279 } | 273 } |
| 280 | 274 |
| 281 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) | 275 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At
omicString& uri) |
| 282 { | 276 { |
| 283 if (uri.isNull() || prefix.isNull()) | 277 if (uri.isNull() || prefix.isNull()) |
| 284 return; | 278 return; |
| 285 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); | 279 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); |
| 286 if (result.isNewEntry) | 280 if (result.isNewEntry) |
| 287 return; | 281 return; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 520 |
| 527 // Clearing the ruleSet means we need to recreate the styleResolver data str
uctures. | 521 // Clearing the ruleSet means we need to recreate the styleResolver data str
uctures. |
| 528 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. | 522 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. |
| 529 for (size_t i = 0; i < m_clients.size(); ++i) { | 523 for (size_t i = 0; i < m_clients.size(); ++i) { |
| 530 if (Document* document = m_clients[i]->ownerDocument()) | 524 if (Document* document = m_clients[i]->ownerDocument()) |
| 531 document->styleEngine()->clearResolver(); | 525 document->styleEngine()->clearResolver(); |
| 532 } | 526 } |
| 533 m_ruleSet.clear(); | 527 m_ruleSet.clear(); |
| 534 } | 528 } |
| 535 | 529 |
| 536 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF
aceRule) | |
| 537 { | |
| 538 StyleSheetContents* root = rootStyleSheet(); | |
| 539 if (root->m_clients.isEmpty()) | |
| 540 return; | |
| 541 | |
| 542 for (unsigned i = 0; i < root->m_clients.size(); ++i) { | |
| 543 if (Node* ownerNode = root->m_clients[0]->ownerNode()) | |
| 544 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<cons
t StyleRuleFontFace*>(1, fontFaceRule)); | |
| 545 } | |
| 546 } | |
| 547 | |
| 548 static void findFontFaceRulesFromRules(const Vector<RefPtr<StyleRuleBase> >& rul
es, Vector<const StyleRuleFontFace*>& fontFaceRules) | |
| 549 { | |
| 550 for (unsigned i = 0; i < rules.size(); ++i) { | |
| 551 StyleRuleBase* rule = rules[i].get(); | |
| 552 | |
| 553 if (rule->isFontFaceRule()) { | |
| 554 fontFaceRules.append(toStyleRuleFontFace(rule)); | |
| 555 } else if (rule->isMediaRule()) { | |
| 556 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule); | |
| 557 // We cannot know whether the media rule matches or not, but | |
| 558 // for safety, remove @font-face in the media rule (if exists). | |
| 559 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); | |
| 560 } | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 void StyleSheetContents::findFontFaceRules(Vector<const StyleRuleFontFace*>& fon
tFaceRules) | |
| 565 { | |
| 566 for (unsigned i = 0; i < m_importRules.size(); ++i) { | |
| 567 if (!m_importRules[i]->styleSheet()) | |
| 568 continue; | |
| 569 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules); | |
| 570 } | |
| 571 | |
| 572 findFontFaceRulesFromRules(childRules(), fontFaceRules); | |
| 573 } | |
| 574 | 530 |
| 575 } | 531 } |
| OLD | NEW |