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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtr<StyleSheetContents> s
heet, CSSImportRule* ownerRule) | 73 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtr<StyleSheetContents> s
heet, CSSImportRule* ownerRule) |
74 { | 74 { |
75 return adoptRef(new CSSStyleSheet(sheet, ownerRule)); | 75 return adoptRef(new CSSStyleSheet(sheet, ownerRule)); |
76 } | 76 } |
77 | 77 |
78 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtr<StyleSheetContents> s
heet, Node* ownerNode) | 78 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtr<StyleSheetContents> s
heet, Node* ownerNode) |
79 { | 79 { |
80 return adoptRef(new CSSStyleSheet(sheet, ownerNode, false, TextPosition::min
imumPosition())); | 80 return adoptRef(new CSSStyleSheet(sheet, ownerNode, false, TextPosition::min
imumPosition())); |
81 } | 81 } |
82 | 82 |
| 83 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(PassRefPtr<StyleSheetConte
nts> sheet, Node* ownerNode, const TextPosition& startPosition) |
| 84 { |
| 85 ASSERT(sheet); |
| 86 return adoptRef(new CSSStyleSheet(sheet, ownerNode, true, startPosition)); |
| 87 } |
| 88 |
83 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNode, const KUR
L& baseURL, const TextPosition& startPosition, const String& encoding) | 89 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNode, const KUR
L& baseURL, const TextPosition& startPosition, const String& encoding) |
84 { | 90 { |
85 CSSParserContext parserContext(ownerNode->document(), baseURL, encoding); | 91 CSSParserContext parserContext(ownerNode->document(), baseURL, encoding); |
86 RefPtr<StyleSheetContents> sheet = StyleSheetContents::create(baseURL.string
(), parserContext); | 92 RefPtr<StyleSheetContents> sheet = StyleSheetContents::create(baseURL.string
(), parserContext); |
87 return adoptRef(new CSSStyleSheet(sheet.release(), ownerNode, true, startPos
ition)); | 93 return adoptRef(new CSSStyleSheet(sheet.release(), ownerNode, true, startPos
ition)); |
88 } | 94 } |
89 | 95 |
90 CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, CSSImportR
ule* ownerRule) | 96 CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, CSSImportR
ule* ownerRule) |
91 : m_contents(contents) | 97 : m_contents(contents) |
92 , m_isInlineStylesheet(false) | 98 , m_isInlineStylesheet(false) |
93 , m_isDisabled(false) | 99 , m_isDisabled(false) |
94 , m_ownerNode(0) | 100 , m_ownerNode(0) |
95 , m_ownerRule(ownerRule) | 101 , m_ownerRule(ownerRule) |
96 , m_startPosition(TextPosition::minimumPosition()) | 102 , m_startPosition(TextPosition::minimumPosition()) |
| 103 , m_loadCompleted(false) |
97 { | 104 { |
98 m_contents->registerClient(this); | 105 m_contents->registerClient(this); |
99 } | 106 } |
100 | 107 |
101 CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, Node* owne
rNode, bool isInlineStylesheet, const TextPosition& startPosition) | 108 CSSStyleSheet::CSSStyleSheet(PassRefPtr<StyleSheetContents> contents, Node* owne
rNode, bool isInlineStylesheet, const TextPosition& startPosition) |
102 : m_contents(contents) | 109 : m_contents(contents) |
103 , m_isInlineStylesheet(isInlineStylesheet) | 110 , m_isInlineStylesheet(isInlineStylesheet) |
104 , m_isDisabled(false) | 111 , m_isDisabled(false) |
105 , m_ownerNode(ownerNode) | 112 , m_ownerNode(ownerNode) |
106 , m_ownerRule(0) | 113 , m_ownerRule(0) |
107 , m_startPosition(startPosition) | 114 , m_startPosition(startPosition) |
| 115 , m_loadCompleted(false) |
108 { | 116 { |
109 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); | 117 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); |
110 m_contents->registerClient(this); | 118 m_contents->registerClient(this); |
111 } | 119 } |
112 | 120 |
113 CSSStyleSheet::~CSSStyleSheet() | 121 CSSStyleSheet::~CSSStyleSheet() |
114 { | 122 { |
115 // For style rules outside the document, .parentStyleSheet can become null e
ven if the style rule | 123 // For style rules outside the document, .parentStyleSheet can become null e
ven if the style rule |
116 // is still observable from JavaScript. This matches the behavior of .parent
Node for nodes, but | 124 // is still observable from JavaScript. This matches the behavior of .parent
Node for nodes, but |
117 // it's not ideal because it makes the CSSOM's behavior depend on the timing
of garbage collection. | 125 // it's not ideal because it makes the CSSOM's behavior depend on the timing
of garbage collection. |
118 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | 126 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { |
119 if (m_childRuleCSSOMWrappers[i]) | 127 if (m_childRuleCSSOMWrappers[i]) |
120 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); | 128 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); |
121 } | 129 } |
122 | 130 |
123 if (m_mediaCSSOMWrapper) | 131 if (m_mediaCSSOMWrapper) |
124 m_mediaCSSOMWrapper->clearParentStyleSheet(); | 132 m_mediaCSSOMWrapper->clearParentStyleSheet(); |
125 | 133 |
126 m_contents->unregisterClient(this); | 134 m_contents->unregisterClient(this); |
127 } | 135 } |
128 | 136 |
129 void CSSStyleSheet::willMutateRules() | 137 void CSSStyleSheet::willMutateRules() |
130 { | 138 { |
131 InspectorInstrumentation::willMutateRules(this); | 139 InspectorInstrumentation::willMutateRules(this); |
132 // If we are the only client it is safe to mutate. | 140 // If we are the only client it is safe to mutate. |
133 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { | 141 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { |
134 m_contents->clearRuleSet(); | 142 m_contents->clearRuleSet(); |
| 143 if (m_contents->maybeCacheable()) |
| 144 StyleEngine::removeSheet(m_contents.get()); |
135 m_contents->setMutable(); | 145 m_contents->setMutable(); |
136 return; | 146 return; |
137 } | 147 } |
138 // Only cacheable stylesheets should have multiple clients. | 148 // Only cacheable stylesheets should have multiple clients. |
139 ASSERT(m_contents->isCacheable()); | 149 ASSERT(m_contents->isCacheable()); |
140 | 150 |
141 // Copy-on-write. | 151 // Copy-on-write. |
142 m_contents->unregisterClient(this); | 152 m_contents->unregisterClient(this); |
143 m_contents = m_contents->copy(); | 153 m_contents = m_contents->copy(); |
144 m_contents->registerClient(this); | 154 m_contents->registerClient(this); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 while (root->parentStyleSheet()) | 384 while (root->parentStyleSheet()) |
375 root = root->parentStyleSheet(); | 385 root = root->parentStyleSheet(); |
376 return root->ownerNode() ? &root->ownerNode()->document() : 0; | 386 return root->ownerNode() ? &root->ownerNode()->document() : 0; |
377 } | 387 } |
378 | 388 |
379 void CSSStyleSheet::clearChildRuleCSSOMWrappers() | 389 void CSSStyleSheet::clearChildRuleCSSOMWrappers() |
380 { | 390 { |
381 m_childRuleCSSOMWrappers.clear(); | 391 m_childRuleCSSOMWrappers.clear(); |
382 } | 392 } |
383 | 393 |
| 394 bool CSSStyleSheet::sheetLoaded() |
| 395 { |
| 396 m_loadCompleted = m_ownerNode->sheetLoaded(); |
| 397 return m_loadCompleted; |
384 } | 398 } |
| 399 |
| 400 void CSSStyleSheet::startLoadingDynamicSheet() |
| 401 { |
| 402 m_loadCompleted = false; |
| 403 m_ownerNode->startLoadingDynamicSheet(); |
| 404 } |
| 405 |
| 406 } |
OLD | NEW |