Revision: 14070
http://sourceforge.net/p/skim-app/code/14070
Author: hofman
Date: 2024-02-27 19:03:42 +0000 (Tue, 27 Feb 2024)
Log Message:
-----------
Override scroll by page in PDFView, because it scrolls by a too large amount
Modified Paths:
--------------
trunk/SKBasePDFView.m
Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m 2024-02-27 18:17:20 UTC (rev 14069)
+++ trunk/SKBasePDFView.m 2024-02-27 19:03:42 UTC (rev 14070)
@@ -311,6 +311,64 @@
[super goToDestination:destination];
}
+- (void)verticallyScrollPageUp:(id)sender {
+ NSScrollView *scrollView = [self scrollView];
+ NSClipView *clipView = [scrollView contentView];
+ NSView *docView = [self documentView];
+ NSRect bounds = [clipView bounds];
+ NSRect docRect = [docView convertRect:[docView bounds] toView:clipView];
+ CGFloat inset = [clipView contentInsets].top;
+
+ if ([clipView isFlipped])
+ bounds.origin.y = fmin(NSMaxY(docRect) - NSHeight(bounds),
NSMaxY(bounds) - inset - 10.0);
+ else
+ bounds.origin.y = fmax(NSMinY(docRect), NSMinY(bounds) -
NSHeight(bounds) + inset + 10.0);
+ [clipView scrollToPoint:bounds.origin];
+ [scrollView reflectScrolledClipView:clipView];
+}
+
+- (void)verticallyScrollPageDown:(id)sender {
+ NSScrollView *scrollView = [self scrollView];
+ NSClipView *clipView = [scrollView contentView];
+ NSView *docView = [self documentView];
+ NSRect bounds = [clipView bounds];
+ NSRect docRect = [docView convertRect:[docView bounds] toView:clipView];
+ CGFloat inset = [clipView contentInsets].top;
+
+ if ([clipView isFlipped])
+ bounds.origin.y = fmax(NSMinY(docRect) - inset, NSMinY(bounds) -
NSHeight(bounds) + inset + 10.0);
+ else
+ bounds.origin.y = fmin(NSMaxY(docRect) - NSHeight(bounds) + inset,
NSMaxY(bounds) - inset - 10.0);
+ [clipView scrollToPoint:bounds.origin];
+ [scrollView reflectScrolledClipView:clipView];
+}
+
+// PDFView scrolls by page with slightly more than the visible height
+// especially with (extra) contentInsets.
+// This really should be by slightly less than the visible height instead.
+// We should really override scrollPageUp:and scrollPageDown:,
+// but those are weirdly swapped in PDFView,
+// and we cannot be sure that will be true in the future.
+- (void)keyDown:(NSEvent *)theEvent {
+ unichar pageUpDown = 0;
+
+ if (hasVerticalLayout(self)) {
+ pageUpDown = [theEvent firstCharacter];
+ NSUInteger modifiers = [theEvent standardModifierFlags];
+ if ((pageUpDown == SKSpaceCharacter) && ((modifiers &
~NSEventModifierFlagShift) == 0))
+ pageUpDown = modifiers == NSEventModifierFlagShift ?
NSPageUpFunctionKey : NSPageDownFunctionKey;
+ else if (modifiers != 0 || (pageUpDown != NSPageUpFunctionKey &&
pageUpDown != NSPageDownFunctionKey))
+ pageUpDown = 0;
+ }
+
+ if (pageUpDown == NSPageDownFunctionKey)
+ [self verticallyScrollPageUp:self];
+ else if (pageUpDown == NSPageUpFunctionKey)
+ [self verticallyScrollPageDown:self];
+ else
+ [super keyDown:theEvent];
+}
+
static inline CGRect SKPixelAlignedRect(CGRect rect, CGContextRef context) {
CGRect r;
rect = CGContextConvertRectToDeviceSpace(context, rect);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit