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 14 matching lines...) Expand all Loading... |
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
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/CSSStyleSheet.h" |
35 #include "core/css/CSSToLengthConversionData.h" | 36 #include "core/css/CSSToLengthConversionData.h" |
| 37 #include "core/css/MediaValuesDynamic.h" |
36 #include "core/css/StylePropertySet.h" | 38 #include "core/css/StylePropertySet.h" |
37 #include "core/css/StyleRule.h" | 39 #include "core/css/StyleRule.h" |
38 #include "core/css/resolver/ScopedStyleResolver.h" | 40 #include "core/css/StyleSheetContents.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) { |
49 ASSERT(m_document); | 51 DCHECK(m_document); |
| 52 DCHECK(m_document->frame()); |
| 53 // TODO(rune@opera.com): The MediaValues object passed here should reflect the |
| 54 // initial viewport, not the actual viewport. See https://crbug.com/332763 |
| 55 m_initialViewportMedium = |
| 56 new MediaQueryEvaluator(MediaValuesDynamic::create(m_document->frame())); |
50 } | 57 } |
51 | 58 |
52 void ViewportStyleResolver::collectViewportRules() { | 59 void ViewportStyleResolver::reset() { |
| 60 m_viewportDependentMediaQueryResults.clear(); |
| 61 m_deviceDependentMediaQueryResults.clear(); |
| 62 m_propertySet = nullptr; |
| 63 m_hasAuthorStyle = false; |
| 64 m_hasViewportUnits = false; |
| 65 } |
| 66 |
| 67 void ViewportStyleResolver::collectViewportRulesFromUASheets() { |
53 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(); | 68 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(); |
54 collectViewportRules(defaultStyleSheets.defaultStyle(), UserAgentOrigin); | |
55 | 69 |
56 WebViewportStyle viewportStyle = m_document->settings() | 70 WebViewportStyle viewportStyle = m_document->settings() |
57 ? m_document->settings()->viewportStyle() | 71 ? m_document->settings()->viewportStyle() |
58 : WebViewportStyle::Default; | 72 : WebViewportStyle::Default; |
59 RuleSet* viewportRules = nullptr; | 73 StyleSheetContents* viewportContents = nullptr; |
60 switch (viewportStyle) { | 74 switch (viewportStyle) { |
61 case WebViewportStyle::Default: | 75 case WebViewportStyle::Default: |
62 break; | 76 break; |
63 case WebViewportStyle::Mobile: | 77 case WebViewportStyle::Mobile: |
64 viewportRules = defaultStyleSheets.defaultMobileViewportStyle(); | 78 viewportContents = defaultStyleSheets.ensureMobileViewportStyleSheet(); |
65 break; | 79 break; |
66 case WebViewportStyle::Television: | 80 case WebViewportStyle::Television: |
67 viewportRules = defaultStyleSheets.defaultTelevisionViewportStyle(); | 81 viewportContents = |
| 82 defaultStyleSheets.ensureTelevisionViewportStyleSheet(); |
68 break; | 83 break; |
69 } | 84 } |
70 if (viewportRules) | 85 if (viewportContents) |
71 collectViewportRules(viewportRules, UserAgentOrigin); | 86 collectViewportChildRules(viewportContents->childRules(), UserAgentOrigin); |
72 | 87 if (m_document->isMobileDocument()) { |
73 if (m_document->isMobileDocument()) | 88 collectViewportChildRules( |
74 collectViewportRules(defaultStyleSheets.defaultXHTMLMobileProfileStyle(), | 89 defaultStyleSheets.ensureXHTMLMobileProfileStyleSheet()->childRules(), |
75 UserAgentOrigin); | 90 UserAgentOrigin); |
76 | 91 } |
77 if (ScopedStyleResolver* scopedResolver = m_document->scopedStyleResolver()) | |
78 scopedResolver->collectViewportRulesTo(this); | |
79 | |
80 resolve(); | |
81 } | 92 } |
82 | 93 |
83 void ViewportStyleResolver::collectViewportRules(RuleSet* rules, | 94 void ViewportStyleResolver::collectViewportRulesFromAuthorSheet( |
84 Origin origin) { | 95 const CSSStyleSheet& sheet) { |
85 rules->compactRulesIfNeeded(); | 96 if (!sheet.contents()->hasViewportRule()) |
86 | 97 return; |
87 const HeapVector<Member<StyleRuleViewport>>& viewportRules = | 98 if (sheet.mediaQueries() && |
88 rules->viewportRules(); | 99 !m_initialViewportMedium->eval(sheet.mediaQueries(), |
89 for (size_t i = 0; i < viewportRules.size(); ++i) | 100 &m_viewportDependentMediaQueryResults)) |
90 addViewportRule(viewportRules[i], origin); | 101 return; |
| 102 collectViewportChildRules(sheet.contents()->childRules(), AuthorOrigin); |
91 } | 103 } |
92 | 104 |
93 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule, | 105 void ViewportStyleResolver::collectViewportChildRules( |
| 106 const HeapVector<Member<StyleRuleBase>>& rules, |
| 107 Origin origin) { |
| 108 for (auto& rule : rules) { |
| 109 if (rule->isViewportRule()) |
| 110 addViewportRule(*toStyleRuleViewport(rule), origin); |
| 111 if (!rule->isMediaRule()) |
| 112 continue; |
| 113 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); |
| 114 if (!mediaRule->mediaQueries() || |
| 115 m_initialViewportMedium->eval(mediaRule->mediaQueries(), |
| 116 &m_viewportDependentMediaQueryResults)) |
| 117 collectViewportChildRules(mediaRule->childRules(), origin); |
| 118 } |
| 119 } |
| 120 |
| 121 void ViewportStyleResolver::addViewportRule(StyleRuleViewport& viewportRule, |
94 Origin origin) { | 122 Origin origin) { |
95 StylePropertySet& propertySet = viewportRule->mutableProperties(); | 123 StylePropertySet& propertySet = viewportRule.mutableProperties(); |
96 | 124 |
97 unsigned propertyCount = propertySet.propertyCount(); | 125 unsigned propertyCount = propertySet.propertyCount(); |
98 if (!propertyCount) | 126 if (!propertyCount) |
99 return; | 127 return; |
100 | 128 |
101 if (origin == AuthorOrigin) | 129 if (origin == AuthorOrigin) |
102 m_hasAuthorStyle = true; | 130 m_hasAuthorStyle = true; |
103 | 131 |
104 if (!m_propertySet) { | 132 if (!m_propertySet) { |
105 m_propertySet = propertySet.mutableCopy(); | 133 m_propertySet = propertySet.mutableCopy(); |
(...skipping 22 matching lines...) Expand all Loading... |
128 description.zoom = viewportArgumentValue(CSSPropertyZoom); | 156 description.zoom = viewportArgumentValue(CSSPropertyZoom); |
129 description.minZoom = viewportArgumentValue(CSSPropertyMinZoom); | 157 description.minZoom = viewportArgumentValue(CSSPropertyMinZoom); |
130 description.maxZoom = viewportArgumentValue(CSSPropertyMaxZoom); | 158 description.maxZoom = viewportArgumentValue(CSSPropertyMaxZoom); |
131 description.minWidth = viewportLengthValue(CSSPropertyMinWidth); | 159 description.minWidth = viewportLengthValue(CSSPropertyMinWidth); |
132 description.maxWidth = viewportLengthValue(CSSPropertyMaxWidth); | 160 description.maxWidth = viewportLengthValue(CSSPropertyMaxWidth); |
133 description.minHeight = viewportLengthValue(CSSPropertyMinHeight); | 161 description.minHeight = viewportLengthValue(CSSPropertyMinHeight); |
134 description.maxHeight = viewportLengthValue(CSSPropertyMaxHeight); | 162 description.maxHeight = viewportLengthValue(CSSPropertyMaxHeight); |
135 description.orientation = viewportArgumentValue(CSSPropertyOrientation); | 163 description.orientation = viewportArgumentValue(CSSPropertyOrientation); |
136 | 164 |
137 m_document->setViewportDescription(description); | 165 m_document->setViewportDescription(description); |
138 | |
139 m_propertySet = nullptr; | |
140 m_hasAuthorStyle = false; | |
141 } | 166 } |
142 | 167 |
143 float ViewportStyleResolver::viewportArgumentValue(CSSPropertyID id) const { | 168 float ViewportStyleResolver::viewportArgumentValue(CSSPropertyID id) const { |
144 float defaultValue = ViewportDescription::ValueAuto; | 169 float defaultValue = ViewportDescription::ValueAuto; |
145 | 170 |
146 // UserZoom default value is CSSValueZoom, which maps to true, meaning that | 171 // UserZoom default value is CSSValueZoom, which maps to true, meaning that |
147 // yes, it is user scalable. When the value is set to CSSValueFixed, we | 172 // yes, it is user scalable. When the value is set to CSSValueFixed, we |
148 // return false. | 173 // return false. |
149 if (id == CSSPropertyUserZoom) | 174 if (id == CSSPropertyUserZoom) |
150 defaultValue = 1; | 175 defaultValue = 1; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 default: | 216 default: |
192 NOTREACHED(); | 217 NOTREACHED(); |
193 break; | 218 break; |
194 } | 219 } |
195 } | 220 } |
196 | 221 |
197 NOTREACHED(); | 222 NOTREACHED(); |
198 return defaultValue; | 223 return defaultValue; |
199 } | 224 } |
200 | 225 |
201 Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const { | 226 Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) { |
202 ASSERT(id == CSSPropertyMaxHeight || id == CSSPropertyMinHeight || | 227 ASSERT(id == CSSPropertyMaxHeight || id == CSSPropertyMinHeight || |
203 id == CSSPropertyMaxWidth || id == CSSPropertyMinWidth); | 228 id == CSSPropertyMaxWidth || id == CSSPropertyMinWidth); |
204 | 229 |
205 const CSSValue* value = m_propertySet->getPropertyCSSValue(id); | 230 const CSSValue* value = m_propertySet->getPropertyCSSValue(id); |
206 if (!value || !(value->isPrimitiveValue() || value->isIdentifierValue())) | 231 if (!value || !(value->isPrimitiveValue() || value->isIdentifierValue())) |
207 return Length(); // auto | 232 return Length(); // auto |
208 | 233 |
209 if (value->isIdentifierValue()) { | 234 if (value->isIdentifierValue()) { |
210 CSSValueID valueID = toCSSIdentifierValue(value)->getValueID(); | 235 CSSValueID valueID = toCSSIdentifierValue(value)->getValueID(); |
211 if (valueID == CSSValueInternalExtendToZoom) | 236 if (valueID == CSSValueInternalExtendToZoom) |
(...skipping 10 matching lines...) Expand all Loading... |
222 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); | 247 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); |
223 documentStyle->setHasViewportUnits(false); | 248 documentStyle->setHasViewportUnits(false); |
224 | 249 |
225 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle); | 250 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle); |
226 CSSToLengthConversionData::ViewportSize viewportSize( | 251 CSSToLengthConversionData::ViewportSize viewportSize( |
227 m_document->layoutViewItem()); | 252 m_document->layoutViewItem()); |
228 | 253 |
229 Length result = primitiveValue->convertToLength( | 254 Length result = primitiveValue->convertToLength( |
230 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); | 255 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); |
231 if (documentStyle->hasViewportUnits()) | 256 if (documentStyle->hasViewportUnits()) |
232 m_document->setHasViewportUnits(); | 257 m_hasViewportUnits = true; |
233 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); | 258 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); |
234 | 259 |
235 return result; | 260 return result; |
236 } | 261 } |
237 | 262 |
| 263 bool ViewportStyleResolver::isAffectedByInitialViewportChange() { |
| 264 if (m_hasViewportUnits) |
| 265 return true; |
| 266 auto& results = m_viewportDependentMediaQueryResults; |
| 267 for (unsigned i = 0; i < results.size(); i++) { |
| 268 if (m_initialViewportMedium->eval(results[i]->expression()) != |
| 269 results[i]->result()) |
| 270 return true; |
| 271 } |
| 272 return false; |
| 273 } |
| 274 |
238 DEFINE_TRACE(ViewportStyleResolver) { | 275 DEFINE_TRACE(ViewportStyleResolver) { |
| 276 visitor->trace(m_document); |
239 visitor->trace(m_propertySet); | 277 visitor->trace(m_propertySet); |
240 visitor->trace(m_document); | 278 visitor->trace(m_initialViewportMedium); |
| 279 visitor->trace(m_viewportDependentMediaQueryResults); |
| 280 visitor->trace(m_deviceDependentMediaQueryResults); |
241 } | 281 } |
242 | 282 |
243 } // namespace blink | 283 } // namespace blink |
OLD | NEW |