OLD | NEW |
---|---|
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 Loading... | |
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 if (!rule->isMediaRule()) | |
Timothy Loh
2016/10/14 04:27:24
Also needs to recurse on @supports rules (this is
rune
2016/10/14 07:59:02
Oh, yes. Well spotted. And @import rules too, if t
| |
101 continue; | |
102 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); | |
103 if (!mediaRule->mediaQueries() || | |
104 m_initialViewportMedium->eval(mediaRule->mediaQueries())) | |
105 collectViewportChildRules(mediaRule->childRules(), origin); | |
106 } | |
107 } | |
108 | |
83 void ViewportStyleResolver::collectViewportRules(RuleSet* rules, | 109 void ViewportStyleResolver::collectViewportRules(RuleSet* rules, |
84 Origin origin) { | 110 Origin origin) { |
85 rules->compactRulesIfNeeded(); | 111 rules->compactRulesIfNeeded(); |
86 | 112 |
87 const HeapVector<Member<StyleRuleViewport>>& viewportRules = | 113 const HeapVector<Member<StyleRuleViewport>>& viewportRules = |
88 rules->viewportRules(); | 114 rules->viewportRules(); |
89 for (size_t i = 0; i < viewportRules.size(); ++i) | 115 for (size_t i = 0; i < viewportRules.size(); ++i) |
90 addViewportRule(viewportRules[i], origin); | 116 addViewportRule(*viewportRules[i], origin); |
91 } | 117 } |
92 | 118 |
93 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule, | 119 void ViewportStyleResolver::addViewportRule(StyleRuleViewport& viewportRule, |
94 Origin origin) { | 120 Origin origin) { |
95 StylePropertySet& propertySet = viewportRule->mutableProperties(); | 121 StylePropertySet& propertySet = viewportRule.mutableProperties(); |
96 | 122 |
97 unsigned propertyCount = propertySet.propertyCount(); | 123 unsigned propertyCount = propertySet.propertyCount(); |
98 if (!propertyCount) | 124 if (!propertyCount) |
99 return; | 125 return; |
100 | 126 |
101 if (origin == AuthorOrigin) | 127 if (origin == AuthorOrigin) |
102 m_hasAuthorStyle = true; | 128 m_hasAuthorStyle = true; |
103 | 129 |
104 if (!m_propertySet) { | 130 if (!m_propertySet) { |
105 m_propertySet = propertySet.mutableCopy(); | 131 m_propertySet = propertySet.mutableCopy(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 Length result = primitiveValue->convertToLength( | 255 Length result = primitiveValue->convertToLength( |
230 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); | 256 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); |
231 if (documentStyle->hasViewportUnits()) | 257 if (documentStyle->hasViewportUnits()) |
232 m_document->setHasViewportUnits(); | 258 m_document->setHasViewportUnits(); |
233 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); | 259 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); |
234 | 260 |
235 return result; | 261 return result; |
236 } | 262 } |
237 | 263 |
238 DEFINE_TRACE(ViewportStyleResolver) { | 264 DEFINE_TRACE(ViewportStyleResolver) { |
265 visitor->trace(m_document); | |
239 visitor->trace(m_propertySet); | 266 visitor->trace(m_propertySet); |
240 visitor->trace(m_document); | 267 visitor->trace(m_initialViewportMedium); |
241 } | 268 } |
242 | 269 |
243 } // namespace blink | 270 } // namespace blink |
OLD | NEW |