Modified: trunk/Source/WebKit/chromium/ChangeLog (102291 => 102292)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-12-08 01:50:51 UTC (rev 102291)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-12-08 01:53:42 UTC (rev 102292)
@@ -1,3 +1,33 @@
+2011-12-07 Alexandre Elias <[email protected]>
+
+ [chromium] Preserve original pageScale limits in WebViewImpl
+ https://bugs.webkit.org/show_bug.cgi?id=72983
+
+ Reviewed by Darin Fisher.
+
+ Preserve the originally viewport-tag specified page scale limits, and
+ compute the final ones in a new private method
+ computePageScaleFactorLimits(). This is then called when contents
+ size change (which can affect the minimum).
+
+ Also clean up several minor bugs, namely clamping issues (reorder
+ clampNegativeToZero to avoid negative scroll offsets, and force max to
+ be greater than min), and incorrect behavior in the presence of
+ "solid" scrollbars.
+
+ * src/ChromeClientImpl.cpp:
+ (WebKit::ChromeClientImpl::contentsSizeChanged):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::WebViewImpl):
+ (WebKit::WebViewImpl::clampPageScaleFactorToLimits):
+ (WebKit::WebViewImpl::clampOffsetAtScale):
+ (WebKit::WebViewImpl::setPageScaleFactorPreservingScrollOffset):
+ (WebKit::WebViewImpl::setPageScaleFactor):
+ (WebKit::WebViewImpl::setPageScaleFactorLimits):
+ (WebKit::WebViewImpl::computePageScaleFactorLimits):
+ (WebKit::WebViewImpl::didChangeContentsSize):
+ * src/WebViewImpl.h:
+
2011-12-07 Chris Sharp <[email protected]>
Exposing boundsInScreenSpace in WebElement.
Modified: trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp (102291 => 102292)
--- trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp 2011-12-08 01:50:51 UTC (rev 102291)
+++ trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp 2011-12-08 01:53:42 UTC (rev 102292)
@@ -550,6 +550,8 @@
void ChromeClientImpl::contentsSizeChanged(Frame* frame, const IntSize& size) const
{
+ m_webView->didChangeContentsSize();
+
WebFrameImpl* webframe = WebFrameImpl::fromFrame(frame);
if (webframe->client())
webframe->client()->didChangeContentsSize(webframe, size);
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (102291 => 102292)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-12-08 01:50:51 UTC (rev 102291)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-12-08 01:53:42 UTC (rev 102292)
@@ -343,6 +343,8 @@
, m_zoomLevel(0)
, m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
, m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
+ , m_pageDefinedMinimumPageScaleFactor(-1)
+ , m_pageDefinedMaximumPageScaleFactor(-1)
, m_minimumPageScaleFactor(minPageScaleFactor)
, m_maximumPageScaleFactor(maxPageScaleFactor)
, m_contextMenuAllowed(false)
@@ -1953,7 +1955,7 @@
return page()->pageScaleFactor();
}
-float WebViewImpl::computePageScaleFactorWithinLimits(float scaleFactor)
+float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor)
{
return min(max(scaleFactor, m_minimumPageScaleFactor), m_maximumPageScaleFactor);
}
@@ -1970,15 +1972,15 @@
// Enforce the maximum and minimum scroll positions at the new scale.
IntPoint clampedOffset = offset;
+ clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
clampedOffset.clampNegativeToZero();
- clampedOffset = clampedOffset.shrunkTo(IntPoint(docWidthAtNewScale - viewWidth, docHeightAtNewScale - viewHeight));
return clampedOffset;
}
void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
{
// Pick a scale factor that is within the expected limits
- scaleFactor = computePageScaleFactorWithinLimits(scaleFactor);
+ scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
if (scaleFactor == pageScaleFactor())
return;
@@ -1998,7 +2000,7 @@
if (!scaleFactor)
scaleFactor = 1;
- scaleFactor = computePageScaleFactorWithinLimits(scaleFactor);
+ scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
WebPoint clampedOrigin = clampOffsetAtScale(origin, scaleFactor);
page()->setPageScaleFactor(scaleFactor, clampedOrigin);
}
@@ -2064,24 +2066,43 @@
void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScale)
{
- m_minimumPageScaleFactor = min(max(minPageScale, minPageScaleFactor), maxPageScaleFactor) * deviceScaleFactor();
- m_maximumPageScaleFactor = max(min(maxPageScale, maxPageScaleFactor), minPageScaleFactor) * deviceScaleFactor();
+ m_pageDefinedMinimumPageScaleFactor = minPageScale;
+ m_pageDefinedMaximumPageScaleFactor = maxPageScale;
+ computePageScaleFactorLimits();
+}
- if (m_size.width && mainFrame() && mainFrame()->contentsSize().width) {
+bool WebViewImpl::computePageScaleFactorLimits()
+{
+ if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageScaleFactor == -1)
+ return false;
+
+ if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()->view())
+ return false;
+
+ m_minimumPageScaleFactor = min(max(m_pageDefinedMinimumPageScaleFactor, minPageScaleFactor), maxPageScaleFactor) * deviceScaleFactor();
+ m_maximumPageScaleFactor = max(min(m_pageDefinedMaximumPageScaleFactor, maxPageScaleFactor), minPageScaleFactor) * deviceScaleFactor();
+
+ int viewWidthNotIncludingScrollbars = page()->mainFrame()->view()->visibleContentRect(false).width();
+ int contentsWidth = mainFrame()->contentsSize().width;
+ if (viewWidthNotIncludingScrollbars && contentsWidth) {
// Limit page scaling down to the document width.
- int viewWidth = m_size.width;
- int unscaledContentWidth = mainFrame()->contentsSize().width / pageScaleFactor();
- m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidth) / unscaledContentWidth);
+ int unscaledContentWidth = contentsWidth / pageScaleFactor();
+ m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<float>(viewWidthNotIncludingScrollbars) / unscaledContentWidth);
+ m_maximumPageScaleFactor = max(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
}
- ASSERT(minPageScale <= maxPageScale);
+ ASSERT(m_minimumPageScaleFactor <= m_maximumPageScaleFactor);
#if USE(ACCELERATED_COMPOSITING)
if (m_layerTreeHost)
m_layerTreeHost->setPageScaleFactorLimits(m_minimumPageScaleFactor, m_maximumPageScaleFactor);
#endif
- float clampedScale = computePageScaleFactorWithinLimits(pageScaleFactor());
- if (clampedScale != pageScaleFactor())
+ float clampedScale = clampPageScaleFactorToLimits(pageScaleFactor());
+ if (clampedScale != pageScaleFactor()) {
setPageScaleFactorPreservingScrollOffset(clampedScale);
+ return true;
+ }
+
+ return false;
}
float WebViewImpl::minimumPageScaleFactor() const
@@ -2591,6 +2612,21 @@
m_client->didUpdateLayout();
}
+void WebViewImpl::didChangeContentsSize()
+{
+ bool didClampScale = computePageScaleFactorLimits();
+
+ if (!didClampScale)
+ return;
+
+ if (!mainFrameImpl())
+ return;
+
+ FrameView* view = mainFrameImpl()->frameView();
+ if (view && view->needsLayout())
+ view->layout();
+}
+
bool WebViewImpl::useExternalPopupMenus()
{
return shouldUseExternalPopupMenus;
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (102291 => 102292)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-12-08 01:50:51 UTC (rev 102291)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-12-08 01:53:42 UTC (rev 102292)
@@ -335,6 +335,8 @@
// unless the view did not need a layout.
void layoutUpdated(WebFrameImpl*);
+ void didChangeContentsSize();
+
// Returns true if popup menus should be rendered by the browser, false if
// they should be rendered by WebKit (which is the default).
static bool useExternalPopupMenus();
@@ -461,7 +463,8 @@
bool hasVerticalScrollbar();
private:
- float computePageScaleFactorWithinLimits(float scale);
+ bool computePageScaleFactorLimits();
+ float clampPageScaleFactorToLimits(float scale);
WebPoint clampOffsetAtScale(const WebPoint& offset, float scale);
friend class WebView; // So WebView::Create can call our constructor
@@ -568,8 +571,9 @@
double m_maximumZoomLevel;
+ float m_pageDefinedMinimumPageScaleFactor;
+ float m_pageDefinedMaximumPageScaleFactor;
float m_minimumPageScaleFactor;
-
float m_maximumPageScaleFactor;
bool m_contextMenuAllowed;