@@ -118,7 +118,7 @@ - (void)setBoundsInset:(PGInset)inset
118
118
{
119
119
NSPoint const p = [self position ];
120
120
_boundsInset = inset;
121
- [self scrollTo: p allowAnimation: NO ];
121
+ [self scrollTo: p mode: PGScrollNoAnimation ];
122
122
}
123
123
- (NSRect )insetBounds
124
124
{
@@ -234,12 +234,16 @@ - (NSPoint)position
234
234
{
235
235
return _scrollTimer ? _position : _immediatePosition;
236
236
}
237
+ - (NSPoint )positionForScrollMode : (PGScrollMode)mode
238
+ {
239
+ return PGScrollKeepCurrent == mode ? _immediatePosition : [self position ];
240
+ }
237
241
238
242
- (BOOL )scrollTo : (NSPoint )aPoint
239
- allowAnimation : ( BOOL ) flag
243
+ mode : (PGScrollMode) mode
240
244
{
241
- if (!PGAnimateScrolling || !flag ) {
242
- [self stopAnimatedScrolling ];
245
+ if (PGScrollAllowAnimation != mode ) {
246
+ if (PGAnimateScrolling && PGScrollNoAnimation == mode) [self stopAnimatedScrolling ];
243
247
return [self _scrollTo: aPoint];
244
248
}
245
249
NSPoint const newTargetPosition = PGPointInRect (aPoint, [self scrollableRectWithBorder: YES ]);
@@ -252,20 +256,20 @@ - (BOOL)scrollTo:(NSPoint)aPoint
252
256
return YES ;
253
257
}
254
258
- (BOOL )scrollBy : (NSSize )aSize
255
- allowAnimation : ( BOOL ) flag
259
+ mode : (PGScrollMode) mode
256
260
{
257
- return [self scrollTo: PGOffsetPointBySize ([self position ], aSize) allowAnimation: flag ];
261
+ return [self scrollTo: PGOffsetPointBySize ([self positionForScrollMode: mode ], aSize) mode: mode ];
258
262
}
259
263
- (BOOL )scrollToEdge : (PGRectEdgeMask)mask
260
- allowAnimation : ( BOOL ) flag
264
+ mode : (PGScrollMode) mode
261
265
{
262
266
NSAssert (!PGHasContradictoryRectEdges(mask), @"Can't scroll to contradictory edges.");
263
- return [self scrollBy: PGRectEdgeMaskToSizeWithMagnitude (mask, FLT_MAX) allowAnimation: flag ];
267
+ return [self scrollBy: PGRectEdgeMaskToSizeWithMagnitude (mask, FLT_MAX) mode: mode ];
264
268
}
265
269
- (BOOL )scrollToLocation : (PGPageLocation)location
266
- allowAnimation : ( BOOL ) flag
270
+ mode : (PGScrollMode) mode
267
271
{
268
- return [self scrollToEdge: [[self delegate ] clipView: self directionFor: location] allowAnimation: flag ];
272
+ return [self scrollToEdge: [[self delegate ] clipView: self directionFor: location] mode: mode ];
269
273
}
270
274
271
275
- (void )stopAnimatedScrolling
@@ -295,13 +299,12 @@ - (NSSize)pinLocationOffset
295
299
return NSMakeSize (diff.width * 2 .0f / NSWidth (_documentFrame), diff.height * 2 .0f / NSHeight (_documentFrame));
296
300
}
297
301
- (BOOL )scrollPinLocationToOffset : (NSSize )aSize
298
- allowAnimation : (BOOL )flag
299
302
{
300
303
NSSize o = aSize;
301
304
NSRect const b = [self insetBounds ];
302
305
PGRectEdgeMask const pin = [self pinLocation ];
303
306
if ([[self documentView ] scalesContentWithFrameSizeInClipView: self ]) o = NSMakeSize (o.width * NSWidth (_documentFrame) * 0 .5f , o.height * NSHeight (_documentFrame) * 0 .5f );
304
- return [self scrollTo: PGOffsetPointBySize ([ self position ], PGPointDiff (PGOffsetPointBySize (PGPointOfPartOfRect (_documentFrame, pin), o), PGPointOfPartOfRect (b, pin))) allowAnimation: flag ];
307
+ return [self scrollBy: PGPointDiff (PGOffsetPointBySize (PGPointOfPartOfRect (_documentFrame, pin), o), PGPointOfPartOfRect (b, pin)) mode: PGScrollKeepCurrent ];
305
308
}
306
309
307
310
#pragma mark -
@@ -313,11 +316,11 @@ - (NSPoint)center
313
316
return PGOffsetPointByXY ([self position ], inset.minX + NSWidth (b) / 2 , inset.minY + NSHeight (b) / 2 );
314
317
}
315
318
- (BOOL )scrollCenterTo : (NSPoint )aPoint
316
- allowAnimation : ( BOOL ) flag
319
+ mode : (PGScrollMode) mode
317
320
{
318
321
NSRect const b = [self insetBounds ];
319
322
PGInset const inset = [self boundsInset ];
320
- return [self scrollTo: PGOffsetPointByXY (aPoint, -inset.minX - NSWidth (b) / 2 , -inset.minY - NSHeight (b) / 2 ) allowAnimation: flag ];
323
+ return [self scrollTo: PGOffsetPointByXY (aPoint, -inset.minX - NSWidth (b) / 2 , -inset.minY - NSHeight (b) / 2 ) mode: mode ];
321
324
}
322
325
323
326
#pragma mark -
@@ -356,8 +359,8 @@ - (BOOL)handleMouseDown:(NSEvent *)firstEvent
356
359
} else [[NSCursor closedHandCursor ] push ];
357
360
[self PG_cancelPreviousPerformRequestsWithSelector: @selector (_beginPreliminaryDrag ) object: nil ];
358
361
}
359
- if (PGMouseHiddenDraggingStyle) [self scrollBy: NSMakeSize (-[latestEvent deltaX ], [latestEvent deltaY ]) allowAnimation: NO ];
360
- else [self scrollTo: PGOffsetPointByXY (dragPoint, -[latestEvent locationInWindow ].x, -[latestEvent locationInWindow ].y) allowAnimation: NO ];
362
+ if (PGMouseHiddenDraggingStyle) [self scrollBy: NSMakeSize (-[latestEvent deltaX ], [latestEvent deltaY ]) mode: PGScrollNoAnimation ];
363
+ else [self scrollTo: PGOffsetPointByXY (dragPoint, -[latestEvent locationInWindow ].x, -[latestEvent locationInWindow ].y) mode: PGScrollNoAnimation ];
361
364
finalPoint = PGPointInRect (PGOffsetPointByXY (finalPoint, [latestEvent deltaX ], -[latestEvent deltaY ]), availableDragRect);
362
365
}
363
366
[self PG_cancelPreviousPerformRequestsWithSelector: @selector (_beginPreliminaryDrag ) object: nil ];
@@ -391,7 +394,7 @@ - (void)arrowKeyDown:(NSEvent *)firstEvent
391
394
if (currentTime > pageTurnTime + PGPageTurnMovementDelay) {
392
395
NSSize const d = [self distanceInDirection: PGNonContradictoryRectEdges (pressedDirections) forScrollType: PGScrollByLine];
393
396
float const timeAdjustment = lastScrollTime ? PGAnimationFramerate / (currentTime - lastScrollTime) : 1 ;
394
- [self scrollBy: NSMakeSize (d.width / timeAdjustment, d.height / timeAdjustment) allowAnimation: NO ];
397
+ [self scrollBy: NSMakeSize (d.width / timeAdjustment, d.height / timeAdjustment) mode: PGScrollNoAnimation ];
395
398
}
396
399
lastScrollTime = currentTime;
397
400
continue ;
@@ -420,7 +423,7 @@ - (void)arrowKeyDown:(NSEvent *)firstEvent
420
423
- (void )scrollInDirection : (PGRectEdgeMask)direction
421
424
type : (PGScrollType)scrollType
422
425
{
423
- if (![self shouldExitForMovementInDirection: direction] || ![[self delegate ] clipView: self shouldExitEdges: direction]) [self scrollBy: [self distanceInDirection: direction forScrollType: scrollType] allowAnimation: YES ];
426
+ if (![self shouldExitForMovementInDirection: direction] || ![[self delegate ] clipView: self shouldExitEdges: direction]) [self scrollBy: [self distanceInDirection: direction forScrollType: scrollType] mode: PGScrollAllowAnimation ];
424
427
}
425
428
- (void )magicPanForward : (BOOL )forward
426
429
acrossFirst : (BOOL )across
@@ -439,7 +442,7 @@ - (void)magicPanForward:(BOOL)forward
439
442
} else if (across) position.x = FLT_MAX * (mask & PGMinXEdgeMask ? 1 : -1 );
440
443
else position.y = FLT_MAX * (mask & PGMinYEdgeMask ? 1 : -1 );
441
444
}
442
- [self scrollTo: position allowAnimation: YES ];
445
+ [self scrollTo: position mode: PGScrollAllowAnimation ];
443
446
}
444
447
445
448
#pragma mark -
@@ -449,7 +452,7 @@ - (void)viewFrameDidChange:(NSNotification *)aNotif
449
452
[self stopAnimatedScrolling ];
450
453
NSSize const offset = [self pinLocationOffset ];
451
454
_documentFrame = [documentView frame ];
452
- [self scrollPinLocationToOffset: offset allowAnimation: NO ];
455
+ [self scrollPinLocationToOffset: offset];
453
456
}
454
457
455
458
#pragma mark Private Protocol
@@ -458,7 +461,7 @@ - (BOOL)_setPosition:(NSPoint)aPoint
458
461
markForRedisplayIfNeeded : (BOOL )flag
459
462
{
460
463
NSPoint const newPosition = PGPointInRect (aPoint, [self scrollableRectWithBorder: YES ]);
461
- [[self PG_enclosingClipView ] scrollBy: NSMakeSize (aPoint.x - newPosition.x, aPoint.y - newPosition.y) allowAnimation: NO ];
464
+ [[self PG_enclosingClipView ] scrollBy: NSMakeSize (aPoint.x - newPosition.x, aPoint.y - newPosition.y) mode: PGScrollKeepCurrent ];
462
465
if (NSEqualPoints (newPosition, _immediatePosition)) return NO ;
463
466
_immediatePosition = newPosition;
464
467
[self setBoundsOrigin: NSMakePoint (floorf (_immediatePosition.x), floorf (_immediatePosition.y))];
@@ -605,7 +608,7 @@ - (void)scrollWheel:(NSEvent *)anEvent
605
608
{
606
609
[NSCursor setHiddenUntilMouseMoves: YES ];
607
610
float const x = -[anEvent deltaX ], y = [anEvent deltaY ];
608
- [self scrollBy: NSMakeSize (x * PGLineScrollDistance, y * PGLineScrollDistance) allowAnimation: YES ];
611
+ [self scrollBy: NSMakeSize (x * PGLineScrollDistance, y * PGLineScrollDistance) mode: PGScrollAllowAnimation ];
609
612
}
610
613
611
614
#pragma mark -
@@ -699,11 +702,11 @@ - (void)moveRight:(id)sender
699
702
700
703
- (IBAction )moveToBeginningOfDocument : (id )sender
701
704
{
702
- [self scrollToLocation: PGHomeLocation allowAnimation: YES ];
705
+ [self scrollToLocation: PGHomeLocation mode: PGScrollAllowAnimation ];
703
706
}
704
707
- (IBAction )moveToEndOfDocument : (id )sender
705
708
{
706
- [self scrollToLocation: PGEndLocation allowAnimation: YES ];
709
+ [self scrollToLocation: PGEndLocation mode: PGScrollAllowAnimation ];
707
710
}
708
711
- (IBAction )scrollPageUp : (id )sender
709
712
{
0 commit comments