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

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

Issue 2410283005: Don't generate RuleSets for viewport UA sheets. (Closed)
Patch Set: Rebased Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/css/resolver/ViewportStyleResolver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved. 2 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 15 matching lines...) Expand all
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "core/css/resolver/ViewportStyleResolver.h" 30 #include "core/css/resolver/ViewportStyleResolver.h"
31 31
32 #include "core/CSSValueKeywords.h" 32 #include "core/CSSValueKeywords.h"
33 #include "core/css/CSSDefaultStyleSheets.h" 33 #include "core/css/CSSDefaultStyleSheets.h"
34 #include "core/css/CSSPrimitiveValueMappings.h" 34 #include "core/css/CSSPrimitiveValueMappings.h"
35 #include "core/css/CSSToLengthConversionData.h" 35 #include "core/css/CSSToLengthConversionData.h"
36 #include "core/css/MediaValuesDynamic.h"
36 #include "core/css/StylePropertySet.h" 37 #include "core/css/StylePropertySet.h"
37 #include "core/css/StyleRule.h" 38 #include "core/css/StyleRule.h"
39 #include "core/css/StyleSheetContents.h"
38 #include "core/css/resolver/ScopedStyleResolver.h" 40 #include "core/css/resolver/ScopedStyleResolver.h"
39 #include "core/dom/Document.h" 41 #include "core/dom/Document.h"
40 #include "core/dom/NodeComputedStyle.h" 42 #include "core/dom/NodeComputedStyle.h"
41 #include "core/dom/ViewportDescription.h" 43 #include "core/dom/ViewportDescription.h"
42 #include "core/frame/Settings.h" 44 #include "core/frame/Settings.h"
43 #include "core/layout/api/LayoutViewItem.h" 45 #include "core/layout/api/LayoutViewItem.h"
44 46
45 namespace blink { 47 namespace blink {
46 48
47 ViewportStyleResolver::ViewportStyleResolver(Document* document) 49 ViewportStyleResolver::ViewportStyleResolver(Document& document)
48 : m_document(document), m_hasAuthorStyle(false) { 50 : m_document(document), m_hasAuthorStyle(false) {
49 ASSERT(m_document); 51 DCHECK(document.frame());
52 // TODO(rune@opera.com): The MediaValues object passed here should reflect the
53 // initial viewport, not the actual viewport. See https://crbug.com/332763
54 m_initialViewportMedium =
55 new MediaQueryEvaluator(MediaValuesDynamic::create(document.frame()));
50 } 56 }
51 57
52 void ViewportStyleResolver::collectViewportRules() { 58 void ViewportStyleResolver::collectViewportRulesFromUASheets() {
53 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(); 59 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance();
54 collectViewportRules(defaultStyleSheets.defaultStyle(), UserAgentOrigin);
55
56 WebViewportStyle viewportStyle = m_document->settings() 60 WebViewportStyle viewportStyle = m_document->settings()
57 ? m_document->settings()->viewportStyle() 61 ? m_document->settings()->viewportStyle()
58 : WebViewportStyle::Default; 62 : WebViewportStyle::Default;
59 RuleSet* viewportRules = nullptr; 63 StyleSheetContents* viewportContents = nullptr;
60 switch (viewportStyle) { 64 switch (viewportStyle) {
61 case WebViewportStyle::Default: 65 case WebViewportStyle::Default:
62 break; 66 break;
63 case WebViewportStyle::Mobile: 67 case WebViewportStyle::Mobile:
64 viewportRules = defaultStyleSheets.defaultMobileViewportStyle(); 68 viewportContents = defaultStyleSheets.ensureMobileViewportStyleSheet();
65 break; 69 break;
66 case WebViewportStyle::Television: 70 case WebViewportStyle::Television:
67 viewportRules = defaultStyleSheets.defaultTelevisionViewportStyle(); 71 viewportContents =
72 defaultStyleSheets.ensureTelevisionViewportStyleSheet();
68 break; 73 break;
69 } 74 }
70 if (viewportRules) 75 if (viewportContents)
71 collectViewportRules(viewportRules, UserAgentOrigin); 76 collectViewportChildRules(viewportContents->childRules(), UserAgentOrigin);
72 77
73 if (m_document->isMobileDocument()) 78 if (m_document->isMobileDocument()) {
74 collectViewportRules(defaultStyleSheets.defaultXHTMLMobileProfileStyle(), 79 collectViewportChildRules(
75 UserAgentOrigin); 80 defaultStyleSheets.ensureXHTMLMobileProfileStyleSheet()->childRules(),
81 UserAgentOrigin);
82 }
83 DCHECK(!defaultStyleSheets.defaultStyleSheet()->hasViewportRule());
84 }
76 85
86 void ViewportStyleResolver::collectViewportRules() {
87 collectViewportRulesFromUASheets();
77 if (ScopedStyleResolver* scopedResolver = m_document->scopedStyleResolver()) 88 if (ScopedStyleResolver* scopedResolver = m_document->scopedStyleResolver())
78 scopedResolver->collectViewportRulesTo(this); 89 scopedResolver->collectViewportRulesTo(this);
79 90
80 resolve(); 91 resolve();
81 } 92 }
82 93
94 void ViewportStyleResolver::collectViewportChildRules(
95 const HeapVector<Member<StyleRuleBase>>& rules,
96 Origin origin) {
97 for (auto& rule : rules) {
98 if (rule->isViewportRule()) {
99 addViewportRule(*toStyleRuleViewport(rule), origin);
100 } else if (rule->isMediaRule()) {
101 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule);
102 if (!mediaRule->mediaQueries() ||
103 m_initialViewportMedium->eval(mediaRule->mediaQueries()))
104 collectViewportChildRules(mediaRule->childRules(), origin);
105 } else if (rule->isSupportsRule()) {
106 StyleRuleSupports* supportsRule = toStyleRuleSupports(rule);
107 if (supportsRule->conditionIsSupported())
108 collectViewportChildRules(supportsRule->childRules(), origin);
109 }
110 }
111 }
112
83 void ViewportStyleResolver::collectViewportRules(RuleSet* rules, 113 void ViewportStyleResolver::collectViewportRules(RuleSet* rules,
84 Origin origin) { 114 Origin origin) {
85 rules->compactRulesIfNeeded(); 115 rules->compactRulesIfNeeded();
86 116
87 const HeapVector<Member<StyleRuleViewport>>& viewportRules = 117 const HeapVector<Member<StyleRuleViewport>>& viewportRules =
88 rules->viewportRules(); 118 rules->viewportRules();
89 for (size_t i = 0; i < viewportRules.size(); ++i) 119 for (size_t i = 0; i < viewportRules.size(); ++i)
90 addViewportRule(viewportRules[i], origin); 120 addViewportRule(*viewportRules[i], origin);
91 } 121 }
92 122
93 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule, 123 void ViewportStyleResolver::addViewportRule(StyleRuleViewport& viewportRule,
94 Origin origin) { 124 Origin origin) {
95 StylePropertySet& propertySet = viewportRule->mutableProperties(); 125 StylePropertySet& propertySet = viewportRule.mutableProperties();
96 126
97 unsigned propertyCount = propertySet.propertyCount(); 127 unsigned propertyCount = propertySet.propertyCount();
98 if (!propertyCount) 128 if (!propertyCount)
99 return; 129 return;
100 130
101 if (origin == AuthorOrigin) 131 if (origin == AuthorOrigin)
102 m_hasAuthorStyle = true; 132 m_hasAuthorStyle = true;
103 133
104 if (!m_propertySet) { 134 if (!m_propertySet) {
105 m_propertySet = propertySet.mutableCopy(); 135 m_propertySet = propertySet.mutableCopy();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 Length result = primitiveValue->convertToLength( 259 Length result = primitiveValue->convertToLength(
230 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); 260 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f));
231 if (documentStyle->hasViewportUnits()) 261 if (documentStyle->hasViewportUnits())
232 m_document->setHasViewportUnits(); 262 m_document->setHasViewportUnits();
233 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); 263 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits);
234 264
235 return result; 265 return result;
236 } 266 }
237 267
238 DEFINE_TRACE(ViewportStyleResolver) { 268 DEFINE_TRACE(ViewportStyleResolver) {
269 visitor->trace(m_document);
239 visitor->trace(m_propertySet); 270 visitor->trace(m_propertySet);
240 visitor->trace(m_document); 271 visitor->trace(m_initialViewportMedium);
241 } 272 }
242 273
243 } // namespace blink 274 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/resolver/ViewportStyleResolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698