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

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

Issue 893683003: Implement top controls show/hide functionality for main thread scrolling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix hiding at the page bottom issue 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
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 , m_fullscreenController(FullscreenController::create(this)) 406 , m_fullscreenController(FullscreenController::create(this))
407 , m_showFPSCounter(false) 407 , m_showFPSCounter(false)
408 , m_showPaintRects(false) 408 , m_showPaintRects(false)
409 , m_showDebugBorders(false) 409 , m_showDebugBorders(false)
410 , m_continuousPaintingEnabled(false) 410 , m_continuousPaintingEnabled(false)
411 , m_showScrollBottleneckRects(false) 411 , m_showScrollBottleneckRects(false)
412 , m_baseBackgroundColor(Color::white) 412 , m_baseBackgroundColor(Color::white)
413 , m_backgroundColorOverride(Color::transparent) 413 , m_backgroundColorOverride(Color::transparent)
414 , m_zoomFactorOverride(0) 414 , m_zoomFactorOverride(0)
415 , m_userGestureObserved(false) 415 , m_userGestureObserved(false)
416 , m_topControlsShownRatio(0) 416 , m_topControls(adoptPtr(new TopControls(this)))
417 , m_topControlsHeight(0)
418 , m_topControlsShrinkLayoutSize(true)
419 { 417 {
420 Page::PageClients pageClients; 418 Page::PageClients pageClients;
421 pageClients.chromeClient = &m_chromeClientImpl; 419 pageClients.chromeClient = &m_chromeClientImpl;
422 pageClients.contextMenuClient = &m_contextMenuClientImpl; 420 pageClients.contextMenuClient = &m_contextMenuClientImpl;
423 pageClients.editorClient = &m_editorClientImpl; 421 pageClients.editorClient = &m_editorClientImpl;
424 pageClients.dragClient = &m_dragClientImpl; 422 pageClients.dragClient = &m_dragClientImpl;
425 pageClients.inspectorClient = &m_inspectorClientImpl; 423 pageClients.inspectorClient = &m_inspectorClientImpl;
426 pageClients.spellCheckerClient = &m_spellCheckerClientImpl; 424 pageClients.spellCheckerClient = &m_spellCheckerClientImpl;
427 425
428 m_page = adoptPtrWillBeNoop(new Page(pageClients)); 426 m_page = adoptPtrWillBeNoop(new Page(pageClients));
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 688 }
691 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore, 689 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore,
692 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here. 690 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here.
693 eventSwallowed = true; 691 eventSwallowed = true;
694 m_client->didHandleGestureEvent(event, eventCancelled); 692 m_client->didHandleGestureEvent(event, eventCancelled);
695 return eventSwallowed; 693 return eventSwallowed;
696 case WebInputEvent::GestureScrollBegin: 694 case WebInputEvent::GestureScrollBegin:
697 m_client->cancelScheduledContentIntents(); 695 m_client->cancelScheduledContentIntents();
698 case WebInputEvent::GestureScrollEnd: 696 case WebInputEvent::GestureScrollEnd:
699 case WebInputEvent::GestureScrollUpdate: 697 case WebInputEvent::GestureScrollUpdate:
700 case WebInputEvent::GestureFlingStart: 698 case WebInputEvent::GestureFlingStart: {
699 // Top Controls scrolling happens before anything else. If top controls
700 // consumed any delta consider event consumed.
701 // FIXME: Add a flag in settings that controls top control feature.
aelias_OOO_until_Jul13 2015/02/13 02:03:17 I don't think we should ever add a setting. Top-c
majidvp 2015/02/18 21:03:57 Done.
702 float remainigDeltaY = 0.f;
aelias_OOO_until_Jul13 2015/02/13 02:03:17 Typo: "remaining"
majidvp 2015/02/18 21:03:57 Done.
703 eventSwallowed = m_topControls->handleGestureEvent(platformEvent, &remai nigDeltaY);
704
705 if (eventSwallowed) {
706 // Modify event to adjust vertical scroll delta before passing to |E ventHandler|.
aelias_OOO_until_Jul13 2015/02/13 02:03:17 Top controls don't have priority over scrollable s
bokan 2015/02/13 12:35:25 Right, I think this should go in EventHandler::han
majidvp 2015/02/18 21:03:57 I moved TopControls inside FrameHost and remove it
707 // The event is passed to |EventHandler| even if deltaY is fully con sumed by top
708 // controls to ensure that document consumes any horizontal scroll d elta.
709 platformEvent = PlatformGestureEventBuilder(mainFrameImpl()->frameVi ew(), event,
710 platformEvent.deltaX(), remainigDeltaY);
711 }
712
701 // Scrolling-related gesture events invoke EventHandler recursively for each frame down 713 // Scrolling-related gesture events invoke EventHandler recursively for each frame down
702 // the chain, doing a single-frame hit-test per frame. This matches hand leWheelEvent. 714 // the chain, doing a single-frame hit-test per frame. This matches hand leWheelEvent.
703 // Perhaps we could simplify things by rewriting scroll handling to work inner frame 715 // Perhaps we could simplify things by rewriting scroll handling to work inner frame
704 // out, and then unify with other gesture events. 716 // out, and then unify with other gesture events.
705 eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureS crollEvent(platformEvent); 717 eventSwallowed |= mainFrameImpl()->frame()->eventHandler().handleGesture ScrollEvent(platformEvent);
706 m_client->didHandleGestureEvent(event, eventCancelled); 718 m_client->didHandleGestureEvent(event, eventCancelled);
707 return eventSwallowed; 719 return eventSwallowed;
720 }
708 case WebInputEvent::GesturePinchBegin: 721 case WebInputEvent::GesturePinchBegin:
709 case WebInputEvent::GesturePinchEnd: 722 case WebInputEvent::GesturePinchEnd:
710 case WebInputEvent::GesturePinchUpdate: 723 case WebInputEvent::GesturePinchUpdate:
711 // Gesture pinch events are aborted in PageWidgetDelegate::handleInputEv ent and should 724 m_topControls->handleGestureEvent(platformEvent, 0);
712 // not reach here.
713 ASSERT_NOT_REACHED();
714 return false; 725 return false;
715 default: 726 default:
716 break; 727 break;
717 } 728 }
718 729
719 // Hit test across all frames and do touch adjustment as necessary for the e vent type. 730 // Hit test across all frames and do touch adjustment as necessary for the e vent type.
720 GestureEventWithHitTestResults targetedEvent = 731 GestureEventWithHitTestResults targetedEvent =
721 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(pl atformEvent); 732 m_page->deprecatedLocalMainFrame()->eventHandler().targetGestureEvent(pl atformEvent);
722 733
723 // Handle link highlighting outside the main switch to avoid getting lost in the 734 // Handle link highlighting outside the main switch to avoid getting lost in the
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 if (page()->inspectorController().deviceEmulationEnabled()) { 1712 if (page()->inspectorController().deviceEmulationEnabled()) {
1702 if (Document* document = mainFrameImpl()->frame()->document()) { 1713 if (Document* document = mainFrameImpl()->frame()->document()) {
1703 document->styleResolverChanged(); 1714 document->styleResolverChanged();
1704 document->mediaQueryAffectingValueChanged(); 1715 document->mediaQueryAffectingValueChanged();
1705 } 1716 }
1706 } 1717 }
1707 } 1718 }
1708 1719
1709 void WebViewImpl::setTopControlsShownRatio(float offset) 1720 void WebViewImpl::setTopControlsShownRatio(float offset)
1710 { 1721 {
1711 m_topControlsShownRatio = offset; 1722 m_topControls->setShownRatio(offset);
1712 m_layerTreeView->setTopControlsShownRatio(offset);
1713 didUpdateTopControls();
1714 } 1723 }
1715 1724
1716 void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayou tSize) 1725 void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayou tSize)
1717 { 1726 {
1718 if (m_topControlsHeight == height && m_topControlsShrinkLayoutSize == topCon trolsShrinkLayoutSize) 1727 m_topControls->setHeight(height);
1719 return; 1728 m_topControls->setShrinkViewport(topControlsShrinkLayoutSize);
1720 1729
1721 m_topControlsHeight = height; 1730 m_layerTreeView->setTopControlsHeight(height);
aelias_OOO_until_Jul13 2015/02/13 02:03:17 Would be more consistent to put this in didUpdateT
majidvp 2015/02/18 21:03:57 Done.
1722 m_topControlsShrinkLayoutSize = topControlsShrinkLayoutSize; 1731 m_layerTreeView->setTopControlsShrinkBlinkSize(topControlsShrinkLayoutSize);
1723 didUpdateTopControls(); 1732
1733 }
1734
1735 void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopC ontrolsState current, bool animate)
1736 {
1737 m_topControls->updateState(constraint, current, animate);
1738 m_layerTreeView->updateTopControlsState(constraint, current, animate);
1724 } 1739 }
1725 1740
1726 void WebViewImpl::didUpdateTopControls() 1741 void WebViewImpl::didUpdateTopControls()
1727 { 1742 {
1743 if (m_layerTreeView)
1744 m_layerTreeView->setTopControlsShownRatio(m_topControls->shownRatio());
1745
1728 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1746 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1729 if (!mainFrame) 1747 if (!mainFrame)
1730 return; 1748 return;
1731 1749
1732 FrameView* view = mainFrame->frameView(); 1750 FrameView* view = mainFrame->frameView();
1733 if (!view) 1751 if (!view)
1734 return; 1752 return;
1735 1753
1736 float topControlsViewportAdjustment = 0; 1754 float topControlsViewportAdjustment = m_topControls->layoutHeight() - m_topC ontrols->contentOffset();
1737 if (m_topControlsShrinkLayoutSize)
1738 topControlsViewportAdjustment += m_topControlsHeight;
1739 topControlsViewportAdjustment -= m_topControlsShownRatio * m_topControlsHeig ht;
1740 1755
1741 if (!pinchVirtualViewportEnabled()) { 1756 if (!pinchVirtualViewportEnabled()) {
1742 // The viewport bounds were adjusted on the compositor by this much due to top controls. Tell 1757 // The viewport bounds were adjusted on the compositor by this much due to top controls. Tell
1743 // the FrameView about it so it can make correct scroll offset clamping decisions during compositor 1758 // the FrameView about it so it can make correct scroll offset clamping decisions during compositor
1744 // commits. 1759 // commits.
1745 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment); 1760 view->setTopControlsViewportAdjustment(topControlsViewportAdjustment);
1746 } else { 1761 } else {
1747 PinchViewport& pinchViewport = page()->frameHost().pinchViewport(); 1762 PinchViewport& pinchViewport = page()->frameHost().pinchViewport();
1748 1763
1749 if (pinchViewport.visibleRect().isEmpty()) 1764 if (pinchViewport.visibleRect().isEmpty())
1750 return; 1765 return;
1751 1766
1752 pinchViewport.setTopControlsAdjustment(topControlsViewportAdjustment); 1767 pinchViewport.setTopControlsAdjustment(topControlsViewportAdjustment);
1753 1768
1754 // On ChromeOS the pinch viewport can change size independent of the layout view port due to the 1769 // On ChromeOS the pinch viewport can change size independent of the layout view port due to the
1755 // on screen keyboard so we should only set the FrameView adjustment on Android. 1770 // on screen keyboard so we should only set the FrameView adjustment on Android.
1756 if (settings() && settings()->mainFrameResizesAreOrientationChanges()) { 1771 if (settings() && settings()->mainFrameResizesAreOrientationChanges()) {
1757 // Shrink the FrameView by the amount that will maintain the aspect- ratio with the PinchViewport. 1772 // Shrink the FrameView by the amount that will maintain the aspect- ratio with the PinchViewport.
1758 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewp ort.visibleRect().height(); 1773 float aspectRatio = pinchViewport.visibleRect().width() / pinchViewp ort.visibleRect().height();
1759 float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars ).width() / aspectRatio; 1774 float newHeight = view->unscaledVisibleContentSize(ExcludeScrollbars ).width() / aspectRatio;
1760 float adjustment = newHeight - view->unscaledVisibleContentSize(Excl udeScrollbars).height(); 1775 float adjustment = newHeight - view->unscaledVisibleContentSize(Excl udeScrollbars).height();
1761 view->setTopControlsViewportAdjustment(adjustment); 1776 view->setTopControlsViewportAdjustment(adjustment);
1762 } 1777 }
1763 } 1778 }
1764 } 1779 }
1765 1780
1781 bool WebViewImpl::shouldTopControlsConsumeScroll(float scrollDeltaY)
1782 {
1783 // Always consume if it's in the direction to show the top controls.
1784 if (scrollDeltaY > 0)
1785 return true;
1786
1787 if (mainFrame()->scrollOffset().height < mainFrame()->maximumScrollOffset(). height)
1788 return true;
1789
1790 return false;
1791 }
1792
1766 void WebViewImpl::resize(const WebSize& newSize) 1793 void WebViewImpl::resize(const WebSize& newSize)
1767 { 1794 {
1768 if (m_shouldAutoResize || m_size == newSize) 1795 if (m_shouldAutoResize || m_size == newSize)
1769 return; 1796 return;
1770 1797
1771 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1798 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1772 if (!mainFrame) 1799 if (!mainFrame)
1773 return; 1800 return;
1774 1801
1775 FrameView* view = mainFrame->frameView(); 1802 FrameView* view = mainFrame->frameView();
(...skipping 2633 matching lines...) Expand 10 before | Expand all | Expand 10 after
4409 float topControlsShownRatioDelta) 4436 float topControlsShownRatioDelta)
4410 { 4437 {
4411 ASSERT(pinchVirtualViewportEnabled()); 4438 ASSERT(pinchVirtualViewportEnabled());
4412 4439
4413 if (!mainFrameImpl()) 4440 if (!mainFrameImpl())
4414 return; 4441 return;
4415 FrameView* frameView = mainFrameImpl()->frameView(); 4442 FrameView* frameView = mainFrameImpl()->frameView();
4416 if (!frameView) 4443 if (!frameView)
4417 return; 4444 return;
4418 4445
4419 setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelt a); 4446 m_topControls->updateShownRatio(topControlsShownRatioDelta);
4420 4447
4421 FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visible Rect().location(); 4448 FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visible Rect().location();
4422 pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height ); 4449 pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height );
4423 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, pinchViewp ortOffset); 4450 setPageScaleFactorAndLocation(pageScaleFactor() * pageScaleDelta, pinchViewp ortOffset);
4424 4451
4425 if (pageScaleDelta != 1) 4452 if (pageScaleDelta != 1)
4426 m_doubleTapZoomPending = false; 4453 m_doubleTapZoomPending = false;
4427 4454
4428 frameView->setElasticOverscroll(elasticOverscrollDelta + frameView->elasticO verscroll()); 4455 frameView->setElasticOverscroll(elasticOverscrollDelta + frameView->elasticO verscroll());
4429 4456
4430 updateMainFrameScrollPosition(frameView->scrollableArea()->scrollPositionDou ble() + 4457 updateMainFrameScrollPosition(frameView->scrollableArea()->scrollPositionDou ble() +
4431 DoubleSize(outerViewportDelta.width, outerViewportDelta.height), /* prog rammaticScroll */ false); 4458 DoubleSize(outerViewportDelta.width, outerViewportDelta.height), /* prog rammaticScroll */ false);
4432 } 4459 }
4433 4460
4434 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal eDelta, float topControlsShownRatioDelta) 4461 void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal eDelta, float topControlsShownRatioDelta)
4435 { 4462 {
4436 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) 4463 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
4437 return; 4464 return;
4438 4465
4439 setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelt a); 4466 m_topControls->updateShownRatio(topControlsShownRatioDelta);
4440 4467
4441 if (pageScaleDelta == 1) { 4468 if (pageScaleDelta == 1) {
4442 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB y", "x", scrollDelta.width, "y", scrollDelta.height); 4469 TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollB y", "x", scrollDelta.width, "y", scrollDelta.height);
4443 WebSize webScrollOffset = mainFrame()->scrollOffset(); 4470 WebSize webScrollOffset = mainFrame()->scrollOffset();
4444 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height); 4471 IntPoint scrollOffset(webScrollOffset.width + scrollDelta.width, webScro llOffset.height + scrollDelta.height);
4445 updateMainFrameScrollPosition(scrollOffset, false); 4472 updateMainFrameScrollPosition(scrollOffset, false);
4446 } else { 4473 } else {
4447 // The page scale changed, so apply a scale and scroll in a single 4474 // The page scale changed, so apply a scale and scroll in a single
4448 // operation. 4475 // operation.
4449 WebSize scrollOffset = mainFrame()->scrollOffset(); 4476 WebSize scrollOffset = mainFrame()->scrollOffset();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
4609 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4636 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4610 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4637 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4611 } 4638 }
4612 4639
4613 void WebViewImpl::forceNextWebGLContextCreationToFail() 4640 void WebViewImpl::forceNextWebGLContextCreationToFail()
4614 { 4641 {
4615 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); 4642 WebGLRenderingContext::forceNextWebGLContextCreationToFail();
4616 } 4643 }
4617 4644
4618 } // namespace blink 4645 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698