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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/web/WebViewImpl.cpp
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index c3bb8bde0a36465d823cec376a721c2b76cbac74..f13adc2aabd74fbe5d24a052076aaf6268b85e75 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -413,9 +413,7 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
, m_backgroundColorOverride(Color::transparent)
, m_zoomFactorOverride(0)
, m_userGestureObserved(false)
- , m_topControlsShownRatio(0)
- , m_topControlsHeight(0)
- , m_topControlsShrinkLayoutSize(true)
+ , m_topControls(adoptPtr(new TopControls(this)))
{
Page::PageClients pageClients;
pageClients.chromeClient = &m_chromeClientImpl;
@@ -697,20 +695,33 @@ bool WebViewImpl::handleGestureEvent(const WebGestureEvent& event)
m_client->cancelScheduledContentIntents();
case WebInputEvent::GestureScrollEnd:
case WebInputEvent::GestureScrollUpdate:
- case WebInputEvent::GestureFlingStart:
+ case WebInputEvent::GestureFlingStart: {
+ // Top Controls scrolling happens before anything else. If top controls
+ // consumed any delta consider event consumed.
+ // 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.
+ float remainigDeltaY = 0.f;
aelias_OOO_until_Jul13 2015/02/13 02:03:17 Typo: "remaining"
majidvp 2015/02/18 21:03:57 Done.
+ eventSwallowed = m_topControls->handleGestureEvent(platformEvent, &remainigDeltaY);
+
+ if (eventSwallowed) {
+ // Modify event to adjust vertical scroll delta before passing to |EventHandler|.
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
+ // The event is passed to |EventHandler| even if deltaY is fully consumed by top
+ // controls to ensure that document consumes any horizontal scroll delta.
+ platformEvent = PlatformGestureEventBuilder(mainFrameImpl()->frameView(), event,
+ platformEvent.deltaX(), remainigDeltaY);
+ }
+
// Scrolling-related gesture events invoke EventHandler recursively for each frame down
// the chain, doing a single-frame hit-test per frame. This matches handleWheelEvent.
// Perhaps we could simplify things by rewriting scroll handling to work inner frame
// out, and then unify with other gesture events.
- eventSwallowed = mainFrameImpl()->frame()->eventHandler().handleGestureScrollEvent(platformEvent);
+ eventSwallowed |= mainFrameImpl()->frame()->eventHandler().handleGestureScrollEvent(platformEvent);
m_client->didHandleGestureEvent(event, eventCancelled);
return eventSwallowed;
+ }
case WebInputEvent::GesturePinchBegin:
case WebInputEvent::GesturePinchEnd:
case WebInputEvent::GesturePinchUpdate:
- // Gesture pinch events are aborted in PageWidgetDelegate::handleInputEvent and should
- // not reach here.
- ASSERT_NOT_REACHED();
+ m_topControls->handleGestureEvent(platformEvent, 0);
return false;
default:
break;
@@ -1708,23 +1719,30 @@ void WebViewImpl::performResize()
void WebViewImpl::setTopControlsShownRatio(float offset)
{
- m_topControlsShownRatio = offset;
- m_layerTreeView->setTopControlsShownRatio(offset);
- didUpdateTopControls();
+ m_topControls->setShownRatio(offset);
}
void WebViewImpl::setTopControlsHeight(float height, bool topControlsShrinkLayoutSize)
{
- if (m_topControlsHeight == height && m_topControlsShrinkLayoutSize == topControlsShrinkLayoutSize)
- return;
+ m_topControls->setHeight(height);
+ m_topControls->setShrinkViewport(topControlsShrinkLayoutSize);
- m_topControlsHeight = height;
- m_topControlsShrinkLayoutSize = topControlsShrinkLayoutSize;
- didUpdateTopControls();
+ 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.
+ m_layerTreeView->setTopControlsShrinkBlinkSize(topControlsShrinkLayoutSize);
+
+}
+
+void WebViewImpl::updateTopControlsState(WebTopControlsState constraint, WebTopControlsState current, bool animate)
+{
+ m_topControls->updateState(constraint, current, animate);
+ m_layerTreeView->updateTopControlsState(constraint, current, animate);
}
void WebViewImpl::didUpdateTopControls()
{
+ if (m_layerTreeView)
+ m_layerTreeView->setTopControlsShownRatio(m_topControls->shownRatio());
+
WebLocalFrameImpl* mainFrame = mainFrameImpl();
if (!mainFrame)
return;
@@ -1733,10 +1751,7 @@ void WebViewImpl::didUpdateTopControls()
if (!view)
return;
- float topControlsViewportAdjustment = 0;
- if (m_topControlsShrinkLayoutSize)
- topControlsViewportAdjustment += m_topControlsHeight;
- topControlsViewportAdjustment -= m_topControlsShownRatio * m_topControlsHeight;
+ float topControlsViewportAdjustment = m_topControls->layoutHeight() - m_topControls->contentOffset();
if (!pinchVirtualViewportEnabled()) {
// The viewport bounds were adjusted on the compositor by this much due to top controls. Tell
@@ -1763,6 +1778,18 @@ void WebViewImpl::didUpdateTopControls()
}
}
+bool WebViewImpl::shouldTopControlsConsumeScroll(float scrollDeltaY)
+{
+ // Always consume if it's in the direction to show the top controls.
+ if (scrollDeltaY > 0)
+ return true;
+
+ if (mainFrame()->scrollOffset().height < mainFrame()->maximumScrollOffset().height)
+ return true;
+
+ return false;
+}
+
void WebViewImpl::resize(const WebSize& newSize)
{
if (m_shouldAutoResize || m_size == newSize)
@@ -4416,7 +4443,7 @@ void WebViewImpl::applyViewportDeltas(
if (!frameView)
return;
- setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelta);
+ m_topControls->updateShownRatio(topControlsShownRatioDelta);
FloatPoint pinchViewportOffset = page()->frameHost().pinchViewport().visibleRect().location();
pinchViewportOffset.move(pinchViewportDelta.width, pinchViewportDelta.height);
@@ -4436,7 +4463,7 @@ void WebViewImpl::applyViewportDeltas(const WebSize& scrollDelta, float pageScal
if (!mainFrameImpl() || !mainFrameImpl()->frameView())
return;
- setTopControlsShownRatio(m_topControlsShownRatio + topControlsShownRatioDelta);
+ m_topControls->updateShownRatio(topControlsShownRatioDelta);
if (pageScaleDelta == 1) {
TRACE_EVENT_INSTANT2("blink", "WebViewImpl::applyScrollAndScale::scrollBy", "x", scrollDelta.width, "y", scrollDelta.height);

Powered by Google App Engine
This is Rietveld 408576698