| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
ights reserved. |
| 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "sky/engine/core/frame/Settings.h" | 40 #include "sky/engine/core/frame/Settings.h" |
| 41 #include "sky/engine/core/html/HTMLStyleElement.h" | 41 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 42 #include "sky/engine/core/html/imports/HTMLImportsController.h" | 42 #include "sky/engine/core/html/imports/HTMLImportsController.h" |
| 43 #include "sky/engine/core/page/Page.h" | 43 #include "sky/engine/core/page/Page.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 StyleEngine::StyleEngine(Document& document) | 47 StyleEngine::StyleEngine(Document& document) |
| 48 : m_document(&document) | 48 : m_document(&document) |
| 49 , m_ignorePendingStylesheets(false) | 49 , m_ignorePendingStylesheets(false) |
| 50 // We don't need to create CSSFontSelector for imported document or | 50 , m_fontSelector(CSSFontSelector::create(&document)) |
| 51 // HTMLTemplateElement's document, because those documents have no frame. | |
| 52 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : nul
lptr) | |
| 53 { | 51 { |
| 54 if (m_fontSelector) | 52 m_fontSelector->registerForInvalidationCallbacks(this); |
| 55 m_fontSelector->registerForInvalidationCallbacks(this); | |
| 56 } | 53 } |
| 57 | 54 |
| 58 StyleEngine::~StyleEngine() | 55 StyleEngine::~StyleEngine() |
| 59 { | 56 { |
| 60 } | 57 m_fontSelector->clearDocument(); |
| 61 | 58 m_fontSelector->unregisterForInvalidationCallbacks(this); |
| 62 void StyleEngine::detachFromDocument() | |
| 63 { | |
| 64 // Cleanup is performed eagerly when the StyleEngine is removed from the | |
| 65 // document. The StyleEngine is unreachable after this, since only the | |
| 66 // document has a reference to it. | |
| 67 | |
| 68 if (m_fontSelector) { | |
| 69 m_fontSelector->clearDocument(); | |
| 70 m_fontSelector->unregisterForInvalidationCallbacks(this); | |
| 71 } | |
| 72 | |
| 73 // Decrement reference counts for things we could be keeping alive. | |
| 74 m_fontSelector.clear(); | |
| 75 m_resolver.clear(); | |
| 76 } | 59 } |
| 77 | 60 |
| 78 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) | 61 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) |
| 79 { | 62 { |
| 80 if (!node->inDocument()) | 63 if (!node->inDocument()) |
| 81 return; | 64 return; |
| 82 | 65 |
| 83 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; | 66 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do
cument; |
| 84 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); | 67 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); |
| 85 StyleSheetCollection& collection = treeScope.styleSheets(); | 68 StyleSheetCollection& collection = treeScope.styleSheets(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 { | 134 { |
| 152 ASSERT(!m_document->inStyleRecalc()); | 135 ASSERT(!m_document->inStyleRecalc()); |
| 153 m_resolver.clear(); | 136 m_resolver.clear(); |
| 154 } | 137 } |
| 155 | 138 |
| 156 unsigned StyleEngine::resolverAccessCount() const | 139 unsigned StyleEngine::resolverAccessCount() const |
| 157 { | 140 { |
| 158 return m_resolver ? m_resolver->accessCount() : 0; | 141 return m_resolver ? m_resolver->accessCount() : 0; |
| 159 } | 142 } |
| 160 | 143 |
| 161 void StyleEngine::didDetach() | |
| 162 { | |
| 163 clearResolver(); | |
| 164 } | |
| 165 | |
| 166 void StyleEngine::resolverChanged() | 144 void StyleEngine::resolverChanged() |
| 167 { | 145 { |
| 168 // Don't bother updating, since we haven't loaded all our style info yet | 146 // Don't bother updating, since we haven't loaded all our style info yet |
| 169 // and haven't calculated the style selector for the first time. | 147 // and haven't calculated the style selector for the first time. |
| 170 if (!m_document->isActive()) { | 148 if (!m_document->isActive()) { |
| 171 clearResolver(); | 149 clearResolver(); |
| 172 return; | 150 return; |
| 173 } | 151 } |
| 174 | 152 |
| 175 updateActiveStyleSheets(); | 153 updateActiveStyleSheets(); |
| 176 } | 154 } |
| 177 | 155 |
| 178 void StyleEngine::clearFontCache() | 156 void StyleEngine::clearFontCache() |
| 179 { | 157 { |
| 180 if (m_fontSelector) | 158 m_fontSelector->fontFaceCache()->clearCSSConnected(); |
| 181 m_fontSelector->fontFaceCache()->clearCSSConnected(); | |
| 182 if (m_resolver) | 159 if (m_resolver) |
| 183 m_resolver->invalidateMatchedPropertiesCache(); | 160 m_resolver->invalidateMatchedPropertiesCache(); |
| 184 } | 161 } |
| 185 | 162 |
| 186 void StyleEngine::updateGenericFontFamilySettings() | 163 void StyleEngine::updateGenericFontFamilySettings() |
| 187 { | 164 { |
| 188 // FIXME: we should not update generic font family settings when | 165 // FIXME: we should not update generic font family settings when |
| 189 // document is inactive. | 166 // document is inactive. |
| 190 ASSERT(m_document->isActive()); | 167 ASSERT(m_document->isActive()); |
| 191 | 168 |
| 192 if (!m_fontSelector) | |
| 193 return; | |
| 194 | |
| 195 m_fontSelector->updateGenericFontFamilySettings(*m_document); | 169 m_fontSelector->updateGenericFontFamilySettings(*m_document); |
| 196 if (m_resolver) | 170 if (m_resolver) |
| 197 m_resolver->invalidateMatchedPropertiesCache(); | 171 m_resolver->invalidateMatchedPropertiesCache(); |
| 198 } | 172 } |
| 199 | 173 |
| 200 void StyleEngine::removeFontFaceRules(const Vector<RawPtr<const StyleRuleFontFac
e> >& fontFaceRules) | 174 void StyleEngine::removeFontFaceRules(const Vector<RawPtr<const StyleRuleFontFac
e> >& fontFaceRules) |
| 201 { | 175 { |
| 202 if (!m_fontSelector) | |
| 203 return; | |
| 204 | |
| 205 FontFaceCache* cache = m_fontSelector->fontFaceCache(); | 176 FontFaceCache* cache = m_fontSelector->fontFaceCache(); |
| 206 for (unsigned i = 0; i < fontFaceRules.size(); ++i) | 177 for (unsigned i = 0; i < fontFaceRules.size(); ++i) |
| 207 cache->remove(fontFaceRules[i]); | 178 cache->remove(fontFaceRules[i]); |
| 208 if (m_resolver) | 179 if (m_resolver) |
| 209 m_resolver->invalidateMatchedPropertiesCache(); | 180 m_resolver->invalidateMatchedPropertiesCache(); |
| 210 } | 181 } |
| 211 | 182 |
| 212 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex
t) | 183 PassRefPtr<CSSStyleSheet> StyleEngine::createSheet(Element* e, const String& tex
t) |
| 213 { | 184 { |
| 214 RefPtr<CSSStyleSheet> styleSheet; | 185 RefPtr<CSSStyleSheet> styleSheet; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 231 } |
| 261 | 232 |
| 262 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) | 233 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) |
| 263 { | 234 { |
| 264 if (m_resolver) | 235 if (m_resolver) |
| 265 m_resolver->invalidateMatchedPropertiesCache(); | 236 m_resolver->invalidateMatchedPropertiesCache(); |
| 266 m_document->setNeedsStyleRecalc(SubtreeStyleChange); | 237 m_document->setNeedsStyleRecalc(SubtreeStyleChange); |
| 267 } | 238 } |
| 268 | 239 |
| 269 } | 240 } |
| OLD | NEW |