OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv
ed. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv
ed. |
7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
9 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved. |
10 * | 10 * |
(...skipping 30 matching lines...) Expand all Loading... |
41 return value2; | 41 return value2; |
42 | 42 |
43 if (value2 == ViewportArguments::ValueAuto) | 43 if (value2 == ViewportArguments::ValueAuto) |
44 return value1; | 44 return value1; |
45 | 45 |
46 return compare(value1, value2); | 46 return compare(value1, value2); |
47 } | 47 } |
48 | 48 |
49 static inline float clampLengthValue(float value) | 49 static inline float clampLengthValue(float value) |
50 { | 50 { |
51 ASSERT(value != ViewportArguments::ValueDeviceWidth); | |
52 ASSERT(value != ViewportArguments::ValueDeviceHeight); | |
53 | |
54 // Limits as defined in the css-device-adapt spec. | 51 // Limits as defined in the css-device-adapt spec. |
55 if (value != ViewportArguments::ValueAuto) | 52 if (value != ViewportArguments::ValueAuto) |
56 return min(float(10000), max(value, float(1))); | 53 return min(float(10000), max(value, float(1))); |
57 return value; | 54 return value; |
58 } | 55 } |
59 | 56 |
60 static inline float clampScaleValue(float value) | 57 static inline float clampScaleValue(float value) |
61 { | 58 { |
62 ASSERT(value != ViewportArguments::ValueDeviceWidth); | |
63 ASSERT(value != ViewportArguments::ValueDeviceHeight); | |
64 | |
65 // Limits as defined in the css-device-adapt spec. | 59 // Limits as defined in the css-device-adapt spec. |
66 if (value != ViewportArguments::ValueAuto) | 60 if (value != ViewportArguments::ValueAuto) |
67 return min(float(10), max(value, float(0.1))); | 61 return min(float(10), max(value, float(0.1))); |
68 return value; | 62 return value; |
69 } | 63 } |
70 | 64 |
71 float ViewportArguments::resolveViewportLength(const Length& length, const Float
Size& initialViewportSize, Direction direction) | 65 float ViewportArguments::resolveViewportLength(const Length& length, const Float
Size& initialViewportSize, Direction direction) |
72 { | 66 { |
73 if (length.isAuto()) | 67 if (length.isAuto()) |
74 return ViewportArguments::ValueAuto; | 68 return ViewportArguments::ValueAuto; |
(...skipping 13 matching lines...) Expand all Loading... |
88 if (length.type() == ViewportPercentageMin) | 82 if (length.type() == ViewportPercentageMin) |
89 return min(initialViewportSize.width(), initialViewportSize.height()) *
length.viewportPercentageLength() / 100.0f; | 83 return min(initialViewportSize.width(), initialViewportSize.height()) *
length.viewportPercentageLength() / 100.0f; |
90 | 84 |
91 if (length.type() == ViewportPercentageMax) | 85 if (length.type() == ViewportPercentageMax) |
92 return max(initialViewportSize.width(), initialViewportSize.height()) *
length.viewportPercentageLength() / 100.0f; | 86 return max(initialViewportSize.width(), initialViewportSize.height()) *
length.viewportPercentageLength() / 100.0f; |
93 | 87 |
94 ASSERT_NOT_REACHED(); | 88 ASSERT_NOT_REACHED(); |
95 return ViewportArguments::ValueAuto; | 89 return ViewportArguments::ValueAuto; |
96 } | 90 } |
97 | 91 |
98 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport
Size, int defaultWidth) const | 92 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport
Size) const |
99 { | 93 { |
100 float resultWidth = width; | 94 float resultWidth = ValueAuto; |
101 float resultHeight = height; | 95 float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSize,
Horizontal); |
| 96 float resultMinWidth = resolveViewportLength(minWidth, initialViewportSize,
Horizontal); |
| 97 float resultHeight = ValueAuto; |
| 98 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize
, Vertical); |
| 99 float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize
, Vertical); |
| 100 |
102 float resultZoom = zoom; | 101 float resultZoom = zoom; |
103 float resultMinZoom = minZoom; | 102 float resultMinZoom = minZoom; |
104 float resultMaxZoom = maxZoom; | 103 float resultMaxZoom = maxZoom; |
105 float resultUserZoom = userZoom; | 104 float resultUserZoom = userZoom; |
106 | 105 |
107 if (type == ViewportArguments::CSSDeviceAdaptation) { | 106 // 1. Resolve min-zoom and max-zoom values. |
| 107 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Viewpo
rtArguments::ValueAuto) |
| 108 resultMaxZoom = max(resultMinZoom, resultMaxZoom); |
108 | 109 |
109 float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSi
ze, Horizontal); | 110 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. |
110 float resultMinWidth = resolveViewportLength(minWidth, initialViewportSi
ze, Horizontal); | 111 if (resultZoom != ViewportArguments::ValueAuto) |
111 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewport
Size, Vertical); | 112 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resu
ltMaxZoom, resultZoom, min), max); |
112 float resultMinHeight = resolveViewportLength(minHeight, initialViewport
Size, Vertical); | |
113 | 113 |
114 // 1. Resolve min-zoom and max-zoom values. | 114 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); |
115 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi
ewportArguments::ValueAuto) | |
116 resultMaxZoom = max(resultMinZoom, resultMaxZoom); | |
117 | 115 |
118 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. | 116 // 3. Resolve non-"auto" lengths to pixel lengths. |
119 if (resultZoom != ViewportArguments::ValueAuto) | 117 if (extendZoom == ViewportArguments::ValueAuto) { |
120 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(
resultMaxZoom, resultZoom, min), max); | 118 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom) |
| 119 resultMaxWidth = ViewportArguments::ValueAuto; |
121 | 120 |
122 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); | 121 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom) |
| 122 resultMaxHeight = ViewportArguments::ValueAuto; |
123 | 123 |
124 if (extendZoom == ViewportArguments::ValueAuto) { | 124 if (resultMinWidth == ViewportArguments::ValueExtendToZoom) |
125 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom) | 125 resultMinWidth = resultMaxWidth; |
126 resultMaxWidth = ViewportArguments::ValueAuto; | |
127 | 126 |
128 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom) | 127 if (resultMinHeight == ViewportArguments::ValueExtendToZoom) |
129 resultMaxHeight = ViewportArguments::ValueAuto; | 128 resultMinHeight = resultMaxHeight; |
| 129 } else { |
| 130 float extendWidth = initialViewportSize.width() / extendZoom; |
| 131 float extendHeight = initialViewportSize.height() / extendZoom; |
130 | 132 |
131 if (resultMinWidth == ViewportArguments::ValueExtendToZoom) | 133 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom) |
132 resultMinWidth = resultMaxWidth; | 134 resultMaxWidth = extendWidth; |
133 | 135 |
134 if (resultMinHeight == ViewportArguments::ValueExtendToZoom) | 136 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom) |
135 resultMinHeight = resultMaxHeight; | 137 resultMaxHeight = extendHeight; |
136 } else { | |
137 float extendWidth = initialViewportSize.width() / extendZoom; | |
138 float extendHeight = initialViewportSize.height() / extendZoom; | |
139 | 138 |
140 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom) | 139 if (resultMinWidth == ViewportArguments::ValueExtendToZoom) |
141 resultMaxWidth = extendWidth; | 140 resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, ma
x); |
142 | 141 |
143 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom) | 142 if (resultMinHeight == ViewportArguments::ValueExtendToZoom) |
144 resultMaxHeight = extendHeight; | 143 resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight,
max); |
145 | |
146 if (resultMinWidth == ViewportArguments::ValueExtendToZoom) | |
147 resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth
, max); | |
148 | |
149 if (resultMinHeight == ViewportArguments::ValueExtendToZoom) | |
150 resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHei
ght, max); | |
151 } | |
152 | |
153 // 4. Resolve initial width from min/max descriptors. | |
154 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth !=
ViewportArguments::ValueAuto) | |
155 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut
o(resultMaxWidth, initialViewportSize.width(), min), max); | |
156 | |
157 // 5. Resolve initial height from min/max descriptors. | |
158 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight !
= ViewportArguments::ValueAuto) | |
159 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA
uto(resultMaxHeight, initialViewportSize.height(), min), max); | |
160 | |
161 // 6-7. Resolve width value. | |
162 if (resultWidth == ViewportArguments::ValueAuto) { | |
163 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport
Size.height()) | |
164 resultWidth = initialViewportSize.width(); | |
165 else | |
166 resultWidth = resultHeight * (initialViewportSize.width() / init
ialViewportSize.height()); | |
167 } | |
168 | |
169 // 8. Resolve height value. | |
170 if (resultHeight == ViewportArguments::ValueAuto) { | |
171 if (!initialViewportSize.width()) | |
172 resultHeight = initialViewportSize.height(); | |
173 else | |
174 resultHeight = resultWidth * initialViewportSize.height() / init
ialViewportSize.width(); | |
175 } | |
176 | |
177 PageScaleConstraints result; | |
178 result.minimumScale = resultMinZoom; | |
179 result.maximumScale = resultMaxZoom; | |
180 result.initialScale = resultZoom; | |
181 result.layoutSize.setWidth(resultWidth); | |
182 result.layoutSize.setHeight(resultHeight); | |
183 return result; | |
184 } | 144 } |
185 | 145 |
186 switch (static_cast<int>(resultWidth)) { | 146 // 4. Resolve initial width from min/max descriptors. |
187 case ViewportArguments::ValueDeviceWidth: | 147 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != View
portArguments::ValueAuto) |
188 resultWidth = initialViewportSize.width(); | 148 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(re
sultMaxWidth, initialViewportSize.width(), min), max); |
189 break; | 149 |
190 case ViewportArguments::ValueDeviceHeight: | 150 // 5. Resolve initial height from min/max descriptors. |
191 resultWidth = initialViewportSize.height(); | 151 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight != Vi
ewportArguments::ValueAuto) |
192 break; | 152 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(
resultMaxHeight, initialViewportSize.height(), min), max); |
| 153 |
| 154 // 6-7. Resolve width value. |
| 155 if (resultWidth == ViewportArguments::ValueAuto) { |
| 156 if (resultHeight == ViewportArguments::ValueAuto || !initialViewportSize
.height()) |
| 157 resultWidth = initialViewportSize.width(); |
| 158 else |
| 159 resultWidth = resultHeight * (initialViewportSize.width() / initialV
iewportSize.height()); |
193 } | 160 } |
194 | 161 |
195 switch (static_cast<int>(resultHeight)) { | 162 // 8. Resolve height value. |
196 case ViewportArguments::ValueDeviceWidth: | 163 if (resultHeight == ViewportArguments::ValueAuto) { |
197 resultHeight = initialViewportSize.width(); | 164 if (!initialViewportSize.width()) |
198 break; | 165 resultHeight = initialViewportSize.height(); |
199 case ViewportArguments::ValueDeviceHeight: | 166 else |
200 resultHeight = initialViewportSize.height(); | 167 resultHeight = resultWidth * initialViewportSize.height() / initialV
iewportSize.width(); |
201 break; | |
202 } | 168 } |
203 | 169 |
204 if (type != ViewportArguments::Implicit) { | |
205 // Clamp values to a valid range, but not for @viewport since is | |
206 // not mandated by the specification. | |
207 resultWidth = clampLengthValue(resultWidth); | |
208 resultHeight = clampLengthValue(resultHeight); | |
209 resultZoom = clampScaleValue(resultZoom); | |
210 resultMinZoom = clampScaleValue(resultMinZoom); | |
211 resultMaxZoom = clampScaleValue(resultMaxZoom); | |
212 } | |
213 | |
214 PageScaleConstraints result; | |
215 | |
216 // Resolve minimum-scale and maximum-scale values according to spec. | |
217 if (resultMinZoom == ViewportArguments::ValueAuto) | |
218 result.minimumScale = float(0.25); | |
219 else | |
220 result.minimumScale = resultMinZoom; | |
221 | |
222 if (resultMaxZoom == ViewportArguments::ValueAuto) { | |
223 result.maximumScale = float(5.0); | |
224 result.minimumScale = min(float(5.0), result.minimumScale); | |
225 } else | |
226 result.maximumScale = resultMaxZoom; | |
227 result.maximumScale = max(result.minimumScale, result.maximumScale); | |
228 | |
229 // Resolve initial-scale value. | 170 // Resolve initial-scale value. |
230 result.initialScale = resultZoom; | |
231 if (resultZoom == ViewportArguments::ValueAuto) { | 171 if (resultZoom == ViewportArguments::ValueAuto) { |
232 result.initialScale = initialViewportSize.width() / defaultWidth; | |
233 if (resultWidth != ViewportArguments::ValueAuto && resultWidth > 0) | 172 if (resultWidth != ViewportArguments::ValueAuto && resultWidth > 0) |
234 result.initialScale = initialViewportSize.width() / resultWidth; | 173 resultZoom = initialViewportSize.width() / resultWidth; |
235 if (resultHeight != ViewportArguments::ValueAuto && resultHeight > 0) { | 174 if (resultHeight != ViewportArguments::ValueAuto && resultHeight > 0) { |
236 // if 'auto', the initial-scale will be negative here and thus ignor
ed. | 175 // if 'auto', the initial-scale will be negative here and thus ignor
ed. |
237 result.initialScale = max<float>(result.initialScale, initialViewpor
tSize.height() / resultHeight); | 176 resultZoom = max<float>(resultZoom, initialViewportSize.height() / r
esultHeight); |
238 } | 177 } |
239 } | 178 } |
240 | 179 |
241 // Constrain initial-scale value to minimum-scale/maximum-scale range. | |
242 result.initialScale = min(result.maximumScale, max(result.minimumScale, resu
lt.initialScale)); | |
243 | |
244 // Resolve width value. | |
245 if (resultWidth == ViewportArguments::ValueAuto) { | |
246 if (resultZoom == ViewportArguments::ValueAuto) | |
247 resultWidth = defaultWidth; | |
248 else if (resultHeight != ViewportArguments::ValueAuto) | |
249 resultWidth = resultHeight * (initialViewportSize.width() / initialV
iewportSize.height()); | |
250 else | |
251 resultWidth = initialViewportSize.width() / result.initialScale; | |
252 } | |
253 | |
254 // Resolve height value. | |
255 if (resultHeight == ViewportArguments::ValueAuto) | |
256 resultHeight = resultWidth * (initialViewportSize.height() / initialView
portSize.width()); | |
257 | |
258 if (type == ViewportArguments::ViewportMeta) { | |
259 // Extend width and height to fill the visual viewport for the resolved
initial-scale. | |
260 resultWidth = max<float>(resultWidth, initialViewportSize.width() / resu
lt.initialScale); | |
261 resultHeight = max<float>(resultHeight, initialViewportSize.height() / r
esult.initialScale); | |
262 } | |
263 | |
264 result.layoutSize.setWidth(resultWidth); | |
265 result.layoutSize.setHeight(resultHeight); | |
266 | |
267 // If user-scalable = no, lock the min/max scale to the computed initial | 180 // If user-scalable = no, lock the min/max scale to the computed initial |
268 // scale. | 181 // scale. |
269 if (!resultUserZoom) | 182 if (!resultUserZoom) |
270 result.maximumScale = result.minimumScale = result.initialScale; | 183 resultMinZoom = resultMaxZoom = resultZoom; |
271 | 184 |
272 // Only set initialScale to a value if it was explicitly set. | 185 // Only set initialScale to a value if it was explicitly set. |
273 if (resultZoom == ViewportArguments::ValueAuto) | 186 if (zoom == ViewportArguments::ValueAuto) |
274 result.initialScale = ViewportArguments::ValueAuto; | 187 resultZoom = ViewportArguments::ValueAuto; |
275 | 188 |
| 189 PageScaleConstraints result; |
| 190 result.minimumScale = resultMinZoom; |
| 191 result.maximumScale = resultMaxZoom; |
| 192 result.initialScale = resultZoom; |
| 193 result.layoutSize.setWidth(resultWidth); |
| 194 result.layoutSize.setHeight(resultHeight); |
276 return result; | 195 return result; |
277 } | 196 } |
278 | 197 |
279 static float numericPrefix(const String& keyString, const String& valueString, D
ocument* document, bool* ok = 0) | 198 static float numericPrefix(const String& keyString, const String& valueString, D
ocument* document, bool* ok = 0) |
280 { | 199 { |
281 size_t parsedLength; | 200 size_t parsedLength; |
282 float value; | 201 float value; |
283 if (valueString.is8Bit()) | 202 if (valueString.is8Bit()) |
284 value = charactersToFloat(valueString.characters8(), valueString.length(
), parsedLength); | 203 value = charactersToFloat(valueString.characters8(), valueString.length(
), parsedLength); |
285 else | 204 else |
286 value = charactersToFloat(valueString.characters16(), valueString.length
(), parsedLength); | 205 value = charactersToFloat(valueString.characters16(), valueString.length
(), parsedLength); |
287 if (!parsedLength) { | 206 if (!parsedLength) { |
288 reportViewportWarning(document, UnrecognizedViewportArgumentValueError,
valueString, keyString); | 207 reportViewportWarning(document, UnrecognizedViewportArgumentValueError,
valueString, keyString); |
289 if (ok) | 208 if (ok) |
290 *ok = false; | 209 *ok = false; |
291 return 0; | 210 return 0; |
292 } | 211 } |
293 if (parsedLength < valueString.length()) | 212 if (parsedLength < valueString.length()) |
294 reportViewportWarning(document, TruncatedViewportArgumentValueError, val
ueString, keyString); | 213 reportViewportWarning(document, TruncatedViewportArgumentValueError, val
ueString, keyString); |
295 if (ok) | 214 if (ok) |
296 *ok = true; | 215 *ok = true; |
297 return value; | 216 return value; |
298 } | 217 } |
299 | 218 |
300 static float findSizeValue(const String& keyString, const String& valueString, D
ocument* document) | 219 static Length findSizeValue(const String& keyString, const String& valueString,
Document* document) |
301 { | 220 { |
302 // 1) Non-negative number values are translated to px lengths. | 221 // 1) Non-negative number values are translated to px lengths. |
303 // 2) Negative number values are translated to auto. | 222 // 2) Negative number values are translated to auto. |
304 // 3) device-width and device-height are used as keywords. | 223 // 3) device-width and device-height are used as keywords. |
305 // 4) Other keywords and unknown values translate to 0.0. | 224 // 4) Other keywords and unknown values translate to 0.0. |
306 | 225 |
307 if (equalIgnoringCase(valueString, "device-width")) | 226 if (equalIgnoringCase(valueString, "device-width")) |
308 return ViewportArguments::ValueDeviceWidth; | 227 return Length(100, ViewportPercentageWidth); |
309 if (equalIgnoringCase(valueString, "device-height")) | 228 if (equalIgnoringCase(valueString, "device-height")) |
310 return ViewportArguments::ValueDeviceHeight; | 229 return Length(100, ViewportPercentageHeight); |
311 | 230 |
312 float value = numericPrefix(keyString, valueString, document); | 231 float value = numericPrefix(keyString, valueString, document); |
313 | 232 |
314 if (value < 0) | 233 if (value < 0) |
315 return ViewportArguments::ValueAuto; | 234 return Length(); // auto |
316 | 235 |
317 return value; | 236 return Length(clampLengthValue(value), Fixed); |
318 } | 237 } |
319 | 238 |
320 static float findScaleValue(const String& keyString, const String& valueString,
Document* document) | 239 static float findScaleValue(const String& keyString, const String& valueString,
Document* document) |
321 { | 240 { |
322 // 1) Non-negative number values are translated to <number> values. | 241 // 1) Non-negative number values are translated to <number> values. |
323 // 2) Negative number values are translated to auto. | 242 // 2) Negative number values are translated to auto. |
324 // 3) yes is translated to 1.0. | 243 // 3) yes is translated to 1.0. |
325 // 4) device-width and device-height are translated to 10.0. | 244 // 4) device-width and device-height are translated to 10.0. |
326 // 5) no and unknown values are translated to 0.0 | 245 // 5) no and unknown values are translated to 0.0 |
327 | 246 |
328 if (equalIgnoringCase(valueString, "yes")) | 247 if (equalIgnoringCase(valueString, "yes")) |
329 return 1; | 248 return 1; |
330 if (equalIgnoringCase(valueString, "no")) | 249 if (equalIgnoringCase(valueString, "no")) |
331 return 0; | 250 return 0; |
332 if (equalIgnoringCase(valueString, "device-width")) | 251 if (equalIgnoringCase(valueString, "device-width")) |
333 return 10; | 252 return 10; |
334 if (equalIgnoringCase(valueString, "device-height")) | 253 if (equalIgnoringCase(valueString, "device-height")) |
335 return 10; | 254 return 10; |
336 | 255 |
337 float value = numericPrefix(keyString, valueString, document); | 256 float value = numericPrefix(keyString, valueString, document); |
338 | 257 |
339 if (value < 0) | 258 if (value < 0) |
340 return ViewportArguments::ValueAuto; | 259 return ViewportArguments::ValueAuto; |
341 | 260 |
342 if (value > 10.0) | 261 if (value > 10.0) |
343 reportViewportWarning(document, MaximumScaleTooLargeError, String(), Str
ing()); | 262 reportViewportWarning(document, MaximumScaleTooLargeError, String(), Str
ing()); |
344 | 263 |
345 return value; | 264 return clampScaleValue(value); |
346 } | 265 } |
347 | 266 |
348 static float findUserScalableValue(const String& keyString, const String& valueS
tring, Document* document) | 267 static float findUserScalableValue(const String& keyString, const String& valueS
tring, Document* document) |
349 { | 268 { |
350 // yes and no are used as keywords. | 269 // yes and no are used as keywords. |
351 // Numbers >= 1, numbers <= -1, device-width and device-height are mapped to
yes. | 270 // Numbers >= 1, numbers <= -1, device-width and device-height are mapped to
yes. |
352 // Numbers in the range <-1, 1>, and unknown values, are mapped to no. | 271 // Numbers in the range <-1, 1>, and unknown values, are mapped to no. |
353 | 272 |
354 if (equalIgnoringCase(valueString, "yes")) | 273 if (equalIgnoringCase(valueString, "yes")) |
355 return 1; | 274 return 1; |
(...skipping 28 matching lines...) Expand all Loading... |
384 if (!ok || value < 70 || value > 400) | 303 if (!ok || value < 70 || value > 400) |
385 return ViewportArguments::ValueAuto; | 304 return ViewportArguments::ValueAuto; |
386 | 305 |
387 return value; | 306 return value; |
388 } | 307 } |
389 | 308 |
390 void setViewportFeature(const String& keyString, const String& valueString, Docu
ment* document, void* data) | 309 void setViewportFeature(const String& keyString, const String& valueString, Docu
ment* document, void* data) |
391 { | 310 { |
392 ViewportArguments* arguments = static_cast<ViewportArguments*>(data); | 311 ViewportArguments* arguments = static_cast<ViewportArguments*>(data); |
393 | 312 |
394 if (keyString == "width") | 313 if (keyString == "width") { |
395 arguments->width = findSizeValue(keyString, valueString, document); | 314 const Length& width = findSizeValue(keyString, valueString, document); |
396 else if (keyString == "height") | 315 if (!width.isAuto()) { |
397 arguments->height = findSizeValue(keyString, valueString, document); | 316 arguments->minWidth = Length(ExtendToZoom); |
398 else if (keyString == "initial-scale") | 317 arguments->maxWidth = width; |
| 318 } |
| 319 } else if (keyString == "height") { |
| 320 const Length& height = findSizeValue(keyString, valueString, document); |
| 321 if (!height.isAuto()) { |
| 322 arguments->minHeight = Length(ExtendToZoom); |
| 323 arguments->maxHeight = height; |
| 324 } |
| 325 } else if (keyString == "initial-scale") { |
399 arguments->zoom = findScaleValue(keyString, valueString, document); | 326 arguments->zoom = findScaleValue(keyString, valueString, document); |
400 else if (keyString == "minimum-scale") | 327 } else if (keyString == "minimum-scale") { |
401 arguments->minZoom = findScaleValue(keyString, valueString, document); | 328 arguments->minZoom = findScaleValue(keyString, valueString, document); |
402 else if (keyString == "maximum-scale") | 329 } else if (keyString == "maximum-scale") { |
403 arguments->maxZoom = findScaleValue(keyString, valueString, document); | 330 arguments->maxZoom = findScaleValue(keyString, valueString, document); |
404 else if (keyString == "user-scalable") | 331 } else if (keyString == "user-scalable") { |
405 arguments->userZoom = findUserScalableValue(keyString, valueString, docu
ment); | 332 arguments->userZoom = findUserScalableValue(keyString, valueString, docu
ment); |
406 else if (keyString == "target-densitydpi") { | 333 } else if (keyString == "target-densitydpi") { |
407 arguments->deprecatedTargetDensityDPI = findTargetDensityDPIValue(keyStr
ing, valueString, document); | 334 arguments->deprecatedTargetDensityDPI = findTargetDensityDPIValue(keyStr
ing, valueString, document); |
408 reportViewportWarning(document, TargetDensityDpiUnsupported, String(), S
tring()); | 335 reportViewportWarning(document, TargetDensityDpiUnsupported, String(), S
tring()); |
409 } else | 336 } else { |
410 reportViewportWarning(document, UnrecognizedViewportArgumentKeyError, ke
yString, String()); | 337 reportViewportWarning(document, UnrecognizedViewportArgumentKeyError, ke
yString, String()); |
| 338 } |
411 } | 339 } |
412 | 340 |
413 static const char* viewportErrorMessageTemplate(ViewportErrorCode errorCode) | 341 static const char* viewportErrorMessageTemplate(ViewportErrorCode errorCode) |
414 { | 342 { |
415 static const char* const errors[] = { | 343 static const char* const errors[] = { |
416 "Note that ';' is not a key-value pair separator. The list should be com
ma-separated.", | 344 "Note that ';' is not a key-value pair separator. The list should be com
ma-separated.", |
417 "The key \"%replacement1\" is not recognized and ignored.", | 345 "The key \"%replacement1\" is not recognized and ignored.", |
418 "The value \"%replacement1\" for key \"%replacement2\" is invalid, and h
as been ignored.", | 346 "The value \"%replacement1\" for key \"%replacement2\" is invalid, and h
as been ignored.", |
419 "The value \"%replacement1\" for key \"%replacement2\" was truncated to
its numeric prefix.", | 347 "The value \"%replacement1\" for key \"%replacement2\" was truncated to
its numeric prefix.", |
420 "The value for key \"maximum-scale\" is out of bounds and the value has
been clamped.", | 348 "The value for key \"maximum-scale\" is out of bounds and the value has
been clamped.", |
(...skipping 30 matching lines...) Expand all Loading... |
451 if (!replacement1.isNull()) | 379 if (!replacement1.isNull()) |
452 message.replace("%replacement1", replacement1); | 380 message.replace("%replacement1", replacement1); |
453 if (!replacement2.isNull()) | 381 if (!replacement2.isNull()) |
454 message.replace("%replacement2", replacement2); | 382 message.replace("%replacement2", replacement2); |
455 | 383 |
456 // FIXME: This message should be moved off the console once a solution to ht
tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 384 // FIXME: This message should be moved off the console once a solution to ht
tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
457 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve
l(errorCode), message); | 385 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve
l(errorCode), message); |
458 } | 386 } |
459 | 387 |
460 } // namespace WebCore | 388 } // namespace WebCore |
OLD | NEW |