| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/page/scrolling/RootViewportScrollCallback.h" | |
| 6 | |
| 7 #include "core/frame/FrameHost.h" | |
| 8 #include "core/frame/FrameView.h" | |
| 9 #include "core/frame/RootFrameViewport.h" | |
| 10 #include "core/frame/Settings.h" | |
| 11 #include "core/frame/TopControls.h" | |
| 12 #include "core/page/scrolling/OverscrollController.h" | |
| 13 #include "core/page/scrolling/ScrollState.h" | |
| 14 #include "platform/geometry/FloatSize.h" | |
| 15 #include "platform/scroll/ScrollableArea.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 RootViewportScrollCallback::RootViewportScrollCallback( | |
| 20 TopControls* topControls, | |
| 21 OverscrollController* overscrollController, | |
| 22 RootFrameViewport& rootFrameViewport) | |
| 23 : m_topControls(topControls) | |
| 24 , m_overscrollController(overscrollController) | |
| 25 , m_rootFrameViewport(&rootFrameViewport) | |
| 26 { | |
| 27 } | |
| 28 | |
| 29 RootViewportScrollCallback::~RootViewportScrollCallback() | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 DEFINE_TRACE(RootViewportScrollCallback) | |
| 34 { | |
| 35 visitor->trace(m_topControls); | |
| 36 visitor->trace(m_overscrollController); | |
| 37 visitor->trace(m_rootFrameViewport); | |
| 38 ViewportScrollCallback::trace(visitor); | |
| 39 } | |
| 40 | |
| 41 bool RootViewportScrollCallback::shouldScrollTopControls(const FloatSize& delta, | |
| 42 ScrollGranularity granularity) const | |
| 43 { | |
| 44 if (granularity != ScrollByPixel && granularity != ScrollByPrecisePixel) | |
| 45 return false; | |
| 46 | |
| 47 if (!m_rootFrameViewport) | |
| 48 return false; | |
| 49 | |
| 50 DoublePoint maxScroll = m_rootFrameViewport->maximumScrollPositionDouble(); | |
| 51 DoublePoint scrollPosition = m_rootFrameViewport->scrollPositionDouble(); | |
| 52 | |
| 53 // Always give the delta to the top controls if the scroll is in | |
| 54 // the direction to show the top controls. If it's in the | |
| 55 // direction to hide the top controls, only give the delta to the | |
| 56 // top controls when the frame can scroll. | |
| 57 return delta.height() < 0 || scrollPosition.y() < maxScroll.y(); | |
| 58 } | |
| 59 | |
| 60 bool RootViewportScrollCallback::scrollTopControls(ScrollState& state) | |
| 61 { | |
| 62 // Scroll top controls. | |
| 63 if (m_topControls) { | |
| 64 if (state.isBeginning()) | |
| 65 m_topControls->scrollBegin(); | |
| 66 | |
| 67 FloatSize delta(state.deltaX(), state.deltaY()); | |
| 68 ScrollGranularity granularity = | |
| 69 ScrollGranularity(static_cast<int>(state.deltaGranularity())); | |
| 70 if (shouldScrollTopControls(delta, granularity)) { | |
| 71 FloatSize remainingDelta = m_topControls->scrollBy(delta); | |
| 72 FloatSize consumed = delta - remainingDelta; | |
| 73 state.consumeDeltaNative(consumed.width(), consumed.height()); | |
| 74 return !consumed.isZero(); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 void RootViewportScrollCallback::handleEvent(ScrollState* state) | |
| 82 { | |
| 83 DCHECK(state); | |
| 84 if (!m_rootFrameViewport) | |
| 85 return; | |
| 86 | |
| 87 bool topControlsDidScroll = scrollTopControls(*state); | |
| 88 | |
| 89 ScrollResult result = performNativeScroll(*state, *m_rootFrameViewport); | |
| 90 | |
| 91 // We consider top controls movement to be scrolling. | |
| 92 result.didScrollY |= topControlsDidScroll; | |
| 93 | |
| 94 // Handle Overscroll. | |
| 95 if (m_overscrollController) { | |
| 96 FloatPoint position(state->positionX(), state->positionY()); | |
| 97 FloatSize velocity(state->velocityX(), state->velocityY()); | |
| 98 m_overscrollController->handleOverscroll(result, position, velocity); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 void RootViewportScrollCallback::setScroller(ScrollableArea* scroller) | |
| 103 { | |
| 104 DCHECK(scroller); | |
| 105 m_rootFrameViewport->setLayoutViewport(*scroller); | |
| 106 } | |
| 107 | |
| 108 } // namespace blink | |
| OLD | NEW |