Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 : m_client(client) | 100 : m_client(client) |
| 101 , m_inScrollGesture(false) | 101 , m_inScrollGesture(false) |
| 102 , m_momentumScrollInProgress(false) | 102 , m_momentumScrollInProgress(false) |
| 103 , m_ignoreMomentumScrolls(false) | 103 , m_ignoreMomentumScrolls(false) |
| 104 , m_lastMomentumScrollTimestamp(0) | 104 , m_lastMomentumScrollTimestamp(0) |
| 105 , m_startTime(0) | 105 , m_startTime(0) |
| 106 , m_snapRubberbandTimerIsActive(false) | 106 , m_snapRubberbandTimerIsActive(false) |
| 107 { | 107 { |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee lEvent) | 110 // |canRubberbandLeft| and |canRubberbandRight| prevent the start of rubber-band ing in their respective directions. |
| 111 // Once rubber banding has started, the two parameters have no effect. | |
| 112 bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee lEvent, bool canRubberbandLeft, bool canRubberbandRight) | |
| 111 { | 113 { |
| 112 if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { | 114 if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { |
| 115 // Don't allow rubber banding to start in a direction that explicitly di sallows rubberbanding. | |
| 116 if (!canRubberbandLeft && wheelEvent.deltaX() > 0) { | |
| 117 printf("cannot rubberband left"); | |
| 118 return false; | |
| 119 } | |
| 120 if (!canRubberbandRight && wheelEvent.deltaX() < 0) { | |
| 121 printf("cannot rubberband right"); | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 | |
| 113 // First, check if we should rubber-band at all. | 126 // First, check if we should rubber-band at all. |
| 114 if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) && | 127 if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) && |
| 115 !shouldRubberBandInHorizontalDirection(wheelEvent)) | 128 !shouldRubberBandInHorizontalDirection(wheelEvent)) |
|
Nico
2014/03/14 17:51:46
Should the checks be in shouldRubberBandInHorizont
erikchen
2014/03/20 18:04:26
I've moved all the relevant logic into the method.
| |
| 116 return false; | 129 return false; |
| 117 | 130 |
| 118 m_inScrollGesture = true; | 131 m_inScrollGesture = true; |
| 119 m_momentumScrollInProgress = false; | 132 m_momentumScrollInProgress = false; |
| 120 m_ignoreMomentumScrolls = false; | 133 m_ignoreMomentumScrolls = false; |
| 121 m_lastMomentumScrollTimestamp = 0; | 134 m_lastMomentumScrollTimestamp = 0; |
| 122 m_momentumVelocity = FloatSize(); | 135 m_momentumVelocity = FloatSize(); |
| 123 | 136 |
| 124 IntSize stretchAmount = m_client->stretchAmount(); | 137 IntSize stretchAmount = m_client->stretchAmount(); |
| 125 m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount. width())); | 138 m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount. width())); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 deltaX = 0; | 191 deltaX = 0; |
| 179 else | 192 else |
| 180 deltaY = 0; | 193 deltaY = 0; |
| 181 | 194 |
| 182 bool shouldStretch = false; | 195 bool shouldStretch = false; |
| 183 | 196 |
| 184 PlatformWheelEventPhase momentumPhase = wheelEvent.momentumPhase(); | 197 PlatformWheelEventPhase momentumPhase = wheelEvent.momentumPhase(); |
| 185 | 198 |
| 186 // If we are starting momentum scrolling then do some setup. | 199 // If we are starting momentum scrolling then do some setup. |
| 187 if (!m_momentumScrollInProgress && (momentumPhase == PlatformWheelEventPhase Began || momentumPhase == PlatformWheelEventPhaseChanged)) { | 200 if (!m_momentumScrollInProgress && (momentumPhase == PlatformWheelEventPhase Began || momentumPhase == PlatformWheelEventPhaseChanged)) { |
| 201 // Momentum events should not trigger rubber banding in a disallowed dir ection. | |
| 202 if (!canRubberbandLeft && wheelEvent.deltaX() > 0) { | |
| 203 return false; | |
| 204 } | |
| 205 if (!canRubberbandRight && wheelEvent.deltaX() < 0) { | |
| 206 return false; | |
| 207 } | |
| 188 m_momentumScrollInProgress = true; | 208 m_momentumScrollInProgress = true; |
| 189 // Start the snap rubber band timer if it's not running. This is needed to | 209 // Start the snap rubber band timer if it's not running. This is needed to |
| 190 // snap back from the over scroll caused by momentum events. | 210 // snap back from the over scroll caused by momentum events. |
| 191 if (!m_snapRubberbandTimerIsActive && m_startTime == 0) | 211 if (!m_snapRubberbandTimerIsActive && m_startTime == 0) |
| 192 snapRubberBand(); | 212 snapRubberBand(); |
| 193 } | 213 } |
| 194 | 214 |
| 195 CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTime stamp; | 215 CFTimeInterval timeDelta = wheelEvent.timestamp() - m_lastMomentumScrollTime stamp; |
| 196 if (m_inScrollGesture || m_momentumScrollInProgress) { | 216 if (m_inScrollGesture || m_momentumScrollInProgress) { |
| 197 if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scroll VelocityZeroingTimeout) { | 217 if (m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scroll VelocityZeroingTimeout) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 return m_client->shouldRubberBandInDirection(ScrollLeft); | 439 return m_client->shouldRubberBandInDirection(ScrollLeft); |
| 420 if (wheelEvent.deltaX() < 0) | 440 if (wheelEvent.deltaX() < 0) |
| 421 return m_client->shouldRubberBandInDirection(ScrollRight); | 441 return m_client->shouldRubberBandInDirection(ScrollRight); |
| 422 | 442 |
| 423 return true; | 443 return true; |
| 424 } | 444 } |
| 425 | 445 |
| 426 } // namespace WebCore | 446 } // namespace WebCore |
| 427 | 447 |
| 428 #endif // USE(RUBBER_BANDING) | 448 #endif // USE(RUBBER_BANDING) |
| OLD | NEW |