OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 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. |
11 * 2. Redistributions in binary form must reproduce the above | 11 * 2. Redistributions in binary form must reproduce the above |
12 * copyright notice, this list of conditions and the following | 12 * copyright notice, this list of conditions and the following |
(...skipping 16 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "config.h" | 30 #include "config.h" |
31 #include "core/css/resolver/ViewportStyleResolver.h" | 31 #include "core/css/resolver/ViewportStyleResolver.h" |
32 | 32 |
33 #include "CSSValueKeywords.h" | 33 #include "CSSValueKeywords.h" |
34 #include "core/css/StylePropertySet.h" | 34 #include "core/css/StylePropertySet.h" |
35 #include "core/css/StyleRule.h" | 35 #include "core/css/StyleRule.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/dom/NodeRenderStyle.h" | 37 #include "core/dom/NodeRenderStyle.h" |
38 #include "core/dom/ViewportArguments.h" | 38 #include "core/dom/ViewportArguments.h" |
| 39 #include "wtf/dtoa/utils.h" |
39 | 40 |
40 namespace WebCore { | 41 namespace WebCore { |
41 | 42 |
42 ViewportStyleResolver::ViewportStyleResolver(Document* document) | 43 ViewportStyleResolver::ViewportStyleResolver(Document* document) |
43 : m_document(document) | 44 : m_document(document) |
| 45 , m_maxPriority(0) |
44 { | 46 { |
45 ASSERT(m_document); | 47 ASSERT(m_document); |
46 } | 48 } |
47 | 49 |
48 ViewportStyleResolver::~ViewportStyleResolver() | 50 ViewportStyleResolver::~ViewportStyleResolver() |
49 { | 51 { |
50 } | 52 } |
51 | 53 |
52 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule) | 54 void ViewportStyleResolver::addViewportRule(StyleRuleViewport* viewportRule) |
53 { | 55 { |
54 StylePropertySet* propertySet = viewportRule->mutableProperties(); | 56 StylePropertySet* propertySet = viewportRule->mutableProperties(); |
55 | 57 |
56 unsigned propertyCount = propertySet->propertyCount(); | 58 unsigned propertyCount = propertySet->propertyCount(); |
57 if (!propertyCount) | 59 if (!propertyCount) |
58 return; | 60 return; |
59 | 61 |
60 if (!m_propertySet) { | 62 // Rules derived from legacy meta tags are only applied if no author @viewpo
rt rule |
| 63 // precedes it, with the exception of viewport meta which is considered an a
ctual |
| 64 // @viewport rule according to the spec. They also have individual priority
as defined |
| 65 // below. |
| 66 // |
| 67 // 1) UA stylesheet is always applied first (min priority) |
| 68 // 2) XHTML Mobile Profile (priority 1) |
| 69 // 3) handheldfriendly meta tag (priority 2) |
| 70 // 4) mobileoptimized meta tag (priority 3) |
| 71 // 5) viewport meta tag and any author style sheet (max priority). |
| 72 |
| 73 RefPtr<CSSValue> value = propertySet->getPropertyCSSValue(CSSPropertyInterna
lPriority); |
| 74 float priority = (value && value->isPrimitiveValue()) ? toCSSPrimitiveValue(
value.get())->getFloatValue() : std::numeric_limits<float>::max(); |
| 75 |
| 76 if (priority < m_maxPriority) |
| 77 return; |
| 78 m_maxPriority = priority; |
| 79 |
| 80 if (m_propertySet) { |
| 81 // We cannot use mergeAndOverrideOnConflict() here because it doesn't |
| 82 // respect the !important declaration (but addParsedProperty() does). |
| 83 for (unsigned i = 0; i < propertyCount; ++i) |
| 84 m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSPro
perty()); |
| 85 } else { |
61 m_propertySet = propertySet->mutableCopy(); | 86 m_propertySet = propertySet->mutableCopy(); |
62 return; | |
63 } | 87 } |
| 88 } |
64 | 89 |
65 // We cannot use mergeAndOverrideOnConflict() here because it doesn't | 90 bool ViewportStyleResolver::shouldDisableDesktopWorkarounds() const |
66 // respect the !important declaration (but addParsedProperty() does). | 91 { |
67 for (unsigned i = 0; i < propertyCount; ++i) | 92 if (!m_propertySet) |
68 m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSPropert
y()); | 93 return false; |
| 94 |
| 95 RefPtr<CSSValue> value; |
| 96 |
| 97 // Check is zoomable. |
| 98 if (!getViewportArgumentValue(CSSPropertyUserZoom)) |
| 99 return true; |
| 100 |
| 101 float minZoom = getViewportArgumentValue(CSSPropertyMinZoom); |
| 102 float maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); |
| 103 if (minZoom == maxZoom && minZoom == ViewportArguments::ValueAuto) |
| 104 return true; |
| 105 |
| 106 // Check whether 100% of viewport (device-width etc.) |
| 107 value = m_propertySet->getPropertyCSSValue(CSSPropertyMaxWidth); |
| 108 if (!value || !value->isPrimitiveValue()) |
| 109 return false; |
| 110 |
| 111 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); |
| 112 return primitiveValue->isPercentage() && primitiveValue->getFloatValue() ==
100.0f; |
69 } | 113 } |
70 | 114 |
71 void ViewportStyleResolver::clearDocument() | 115 void ViewportStyleResolver::clearDocument() |
72 { | 116 { |
73 m_document = 0; | 117 m_document = 0; |
74 } | 118 } |
75 | 119 |
76 void ViewportStyleResolver::resolve() | 120 void ViewportStyleResolver::resolve() |
77 { | 121 { |
78 if (!m_document || !m_propertySet) | 122 if (!m_document || !m_propertySet) |
79 return; | 123 return; |
80 | 124 |
81 ViewportArguments arguments(ViewportArguments::CSSDeviceAdaptation); | 125 ViewportArguments arguments; |
82 | 126 |
83 arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom); | 127 arguments.userZoom = getViewportArgumentValue(CSSPropertyUserZoom); |
84 arguments.zoom = getViewportArgumentValue(CSSPropertyZoom); | 128 arguments.zoom = getViewportArgumentValue(CSSPropertyZoom); |
85 arguments.minZoom = getViewportArgumentValue(CSSPropertyMinZoom); | 129 arguments.minZoom = getViewportArgumentValue(CSSPropertyMinZoom); |
86 arguments.maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); | 130 arguments.maxZoom = getViewportArgumentValue(CSSPropertyMaxZoom); |
87 arguments.minWidth = getViewportArgumentValue(CSSPropertyMinWidth); | 131 arguments.minWidth = getViewportArgumentValue(CSSPropertyMinWidth); |
88 arguments.maxWidth = getViewportArgumentValue(CSSPropertyMaxWidth); | 132 arguments.maxWidth = getViewportArgumentValue(CSSPropertyMaxWidth); |
89 arguments.minHeight = getViewportArgumentValue(CSSPropertyMinHeight); | 133 arguments.minHeight = getViewportArgumentValue(CSSPropertyMinHeight); |
90 arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight); | 134 arguments.maxHeight = getViewportArgumentValue(CSSPropertyMaxHeight); |
91 arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation); | 135 arguments.orientation = getViewportArgumentValue(CSSPropertyOrientation); |
92 | 136 |
| 137 // Deprecated values: |
| 138 arguments.deprecatedTargetDensityDPI = getViewportArgumentValue(CSSPropertyI
nternalTargetDensity); |
| 139 |
93 m_document->setViewportArguments(arguments); | 140 m_document->setViewportArguments(arguments); |
94 m_document->updateViewportArguments(); | 141 m_document->updateViewportArguments(); |
| 142 } |
95 | 143 |
96 m_propertySet = 0; | 144 bool ViewportStyleResolver::affectedByViewportChange() const |
| 145 { |
| 146 if (!m_propertySet) |
| 147 return false; |
| 148 |
| 149 CSSPropertyID ids[] = { CSSPropertyMaxHeight, CSSPropertyMinHeight, CSSPrope
rtyMaxWidth, CSSPropertyMinWidth }; |
| 150 |
| 151 for (size_t i = 0; i < ARRAY_SIZE(ids); ++i) { |
| 152 RefPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(ids[i]); |
| 153 if (!value || !value->isPrimitiveValue()) |
| 154 continue; |
| 155 CSSPrimitiveValue* primValue = toCSSPrimitiveValue(value.get()); |
| 156 if (primValue->isPercentage()) |
| 157 return true; |
| 158 } |
| 159 |
| 160 return false; |
97 } | 161 } |
98 | 162 |
99 float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const | 163 float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const |
100 { | 164 { |
101 float defaultValue = ViewportArguments::ValueAuto; | 165 float defaultValue = ViewportArguments::ValueAuto; |
102 | 166 |
103 // UserZoom default value is CSSValueZoom, which maps to true, meaning that | 167 // UserZoom default value is CSSValueZoom, which maps to true, meaning that |
104 // yes, it is user scalable. When the value is set to CSSValueFixed, we | 168 // yes, it is user scalable. When the value is set to CSSValueFixed, we |
105 // return false. | 169 // return false. |
106 if (id == CSSPropertyUserZoom) | 170 if (id == CSSPropertyUserZoom) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 203 |
140 switch (primitiveValue->getValueID()) { | 204 switch (primitiveValue->getValueID()) { |
141 case CSSValueAuto: | 205 case CSSValueAuto: |
142 return defaultValue; | 206 return defaultValue; |
143 case CSSValueLandscape: | 207 case CSSValueLandscape: |
144 return ViewportArguments::ValueLandscape; | 208 return ViewportArguments::ValueLandscape; |
145 case CSSValuePortrait: | 209 case CSSValuePortrait: |
146 return ViewportArguments::ValuePortrait; | 210 return ViewportArguments::ValuePortrait; |
147 case CSSValueZoom: | 211 case CSSValueZoom: |
148 return defaultValue; | 212 return defaultValue; |
| 213 case CSSValueExtendToZoom: |
| 214 return ViewportArguments::ValueExtendToZoom; |
| 215 case CSSValueDevice: |
| 216 return ViewportArguments::ValueDeviceDPI; |
| 217 case CSSValueSmall: |
| 218 return ViewportArguments::ValueLowDPI; |
| 219 case CSSValueMedium: |
| 220 return ViewportArguments::ValueMediumDPI; |
| 221 case CSSValueLarge: |
| 222 return ViewportArguments::ValueHighDPI; |
149 case CSSValueFixed: | 223 case CSSValueFixed: |
150 return 0; | 224 return 0; |
151 default: | 225 default: |
152 return defaultValue; | 226 return defaultValue; |
153 } | 227 } |
154 } | 228 } |
155 | 229 |
156 } // namespace WebCore | 230 } // namespace WebCore |
OLD | NEW |