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

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: sievers@ review 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(
1880 FrameView* view, float topControlsHeight, bool topControlsShrinkLayout)
1872 { 1881 {
1873 DCHECK(mainFrameImpl()); 1882 DCHECK(mainFrameImpl());
1874 DCHECK(mainFrameImpl()->frame()->isLocalFrame()); 1883 DCHECK(mainFrameImpl()->frame()->isLocalFrame());
1875 1884
1885 topControls().setHeight(topControlsHeight, topControlsShrinkLayout);
1886
1876 { 1887 {
1877 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated. 1888 // Avoids unnecessary invalidations while various bits of state in TextA utosizer are updated.
1878 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page()); 1889 TextAutosizer::DeferUpdatePageInfo deferUpdatePageInfo(page());
1879 performResize(); 1890 performResize();
1880 } 1891 }
1881 1892
1882 m_fullscreenController->updateSize(); 1893 m_fullscreenController->updateSize();
1883 1894
1884 // Update lifecyle phases immediately to recalculate the minimum scale limit for rotation anchoring, 1895 // 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. 1896 // and to make sure that no lifecycle states are stale if this WebView is em bedded in another one.
1886 updateAllLifecyclePhases(); 1897 updateAllLifecyclePhases();
1887 } 1898 }
1888 1899
1889 void WebViewImpl::resize(const WebSize& newSize) 1900 void WebViewImpl::resizeWithTopControls(const WebSize& newSize, float topControl sHeight, bool topControlsShrinkLayout)
1890 { 1901 {
1891 if (m_shouldAutoResize || m_size == newSize) 1902 if (m_shouldAutoResize)
1903 return;
1904
1905 if (m_size == newSize
1906 && topControls().height() == topControlsHeight
1907 && topControls().shrinkViewport() == topControlsShrinkLayout)
1892 return; 1908 return;
1893 1909
1894 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) { 1910 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) {
1895 // Viewport resize for a remote main frame does not require any 1911 // Viewport resize for a remote main frame does not require any
1896 // particular action, but the state needs to reflect the correct size 1912 // 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 1913 // so that it can be used for initalization if the main frame gets
1898 // swapped to a LocalFrame at a later time. 1914 // swapped to a LocalFrame at a later time.
1899 m_size = newSize; 1915 m_size = newSize;
1900 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size); 1916 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size);
1901 page()->frameHost().visualViewport().setSize(m_size); 1917 page()->frameHost().visualViewport().setSize(m_size);
(...skipping 10 matching lines...) Expand all
1912 1928
1913 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1929 VisualViewport& visualViewport = page()->frameHost().visualViewport();
1914 1930
1915 bool isRotation = settings()->mainFrameResizesAreOrientationChanges() 1931 bool isRotation = settings()->mainFrameResizesAreOrientationChanges()
1916 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen(); 1932 && m_size.width && contentsSize().width() && newSize.width != m_size.wid th && !m_fullscreenController->isFullscreen();
1917 m_size = newSize; 1933 m_size = newSize;
1918 1934
1919 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY); 1935 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY);
1920 if (isRotation) { 1936 if (isRotation) {
1921 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet()); 1937 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoord s, pageScaleConstraintsSet());
1922 resizeViewWhileAnchored(view); 1938 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout );
1923 } else { 1939 } else {
1924 ResizeViewportAnchor anchor(*view, visualViewport); 1940 ResizeViewportAnchor anchor(*view, visualViewport);
1925 resizeViewWhileAnchored(view); 1941 resizeViewWhileAnchored(view, topControlsHeight, topControlsShrinkLayout );
1926 } 1942 }
1927 sendResizeEventAndRepaint(); 1943 sendResizeEventAndRepaint();
1928 } 1944 }
1929 1945
1946 void WebViewImpl::resize(const WebSize& newSize)
1947 {
1948 if (m_shouldAutoResize || m_size == newSize)
1949 return;
1950
1951 resizeWithTopControls(
1952 newSize, topControls().height(), topControls().shrinkViewport());
1953 }
1954
1930 void WebViewImpl::didEnterFullScreen() 1955 void WebViewImpl::didEnterFullScreen()
1931 { 1956 {
1932 m_fullscreenController->didEnterFullScreen(); 1957 m_fullscreenController->didEnterFullScreen();
1933 } 1958 }
1934 1959
1935 void WebViewImpl::didExitFullScreen() 1960 void WebViewImpl::didExitFullScreen()
1936 { 1961 {
1937 m_fullscreenController->didExitFullScreen(); 1962 m_fullscreenController->didExitFullScreen();
1938 } 1963 }
1939 1964
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 4120
4096 FrameView* view = webframe->frame()->view(); 4121 FrameView* view = webframe->frame()->view();
4097 4122
4098 postLayoutResize(webframe); 4123 postLayoutResize(webframe);
4099 4124
4100 // Relayout immediately to avoid violating the rule that needsLayout() 4125 // Relayout immediately to avoid violating the rule that needsLayout()
4101 // isn't set at the end of a layout. 4126 // isn't set at the end of a layout.
4102 if (view->needsLayout()) 4127 if (view->needsLayout())
4103 view->layout(); 4128 view->layout();
4104 4129
4105 // In case we didn't have a size when the top controls were updated.
4106 didUpdateTopControls();
4107
4108 m_client->didUpdateLayout(); 4130 m_client->didUpdateLayout();
4109 } 4131 }
4110 4132
4111 void WebViewImpl::didChangeContentsSize() 4133 void WebViewImpl::didChangeContentsSize()
4112 { 4134 {
4113 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor()); 4135 pageScaleConstraintsSet().didChangeContentsSize(contentsSize(), pageScaleFac tor());
4114 } 4136 }
4115 4137
4116 void WebViewImpl::pageScaleFactorChanged() 4138 void WebViewImpl::pageScaleFactorChanged()
4117 { 4139 {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
4353 const WebFloatSize& elasticOverscrollDelta, 4375 const WebFloatSize& elasticOverscrollDelta,
4354 float pageScaleDelta, 4376 float pageScaleDelta,
4355 float topControlsShownRatioDelta) 4377 float topControlsShownRatioDelta)
4356 { 4378 {
4357 if (!mainFrameImpl()) 4379 if (!mainFrameImpl())
4358 return; 4380 return;
4359 FrameView* frameView = mainFrameImpl()->frameView(); 4381 FrameView* frameView = mainFrameImpl()->frameView();
4360 if (!frameView) 4382 if (!frameView)
4361 return; 4383 return;
4362 4384
4385 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4386 VisualViewport& visualViewport = page()->frameHost().visualViewport();
4387
4388 // Store the desired offsets for visual and layout viewports before setting
4389 // the top controls ratio since doing so will change the bounds and move the
4390 // viewports to keep the offsets valid. The compositor may have already done
4391 // that so we don't want to double apply the deltas here.
4392 FloatPoint visualViewportOffset = visualViewport.visibleRect().location();
4393 visualViewportOffset.move(
4394 visualViewportDelta.width,
4395 visualViewportDelta.height);
4396 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4397 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4398
4363 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta); 4399 topControls().setShownRatio(topControls().shownRatio() + topControlsShownRat ioDelta);
4364 4400
4365 FloatPoint visualViewportOffset = page()->frameHost().visualViewport().visib leRect().location();
4366 visualViewportOffset.move(visualViewportDelta.width, visualViewportDelta.hei ght);
4367 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset); 4401 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, visualView portOffset);
4368 4402
4369 if (pageScaleDelta != 1) { 4403 if (pageScaleDelta != 1) {
4370 m_doubleTapZoomPending = false; 4404 m_doubleTapZoomPending = false;
4371 page()->frameHost().visualViewport().userDidChangeScale(); 4405 visualViewport.userDidChangeScale();
4372 } 4406 }
4373 4407
4374 m_elasticOverscroll += elasticOverscrollDelta; 4408 m_elasticOverscroll += elasticOverscrollDelta;
4375 frameView->didUpdateElasticOverscroll(); 4409 frameView->didUpdateElasticOverscroll();
4376 4410
4377 ScrollableArea* layoutViewport = frameView->layoutViewportScrollableArea();
4378
4379 DoublePoint layoutViewportPosition = layoutViewport->scrollPositionDouble()
4380 + DoubleSize(layoutViewportDelta.width, layoutViewportDelta.height);
4381
4382 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) { 4411 if (layoutViewport->scrollPositionDouble() != layoutViewportPosition) {
4383 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll); 4412 layoutViewport->setScrollPosition(layoutViewportPosition, CompositorScro ll);
4384 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader()) 4413 if (DocumentLoader* documentLoader = mainFrameImpl()->frame()->loader(). documentLoader())
4385 documentLoader->initialScrollState().wasScrolledByUser = true; 4414 documentLoader->initialScrollState().wasScrolledByUser = true;
4386 } 4415 }
4387 } 4416 }
4388 4417
4389 void WebViewImpl::recordFrameTimingEvent(FrameTimingEventType eventType, int64_t FrameId, const WebVector<WebFrameTimingEvent>& events) 4418 void WebViewImpl::recordFrameTimingEvent(FrameTimingEventType eventType, int64_t FrameId, const WebVector<WebFrameTimingEvent>& events)
4390 { 4419 {
4391 Frame* frame = m_page ? m_page->mainFrame() : 0; 4420 Frame* frame = m_page ? m_page->mainFrame() : 0;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4594 { 4623 {
4595 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4624 // 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. 4625 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4597 if (!page()) 4626 if (!page())
4598 return 1; 4627 return 1;
4599 4628
4600 return page()->deviceScaleFactor(); 4629 return page()->deviceScaleFactor();
4601 } 4630 }
4602 4631
4603 } // namespace blink 4632 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698