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

Side by Side Diff: third_party/WebKit/Source/core/dom/ViewportDescription.cpp

Issue 2461143002: Reconstrain zoom value to the [min-zoom, max-zoom] range before it used (Closed)
Patch Set: fix for comments and html format Created 4 years, 1 month 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
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 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights
7 * reserved. 7 * reserved.
8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 float resultMaxHeight = 112 float resultMaxHeight =
113 resolveViewportLength(maxHeight, initialViewportSize, Vertical); 113 resolveViewportLength(maxHeight, initialViewportSize, Vertical);
114 float resultMinHeight = 114 float resultMinHeight =
115 resolveViewportLength(minHeight, initialViewportSize, Vertical); 115 resolveViewportLength(minHeight, initialViewportSize, Vertical);
116 116
117 float resultZoom = zoom; 117 float resultZoom = zoom;
118 float resultMinZoom = minZoom; 118 float resultMinZoom = minZoom;
119 float resultMaxZoom = maxZoom; 119 float resultMaxZoom = maxZoom;
120 bool resultUserZoom = userZoom; 120 bool resultUserZoom = userZoom;
121 121
122 // 1. Resolve min-zoom and max-zoom values. 122 // Resolve min-zoom and max-zoom values.
123 if (resultMinZoom != ViewportDescription::ValueAuto && 123 if (resultMinZoom != ViewportDescription::ValueAuto &&
124 resultMaxZoom != ViewportDescription::ValueAuto) 124 resultMaxZoom != ViewportDescription::ValueAuto)
125 resultMaxZoom = std::max(resultMinZoom, resultMaxZoom); 125 resultMaxZoom = std::max(resultMinZoom, resultMaxZoom);
126 126
127 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. 127 // Constrain zoom value to the [min-zoom, max-zoom] range.
128 if (resultZoom != ViewportDescription::ValueAuto) 128 if (resultZoom != ViewportDescription::ValueAuto)
129 resultZoom = compareIgnoringAuto( 129 resultZoom = compareIgnoringAuto(
130 resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, std::min), 130 resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, std::min),
131 std::max); 131 std::max);
132 132
133 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, std::min); 133 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, std::min);
134 134
135 // 3. Resolve non-"auto" lengths to pixel lengths. 135 // Resolve non-"auto" lengths to pixel lengths.
136 if (extendZoom == ViewportDescription::ValueAuto) { 136 if (extendZoom == ViewportDescription::ValueAuto) {
137 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom) 137 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom)
138 resultMaxWidth = ViewportDescription::ValueAuto; 138 resultMaxWidth = ViewportDescription::ValueAuto;
139 139
140 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom) 140 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom)
141 resultMaxHeight = ViewportDescription::ValueAuto; 141 resultMaxHeight = ViewportDescription::ValueAuto;
142 142
143 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) 143 if (resultMinWidth == ViewportDescription::ValueExtendToZoom)
144 resultMinWidth = resultMaxWidth; 144 resultMinWidth = resultMaxWidth;
145 145
(...skipping 11 matching lines...) Expand all
157 157
158 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) 158 if (resultMinWidth == ViewportDescription::ValueExtendToZoom)
159 resultMinWidth = 159 resultMinWidth =
160 compareIgnoringAuto(extendWidth, resultMaxWidth, std::max); 160 compareIgnoringAuto(extendWidth, resultMaxWidth, std::max);
161 161
162 if (resultMinHeight == ViewportDescription::ValueExtendToZoom) 162 if (resultMinHeight == ViewportDescription::ValueExtendToZoom)
163 resultMinHeight = 163 resultMinHeight =
164 compareIgnoringAuto(extendHeight, resultMaxHeight, std::max); 164 compareIgnoringAuto(extendHeight, resultMaxHeight, std::max);
165 } 165 }
166 166
167 // 4. Resolve initial width from min/max descriptors. 167 // Resolve initial width from min/max descriptors.
168 if (resultMinWidth != ViewportDescription::ValueAuto || 168 if (resultMinWidth != ViewportDescription::ValueAuto ||
169 resultMaxWidth != ViewportDescription::ValueAuto) 169 resultMaxWidth != ViewportDescription::ValueAuto)
170 resultWidth = compareIgnoringAuto( 170 resultWidth = compareIgnoringAuto(
171 resultMinWidth, 171 resultMinWidth,
172 compareIgnoringAuto(resultMaxWidth, initialViewportSize.width(), 172 compareIgnoringAuto(resultMaxWidth, initialViewportSize.width(),
173 std::min), 173 std::min),
174 std::max); 174 std::max);
175 175
176 // 5. Resolve initial height from min/max descriptors. 176 // Resolve initial height from min/max descriptors.
177 if (resultMinHeight != ViewportDescription::ValueAuto || 177 if (resultMinHeight != ViewportDescription::ValueAuto ||
178 resultMaxHeight != ViewportDescription::ValueAuto) 178 resultMaxHeight != ViewportDescription::ValueAuto)
179 resultHeight = compareIgnoringAuto( 179 resultHeight = compareIgnoringAuto(
180 resultMinHeight, 180 resultMinHeight,
181 compareIgnoringAuto(resultMaxHeight, initialViewportSize.height(), 181 compareIgnoringAuto(resultMaxHeight, initialViewportSize.height(),
182 std::min), 182 std::min),
183 std::max); 183 std::max);
184 184
185 // 6-7. Resolve width value. 185 // Resolve width value.
186 if (resultWidth == ViewportDescription::ValueAuto) { 186 if (resultWidth == ViewportDescription::ValueAuto) {
187 if (resultHeight == ViewportDescription::ValueAuto || 187 if (resultHeight == ViewportDescription::ValueAuto ||
188 !initialViewportSize.height()) 188 !initialViewportSize.height())
189 resultWidth = initialViewportSize.width(); 189 resultWidth = initialViewportSize.width();
190 else 190 else
191 resultWidth = resultHeight * (initialViewportSize.width() / 191 resultWidth = resultHeight * (initialViewportSize.width() /
192 initialViewportSize.height()); 192 initialViewportSize.height());
193 } 193 }
194 194
195 // 8. Resolve height value. 195 // Resolve height value.
196 if (resultHeight == ViewportDescription::ValueAuto) { 196 if (resultHeight == ViewportDescription::ValueAuto) {
197 if (!initialViewportSize.width()) 197 if (!initialViewportSize.width())
198 resultHeight = initialViewportSize.height(); 198 resultHeight = initialViewportSize.height();
199 else 199 else
200 resultHeight = resultWidth * initialViewportSize.height() / 200 resultHeight = resultWidth * initialViewportSize.height() /
201 initialViewportSize.width(); 201 initialViewportSize.width();
202 } 202 }
203 203
204 // Resolve initial-scale value. 204 // Resolve initial-scale value.
205 if (resultZoom == ViewportDescription::ValueAuto) { 205 if (resultZoom == ViewportDescription::ValueAuto) {
206 if (resultWidth != ViewportDescription::ValueAuto && resultWidth > 0) 206 if (resultWidth != ViewportDescription::ValueAuto && resultWidth > 0)
207 resultZoom = initialViewportSize.width() / resultWidth; 207 resultZoom = initialViewportSize.width() / resultWidth;
208 if (resultHeight != ViewportDescription::ValueAuto && resultHeight > 0) { 208 if (resultHeight != ViewportDescription::ValueAuto && resultHeight > 0) {
209 // if 'auto', the initial-scale will be negative here and thus ignored. 209 // if 'auto', the initial-scale will be negative here and thus ignored.
210 resultZoom = std::max<float>(resultZoom, 210 resultZoom = std::max<float>(resultZoom,
211 initialViewportSize.height() / resultHeight); 211 initialViewportSize.height() / resultHeight);
212 } 212 }
213
214 // Reconstrain zoom value to the [min-zoom, max-zoom] range. It will reset
215 // below, if it is ValueAuto here.
rune 2016/10/31 22:24:24 I didn't understand the second sentence: "It will
216 resultZoom = compareIgnoringAuto(
217 resultMinZoom, compareIgnoringAuto(resultMaxZoom, resultZoom, std::min),
218 std::max);
213 } 219 }
214 220
215 // If user-scalable = no, lock the min/max scale to the computed initial 221 // If user-scalable = no, lock the min/max scale to the computed initial
216 // scale. 222 // scale.
217 if (!resultUserZoom) 223 if (!resultUserZoom)
218 resultMinZoom = resultMaxZoom = resultZoom; 224 resultMinZoom = resultMaxZoom = resultZoom;
219 225
220 // Only set initialScale to a value if it was explicitly set. 226 // Only set initialScale to a value if it was explicitly set.
221 if (zoom == ViewportDescription::ValueAuto) 227 if (zoom == ViewportDescription::ValueAuto)
222 resultZoom = ViewportDescription::ValueAuto; 228 resultZoom = ViewportDescription::ValueAuto;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 metaTagTypeHistogram.count(MobileOptimizedMeta); 298 metaTagTypeHistogram.count(MobileOptimizedMeta);
293 } 299 }
294 #endif 300 #endif
295 } 301 }
296 302
297 bool ViewportDescription::matchesHeuristicsForGpuRasterization() const { 303 bool ViewportDescription::matchesHeuristicsForGpuRasterization() const {
298 return isSpecifiedByAuthor(); 304 return isSpecifiedByAuthor();
299 } 305 }
300 306
301 } // namespace blink 307 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698