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