Commit 943633d0 authored by bokan@chromium.org's avatar bokan@chromium.org

Use expected main frame size from WebViewImpl when creating a new FrameView.

The main frame's size is no longer simply the viewport size. Instead,
WebViewImpl sizes it after layout to be the either the content width with
a height matching the viewport aspect ratio, or the viewport at minimum page
scale. This fixes a bug where the innerWidth/innerHeight values would be
wrong during an onload event if the onload would happen before the content was
properly sized.

BUG=431097,428722

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185145 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b9668732
...@@ -1666,7 +1666,7 @@ void WebLocalFrameImpl::createFrameView() ...@@ -1666,7 +1666,7 @@ void WebLocalFrameImpl::createFrameView()
if (isLocalRoot) if (isLocalRoot)
webView->suppressInvalidations(true); webView->suppressInvalidations(true);
frame()->createView(webView->size(), webView->baseBackgroundColor(), webView->isTransparent()); frame()->createView(webView->mainFrameSize(), webView->baseBackgroundColor(), webView->isTransparent());
if (webView->shouldAutoResize() && isLocalRoot) if (webView->shouldAutoResize() && isLocalRoot)
frame()->view()->enableAutoSizeMode(webView->minAutoSize(), webView->maxAutoSize()); frame()->view()->enableAutoSizeMode(webView->minAutoSize(), webView->maxAutoSize());
......
...@@ -3210,6 +3210,21 @@ void WebViewImpl::setIgnoreViewportTagScaleLimits(bool ignore) ...@@ -3210,6 +3210,21 @@ void WebViewImpl::setIgnoreViewportTagScaleLimits(bool ignore)
setUserAgentPageScaleConstraints(constraints); setUserAgentPageScaleConstraints(constraints);
} }
IntSize WebViewImpl::mainFrameSize() const
{
if (!pinchVirtualViewportEnabled())
return m_size;
FrameView* view = page()->deprecatedLocalMainFrame()->view();
int contentAndScrollbarWidth = contentsSize().width();
if (view && view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
contentAndScrollbarWidth += view->verticalScrollbar()->width();
return m_pageScaleConstraintsSet.mainFrameSize(contentAndScrollbarWidth);
}
void WebViewImpl::refreshPageScaleFactorAfterLayout() void WebViewImpl::refreshPageScaleFactorAfterLayout()
{ {
if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()->isLocalFrame() || !page()->deprecatedLocalMainFrame()->view()) if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()->isLocalFrame() || !page()->deprecatedLocalMainFrame()->view())
...@@ -3226,13 +3241,8 @@ void WebViewImpl::refreshPageScaleFactorAfterLayout() ...@@ -3226,13 +3241,8 @@ void WebViewImpl::refreshPageScaleFactorAfterLayout()
m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(contentsSize(), verticalScrollbarWidth); m_pageScaleConstraintsSet.adjustFinalConstraintsToContentsSize(contentsSize(), verticalScrollbarWidth);
} }
if (pinchVirtualViewportEnabled()) { if (pinchVirtualViewportEnabled())
int contentAndScrollbarWidth = contentsSize().width(); view->resize(mainFrameSize());
if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlayScrollbar())
contentAndScrollbarWidth += view->verticalScrollbar()->width();
view->resize(m_pageScaleConstraintsSet.mainFrameSize(contentAndScrollbarWidth));
}
float newPageScaleFactor = pageScaleFactor(); float newPageScaleFactor = pageScaleFactor();
if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.finalConstraints().initialScale != -1) { if (m_pageScaleConstraintsSet.needsReset() && m_pageScaleConstraintsSet.finalConstraints().initialScale != -1) {
......
...@@ -508,6 +508,8 @@ public: ...@@ -508,6 +508,8 @@ public:
virtual void setTopControlsLayoutHeight(float) override; virtual void setTopControlsLayoutHeight(float) override;
IntSize mainFrameSize() const;
private: private:
void didUpdateTopControls(); void didUpdateTopControls();
void setTopControlsContentOffset(float); void setTopControlsContentOffset(float);
......
...@@ -1209,5 +1209,23 @@ TEST_F(PinchViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) ...@@ -1209,5 +1209,23 @@ TEST_F(PinchViewportTest, TestTopControlHidingResizeDoesntClampMainFrame)
EXPECT_EQ(500, frameView.scrollPositionDouble().y()); EXPECT_EQ(500, frameView.scrollPositionDouble().y());
} }
// Tests that when a new frame is created, it is created with the intended
// size (i.e. the contentWidth).
TEST_F(PinchViewportTest, TestMainFrameInitializationSizing)
{
initializeWithAndroidSettings();
webViewImpl()->setPageScaleFactorLimits(0.5, 2.0);
webViewImpl()->resize(IntSize(100, 200));
registerMockedHttpURLLoad("content-width-1000.html");
navigateTo(m_baseURL + "content-width-1000.html");
WebLocalFrameImpl* localFrame = webViewImpl()->mainFrameImpl();
FrameView& frameView = *localFrame->frameView();
localFrame->createFrameView();
EXPECT_SIZE_EQ(IntSize(200, 400), frameView.frameRect().size());
}
} // namespace } // namespace
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