Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1847)

Unified Diff: Source/core/testing/Internals.cpp

Issue 14813025: Refactor viewport initialization logic out of WebViewImpl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add tests for new behavior Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/core/page/Page.cpp ('K') | « Source/core/page/Page.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/testing/Internals.cpp
diff --git a/Source/core/testing/Internals.cpp b/Source/core/testing/Internals.cpp
index 111e1fff839f2edd0a427a21dc15374fd0ab12e1..e2e59dc89b48809580fe92ece876d102ee41a925 100644
--- a/Source/core/testing/Internals.cpp
+++ b/Source/core/testing/Internals.cpp
@@ -919,6 +919,35 @@ void Internals::setPagination(Document* document, const String& mode, int gap, i
page->setPagination(pagination);
}
+static FloatSize convertToUserSpace(const FloatSize& deviceSize, float devicePixelRatio)
+{
+ FloatSize result = deviceSize;
+ if (devicePixelRatio != 1)
+ result.scale(1 / devicePixelRatio);
+ return result;
+}
+
+static ViewportAttributes computeViewportAttributes(ViewportArguments args, int desktopWidth, int deviceWidth, int deviceHeight, float devicePixelRatio, IntSize visibleViewport)
+{
+ FloatSize initialViewportSize = convertToUserSpace(visibleViewport, devicePixelRatio);
+ FloatSize deviceSize = convertToUserSpace(FloatSize(deviceWidth, deviceHeight), devicePixelRatio);
+
+ return args.resolve(initialViewportSize, deviceSize, desktopWidth);
+}
+
+static float computeMinimumScaleFactorForContentContained(const ViewportAttributes& result, const IntSize& visibleViewport, const IntSize& contentsSize)
+{
+ FloatSize viewportSize(visibleViewport);
+ return max<float>(result.minimumScale, max(viewportSize.width() / contentsSize.width(), viewportSize.height() / contentsSize.height()));
+}
+
+static void restrictMinimumScaleFactorToViewportSize(ViewportAttributes& result, IntSize visibleViewport, float devicePixelRatio)
+{
+ FloatSize viewportSize = convertToUserSpace(visibleViewport, devicePixelRatio);
+
+ result.minimumScale = max<float>(result.minimumScale, max(viewportSize.width() / result.layoutSize.width(), viewportSize.height() / result.layoutSize.height()));
+}
+
String Internals::configurationForViewport(Document* document, float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
{
if (!document || !document->page()) {
@@ -932,9 +961,8 @@ String Internals::configurationForViewport(Document* document, float devicePixel
ViewportArguments arguments = page->viewportArguments();
ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
- restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
- return "viewport size " + String::number(attributes.layoutSize.width()) + "x" + String::number(attributes.layoutSize.height()) + " scale " + String::number(attributes.initialScale) + " with limits [" + String::number(attributes.minimumScale) + ", " + String::number(attributes.maximumScale) + "] and userScalable " + (attributes.userScalable ? "true" : "false");
+ return "viewport size " + String::number(attributes.layoutSize.width()) + "x" + String::number(attributes.layoutSize.height()) + " scale " + String::number(attributes.initialScale) + " with limits [" + String::number(attributes.minimumScale) + ", " + String::number(attributes.maximumScale) + "] and userScalable " + (arguments.userZoom ? "true" : "false");
}
bool Internals::wasLastChangeUserEdit(Element* textField, ExceptionCode& ec)
« Source/core/page/Page.cpp ('K') | « Source/core/page/Page.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698