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

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: Fixed anchoring to check width too Created 4 years, 8 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 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 updateMainFrameLayoutSize(); 1821 updateMainFrameLayoutSize();
1822 1822
1823 page()->frameHost().visualViewport().setSize(m_size); 1823 page()->frameHost().visualViewport().setSize(m_size);
1824 1824
1825 if (mainFrameImpl()->frameView()) { 1825 if (mainFrameImpl()->frameView()) {
1826 if (!mainFrameImpl()->frameView()->needsLayout()) 1826 if (!mainFrameImpl()->frameView()->needsLayout())
1827 postLayoutResize(mainFrameImpl()); 1827 postLayoutResize(mainFrameImpl());
1828 } 1828 }
1829 } 1829 }
1830 1830
1831 void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayou tSize)
1832 {
1833 topControls().setHeight(height, topControlsShrinkLayoutSize);
1834 }
1835
1836 void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopC ontrolsState current, bool animate) 1831 void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopC ontrolsState current, bool animate)
1837 { 1832 {
1838 topControls().updateConstraints(constraint); 1833 topControls().updateConstraints(constraint);
1839 if (m_layerTreeView) 1834 if (m_layerTreeView)
1840 m_layerTreeView->updateTopControlsState(constraint, current, animate); 1835 m_layerTreeView->updateTopControlsState(constraint, current, animate);
1841 } 1836 }
1842 1837
1843 void WebViewImpl::didUpdateTopControls() 1838 void WebViewImpl::didUpdateTopControls()
1844 { 1839 {
1845 if (m_layerTreeView) { 1840 if (m_layerTreeView) {
1846 m_layerTreeView->setTopControlsShownRatio(topControls().shownRatio()); 1841 m_layerTreeView->setTopControlsShownRatio(topControls().shownRatio());
1847 m_layerTreeView->setTopControlsHeight(topControls().height(), topControl s().shrinkViewport()); 1842 m_layerTreeView->setTopControlsHeight(topControls().height(), topControl s().shrinkViewport());
1848 } 1843 }
1849 1844
1850 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1845 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1851 if (!mainFrame) 1846 if (!mainFrame)
1852 return; 1847 return;
1853 1848
1854 FrameView* view = mainFrame->frameView(); 1849 FrameView* view = mainFrame->frameView();
1855 if (!view) 1850 if (!view)
1856 return; 1851 return;
1857 1852
1858 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1853 VisualViewport& visualViewport = page()->frameHost().visualViewport();
1859 float topControlsViewportAdjustment = topControls().layoutHeight() - topCont rols().contentOffset();
1860 visualViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1861 1854
1862 // Shrink the FrameView by the amount that will maintain the aspect-ratio wi th the VisualViewport. 1855 {
1863 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment / minim umPageScaleFactor()); 1856 // This object will save the current visual viewport offset w.r.t. the
1857 // document and restore it when the object goes out of scope. It's
1858 // needed since the top controls adjustment will change the maximum
1859 // scroll offset and we may need to reposition them to keep the user's
1860 // apparent position unchanged.
1861 ResizeViewportAnchor anchor(*view, visualViewport);
1862
1863 float topControlsViewportAdjustment =
1864 topControls().layoutHeight() - topControls().contentOffset();
1865 visualViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1866
1867 // Since the FrameView is sized to be the visual viewport at minimum
1868 // scale, its adjustment must also be scaled by the minimum scale.
1869 view->setTopControlsViewportAdjustment(
1870 topControlsViewportAdjustment / minimumPageScaleFactor());
1871 }
1864 } 1872 }
1865 1873
1866 TopControls& WebViewImpl::topControls() 1874 TopControls& WebViewImpl::topControls()
1867 { 1875 {
1868 return page()->frameHost().topControls(); 1876 return page()->frameHost().topControls();
1869 } 1877 }
1870 1878
1871 void WebViewImpl::resizeViewWhileAnchored(FrameView* view) 1879 void WebViewImpl::resizeViewWhileAnchored(FrameView* view, float topControlsHeig ht, bool topControlsShrinkLayoutSize)
1872 { 1880 {
1873 DCHECK(mainFrameImpl()); 1881 DCHECK(mainFrameImpl());
1874 DCHECK(mainFrameImpl()->frame()->isLocalFrame()); 1882 DCHECK(mainFrameImpl()->frame()->isLocalFrame());
1875 1883
1884 topControls().setHeight(topControlsHeight, topControlsShrinkLayoutSize);
1885
1876 { 1886 {
1877 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated. 1887 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated.
1878 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page()); 1888 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
1879 performResize(); 1889 performResize();
1880 } 1890 }
1881 1891
1882 m_fullscreenController->updateSize(); 1892 m_fullscreenController->updateSize();
1883 1893
1884 // Update lifecyle phases immediately to recalculate the minimum scale limit for rotation anchoring, 1894 // Update lifecyle phases immediately to recalculate the minimum scale limit for rotation anchoring,
1885 // and to make sure that no lifecycle states are stale if this WebView is em bedded in another one. 1895 // and to make sure that no lifecycle states are stale if this WebView is em bedded in another one.
1886 updateAllLifecyclePhases(); 1896 updateAllLifecyclePhases();
1887 } 1897 }
1888 1898
1889 void WebViewImpl::resize(const WebSize& newSize) 1899 void WebViewImpl::resize(const WebSize& newSize, float topControlsHeight, bool t opControlsShrinkLayoutSize)
1890 { 1900 {
1891 if (m_shouldAutoResize || m_size == newSize) 1901 if (m_shouldAutoResize
1902 || (m_size == newSize
1903 && topControlsHeight == topControls().height()
1904 && topControlsShrinkLayoutSize == topControls().shrinkViewport()))
1892 return; 1905 return;
1893 1906
1894 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) { 1907 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) {
1895 // Viewport resize for a remote main frame does not require any 1908 // Viewport resize for a remote main frame does not require any
1896 // particular action, but the state needs to reflect the correct size 1909 // particular action, but the state needs to reflect the correct size
1897 // so that it can be used for initalization if the main frame gets 1910 // so that it can be used for initalization if the main frame gets
1898 // swapped to a LocalFrame at a later time. 1911 // swapped to a LocalFrame at a later time.
1899 m_size = newSize; 1912 m_size = newSize;
1900 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size); 1913 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size);
1901 page()->frameHost().visualViewport().setSize(m_size); 1914 page()->frameHost().visualViewport().setSize(m_size);
(...skipping 10 matching lines...) Expand all
1912 1925
1913 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1926 VisualViewport& visualViewport = page()->frameHost().visualViewport();
1914 1927
1915 bool isRotation = settings()->mainFrameResizesAreOrientationChanges() 1928 bool isRotation = settings()->mainFrameResizesAreOrientationChanges()
1916 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen(); 1929 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen();
1917 m_size = newSize; 1930 m_size = newSize;
1918 1931
1919 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY); 1932 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY);
1920 if (isRotation) { 1933 if (isRotation) {
1921 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet()); 1934 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet());
1922 resizeViewWhileAnchored(view); 1935 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout Size);
1923 } else { 1936 } else {
1924 ResizeViewportAnchor anchor(*view, visualViewport); 1937 ResizeViewportAnchor anchor(*view, visualViewport);
1925 resizeViewWhileAnchored(view); 1938 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout Size);
1926 } 1939 }
1927 sendResizeEventAndRepaint(); 1940 sendResizeEventAndRepaint();
1928 } 1941 }
1929 1942
1943 void WebViewImpl::resize(const WebSize& newSize)
aelias_OOO_until_Jul13 2016/04/07 02:39:54 Does this still need to exist? Can we make all cal
bokan 2016/04/07 02:42:37 Unfortunately, there's lots of WebWidget types tha
aelias_OOO_until_Jul13 2016/04/07 02:50:23 Should the expanded resize() method be defined in
1944 {
1945 resize(newSize, topControls().height(), topControls().shrinkViewport());
1946 }
1947
1930 void WebViewImpl::didEnterFullScreen() 1948 void WebViewImpl::didEnterFullScreen()
1931 { 1949 {
1932 m_fullscreenController->didEnterFullScreen(); 1950 m_fullscreenController->didEnterFullScreen();
1933 } 1951 }
1934 1952
1935 void WebViewImpl::didExitFullScreen() 1953 void WebViewImpl::didExitFullScreen()
1936 { 1954 {
1937 m_fullscreenController->didExitFullScreen(); 1955 m_fullscreenController->didExitFullScreen();
1938 } 1956 }
1939 1957
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 4113
4096 FrameView* view = webframe->frame()->view(); 4114 FrameView* view = webframe->frame()->view();
4097 4115
4098 postLayoutResize(webframe); 4116 postLayoutResize(webframe);
4099 4117
4100 // Relayout immediately to avoid violating the rule that needsLayout() 4118 // Relayout immediately to avoid violating the rule that needsLayout()
4101 // isn't set at the end of a layout. 4119 // isn't set at the end of a layout.
4102 if (view->needsLayout()) 4120 if (view->needsLayout())
4103 view->layout(); 4121 view->layout();
4104 4122
4105 // In case we didn't have a size when the top controls were updated.
4106 didUpdateTopControls();
4107
4108 m_client->didUpdateLayout(); 4123 m_client->didUpdateLayout();
4109 } 4124 }
4110 4125
4111 void WebViewImpl::didChangeContentsSize() 4126 void WebViewImpl::didChangeContentsSize()
4112 { 4127 {
4113 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor()); 4128 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor());
4114 } 4129 }
4115 4130
4116 void WebViewImpl::pageScaleFactorChanged() 4131 void WebViewImpl::pageScaleFactorChanged()
4117 { 4132 {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
4353 const WebFloatSize& elasticOverscrollDelta, 4368 const WebFloatSize& elasticOverscrollDelta,
4354 float pageScaleDelta, 4369 float pageScaleDelta,
4355 float topControlsShownRatioDelta) 4370 float topControlsShownRatioDelta)
4356 { 4371 {
4357 if (!mainFrameImpl()) 4372 if (!mainFrameImpl())
4358 return; 4373 return;
4359 FrameView* frameView = mainFrameImpl()->frameView(); 4374 FrameView* frameView = mainFrameImpl()->frameView();
4360 if (!frameView) 4375 if (!frameView)
4361 return; 4376 return;
4362 4377
4378 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4379 VisualViewport& visualViewport = page()->frameHost().visualViewport();
4380
4381 // Store the desired offsets for visual and layout viewports before setting
4382 // the top controls ratio since doing so will change the bounds and move the
4383 // viewports to keep the offsets valid. The compositor may have already done
4384 // that so we don't want to double apply the deltas here.
4385 FloatPoint visualViewportOffset = visualViewport.visibleRect().location();
4386 visualViewportOffset.move(
4387 visualViewportDelta.width,
4388 visualViewportDelta.height);
4389 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4390 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4391
4363 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta); 4392 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta);
4364 4393
4365 FloatPoint visualViewportOffset = page()->frameHost().visualViewport().visib leRect().location();
4366 visualViewportOffset.move(visualViewportDelta.width, visualViewportDelta.hei ght);
4367 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset); 4394 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset);
4368 4395
4369 if (pageScaleDelta != 1) { 4396 if (pageScaleDelta != 1) {
4370 m_doubleTapZoomPending = false; 4397 m_doubleTapZoomPending = false;
4371 page()->frameHost().visualViewport().userDidChangeScale(); 4398 visualViewport.userDidChangeScale();
4372 } 4399 }
4373 4400
4374 m_elasticOverscroll += elasticOverscrollDelta; 4401 m_elasticOverscroll += elasticOverscrollDelta;
4375 frameView->didUpdateElasticOverscroll(); 4402 frameView->didUpdateElasticOverscroll();
4376 4403
4377 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4378
4379 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4380 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4381
4382 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) { 4404 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) {
4383 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll); 4405 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll);
4384 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader()) 4406 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader())
4385 documentLoader->initialScrollState().wasScrolledByUser = true; 4407 documentLoader->initialScrollState().wasScrolledByUser = true;
4386 } 4408 }
4387 } 4409 }
4388 4410
4389 void WebViewImpl::recordFrameTimingEvent(FrameTimingEventType eventType, int64_t FrameId, const WebVector<WebFrameTimingEvent>& events) 4411 void WebViewImpl::recordFrameTimingEvent(FrameTimingEventType eventType, int64_t FrameId, const WebVector<WebFrameTimingEvent>& events)
4390 { 4412 {
4391 Frame* frame = m_page ? m_page->mainFrame() : 0; 4413 Frame* frame = m_page ? m_page->mainFrame() : 0;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4594 { 4616 {
4595 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4617 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4596 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4618 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4597 if (!page()) 4619 if (!page())
4598 return 1; 4620 return 1;
4599 4621
4600 return page()->deviceScaleFactor(); 4622 return page()->deviceScaleFactor();
4601 } 4623 }
4602 4624
4603 } // namespace blink 4625 } // 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