1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
|
/*
* Copyright (C) 2011-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ScrollingEffectsController.h"
#include "KeyboardScrollingAnimator.h"
#include "LayoutSize.h"
#include "Logging.h"
#include "PlatformWheelEvent.h"
#include "ScrollAnimationKeyboard.h"
#include "ScrollAnimationMomentum.h"
#include "ScrollAnimationSmooth.h"
#include "ScrollExtents.h"
#include "ScrollableArea.h"
#include <wtf/TZoneMallocInlines.h>
#include <wtf/text/TextStream.h>
#if ENABLE(KINETIC_SCROLLING) && !PLATFORM(MAC)
#include "ScrollAnimationKinetic.h"
#endif
#if HAVE(RUBBER_BANDING)
#include "ScrollAnimationRubberBand.h"
#endif
namespace WebCore {
WTF_MAKE_TZONE_ALLOCATED_IMPL(ScrollingEffectsControllerTimer);
ScrollingEffectsController::ScrollingEffectsController(ScrollingEffectsControllerClient& client)
: m_client(client)
{
}
void ScrollingEffectsController::animationCallback(MonotonicTime currentTime)
{
if (m_currentAnimation) {
if (m_currentAnimation->isActive())
m_currentAnimation->serviceAnimation(currentTime);
if (m_currentAnimation && !m_currentAnimation->isActive())
m_currentAnimation = nullptr;
}
updateRubberBandAnimatingState();
startOrStopAnimationCallbacks();
}
void ScrollingEffectsController::startOrStopAnimationCallbacks()
{
bool needsCallbacks = m_isAnimatingRubberBand || m_isAnimatingKeyboardScrolling || m_currentAnimation;
if (needsCallbacks == m_isRunningAnimatingCallback)
return;
if (needsCallbacks) {
m_client.startAnimationCallback(*this);
m_isRunningAnimatingCallback = true;
return;
}
m_client.stopAnimationCallback(*this);
m_isRunningAnimatingCallback = false;
}
void ScrollingEffectsController::willBeginKeyboardScrolling()
{
setIsAnimatingKeyboardScrolling(true);
}
void ScrollingEffectsController::didStopKeyboardScrolling()
{
setIsAnimatingKeyboardScrolling(false);
}
bool ScrollingEffectsController::startKeyboardScroll(const KeyboardScroll& scrollData)
{
if (m_currentAnimation)
m_currentAnimation->stop();
m_currentAnimation = makeUnique<ScrollAnimationKeyboard>(*this);
bool started = downcast<ScrollAnimationKeyboard>(*m_currentAnimation).startKeyboardScroll(scrollData);
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " startAnimatedScrollToDestination " << *m_currentAnimation << " started " << started);
return started;
}
void ScrollingEffectsController::finishKeyboardScroll(bool immediate)
{
if (auto* animationKeyboard = dynamicDowncast<ScrollAnimationKeyboard>(m_currentAnimation.get()))
animationKeyboard->finishKeyboardScroll(immediate);
}
bool ScrollingEffectsController::startAnimatedScrollToDestination(FloatPoint startOffset, FloatPoint destinationOffset)
{
if (m_currentAnimation)
m_currentAnimation->stop();
// We always create and attempt to start the animation. If it turns out to not need animating, then the animation
// remains inactive, and we'll remove it on the next animationCallback().
m_currentAnimation = makeUnique<ScrollAnimationSmooth>(*this);
bool started = downcast<ScrollAnimationSmooth>(*m_currentAnimation).startAnimatedScrollToDestination(startOffset, destinationOffset);
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " startAnimatedScrollToDestination " << *m_currentAnimation << " started " << started);
return started;
}
bool ScrollingEffectsController::retargetAnimatedScroll(FloatPoint newDestinationOffset)
{
auto* animationSmooth = dynamicDowncast<ScrollAnimationSmooth>(m_currentAnimation.get());
if (!animationSmooth)
return false;
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScroll to " << newDestinationOffset);
ASSERT(animationSmooth->isActive());
return animationSmooth->retargetActiveAnimation(newDestinationOffset);
}
bool ScrollingEffectsController::retargetAnimatedScrollBy(FloatSize offset)
{
if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()) || !m_currentAnimation->isActive())
return false;
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScrollBy " << offset);
if (auto destinationOffset = m_currentAnimation->destinationOffset())
return m_currentAnimation->retargetActiveAnimation(*destinationOffset + offset);
return false;
}
void ScrollingEffectsController::stopAnimatedNonRubberbandingScroll()
{
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " stopAnimatedNonRubberbandingScroll");
if (!m_currentAnimation)
return;
#if HAVE(RUBBER_BANDING)
if (is<ScrollAnimationRubberBand>(m_currentAnimation))
return;
#endif
if (is<ScrollAnimationMomentum>(m_currentAnimation)) {
// If the animation is currently triggering rubberbanding, let it run. Ideally we'd check if the animation will cause rubberbanding at any time in the future.
auto currentOffset = m_currentAnimation->currentOffset();
auto extents = m_client.scrollExtents();
auto constrainedOffset = currentOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
if (currentOffset != constrainedOffset)
return;
}
m_currentAnimation->stop();
}
void ScrollingEffectsController::stopAnimatedScroll()
{
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " stopAnimatedScroll");
if (m_currentAnimation)
m_currentAnimation->stop();
}
bool ScrollingEffectsController::startMomentumScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, NOESCAPE const Function<FloatPoint(const FloatPoint&)>& destinationModifier)
{
if (m_currentAnimation) {
m_currentAnimation->stop();
if (!is<ScrollAnimationMomentum>(m_currentAnimation.get()))
m_currentAnimation = nullptr;
}
if (!m_currentAnimation)
m_currentAnimation = makeUnique<ScrollAnimationMomentum>(*this);
bool started = downcast<ScrollAnimationMomentum>(*m_currentAnimation).startAnimatedScrollWithInitialVelocity(initialOffset, initialVelocity, initialDelta, destinationModifier);
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController::startMomentumScrollWithInitialVelocity() - animation " << *m_currentAnimation << " initialVelocity " << initialVelocity << " initialDelta " << initialDelta << " started " << started);
return started;
}
void ScrollingEffectsController::setIsAnimatingRubberBand(bool isAnimatingRubberBand)
{
if (isAnimatingRubberBand == m_isAnimatingRubberBand)
return;
m_isAnimatingRubberBand = isAnimatingRubberBand;
startOrStopAnimationCallbacks();
}
void ScrollingEffectsController::setIsAnimatingScrollSnap(bool isAnimatingScrollSnap)
{
if (isAnimatingScrollSnap == m_isAnimatingScrollSnap)
return;
m_isAnimatingScrollSnap = isAnimatingScrollSnap;
startOrStopAnimationCallbacks();
}
void ScrollingEffectsController::setIsAnimatingKeyboardScrolling(bool isAnimatingKeyboardScrolling)
{
if (isAnimatingKeyboardScrolling == m_isAnimatingKeyboardScrolling)
return;
m_isAnimatingKeyboardScrolling = isAnimatingKeyboardScrolling;
startOrStopAnimationCallbacks();
}
void ScrollingEffectsController::stopKeyboardScrolling()
{
m_client.keyboardScrollingAnimator()->handleKeyUpEvent();
}
void ScrollingEffectsController::contentsSizeChanged()
{
if (m_currentAnimation)
m_currentAnimation->updateScrollExtents();
}
bool ScrollingEffectsController::usesScrollSnap() const
{
return !!m_scrollSnapState;
}
void ScrollingEffectsController::setSnapOffsetsInfo(const LayoutScrollSnapOffsetsInfo& snapOffsetInfo)
{
if (snapOffsetInfo.isEmpty()) {
m_scrollSnapState = nullptr;
return;
}
bool shouldComputeCurrentSnapIndices = !m_scrollSnapState;
if (!m_scrollSnapState)
m_scrollSnapState = makeUnique<ScrollSnapAnimatorState>(*this);
m_scrollSnapState->setSnapOffsetInfo(snapOffsetInfo);
if (shouldComputeCurrentSnapIndices)
updateActiveScrollSnapIndexForClientOffset();
LOG_WITH_STREAM(ScrollSnap, stream << "ScrollingEffectsController " << this << " setSnapOffsetsInfo new state: " << ValueOrNull(m_scrollSnapState.get()));
}
const LayoutScrollSnapOffsetsInfo* ScrollingEffectsController::snapOffsetsInfo() const
{
return m_scrollSnapState ? &m_scrollSnapState->snapOffsetInfo() : nullptr;
}
std::optional<unsigned> ScrollingEffectsController::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
{
if (!usesScrollSnap())
return std::nullopt;
return m_scrollSnapState->activeSnapIndexForAxis(axis);
}
void ScrollingEffectsController::setActiveScrollSnapIndexForAxis(ScrollEventAxis axis, std::optional<unsigned> index)
{
if (!usesScrollSnap())
return;
m_scrollSnapState->setActiveSnapIndexForAxis(axis, index);
}
float ScrollingEffectsController::adjustedScrollDestination(ScrollEventAxis axis, FloatPoint destinationOffset, float velocity, std::optional<float> originalOffset) const
{
if (!usesScrollSnap())
return axis == ScrollEventAxis::Horizontal ? destinationOffset.x() : destinationOffset.y();
return m_scrollSnapState->adjustedScrollDestination(axis, destinationOffset, velocity, originalOffset, m_client.scrollExtents(), m_client.pageScaleFactor());
}
#if !PLATFORM(MAC)
#if ENABLE(KINETIC_SCROLLING)
bool ScrollingEffectsController::processWheelEventForKineticScrolling(const PlatformWheelEvent& event)
{
if (auto* kineticAnimation = dynamicDowncast<ScrollAnimationKinetic>(m_currentAnimation.get())) {
m_previousKineticAnimationInfo.startTime = kineticAnimation->startTime();
m_previousKineticAnimationInfo.initialOffset = kineticAnimation->initialOffset();
m_previousKineticAnimationInfo.initialVelocity = kineticAnimation->initialVelocity();
kineticAnimation->stop();
}
if (!event.hasPreciseScrollingDeltas()) {
m_scrollHistory.clear();
m_previousKineticAnimationInfo.initialVelocity = FloatSize();
return false;
}
m_scrollHistory.append(event);
if (!event.isEndOfNonMomentumScroll() && !event.isTransitioningToMomentumScroll())
return false;
if (m_currentAnimation && !is<ScrollAnimationKinetic>(m_currentAnimation.get())) {
m_currentAnimation->stop();
m_currentAnimation = nullptr;
m_previousKineticAnimationInfo.initialVelocity = FloatSize();
}
if (usesScrollSnap())
return false;
if (!m_currentAnimation)
m_currentAnimation = makeUnique<ScrollAnimationKinetic>(*this);
auto& kineticAnimation = downcast<ScrollAnimationKinetic>(*m_currentAnimation);
while (!m_scrollHistory.isEmpty())
kineticAnimation.appendToScrollHistory(m_scrollHistory.takeFirst());
FloatSize previousVelocity;
if (!m_previousKineticAnimationInfo.initialVelocity.isZero()) {
previousVelocity = kineticAnimation.accumulateVelocityFromPreviousGesture(m_previousKineticAnimationInfo.startTime,
m_previousKineticAnimationInfo.initialOffset, m_previousKineticAnimationInfo.initialVelocity);
m_previousKineticAnimationInfo.initialVelocity = FloatSize();
}
if (event.isEndOfNonMomentumScroll()) {
kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), kineticAnimation.computeVelocity(), previousVelocity, m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
return true;
}
if (event.isTransitioningToMomentumScroll()) {
kineticAnimation.clearScrollHistory();
kineticAnimation.startAnimatedScrollWithInitialVelocity(m_client.scrollOffset(), event.swipeVelocity(), previousVelocity, m_client.allowsHorizontalScrolling(), m_client.allowsVerticalScrolling());
return true;
}
ASSERT_NOT_REACHED();
return false;
}
#endif
void ScrollingEffectsController::adjustDeltaForSnappingIfNeeded(float& deltaX, float& deltaY)
{
if (snapOffsetsInfo() && !snapOffsetsInfo()->isEmpty()) {
float scale = m_client.pageScaleFactor();
auto scrollOffset = m_client.scrollOffset();
auto extents = m_client.scrollExtents();
auto originalOffset = LayoutPoint(scrollOffset.x() / scale, scrollOffset.y() / scale);
auto newOffset = LayoutPoint((scrollOffset.x() + deltaX) / scale, (scrollOffset.y() + deltaY) / scale);
auto offsetX = snapOffsetsInfo()->closestSnapOffset(ScrollEventAxis::Horizontal, LayoutSize(extents.contentsSize), newOffset, deltaX, originalOffset.x()).first;
auto offsetY = snapOffsetsInfo()->closestSnapOffset(ScrollEventAxis::Vertical, LayoutSize(extents.contentsSize), newOffset, deltaY, originalOffset.y()).first;
deltaX = (offsetX - originalOffset.x()) * scale;
deltaY = (offsetY - originalOffset.y()) * scale;
}
}
void ScrollingEffectsController::updateGestureInProgressState(const PlatformWheelEvent& wheelEvent)
{
#if ENABLE(KINETIC_SCROLLING)
m_inScrollGesture = wheelEvent.hasPreciseScrollingDeltas() && !wheelEvent.isEndOfNonMomentumScroll() && !wheelEvent.isTransitioningToMomentumScroll();
#else
UNUSED_PARAM(wheelEvent);
#endif
}
bool ScrollingEffectsController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
{
#if ENABLE(KINETIC_SCROLLING)
if (processWheelEventForKineticScrolling(wheelEvent))
return true;
#endif
auto scrollOffset = m_client.scrollOffset();
float deltaX = m_client.allowsHorizontalScrolling() ? wheelEvent.deltaX() : 0;
float deltaY = m_client.allowsVerticalScrolling() ? wheelEvent.deltaY() : 0;
auto extents = m_client.scrollExtents();
auto minPosition = extents.minimumScrollOffset();
auto maxPosition = extents.maximumScrollOffset();
if ((deltaX < 0 && scrollOffset.x() >= maxPosition.x())
|| (deltaX > 0 && scrollOffset.x() <= minPosition.x()))
deltaX = 0;
if ((deltaY < 0 && scrollOffset.y() >= maxPosition.y())
|| (deltaY > 0 && scrollOffset.y() <= minPosition.y()))
deltaY = 0;
if (wheelEvent.granularity() == ScrollByPageWheelEvent) {
if (deltaX) {
bool negative = deltaX < 0;
deltaX = Scrollbar::pageStepDelta(extents.contentsSize.width());
if (negative)
deltaX = -deltaX;
}
if (deltaY) {
bool negative = deltaY < 0;
deltaY = Scrollbar::pageStepDelta(extents.contentsSize.height());
if (negative)
deltaY = -deltaY;
}
}
deltaX = -deltaX;
deltaY = -deltaY;
if (!m_inScrollGesture)
adjustDeltaForSnappingIfNeeded(deltaX, deltaY);
if (!deltaX && !deltaY)
return false;
#if ENABLE(SMOOTH_SCROLLING)
if (m_client.scrollAnimationEnabled() && !m_inScrollGesture) {
if (!retargetAnimatedScrollBy({ deltaX, deltaY }))
startAnimatedScrollToDestination(scrollOffset, scrollOffset + FloatSize { deltaX, deltaY });
return true;
}
#endif
m_client.immediateScrollBy({ deltaX, deltaY });
return true;
}
bool ScrollingEffectsController::isUserScrollInProgress() const
{
return m_inScrollGesture;
}
bool ScrollingEffectsController::isScrollSnapInProgress() const
{
if (!usesScrollSnap())
return false;
if (m_inScrollGesture || (m_currentAnimation && m_currentAnimation->isActive()))
return true;
return false;
}
#endif
void ScrollingEffectsController::updateActiveScrollSnapIndexForClientOffset()
{
if (!usesScrollSnap())
return;
ScrollOffset offset = roundedIntPoint(m_client.scrollOffset());
if (m_scrollSnapState->setNearestScrollSnapIndexForOffset(offset, m_client.scrollExtents(), m_client.pageScaleFactor()))
m_activeScrollSnapIndexDidChange = true;
}
void ScrollingEffectsController::resnapAfterLayout()
{
if (!usesScrollSnap())
return;
// If we are already snapped in a particular axis, maintain that. Otherwise, snap to the nearest eligible snap point.
ScrollOffset offset = roundedIntPoint(m_client.scrollOffset());
if (m_scrollSnapState->resnapAfterLayout(offset, m_client.scrollExtents(), m_client.pageScaleFactor()))
m_activeScrollSnapIndexDidChange = true;
}
void ScrollingEffectsController::startScrollSnapAnimation()
{
if (m_isAnimatingScrollSnap)
return;
LOG_WITH_STREAM(ScrollSnap, stream << "ScrollingEffectsController " << this << " startScrollSnapAnimation (main thread " << isMainThread() << ")");
startDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollSnapInProgress);
m_client.willStartScrollSnapAnimation();
setIsAnimatingScrollSnap(true);
}
void ScrollingEffectsController::stopScrollSnapAnimation()
{
if (!m_isAnimatingScrollSnap)
return;
LOG_WITH_STREAM(ScrollSnap, stream << "ScrollingEffectsController " << this << " stopScrollSnapAnimation (main thread " << isMainThread() << ")");
stopDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollSnapInProgress);
m_client.didStopScrollSnapAnimation();
setIsAnimatingScrollSnap(false);
}
void ScrollingEffectsController::scrollAnimationDidUpdate(ScrollAnimation& animation, const FloatPoint& scrollOffset)
{
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationDidUpdate " << animation << " (main thread " << isMainThread() << ") scrolling to " << scrollOffset);
auto currentOffset = m_client.scrollOffset();
auto scrollDelta = scrollOffset - currentOffset;
m_client.immediateScrollBy(scrollDelta, animation.clamping());
}
void ScrollingEffectsController::scrollAnimationWillStart(ScrollAnimation& animation)
{
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationWillStart " << animation);
#if HAVE(RUBBER_BANDING)
if (is<ScrollAnimationRubberBand>(animation))
willStartRubberBandAnimation();
#else
UNUSED_PARAM(animation);
#endif
m_client.willStartAnimatedScroll();
if (is<ScrollAnimationKeyboard>(animation)) {
willBeginKeyboardScrolling();
startDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollAnimationInProgress);
return;
}
startDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollAnimationInProgress);
startOrStopAnimationCallbacks();
}
void ScrollingEffectsController::scrollAnimationDidEnd(ScrollAnimation& animation)
{
LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " scrollAnimationDidEnd " << animation);
if (usesScrollSnap() && m_isAnimatingScrollSnap) {
m_scrollSnapState->transitionToDestinationReachedState();
stopScrollSnapAnimation();
}
#if HAVE(RUBBER_BANDING)
if (is<ScrollAnimationRubberBand>(animation))
didStopRubberBandAnimation();
#else
UNUSED_PARAM(animation);
#endif
// FIXME: Need to track state better and only call this when the running animation is for CSS smooth scrolling. Calling should be harmless, though.
m_client.didStopAnimatedScroll();
if (is<ScrollAnimationKeyboard>(animation)) {
didStopKeyboardScrolling();
stopDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollAnimationInProgress);
return;
}
startOrStopAnimationCallbacks();
stopDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason::ScrollAnimationInProgress);
}
ScrollExtents ScrollingEffectsController::scrollExtentsForAnimation(ScrollAnimation&)
{
return m_client.scrollExtents();
}
FloatSize ScrollingEffectsController::overscrollAmount(ScrollAnimation&)
{
#if HAVE(RUBBER_BANDING)
return m_client.stretchAmount();
#else
return { };
#endif
}
FloatPoint ScrollingEffectsController::scrollOffset(ScrollAnimation&)
{
return m_client.scrollOffset();
}
void ScrollingEffectsController::startDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason reason)
{
m_client.deferWheelEventTestCompletionForReason(m_client.scrollingNodeIDForTesting(), reason);
}
void ScrollingEffectsController::stopDeferringWheelEventTestCompletion(WheelEventTestMonitor::DeferReason reason)
{
m_client.removeWheelEventTestCompletionDeferralForReason(m_client.scrollingNodeIDForTesting(), reason);
}
// Currently, only Mac supports momentum srolling-based scrollsnapping and rubber banding
// so all of these methods are a noop on non-Mac platforms.
#if !PLATFORM(MAC)
ScrollingEffectsController::~ScrollingEffectsController()
{
}
void ScrollingEffectsController::stopAllTimers()
{
}
void ScrollingEffectsController::scrollPositionChanged()
{
}
void ScrollingEffectsController::updateRubberBandAnimatingState()
{
}
#endif // PLATFORM(MAC)
} // namespace WebCore
|