| 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 21 matching lines...) Expand all Loading... |
| 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/CSSStyleSheet.h" |
| 36 #include "core/css/CSSToLengthConversionData.h" | 36 #include "core/css/CSSToLengthConversionData.h" |
| 37 #include "core/css/MediaValuesInitialViewport.h" | 37 #include "core/css/MediaValuesInitialViewport.h" |
| 38 #include "core/css/StylePropertySet.h" | 38 #include "core/css/StylePropertySet.h" |
| 39 #include "core/css/StyleRule.h" | 39 #include "core/css/StyleRule.h" |
| 40 #include "core/css/StyleRuleImport.h" | 40 #include "core/css/StyleRuleImport.h" |
| 41 #include "core/css/StyleSheetContents.h" | 41 #include "core/css/StyleSheetContents.h" |
| 42 #include "core/css/resolver/ScopedStyleResolver.h" | |
| 43 #include "core/dom/Document.h" | 42 #include "core/dom/Document.h" |
| 44 #include "core/dom/DocumentStyleSheetCollection.h" | 43 #include "core/dom/DocumentStyleSheetCollection.h" |
| 45 #include "core/dom/NodeComputedStyle.h" | 44 #include "core/dom/NodeComputedStyle.h" |
| 46 #include "core/dom/ViewportDescription.h" | 45 #include "core/dom/ViewportDescription.h" |
| 46 #include "core/frame/FrameView.h" |
| 47 #include "core/frame/LocalFrame.h" |
| 47 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
| 48 #include "core/layout/api/LayoutViewItem.h" | 49 #include "core/layout/api/LayoutViewItem.h" |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 52 ViewportStyleResolver::ViewportStyleResolver(Document& document) | 53 ViewportStyleResolver::ViewportStyleResolver(Document& document) |
| 53 : m_document(document) { | 54 : m_document(document) { |
| 54 DCHECK(document.frame()); | 55 DCHECK(document.frame()); |
| 55 m_initialViewportMedium = new MediaQueryEvaluator( | 56 m_initialViewportMedium = new MediaQueryEvaluator( |
| 56 MediaValuesInitialViewport::create(*document.frame())); | 57 MediaValuesInitialViewport::create(*document.frame())); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 collectViewportChildRules(viewportContents->childRules(), UserAgentOrigin); | 87 collectViewportChildRules(viewportContents->childRules(), UserAgentOrigin); |
| 87 | 88 |
| 88 if (m_document->isMobileDocument()) { | 89 if (m_document->isMobileDocument()) { |
| 89 collectViewportChildRules( | 90 collectViewportChildRules( |
| 90 defaultStyleSheets.ensureXHTMLMobileProfileStyleSheet()->childRules(), | 91 defaultStyleSheets.ensureXHTMLMobileProfileStyleSheet()->childRules(), |
| 91 UserAgentOrigin); | 92 UserAgentOrigin); |
| 92 } | 93 } |
| 93 DCHECK(!defaultStyleSheets.defaultStyleSheet()->hasViewportRule()); | 94 DCHECK(!defaultStyleSheets.defaultStyleSheet()->hasViewportRule()); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void ViewportStyleResolver::collectViewportRules() { | |
| 97 reset(); | |
| 98 collectViewportRulesFromUASheets(); | |
| 99 if (ScopedStyleResolver* scopedResolver = m_document->scopedStyleResolver()) | |
| 100 scopedResolver->collectViewportRulesTo(this); | |
| 101 | |
| 102 resolve(); | |
| 103 } | |
| 104 | |
| 105 void ViewportStyleResolver::collectViewportChildRules( | 97 void ViewportStyleResolver::collectViewportChildRules( |
| 106 const HeapVector<Member<StyleRuleBase>>& rules, | 98 const HeapVector<Member<StyleRuleBase>>& rules, |
| 107 Origin origin) { | 99 Origin origin) { |
| 108 for (auto& rule : rules) { | 100 for (auto& rule : rules) { |
| 109 if (rule->isViewportRule()) { | 101 if (rule->isViewportRule()) { |
| 110 addViewportRule(*toStyleRuleViewport(rule), origin); | 102 addViewportRule(*toStyleRuleViewport(rule), origin); |
| 111 } else if (rule->isMediaRule()) { | 103 } else if (rule->isMediaRule()) { |
| 112 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); | 104 StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); |
| 113 if (!mediaRule->mediaQueries() || | 105 if (!mediaRule->mediaQueries() || |
| 114 m_initialViewportMedium->eval(mediaRule->mediaQueries(), | 106 m_initialViewportMedium->eval(mediaRule->mediaQueries(), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (!contents.hasViewportRule() && contents.importRules().isEmpty()) | 144 if (!contents.hasViewportRule() && contents.importRules().isEmpty()) |
| 153 return; | 145 return; |
| 154 if (sheet.mediaQueries() && | 146 if (sheet.mediaQueries() && |
| 155 !m_initialViewportMedium->eval(sheet.mediaQueries(), | 147 !m_initialViewportMedium->eval(sheet.mediaQueries(), |
| 156 &m_viewportDependentMediaQueryResults, | 148 &m_viewportDependentMediaQueryResults, |
| 157 &m_deviceDependentMediaQueryResults)) | 149 &m_deviceDependentMediaQueryResults)) |
| 158 return; | 150 return; |
| 159 collectViewportRulesFromAuthorSheetContents(contents); | 151 collectViewportRulesFromAuthorSheetContents(contents); |
| 160 } | 152 } |
| 161 | 153 |
| 162 void ViewportStyleResolver::collectViewportRules(RuleSet* rules, | |
| 163 Origin origin) { | |
| 164 rules->compactRulesIfNeeded(); | |
| 165 | |
| 166 const HeapVector<Member<StyleRuleViewport>>& viewportRules = | |
| 167 rules->viewportRules(); | |
| 168 for (size_t i = 0; i < viewportRules.size(); ++i) | |
| 169 addViewportRule(*viewportRules[i], origin); | |
| 170 } | |
| 171 | |
| 172 void ViewportStyleResolver::addViewportRule(StyleRuleViewport& viewportRule, | 154 void ViewportStyleResolver::addViewportRule(StyleRuleViewport& viewportRule, |
| 173 Origin origin) { | 155 Origin origin) { |
| 174 StylePropertySet& propertySet = viewportRule.mutableProperties(); | 156 StylePropertySet& propertySet = viewportRule.mutableProperties(); |
| 175 | 157 |
| 176 unsigned propertyCount = propertySet.propertyCount(); | 158 unsigned propertyCount = propertySet.propertyCount(); |
| 177 if (!propertyCount) | 159 if (!propertyCount) |
| 178 return; | 160 return; |
| 179 | 161 |
| 180 if (origin == AuthorOrigin) | 162 if (origin == AuthorOrigin) |
| 181 m_hasAuthorStyle = true; | 163 m_hasAuthorStyle = true; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 273 } |
| 292 | 274 |
| 293 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 275 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
| 294 ComputedStyle* documentStyle = m_document->mutableComputedStyle(); | 276 ComputedStyle* documentStyle = m_document->mutableComputedStyle(); |
| 295 | 277 |
| 296 // If we have viewport units the conversion will mark the document style as | 278 // If we have viewport units the conversion will mark the document style as |
| 297 // having viewport units. | 279 // having viewport units. |
| 298 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); | 280 bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); |
| 299 documentStyle->setHasViewportUnits(false); | 281 documentStyle->setHasViewportUnits(false); |
| 300 | 282 |
| 283 FrameView* view = m_document->frame()->view(); |
| 284 DCHECK(view); |
| 285 |
| 301 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle); | 286 CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle); |
| 302 CSSToLengthConversionData::ViewportSize viewportSize( | 287 CSSToLengthConversionData::ViewportSize viewportSize( |
| 303 m_document->layoutViewItem()); | 288 view->initialViewportWidth(), view->initialViewportHeight()); |
| 304 | 289 |
| 305 Length result = primitiveValue->convertToLength( | 290 Length result = primitiveValue->convertToLength( |
| 306 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); | 291 CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); |
| 307 if (documentStyle->hasViewportUnits()) { | 292 if (documentStyle->hasViewportUnits()) |
| 308 // TODO (rune@opera.com): remove the setHasViewportUnit when | |
| 309 // initialViewportChanged() goes live. | |
| 310 m_document->setHasViewportUnits(); | |
| 311 m_hasViewportUnits = true; | 293 m_hasViewportUnits = true; |
| 312 } | |
| 313 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); | 294 documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); |
| 314 | 295 |
| 315 return result; | 296 return result; |
| 316 } | 297 } |
| 317 | 298 |
| 318 void ViewportStyleResolver::initialViewportChanged() { | 299 void ViewportStyleResolver::initialViewportChanged() { |
| 319 if (m_needsUpdate == CollectRules) | 300 if (m_needsUpdate == CollectRules) |
| 320 return; | 301 return; |
| 321 | 302 |
| 322 auto& results = m_viewportDependentMediaQueryResults; | 303 auto& results = m_viewportDependentMediaQueryResults; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 351 | 332 |
| 352 DEFINE_TRACE(ViewportStyleResolver) { | 333 DEFINE_TRACE(ViewportStyleResolver) { |
| 353 visitor->trace(m_document); | 334 visitor->trace(m_document); |
| 354 visitor->trace(m_propertySet); | 335 visitor->trace(m_propertySet); |
| 355 visitor->trace(m_initialViewportMedium); | 336 visitor->trace(m_initialViewportMedium); |
| 356 visitor->trace(m_viewportDependentMediaQueryResults); | 337 visitor->trace(m_viewportDependentMediaQueryResults); |
| 357 visitor->trace(m_deviceDependentMediaQueryResults); | 338 visitor->trace(m_deviceDependentMediaQueryResults); |
| 358 } | 339 } |
| 359 | 340 |
| 360 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |