Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 { | 61 { |
| 62 ASSERT(value != ViewportArguments::ValueDeviceWidth); | 62 ASSERT(value != ViewportArguments::ValueDeviceWidth); |
| 63 ASSERT(value != ViewportArguments::ValueDeviceHeight); | 63 ASSERT(value != ViewportArguments::ValueDeviceHeight); |
| 64 | 64 |
| 65 // Limits as defined in the css-device-adapt spec. | 65 // Limits as defined in the css-device-adapt spec. |
| 66 if (value != ViewportArguments::ValueAuto) | 66 if (value != ViewportArguments::ValueAuto) |
| 67 return min(float(10), max(value, float(0.1))); | 67 return min(float(10), max(value, float(0.1))); |
| 68 return value; | 68 return value; |
| 69 } | 69 } |
| 70 | 70 |
| 71 static float resolveViewportLength(const Length& length, const FloatSize& initia lViewportSize, bool horizontal) | |
|
apavlov
2013/08/07 09:25:54
optionally, you could have an enum instead of the
rune
2013/08/07 10:06:15
I'll fix.
rune
2013/08/07 11:30:04
Done.
| |
| 72 { | |
| 73 if (length.isAuto()) | |
| 74 return ViewportArguments::ValueAuto; | |
| 75 | |
| 76 if (length.isFixed()) | |
| 77 return length.getFloatValue(); | |
| 78 | |
| 79 if (length.type() == ExtendToZoom) | |
| 80 return ViewportArguments::ValueExtendToZoom; | |
| 81 | |
| 82 if (length.type() == Percent && horizontal || length.type() == ViewportPerce ntageWidth) | |
| 83 return initialViewportSize.width() * length.getFloatValue() / 100.0f; | |
| 84 | |
| 85 if (length.type() == Percent && !horizontal || length.type() == ViewportPerc entageHeight) | |
| 86 return initialViewportSize.height() * length.getFloatValue() / 100.0f; | |
| 87 | |
| 88 if (length.type() == ViewportPercentageMin) | |
| 89 return min(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f; | |
| 90 | |
| 91 if (length.type() == ViewportPercentageMax) | |
| 92 return max(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f; | |
| 93 | |
| 94 ASSERT_NOT_REACHED(); | |
| 95 return ViewportArguments::ValueAuto; | |
| 96 } | |
| 97 | |
| 71 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, const FloatSize& deviceSize, int defaultWidth) const | 98 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, const FloatSize& deviceSize, int defaultWidth) const |
| 72 { | 99 { |
| 73 float resultWidth = width; | 100 float resultWidth = width; |
| 74 float resultMaxWidth = maxWidth; | |
| 75 float resultMinWidth = minWidth; | |
| 76 float resultHeight = height; | 101 float resultHeight = height; |
| 77 float resultMinHeight = minHeight; | |
| 78 float resultMaxHeight = maxHeight; | |
| 79 | |
| 80 float resultZoom = zoom; | 102 float resultZoom = zoom; |
| 81 float resultMinZoom = minZoom; | 103 float resultMinZoom = minZoom; |
| 82 float resultMaxZoom = maxZoom; | 104 float resultMaxZoom = maxZoom; |
| 83 float resultUserZoom = userZoom; | 105 float resultUserZoom = userZoom; |
| 84 | 106 |
| 85 if (type == ViewportArguments::CSSDeviceAdaptation) { | 107 if (type == ViewportArguments::CSSDeviceAdaptation) { |
| 86 | 108 |
| 87 // device-width/device-height not supported for @viewport. | 109 float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSi ze, true); |
| 88 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceWidth); | 110 float resultMinWidth = resolveViewportLength(minWidth, initialViewportSi ze, true); |
| 89 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceHeight); | 111 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewport Size, false); |
| 90 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceWidth); | 112 float resultMinHeight = resolveViewportLength(minHeight, initialViewport Size, false); |
| 91 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceHeight); | |
| 92 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceWidth); | |
| 93 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceHeight); | |
| 94 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceWidth); | |
| 95 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceHeight); | |
| 96 | 113 |
| 97 // 1. Resolve min-zoom and max-zoom values. | 114 // 1. Resolve min-zoom and max-zoom values. |
| 98 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto) | 115 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto) |
| 99 resultMaxZoom = max(resultMinZoom, resultMaxZoom); | 116 resultMaxZoom = max(resultMinZoom, resultMaxZoom); |
| 100 | 117 |
| 101 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. | 118 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. |
| 102 if (resultZoom != ViewportArguments::ValueAuto) | 119 if (resultZoom != ViewportArguments::ValueAuto) |
| 103 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max); | 120 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max); |
| 104 | 121 |
| 105 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); | 122 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 136 // 4. Resolve initial width from min/max descriptors. | 153 // 4. Resolve initial width from min/max descriptors. |
| 137 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto) | 154 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto) |
| 138 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max); | 155 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max); |
| 139 | 156 |
| 140 // 5. Resolve initial height from min/max descriptors. | 157 // 5. Resolve initial height from min/max descriptors. |
| 141 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto) | 158 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto) |
| 142 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max); | 159 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max); |
| 143 | 160 |
| 144 // 6-7. Resolve width value. | 161 // 6-7. Resolve width value. |
| 145 if (resultWidth == ViewportArguments::ValueAuto) { | 162 if (resultWidth == ViewportArguments::ValueAuto) { |
| 146 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport Size .height()) | 163 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport Size.height()) |
| 147 resultWidth = initialViewportSize.width(); | 164 resultWidth = initialViewportSize.width(); |
| 148 else | 165 else |
| 149 resultWidth = resultHeight * (initialViewportSize.width() / init ialViewportSize.height()); | 166 resultWidth = resultHeight * (initialViewportSize.width() / init ialViewportSize.height()); |
| 150 } | 167 } |
| 151 | 168 |
| 152 // 8. Resolve height value. | 169 // 8. Resolve height value. |
| 153 if (resultHeight == ViewportArguments::ValueAuto) { | 170 if (resultHeight == ViewportArguments::ValueAuto) { |
| 154 if (!initialViewportSize.width()) | 171 if (!initialViewportSize.width()) |
| 155 resultHeight = initialViewportSize.height(); | 172 resultHeight = initialViewportSize.height(); |
| 156 else | 173 else |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 message.replace("%replacement2", replacement2); | 452 message.replace("%replacement2", replacement2); |
| 436 | 453 |
| 437 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) | 454 if ((errorCode == UnrecognizedViewportArgumentValueError || errorCode == Tru ncatedViewportArgumentValueError) && replacement1.find(';') != WTF::notFound) |
| 438 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated."); | 455 message.append(" Note that ';' is not a separator in viewport values. Th e list should be comma-separated."); |
| 439 | 456 |
| 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. | 457 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
| 441 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message); | 458 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message); |
| 442 } | 459 } |
| 443 | 460 |
| 444 } // namespace WebCore | 461 } // namespace WebCore |
| OLD | NEW |