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 20 matching lines...) Expand all Loading... |
31 #include "sky/engine/core/css/resolver/StyleResolver.h" | 31 #include "sky/engine/core/css/resolver/StyleResolver.h" |
32 #include "sky/engine/core/dom/Document.h" | 32 #include "sky/engine/core/dom/Document.h" |
33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
34 #include "sky/engine/core/dom/TreeScope.h" | 34 #include "sky/engine/core/dom/TreeScope.h" |
35 #include "sky/engine/core/html/HTMLStyleElement.h" | 35 #include "sky/engine/core/html/HTMLStyleElement.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 StyleSheetCollection::StyleSheetCollection(TreeScope& treeScope) | 39 StyleSheetCollection::StyleSheetCollection(TreeScope& treeScope) |
40 : m_treeScope(treeScope) | 40 : m_treeScope(treeScope) |
41 , m_needsUpdate(true) | |
42 { | 41 { |
43 } | 42 } |
44 | 43 |
45 StyleSheetCollection::~StyleSheetCollection() | 44 StyleSheetCollection::~StyleSheetCollection() |
46 { | 45 { |
47 } | 46 } |
48 | 47 |
49 void StyleSheetCollection::addStyleSheetCandidateNode(HTMLStyleElement& element) | 48 void StyleSheetCollection::addStyleSheetCandidateNode(HTMLStyleElement& element) |
50 { | 49 { |
51 ASSERT(element.inActiveDocument()); | 50 ASSERT(element.inActiveDocument()); |
52 m_styleSheetCandidateNodes.add(&element); | 51 m_styleSheetCandidateNodes.add(&element); |
53 m_needsUpdate = true; | |
54 } | 52 } |
55 | 53 |
56 void StyleSheetCollection::removeStyleSheetCandidateNode(HTMLStyleElement& eleme
nt) | 54 void StyleSheetCollection::removeStyleSheetCandidateNode(HTMLStyleElement& eleme
nt) |
57 { | 55 { |
58 m_styleSheetCandidateNodes.remove(&element); | 56 m_styleSheetCandidateNodes.remove(&element); |
59 m_needsUpdate = true; | |
60 } | 57 } |
61 | 58 |
62 void StyleSheetCollection::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& she
ets) | 59 void StyleSheetCollection::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& she
ets) |
63 { | 60 { |
64 for (Node* node : m_styleSheetCandidateNodes) { | 61 for (Node* node : m_styleSheetCandidateNodes) { |
65 ASSERT(isHTMLStyleElement(*node)); | 62 ASSERT(isHTMLStyleElement(*node)); |
66 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet()) | 63 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet()) |
67 sheets.append(sheet); | 64 sheets.append(sheet); |
68 } | 65 } |
69 } | 66 } |
70 | 67 |
71 void StyleSheetCollection::updateActiveStyleSheets(StyleResolver& resolver) | 68 void StyleSheetCollection::updateActiveStyleSheets(StyleResolver& resolver) |
72 { | 69 { |
73 if (!m_needsUpdate) | |
74 return; | |
75 | |
76 Vector<RefPtr<CSSStyleSheet>> candidateSheets; | 70 Vector<RefPtr<CSSStyleSheet>> candidateSheets; |
77 collectStyleSheets(candidateSheets); | 71 collectStyleSheets(candidateSheets); |
78 | 72 |
79 m_treeScope.scopedStyleResolver().resetAuthorStyle(); | 73 m_treeScope.scopedStyleResolver().resetAuthorStyle(); |
80 resolver.removePendingAuthorStyleSheets(m_activeAuthorStyleSheets); | |
81 resolver.lazyAppendAuthorStyleSheets(0, candidateSheets); | |
82 | 74 |
83 Node& root = m_treeScope.rootNode(); | 75 Node& root = m_treeScope.rootNode(); |
84 | 76 |
85 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change | 77 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change |
86 // and only recalc specific tree scopes. | 78 // and only recalc specific tree scopes. |
87 root.setNeedsStyleRecalc(SubtreeStyleChange); | 79 root.setNeedsStyleRecalc(SubtreeStyleChange); |
88 | 80 |
89 // TODO(esprehn): We should use LocalStyleChange, :host rule changes | 81 // TODO(esprehn): We should use LocalStyleChange, :host rule changes |
90 // can only impact the host directly as Sky has no descendant selectors. | 82 // can only impact the host directly as Sky has no descendant selectors. |
91 if (root.isShadowRoot()) | 83 if (root.isShadowRoot()) |
92 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); | 84 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); |
93 | 85 |
94 m_activeAuthorStyleSheets.swap(candidateSheets); | 86 m_activeAuthorStyleSheets.swap(candidateSheets); |
95 m_needsUpdate = false; | 87 |
| 88 for (RefPtr<CSSStyleSheet>& sheet : m_activeAuthorStyleSheets) |
| 89 resolver.appendCSSStyleSheet(sheet.get()); |
96 } | 90 } |
97 | 91 |
98 } | 92 } |
OLD | NEW |