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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 multiplier = [[NSUserDefaults standardUserDefaults] floatForKey:@"NSScro llWheelMultiplier"]; | 92 multiplier = [[NSUserDefaults standardUserDefaults] floatForKey:@"NSScro llWheelMultiplier"]; |
93 if (multiplier <= 0) | 93 if (multiplier <= 0) |
94 multiplier = 1; | 94 multiplier = 1; |
95 } | 95 } |
96 return multiplier; | 96 return multiplier; |
97 } | 97 } |
98 | 98 |
99 ScrollElasticityController::ScrollElasticityController(ScrollElasticityControlle rClient* client) | 99 ScrollElasticityController::ScrollElasticityController(ScrollElasticityControlle rClient* client) |
100 : m_client(client) | 100 : m_client(client) |
101 , m_inScrollGesture(false) | 101 , m_inScrollGesture(false) |
102 , m_hasScrolled(false) | |
102 , m_momentumScrollInProgress(false) | 103 , m_momentumScrollInProgress(false) |
103 , m_ignoreMomentumScrolls(false) | 104 , m_ignoreMomentumScrolls(false) |
104 , m_lastMomentumScrollTimestamp(0) | 105 , m_lastMomentumScrollTimestamp(0) |
105 , m_startTime(0) | 106 , m_startTime(0) |
106 , m_snapRubberbandTimerIsActive(false) | 107 , m_snapRubberbandTimerIsActive(false) |
107 { | 108 { |
108 } | 109 } |
109 | 110 |
110 bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee lEvent) | 111 bool ScrollElasticityController::handleWheelEvent(const PlatformWheelEvent& whee lEvent) |
111 { | 112 { |
113 // When a new gesture begins, reset all state that might have been carried | |
114 // over from the last event. | |
112 if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { | 115 if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) { |
113 // First, check if we should rubber-band at all. | |
114 if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) && | |
115 !shouldRubberBandInHorizontalDirection(wheelEvent)) | |
116 return false; | |
117 | |
118 m_inScrollGesture = true; | 116 m_inScrollGesture = true; |
117 m_hasScrolled = false; | |
119 m_momentumScrollInProgress = false; | 118 m_momentumScrollInProgress = false; |
120 m_ignoreMomentumScrolls = false; | 119 m_ignoreMomentumScrolls = false; |
121 m_lastMomentumScrollTimestamp = 0; | 120 m_lastMomentumScrollTimestamp = 0; |
122 m_momentumVelocity = FloatSize(); | 121 m_momentumVelocity = FloatSize(); |
123 | 122 |
124 IntSize stretchAmount = m_client->stretchAmount(); | 123 IntSize stretchAmount = m_client->stretchAmount(); |
125 m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount. width())); | 124 m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount. width())); |
126 m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount .height())); | 125 m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount .height())); |
127 m_overflowScrollDelta = FloatSize(); | 126 m_overflowScrollDelta = FloatSize(); |
128 | 127 |
129 stopSnapRubberbandTimer(); | 128 stopSnapRubberbandTimer(); |
130 | 129 |
131 return true; | 130 return shouldHandleEvent(wheelEvent); |
132 } | 131 } |
133 | 132 |
134 if (wheelEvent.phase() == PlatformWheelEventPhaseEnded) { | 133 if (wheelEvent.phase() == PlatformWheelEventPhaseEnded || wheelEvent.phase() == PlatformWheelEventPhaseCancelled) { |
erikchen
2014/03/24 22:12:05
this change wasn't necessary to make this CL work,
| |
135 bool wasRubberBandInProgress = isRubberBandInProgress(); | 134 bool wasRubberBandInProgress = isRubberBandInProgress(); |
136 // Call snapRubberBand() even if isRubberBandInProgress() is false. For example, | 135 // Call snapRubberBand() even if isRubberBandInProgress() is false. For example, |
137 // m_inScrollGesture may be true (and needs to be reset on a phase end) even if | 136 // m_inScrollGesture may be true (and needs to be reset on a phase end) even if |
138 // isRubberBandInProgress() is not (e.g. the overhang area is empty). | 137 // isRubberBandInProgress() is not (e.g. the overhang area is empty). |
139 snapRubberBand(); | 138 snapRubberBand(); |
140 return wasRubberBandInProgress; | 139 return wasRubberBandInProgress; |
141 } | 140 } |
142 | 141 |
143 bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEve ntPhaseNone); | 142 bool isMomentumScrollEvent = (wheelEvent.momentumPhase() != PlatformWheelEve ntPhaseNone); |
144 if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberbandTim erIsActive)) { | 143 if (m_ignoreMomentumScrolls && (isMomentumScrollEvent || m_snapRubberbandTim erIsActive)) { |
145 if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) { | 144 if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseEnded) { |
146 m_ignoreMomentumScrolls = false; | 145 m_ignoreMomentumScrolls = false; |
147 return true; | 146 return true; |
148 } | 147 } |
149 return false; | 148 return false; |
150 } | 149 } |
151 | 150 |
151 if (!shouldHandleEvent(wheelEvent)) | |
152 return false; | |
153 | |
152 float deltaX = m_overflowScrollDelta.width(); | 154 float deltaX = m_overflowScrollDelta.width(); |
153 float deltaY = m_overflowScrollDelta.height(); | 155 float deltaY = m_overflowScrollDelta.height(); |
154 | 156 |
155 // Reset overflow values because we may decide to remove delta at various po ints and put it into overflow. | 157 // Reset overflow values because we may decide to remove delta at various po ints and put it into overflow. |
156 m_overflowScrollDelta = FloatSize(); | 158 m_overflowScrollDelta = FloatSize(); |
157 | 159 |
158 IntSize stretchAmount = m_client->stretchAmount(); | 160 IntSize stretchAmount = m_client->stretchAmount(); |
159 bool isVerticallyStretched = stretchAmount.height(); | 161 bool isVerticallyStretched = stretchAmount.height(); |
160 bool isHorizontallyStretched = stretchAmount.width(); | 162 bool isHorizontallyStretched = stretchAmount.width(); |
161 | 163 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 deltaX = 0; | 236 deltaX = 0; |
235 } else | 237 } else |
236 m_overflowScrollDelta.setWidth(m_overflowScrollDelta.wid th() + deltaX); | 238 m_overflowScrollDelta.setWidth(m_overflowScrollDelta.wid th() + deltaX); |
237 } | 239 } |
238 shouldStretch = true; | 240 shouldStretch = true; |
239 } | 241 } |
240 } | 242 } |
241 } | 243 } |
242 | 244 |
243 if (deltaX != 0 || deltaY != 0) { | 245 if (deltaX != 0 || deltaY != 0) { |
246 m_hasScrolled = true; | |
244 if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched) ) { | 247 if (!(shouldStretch || isVerticallyStretched || isHorizontallyStretched) ) { |
245 if (deltaY != 0) { | 248 if (deltaY != 0) { |
246 deltaY *= scrollWheelMultiplier(); | 249 deltaY *= scrollWheelMultiplier(); |
247 m_client->immediateScrollBy(FloatSize(0, deltaY)); | 250 m_client->immediateScrollBy(FloatSize(0, deltaY)); |
248 } | 251 } |
249 if (deltaX != 0) { | 252 if (deltaX != 0) { |
250 deltaX *= scrollWheelMultiplier(); | 253 deltaX *= scrollWheelMultiplier(); |
251 m_client->immediateScrollBy(FloatSize(deltaX, 0)); | 254 m_client->immediateScrollBy(FloatSize(deltaX, 0)); |
252 } | 255 } |
253 } else { | 256 } else { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 m_startTime = 0; | 409 m_startTime = 0; |
407 m_stretchScrollForce = FloatSize(); | 410 m_stretchScrollForce = FloatSize(); |
408 return; | 411 return; |
409 } | 412 } |
410 | 413 |
411 m_startTime = [NSDate timeIntervalSinceReferenceDate]; | 414 m_startTime = [NSDate timeIntervalSinceReferenceDate]; |
412 m_client->startSnapRubberbandTimer(); | 415 m_client->startSnapRubberbandTimer(); |
413 m_snapRubberbandTimerIsActive = true; | 416 m_snapRubberbandTimerIsActive = true; |
414 } | 417 } |
415 | 418 |
416 bool ScrollElasticityController::shouldRubberBandInHorizontalDirection(const Pla tformWheelEvent& wheelEvent) | 419 bool ScrollElasticityController::shouldHandleEvent(const PlatformWheelEvent& whe elEvent) |
417 { | 420 { |
418 if (wheelEvent.deltaX() > 0) | 421 if (m_hasScrolled) |
419 return m_client->shouldRubberBandInDirection(ScrollLeft); | 422 return true; |
420 if (wheelEvent.deltaX() < 0) | 423 if (!m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0))) |
421 return m_client->shouldRubberBandInDirection(ScrollRight); | 424 return true; |
425 | |
426 if (wheelEvent.deltaX() > 0 && !wheelEvent.canRubberbandLeft()) | |
427 return false; | |
428 if (wheelEvent.deltaX() < 0 && !wheelEvent.canRubberbandRight()) | |
429 return false; | |
422 | 430 |
423 return true; | 431 return true; |
424 } | 432 } |
425 | 433 |
426 } // namespace WebCore | 434 } // namespace WebCore |
427 | 435 |
428 #endif // USE(RUBBER_BANDING) | 436 #endif // USE(RUBBER_BANDING) |
OLD | NEW |