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

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

Issue 882683003: Normalize top controls offset to (0, 1), Blink-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rename to shownratio Created 5 years, 10 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
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 , m_fullscreenController(FullscreenController::create(this)) 405 , m_fullscreenController(FullscreenController::create(this))
406 , m_showFPSCounter(false) 406 , m_showFPSCounter(false)
407 , m_showPaintRects(false) 407 , m_showPaintRects(false)
408 , m_showDebugBorders(false) 408 , m_showDebugBorders(false)
409 , m_continuousPaintingEnabled(false) 409 , m_continuousPaintingEnabled(false)
410 , m_showScrollBottleneckRects(false) 410 , m_showScrollBottleneckRects(false)
411 , m_baseBackgroundColor(Color::white) 411 , m_baseBackgroundColor(Color::white)
412 , m_backgroundColorOverride(Color::transparent) 412 , m_backgroundColorOverride(Color::transparent)
413 , m_zoomFactorOverride(0) 413 , m_zoomFactorOverride(0)
414 , m_userGestureObserved(false) 414 , m_userGestureObserved(false)
415 , m_topControlsContentOffset(0) 415 , m_topControlsShownRatio(0)
416 , m_topControlsLayoutHeight(0) 416 , m_topControlsHeight(0)
417 , m_topControlsShrinkLayoutSize(true)
418 , m_topControlsOffsetIsNormalized(true)
417 { 419 {
418 Page::PageClients pageClients; 420 Page::PageClients pageClients;
419 pageClients.chromeClient = &m_chromeClientImpl; 421 pageClients.chromeClient = &m_chromeClientImpl;
420 pageClients.contextMenuClient = &m_contextMenuClientImpl; 422 pageClients.contextMenuClient = &m_contextMenuClientImpl;
421 pageClients.editorClient = &m_editorClientImpl; 423 pageClients.editorClient = &m_editorClientImpl;
422 pageClients.dragClient = &m_dragClientImpl; 424 pageClients.dragClient = &m_dragClientImpl;
423 pageClients.inspectorClient = &m_inspectorClientImpl; 425 pageClients.inspectorClient = &m_inspectorClientImpl;
424 pageClients.spellCheckerClient = &m_spellCheckerClientImpl; 426 pageClients.spellCheckerClient = &m_spellCheckerClientImpl;
425 427
426 m_page = adoptPtrWillBeNoop(new Page(pageClients)); 428 m_page = adoptPtrWillBeNoop(new Page(pageClients));
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 // and thus will not be invalidated in |FrameView::performPreLayoutTasks|. 1712 // and thus will not be invalidated in |FrameView::performPreLayoutTasks|.
1711 // Therefore we should force explicit media queries invalidation here. 1713 // Therefore we should force explicit media queries invalidation here.
1712 if (page()->inspectorController().deviceEmulationEnabled()) { 1714 if (page()->inspectorController().deviceEmulationEnabled()) {
1713 if (Document* document = localFrameRootTemporary()->frame()->document()) { 1715 if (Document* document = localFrameRootTemporary()->frame()->document()) {
1714 document->styleResolverChanged(); 1716 document->styleResolverChanged();
1715 document->mediaQueryAffectingValueChanged(); 1717 document->mediaQueryAffectingValueChanged();
1716 } 1718 }
1717 } 1719 }
1718 } 1720 }
1719 1721
1720 void WebViewImpl::setTopControlsContentOffset(float offset) 1722 void WebViewImpl::setTopControlsShownRatio(float offset)
1721 { 1723 {
1722 m_topControlsContentOffset = offset; 1724 m_topControlsShownRatio = offset;
1725 // TODO(aelias): Rename this to ShownRatio after CC side lands.
1723 m_layerTreeView->setTopControlsContentOffset(offset); 1726 m_layerTreeView->setTopControlsContentOffset(offset);
1724 didUpdateTopControls(); 1727 didUpdateTopControls();
1725 } 1728 }
1726 1729
1727 void WebViewImpl::setTopControlsLayoutHeight(float height) 1730 void WebViewImpl::setTopControlsLayoutHeight(float height)
1728 { 1731 {
1729 m_topControlsLayoutHeight = height; 1732 m_topControlsOffsetIsNormalized = false;
1733 setTopControlsHeight(height, true);
1734 }
1735
1736 void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayou tSize)
1737 {
1738 if (m_topControlsHeight == height && m_topControlsShrinkLayoutSize == topCon trolsShrinkLayoutSize)
1739 return;
1740
1741 m_topControlsHeight = height;
1742 m_topControlsShrinkLayoutSize = topControlsShrinkLayoutSize;
1730 didUpdateTopControls(); 1743 didUpdateTopControls();
1731 } 1744 }
1732 1745
1733 void WebViewImpl::didUpdateTopControls() 1746 void WebViewImpl::didUpdateTopControls()
1734 { 1747 {
1735 WebLocalFrameImpl* localFrameRoot = localFrameRootTemporary(); 1748 WebLocalFrameImpl* localFrameRoot = localFrameRootTemporary();
1736 if (!localFrameRoot) 1749 if (!localFrameRoot)
1737 return; 1750 return;
1738 1751
1739 FrameView* view = localFrameRoot->frameView(); 1752 FrameView* view = localFrameRoot->frameView();
1740 if (!view) 1753 if (!view)
1741 return; 1754 return;
1742 1755
1743 float topControlsViewportAdjustment = m_topControlsLayoutHeight - m_topContr olsContentOffset; 1756 float topControlsViewportAdjustment = 0;
1757 if (m_topControlsShrinkLayoutSize)
1758 topControlsViewportAdjustment += m_topControlsHeight;
1759 topControlsViewportAdjustment -= m_topControlsShownRatio * (m_topControlsOff setIsNormalized ? m_topControlsHeight : 1);
1760
1744 if (!pinchVirtualViewportEnabled()) { 1761 if (!pinchVirtualViewportEnabled()) {
1745 // The viewport bounds were adjusted on the compositor by this much due to top controls. Tell 1762 // The viewport bounds were adjusted on the compositor by this much due to top controls. Tell
1746 // the FrameView about it so it can make correct scroll offset clamping decisions during compositor 1763 // the FrameView about it so it can make correct scroll offset clamping decisions during compositor
1747 // commits. 1764 // commits.
1748 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment); 1765 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment);
1749 } else { 1766 } else {
1750 PinchViewport& pinchViewport = page()->frameHost().pinchViewport(); 1767 PinchViewport& pinchViewport = page()->frameHost().pinchViewport();
1751 1768
1752 if (pinchViewport.visibleRect().isEmpty()) 1769 if (pinchViewport.visibleRect().isEmpty())
1753 return; 1770 return;
1754 1771
1755 pinchViewport.setTopControlsAdjustment(topControlsViewportAdjustment); 1772 pinchViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1756 1773
1757 // On ChromeOS the pinch viewport can change size independent of the layout view port due to the 1774 // On ChromeOS the pinch viewport can change size independent of the layout view port due to the
1758 // on screen keyboard so we should only set the FrameView adjustment on Android. 1775 // on screen keyboard so we should only set the FrameView adjustment on Android.
1759 #if OS(ANDROID) 1776 if (settings() && settings()->mainFrameResizesAreOrientationChanges()) {
1760 // Shrink the FrameView by the amount that will maintain the aspect-rati o with the PinchViewport. 1777 // Shrink the FrameView by the amount that will maintain the aspect- ratio with the PinchViewport.
1761 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewport. visibleRect().height(); 1778 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewp ort.visibleRect().height();
1762 float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars).wi dth() / aspectRatio; 1779 float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars ).width() / aspectRatio;
1763 float adjustment = newHeight - view->unscaledVisibleContentSize(ExcludeS crollbars).height(); 1780 float adjustment = newHeight - view->unscaledVisibleContentSize(Excl udeScrollbars).height();
1764 view->setTopControlsViewportAdjustment(adjustment); 1781 view->setTopControlsViewportAdjustment(adjustment);
1765 #endif 1782 }
1766 } 1783 }
1767 } 1784 }
1768 1785
1769 void WebViewImpl::resize(const WebSize& newSize) 1786 void WebViewImpl::resize(const WebSize& newSize)
1770 { 1787 {
1771 if (m_shouldAutoResize || m_size == newSize) 1788 if (m_shouldAutoResize || m_size == newSize)
1772 return; 1789 return;
1773 1790
1774 WebLocalFrameImpl* localFrameRoot = localFrameRootTemporary(); 1791 WebLocalFrameImpl* localFrameRoot = localFrameRootTemporary();
1775 if (!localFrameRoot) 1792 if (!localFrameRoot)
(...skipping 2605 matching lines...) Expand 10 before | Expand all | Expand 10 after
4381 frameView->setInProgrammaticScroll(programmaticScroll); 4398 frameView->setInProgrammaticScroll(programmaticScroll);
4382 scrollableArea->notifyScrollPositionChanged(scrollPosition); 4399 scrollableArea->notifyScrollPositionChanged(scrollPosition);
4383 frameView->setInProgrammaticScroll(oldProgrammaticScroll); 4400 frameView->setInProgrammaticScroll(oldProgrammaticScroll);
4384 } 4401 }
4385 4402
4386 void WebViewImpl::applyViewportDeltas( 4403 void WebViewImpl::applyViewportDeltas(
4387 const WebSize& pinchViewportDelta, 4404 const WebSize& pinchViewportDelta,
4388 const WebSize& outerViewportDelta, 4405 const WebSize& outerViewportDelta,
4389 const WebFloatSize& elasticOverscrollDelta, 4406 const WebFloatSize& elasticOverscrollDelta,
4390 float pageScaleDelta, 4407 float pageScaleDelta,
4391 float topControlsDelta) 4408 float topControlsShownRatioDelta)
4392 { 4409 {
4393 applyViewportDeltas( 4410 applyViewportDeltas(
4394 WebFloatSize(pinchViewportDelta.width, pinchViewportDelta.height), 4411 WebFloatSize(pinchViewportDelta.width, pinchViewportDelta.height),
4395 WebFloatSize(outerViewportDelta.width, outerViewportDelta.height), 4412 WebFloatSize(outerViewportDelta.width, outerViewportDelta.height),
4396 elasticOverscrollDelta, 4413 elasticOverscrollDelta,
4397 pageScaleDelta, 4414 pageScaleDelta,
4398 topControlsDelta); 4415 topControlsShownRatioDelta);
4399 } 4416 }
4400 4417
4401 void WebViewImpl::applyViewportDeltas( 4418 void WebViewImpl::applyViewportDeltas(
4402 const WebFloatSize& pinchViewportDelta, 4419 const WebFloatSize& pinchViewportDelta,
4403 const WebFloatSize& outerViewportDelta, 4420 const WebFloatSize& outerViewportDelta,
4404 const WebFloatSize& elasticOverscrollDelta, 4421 const WebFloatSize& elasticOverscrollDelta,
4405 float pageScaleDelta, 4422 float pageScaleDelta,
4406 float topControlsDelta) 4423 float topControlsShownRatioDelta)
4407 { 4424 {
4408 ASSERT(pinchVirtualViewportEnabled()); 4425 ASSERT(pinchVirtualViewportEnabled());
4409 4426
4410 if (!mainFrameImpl()) 4427 if (!mainFrameImpl())
4411 return; 4428 return;
4412 FrameView* frameView = mainFrameImpl()->frameView(); 4429 FrameView* frameView = mainFrameImpl()->frameView();
4413 if (!frameView) 4430 if (!frameView)
4414 return; 4431 return;
4415 4432
4416 setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta); 4433 setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelt a);
4417 4434
4418 FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visible Rect().location(); 4435 FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visible Rect().location();
4419 pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height ); 4436 pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height );
4420 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, pinchViewp ortOffset); 4437 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, pinchViewp ortOffset);
4421 4438
4422 if (pageScaleDelta != 1) 4439 if (pageScaleDelta != 1)
4423 m_doubleTapZoomPending = false; 4440 m_doubleTapZoomPending = false;
4424 4441
4425 frameView->setElasticOverscroll(elasticOverscrollDelta + frameView->elasticO verscroll()); 4442 frameView->setElasticOverscroll(elasticOverscrollDelta + frameView->elasticO verscroll());
4426 4443
4427 updateMainFrameScrollPosition(frameView->scrollableArea()->scrollPositionDou ble() + 4444 updateMainFrameScrollPosition(frameView->scrollableArea()->scrollPositionDou ble() +
4428 DoubleSize(outerViewportDelta.width, outerViewportDelta.height), /* prog rammaticScroll */ false); 4445 DoubleSize(outerViewportDelta.width, outerViewportDelta.height), /* prog rammaticScroll */ false);
4429 } 4446 }
4430 4447
4431 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal eDelta, float topControlsDelta) 4448 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal eDelta, float topControlsShownRatioDelta)
4432 { 4449 {
4433 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4450 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4434 return; 4451 return;
4435 4452
4436 setTopControlsContentOffset(m_topControlsContentOffset + topControlsDelta); 4453 setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelt a);
4437 4454
4438 if (pageScaleDelta == 1) { 4455 if (pageScaleDelta == 1) {
4439 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB y", "x", scrollDelta.width, "y", scrollDelta.height); 4456 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB y", "x", scrollDelta.width, "y", scrollDelta.height);
4440 WebSize webScrollOffset = mainFrame()->scrollOffset(); 4457 WebSize webScrollOffset = mainFrame()->scrollOffset();
4441 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height); 4458 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height);
4442 updateMainFrameScrollPosition(scrollOffset, false); 4459 updateMainFrameScrollPosition(scrollOffset, false);
4443 } else { 4460 } else {
4444 // The page scale changed, so apply a scale and scroll in a single 4461 // The page scale changed, so apply a scale and scroll in a single
4445 // operation. 4462 // operation.
4446 WebSize scrollOffset = mainFrame()->scrollOffset(); 4463 WebSize scrollOffset = mainFrame()->scrollOffset();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
4606 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4623 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4607 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4624 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4608 } 4625 }
4609 4626
4610 void WebViewImpl::forceNextWebGLContextCreationToFail() 4627 void WebViewImpl::forceNextWebGLContextCreationToFail()
4611 { 4628 {
4612 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); 4629 WebGLRenderingContext::forceNextWebGLContextCreationToFail();
4613 } 4630 }
4614 4631
4615 } // namespace blink 4632 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | Source/web/tests/PinchViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698