Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: sky/engine/core/css/resolver/ScopedStyleResolver.cpp

Issue 852703002: Merge StyleSheetCollection into ScopedStyleResolver. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 18 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "sky/engine/config.h" 27 #include "sky/engine/config.h"
28 #include "sky/engine/core/css/resolver/ScopedStyleResolver.h" 28 #include "sky/engine/core/css/resolver/ScopedStyleResolver.h"
29 29
30 #include "sky/engine/core/css/CSSFontSelector.h"
30 #include "sky/engine/core/css/CSSStyleSheet.h" 31 #include "sky/engine/core/css/CSSStyleSheet.h"
32 #include "sky/engine/core/css/FontFace.h"
31 #include "sky/engine/core/css/RuleFeature.h" 33 #include "sky/engine/core/css/RuleFeature.h"
32 #include "sky/engine/core/css/StyleRule.h" 34 #include "sky/engine/core/css/StyleRule.h"
33 #include "sky/engine/core/css/StyleSheetContents.h" 35 #include "sky/engine/core/css/StyleSheetContents.h"
36 #include "sky/engine/core/css/resolver/StyleResolver.h"
37 #include "sky/engine/core/dom/Document.h"
38 #include "sky/engine/core/dom/StyleEngine.h"
39 #include "sky/engine/core/dom/TreeScope.h"
40 #include "sky/engine/core/dom/shadow/ShadowRoot.h"
41 #include "sky/engine/core/html/HTMLStyleElement.h"
34 42
35 namespace blink { 43 namespace blink {
36 44
37 ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope) 45 ScopedStyleResolver::ScopedStyleResolver(TreeScope& scope)
38 : m_scope(scope) 46 : m_scope(scope)
39 { 47 {
40 } 48 }
41 49
42 void ScopedStyleResolver::addRulesFromSheet(CSSStyleSheet* cssSheet) 50 void ScopedStyleResolver::appendStyleSheet(CSSStyleSheet& sheet)
43 { 51 {
44 m_authorStyleSheets.append(cssSheet); 52 Document& document = m_scope.document();
53 StyleResolver& styleResolver = document.ensureStyleResolver();
54 MediaQueryEvaluator& medium = styleResolver.medium();
45 55
46 const RuleSet& ruleSet = cssSheet->contents()->ensureRuleSet(); 56 if (sheet.mediaQueries() && !medium.eval(sheet.mediaQueries(), &m_viewportDe pendentMediaQueryResults))
57 return;
58
59 styleResolver.addMediaQueryAffectedByViewportChange(m_viewportDependentMedia QueryResults);
60
61 const RuleSet& ruleSet = sheet.contents()->ensureRuleSet();
47 m_features.add(ruleSet.features()); 62 m_features.add(ruleSet.features());
63
64 if (m_scope.rootNode().isDocumentNode()) {
65 CSSFontSelector* fontSelector = document.styleEngine()->fontSelector();
66 RuleSet& ruleSet = sheet.contents()->ruleSet();
67 for (const auto& rule : ruleSet.fontFaceRules()) {
68 if (RefPtr<FontFace> fontFace = FontFace::create(&document, rule))
69 fontSelector->fontFaceCache()->add(fontSelector, rule, fontFace) ;
70 }
71 if (!ruleSet.fontFaceRules().isEmpty())
72 styleResolver.invalidateMatchedPropertiesCache();
73 }
48 } 74 }
49 75
50 void ScopedStyleResolver::resetAuthorStyle() 76 void ScopedStyleResolver::updateActiveStyleSheets()
51 { 77 {
52 m_authorStyleSheets.clear(); 78 Vector<RefPtr<CSSStyleSheet>> candidateSheets;
79 collectStyleSheets(candidateSheets);
80 m_authorStyleSheets.swap(candidateSheets);
81
82 Node& root = m_scope.rootNode();
83
84 // TODO(esprehn): We should avoid subtree recalcs in sky when rules change
85 // and only recalc specific tree scopes.
86 root.setNeedsStyleRecalc(SubtreeStyleChange);
87
88 // TODO(esprehn): We should use LocalStyleChange, :host rule changes
89 // can only impact the host directly as Sky has no descendant selectors.
90 if (root.isShadowRoot())
91 toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange);
92
53 m_features.clear(); 93 m_features.clear();
94 m_viewportDependentMediaQueryResults.clear();
95
96 for (RefPtr<CSSStyleSheet>& sheet : m_authorStyleSheets)
97 appendStyleSheet(*sheet);
98 }
99
100 const MediaQueryResultList& ScopedStyleResolver::viewportDependentMediaQueryResu lts() const
101 {
102 return m_viewportDependentMediaQueryResults;
103 }
104
105 void ScopedStyleResolver::addStyleSheetCandidateNode(HTMLStyleElement& element)
106 {
107 ASSERT(element.inActiveDocument());
108 m_styleSheetCandidateNodes.add(&element);
109 }
110
111 void ScopedStyleResolver::removeStyleSheetCandidateNode(HTMLStyleElement& elemen t)
112 {
113 m_styleSheetCandidateNodes.remove(&element);
114 }
115
116 void ScopedStyleResolver::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& shee ts)
117 {
118 for (Node* node : m_styleSheetCandidateNodes) {
119 ASSERT(isHTMLStyleElement(*node));
120 if (CSSStyleSheet* sheet = toHTMLStyleElement(node)->sheet())
121 sheets.append(sheet);
122 }
54 } 123 }
55 124
56 const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String animationName) 125 const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String animationName)
57 { 126 {
58 for (auto& sheet : m_authorStyleSheets) { 127 for (auto& sheet : m_authorStyleSheets) {
59 // TODO(esprehn): Maybe just store the keyframes in a map? 128 // TODO(esprehn): Maybe just store the keyframes in a map?
60 for (auto& rule : sheet->contents()->ruleSet().keyframesRules()) { 129 for (auto& rule : sheet->contents()->ruleSet().keyframesRules()) {
61 if (rule->name() == animationName) 130 if (rule->name() == animationName)
62 return rule.get(); 131 return rule.get();
63 } 132 }
64 } 133 }
65 return nullptr; 134 return nullptr;
66 } 135 }
67 136
68 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle ctor, CascadeOrder cascadeOrder) 137 void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& colle ctor, CascadeOrder cascadeOrder)
69 { 138 {
70 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); 139 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange();
71 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { 140 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) {
72 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet() , m_authorStyleSheets[i], i); 141 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet() , m_authorStyleSheets[i].get(), i);
73 collector.collectMatchingRules(matchRequest, ruleRange, cascadeOrder); 142 collector.collectMatchingRules(matchRequest, ruleRange, cascadeOrder);
74 } 143 }
75 } 144 }
76 145
77 void ScopedStyleResolver::collectMatchingHostRules(ElementRuleCollector& collect or, CascadeOrder cascadeOrder) 146 void ScopedStyleResolver::collectMatchingHostRules(ElementRuleCollector& collect or, CascadeOrder cascadeOrder)
78 { 147 {
79 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); 148 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange();
80 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { 149 for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) {
81 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet() , m_authorStyleSheets[i], i); 150 MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet() , m_authorStyleSheets[i].get(), i);
82 collector.collectMatchingHostRules(matchRequest, ruleRange, cascadeOrder ); 151 collector.collectMatchingHostRules(matchRequest, ruleRange, cascadeOrder );
83 } 152 }
84 } 153 }
85 154
86 } // namespace blink 155 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/resolver/ScopedStyleResolver.h ('k') | sky/engine/core/css/resolver/StyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698