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 18 matching lines...) Expand all Loading... |
29 #include "core/dom/ViewportDescription.h" | 29 #include "core/dom/ViewportDescription.h" |
30 | 30 |
31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
32 #include "core/frame/FrameHost.h" | 32 #include "core/frame/FrameHost.h" |
33 #include "core/frame/FrameView.h" | 33 #include "core/frame/FrameView.h" |
34 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
36 #include "platform/weborigin/KURL.h" | 36 #include "platform/weborigin/KURL.h" |
37 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
38 | 38 |
| 39 using namespace std; |
| 40 |
39 namespace WebCore { | 41 namespace WebCore { |
40 | 42 |
41 static const float& compareIgnoringAuto(const float& value1, const float& value2
, const float& (*compare) (const float&, const float&)) | 43 static const float& compareIgnoringAuto(const float& value1, const float& value2
, const float& (*compare) (const float&, const float&)) |
42 { | 44 { |
43 if (value1 == ViewportDescription::ValueAuto) | 45 if (value1 == ViewportDescription::ValueAuto) |
44 return value2; | 46 return value2; |
45 | 47 |
46 if (value2 == ViewportDescription::ValueAuto) | 48 if (value2 == ViewportDescription::ValueAuto) |
47 return value1; | 49 return value1; |
48 | 50 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize
, Vertical); | 105 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewportSize
, Vertical); |
104 float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize
, Vertical); | 106 float resultMinHeight = resolveViewportLength(minHeight, initialViewportSize
, Vertical); |
105 | 107 |
106 float resultZoom = zoom; | 108 float resultZoom = zoom; |
107 float resultMinZoom = minZoom; | 109 float resultMinZoom = minZoom; |
108 float resultMaxZoom = maxZoom; | 110 float resultMaxZoom = maxZoom; |
109 bool resultUserZoom = userZoom; | 111 bool resultUserZoom = userZoom; |
110 | 112 |
111 // 1. Resolve min-zoom and max-zoom values. | 113 // 1. Resolve min-zoom and max-zoom values. |
112 if (resultMinZoom != ViewportDescription::ValueAuto && resultMaxZoom != View
portDescription::ValueAuto) | 114 if (resultMinZoom != ViewportDescription::ValueAuto && resultMaxZoom != View
portDescription::ValueAuto) |
113 resultMaxZoom = std::max(resultMinZoom, resultMaxZoom); | 115 resultMaxZoom = max(resultMinZoom, resultMaxZoom); |
114 | 116 |
115 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. | 117 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. |
116 if (resultZoom != ViewportDescription::ValueAuto) | 118 if (resultZoom != ViewportDescription::ValueAuto) |
117 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resu
ltMaxZoom, resultZoom, std::min), std::max); | 119 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto(resu
ltMaxZoom, resultZoom, min), max); |
118 | 120 |
119 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, std::min); | 121 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); |
120 | 122 |
121 // 3. Resolve non-"auto" lengths to pixel lengths. | 123 // 3. Resolve non-"auto" lengths to pixel lengths. |
122 if (extendZoom == ViewportDescription::ValueAuto) { | 124 if (extendZoom == ViewportDescription::ValueAuto) { |
123 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom) | 125 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom) |
124 resultMaxWidth = ViewportDescription::ValueAuto; | 126 resultMaxWidth = ViewportDescription::ValueAuto; |
125 | 127 |
126 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom) | 128 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom) |
127 resultMaxHeight = ViewportDescription::ValueAuto; | 129 resultMaxHeight = ViewportDescription::ValueAuto; |
128 | 130 |
129 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) | 131 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) |
130 resultMinWidth = resultMaxWidth; | 132 resultMinWidth = resultMaxWidth; |
131 | 133 |
132 if (resultMinHeight == ViewportDescription::ValueExtendToZoom) | 134 if (resultMinHeight == ViewportDescription::ValueExtendToZoom) |
133 resultMinHeight = resultMaxHeight; | 135 resultMinHeight = resultMaxHeight; |
134 } else { | 136 } else { |
135 float extendWidth = initialViewportSize.width() / extendZoom; | 137 float extendWidth = initialViewportSize.width() / extendZoom; |
136 float extendHeight = initialViewportSize.height() / extendZoom; | 138 float extendHeight = initialViewportSize.height() / extendZoom; |
137 | 139 |
138 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom) | 140 if (resultMaxWidth == ViewportDescription::ValueExtendToZoom) |
139 resultMaxWidth = extendWidth; | 141 resultMaxWidth = extendWidth; |
140 | 142 |
141 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom) | 143 if (resultMaxHeight == ViewportDescription::ValueExtendToZoom) |
142 resultMaxHeight = extendHeight; | 144 resultMaxHeight = extendHeight; |
143 | 145 |
144 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) | 146 if (resultMinWidth == ViewportDescription::ValueExtendToZoom) |
145 resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, st
d::max); | 147 resultMinWidth = compareIgnoringAuto(extendWidth, resultMaxWidth, ma
x); |
146 | 148 |
147 if (resultMinHeight == ViewportDescription::ValueExtendToZoom) | 149 if (resultMinHeight == ViewportDescription::ValueExtendToZoom) |
148 resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight,
std::max); | 150 resultMinHeight = compareIgnoringAuto(extendHeight, resultMaxHeight,
max); |
149 } | 151 } |
150 | 152 |
151 // 4. Resolve initial width from min/max descriptors. | 153 // 4. Resolve initial width from min/max descriptors. |
152 if (resultMinWidth != ViewportDescription::ValueAuto || resultMaxWidth != Vi
ewportDescription::ValueAuto) | 154 if (resultMinWidth != ViewportDescription::ValueAuto || resultMaxWidth != Vi
ewportDescription::ValueAuto) |
153 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(re
sultMaxWidth, initialViewportSize.width(), std::min), std::max); | 155 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAuto(re
sultMaxWidth, initialViewportSize.width(), min), max); |
154 | 156 |
155 // 5. Resolve initial height from min/max descriptors. | 157 // 5. Resolve initial height from min/max descriptors. |
156 if (resultMinHeight != ViewportDescription::ValueAuto || resultMaxHeight !=
ViewportDescription::ValueAuto) | 158 if (resultMinHeight != ViewportDescription::ValueAuto || resultMaxHeight !=
ViewportDescription::ValueAuto) |
157 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(
resultMaxHeight, initialViewportSize.height(), std::min), std::max); | 159 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringAuto(
resultMaxHeight, initialViewportSize.height(), min), max); |
158 | 160 |
159 // 6-7. Resolve width value. | 161 // 6-7. Resolve width value. |
160 if (resultWidth == ViewportDescription::ValueAuto) { | 162 if (resultWidth == ViewportDescription::ValueAuto) { |
161 if (resultHeight == ViewportDescription::ValueAuto || !initialViewportSi
ze.height()) | 163 if (resultHeight == ViewportDescription::ValueAuto || !initialViewportSi
ze.height()) |
162 resultWidth = initialViewportSize.width(); | 164 resultWidth = initialViewportSize.width(); |
163 else | 165 else |
164 resultWidth = resultHeight * (initialViewportSize.width() / initialV
iewportSize.height()); | 166 resultWidth = resultHeight * (initialViewportSize.width() / initialV
iewportSize.height()); |
165 } | 167 } |
166 | 168 |
167 // 8. Resolve height value. | 169 // 8. Resolve height value. |
168 if (resultHeight == ViewportDescription::ValueAuto) { | 170 if (resultHeight == ViewportDescription::ValueAuto) { |
169 if (!initialViewportSize.width()) | 171 if (!initialViewportSize.width()) |
170 resultHeight = initialViewportSize.height(); | 172 resultHeight = initialViewportSize.height(); |
171 else | 173 else |
172 resultHeight = resultWidth * initialViewportSize.height() / initialV
iewportSize.width(); | 174 resultHeight = resultWidth * initialViewportSize.height() / initialV
iewportSize.width(); |
173 } | 175 } |
174 | 176 |
175 // Resolve initial-scale value. | 177 // Resolve initial-scale value. |
176 if (resultZoom == ViewportDescription::ValueAuto) { | 178 if (resultZoom == ViewportDescription::ValueAuto) { |
177 if (resultWidth != ViewportDescription::ValueAuto && resultWidth > 0) | 179 if (resultWidth != ViewportDescription::ValueAuto && resultWidth > 0) |
178 resultZoom = initialViewportSize.width() / resultWidth; | 180 resultZoom = initialViewportSize.width() / resultWidth; |
179 if (resultHeight != ViewportDescription::ValueAuto && resultHeight > 0)
{ | 181 if (resultHeight != ViewportDescription::ValueAuto && resultHeight > 0)
{ |
180 // if 'auto', the initial-scale will be negative here and thus ignor
ed. | 182 // if 'auto', the initial-scale will be negative here and thus ignor
ed. |
181 resultZoom = std::max<float>(resultZoom, initialViewportSize.height(
) / resultHeight); | 183 resultZoom = max<float>(resultZoom, initialViewportSize.height() / r
esultHeight); |
182 } | 184 } |
183 } | 185 } |
184 | 186 |
185 // If user-scalable = no, lock the min/max scale to the computed initial | 187 // If user-scalable = no, lock the min/max scale to the computed initial |
186 // scale. | 188 // scale. |
187 if (!resultUserZoom) | 189 if (!resultUserZoom) |
188 resultMinZoom = resultMaxZoom = resultZoom; | 190 resultMinZoom = resultMaxZoom = resultZoom; |
189 | 191 |
190 // Only set initialScale to a value if it was explicitly set. | 192 // Only set initialScale to a value if it was explicitly set. |
191 if (zoom == ViewportDescription::ValueAuto) | 193 if (zoom == ViewportDescription::ValueAuto) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 255 } |
254 } else if (type == ViewportDescription::HandheldFriendlyMeta) { | 256 } else if (type == ViewportDescription::HandheldFriendlyMeta) { |
255 blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType",
MetaHandheldFriendly, TypeCount); | 257 blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType",
MetaHandheldFriendly, TypeCount); |
256 } else if (type == ViewportDescription::MobileOptimizedMeta) { | 258 } else if (type == ViewportDescription::MobileOptimizedMeta) { |
257 blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType",
MobileOptimizedMeta, TypeCount); | 259 blink::Platform::current()->histogramEnumeration("Viewport.MetaTagType",
MobileOptimizedMeta, TypeCount); |
258 } | 260 } |
259 #endif | 261 #endif |
260 } | 262 } |
261 | 263 |
262 } // namespace WebCore | 264 } // namespace WebCore |
OLD | NEW |