| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Only these nodes can be parents of StyleSheets, and they need to call cle
arOwnerNode() when moved out of document. | 64 // Only these nodes can be parents of StyleSheets, and they need to call cle
arOwnerNode() when moved out of document. |
| 65 return !parentNode | 65 return !parentNode |
| 66 || parentNode->isDocumentNode() | 66 || parentNode->isDocumentNode() |
| 67 || parentNode->hasTagName(HTMLNames::linkTag) | 67 || parentNode->hasTagName(HTMLNames::linkTag) |
| 68 || parentNode->hasTagName(HTMLNames::styleTag) | 68 || parentNode->hasTagName(HTMLNames::styleTag) |
| 69 || parentNode->hasTagName(SVGNames::styleTag) | 69 || parentNode->hasTagName(SVGNames::styleTag) |
| 70 || parentNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE; | 70 || parentNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE; |
| 71 } | 71 } |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawPtr<StyleShee
tContents> sheet, CSSImportRule* ownerRule) | 74 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawP
tr<StyleSheetContents> sheet, CSSImportRule* ownerRule) |
| 75 { | 75 { |
| 76 return adoptRef(new CSSStyleSheet(sheet, ownerRule)); | 76 return adoptRefWillBeRefCountedGarbageCollected(new CSSStyleSheet(sheet, own
erRule)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 PassRefPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawPtr<StyleShee
tContents> sheet, Node* ownerNode) | 79 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawP
tr<StyleSheetContents> sheet, Node* ownerNode) |
| 80 { | 80 { |
| 81 return adoptRef(new CSSStyleSheet(sheet, ownerNode, false, TextPosition::min
imumPosition())); | 81 return adoptRefWillBeRefCountedGarbageCollected(new CSSStyleSheet(sheet, own
erNode, false, TextPosition::minimumPosition())); |
| 82 } | 82 } |
| 83 | 83 |
| 84 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(PassRefPtrWillBeRawPtr<Sty
leSheetContents> sheet, Node* ownerNode, const TextPosition& startPosition) | 84 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::createInline(PassRefPtrWill
BeRawPtr<StyleSheetContents> sheet, Node* ownerNode, const TextPosition& startPo
sition) |
| 85 { | 85 { |
| 86 ASSERT(sheet); | 86 ASSERT(sheet); |
| 87 return adoptRef(new CSSStyleSheet(sheet, ownerNode, true, startPosition)); | 87 return adoptRefWillBeRefCountedGarbageCollected(new CSSStyleSheet(sheet, own
erNode, true, startPosition)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 PassRefPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNode, const KUR
L& baseURL, const TextPosition& startPosition, const String& encoding) | 90 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNod
e, const KURL& baseURL, const TextPosition& startPosition, const String& encodin
g) |
| 91 { | 91 { |
| 92 CSSParserContext parserContext(ownerNode->document(), 0, baseURL, encoding); | 92 CSSParserContext parserContext(ownerNode->document(), 0, baseURL, encoding); |
| 93 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(ba
seURL.string(), parserContext); | 93 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(ba
seURL.string(), parserContext); |
| 94 return adoptRef(new CSSStyleSheet(sheet.release(), ownerNode, true, startPos
ition)); | 94 return adoptRefWillBeRefCountedGarbageCollected(new CSSStyleSheet(sheet.rele
ase(), ownerNode, true, startPosition)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, CSSImportRule* ownerRule) | 97 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, CSSImportRule* ownerRule) |
| 98 : m_contents(contents) | 98 : m_contents(contents) |
| 99 , m_isInlineStylesheet(false) | 99 , m_isInlineStylesheet(false) |
| 100 , m_isDisabled(false) | 100 , m_isDisabled(false) |
| 101 , m_ownerNode(0) | 101 , m_ownerNode(0) |
| 102 , m_ownerRule(ownerRule) | 102 , m_ownerRule(ownerRule) |
| 103 , m_startPosition(TextPosition::minimumPosition()) | 103 , m_startPosition(TextPosition::minimumPosition()) |
| 104 , m_loadCompleted(false) | 104 , m_loadCompleted(false) |
| 105 { | 105 { |
| 106 m_contents->registerClient(this); | 106 m_contents->registerClient(this); |
| 107 } | 107 } |
| 108 | 108 |
| 109 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, Node* ownerNode, bool isInlineStylesheet, const TextPosition& startPosition) | 109 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, Node* ownerNode, bool isInlineStylesheet, const TextPosition& startPosition) |
| 110 : m_contents(contents) | 110 : m_contents(contents) |
| 111 , m_isInlineStylesheet(isInlineStylesheet) | 111 , m_isInlineStylesheet(isInlineStylesheet) |
| 112 , m_isDisabled(false) | 112 , m_isDisabled(false) |
| 113 , m_ownerNode(ownerNode) | 113 , m_ownerNode(ownerNode) |
| 114 , m_ownerRule(0) | 114 , m_ownerRule(nullptr) |
| 115 , m_startPosition(startPosition) | 115 , m_startPosition(startPosition) |
| 116 , m_loadCompleted(false) | 116 , m_loadCompleted(false) |
| 117 { | 117 { |
| 118 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); | 118 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); |
| 119 m_contents->registerClient(this); | 119 m_contents->registerClient(this); |
| 120 } | 120 } |
| 121 | 121 |
| 122 CSSStyleSheet::~CSSStyleSheet() | 122 CSSStyleSheet::~CSSStyleSheet() |
| 123 { | 123 { |
| 124 // With oilpan the parent style sheet pointer is strong and the sheet and |
| 125 // its RuleCSSOMWrappers die together and we don't need to clear them here. |
| 126 // Also with oilpan the StyleSheetContents client pointers are weak and |
| 127 // therefore do not need to be cleared here. |
| 128 #if !ENABLE(OILPAN) |
| 124 // For style rules outside the document, .parentStyleSheet can become null e
ven if the style rule | 129 // For style rules outside the document, .parentStyleSheet can become null e
ven if the style rule |
| 125 // is still observable from JavaScript. This matches the behavior of .parent
Node for nodes, but | 130 // is still observable from JavaScript. This matches the behavior of .parent
Node for nodes, but |
| 126 // it's not ideal because it makes the CSSOM's behavior depend on the timing
of garbage collection. | 131 // it's not ideal because it makes the CSSOM's behavior depend on the timing
of garbage collection. |
| 127 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | 132 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { |
| 128 if (m_childRuleCSSOMWrappers[i]) | 133 if (m_childRuleCSSOMWrappers[i]) |
| 129 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); | 134 m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0); |
| 130 } | 135 } |
| 131 | 136 |
| 132 if (m_mediaCSSOMWrapper) | 137 if (m_mediaCSSOMWrapper) |
| 133 m_mediaCSSOMWrapper->clearParentStyleSheet(); | 138 m_mediaCSSOMWrapper->clearParentStyleSheet(); |
| 134 | 139 |
| 135 m_contents->unregisterClient(this); | 140 m_contents->unregisterClient(this); |
| 141 #endif |
| 136 } | 142 } |
| 137 | 143 |
| 138 void CSSStyleSheet::willMutateRules() | 144 void CSSStyleSheet::willMutateRules() |
| 139 { | 145 { |
| 140 InspectorInstrumentation::willMutateRules(this); | 146 InspectorInstrumentation::willMutateRules(this); |
| 141 // If we are the only client it is safe to mutate. | 147 // If we are the only client it is safe to mutate. |
| 142 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { | 148 if (m_contents->hasOneClient() && !m_contents->isInMemoryCache()) { |
| 143 m_contents->clearRuleSet(); | 149 m_contents->clearRuleSet(); |
| 144 if (m_contents->maybeCacheable()) | 150 if (m_contents->maybeCacheable()) |
| 145 StyleEngine::removeSheet(m_contents.get()); | 151 StyleEngine::removeSheet(m_contents.get()); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 m_loadCompleted = m_ownerNode->sheetLoaded(); | 405 m_loadCompleted = m_ownerNode->sheetLoaded(); |
| 400 return m_loadCompleted; | 406 return m_loadCompleted; |
| 401 } | 407 } |
| 402 | 408 |
| 403 void CSSStyleSheet::startLoadingDynamicSheet() | 409 void CSSStyleSheet::startLoadingDynamicSheet() |
| 404 { | 410 { |
| 405 m_loadCompleted = false; | 411 m_loadCompleted = false; |
| 406 m_ownerNode->startLoadingDynamicSheet(); | 412 m_ownerNode->startLoadingDynamicSheet(); |
| 407 } | 413 } |
| 408 | 414 |
| 415 void CSSStyleSheet::trace(Visitor* visitor) |
| 416 { |
| 417 visitor->trace(m_contents); |
| 418 visitor->trace(m_mediaQueries); |
| 419 visitor->trace(m_ownerRule); |
| 420 visitor->trace(m_mediaCSSOMWrapper); |
| 421 visitor->trace(m_childRuleCSSOMWrappers); |
| 409 } | 422 } |
| 423 |
| 424 } |
| OLD | NEW |