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 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
10 * | 10 * |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "core/page/DOMWindow.h" | 35 #include "core/page/DOMWindow.h" |
36 #include "core/page/Frame.h" | 36 #include "core/page/Frame.h" |
37 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
38 #include "core/platform/graphics/IntSize.h" | 38 #include "core/platform/graphics/IntSize.h" |
39 #include <wtf/text/WTFString.h> | 39 #include <wtf/text/WTFString.h> |
40 | 40 |
41 using namespace std; | 41 using namespace std; |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 const float ViewportArguments::deprecatedTargetDPI = 160; | |
46 | |
47 static const float& compareIgnoringAuto(const float& value1, const float& value2
, const float& (*compare) (const float&, const float&)) | 45 static const float& compareIgnoringAuto(const float& value1, const float& value2
, const float& (*compare) (const float&, const float&)) |
48 { | 46 { |
49 ASSERT(value1 != ViewportArguments::ValueAuto || value2 != ViewportArguments
::ValueAuto); | 47 ASSERT(value1 != ViewportArguments::ValueAuto || value2 != ViewportArguments
::ValueAuto); |
50 | 48 |
51 if (value1 == ViewportArguments::ValueAuto) | 49 if (value1 == ViewportArguments::ValueAuto) |
52 return value2; | 50 return value2; |
53 | 51 |
54 if (value2 == ViewportArguments::ValueAuto) | 52 if (value2 == ViewportArguments::ValueAuto) |
55 return value1; | 53 return value1; |
56 | 54 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Clamp values to a valid range, but not for @viewport since is | 182 // Clamp values to a valid range, but not for @viewport since is |
185 // not mandated by the specification. | 183 // not mandated by the specification. |
186 resultWidth = clampLengthValue(resultWidth); | 184 resultWidth = clampLengthValue(resultWidth); |
187 resultHeight = clampLengthValue(resultHeight); | 185 resultHeight = clampLengthValue(resultHeight); |
188 resultZoom = clampScaleValue(resultZoom); | 186 resultZoom = clampScaleValue(resultZoom); |
189 resultMinZoom = clampScaleValue(resultMinZoom); | 187 resultMinZoom = clampScaleValue(resultMinZoom); |
190 resultMaxZoom = clampScaleValue(resultMaxZoom); | 188 resultMaxZoom = clampScaleValue(resultMaxZoom); |
191 } | 189 } |
192 | 190 |
193 ViewportAttributes result; | 191 ViewportAttributes result; |
194 result.orientation = orientation; | |
195 | 192 |
196 // Resolve minimum-scale and maximum-scale values according to spec. | 193 // Resolve minimum-scale and maximum-scale values according to spec. |
197 if (resultMinZoom == ViewportArguments::ValueAuto) | 194 if (resultMinZoom == ViewportArguments::ValueAuto) |
198 result.minimumScale = float(0.25); | 195 result.minimumScale = float(0.25); |
199 else | 196 else |
200 result.minimumScale = resultMinZoom; | 197 result.minimumScale = resultMinZoom; |
201 | 198 |
202 if (resultMaxZoom == ViewportArguments::ValueAuto) { | 199 if (resultMaxZoom == ViewportArguments::ValueAuto) { |
203 result.maximumScale = float(5.0); | 200 result.maximumScale = float(5.0); |
204 result.minimumScale = min(float(5.0), result.minimumScale); | 201 result.minimumScale = min(float(5.0), result.minimumScale); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 234 |
238 if (type == ViewportArguments::ViewportMeta) { | 235 if (type == ViewportArguments::ViewportMeta) { |
239 // Extend width and height to fill the visual viewport for the resolved
initial-scale. | 236 // Extend width and height to fill the visual viewport for the resolved
initial-scale. |
240 resultWidth = max<float>(resultWidth, initialViewportSize.width() / resu
lt.initialScale); | 237 resultWidth = max<float>(resultWidth, initialViewportSize.width() / resu
lt.initialScale); |
241 resultHeight = max<float>(resultHeight, initialViewportSize.height() / r
esult.initialScale); | 238 resultHeight = max<float>(resultHeight, initialViewportSize.height() / r
esult.initialScale); |
242 } | 239 } |
243 | 240 |
244 result.layoutSize.setWidth(resultWidth); | 241 result.layoutSize.setWidth(resultWidth); |
245 result.layoutSize.setHeight(resultHeight); | 242 result.layoutSize.setHeight(resultHeight); |
246 | 243 |
247 // FIXME: This might affect some ports, but is the right thing to do. | 244 // If user-scalable = no, lock the min/max scale to the computed initial |
248 // Only set initialScale to a value if it was explicitly set. | 245 // scale. |
249 // if (resultZoom == ViewportArguments::ValueAuto) | 246 if (!resultUserZoom) |
250 // result.initialScale = ViewportArguments::ValueAuto; | 247 result.maximumScale = result.minimumScale = result.initialScale; |
251 | |
252 result.userScalable = resultUserZoom; | |
253 result.orientation = orientation; | |
254 | 248 |
255 return result; | 249 return result; |
256 } | 250 } |
257 | 251 |
258 static FloatSize convertToUserSpace(const FloatSize& deviceSize, float devicePix
elRatio) | |
259 { | |
260 FloatSize result = deviceSize; | |
261 if (devicePixelRatio != 1) | |
262 result.scale(1 / devicePixelRatio); | |
263 return result; | |
264 } | |
265 | |
266 ViewportAttributes computeViewportAttributes(ViewportArguments args, int desktop
Width, int deviceWidth, int deviceHeight, float devicePixelRatio, IntSize visibl
eViewport) | |
267 { | |
268 FloatSize initialViewportSize = convertToUserSpace(visibleViewport, devicePi
xelRatio); | |
269 FloatSize deviceSize = convertToUserSpace(FloatSize(deviceWidth, deviceHeigh
t), devicePixelRatio); | |
270 | |
271 return args.resolve(initialViewportSize, deviceSize, desktopWidth); | |
272 } | |
273 | |
274 float computeMinimumScaleFactorForContentContained(const ViewportAttributes& res
ult, const IntSize& visibleViewport, const IntSize& contentsSize) | |
275 { | |
276 FloatSize viewportSize(visibleViewport); | |
277 return max<float>(result.minimumScale, max(viewportSize.width() / contentsSi
ze.width(), viewportSize.height() / contentsSize.height())); | |
278 } | |
279 | |
280 void restrictMinimumScaleFactorToViewportSize(ViewportAttributes& result, IntSiz
e visibleViewport, float devicePixelRatio) | |
281 { | |
282 FloatSize viewportSize = convertToUserSpace(visibleViewport, devicePixelRati
o); | |
283 | |
284 result.minimumScale = max<float>(result.minimumScale, max(viewportSize.width
() / result.layoutSize.width(), viewportSize.height() / result.layoutSize.height
())); | |
285 } | |
286 | |
287 void restrictScaleFactorToInitialScaleIfNotUserScalable(ViewportAttributes& resu
lt) | |
288 { | |
289 if (!result.userScalable) | |
290 result.maximumScale = result.minimumScale = result.initialScale; | |
291 } | |
292 | |
293 static float numericPrefix(const String& keyString, const String& valueString, D
ocument* document, bool* ok = 0) | 252 static float numericPrefix(const String& keyString, const String& valueString, D
ocument* document, bool* ok = 0) |
294 { | 253 { |
295 size_t parsedLength; | 254 size_t parsedLength; |
296 float value; | 255 float value; |
297 if (valueString.is8Bit()) | 256 if (valueString.is8Bit()) |
298 value = charactersToFloat(valueString.characters8(), valueString.length(
), parsedLength); | 257 value = charactersToFloat(valueString.characters8(), valueString.length(
), parsedLength); |
299 else | 258 else |
300 value = charactersToFloat(valueString.characters16(), valueString.length
(), parsedLength); | 259 value = charactersToFloat(valueString.characters16(), valueString.length
(), parsedLength); |
301 if (!parsedLength) { | 260 if (!parsedLength) { |
302 reportViewportWarning(document, UnrecognizedViewportArgumentValueError,
valueString, keyString); | 261 reportViewportWarning(document, UnrecognizedViewportArgumentValueError,
valueString, keyString); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 message.replace("%replacement2", replacement2); | 425 message.replace("%replacement2", replacement2); |
467 | 426 |
468 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru
ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) | 427 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru
ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) |
469 message.append(" Note that ';' is not a separator in viewport values. Th
e list should be comma-separated."); | 428 message.append(" Note that ';' is not a separator in viewport values. Th
e list should be comma-separated."); |
470 | 429 |
471 // FIXME: This message should be moved off the console once a solution to ht
tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 430 // FIXME: This message should be moved off the console once a solution to ht
tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
472 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve
l(errorCode), message); | 431 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve
l(errorCode), message); |
473 } | 432 } |
474 | 433 |
475 } // namespace WebCore | 434 } // namespace WebCore |
OLD | NEW |