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

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

Issue 82583005: Use removeFontFace to avoid resetting fontSelector. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added 2 layout tests Created 7 years 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 | Annotate | Revision Log
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,
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/CSSParser.h" 24 #include "core/css/CSSParser.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 "platform/TraceEvent.h" 34 #include "platform/TraceEvent.h"
35 #include "platform/weborigin/SecurityOrigin.h" 35 #include "platform/weborigin/SecurityOrigin.h"
36 #include "wtf/Deque.h" 36 #include "wtf/Deque.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 // Rough size estimate for the memory cache. 40 // Rough size estimate for the memory cache.
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 m_importRules[childVectorIndex]->setParentStyleSheet(this); 235 m_importRules[childVectorIndex]->setParentStyleSheet(this);
236 m_importRules[childVectorIndex]->requestStyleSheet(); 236 m_importRules[childVectorIndex]->requestStyleSheet();
237 // FIXME: Stylesheet doesn't actually change meaningfully before the imp orted sheets are loaded. 237 // FIXME: Stylesheet doesn't actually change meaningfully before the imp orted sheets are loaded.
238 return true; 238 return true;
239 } 239 }
240 // Inserting @import rule after a non-import rule is not allowed. 240 // Inserting @import rule after a non-import rule is not allowed.
241 if (rule->isImportRule()) 241 if (rule->isImportRule())
242 return false; 242 return false;
243 childVectorIndex -= m_importRules.size(); 243 childVectorIndex -= m_importRules.size();
244 244
245 if (rule->isFontFaceRule())
246 setHasFontFaceRule(true);
245 m_childRules.insert(childVectorIndex, rule); 247 m_childRules.insert(childVectorIndex, rule);
246 return true; 248 return true;
247 } 249 }
248 250
249 void StyleSheetContents::wrapperDeleteRule(unsigned index) 251 void StyleSheetContents::wrapperDeleteRule(unsigned index)
250 { 252 {
251 ASSERT(m_isMutable); 253 ASSERT(m_isMutable);
252 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); 254 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount());
253 255
254 unsigned childVectorIndex = index; 256 unsigned childVectorIndex = index;
255 if (hasCharsetRule()) { 257 if (hasCharsetRule()) {
256 if (childVectorIndex == 0) { 258 if (childVectorIndex == 0) {
257 clearCharsetRule(); 259 clearCharsetRule();
258 return; 260 return;
259 } 261 }
260 --childVectorIndex; 262 --childVectorIndex;
261 } 263 }
262 if (childVectorIndex < m_importRules.size()) { 264 if (childVectorIndex < m_importRules.size()) {
263 m_importRules[childVectorIndex]->clearParentStyleSheet(); 265 m_importRules[childVectorIndex]->clearParentStyleSheet();
266 if (m_importRules[childVectorIndex]->isFontFaceRule())
267 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[childVect orIndex].get()));
264 m_importRules.remove(childVectorIndex); 268 m_importRules.remove(childVectorIndex);
265 return; 269 return;
266 } 270 }
267 childVectorIndex -= m_importRules.size(); 271 childVectorIndex -= m_importRules.size();
268 272
273 if (m_childRules[childVectorIndex]->isFontFaceRule())
274 notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[childVectorInd ex].get()));
269 m_childRules.remove(childVectorIndex); 275 m_childRules.remove(childVectorIndex);
270 } 276 }
271 277
272 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri) 278 void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const At omicString& uri)
273 { 279 {
274 if (uri.isNull() || prefix.isNull()) 280 if (uri.isNull() || prefix.isNull())
275 return; 281 return;
276 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri); 282 PrefixNamespaceURIMap::AddResult result = m_namespaces.add(prefix, uri);
277 if (result.isNewEntry) 283 if (result.isNewEntry)
278 return; 284 return;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 547
542 // Clearing the ruleSet means we need to recreate the styleResolver data str uctures. 548 // Clearing the ruleSet means we need to recreate the styleResolver data str uctures.
543 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. 549 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet.
544 for (size_t i = 0; i < m_clients.size(); ++i) { 550 for (size_t i = 0; i < m_clients.size(); ++i) {
545 if (Document* document = m_clients[i]->ownerDocument()) 551 if (Document* document = m_clients[i]->ownerDocument())
546 document->styleEngine()->clearResolver(); 552 document->styleEngine()->clearResolver();
547 } 553 }
548 m_ruleSet.clear(); 554 m_ruleSet.clear();
549 } 555 }
550 556
557 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF aceRule)
558 {
559 StyleSheetContents* root = rootStyleSheet();
560 if (root->m_clients.isEmpty())
561 return;
562
563 for (unsigned i = 0; i < root->m_clients.size(); ++i) {
564 if (Node* ownerNode = root->m_clients[0]->ownerNode())
565 ownerNode->document().styleEngine()->removeFontFaceRules(Vector<cons t StyleRuleFontFace*>(1, fontFaceRule));
566 }
567 }
568
569 static void findFontFaceRulesFromRules(const Vector<RefPtr<StyleRuleBase> >& rul es, Vector<const StyleRuleFontFace*>& fontFaceRules)
570 {
571 for (unsigned i = 0; i < rules.size(); ++i) {
572 StyleRuleBase* rule = rules[i].get();
573
574 if (rule->isFontFaceRule()) {
575 fontFaceRules.append(toStyleRuleFontFace(rule));
576 } else if (rule->isMediaRule()) {
577 StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule);
578 // We cannot know whether the media rule matches or not, but
579 // for safety, remove @font-face in the media rule (if exists).
580 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules);
581 }
582 }
583 }
584
585 void StyleSheetContents::findFontFaceRules(Vector<const StyleRuleFontFace*>& fon tFaceRules)
586 {
587 for (unsigned i = 0; i < m_importRules.size(); ++i) {
588 if (!m_importRules[i]->styleSheet())
589 continue;
590 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules);
591 }
592
593 findFontFaceRulesFromRules(childRules(), fontFaceRules);
594 }
551 595
552 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698