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

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

Issue 19632002: Support 'extend-to-zoom' viewport descriptor value (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed isExtendToZoom() Created 7 years, 5 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
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | Source/core/platform/Length.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2013 Intel Corporation. All rights reserved.
10 * 10 *
11 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
15 * 15 *
16 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details. 19 * Library General Public License for more details.
(...skipping 10 matching lines...) Expand all
30 30
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
33 33
34 using namespace std; 34 using namespace std;
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 static const float& compareIgnoringAuto(const float& value1, const float& value2 , const float& (*compare) (const float&, const float&)) 38 static const float& compareIgnoringAuto(const float& value1, const float& value2 , const float& (*compare) (const float&, const float&))
39 { 39 {
40 ASSERT(value1 != ViewportArguments::ValueAuto || value2 != ViewportArguments ::ValueAuto);
41
42 if (value1 == ViewportArguments::ValueAuto) 40 if (value1 == ViewportArguments::ValueAuto)
43 return value2; 41 return value2;
44 42
45 if (value2 == ViewportArguments::ValueAuto) 43 if (value2 == ViewportArguments::ValueAuto)
46 return value1; 44 return value1;
47 45
48 return compare(value1, value2); 46 return compare(value1, value2);
49 } 47 }
50 48
51 static inline float clampLengthValue(float value) 49 static inline float clampLengthValue(float value)
(...skipping 19 matching lines...) Expand all
71 } 69 }
72 70
73 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, const FloatSize& deviceSize, int defaultWidth) const 71 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, const FloatSize& deviceSize, int defaultWidth) const
74 { 72 {
75 float resultWidth = width; 73 float resultWidth = width;
76 float resultMaxWidth = maxWidth; 74 float resultMaxWidth = maxWidth;
77 float resultMinWidth = minWidth; 75 float resultMinWidth = minWidth;
78 float resultHeight = height; 76 float resultHeight = height;
79 float resultMinHeight = minHeight; 77 float resultMinHeight = minHeight;
80 float resultMaxHeight = maxHeight; 78 float resultMaxHeight = maxHeight;
79
81 float resultZoom = zoom; 80 float resultZoom = zoom;
82 float resultMinZoom = minZoom; 81 float resultMinZoom = minZoom;
83 float resultMaxZoom = maxZoom; 82 float resultMaxZoom = maxZoom;
84 float resultUserZoom = userZoom; 83 float resultUserZoom = userZoom;
85 84
86 switch (int(resultWidth)) {
87 case ViewportArguments::ValueDeviceWidth:
88 resultWidth = deviceSize.width();
89 break;
90 case ViewportArguments::ValueDeviceHeight:
91 resultWidth = deviceSize.height();
92 break;
93 }
94
95 switch (int(resultHeight)) {
96 case ViewportArguments::ValueDeviceWidth:
97 resultHeight = deviceSize.width();
98 break;
99 case ViewportArguments::ValueDeviceHeight:
100 resultHeight = deviceSize.height();
101 break;
102 }
103
104 if (type == ViewportArguments::CSSDeviceAdaptation) { 85 if (type == ViewportArguments::CSSDeviceAdaptation) {
105 86
106 // device-width/device-height not supported for @viewport. 87 // device-width/device-height not supported for @viewport.
107 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceWidth); 88 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceWidth);
108 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceHeight); 89 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceHeight);
109 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceWidth); 90 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceWidth);
110 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceHeight); 91 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceHeight);
111 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceWidth); 92 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceWidth);
112 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceHeight); 93 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceHeight);
113 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceWidth); 94 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceWidth);
114 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceHeight); 95 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceHeight);
115 96
97 // 1. Resolve min-zoom and max-zoom values.
98 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto)
99 resultMaxZoom = max(resultMinZoom, resultMaxZoom);
100
101 // 2. Constrain zoom value to the [min-zoom, max-zoom] range.
102 if (resultZoom != ViewportArguments::ValueAuto)
103 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max);
104
105 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min);
106
107 if (extendZoom == ViewportArguments::ValueAuto) {
108 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
109 resultMaxWidth = ViewportArguments::ValueAuto;
110
111 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
112 resultMaxHeight = ViewportArguments::ValueAuto;
113
114 if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
115 resultMinWidth = resultMaxWidth;
116
117 if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
118 resultMinHeight = resultMaxHeight;
119 } else {
120 float extendWidth = initialViewportSize.width() / extendZoom;
121 float extendHeight = initialViewportSize.height() / extendZoom;
122
123 if (resultMaxWidth == ViewportArguments::ValueExtendToZoom)
124 resultMaxWidth = extendWidth;
125
126 if (resultMaxHeight == ViewportArguments::ValueExtendToZoom)
127 resultMaxHeight = extendHeight;
128
129 if (resultMinWidth == ViewportArguments::ValueExtendToZoom)
130 resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth , max);
131
132 if (resultMinHeight == ViewportArguments::ValueExtendToZoom)
133 resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHei ght, max);
134 }
135
136 // 4. Resolve initial width from min/max descriptors.
116 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto) 137 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto)
117 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max); 138 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max);
118 139
140 // 5. Resolve initial height from min/max descriptors.
119 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto) 141 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto)
120 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max); 142 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max);
121 143
122 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto) 144 // 6-7. Resolve width value.
123 resultMaxZoom = max(resultMinZoom, resultMaxZoom);
124
125 if (resultZoom != ViewportArguments::ValueAuto)
126 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max);
127
128 if (resultWidth == ViewportArguments::ValueAuto && (resultHeight == View portArguments::ValueAuto || !initialViewportSize.height()))
129 resultWidth = initialViewportSize.width();
130
131 if (resultWidth == ViewportArguments::ValueAuto) { 145 if (resultWidth == ViewportArguments::ValueAuto) {
132 ASSERT(initialViewportSize.height()); // If height is 0, resultWidth should be resolved above. 146 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport Size .height())
133 resultWidth = resultHeight * initialViewportSize.width() / initialVi ewportSize.height(); 147 resultWidth = initialViewportSize.width();
148 else
149 resultWidth = resultHeight * (initialViewportSize.width() / init ialViewportSize.height());
134 } 150 }
135 151
152 // 8. Resolve height value.
136 if (resultHeight == ViewportArguments::ValueAuto) { 153 if (resultHeight == ViewportArguments::ValueAuto) {
137 if (!initialViewportSize.width()) 154 if (!initialViewportSize.width())
138 resultHeight = initialViewportSize.height(); 155 resultHeight = initialViewportSize.height();
139 else 156 else
140 resultHeight = resultWidth * initialViewportSize.height() / init ialViewportSize.width(); 157 resultHeight = resultWidth * initialViewportSize.height() / init ialViewportSize.width();
141 } 158 }
159
160 PageScaleConstraints result;
161 result.minimumScale = resultMinZoom;
162 result.maximumScale = resultMaxZoom;
163 result.initialScale = resultZoom;
164 result.layoutSize.setWidth(resultWidth);
165 result.layoutSize.setHeight(resultHeight);
166 return result;
142 } 167 }
143 168
144 if (type != ViewportArguments::CSSDeviceAdaptation && type != ViewportArgume nts::Implicit) { 169 switch (static_cast<int>(resultWidth)) {
170 case ViewportArguments::ValueDeviceWidth:
171 resultWidth = deviceSize.width();
172 break;
173 case ViewportArguments::ValueDeviceHeight:
174 resultWidth = deviceSize.height();
175 break;
176 }
177
178 switch (static_cast<int>(resultHeight)) {
179 case ViewportArguments::ValueDeviceWidth:
180 resultHeight = deviceSize.width();
181 break;
182 case ViewportArguments::ValueDeviceHeight:
183 resultHeight = deviceSize.height();
184 break;
185 }
186
187 if (type != ViewportArguments::Implicit) {
145 // Clamp values to a valid range, but not for @viewport since is 188 // Clamp values to a valid range, but not for @viewport since is
146 // not mandated by the specification. 189 // not mandated by the specification.
147 resultWidth = clampLengthValue(resultWidth); 190 resultWidth = clampLengthValue(resultWidth);
148 resultHeight = clampLengthValue(resultHeight); 191 resultHeight = clampLengthValue(resultHeight);
149 resultZoom = clampScaleValue(resultZoom); 192 resultZoom = clampScaleValue(resultZoom);
150 resultMinZoom = clampScaleValue(resultMinZoom); 193 resultMinZoom = clampScaleValue(resultMinZoom);
151 resultMaxZoom = clampScaleValue(resultMaxZoom); 194 resultMaxZoom = clampScaleValue(resultMaxZoom);
152 } 195 }
153 196
154 PageScaleConstraints result; 197 PageScaleConstraints result;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 message.replace("%replacement2", replacement2); 435 message.replace("%replacement2", replacement2);
393 436
394 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) 437 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound)
395 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated."); 438 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated.");
396 439
397 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. 440 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists.
398 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message); 441 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message);
399 } 442 }
400 443
401 } // namespace WebCore 444 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | Source/core/platform/Length.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698