OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
4 * Copyright (C) 2012 Google Inc. All rights reserved. | 4 * Copyright (C) 2012 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 37 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
38 #include "sky/engine/core/html/HTMLStyleElement.h" | 38 #include "sky/engine/core/html/HTMLStyleElement.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope) | 42 ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope) |
43 : m_scope(scope) | 43 : m_scope(scope) |
44 { | 44 { |
45 } | 45 } |
46 | 46 |
47 void ScopedStyleResolver::appendStyleSheet(CSSStyleSheet& sheet) | |
48 { | |
49 MediaQueryEvaluator medium(m_scope.document().view()); | |
50 | |
51 if (sheet.mediaQueries() && !medium.eval(sheet.mediaQueries())) | |
52 return; | |
53 | |
54 const RuleSet& ruleSet = sheet.contents()->ensureRuleSet(); | |
55 m_features.add(ruleSet.features()); | |
56 } | |
57 | |
58 void ScopedStyleResolver::updateActiveStyleSheets() | 47 void ScopedStyleResolver::updateActiveStyleSheets() |
59 { | 48 { |
60 Vector<RefPtr<CSSStyleSheet>> candidateSheets; | 49 Vector<RefPtr<CSSStyleSheet>> candidateSheets; |
61 collectStyleSheets(candidateSheets); | 50 collectStyleSheets(candidateSheets); |
62 m_authorStyleSheets.swap(candidateSheets); | 51 m_authorStyleSheets.swap(candidateSheets); |
63 | 52 |
64 Node& root = m_scope.rootNode(); | 53 Node& root = m_scope.rootNode(); |
65 | 54 |
66 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change | 55 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change |
67 // and only recalc specific tree scopes. | 56 // and only recalc specific tree scopes. |
68 root.setNeedsStyleRecalc(SubtreeStyleChange); | 57 root.setNeedsStyleRecalc(SubtreeStyleChange); |
69 | 58 |
70 // TODO(esprehn): We should use LocalStyleChange, :host rule changes | 59 // TODO(esprehn): We should use LocalStyleChange, :host rule changes |
71 // can only impact the host directly as Sky has no descendant selectors. | 60 // can only impact the host directly as Sky has no descendant selectors. |
72 if (root.isShadowRoot()) | 61 if (root.isShadowRoot()) |
73 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); | 62 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 63 } |
74 | 64 |
75 m_features.clear(); | 65 bool ScopedStyleResolver::hasSelectorForId(const AtomicString& id) const |
| 66 { |
| 67 for (auto& sheet : m_authorStyleSheets) { |
| 68 RuleSet& ruleSet = sheet->contents()->ensureRuleSet(); |
| 69 if (ruleSet.features().hasSelectorForId(id)) |
| 70 return true; |
| 71 } |
| 72 return false; |
| 73 } |
76 | 74 |
77 for (RefPtr<CSSStyleSheet>& sheet : m_authorStyleSheets) | 75 bool ScopedStyleResolver::hasSelectorForClass(const AtomicString& className) con
st |
78 appendStyleSheet(*sheet); | 76 { |
| 77 for (auto& sheet : m_authorStyleSheets) { |
| 78 RuleSet& ruleSet = sheet->contents()->ensureRuleSet(); |
| 79 if (ruleSet.features().hasSelectorForClass(className)) |
| 80 return true; |
| 81 } |
| 82 return false; |
| 83 } |
| 84 |
| 85 bool ScopedStyleResolver::hasSelectorForAttribute(const AtomicString& attributeN
ame) const |
| 86 { |
| 87 for (auto& sheet : m_authorStyleSheets) { |
| 88 RuleSet& ruleSet = sheet->contents()->ensureRuleSet(); |
| 89 if (ruleSet.features().hasSelectorForAttribute(attributeName)) |
| 90 return true; |
| 91 } |
| 92 return false; |
79 } | 93 } |
80 | 94 |
81 void ScopedStyleResolver::addStyleSheetCandidateNode(HTMLStyleElement& element) | 95 void ScopedStyleResolver::addStyleSheetCandidateNode(HTMLStyleElement& element) |
82 { | 96 { |
83 ASSERT(element.inActiveDocument()); | 97 ASSERT(element.inActiveDocument()); |
84 m_styleSheetCandidateNodes.add(&element); | 98 m_styleSheetCandidateNodes.add(&element); |
85 } | 99 } |
86 | 100 |
87 void ScopedStyleResolver::removeStyleSheetCandidateNode(HTMLStyleElement& elemen
t) | 101 void ScopedStyleResolver::removeStyleSheetCandidateNode(HTMLStyleElement& elemen
t) |
88 { | 102 { |
89 m_styleSheetCandidateNodes.remove(&element); | 103 m_styleSheetCandidateNodes.remove(&element); |
90 } | 104 } |
91 | 105 |
92 void ScopedStyleResolver::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& shee
ts) | 106 void ScopedStyleResolver::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& shee
ts) |
93 { | 107 { |
| 108 MediaQueryEvaluator medium(m_scope.document().view()); |
| 109 |
94 for (Node* node : m_styleSheetCandidateNodes) { | 110 for (Node* node : m_styleSheetCandidateNodes) { |
95 ASSERT(isHTMLStyleElement(*node)); | 111 ASSERT(isHTMLStyleElement(*node)); |
96 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet()) | 112 CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet(); |
| 113 if (sheet && (!sheet->mediaQueries() || medium.eval(sheet->mediaQueries(
)))) { |
97 sheets.append(sheet); | 114 sheets.append(sheet); |
| 115 } |
98 } | 116 } |
99 } | 117 } |
100 | 118 |
101 const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String
animationName) | 119 const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String
animationName) |
102 { | 120 { |
103 for (auto& sheet : m_authorStyleSheets) { | 121 for (auto& sheet : m_authorStyleSheets) { |
104 // TODO(esprehn): Maybe just store the keyframes in a map? | 122 // TODO(esprehn): Maybe just store the keyframes in a map? |
105 for (auto& rule : sheet->contents()->ruleSet().keyframesRules()) { | 123 for (auto& rule : sheet->contents()->ensureRuleSet().keyframesRules()) { |
106 if (rule->name() == animationName) | 124 if (rule->name() == animationName) |
107 return rule.get(); | 125 return rule.get(); |
108 } | 126 } |
109 } | 127 } |
110 return nullptr; | 128 return nullptr; |
111 } | 129 } |
112 | 130 |
113 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
ctor, CascadeOrder cascadeOrder) | 131 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle
ctor, CascadeOrder cascadeOrder) |
114 { | 132 { |
115 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { | 133 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |
116 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet()
, m_authorStyleSheets[i].get(), i); | 134 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ensureRul
eSet(), m_authorStyleSheets[i].get(), i); |
117 collector.collectMatchingRules(matchRequest, cascadeOrder); | 135 collector.collectMatchingRules(matchRequest, cascadeOrder); |
118 } | 136 } |
119 } | 137 } |
120 | 138 |
121 void ScopedStyleResolver::collectMatchingHostRules(ElementRuleCollector& collect
or, CascadeOrder cascadeOrder) | 139 void ScopedStyleResolver::collectMatchingHostRules(ElementRuleCollector& collect
or, CascadeOrder cascadeOrder) |
122 { | 140 { |
123 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { | 141 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { |
124 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet()
, m_authorStyleSheets[i].get(), i); | 142 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ensureRul
eSet(), m_authorStyleSheets[i].get(), i); |
125 collector.collectMatchingHostRules(matchRequest, cascadeOrder); | 143 collector.collectMatchingHostRules(matchRequest, cascadeOrder); |
126 } | 144 } |
127 } | 145 } |
128 | 146 |
129 } // namespace blink | 147 } // namespace blink |
OLD | NEW |