Index: Source/WebKit/chromium/src/ViewportAttributesManager.cpp |
diff --git a/Source/WebKit/chromium/src/ViewportAttributesManager.cpp b/Source/WebKit/chromium/src/ViewportAttributesManager.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..199e5e1cee0e762bb927922c5dd7e21c2a107bad |
--- /dev/null |
+++ b/Source/WebKit/chromium/src/ViewportAttributesManager.cpp |
@@ -0,0 +1,164 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+#include "ViewportAttributesManager.h" |
+ |
+using namespace WebCore; |
+ |
+static const float defaultMinimumScale = 0.25f; |
+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
|
+ |
+namespace WebKit { |
+ |
+ViewportAttributesManager::ViewportAttributesManager() |
+ : m_lastContentsWidth(0) |
+ , m_needsReset(false) |
+ , m_constraintsDirty(false) |
+{ |
+ m_finalAttributes = defaultConstraints(); |
+} |
+ |
+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
|
+{ |
+ return ViewportAttributes(-1, defaultMinimumScale, defaultMaximumScale); |
+} |
+ |
+void ViewportAttributesManager::updatePageDefined(const ViewportArguments& arguments, IntSize viewSize, int layoutFallbackWidth) |
+{ |
+ m_pageDefined = arguments.resolve(viewSize, viewSize, layoutFallbackWidth); |
+ |
+ // 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
|
+ if (arguments.zoom == ViewportArguments::ValueAuto) |
+ m_pageDefined.initialScale = -1; |
+ |
+ m_constraintsDirty = true; |
+} |
+ |
+void ViewportAttributesManager::setEmbedderConstraints(ViewportAttributes embedderConstraints) |
+{ |
+ m_embedderConstraints = embedderConstraints; |
+ m_constraintsDirty = true; |
+} |
+ |
+void ViewportAttributesManager::computeFinalAttributes() |
+{ |
+ m_finalAttributes = defaultConstraints(); |
+ m_finalAttributes.overrideWith(m_pageDefined); |
+ m_finalAttributes.overrideWith(m_embedderConstraints); |
+ |
+ m_constraintsDirty = false; |
+} |
+ |
+void ViewportAttributesManager::adjustFinalAttributesToContentsSize(IntSize viewSize, IntSize contentsSize, int nonOverlayScrollbarWidth) |
+{ |
+ if (!viewSize.width() || !contentsSize.width()) |
+ return; |
+ |
+ // Clamp the minimum scale so that the viewport can't exceed the document |
+ // width. |
+ float viewWidthNotIncludingScrollbars = viewSize.width() - nonOverlayScrollbarWidth; |
+ m_finalAttributes.minimumScale = std::max(m_finalAttributes.minimumScale, viewWidthNotIncludingScrollbars / contentsSize.width()); |
+ |
+ // If the initial scale wasn't defined by any of the attributes, set |
+ // it to minimum scale now that we know the real value. |
+ if (m_finalAttributes.initialScale == -1) |
+ m_finalAttributes.initialScale = m_finalAttributes.minimumScale; |
+} |
+ |
+void ViewportAttributesManager::setNeedsReset(bool needsReset) |
+{ |
+ m_needsReset = needsReset; |
+ if (needsReset) |
+ m_constraintsDirty = true; |
+} |
+ |
+void ViewportAttributesManager::didChangeContentsSize(IntSize contentsSize, float pageScaleFactor) |
+{ |
+ // If a large fixed-width element expanded the size of the document |
+ // late in loading and our initial scale is not constrained, reset the |
+ // page scale factor to the new minimum scale. |
+ if (contentsSize.width() > m_lastContentsWidth |
+ && pageScaleFactor == finalAttributes().minimumScale |
+ && embedderConstraints().initialScale == -1 && pageDefined().initialScale == -1) |
+ setNeedsReset(true); |
+ |
+ 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
|
+ m_lastContentsWidth = contentsSize.width(); |
+} |
+ |
+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.
|
+{ |
+ if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueDeviceDPI) |
+ return 1.0f / deviceScaleFactor; |
+ |
+ float targetDPI = -1.0f; |
+ 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
|
+ targetDPI = 120.0f; |
+ else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueMediumDPI) |
+ targetDPI = 160.0f; |
+ else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueHighDPI) |
+ targetDPI = 240.0f; |
+ else if (arguments.deprecatedTargetDensityDPI != ViewportArguments::ValueAuto) |
+ targetDPI = arguments.deprecatedTargetDensityDPI; |
+ return targetDPI > 0 ? (deviceScaleFactor * 120.0f) / targetDPI : 1.0f; |
+} |
+ |
+static float getLayoutWidthForNonWideViewport(const FloatSize& deviceSize, float initialScale) |
+{ |
+ return initialScale == -1 ? deviceSize.width() : deviceSize.width() / initialScale; |
+} |
+ |
+void ViewportAttributesManager::adjustPageDefinedForAndroidWebView(const ViewportArguments& arguments, IntSize viewSize, int layoutFallbackWidth, float deviceScaleFactor, 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
|
+{ |
+ float initialScale = m_pageDefined.initialScale; |
+ if (arguments.zoom == -1 && !initializeAtMinimumPageScale) { |
+ if (arguments.width == -1 || (useWideViewport && arguments.width != ViewportArguments::ValueDeviceWidth)) |
+ m_pageDefined.initialScale = 1.0f; |
+ } |
+ |
+ float targetDensityDPIFactor = |
+ calculateTargetDensityDPIFactor(arguments, deviceScaleFactor); |
+ if (m_pageDefined.initialScale != -1) |
+ m_pageDefined.initialScale *= targetDensityDPIFactor; |
+ m_pageDefined.minimumScale *= targetDensityDPIFactor; |
+ m_pageDefined.maximumScale *= targetDensityDPIFactor; |
+ |
+ if (useWideViewport && arguments.width == -1 && arguments.zoom != 1.0f) |
+ m_pageDefined.layoutSize.setWidth(layoutFallbackWidth); |
+ else { |
+ if (!useWideViewport) |
+ m_pageDefined.layoutSize.setWidth(getLayoutWidthForNonWideViewport(viewSize, initialScale)); |
+ if (!useWideViewport || arguments.width == -1 || arguments.width == ViewportArguments::ValueDeviceWidth) |
+ m_pageDefined.layoutSize.scale(1.0f / targetDensityDPIFactor); |
+ } |
+} |
+ |
+} // namespace WebKit |