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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 , m_defaultNamespace(o.m_defaultNamespace) | 80 , m_defaultNamespace(o.m_defaultNamespace) |
81 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) | 81 , m_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader) |
82 , m_didLoadErrorOccur(false) | 82 , m_didLoadErrorOccur(false) |
83 , m_isMutable(false) | 83 , m_isMutable(false) |
84 , m_isReferencedFromResource(false) | 84 , m_isReferencedFromResource(false) |
85 , m_hasFontFaceRule(o.m_hasFontFaceRule) | 85 , m_hasFontFaceRule(o.m_hasFontFaceRule) |
86 , m_hasMediaQueries(o.m_hasMediaQueries) | 86 , m_hasMediaQueries(o.m_hasMediaQueries) |
87 , m_hasSingleOwnerDocument(true) | 87 , m_hasSingleOwnerDocument(true) |
88 , m_parserContext(o.m_parserContext) | 88 , m_parserContext(o.m_parserContext) |
89 { | 89 { |
90 ASSERT(o.isCacheable()); | |
91 | |
92 // FIXME: Copy import rules. | 90 // FIXME: Copy import rules. |
93 ASSERT(o.m_importRules.isEmpty()); | 91 ASSERT(o.m_importRules.isEmpty()); |
94 | 92 |
95 for (unsigned i = 0; i < m_childRules.size(); ++i) | 93 for (unsigned i = 0; i < m_childRules.size(); ++i) |
96 m_childRules[i] = o.m_childRules[i]->copy(); | 94 m_childRules[i] = o.m_childRules[i]->copy(); |
97 } | 95 } |
98 | 96 |
99 StyleSheetContents::~StyleSheetContents() | 97 StyleSheetContents::~StyleSheetContents() |
100 { | 98 { |
101 } | 99 } |
102 | 100 |
103 void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss) | 101 void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss) |
104 { | 102 { |
105 if (!isValidCss) { | 103 if (!isValidCss) { |
106 if (Document* document = clientSingleOwnerDocument()) | 104 if (Document* document = clientSingleOwnerDocument()) |
107 removeSheetFromCache(document); | 105 removeSheetFromCache(document); |
108 } | 106 } |
109 m_hasSyntacticallyValidCSSHeader = isValidCss; | 107 m_hasSyntacticallyValidCSSHeader = isValidCss; |
110 } | 108 } |
111 | 109 |
112 bool StyleSheetContents::isCacheable() const | 110 bool StyleSheetContents::isCacheableForResource() const |
113 { | 111 { |
114 // This would require dealing with multiple clients for load callbacks. | 112 // This would require dealing with multiple clients for load callbacks. |
115 if (!loadCompleted()) | 113 if (!loadCompleted()) |
116 return false; | 114 return false; |
117 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et | 115 // FIXME: StyleSheets with media queries can't be cached because their RuleS
et |
118 // is processed differently based off the media queries, which might resolve | 116 // is processed differently based off the media queries, which might resolve |
119 // differently depending on the context of the parent CSSStyleSheet (e.g. | 117 // differently depending on the context of the parent CSSStyleSheet (e.g. |
120 // if they are in differently sized iframes). Once RuleSets are media query | 118 // if they are in differently sized iframes). Once RuleSets are media query |
121 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. | 119 // agnostic, we can restore sharing of StyleSheetContents with medea queries
. |
122 if (m_hasMediaQueries) | 120 if (m_hasMediaQueries) |
123 return false; | 121 return false; |
124 // FIXME: Support copying import rules. | 122 // FIXME: Support copying import rules. |
125 if (!m_importRules.isEmpty()) | 123 if (!m_importRules.isEmpty()) |
126 return false; | 124 return false; |
127 // FIXME: Support cached stylesheets in import rules. | 125 // FIXME: Support cached stylesheets in import rules. |
128 if (m_ownerRule) | 126 if (m_ownerRule) |
129 return false; | 127 return false; |
130 if (m_didLoadErrorOccur) | 128 if (m_didLoadErrorOccur) |
131 return false; | 129 return false; |
132 // It is not the original sheet anymore. | 130 // It is not the original sheet anymore. |
133 if (m_isMutable) | 131 if (m_isMutable) |
134 return false; | 132 return false; |
135 // If the header is valid we are not going to need to check the SecurityOrig
in. | 133 // If the header is valid we are not going to need to check the SecurityOrig
in. |
136 // FIXME: Valid mime type avoids the check too. | 134 // FIXME: Valid mime type avoids the check too. |
137 if (!m_hasSyntacticallyValidCSSHeader) | 135 if (!m_hasSyntacticallyValidCSSHeader) |
138 return false; | 136 return false; |
139 return true; | 137 return true; |
140 } | 138 } |
141 | 139 |
| 140 bool StyleSheetContents::isCacheableForStyleElement() const |
| 141 { |
| 142 // FIXME: Support copying import rules. |
| 143 if (!importRules().isEmpty()) |
| 144 return false; |
| 145 // Until import rules are supported in cached sheets it's not possible for l
oading to fail. |
| 146 DCHECK(!didLoadErrorOccur()); |
| 147 // It is not the original sheet anymore. |
| 148 if (isMutable()) |
| 149 return false; |
| 150 if (!hasSyntacticallyValidCSSHeader()) |
| 151 return false; |
| 152 return true; |
| 153 } |
| 154 |
| 155 |
142 void StyleSheetContents::parserAppendRule(StyleRuleBase* rule) | 156 void StyleSheetContents::parserAppendRule(StyleRuleBase* rule) |
143 { | 157 { |
144 if (rule->isImportRule()) { | 158 if (rule->isImportRule()) { |
145 // Parser enforces that @import rules come before anything else | 159 // Parser enforces that @import rules come before anything else |
146 ASSERT(m_childRules.isEmpty()); | 160 ASSERT(m_childRules.isEmpty()); |
147 StyleRuleImport* importRule = toStyleRuleImport(rule); | 161 StyleRuleImport* importRule = toStyleRuleImport(rule); |
148 if (importRule->mediaQueries()) | 162 if (importRule->mediaQueries()) |
149 setHasMediaQueries(); | 163 setHasMediaQueries(); |
150 m_importRules.append(importRule); | 164 m_importRules.append(importRule); |
151 m_importRules.last()->setParentStyleSheet(this); | 165 m_importRules.last()->setParentStyleSheet(this); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 case StyleRuleBase::Supports: | 507 case StyleRuleBase::Supports: |
494 case StyleRuleBase::Viewport: | 508 case StyleRuleBase::Viewport: |
495 break; | 509 break; |
496 } | 510 } |
497 } | 511 } |
498 return false; | 512 return false; |
499 } | 513 } |
500 | 514 |
501 bool StyleSheetContents::hasFailedOrCanceledSubresources() const | 515 bool StyleSheetContents::hasFailedOrCanceledSubresources() const |
502 { | 516 { |
503 ASSERT(isCacheable()); | 517 ASSERT(isCacheableForResource()); |
504 return childRulesHaveFailedOrCanceledSubresources(m_childRules); | 518 return childRulesHaveFailedOrCanceledSubresources(m_childRules); |
505 } | 519 } |
506 | 520 |
507 Document* StyleSheetContents::clientSingleOwnerDocument() const | 521 Document* StyleSheetContents::clientSingleOwnerDocument() const |
508 { | 522 { |
509 if (!m_hasSingleOwnerDocument || clientSize() <= 0) | 523 if (!m_hasSingleOwnerDocument || clientSize() <= 0) |
510 return nullptr; | 524 return nullptr; |
511 | 525 |
512 if (m_loadingClients.size()) | 526 if (m_loadingClients.size()) |
513 return (*m_loadingClients.begin())->ownerDocument(); | 527 return (*m_loadingClients.begin())->ownerDocument(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 582 |
569 void StyleSheetContents::removeSheetFromCache(Document* document) | 583 void StyleSheetContents::removeSheetFromCache(Document* document) |
570 { | 584 { |
571 ASSERT(document); | 585 ASSERT(document); |
572 document->styleEngine().removeSheet(this); | 586 document->styleEngine().removeSheet(this); |
573 } | 587 } |
574 | 588 |
575 void StyleSheetContents::setReferencedFromResource(bool referenced) | 589 void StyleSheetContents::setReferencedFromResource(bool referenced) |
576 { | 590 { |
577 ASSERT(referenced != m_isReferencedFromResource); | 591 ASSERT(referenced != m_isReferencedFromResource); |
578 ASSERT(isCacheable()); | 592 ASSERT(isCacheableForResource()); |
579 m_isReferencedFromResource = referenced; | 593 m_isReferencedFromResource = referenced; |
580 } | 594 } |
581 | 595 |
582 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) | 596 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad
dRuleFlags addRuleFlags) |
583 { | 597 { |
584 if (!m_ruleSet) { | 598 if (!m_ruleSet) { |
585 m_ruleSet = RuleSet::create(); | 599 m_ruleSet = RuleSet::create(); |
586 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); | 600 m_ruleSet->addRulesFromSheet(this, medium, addRuleFlags); |
587 } | 601 } |
588 return *m_ruleSet.get(); | 602 return *m_ruleSet.get(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 visitor->trace(m_ownerRule); | 675 visitor->trace(m_ownerRule); |
662 visitor->trace(m_importRules); | 676 visitor->trace(m_importRules); |
663 visitor->trace(m_namespaceRules); | 677 visitor->trace(m_namespaceRules); |
664 visitor->trace(m_childRules); | 678 visitor->trace(m_childRules); |
665 visitor->trace(m_loadingClients); | 679 visitor->trace(m_loadingClients); |
666 visitor->trace(m_completedClients); | 680 visitor->trace(m_completedClients); |
667 visitor->trace(m_ruleSet); | 681 visitor->trace(m_ruleSet); |
668 } | 682 } |
669 | 683 |
670 } // namespace blink | 684 } // namespace blink |
OLD | NEW |