| 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, 2010, 2012 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 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) 2010 Nokia Corporation and/or its subsidiary(-ies) | 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 9 * Copyright (C) 2013 Google Inc. All rights reserved. | 9 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 10 * | 10 * |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "sky/engine/core/dom/Document.h" | 32 #include "sky/engine/core/dom/Document.h" |
| 33 #include "sky/engine/core/dom/StyleEngine.h" | 33 #include "sky/engine/core/dom/StyleEngine.h" |
| 34 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 34 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 35 #include "sky/engine/core/dom/TreeScope.h" | 35 #include "sky/engine/core/dom/TreeScope.h" |
| 36 #include "sky/engine/core/html/HTMLStyleElement.h" | 36 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 StyleSheetCollection::StyleSheetCollection(TreeScope& treeScope) | 40 StyleSheetCollection::StyleSheetCollection(TreeScope& treeScope) |
| 41 : m_treeScope(treeScope) | 41 : m_treeScope(treeScope) |
| 42 , m_needsUpdate(true) |
| 42 { | 43 { |
| 43 } | 44 } |
| 44 | 45 |
| 45 StyleSheetCollection::~StyleSheetCollection() | 46 StyleSheetCollection::~StyleSheetCollection() |
| 46 { | 47 { |
| 47 } | 48 } |
| 48 | 49 |
| 49 void StyleSheetCollection::addStyleSheetCandidateNode(HTMLStyleElement& element) | 50 void StyleSheetCollection::addStyleSheetCandidateNode(HTMLStyleElement& element) |
| 50 { | 51 { |
| 51 ASSERT(element.inActiveDocument()); | 52 ASSERT(element.inActiveDocument()); |
| 52 m_styleSheetCandidateNodes.add(&element); | 53 m_styleSheetCandidateNodes.add(&element); |
| 54 m_needsUpdate = true; |
| 53 } | 55 } |
| 54 | 56 |
| 55 void StyleSheetCollection::removeStyleSheetCandidateNode(HTMLStyleElement& eleme
nt) | 57 void StyleSheetCollection::removeStyleSheetCandidateNode(HTMLStyleElement& eleme
nt) |
| 56 { | 58 { |
| 57 m_styleSheetCandidateNodes.remove(&element); | 59 m_styleSheetCandidateNodes.remove(&element); |
| 60 m_needsUpdate = true; |
| 58 } | 61 } |
| 59 | 62 |
| 60 void StyleSheetCollection::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& she
ets) | 63 void StyleSheetCollection::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& she
ets) |
| 61 { | 64 { |
| 62 for (Node* node : m_styleSheetCandidateNodes) { | 65 for (Node* node : m_styleSheetCandidateNodes) { |
| 63 ASSERT(isHTMLStyleElement(*node)); | 66 ASSERT(isHTMLStyleElement(*node)); |
| 64 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet()) | 67 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet()) |
| 65 sheets.append(sheet); | 68 sheets.append(sheet); |
| 66 } | 69 } |
| 67 } | 70 } |
| 68 | 71 |
| 69 void StyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine) | 72 void StyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine) |
| 70 { | 73 { |
| 74 // TODO(esprehn): We need to check if the resolver exists otherwise style |
| 75 // doesn't get computed right. We should figure out why. |
| 76 if (!m_needsUpdate && engine->resolver()) |
| 77 return; |
| 78 |
| 71 Vector<RefPtr<CSSStyleSheet>> candidateSheets; | 79 Vector<RefPtr<CSSStyleSheet>> candidateSheets; |
| 72 collectStyleSheets(candidateSheets); | 80 collectStyleSheets(candidateSheets); |
| 73 | 81 |
| 74 Node& root = m_treeScope.rootNode(); | 82 Node& root = m_treeScope.rootNode(); |
| 75 | 83 |
| 76 // TODO(esprehn): Remove special casing for Document. | 84 // TODO(esprehn): Remove special casing for Document. |
| 77 if (root.isDocumentNode()) { | 85 if (root.isDocumentNode()) { |
| 78 engine->clearResolver(); | 86 engine->clearResolver(); |
| 79 // FIMXE: The following depends on whether StyleRuleFontFace was modifie
d or not. | 87 // FIMXE: The following depends on whether StyleRuleFontFace was modifie
d or not. |
| 80 // No need to always-clear font cache. | 88 // No need to always-clear font cache. |
| 81 engine->clearFontCache(); | 89 engine->clearFontCache(); |
| 82 } else if (StyleResolver* styleResolver = engine->resolver()) { | 90 } else if (StyleResolver* styleResolver = engine->resolver()) { |
| 83 // We should not destroy StyleResolver when we find any stylesheet updat
e in a shadow tree. | 91 // We should not destroy StyleResolver when we find any stylesheet updat
e in a shadow tree. |
| 84 // In this case, we will reset rulesets created from style elements in t
he shadow tree. | 92 // In this case, we will reset rulesets created from style elements in t
he shadow tree. |
| 85 m_treeScope.scopedStyleResolver().resetAuthorStyle(); | 93 m_treeScope.scopedStyleResolver().resetAuthorStyle(); |
| 86 styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets)
; | 94 styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets)
; |
| 87 styleResolver->lazyAppendAuthorStyleSheets(0, candidateSheets); | 95 styleResolver->lazyAppendAuthorStyleSheets(0, candidateSheets); |
| 88 } | 96 } |
| 89 | 97 |
| 90 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change | 98 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change |
| 91 // and only recalc specific tree scopes. | 99 // and only recalc specific tree scopes. |
| 92 root.setNeedsStyleRecalc(SubtreeStyleChange); | 100 root.setNeedsStyleRecalc(SubtreeStyleChange); |
| 93 | 101 |
| 94 // TODO(esprehn): We should use LocalStyleChange, :host rule changes | 102 // TODO(esprehn): We should use LocalStyleChange, :host rule changes |
| 95 // can only impact the host directly as Sky has no descendant selectors. | 103 // can only impact the host directly as Sky has no descendant selectors. |
| 96 if (root.isShadowRoot()) | 104 if (root.isShadowRoot()) |
| 97 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); | 105 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 98 | 106 |
| 99 m_activeAuthorStyleSheets.swap(candidateSheets); | 107 m_activeAuthorStyleSheets.swap(candidateSheets); |
| 108 m_needsUpdate = false; |
| 100 } | 109 } |
| 101 | 110 |
| 102 } | 111 } |
| OLD | NEW |