Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (141482 => 141483)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2013-01-31 22:00:22 UTC (rev 141482)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2013-01-31 22:02:23 UTC (rev 141483)
@@ -396,6 +396,7 @@
, m_pageDefinedMaximumPageScaleFactor(-1)
, m_minimumPageScaleFactor(minPageScaleFactor)
, m_maximumPageScaleFactor(maxPageScaleFactor)
+ , m_initialPageScaleFactor(-1)
, m_ignoreViewportTagMaximumScale(false)
, m_pageScaleFactorIsSet(false)
, m_savedPageScaleFactor(0)
@@ -1660,10 +1661,9 @@
#if ENABLE(VIEWPORT)
if (settings()->viewportEnabled()) {
- // Relayout immediately to obtain the new content width, which is needed
- // to calculate the minimum scale limit.
- view->layout();
- computePageScaleFactorLimits();
+ // Relayout immediately to recalculate the minimum scale limit.
+ if (view->needsLayout())
+ view->layout();
// When the device rotates:
// - If the page width is unchanged, then zoom by new width/old width
@@ -3047,9 +3047,22 @@
void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScale)
{
+ if (minPageScale == m_pageDefinedMinimumPageScaleFactor && maxPageScale == m_pageDefinedMaximumPageScaleFactor)
+ return;
+
m_pageDefinedMinimumPageScaleFactor = minPageScale;
m_pageDefinedMaximumPageScaleFactor = maxPageScale;
- computePageScaleFactorLimits();
+
+ if (settings()->viewportEnabled()) {
+ // If we're in viewport tag mode, we need to layout to obtain the latest
+ // contents size and compute the final limits.
+ FrameView* view = mainFrameImpl()->frameView();
+ if (view)
+ view->setNeedsLayout();
+ } else {
+ // Otherwise just compute the limits immediately.
+ computePageScaleFactorLimits();
+ }
}
void WebViewImpl::setIgnoreViewportTagMaximumScale(bool flag)
@@ -3092,45 +3105,46 @@
return IntSize(contentSize.width(), contentSize.width() * aspectRatio);
}
-bool WebViewImpl::computePageScaleFactorLimits()
+void WebViewImpl::computePageScaleFactorLimits()
{
if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageScaleFactor == -1)
- return false;
+ return;
if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()->view())
- return false;
+ return;
FrameView* view = page()->mainFrame()->view();
m_minimumPageScaleFactor = min(max(m_pageDefinedMinimumPageScaleFactor, minPageScaleFactor), maxPageScaleFactor);
m_maximumPageScaleFactor = max(min(m_pageDefinedMaximumPageScaleFactor, maxPageScaleFactor), minPageScaleFactor);
- if (!m_webSettings->applyDeviceScaleFactorInCompositor()) {
- m_minimumPageScaleFactor *= deviceScaleFactor();
- m_maximumPageScaleFactor *= deviceScaleFactor();
- }
- int viewWidthNotIncludingScrollbars = m_size.width;
- if (viewWidthNotIncludingScrollbars && view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
- viewWidthNotIncludingScrollbars -= view->verticalScrollbar()->width();
- int unscaledContentsWidth = contentsSize().width();
- if (viewWidthNotIncludingScrollbars && unscaledContentsWidth) {
- // Limit page scaling down to the document width.
- m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / unscaledContentsWidth);
+ if (settings()->viewportEnabled()) {
+ if (!contentsSize().width() || !m_size.width)
+ return;
+
+ // When viewport tag is enabled, the scale needed to see the full
+ // content width is the default minimum.
+ int viewWidthNotIncludingScrollbars = m_size.width;
+ if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
+ viewWidthNotIncludingScrollbars -= view->verticalScrollbar()->width();
+ m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / contentsSize().width());
m_maximumPageScaleFactor = max(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
}
ASSERT(m_minimumPageScaleFactor <= m_maximumPageScaleFactor);
- float clampedScale = clampPageScaleFactorToLimits(pageScaleFactor());
+ // Initialize and/or clamp the page scale factor if needed.
+ float newPageScaleFactor = pageScaleFactor();
+ if (!m_pageScaleFactorIsSet && m_initialPageScaleFactor != -1) {
+ newPageScaleFactor = m_initialPageScaleFactor;
+ m_pageScaleFactorIsSet = true;
+ }
+ newPageScaleFactor = clampPageScaleFactorToLimits(newPageScaleFactor);
#if USE(ACCELERATED_COMPOSITING)
if (m_layerTreeView)
- m_layerTreeView->setPageScaleFactorAndLimits(clampedScale, m_minimumPageScaleFactor, m_maximumPageScaleFactor);
+ m_layerTreeView->setPageScaleFactorAndLimits(newPageScaleFactor, m_minimumPageScaleFactor, m_maximumPageScaleFactor);
#endif
- if (clampedScale != pageScaleFactor()) {
- setPageScaleFactorPreservingScrollOffset(clampedScale);
- return true;
- }
-
- return false;
+ if (newPageScaleFactor != pageScaleFactor())
+ setPageScaleFactorPreservingScrollOffset(newPageScaleFactor);
}
float WebViewImpl::minimumPageScaleFactor() const
@@ -3742,32 +3756,31 @@
}
}
+ if (settings()->viewportEnabled()) {
+ if (!isPageScaleFactorSet()) {
+ // If the viewport tag failed to be processed earlier, we need
+ // to recompute it now.
+ ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()->viewportArguments();
+ m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArguments);
+ }
+
+ // Contents size is an input to the page scale limits, so a good time to
+ // recalculate is after layout has occurred.
+ computePageScaleFactorLimits();
+
+ // Relayout immediately to avoid violating the rule that needsLayout()
+ // isn't set at the end of a layout.
+ FrameView* view = mainFrameImpl()->frameView();
+ if (view && view->needsLayout())
+ view->layout();
+ }
+
m_client->didUpdateLayout();
+
}
void WebViewImpl::didChangeContentsSize()
{
-#if ENABLE(VIEWPORT)
- if (!settings()->viewportEnabled() || !mainFrameImpl())
- return;
-
- bool mayNeedLayout = false;
- if (!isPageScaleFactorSet()) {
- // If the viewport tag failed to be processed earlier, we need
- // to recompute it now.
- ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()->viewportArguments();
- m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArguments);
- mayNeedLayout = true;
- } else
- mayNeedLayout = computePageScaleFactorLimits();
-
- // didChangeContentsSize() may be called from FrameView::layout; we need to
- // relayout to avoid triggering the assertion that needsLayout() isn't set
- // at the end of a layout.
- FrameView* view = mainFrameImpl()->frameView();
- if (mayNeedLayout && view && view->needsLayout())
- view->layout();
-#endif
}
bool WebViewImpl::useExternalPopupMenus()
Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (141482 => 141483)
--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2013-01-31 22:00:22 UTC (rev 141482)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2013-01-31 22:02:23 UTC (rev 141483)
@@ -286,9 +286,7 @@
webView->mainFrame()->contentAsText(1024).utf8();
}
-// Test is disabled because it started failing after r140025.
-// See bug for details: webkit.org/b/107206.
-TEST_F(WebFrameTest, DISABLED_FixedLayoutInitializeAtMinimumPageScale)
+TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumPageScale)
{
registerMockedHttpURLLoad("fixed_layout.html");
@@ -300,6 +298,8 @@
// Make sure we initialize to minimum scale, even if the window size
// only becomes available after the load begins.
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
+ webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
+ webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
webViewImpl->enableFixedLayoutMode(true);
webViewImpl->settings()->setViewportEnabled(true);
webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
@@ -387,8 +387,7 @@
EXPECT_EQ(3, webViewImpl->pageScaleFactor());
}
-// Disabled, pending investigation after http://trac.webkit.org/changeset/141053
-TEST_F(WebFrameTest, DISABLED_pageScaleFactorShrinksViewport)
+TEST_F(WebFrameTest, pageScaleFactorShrinksViewport)
{
registerMockedHttpURLLoad("fixed_layout.html");
@@ -396,8 +395,6 @@
client.m_screenInfo.deviceScaleFactor = 1;
int viewportWidth = 640;
int viewportHeight = 480;
- int viewportWidthMinusScrollbar = 640 - 15;
- int viewportHeightMinusScrollbar = 480 - 15;
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
@@ -407,17 +404,21 @@
webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
webViewImpl->layout();
+ WebCore::FrameView* view = webViewImpl->mainFrameImpl()->frameView();
+ int viewportWidthMinusScrollbar = 640 - (view->verticalScrollbar()->isOverlayScrollbar() ? 0 : 15);
+ int viewportHeightMinusScrollbar = 480 - (view->horizontalScrollbar()->isOverlayScrollbar() ? 0 : 15);
+
webViewImpl->setPageScaleFactor(2, WebPoint());
- WebCore::IntSize unscaledSize = webViewImpl->mainFrameImpl()->frameView()->unscaledVisibleContentSize(true);
+ WebCore::IntSize unscaledSize = view->unscaledVisibleContentSize(true);
EXPECT_EQ(viewportWidth, unscaledSize.width());
EXPECT_EQ(viewportHeight, unscaledSize.height());
- WebCore::IntSize unscaledSizeMinusScrollbar = webViewImpl->mainFrameImpl()->frameView()->unscaledVisibleContentSize(false);
+ WebCore::IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSize(false);
EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width());
EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height());
- WebCore::IntSize scaledSize = webViewImpl->mainFrameImpl()->frameView()->visibleContentRect().size();
+ WebCore::IntSize scaledSize = view->visibleContentRect().size();
EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width());
EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height());
}
@@ -457,6 +458,8 @@
int viewportHeight = 480;
WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for_you.html", true, 0, &client));
+ webViewImpl->settings()->setApplyDeviceScaleFactorInCompositor(true);
+ webViewImpl->settings()->setApplyPageScaleFactorInCompositor(true);
webViewImpl->enableFixedLayoutMode(true);
webViewImpl->settings()->setViewportEnabled(true);
webViewImpl->resize(WebSize(viewportWidth, viewportHeight));
@@ -464,6 +467,7 @@
EXPECT_EQ(1.0f, webViewImpl->maximumPageScaleFactor());
webViewImpl->setIgnoreViewportTagMaximumScale(true);
+ webViewImpl->layout();
EXPECT_EQ(4.0f, webViewImpl->maximumPageScaleFactor());
}
@@ -535,9 +539,7 @@
void simulateDoubleTap(WebViewImpl* webViewImpl, WebPoint& point, float& scale)
{
- WebPoint scaledPoint(static_cast<int>(point.x * webViewImpl->pageScaleFactor()),
- static_cast<int>(point.y * webViewImpl->pageScaleFactor()));
- webViewImpl->animateZoomAroundPoint(scaledPoint, WebViewImpl::DoubleTap);
+ webViewImpl->animateZoomAroundPoint(point, WebViewImpl::DoubleTap);
webViewImpl->mainFrameImpl()->frameView()->layout();
scale = webViewImpl->pageScaleFactor();
}
@@ -610,6 +612,7 @@
// Test double tap scale bounds.
// minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1
webView->setPageScaleFactorLimits(0.5f, 4);
+ webView->layout();
float doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -623,6 +626,7 @@
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
// 1 < minimumPageScale < doubleTapZoomAlreadyLegibleScale
webView->setPageScaleFactorLimits(1.1f, 4);
+ webView->layout();
doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -636,6 +640,7 @@
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
// minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale
webView->setPageScaleFactorLimits(0.95f, 4);
+ webView->layout();
doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -674,8 +679,9 @@
// minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingFontScaleFactor
float legibleScale = textAutosizingFontScaleFactor;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
+ float doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
webView->setPageScaleFactorLimits(0.5f, 4);
- float doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
+ webView->layout();
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
EXPECT_FLOAT_EQ(legibleScale, scale);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -687,6 +693,7 @@
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
// 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlreadyLegibleScale
webView->setPageScaleFactorLimits(1.0f, 4);
+ webView->layout();
doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -700,6 +707,7 @@
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
// minimumPageScale < 1 < textAutosizingFontScaleFactor < doubleTapZoomAlreadyLegibleScale
webView->setPageScaleFactorLimits(0.95f, 4);
+ webView->layout();
doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);
@@ -713,6 +721,7 @@
webViewImpl->applyScrollAndScale(WebSize(), 1.1f);
// minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale < textAutosizingFontScaleFactor
webView->setPageScaleFactorLimits(0.9f, 4);
+ webView->layout();
doubleTapZoomAlreadyLegibleScale = webViewImpl->minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
setScaleAndScrollAndLayout(webViewImpl, WebPoint(0, 0), (webViewImpl->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2);
simulateDoubleTap(webViewImpl, doubleTapPoint, scale);