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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 1844013002: Fix main thread top controls scrolling to mirror CC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@propertyTreesBoundsDelta
Patch Set: Build fix after rebase Created 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 updateMainFrameLayoutSize(); 1810 updateMainFrameLayoutSize();
1811 1811
1812 page()->frameHost().visualViewport().setSize(m_size); 1812 page()->frameHost().visualViewport().setSize(m_size);
1813 1813
1814 if (mainFrameImpl()->frameView()) { 1814 if (mainFrameImpl()->frameView()) {
1815 if (!mainFrameImpl()->frameView()->needsLayout()) 1815 if (!mainFrameImpl()->frameView()->needsLayout())
1816 postLayoutResize(mainFrameImpl()); 1816 postLayoutResize(mainFrameImpl());
1817 } 1817 }
1818 } 1818 }
1819 1819
1820 void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayou tSize)
1821 {
1822 topControls().setHeight(height, topControlsShrinkLayoutSize);
1823 }
1824
1825 void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopC ontrolsState current, bool animate) 1820 void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopC ontrolsState current, bool animate)
1826 { 1821 {
1827 topControls().updateConstraints(constraint); 1822 topControls().updateConstraints(constraint);
1828 if (m_layerTreeView) 1823 if (m_layerTreeView)
1829 m_layerTreeView->updateTopControlsState(constraint, current, animate); 1824 m_layerTreeView->updateTopControlsState(constraint, current, animate);
1830 } 1825 }
1831 1826
1832 void WebViewImpl::didUpdateTopControls() 1827 void WebViewImpl::didUpdateTopControls()
1833 { 1828 {
1834 if (m_layerTreeView) { 1829 if (m_layerTreeView) {
1835 m_layerTreeView->setTopControlsShownRatio(topControls().shownRatio()); 1830 m_layerTreeView->setTopControlsShownRatio(topControls().shownRatio());
1836 m_layerTreeView->setTopControlsHeight(topControls().height(), topControl s().shrinkViewport()); 1831 m_layerTreeView->setTopControlsHeight(topControls().height(), topControl s().shrinkViewport());
1837 } 1832 }
1838 1833
1839 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1834 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1840 if (!mainFrame) 1835 if (!mainFrame)
1841 return; 1836 return;
1842 1837
1843 FrameView* view = mainFrame->frameView(); 1838 FrameView* view = mainFrame->frameView();
1844 if (!view) 1839 if (!view)
1845 return; 1840 return;
1846 1841
1847 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1842 VisualViewport& visualViewport = page()->frameHost().visualViewport();
1848 float topControlsViewportAdjustment = topControls().layoutHeight() - topCont rols().contentOffset();
1849 visualViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1850 1843
1851 // Shrink the FrameView by the amount that will maintain the aspect-ratio wi th the VisualViewport. 1844 {
1852 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment / minim umPageScaleFactor()); 1845 // This object will save the current visual viewport offset w.r.t. the
1846 // document and restore it when the object goes out of scope. It's
1847 // needed since the top controls adjustment will change the maximum
1848 // scroll offset and we may need to reposition them to keep the user's
1849 // apparent position unchanged.
1850 ResizeViewportAnchor anchor(*view, visualViewport);
1851
1852 float topControlsViewportAdjustment =
1853 topControls().layoutHeight() - topControls().contentOffset();
1854 visualViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1855
1856 // Since the FrameView is sized to be the visual viewport at minimum
1857 // scale, its adjustment must also be scaled by the minimum scale.
1858 view->setTopControlsViewportAdjustment(
1859 topControlsViewportAdjustment / minimumPageScaleFactor());
1860 }
1853 } 1861 }
1854 1862
1855 TopControls& WebViewImpl::topControls() 1863 TopControls& WebViewImpl::topControls()
1856 { 1864 {
1857 return page()->frameHost().topControls(); 1865 return page()->frameHost().topControls();
1858 } 1866 }
1859 1867
1860 void WebViewImpl::resizeViewWhileAnchored(FrameView* view) 1868 void WebViewImpl::resizeViewWhileAnchored(
1869 FrameView* view, float topControlsHeight, bool topControlsShrinkLayout)
1861 { 1870 {
1862 DCHECK(mainFrameImpl()); 1871 DCHECK(mainFrameImpl());
1863 DCHECK(mainFrameImpl()->frame()->isLocalFrame()); 1872 DCHECK(mainFrameImpl()->frame()->isLocalFrame());
1864 1873
1874 topControls().setHeight(topControlsHeight, topControlsShrinkLayout);
1875
1865 { 1876 {
1866 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated. 1877 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated.
1867 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page()); 1878 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
1868 performResize(); 1879 performResize();
1869 } 1880 }
1870 1881
1871 m_fullscreenController->updateSize(); 1882 m_fullscreenController->updateSize();
1872 1883
1873 // Update lifecyle phases immediately to recalculate the minimum scale limit for rotation anchoring, 1884 // Update lifecyle phases immediately to recalculate the minimum scale limit for rotation anchoring,
1874 // and to make sure that no lifecycle states are stale if this WebView is em bedded in another one. 1885 // and to make sure that no lifecycle states are stale if this WebView is em bedded in another one.
1875 updateAllLifecyclePhases(); 1886 updateAllLifecyclePhases();
1876 } 1887 }
1877 1888
1878 void WebViewImpl::resize(const WebSize& newSize) 1889 void WebViewImpl::resizeWithTopControls(const WebSize& newSize, float topControl sHeight, bool topControlsShrinkLayout)
1879 { 1890 {
1880 if (m_shouldAutoResize || m_size == newSize) 1891 if (m_shouldAutoResize)
1892 return;
1893
1894 if (m_size == newSize
1895 && topControls().height() == topControlsHeight
1896 && topControls().shrinkViewport() == topControlsShrinkLayout)
1881 return; 1897 return;
1882 1898
1883 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) { 1899 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) {
1884 // Viewport resize for a remote main frame does not require any 1900 // Viewport resize for a remote main frame does not require any
1885 // particular action, but the state needs to reflect the correct size 1901 // particular action, but the state needs to reflect the correct size
1886 // so that it can be used for initalization if the main frame gets 1902 // so that it can be used for initalization if the main frame gets
1887 // swapped to a LocalFrame at a later time. 1903 // swapped to a LocalFrame at a later time.
1888 m_size = newSize; 1904 m_size = newSize;
1889 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size); 1905 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size);
1890 page()->frameHost().visualViewport().setSize(m_size); 1906 page()->frameHost().visualViewport().setSize(m_size);
(...skipping 10 matching lines...) Expand all
1901 1917
1902 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1918 VisualViewport& visualViewport = page()->frameHost().visualViewport();
1903 1919
1904 bool isRotation = settings()->mainFrameResizesAreOrientationChanges() 1920 bool isRotation = settings()->mainFrameResizesAreOrientationChanges()
1905 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen(); 1921 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen();
1906 m_size = newSize; 1922 m_size = newSize;
1907 1923
1908 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY); 1924 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY);
1909 if (isRotation) { 1925 if (isRotation) {
1910 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet()); 1926 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet());
1911 resizeViewWhileAnchored(view); 1927 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout );
1912 } else { 1928 } else {
1913 ResizeViewportAnchor anchor(*view, visualViewport); 1929 ResizeViewportAnchor anchor(*view, visualViewport);
1914 resizeViewWhileAnchored(view); 1930 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout );
1915 } 1931 }
1916 sendResizeEventAndRepaint(); 1932 sendResizeEventAndRepaint();
1917 } 1933 }
1918 1934
1935 void WebViewImpl::resize(const WebSize& newSize)
1936 {
1937 if (m_shouldAutoResize || m_size == newSize)
1938 return;
1939
1940 resizeWithTopControls(
1941 newSize, topControls().height(), topControls().shrinkViewport());
1942 }
1943
1919 void WebViewImpl::didEnterFullScreen() 1944 void WebViewImpl::didEnterFullScreen()
1920 { 1945 {
1921 m_fullscreenController->didEnterFullScreen(); 1946 m_fullscreenController->didEnterFullScreen();
1922 } 1947 }
1923 1948
1924 void WebViewImpl::didExitFullScreen() 1949 void WebViewImpl::didExitFullScreen()
1925 { 1950 {
1926 m_fullscreenController->didExitFullScreen(); 1951 m_fullscreenController->didExitFullScreen();
1927 } 1952 }
1928 1953
(...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after
4009 4034
4010 FrameView* view = webframe->frame()->view(); 4035 FrameView* view = webframe->frame()->view();
4011 4036
4012 postLayoutResize(webframe); 4037 postLayoutResize(webframe);
4013 4038
4014 // Relayout immediately to avoid violating the rule that needsLayout() 4039 // Relayout immediately to avoid violating the rule that needsLayout()
4015 // isn't set at the end of a layout. 4040 // isn't set at the end of a layout.
4016 if (view->needsLayout()) 4041 if (view->needsLayout())
4017 view->layout(); 4042 view->layout();
4018 4043
4019 // In case we didn't have a size when the top controls were updated.
4020 didUpdateTopControls();
4021
4022 m_client->didUpdateLayout(); 4044 m_client->didUpdateLayout();
4023 } 4045 }
4024 4046
4025 void WebViewImpl::didChangeContentsSize() 4047 void WebViewImpl::didChangeContentsSize()
4026 { 4048 {
4027 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor()); 4049 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor());
4028 } 4050 }
4029 4051
4030 void WebViewImpl::pageScaleFactorChanged() 4052 void WebViewImpl::pageScaleFactorChanged()
4031 { 4053 {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
4269 const WebFloatSize& elasticOverscrollDelta, 4291 const WebFloatSize& elasticOverscrollDelta,
4270 float pageScaleDelta, 4292 float pageScaleDelta,
4271 float topControlsShownRatioDelta) 4293 float topControlsShownRatioDelta)
4272 { 4294 {
4273 if (!mainFrameImpl()) 4295 if (!mainFrameImpl())
4274 return; 4296 return;
4275 FrameView* frameView = mainFrameImpl()->frameView(); 4297 FrameView* frameView = mainFrameImpl()->frameView();
4276 if (!frameView) 4298 if (!frameView)
4277 return; 4299 return;
4278 4300
4301 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4302 VisualViewport& visualViewport = page()->frameHost().visualViewport();
4303
4304 // Store the desired offsets for visual and layout viewports before setting
4305 // the top controls ratio since doing so will change the bounds and move the
4306 // viewports to keep the offsets valid. The compositor may have already done
4307 // that so we don't want to double apply the deltas here.
4308 FloatPoint visualViewportOffset = visualViewport.visibleRect().location();
4309 visualViewportOffset.move(
4310 visualViewportDelta.width,
4311 visualViewportDelta.height);
4312 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4313 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4314
4279 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta); 4315 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta);
4280 4316
4281 FloatPoint visualViewportOffset = page()->frameHost().visualViewport().visib leRect().location();
4282 visualViewportOffset.move(visualViewportDelta.width, visualViewportDelta.hei ght);
4283 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset); 4317 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset);
4284 4318
4285 if (pageScaleDelta != 1) { 4319 if (pageScaleDelta != 1) {
4286 m_doubleTapZoomPending = false; 4320 m_doubleTapZoomPending = false;
4287 page()->frameHost().visualViewport().userDidChangeScale(); 4321 visualViewport.userDidChangeScale();
4288 } 4322 }
4289 4323
4290 m_elasticOverscroll += elasticOverscrollDelta; 4324 m_elasticOverscroll += elasticOverscrollDelta;
4291 frameView->didUpdateElasticOverscroll(); 4325 frameView->didUpdateElasticOverscroll();
4292 4326
4293 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4294
4295 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4296 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4297
4298 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) { 4327 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) {
4299 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll); 4328 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll);
4300 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader()) 4329 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader())
4301 documentLoader->initialScrollState().wasScrolledByUser = true; 4330 documentLoader->initialScrollState().wasScrolledByUser = true;
4302 } 4331 }
4303 } 4332 }
4304 4333
4305 void WebViewImpl::updateLayerTreeViewport() 4334 void WebViewImpl::updateLayerTreeViewport()
4306 { 4335 {
4307 if (!page() || !m_layerTreeView) 4336 if (!page() || !m_layerTreeView)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4489 { 4518 {
4490 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4519 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4491 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4520 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4492 if (!page()) 4521 if (!page())
4493 return 1; 4522 return 1;
4494 4523
4495 return page()->deviceScaleFactor(); 4524 return page()->deviceScaleFactor();
4496 } 4525 }
4497 4526
4498 } // namespace blink 4527 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/Source/web/tests/TopControlsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698