Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2004)

Side by Side Diff: Source/core/dom/ViewportArguments.cpp

Issue 14813025: Refactor viewport initialization logic out of WebViewImpl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix webkit_unit_tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 #include "core/dom/ViewportArguments.h" 29 #include "core/dom/ViewportArguments.h"
30 30
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/platform/graphics/IntSize.h" 32 #include "core/platform/graphics/IntSize.h"
33 #include <wtf/text/WTFString.h> 33 #include <wtf/text/WTFString.h>
34 34
35 using namespace std; 35 using namespace std;
36 36
37 namespace WebCore { 37 namespace WebCore {
38 38
39 const float ViewportArguments::deprecatedTargetDPI = 160;
40
41 static const float& compareIgnoringAuto(const float& value1, const float& value2 , const float& (*compare) (const float&, const float&)) 39 static const float& compareIgnoringAuto(const float& value1, const float& value2 , const float& (*compare) (const float&, const float&))
42 { 40 {
43 ASSERT(value1 != ViewportArguments::ValueAuto || value2 != ViewportArguments ::ValueAuto); 41 ASSERT(value1 != ViewportArguments::ValueAuto || value2 != ViewportArguments ::ValueAuto);
44 42
45 if (value1 == ViewportArguments::ValueAuto) 43 if (value1 == ViewportArguments::ValueAuto)
46 return value2; 44 return value2;
47 45
48 if (value2 == ViewportArguments::ValueAuto) 46 if (value2 == ViewportArguments::ValueAuto)
49 return value1; 47 return value1;
50 48
(...skipping 15 matching lines...) Expand all
66 { 64 {
67 ASSERT(value != ViewportArguments::ValueDeviceWidth); 65 ASSERT(value != ViewportArguments::ValueDeviceWidth);
68 ASSERT(value != ViewportArguments::ValueDeviceHeight); 66 ASSERT(value != ViewportArguments::ValueDeviceHeight);
69 67
70 // Limits as defined in the css-device-adapt spec. 68 // Limits as defined in the css-device-adapt spec.
71 if (value != ViewportArguments::ValueAuto) 69 if (value != ViewportArguments::ValueAuto)
72 return min(float(10), max(value, float(0.1))); 70 return min(float(10), max(value, float(0.1)));
73 return value; 71 return value;
74 } 72 }
75 73
76 ViewportAttributes ViewportArguments::resolve(const FloatSize& initialViewportSi ze, const FloatSize& deviceSize, int defaultWidth) const 74 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, const FloatSize& deviceSize, int defaultWidth) const
77 { 75 {
78 float resultWidth = width; 76 float resultWidth = width;
79 float resultMaxWidth = maxWidth; 77 float resultMaxWidth = maxWidth;
80 float resultMinWidth = minWidth; 78 float resultMinWidth = minWidth;
81 float resultHeight = height; 79 float resultHeight = height;
82 float resultMinHeight = minHeight; 80 float resultMinHeight = minHeight;
83 float resultMaxHeight = maxHeight; 81 float resultMaxHeight = maxHeight;
84 float resultZoom = zoom; 82 float resultZoom = zoom;
85 float resultMinZoom = minZoom; 83 float resultMinZoom = minZoom;
86 float resultMaxZoom = maxZoom; 84 float resultMaxZoom = maxZoom;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (type != ViewportArguments::CSSDeviceAdaptation && type != ViewportArgume nts::Implicit) { 175 if (type != ViewportArguments::CSSDeviceAdaptation && type != ViewportArgume nts::Implicit) {
178 // Clamp values to a valid range, but not for @viewport since is 176 // Clamp values to a valid range, but not for @viewport since is
179 // not mandated by the specification. 177 // not mandated by the specification.
180 resultWidth = clampLengthValue(resultWidth); 178 resultWidth = clampLengthValue(resultWidth);
181 resultHeight = clampLengthValue(resultHeight); 179 resultHeight = clampLengthValue(resultHeight);
182 resultZoom = clampScaleValue(resultZoom); 180 resultZoom = clampScaleValue(resultZoom);
183 resultMinZoom = clampScaleValue(resultMinZoom); 181 resultMinZoom = clampScaleValue(resultMinZoom);
184 resultMaxZoom = clampScaleValue(resultMaxZoom); 182 resultMaxZoom = clampScaleValue(resultMaxZoom);
185 } 183 }
186 184
187 ViewportAttributes result; 185 PageScaleConstraints result;
188 result.orientation = orientation;
189 186
190 // Resolve minimum-scale and maximum-scale values according to spec. 187 // Resolve minimum-scale and maximum-scale values according to spec.
191 if (resultMinZoom == ViewportArguments::ValueAuto) 188 if (resultMinZoom == ViewportArguments::ValueAuto)
192 result.minimumScale = float(0.25); 189 result.minimumScale = float(0.25);
193 else 190 else
194 result.minimumScale = resultMinZoom; 191 result.minimumScale = resultMinZoom;
195 192
196 if (resultMaxZoom == ViewportArguments::ValueAuto) { 193 if (resultMaxZoom == ViewportArguments::ValueAuto) {
197 result.maximumScale = float(5.0); 194 result.maximumScale = float(5.0);
198 result.minimumScale = min(float(5.0), result.minimumScale); 195 result.minimumScale = min(float(5.0), result.minimumScale);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 228
232 if (type == ViewportArguments::ViewportMeta) { 229 if (type == ViewportArguments::ViewportMeta) {
233 // Extend width and height to fill the visual viewport for the resolved initial-scale. 230 // Extend width and height to fill the visual viewport for the resolved initial-scale.
234 resultWidth = max<float>(resultWidth, initialViewportSize.width() / resu lt.initialScale); 231 resultWidth = max<float>(resultWidth, initialViewportSize.width() / resu lt.initialScale);
235 resultHeight = max<float>(resultHeight, initialViewportSize.height() / r esult.initialScale); 232 resultHeight = max<float>(resultHeight, initialViewportSize.height() / r esult.initialScale);
236 } 233 }
237 234
238 result.layoutSize.setWidth(resultWidth); 235 result.layoutSize.setWidth(resultWidth);
239 result.layoutSize.setHeight(resultHeight); 236 result.layoutSize.setHeight(resultHeight);
240 237
241 // FIXME: This might affect some ports, but is the right thing to do. 238 // If user-scalable = no, lock the min/max scale to the computed initial
239 // scale.
240 if (!resultUserZoom)
241 result.maximumScale = result.minimumScale = result.initialScale;
242
242 // Only set initialScale to a value if it was explicitly set. 243 // Only set initialScale to a value if it was explicitly set.
243 // if (resultZoom == ViewportArguments::ValueAuto) 244 if (resultZoom == ViewportArguments::ValueAuto)
244 // result.initialScale = ViewportArguments::ValueAuto; 245 result.initialScale = ViewportArguments::ValueAuto;
245
246 result.userScalable = resultUserZoom;
247 result.orientation = orientation;
248 246
249 return result; 247 return result;
250 } 248 }
251 249
252 static FloatSize convertToUserSpace(const FloatSize& deviceSize, float devicePix elRatio)
253 {
254 FloatSize result = deviceSize;
255 if (devicePixelRatio != 1)
256 result.scale(1 / devicePixelRatio);
257 return result;
258 }
259
260 ViewportAttributes computeViewportAttributes(ViewportArguments args, int desktop Width, int deviceWidth, int deviceHeight, float devicePixelRatio, IntSize visibl eViewport)
261 {
262 FloatSize initialViewportSize = convertToUserSpace(visibleViewport, devicePi xelRatio);
263 FloatSize deviceSize = convertToUserSpace(FloatSize(deviceWidth, deviceHeigh t), devicePixelRatio);
264
265 return args.resolve(initialViewportSize, deviceSize, desktopWidth);
266 }
267
268 float computeMinimumScaleFactorForContentContained(const ViewportAttributes& res ult, const IntSize& visibleViewport, const IntSize& contentsSize)
269 {
270 FloatSize viewportSize(visibleViewport);
271 return max<float>(result.minimumScale, max(viewportSize.width() / contentsSi ze.width(), viewportSize.height() / contentsSize.height()));
272 }
273
274 void restrictMinimumScaleFactorToViewportSize(ViewportAttributes& result, IntSiz e visibleViewport, float devicePixelRatio)
275 {
276 FloatSize viewportSize = convertToUserSpace(visibleViewport, devicePixelRati o);
277
278 result.minimumScale = max<float>(result.minimumScale, max(viewportSize.width () / result.layoutSize.width(), viewportSize.height() / result.layoutSize.height ()));
279 }
280
281 void restrictScaleFactorToInitialScaleIfNotUserScalable(ViewportAttributes& resu lt)
282 {
283 if (!result.userScalable)
284 result.maximumScale = result.minimumScale = result.initialScale;
285 }
286
287 static float numericPrefix(const String& keyString, const String& valueString, D ocument* document, bool* ok = 0) 250 static float numericPrefix(const String& keyString, const String& valueString, D ocument* document, bool* ok = 0)
288 { 251 {
289 size_t parsedLength; 252 size_t parsedLength;
290 float value; 253 float value;
291 if (valueString.is8Bit()) 254 if (valueString.is8Bit())
292 value = charactersToFloat(valueString.characters8(), valueString.length( ), parsedLength); 255 value = charactersToFloat(valueString.characters8(), valueString.length( ), parsedLength);
293 else 256 else
294 value = charactersToFloat(valueString.characters16(), valueString.length (), parsedLength); 257 value = charactersToFloat(valueString.characters16(), valueString.length (), parsedLength);
295 if (!parsedLength) { 258 if (!parsedLength) {
296 reportViewportWarning(document, UnrecognizedViewportArgumentValueError, valueString, keyString); 259 reportViewportWarning(document, UnrecognizedViewportArgumentValueError, valueString, keyString);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 message.replace("%replacement2", replacement2); 423 message.replace("%replacement2", replacement2);
461 424
462 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) 425 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound)
463 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated."); 426 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated.");
464 427
465 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. 428 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists.
466 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message); 429 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message);
467 } 430 }
468 431
469 } // namespace WebCore 432 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698