Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "ViewportAttributesManager.h" | |
| 33 | |
| 34 using namespace WebCore; | |
| 35 | |
| 36 static const float defaultMinimumScale = 0.25f; | |
| 37 static const float defaultMaximumScale = 4.0f; | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
doesn't iOS use 5 as maximum scale by default? I a
dshwang
2013/05/13 12:38:01
Is any reason that two static values out of WebKit
aelias_OOO_until_Jul13
2013/05/13 18:13:06
OK, changed to 5.0 and moved into namespace WebKit
| |
| 38 | |
| 39 namespace WebKit { | |
| 40 | |
| 41 ViewportAttributesManager::ViewportAttributesManager() | |
| 42 : m_lastContentsWidth(0) | |
| 43 , m_needsReset(false) | |
| 44 , m_constraintsDirty(false) | |
| 45 { | |
| 46 m_finalAttributes = defaultConstraints(); | |
| 47 } | |
| 48 | |
| 49 ViewportAttributes ViewportAttributesManager::defaultConstraints() const | |
|
dshwang
2013/05/13 12:38:01
I think this function can be static in this file s
aelias_OOO_until_Jul13
2013/05/13 18:13:06
No, there is a callsite from WebViewImpl::setIgnor
| |
| 50 { | |
| 51 return ViewportAttributes(-1, defaultMinimumScale, defaultMaximumScale); | |
| 52 } | |
| 53 | |
| 54 void ViewportAttributesManager::updatePageDefined(const ViewportArguments& argum ents, IntSize viewSize, int layoutFallbackWidth) | |
| 55 { | |
| 56 m_pageDefined = arguments.resolve(viewSize, viewSize, layoutFallbackWidth); | |
| 57 | |
| 58 // Only set initialScale to a value if it was explicitly set. | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
Why not fix this in the actual ViewportArguments.c
aelias_OOO_until_Jul13
2013/05/13 18:13:06
I tried that, but it causes a large number of fast
| |
| 59 if (arguments.zoom == ViewportArguments::ValueAuto) | |
| 60 m_pageDefined.initialScale = -1; | |
| 61 | |
| 62 m_constraintsDirty = true; | |
| 63 } | |
| 64 | |
| 65 void ViewportAttributesManager::setEmbedderConstraints(ViewportAttributes embedd erConstraints) | |
| 66 { | |
| 67 m_embedderConstraints = embedderConstraints; | |
| 68 m_constraintsDirty = true; | |
| 69 } | |
| 70 | |
| 71 void ViewportAttributesManager::computeFinalAttributes() | |
| 72 { | |
| 73 m_finalAttributes = defaultConstraints(); | |
| 74 m_finalAttributes.overrideWith(m_pageDefined); | |
| 75 m_finalAttributes.overrideWith(m_embedderConstraints); | |
| 76 | |
| 77 m_constraintsDirty = false; | |
| 78 } | |
| 79 | |
| 80 void ViewportAttributesManager::adjustFinalAttributesToContentsSize(IntSize view Size, IntSize contentsSize, int nonOverlayScrollbarWidth) | |
| 81 { | |
| 82 if (!viewSize.width() || !contentsSize.width()) | |
| 83 return; | |
| 84 | |
| 85 // Clamp the minimum scale so that the viewport can't exceed the document | |
| 86 // width. | |
| 87 float viewWidthNotIncludingScrollbars = viewSize.width() - nonOverlayScrollb arWidth; | |
| 88 m_finalAttributes.minimumScale = std::max(m_finalAttributes.minimumScale, vi ewWidthNotIncludingScrollbars / contentsSize.width()); | |
| 89 | |
| 90 // If the initial scale wasn't defined by any of the attributes, set | |
| 91 // it to minimum scale now that we know the real value. | |
| 92 if (m_finalAttributes.initialScale == -1) | |
| 93 m_finalAttributes.initialScale = m_finalAttributes.minimumScale; | |
| 94 } | |
| 95 | |
| 96 void ViewportAttributesManager::setNeedsReset(bool needsReset) | |
| 97 { | |
| 98 m_needsReset = needsReset; | |
| 99 if (needsReset) | |
| 100 m_constraintsDirty = true; | |
| 101 } | |
| 102 | |
| 103 void ViewportAttributesManager::didChangeContentsSize(IntSize contentsSize, floa t pageScaleFactor) | |
| 104 { | |
| 105 // If a large fixed-width element expanded the size of the document | |
| 106 // late in loading and our initial scale is not constrained, reset the | |
| 107 // page scale factor to the new minimum scale. | |
| 108 if (contentsSize.width() > m_lastContentsWidth | |
| 109 && pageScaleFactor == finalAttributes().minimumScale | |
| 110 && embedderConstraints().initialScale == -1 && pageDefined().initialScal e == -1) | |
| 111 setNeedsReset(true); | |
| 112 | |
| 113 m_constraintsDirty = true; | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
So above you sometimes call setNeedsReset which wi
aelias_OOO_until_Jul13
2013/05/13 18:13:06
Yes, but I also want to mark them dirty in all cas
| |
| 114 m_lastContentsWidth = contentsSize.width(); | |
| 115 } | |
| 116 | |
| 117 static float calculateTargetDensityDPIFactor(const ViewportArguments& arguments, float deviceScaleFactor) | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
computeDeprecatedTargetDensityDPIFactor?
aelias_OOO_until_Jul13
2013/05/13 18:13:06
Done.
| |
| 118 { | |
| 119 if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueDeviceDP I) | |
| 120 return 1.0f / deviceScaleFactor; | |
| 121 | |
| 122 float targetDPI = -1.0f; | |
| 123 if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueLowDPI) | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
Have any one measure if we can get rid of this? I
mnaganov (inactive)
2013/05/13 11:58:38
This is used by existing Android WebView-based app
| |
| 124 targetDPI = 120.0f; | |
| 125 else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueMed iumDPI) | |
| 126 targetDPI = 160.0f; | |
| 127 else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueHig hDPI) | |
| 128 targetDPI = 240.0f; | |
| 129 else if (arguments.deprecatedTargetDensityDPI != ViewportArguments::ValueAut o) | |
| 130 targetDPI = arguments.deprecatedTargetDensityDPI; | |
| 131 return targetDPI > 0 ? (deviceScaleFactor * 120.0f) / targetDPI : 1.0f; | |
| 132 } | |
| 133 | |
| 134 static float getLayoutWidthForNonWideViewport(const FloatSize& deviceSize, float initialScale) | |
| 135 { | |
| 136 return initialScale == -1 ? deviceSize.width() : deviceSize.width() / initia lScale; | |
| 137 } | |
| 138 | |
| 139 void ViewportAttributesManager::adjustPageDefinedForAndroidWebView(const Viewpor tArguments& arguments, IntSize viewSize, int layoutFallbackWidth, float deviceSc aleFactor, bool useWideViewport, bool initializeAtMinimumPageScale) | |
|
kenneth.r.christiansen
2013/05/13 11:00:18
So this does not affect the android chrome browser
mnaganov (inactive)
2013/05/13 11:58:38
Correct. Chrome for Android and Chromium-based And
| |
| 140 { | |
| 141 float initialScale = m_pageDefined.initialScale; | |
| 142 if (arguments.zoom == -1 && !initializeAtMinimumPageScale) { | |
| 143 if (arguments.width == -1 || (useWideViewport && arguments.width != View portArguments::ValueDeviceWidth)) | |
| 144 m_pageDefined.initialScale = 1.0f; | |
| 145 } | |
| 146 | |
| 147 float targetDensityDPIFactor = | |
| 148 calculateTargetDensityDPIFactor(arguments, deviceScaleFactor); | |
| 149 if (m_pageDefined.initialScale != -1) | |
| 150 m_pageDefined.initialScale *= targetDensityDPIFactor; | |
| 151 m_pageDefined.minimumScale *= targetDensityDPIFactor; | |
| 152 m_pageDefined.maximumScale *= targetDensityDPIFactor; | |
| 153 | |
| 154 if (useWideViewport && arguments.width == -1 && arguments.zoom != 1.0f) | |
| 155 m_pageDefined.layoutSize.setWidth(layoutFallbackWidth); | |
| 156 else { | |
| 157 if (!useWideViewport) | |
| 158 m_pageDefined.layoutSize.setWidth(getLayoutWidthForNonWideViewport(v iewSize, initialScale)); | |
| 159 if (!useWideViewport || arguments.width == -1 || arguments.width == View portArguments::ValueDeviceWidth) | |
| 160 m_pageDefined.layoutSize.scale(1.0f / targetDensityDPIFactor); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 } // namespace WebKit | |
| OLD | NEW |