Commit a324b057 authored by bokan@chromium.org's avatar bokan@chromium.org

Moved main frame resize to happen outside refreshPageScaleFactor.

refreshPageScaleFactor only gets called if the page scale constraints are dirty.
This happens when the page changes width but not when the height changes. This
cuased a bug where changing the window height only wouldn't resize the main
frame/outer viewport.

BUG=370218

Review URL: https://codereview.chromium.org/271593005

git-svn-id: svn://svn.chromium.org/blink/trunk@173672 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 76cdf4e7
......@@ -54,9 +54,9 @@ PageScaleConstraints PageScaleConstraintsSet::defaultConstraints() const
return PageScaleConstraints(-1, defaultMinimumScale, defaultMaximumScale);
}
void PageScaleConstraintsSet::updatePageDefinedConstraints(const ViewportDescription& description, IntSize viewSize, Length legacyFallbackWidth)
void PageScaleConstraintsSet::updatePageDefinedConstraints(const ViewportDescription& description, Length legacyFallbackWidth)
{
m_pageDefinedConstraints = description.resolve(viewSize, legacyFallbackWidth);
m_pageDefinedConstraints = description.resolve(m_viewSize, legacyFallbackWidth);
m_constraintsDirty = true;
}
......@@ -82,9 +82,9 @@ void PageScaleConstraintsSet::computeFinalConstraints()
m_constraintsDirty = false;
}
void PageScaleConstraintsSet::adjustFinalConstraintsToContentsSize(IntSize viewSize, IntSize contentsSize, int nonOverlayScrollbarWidth)
void PageScaleConstraintsSet::adjustFinalConstraintsToContentsSize(IntSize contentsSize, int nonOverlayScrollbarWidth)
{
m_finalConstraints.fitToContentsWidth(contentsSize.width(), viewSize.width() - nonOverlayScrollbarWidth);
m_finalConstraints.fitToContentsWidth(contentsSize.width(), m_viewSize.width() - nonOverlayScrollbarWidth);
}
void PageScaleConstraintsSet::setNeedsReset(bool needsReset)
......@@ -135,24 +135,33 @@ static float computeHeightByAspectRatio(float width, const FloatSize& deviceSize
return width * (deviceSize.height() / deviceSize.width());
}
IntSize PageScaleConstraintsSet::mainFrameSize(const IntSize& viewportSize, const IntSize& contentsSize) const
void PageScaleConstraintsSet::didChangeViewSize(const IntSize& size)
{
if (m_viewSize == size)
return;
m_viewSize = size;
m_constraintsDirty = true;
}
IntSize PageScaleConstraintsSet::mainFrameSize(const IntSize& contentsSize) const
{
// If there's no explicit minimum scale factor set, size the frame so that its width == content width
// so there's no horizontal scrolling at the minimum scale.
if (m_pageDefinedConstraints.minimumScale < finalConstraints().minimumScale
&& m_userAgentConstraints.minimumScale < finalConstraints().minimumScale
&& contentsSize.width()
&& viewportSize.width())
return IntSize(contentsSize.width(), computeHeightByAspectRatio(contentsSize.width(), viewportSize));
&& m_viewSize.width())
return IntSize(contentsSize.width(), computeHeightByAspectRatio(contentsSize.width(), m_viewSize));
// If there is a minimum scale (or there's no content size yet), the frame size should match the viewport
// size at minimum scale, since the viewport must always be contained by the frame.
IntSize frameSize(viewportSize);
IntSize frameSize(m_viewSize);
frameSize.scale(1 / finalConstraints().minimumScale);
return frameSize;
}
void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescription& description, IntSize viewSize, int layoutFallbackWidth, float deviceScaleFactor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool loadWithOverviewMode, bool nonUserScalableQuirkEnabled)
void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescription& description, int layoutFallbackWidth, float deviceScaleFactor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool loadWithOverviewMode, bool nonUserScalableQuirkEnabled)
{
if (!supportTargetDensityDPI && !wideViewportQuirkEnabled && loadWithOverviewMode && !nonUserScalableQuirkEnabled)
return;
......@@ -191,16 +200,16 @@ void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescri
if (wideViewportQuirkEnabled) {
if (useWideViewport && (description.maxWidth.isAuto() || description.maxWidth.type() == ExtendToZoom) && description.zoom != 1.0f) {
adjustedLayoutSizeWidth = layoutFallbackWidth;
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, viewSize);
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, m_viewSize);
} else if (!useWideViewport) {
const float nonWideScale = description.zoom < 1 && description.maxWidth.type() != DeviceWidth && description.maxWidth.type() != DeviceHeight ? -1 : oldInitialScale;
adjustedLayoutSizeWidth = getLayoutWidthForNonWideViewport(viewSize, nonWideScale) / targetDensityDPIFactor;
adjustedLayoutSizeWidth = getLayoutWidthForNonWideViewport(m_viewSize, nonWideScale) / targetDensityDPIFactor;
float newInitialScale = targetDensityDPIFactor;
if (m_userAgentConstraints.initialScale != -1 && (description.maxWidth.type() == DeviceWidth || ((description.maxWidth.isAuto() || description.maxWidth.type() == ExtendToZoom) && description.zoom == -1))) {
adjustedLayoutSizeWidth /= m_userAgentConstraints.initialScale;
newInitialScale = m_userAgentConstraints.initialScale;
}
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, viewSize);
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, m_viewSize);
if (description.zoom < 1) {
m_pageDefinedConstraints.initialScale = newInitialScale;
if (m_pageDefinedConstraints.minimumScale != -1)
......@@ -216,8 +225,8 @@ void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescri
m_pageDefinedConstraints.minimumScale = m_pageDefinedConstraints.initialScale;
m_pageDefinedConstraints.maximumScale = m_pageDefinedConstraints.initialScale;
if (description.maxWidth.isAuto() || description.maxWidth.type() == ExtendToZoom || description.maxWidth.type() == DeviceWidth) {
adjustedLayoutSizeWidth = viewSize.width() / targetDensityDPIFactor;
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, viewSize);
adjustedLayoutSizeWidth = m_viewSize.width() / targetDensityDPIFactor;
adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayoutSizeWidth, m_viewSize);
}
}
......
......@@ -49,8 +49,8 @@ public:
// Settings defined in the website's viewport tag, if viewport tag support
// is enabled.
const WebCore::PageScaleConstraints& pageDefinedConstraints() const { return m_pageDefinedConstraints; }
void updatePageDefinedConstraints(const WebCore::ViewportDescription&, WebCore::IntSize viewSize, WebCore::Length legacyFallbackWidth);
void adjustForAndroidWebViewQuirks(const WebCore::ViewportDescription&, WebCore::IntSize viewSize, int layoutFallbackWidth, float deviceScaleFactor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool loadWithOverviewMode, bool nonUserScalableQuirkEnabled);
void updatePageDefinedConstraints(const WebCore::ViewportDescription&, WebCore::Length legacyFallbackWidth);
void adjustForAndroidWebViewQuirks(const WebCore::ViewportDescription&, int layoutFallbackWidth, float deviceScaleFactor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool loadWithOverviewMode, bool nonUserScalableQuirkEnabled);
// Constraints may also be set from Chromium -- this overrides any
// page-defined values.
......@@ -61,7 +61,7 @@ public:
// viewport size and document width.
const WebCore::PageScaleConstraints& finalConstraints() const { return m_finalConstraints; }
void computeFinalConstraints();
void adjustFinalConstraintsToContentsSize(WebCore::IntSize viewSize, WebCore::IntSize contentsSize, int nonOverlayScrollbarWidth);
void adjustFinalConstraintsToContentsSize(WebCore::IntSize contentsSize, int nonOverlayScrollbarWidth);
void didChangeContentsSize(WebCore::IntSize contentsSize, float pageScaleFactor);
......@@ -73,7 +73,9 @@ public:
// This is set when one of the inputs to finalConstraints changes.
bool constraintsDirty() const { return m_constraintsDirty; }
WebCore::IntSize mainFrameSize(const WebCore::IntSize& viewportSize, const WebCore::IntSize& contentsSize) const;
void didChangeViewSize(const WebCore::IntSize&);
WebCore::IntSize mainFrameSize(const WebCore::IntSize& contentsSize) const;
private:
WebCore::PageScaleConstraints computeConstraintsStack() const;
......@@ -83,6 +85,7 @@ private:
WebCore::PageScaleConstraints m_finalConstraints;
int m_lastContentsWidth;
WebCore::IntSize m_viewSize;
bool m_needsReset;
bool m_constraintsDirty;
......
......@@ -1611,6 +1611,8 @@ void WebViewImpl::resize(const WebSize& newSize)
// Avoids unnecessary invalidations while various bits of state in FastTextAutosizer are updated.
FastTextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
m_pageScaleConstraintsSet.didChangeViewSize(m_size);
updatePageDefinedViewportConstraints(mainFrameImpl()->frame()->document()->viewportDescription());
updateMainFrameLayoutSize();
......@@ -1625,7 +1627,6 @@ void WebViewImpl::resize(const WebSize& newSize)
if (pinchVirtualViewportEnabled())
page()->frameHost().pinchViewport().setSize(m_size);
}
if (settings()->viewportEnabled() && !m_fixedLayoutSizeLock) {
......@@ -2912,11 +2913,11 @@ void WebViewImpl::refreshPageScaleFactorAfterLayout()
int verticalScrollbarWidth = 0;
if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
verticalScrollbarWidth = view->verticalScrollbar()->width();
m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(m_size, contentsSize(), verticalScrollbarWidth);
m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(contentsSize(), verticalScrollbarWidth);
}
if (pinchVirtualViewportEnabled())
mainFrameImpl()->frameView()->resize(m_pageScaleConstraintsSet.mainFrameSize(m_size, contentsSize()));
mainFrameImpl()->frameView()->resize(m_pageScaleConstraintsSet.mainFrameSize(contentsSize()));
float newPageScaleFactor = pageScaleFactor();
if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.finalConstraints().initialScale != -1) {
......@@ -2966,7 +2967,7 @@ void WebViewImpl::updatePageDefinedViewportConstraints(const ViewportDescription
}
float oldInitialScale = m_pageScaleConstraintsSet.pageDefinedConstraints().initialScale;
m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedDescription, m_size, defaultMinWidth);
m_pageScaleConstraintsSet.updatePageDefinedConstraints(adjustedDescription, defaultMinWidth);
if (settingsImpl()->clobberUserAgentInitialScaleQuirk()
&& m_pageScaleConstraintsSet.userAgentConstraints().initialScale != -1
......@@ -2976,7 +2977,7 @@ void WebViewImpl::updatePageDefinedViewportConstraints(const ViewportDescription
setInitialPageScaleOverride(-1);
}
m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedDescription, m_size, defaultMinWidth.intValue(), deviceScaleFactor(), settingsImpl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuirkEnabled(), page()->settings().useWideViewport(), page()->settings().loadWithOverviewMode(), settingsImpl()->viewportMetaNonUserScalableQuirk());
m_pageScaleConstraintsSet.adjustForAndroidWebViewQuirks(adjustedDescription, defaultMinWidth.intValue(), deviceScaleFactor(), settingsImpl()->supportDeprecatedTargetDensityDPI(), page()->settings().wideViewportQuirkEnabled(), page()->settings().useWideViewport(), page()->settings().loadWithOverviewMode(), settingsImpl()->viewportMetaNonUserScalableQuirk());
float newInitialScale = m_pageScaleConstraintsSet.pageDefinedConstraints().initialScale;
if (oldInitialScale != newInitialScale && newInitialScale != -1) {
m_pageScaleConstraintsSet.setNeedsReset(true);
......@@ -3635,6 +3636,7 @@ void WebViewImpl::layoutUpdated(WebLocalFrameImpl* webframe)
m_size = frameSize;
page()->frameHost().pinchViewport().setSize(m_size);
m_pageScaleConstraintsSet.didChangeViewSize(m_size);
m_client->didAutoResize(m_size);
sendResizeEventAndRepaint();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment