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 |
| 587 for (unsigned i = 0; i < root->m_clients.size(); ++i) { |
| 588 if (Node* ownerNode = root->m_clients[0]->ownerNode()) |
| 589 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<cons
t StyleRuleFontFace*>(1, fontFaceRule)); |
| 590 } |
| 591 } |
| 592 |
| 593 static void findFontFaceRulesFromRules(const Vector<RefPtr<StyleRuleBase> >& rul
es, Vector<const StyleRuleFontFace*>& fontFaceRules) |
| 594 { |
| 595 for (unsigned i = 0; i < rules.size(); ++i) { |
| 596 StyleRuleBase* rule = rules[i].get(); |
| 597 |
| 598 if (rule->isFontFaceRule()) { |
| 599 fontFaceRules.append(toStyleRuleFontFace(rule)); |
| 600 } else if (rule->isMediaRule()) { |
| 601 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); |
| 602 // We cannot know whether the media rule matches or not, but |
| 603 // for safety, remove @font-face in the media rule (if exists). |
| 604 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); |
| 605 } |
| 606 } |
| 607 } |
| 608 |
| 609 void StyleSheetContents::findFontFaceRules(Vector<const StyleRuleFontFace*>& fon
tFaceRules) |
| 610 { |
| 611 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
| 612 if (!m_importRules[i]->styleSheet()) |
| 613 continue; |
| 614 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules); |
| 615 } |
| 616 |
| 617 findFontFaceRulesFromRules(childRules(), fontFaceRules); |
| 618 } |
577 | 619 |
578 void StyleSheetContents::trace(Visitor*) | 620 void StyleSheetContents::trace(Visitor*) |
579 { | 621 { |
580 } | 622 } |
581 | 623 |
582 } | 624 } |
OLD | NEW |