|
Lines 1-492
a/Source/WebCore/platform/cocoa/ScrollController.mm_sec1
|
| 1 |
/* |
|
|
| 2 |
* Copyright (C) 2011, 2014-2015 Apple Inc. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
| 6 |
* are met: |
| 7 |
* 1. Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* |
| 13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 |
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "config.h" |
| 27 |
#include "ScrollController.h" |
| 28 |
|
| 29 |
#include "PlatformWheelEvent.h" |
| 30 |
#include "WebCoreSystemInterface.h" |
| 31 |
#include <sys/sysctl.h> |
| 32 |
#include <sys/time.h> |
| 33 |
|
| 34 |
#if ENABLE(CSS_SCROLL_SNAP) |
| 35 |
#include "AxisScrollSnapAnimator.h" |
| 36 |
#include "ScrollableArea.h" |
| 37 |
#endif |
| 38 |
|
| 39 |
#if ENABLE(RUBBER_BANDING) |
| 40 |
|
| 41 |
static NSTimeInterval systemUptime() |
| 42 |
{ |
| 43 |
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(systemUptime)]) |
| 44 |
return [[NSProcessInfo processInfo] systemUptime]; |
| 45 |
|
| 46 |
// Get how long system has been up. Found by looking getting "boottime" from the kernel. |
| 47 |
static struct timeval boottime = {0, 0}; |
| 48 |
if (!boottime.tv_sec) { |
| 49 |
int mib[2] = {CTL_KERN, KERN_BOOTTIME}; |
| 50 |
size_t size = sizeof(boottime); |
| 51 |
if (-1 == sysctl(mib, 2, &boottime, &size, 0, 0)) |
| 52 |
boottime.tv_sec = 0; |
| 53 |
} |
| 54 |
struct timeval now; |
| 55 |
if (boottime.tv_sec && -1 != gettimeofday(&now, 0)) { |
| 56 |
struct timeval uptime; |
| 57 |
timersub(&now, &boottime, &uptime); |
| 58 |
NSTimeInterval result = uptime.tv_sec + (uptime.tv_usec / 1E+6); |
| 59 |
return result; |
| 60 |
} |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
namespace WebCore { |
| 66 |
|
| 67 |
static const float scrollVelocityZeroingTimeout = 0.10f; |
| 68 |
static const float rubberbandDirectionLockStretchRatio = 1; |
| 69 |
static const float rubberbandMinimumRequiredDeltaBeforeStretch = 10; |
| 70 |
|
| 71 |
static float elasticDeltaForTimeDelta(float initialPosition, float initialVelocity, float elapsedTime) |
| 72 |
{ |
| 73 |
return wkNSElasticDeltaForTimeDelta(initialPosition, initialVelocity, elapsedTime); |
| 74 |
} |
| 75 |
|
| 76 |
static float elasticDeltaForReboundDelta(float delta) |
| 77 |
{ |
| 78 |
return wkNSElasticDeltaForReboundDelta(delta); |
| 79 |
} |
| 80 |
|
| 81 |
static float reboundDeltaForElasticDelta(float delta) |
| 82 |
{ |
| 83 |
return wkNSReboundDeltaForElasticDelta(delta); |
| 84 |
} |
| 85 |
|
| 86 |
static float scrollWheelMultiplier() |
| 87 |
{ |
| 88 |
static float multiplier = -1; |
| 89 |
if (multiplier < 0) { |
| 90 |
multiplier = [[NSUserDefaults standardUserDefaults] floatForKey:@"NSScrollWheelMultiplier"]; |
| 91 |
if (multiplier <= 0) |
| 92 |
multiplier = 1; |
| 93 |
} |
| 94 |
return multiplier; |
| 95 |
} |
| 96 |
|
| 97 |
ScrollController::ScrollController(ScrollControllerClient* client) |
| 98 |
: m_client(client) |
| 99 |
, m_lastMomentumScrollTimestamp(0) |
| 100 |
, m_startTime(0) |
| 101 |
, m_snapRubberbandTimer(RunLoop::current(), this, &ScrollController::snapRubberBandTimerFired) |
| 102 |
#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) |
| 103 |
, m_horizontalScrollSnapTimer(RunLoop::current(), this, &ScrollController::horizontalScrollSnapTimerFired) |
| 104 |
, m_verticalScrollSnapTimer(RunLoop::current(), this, &ScrollController::verticalScrollSnapTimerFired) |
| 105 |
#endif |
| 106 |
, m_inScrollGesture(false) |
| 107 |
, m_momentumScrollInProgress(false) |
| 108 |
, m_ignoreMomentumScrolls(false) |
| 109 |
, m_snapRubberbandTimerIsActive(false) |
| 110 |
{ |
| 111 |
} |
| 112 |
|
| 113 |
bool ScrollController::handleWheelEvent(const PlatformWheelEvent& wheelEvent) |
| 114 |
{ |
| 115 |
#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) |
| 116 |
if (!processWheelEventForScrollSnap(wheelEvent)) |
| 117 |
return false; |
| 118 |
#endif |
| 119 |
if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { |
| 120 |
// First, check if we should rubber-band at all. |
| 121 |
if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) |
| 122 |
&& !shouldRubberBandInHorizontalDirection(wheelEvent)) |
| 123 |
return false; |
| 124 |
|
| 125 |
m_inScrollGesture = true; |
| 126 |
m_momentumScrollInProgress = false; |
| 127 |
m_ignoreMomentumScrolls = false; |
| 128 |
m_lastMomentumScrollTimestamp = 0; |
| 129 |
m_momentumVelocity = FloatSize(); |
| 130 |
|
| 131 |
IntSize stretchAmount = m_client->stretchAmount(); |
| 132 |
m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width())); |
| 133 |
m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height())); |
| 134 |
m_overflowScrollDelta = FloatSize(); |
| 135 |
|
| 136 |
stopSnapRubberbandTimer(); |
| 137 |
|
| 138 |
return true; |
| 139 |
} |
| 140 |
|
| 141 |
if (wheelEvent.phase() == PlatformWheelEventPhaseEnded) { |
| 142 |
snapRubberBand(); |
| 143 |
return true; |
| 144 |
} |
| 145 |
|
| 146 |
bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEventPhaseNone); |
| 147 |
if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberbandTimerIsActive)) { |
| 148 |
if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) { |
| 149 |
m_ignoreMomentumScrolls = false; |
| 150 |
return true; |
| 151 |
} |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
float deltaX = m_overflowScrollDelta.width(); |
| 156 |
float deltaY = m_overflowScrollDelta.height(); |
| 157 |
|
| 158 |
// Reset overflow values because we may decide to remove delta at various points and put it into overflow. |
| 159 |
m_overflowScrollDelta = FloatSize(); |
| 160 |
|
| 161 |
IntSize stretchAmount = m_client->stretchAmount(); |
| 162 |
bool isVerticallyStretched = stretchAmount.height(); |
| 163 |
bool isHorizontallyStretched = stretchAmount.width(); |
| 164 |
|
| 165 |
float eventCoalescedDeltaX; |
| 166 |
float eventCoalescedDeltaY; |
| 167 |
|
| 168 |
if (isVerticallyStretched || isHorizontallyStretched) { |
| 169 |
eventCoalescedDeltaX = -wheelEvent.unacceleratedScrollingDeltaX(); |
| 170 |
eventCoalescedDeltaY = -wheelEvent.unacceleratedScrollingDeltaY(); |
| 171 |
} else { |
| 172 |
eventCoalescedDeltaX = -wheelEvent.deltaX(); |
| 173 |
eventCoalescedDeltaY = -wheelEvent.deltaY(); |
| 174 |
} |
| 175 |
|
| 176 |
deltaX += eventCoalescedDeltaX; |
| 177 |
deltaY += eventCoalescedDeltaY; |
| 178 |
|
| 179 |
// Slightly prefer scrolling vertically by applying the = case to deltaY |
| 180 |
if (fabsf(deltaY) >= fabsf(deltaX)) |
| 181 |
deltaX = 0; |
| 182 |
else |
| 183 |
deltaY = 0; |
| 184 |
|
| 185 |
bool shouldStretch = false; |
| 186 |
|
| 187 |
PlatformWheelEventPhase momentumPhase = wheelEvent.momentumPhase(); |
| 188 |
|
| 189 |
// If we are starting momentum scrolling then do some setup. |
| 190 |
if (!m_momentumScrollInProgress && (momentumPhase == PlatformWheelEventPhaseBegan || momentumPhase == PlatformWheelEventPhaseChanged)) |
| 191 |
m_momentumScrollInProgress = true; |
| 192 |
|
| 193 |
CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTimestamp; |
| 194 |
if (m_inScrollGesture || m_momentumScrollInProgress) { |
| 195 |
if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) { |
| 196 |
m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta); |
| 197 |
m_momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta); |
| 198 |
m_lastMomentumScrollTimestamp = wheelEvent.timestamp(); |
| 199 |
} else { |
| 200 |
m_lastMomentumScrollTimestamp = wheelEvent.timestamp(); |
| 201 |
m_momentumVelocity = FloatSize(); |
| 202 |
} |
| 203 |
|
| 204 |
if (isVerticallyStretched) { |
| 205 |
if (!isHorizontallyStretched && m_client->pinnedInDirection(FloatSize(deltaX, 0))) { |
| 206 |
// Stretching only in the vertical. |
| 207 |
if (deltaY && (fabsf(deltaX / deltaY) < rubberbandDirectionLockStretchRatio)) |
| 208 |
deltaX = 0; |
| 209 |
else if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) { |
| 210 |
m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX); |
| 211 |
deltaX = 0; |
| 212 |
} else |
| 213 |
m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX); |
| 214 |
} |
| 215 |
} else if (isHorizontallyStretched) { |
| 216 |
// Stretching only in the horizontal. |
| 217 |
if (m_client->pinnedInDirection(FloatSize(0, deltaY))) { |
| 218 |
if (deltaX && (fabsf(deltaY / deltaX) < rubberbandDirectionLockStretchRatio)) |
| 219 |
deltaY = 0; |
| 220 |
else if (fabsf(deltaY) < rubberbandMinimumRequiredDeltaBeforeStretch) { |
| 221 |
m_overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY); |
| 222 |
deltaY = 0; |
| 223 |
} else |
| 224 |
m_overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY); |
| 225 |
} |
| 226 |
} else { |
| 227 |
// Not stretching at all yet. |
| 228 |
if (m_client->pinnedInDirection(FloatSize(deltaX, deltaY))) { |
| 229 |
if (fabsf(deltaY) >= fabsf(deltaX)) { |
| 230 |
if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) { |
| 231 |
m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX); |
| 232 |
deltaX = 0; |
| 233 |
} else |
| 234 |
m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX); |
| 235 |
} |
| 236 |
shouldStretch = true; |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
if (deltaX || deltaY) { |
| 242 |
if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched)) { |
| 243 |
if (deltaY) { |
| 244 |
deltaY *= scrollWheelMultiplier(); |
| 245 |
m_client->immediateScrollBy(FloatSize(0, deltaY)); |
| 246 |
} |
| 247 |
if (deltaX) { |
| 248 |
deltaX *= scrollWheelMultiplier(); |
| 249 |
m_client->immediateScrollBy(FloatSize(deltaX, 0)); |
| 250 |
} |
| 251 |
} else { |
| 252 |
if (!m_client->allowsHorizontalStretching(wheelEvent)) { |
| 253 |
deltaX = 0; |
| 254 |
eventCoalescedDeltaX = 0; |
| 255 |
} else if (deltaX && !isHorizontallyStretched && !m_client->pinnedInDirection(FloatSize(deltaX, 0))) { |
| 256 |
deltaX *= scrollWheelMultiplier(); |
| 257 |
|
| 258 |
m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(deltaX, 0)); |
| 259 |
deltaX = 0; |
| 260 |
} |
| 261 |
|
| 262 |
if (!m_client->allowsVerticalStretching(wheelEvent)) { |
| 263 |
deltaY = 0; |
| 264 |
eventCoalescedDeltaY = 0; |
| 265 |
} else if (deltaY && !isVerticallyStretched && !m_client->pinnedInDirection(FloatSize(0, deltaY))) { |
| 266 |
deltaY *= scrollWheelMultiplier(); |
| 267 |
|
| 268 |
m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(0, deltaY)); |
| 269 |
deltaY = 0; |
| 270 |
} |
| 271 |
|
| 272 |
IntSize stretchAmount = m_client->stretchAmount(); |
| 273 |
|
| 274 |
if (m_momentumScrollInProgress) { |
| 275 |
if ((m_client->pinnedInDirection(FloatSize(eventCoalescedDeltaX, eventCoalescedDeltaY)) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) { |
| 276 |
m_ignoreMomentumScrolls = true; |
| 277 |
m_momentumScrollInProgress = false; |
| 278 |
snapRubberBand(); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
m_stretchScrollForce.setWidth(m_stretchScrollForce.width() + deltaX); |
| 283 |
m_stretchScrollForce.setHeight(m_stretchScrollForce.height() + deltaY); |
| 284 |
|
| 285 |
FloatSize dampedDelta(ceilf(elasticDeltaForReboundDelta(m_stretchScrollForce.width())), ceilf(elasticDeltaForReboundDelta(m_stretchScrollForce.height()))); |
| 286 |
|
| 287 |
m_client->immediateScrollByWithoutContentEdgeConstraints(dampedDelta - stretchAmount); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
if (m_momentumScrollInProgress && momentumPhase == PlatformWheelEventPhaseEnded) { |
| 292 |
m_momentumScrollInProgress = false; |
| 293 |
m_ignoreMomentumScrolls = false; |
| 294 |
m_lastMomentumScrollTimestamp = 0; |
| 295 |
} |
| 296 |
|
| 297 |
return true; |
| 298 |
} |
| 299 |
|
| 300 |
static inline float roundTowardZero(float num) |
| 301 |
{ |
| 302 |
return num > 0 ? ceilf(num - 0.5f) : floorf(num + 0.5f); |
| 303 |
} |
| 304 |
|
| 305 |
static inline float roundToDevicePixelTowardZero(float num) |
| 306 |
{ |
| 307 |
float roundedNum = roundf(num); |
| 308 |
if (fabs(num - roundedNum) < 0.125) |
| 309 |
num = roundedNum; |
| 310 |
|
| 311 |
return roundTowardZero(num); |
| 312 |
} |
| 313 |
|
| 314 |
void ScrollController::snapRubberBandTimerFired() |
| 315 |
{ |
| 316 |
if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) { |
| 317 |
CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_startTime; |
| 318 |
|
| 319 |
if (m_startStretch == FloatSize()) { |
| 320 |
m_startStretch = m_client->stretchAmount(); |
| 321 |
if (m_startStretch == FloatSize()) { |
| 322 |
stopSnapRubberbandTimer(); |
| 323 |
|
| 324 |
m_stretchScrollForce = FloatSize(); |
| 325 |
m_startTime = 0; |
| 326 |
m_startStretch = FloatSize(); |
| 327 |
m_origOrigin = FloatPoint(); |
| 328 |
m_origVelocity = FloatSize(); |
| 329 |
return; |
| 330 |
} |
| 331 |
|
| 332 |
m_origOrigin = m_client->absoluteScrollPosition() - m_startStretch; |
| 333 |
m_origVelocity = m_momentumVelocity; |
| 334 |
|
| 335 |
// Just like normal scrolling, prefer vertical rubberbanding |
| 336 |
if (fabsf(m_origVelocity.height()) >= fabsf(m_origVelocity.width())) |
| 337 |
m_origVelocity.setWidth(0); |
| 338 |
|
| 339 |
// Don't rubber-band horizontally if it's not possible to scroll horizontally |
| 340 |
if (!m_client->canScrollHorizontally()) |
| 341 |
m_origVelocity.setWidth(0); |
| 342 |
|
| 343 |
// Don't rubber-band vertically if it's not possible to scroll vertically |
| 344 |
if (!m_client->canScrollVertically()) |
| 345 |
m_origVelocity.setHeight(0); |
| 346 |
} |
| 347 |
|
| 348 |
FloatPoint delta(roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.width(), -m_origVelocity.width(), (float)timeDelta)), |
| 349 |
roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.height(), -m_origVelocity.height(), (float)timeDelta))); |
| 350 |
|
| 351 |
if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) { |
| 352 |
m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(delta.x(), delta.y()) - m_client->stretchAmount()); |
| 353 |
|
| 354 |
FloatSize newStretch = m_client->stretchAmount(); |
| 355 |
|
| 356 |
m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width())); |
| 357 |
m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height())); |
| 358 |
} else { |
| 359 |
m_client->adjustScrollPositionToBoundsIfNecessary(); |
| 360 |
|
| 361 |
stopSnapRubberbandTimer(); |
| 362 |
m_stretchScrollForce = FloatSize(); |
| 363 |
m_startTime = 0; |
| 364 |
m_startStretch = FloatSize(); |
| 365 |
m_origOrigin = FloatPoint(); |
| 366 |
m_origVelocity = FloatSize(); |
| 367 |
} |
| 368 |
} else { |
| 369 |
m_startTime = [NSDate timeIntervalSinceReferenceDate]; |
| 370 |
m_startStretch = FloatSize(); |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
bool ScrollController::isRubberBandInProgress() const |
| 375 |
{ |
| 376 |
if (!m_inScrollGesture && !m_momentumScrollInProgress && !m_snapRubberbandTimerIsActive) |
| 377 |
return false; |
| 378 |
|
| 379 |
return !m_client->stretchAmount().isZero(); |
| 380 |
} |
| 381 |
|
| 382 |
void ScrollController::startSnapRubberbandTimer() |
| 383 |
{ |
| 384 |
m_snapRubberbandTimer.startRepeating(1.0 / 60.0); |
| 385 |
} |
| 386 |
|
| 387 |
void ScrollController::stopSnapRubberbandTimer() |
| 388 |
{ |
| 389 |
m_snapRubberbandTimer.stop(); |
| 390 |
m_snapRubberbandTimerIsActive = false; |
| 391 |
} |
| 392 |
|
| 393 |
void ScrollController::snapRubberBand() |
| 394 |
{ |
| 395 |
CFTimeInterval timeDelta = systemUptime() - m_lastMomentumScrollTimestamp; |
| 396 |
if (m_lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout) |
| 397 |
m_momentumVelocity = FloatSize(); |
| 398 |
|
| 399 |
m_inScrollGesture = false; |
| 400 |
|
| 401 |
if (m_snapRubberbandTimerIsActive) |
| 402 |
return; |
| 403 |
|
| 404 |
m_startTime = [NSDate timeIntervalSinceReferenceDate]; |
| 405 |
m_startStretch = FloatSize(); |
| 406 |
m_origOrigin = FloatPoint(); |
| 407 |
m_origVelocity = FloatSize(); |
| 408 |
|
| 409 |
startSnapRubberbandTimer(); |
| 410 |
m_snapRubberbandTimerIsActive = true; |
| 411 |
} |
| 412 |
|
| 413 |
bool ScrollController::shouldRubberBandInHorizontalDirection(const PlatformWheelEvent& wheelEvent) |
| 414 |
{ |
| 415 |
if (wheelEvent.deltaX() > 0) |
| 416 |
return m_client->shouldRubberBandInDirection(ScrollLeft); |
| 417 |
if (wheelEvent.deltaX() < 0) |
| 418 |
return m_client->shouldRubberBandInDirection(ScrollRight); |
| 419 |
|
| 420 |
return true; |
| 421 |
} |
| 422 |
|
| 423 |
#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC) |
| 424 |
bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent) |
| 425 |
{ |
| 426 |
if (m_verticalScrollSnapAnimator) { |
| 427 |
m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent); |
| 428 |
if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) |
| 429 |
return false; |
| 430 |
} |
| 431 |
if (m_horizontalScrollSnapAnimator) { |
| 432 |
m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent); |
| 433 |
if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent)) |
| 434 |
return false; |
| 435 |
} |
| 436 |
|
| 437 |
return true; |
| 438 |
} |
| 439 |
|
| 440 |
void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scrollableArea) |
| 441 |
{ |
| 442 |
// FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated. |
| 443 |
if (scrollableArea.horizontalSnapOffsets()) |
| 444 |
m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal); |
| 445 |
else if (m_horizontalScrollSnapAnimator) |
| 446 |
m_horizontalScrollSnapAnimator = nullptr; |
| 447 |
|
| 448 |
if (scrollableArea.verticalSnapOffsets()) |
| 449 |
m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical); |
| 450 |
else if (m_verticalScrollSnapAnimator) |
| 451 |
m_verticalScrollSnapAnimator = nullptr; |
| 452 |
} |
| 453 |
|
| 454 |
void ScrollController::startScrollSnapTimer(ScrollEventAxis axis) |
| 455 |
{ |
| 456 |
RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; |
| 457 |
if (!scrollSnapTimer.isActive()) |
| 458 |
scrollSnapTimer.startRepeating(1.0 / 60.0); |
| 459 |
} |
| 460 |
|
| 461 |
void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis) |
| 462 |
{ |
| 463 |
RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer; |
| 464 |
scrollSnapTimer.stop(); |
| 465 |
} |
| 466 |
|
| 467 |
void ScrollController::horizontalScrollSnapTimerFired() |
| 468 |
{ |
| 469 |
if (m_horizontalScrollSnapAnimator) |
| 470 |
m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate(); |
| 471 |
} |
| 472 |
|
| 473 |
void ScrollController::verticalScrollSnapTimerFired() |
| 474 |
{ |
| 475 |
if (m_verticalScrollSnapAnimator) |
| 476 |
m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate(); |
| 477 |
} |
| 478 |
|
| 479 |
LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis) |
| 480 |
{ |
| 481 |
return m_client->scrollOffsetOnAxis(axis); |
| 482 |
} |
| 483 |
|
| 484 |
void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta) |
| 485 |
{ |
| 486 |
m_client->immediateScrollOnAxis(axis, delta); |
| 487 |
} |
| 488 |
#endif |
| 489 |
|
| 490 |
} // namespace WebCore |
| 491 |
|
| 492 |
#endif // ENABLE(RUBBER_BANDING) |