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

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp

Issue 2521063005: Move MediaQueryEvaluator from StyleResolver to StyleEngine. (Closed)
Patch Set: Rebased Created 4 years 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 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
10 * (http://www.torchmobile.com/) 10 * (http://www.torchmobile.com/)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return; 170 return;
171 171
172 // Adding scoped resolver for active shadow roots for shadow host styling. 172 // Adding scoped resolver for active shadow roots for shadow host styling.
173 for (ShadowRoot* shadowRoot = &shadow->youngestShadowRoot(); shadowRoot; 173 for (ShadowRoot* shadowRoot = &shadow->youngestShadowRoot(); shadowRoot;
174 shadowRoot = shadowRoot->olderShadowRoot()) { 174 shadowRoot = shadowRoot->olderShadowRoot()) {
175 if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver()) 175 if (ScopedStyleResolver* resolver = shadowRoot->scopedStyleResolver())
176 resolvers.append(resolver); 176 resolvers.append(resolver);
177 } 177 }
178 } 178 }
179 179
180 StyleResolver::StyleResolver(Document& document) 180 StyleResolver::StyleResolver(Document& document) : m_document(document) {
181 : m_document(document), m_printMediaType(false), m_styleSharingDepth(0) { 181 updateMediaType();
182 FrameView* view = document.view();
183 DCHECK(view);
184 m_medium = new MediaQueryEvaluator(&view->frame());
185 m_printMediaType =
186 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
187 } 182 }
188 183
189 StyleResolver::~StyleResolver() {} 184 StyleResolver::~StyleResolver() {}
190 185
191 void StyleResolver::dispose() { 186 void StyleResolver::dispose() {
192 m_matchedPropertiesCache.clear(); 187 m_matchedPropertiesCache.clear();
193 } 188 }
194 189
195 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) { 190 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
196 m_tracker = tracker; 191 m_tracker = tracker;
(...skipping 14 matching lines...) Expand all
211 } 206 }
212 207
213 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) { 208 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) {
214 DCHECK(!cssSheet.disabled()); 209 DCHECK(!cssSheet.disabled());
215 DCHECK(cssSheet.ownerDocument()); 210 DCHECK(cssSheet.ownerDocument());
216 DCHECK(cssSheet.ownerNode()); 211 DCHECK(cssSheet.ownerNode());
217 DCHECK(isHTMLStyleElement(cssSheet.ownerNode()) || 212 DCHECK(isHTMLStyleElement(cssSheet.ownerNode()) ||
218 isSVGStyleElement(cssSheet.ownerNode()) || 213 isSVGStyleElement(cssSheet.ownerNode()) ||
219 cssSheet.ownerNode()->isConnected()); 214 cssSheet.ownerNode()->isConnected());
220 215
216 const MediaQueryEvaluator& evaluator =
217 document().styleEngine().ensureMediaQueryEvaluator();
221 if (cssSheet.mediaQueries() && 218 if (cssSheet.mediaQueries() &&
222 !m_medium->eval(cssSheet.mediaQueries(), 219 !evaluator.eval(cssSheet.mediaQueries(),
223 &m_viewportDependentMediaQueryResults, 220 &m_viewportDependentMediaQueryResults,
224 &m_deviceDependentMediaQueryResults)) 221 &m_deviceDependentMediaQueryResults))
225 return; 222 return;
226 223
227 TreeScope* treeScope = &cssSheet.ownerNode()->treeScope(); 224 TreeScope* treeScope = &cssSheet.ownerNode()->treeScope();
228 // TODO(rune@opera.com): This is a workaround for crbug.com/559292 225 // TODO(rune@opera.com): This is a workaround for crbug.com/559292
229 // when we're in the middle of removing a subtree with a style element 226 // when we're in the middle of removing a subtree with a style element
230 // and the treescope has been changed but inDocument and isInShadowTree 227 // and the treescope has been changed but inDocument and isInShadowTree
231 // are not. 228 // are not.
232 // 229 //
233 // This check can be removed when crbug.com/567021 is fixed. 230 // This check can be removed when crbug.com/567021 is fixed.
234 if (cssSheet.ownerNode()->isInShadowTree() && 231 if (cssSheet.ownerNode()->isInShadowTree() &&
235 treeScope->rootNode().isDocumentNode()) 232 treeScope->rootNode().isDocumentNode())
236 return; 233 return;
237 234
238 // Sheets in the document scope of HTML imports apply to the main document 235 // Sheets in the document scope of HTML imports apply to the main document
239 // (m_document), so we override it for all document scoped sheets. 236 // (m_document), so we override it for all document scoped sheets.
240 if (treeScope->rootNode().isDocumentNode()) 237 if (treeScope->rootNode().isDocumentNode())
241 treeScope = m_document; 238 treeScope = m_document;
242 treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(cssSheet, 239 treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(cssSheet,
243 *m_medium); 240 evaluator);
244 } 241 }
245 242
246 void StyleResolver::appendPendingAuthorStyleSheets() { 243 void StyleResolver::appendPendingAuthorStyleSheets() {
247 for (const auto& styleSheet : m_pendingStyleSheets) 244 for (const auto& styleSheet : m_pendingStyleSheets)
248 appendCSSStyleSheet(*styleSheet); 245 appendCSSStyleSheet(*styleSheet);
249 246
250 m_pendingStyleSheets.clear(); 247 m_pendingStyleSheets.clear();
251 } 248 }
252 249
253 void StyleResolver::appendAuthorStyleSheets( 250 void StyleResolver::appendAuthorStyleSheets(
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 m_viewportDependentMediaQueryResults.append(list[i]); 1948 m_viewportDependentMediaQueryResults.append(list[i]);
1952 } 1949 }
1953 1950
1954 void StyleResolver::addDeviceDependentMediaQueries( 1951 void StyleResolver::addDeviceDependentMediaQueries(
1955 const MediaQueryResultList& list) { 1952 const MediaQueryResultList& list) {
1956 for (size_t i = 0; i < list.size(); ++i) 1953 for (size_t i = 0; i < list.size(); ++i)
1957 m_deviceDependentMediaQueryResults.append(list[i]); 1954 m_deviceDependentMediaQueryResults.append(list[i]);
1958 } 1955 }
1959 1956
1960 bool StyleResolver::mediaQueryAffectedByViewportChange() const { 1957 bool StyleResolver::mediaQueryAffectedByViewportChange() const {
1958 const MediaQueryEvaluator& evaluator =
1959 document().styleEngine().ensureMediaQueryEvaluator();
1961 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { 1960 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) {
1962 if (m_medium->eval(m_viewportDependentMediaQueryResults[i]->expression()) != 1961 if (evaluator.eval(m_viewportDependentMediaQueryResults[i]->expression()) !=
1963 m_viewportDependentMediaQueryResults[i]->result()) 1962 m_viewportDependentMediaQueryResults[i]->result())
1964 return true; 1963 return true;
1965 } 1964 }
1966 return false; 1965 return false;
1967 } 1966 }
1968 1967
1969 bool StyleResolver::mediaQueryAffectedByDeviceChange() const { 1968 bool StyleResolver::mediaQueryAffectedByDeviceChange() const {
1969 const MediaQueryEvaluator& evaluator =
1970 document().styleEngine().ensureMediaQueryEvaluator();
1970 for (unsigned i = 0; i < m_deviceDependentMediaQueryResults.size(); ++i) { 1971 for (unsigned i = 0; i < m_deviceDependentMediaQueryResults.size(); ++i) {
1971 if (m_medium->eval(m_deviceDependentMediaQueryResults[i]->expression()) != 1972 if (evaluator.eval(m_deviceDependentMediaQueryResults[i]->expression()) !=
1972 m_deviceDependentMediaQueryResults[i]->result()) 1973 m_deviceDependentMediaQueryResults[i]->result())
1973 return true; 1974 return true;
1974 } 1975 }
1975 return false; 1976 return false;
1976 } 1977 }
1977 1978
1979 void StyleResolver::updateMediaType() {
1980 if (FrameView* view = document().view()) {
1981 m_printMediaType =
1982 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
1983 }
1984 }
1985
1978 DEFINE_TRACE(StyleResolver) { 1986 DEFINE_TRACE(StyleResolver) {
1979 visitor->trace(m_matchedPropertiesCache); 1987 visitor->trace(m_matchedPropertiesCache);
1980 visitor->trace(m_medium);
1981 visitor->trace(m_viewportDependentMediaQueryResults); 1988 visitor->trace(m_viewportDependentMediaQueryResults);
1982 visitor->trace(m_deviceDependentMediaQueryResults); 1989 visitor->trace(m_deviceDependentMediaQueryResults);
1983 visitor->trace(m_selectorFilter); 1990 visitor->trace(m_selectorFilter);
1984 visitor->trace(m_styleSharingLists); 1991 visitor->trace(m_styleSharingLists);
1985 visitor->trace(m_pendingStyleSheets); 1992 visitor->trace(m_pendingStyleSheets);
1986 visitor->trace(m_document); 1993 visitor->trace(m_document);
1987 visitor->trace(m_tracker); 1994 visitor->trace(m_tracker);
1988 } 1995 }
1989 1996
1990 } // namespace blink 1997 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/resolver/StyleResolver.h ('k') | third_party/WebKit/Source/core/dom/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698