| 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, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 return; | 364 return; |
| 365 | 365 |
| 366 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run
via | 366 // Avoid |CSSSStyleSheet| and |ownerNode| being deleted by scripts that run
via |
| 367 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote
ct | 367 // ScriptableDocumentParser::executeScriptsWaitingForResources(). Also prote
ct |
| 368 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa
ded| | 368 // the |CSSStyleSheet| from being deleted during iteration via the |sheetLoa
ded| |
| 369 // method. | 369 // method. |
| 370 // | 370 // |
| 371 // When a sheet is loaded it is moved from the set of loading clients | 371 // When a sheet is loaded it is moved from the set of loading clients |
| 372 // to the set of completed clients. We therefore need the copy in order to | 372 // to the set of completed clients. We therefore need the copy in order to |
| 373 // not modify the set while iterating it. | 373 // not modify the set while iterating it. |
| 374 WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> > loadingClients; | 374 WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet>> loadingClients; |
| 375 copyToVector(m_loadingClients, loadingClients); | 375 copyToVector(m_loadingClients, loadingClients); |
| 376 | 376 |
| 377 for (unsigned i = 0; i < loadingClients.size(); ++i) { | 377 for (unsigned i = 0; i < loadingClients.size(); ++i) { |
| 378 if (loadingClients[i]->loadCompleted()) | 378 if (loadingClients[i]->loadCompleted()) |
| 379 continue; | 379 continue; |
| 380 | 380 |
| 381 // sheetLoaded might be invoked after its owner node is removed from doc
ument. | 381 // sheetLoaded might be invoked after its owner node is removed from doc
ument. |
| 382 if (RefPtrWillBeRawPtr<Node> ownerNode = loadingClients[i]->ownerNode())
{ | 382 if (RefPtrWillBeRawPtr<Node> ownerNode = loadingClients[i]->ownerNode())
{ |
| 383 if (loadingClients[i]->sheetLoaded()) | 383 if (loadingClients[i]->sheetLoaded()) |
| 384 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad
ErrorOccur); | 384 ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoad
ErrorOccur); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 399 void StyleSheetContents::startLoadingDynamicSheet() | 399 void StyleSheetContents::startLoadingDynamicSheet() |
| 400 { | 400 { |
| 401 StyleSheetContents* root = rootStyleSheet(); | 401 StyleSheetContents* root = rootStyleSheet(); |
| 402 for (const auto& client : root->m_loadingClients) | 402 for (const auto& client : root->m_loadingClients) |
| 403 client->startLoadingDynamicSheet(); | 403 client->startLoadingDynamicSheet(); |
| 404 // Copy the completed clients to a vector for iteration. | 404 // Copy the completed clients to a vector for iteration. |
| 405 // startLoadingDynamicSheet will move the style sheet from the | 405 // startLoadingDynamicSheet will move the style sheet from the |
| 406 // completed state to the loading state which modifies the set of | 406 // completed state to the loading state which modifies the set of |
| 407 // completed clients. We therefore need the copy in order to not | 407 // completed clients. We therefore need the copy in order to not |
| 408 // modify the set of completed clients while iterating it. | 408 // modify the set of completed clients while iterating it. |
| 409 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > completedClients; | 409 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet>> completedClients; |
| 410 copyToVector(root->m_completedClients, completedClients); | 410 copyToVector(root->m_completedClients, completedClients); |
| 411 for (unsigned i = 0; i < completedClients.size(); ++i) | 411 for (unsigned i = 0; i < completedClients.size(); ++i) |
| 412 completedClients[i]->startLoadingDynamicSheet(); | 412 completedClients[i]->startLoadingDynamicSheet(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 StyleSheetContents* StyleSheetContents::rootStyleSheet() const | 415 StyleSheetContents* StyleSheetContents::rootStyleSheet() const |
| 416 { | 416 { |
| 417 const StyleSheetContents* root = this; | 417 const StyleSheetContents* root = this; |
| 418 while (root->parentStyleSheet()) | 418 while (root->parentStyleSheet()) |
| 419 root = root->parentStyleSheet(); | 419 root = root->parentStyleSheet(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 440 StyleSheetContents* root = rootStyleSheet(); | 440 StyleSheetContents* root = rootStyleSheet(); |
| 441 return root->clientSingleOwnerDocument(); | 441 return root->clientSingleOwnerDocument(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 KURL StyleSheetContents::completeURL(const String& url) const | 444 KURL StyleSheetContents::completeURL(const String& url) const |
| 445 { | 445 { |
| 446 // FIXME: This is only OK when we have a singleOwnerNode, right? | 446 // FIXME: This is only OK when we have a singleOwnerNode, right? |
| 447 return m_parserContext.completeURL(url); | 447 return m_parserContext.completeURL(url); |
| 448 } | 448 } |
| 449 | 449 |
| 450 static bool childRulesHaveFailedOrCanceledSubresources(const WillBeHeapVector<Re
fPtrWillBeMember<StyleRuleBase> >& rules) | 450 static bool childRulesHaveFailedOrCanceledSubresources(const WillBeHeapVector<Re
fPtrWillBeMember<StyleRuleBase>>& rules) |
| 451 { | 451 { |
| 452 for (unsigned i = 0; i < rules.size(); ++i) { | 452 for (unsigned i = 0; i < rules.size(); ++i) { |
| 453 const StyleRuleBase* rule = rules[i].get(); | 453 const StyleRuleBase* rule = rules[i].get(); |
| 454 switch (rule->type()) { | 454 switch (rule->type()) { |
| 455 case StyleRuleBase::Style: | 455 case StyleRuleBase::Style: |
| 456 if (toStyleRule(rule)->properties().hasFailedOrCanceledSubresources(
)) | 456 if (toStyleRule(rule)->properties().hasFailedOrCanceledSubresources(
)) |
| 457 return true; | 457 return true; |
| 458 break; | 458 break; |
| 459 case StyleRuleBase::FontFace: | 459 case StyleRuleBase::FontFace: |
| 460 if (toStyleRuleFontFace(rule)->properties().hasFailedOrCanceledSubre
sources()) | 460 if (toStyleRuleFontFace(rule)->properties().hasFailedOrCanceledSubre
sources()) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 575 |
| 576 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) | 576 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) |
| 577 { | 577 { |
| 578 if (!m_ruleSet) { | 578 if (!m_ruleSet) { |
| 579 m_ruleSet = RuleSet::create(); | 579 m_ruleSet = RuleSet::create(); |
| 580 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); | 580 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); |
| 581 } | 581 } |
| 582 return *m_ruleSet.get(); | 582 return *m_ruleSet.get(); |
| 583 } | 583 } |
| 584 | 584 |
| 585 static void clearResolvers(WillBeHeapHashSet<RawPtrWillBeWeakMember<CSSStyleShee
t> >& clients) | 585 static void clearResolvers(WillBeHeapHashSet<RawPtrWillBeWeakMember<CSSStyleShee
t>>& clients) |
| 586 { | 586 { |
| 587 for (const auto& sheet : clients) { | 587 for (const auto& sheet : clients) { |
| 588 if (Document* document = sheet->ownerDocument()) | 588 if (Document* document = sheet->ownerDocument()) |
| 589 document->styleEngine().clearResolver(); | 589 document->styleEngine().clearResolver(); |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 void StyleSheetContents::clearRuleSet() | 593 void StyleSheetContents::clearRuleSet() |
| 594 { | 594 { |
| 595 if (StyleSheetContents* parentSheet = parentStyleSheet()) | 595 if (StyleSheetContents* parentSheet = parentStyleSheet()) |
| 596 parentSheet->clearRuleSet(); | 596 parentSheet->clearRuleSet(); |
| 597 | 597 |
| 598 // Don't want to clear the StyleResolver if the RuleSet hasn't been created | 598 // Don't want to clear the StyleResolver if the RuleSet hasn't been created |
| 599 // since we only clear the StyleResolver so that it's members are properly | 599 // since we only clear the StyleResolver so that it's members are properly |
| 600 // updated in ScopedStyleResolver::addRulesFromSheet. | 600 // updated in ScopedStyleResolver::addRulesFromSheet. |
| 601 if (!m_ruleSet) | 601 if (!m_ruleSet) |
| 602 return; | 602 return; |
| 603 | 603 |
| 604 // Clearing the ruleSet means we need to recreate the styleResolver data str
uctures. | 604 // Clearing the ruleSet means we need to recreate the styleResolver data str
uctures. |
| 605 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. | 605 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet. |
| 606 clearResolvers(m_loadingClients); | 606 clearResolvers(m_loadingClients); |
| 607 clearResolvers(m_completedClients); | 607 clearResolvers(m_completedClients); |
| 608 m_ruleSet.clear(); | 608 m_ruleSet.clear(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 static void removeFontFaceRules(WillBeHeapHashSet<RawPtrWillBeWeakMember<CSSStyl
eSheet> >& clients, const StyleRuleFontFace* fontFaceRule) | 611 static void removeFontFaceRules(WillBeHeapHashSet<RawPtrWillBeWeakMember<CSSStyl
eSheet>>& clients, const StyleRuleFontFace* fontFaceRule) |
| 612 { | 612 { |
| 613 for (const auto& sheet : clients) { | 613 for (const auto& sheet : clients) { |
| 614 if (Node* ownerNode = sheet->ownerNode()) | 614 if (Node* ownerNode = sheet->ownerNode()) |
| 615 ownerNode->document().styleEngine().removeFontFaceRules(WillBeHeapVe
ctor<RawPtrWillBeMember<const StyleRuleFontFace>>(1, fontFaceRule)); | 615 ownerNode->document().styleEngine().removeFontFaceRules(WillBeHeapVe
ctor<RawPtrWillBeMember<const StyleRuleFontFace>>(1, fontFaceRule)); |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 | 618 |
| 619 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF
aceRule) | 619 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF
aceRule) |
| 620 { | 620 { |
| 621 StyleSheetContents* root = rootStyleSheet(); | 621 StyleSheetContents* root = rootStyleSheet(); |
| 622 removeFontFaceRules(root->m_loadingClients, fontFaceRule); | 622 removeFontFaceRules(root->m_loadingClients, fontFaceRule); |
| 623 removeFontFaceRules(root->m_completedClients, fontFaceRule); | 623 removeFontFaceRules(root->m_completedClients, fontFaceRule); |
| 624 } | 624 } |
| 625 | 625 |
| 626 static void findFontFaceRulesFromRules(const WillBeHeapVector<RefPtrWillBeMember
<StyleRuleBase> >& rules, WillBeHeapVector<RawPtrWillBeMember<const StyleRuleFon
tFace> >& fontFaceRules) | 626 static void findFontFaceRulesFromRules(const WillBeHeapVector<RefPtrWillBeMember
<StyleRuleBase>>& rules, WillBeHeapVector<RawPtrWillBeMember<const StyleRuleFont
Face>>& fontFaceRules) |
| 627 { | 627 { |
| 628 for (unsigned i = 0; i < rules.size(); ++i) { | 628 for (unsigned i = 0; i < rules.size(); ++i) { |
| 629 StyleRuleBase* rule = rules[i].get(); | 629 StyleRuleBase* rule = rules[i].get(); |
| 630 | 630 |
| 631 if (rule->isFontFaceRule()) { | 631 if (rule->isFontFaceRule()) { |
| 632 fontFaceRules.append(toStyleRuleFontFace(rule)); | 632 fontFaceRules.append(toStyleRuleFontFace(rule)); |
| 633 } else if (rule->isMediaRule()) { | 633 } else if (rule->isMediaRule()) { |
| 634 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); | 634 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); |
| 635 // We cannot know whether the media rule matches or not, but | 635 // We cannot know whether the media rule matches or not, but |
| 636 // for safety, remove @font-face in the media rule (if exists). | 636 // for safety, remove @font-face in the media rule (if exists). |
| 637 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); | 637 findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 | 641 |
| 642 void StyleSheetContents::findFontFaceRules(WillBeHeapVector<RawPtrWillBeMember<c
onst StyleRuleFontFace> >& fontFaceRules) | 642 void StyleSheetContents::findFontFaceRules(WillBeHeapVector<RawPtrWillBeMember<c
onst StyleRuleFontFace>>& fontFaceRules) |
| 643 { | 643 { |
| 644 for (unsigned i = 0; i < m_importRules.size(); ++i) { | 644 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
| 645 if (!m_importRules[i]->styleSheet()) | 645 if (!m_importRules[i]->styleSheet()) |
| 646 continue; | 646 continue; |
| 647 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules); | 647 m_importRules[i]->styleSheet()->findFontFaceRules(fontFaceRules); |
| 648 } | 648 } |
| 649 | 649 |
| 650 findFontFaceRulesFromRules(childRules(), fontFaceRules); | 650 findFontFaceRulesFromRules(childRules(), fontFaceRules); |
| 651 } | 651 } |
| 652 | 652 |
| 653 DEFINE_TRACE(StyleSheetContents) | 653 DEFINE_TRACE(StyleSheetContents) |
| 654 { | 654 { |
| 655 #if ENABLE(OILPAN) | 655 #if ENABLE(OILPAN) |
| 656 visitor->trace(m_ownerRule); | 656 visitor->trace(m_ownerRule); |
| 657 visitor->trace(m_importRules); | 657 visitor->trace(m_importRules); |
| 658 visitor->trace(m_childRules); | 658 visitor->trace(m_childRules); |
| 659 visitor->trace(m_loadingClients); | 659 visitor->trace(m_loadingClients); |
| 660 visitor->trace(m_completedClients); | 660 visitor->trace(m_completedClients); |
| 661 visitor->trace(m_ruleSet); | 661 visitor->trace(m_ruleSet); |
| 662 #endif | 662 #endif |
| 663 } | 663 } |
| 664 | 664 |
| 665 } | 665 } |
| OLD | NEW |