| Index: third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp
|
| diff --git a/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp b/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6b75e8118bc93500a063dc90e1c31f9592d7c5be
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/page/scrolling/OverscrollController.cpp
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/page/scrolling/OverscrollController.h"
|
| +
|
| +#include "core/frame/VisualViewport.h"
|
| +#include "core/page/ChromeClient.h"
|
| +#include "platform/geometry/FloatPoint.h"
|
| +#include "platform/geometry/FloatSize.h"
|
| +#include "platform/scroll/ScrollTypes.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +// Report Overscroll if OverscrollDelta is greater than minimumOverscrollDelta
|
| +// to maintain consistency as done in the compositor.
|
| +const float minimumOverscrollDelta = 0.1;
|
| +
|
| +void adjustOverscroll(FloatSize* unusedDelta)
|
| +{
|
| + DCHECK(unusedDelta);
|
| + if (std::abs(unusedDelta->width()) < minimumOverscrollDelta)
|
| + unusedDelta->setWidth(0);
|
| + if (std::abs(unusedDelta->height()) < minimumOverscrollDelta)
|
| + unusedDelta->setHeight(0);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +OverscrollController::OverscrollController(
|
| + VisualViewport& visualViewport, ChromeClient& chromeClient)
|
| + : m_visualViewport(&visualViewport)
|
| + , m_chromeClient(chromeClient)
|
| +{
|
| +}
|
| +
|
| +DEFINE_TRACE(OverscrollController)
|
| +{
|
| + visitor->trace(m_visualViewport);
|
| +}
|
| +
|
| +void OverscrollController::resetAccumulated(
|
| + bool resetX, bool resetY)
|
| +{
|
| + if (resetX)
|
| + m_accumulatedRootOverscroll.setWidth(0);
|
| + if (resetY)
|
| + m_accumulatedRootOverscroll.setHeight(0);
|
| +}
|
| +
|
| +void OverscrollController::handleOverscroll(
|
| + const ScrollResult& scrollResult,
|
| + const FloatPoint& positionInRootFrame,
|
| + const FloatSize& velocityInRootFrame)
|
| +{
|
| + DCHECK(m_visualViewport);
|
| +
|
| + FloatSize unusedDelta(
|
| + scrollResult.unusedScrollDeltaX,
|
| + scrollResult.unusedScrollDeltaY);
|
| + adjustOverscroll(&unusedDelta);
|
| +
|
| + FloatSize deltaInViewport = unusedDelta.scaledBy(m_visualViewport->scale());
|
| + FloatSize velocityInViewport =
|
| + velocityInRootFrame.scaledBy(m_visualViewport->scale());
|
| + FloatPoint positionInViewport =
|
| + m_visualViewport->rootFrameToViewport(positionInRootFrame);
|
| +
|
| + resetAccumulated(scrollResult.didScrollX, scrollResult.didScrollY);
|
| +
|
| + if (deltaInViewport != FloatSize()) {
|
| + m_accumulatedRootOverscroll += deltaInViewport;
|
| + m_chromeClient.didOverscroll(
|
| + deltaInViewport,
|
| + m_accumulatedRootOverscroll,
|
| + positionInViewport,
|
| + velocityInViewport);
|
| + }
|
| +}
|
| +
|
| +} // namespace blink
|
|
|