Re: PDFView drawPage called often after selecting text
Re: PDFView drawPage called often after selecting text
- Subject: Re: PDFView drawPage called often after selecting text
- From: Martin Hewitson <email@hidden>
- Date: Mon, 07 Jan 2013 11:48:09 +0100
Actually, at the risk of having a conversation with myself, I've narrowed the issue down to the actions I'm taking within my override of -drawPage:. Essentially what I'm aiming at is having a focus ring on the PDFView. I do this in my PDFView subclass:
- (void)drawPage:(PDFPage *)page {
[super drawPage:page];
// focussed?
if ([[self window] firstResponder] == self && [NSApp isActive]) {
[[self superview] lockFocus];
NSRect fr = [self frame];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect:fr] fill];
[[self superview] unlockFocus];
}
}
- (BOOL)becomeFirstResponder {
[self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
return [super becomeFirstResponder];
}
- (BOOL)resignFirstResponder {
[self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
return [super resignFirstResponder];
}
If I remove the call to NSSetFocusRingStyle and [NSBezierPath fill] then the problem goes away. Hmmm.
To make the matter more mysterious, I created a test app which loads the same PDF I'm testing the main app with, and has a text view in a split pane with a PDFView in the other split pane. I use the same PDFView subclass, and the problem isn't present. So clearly there's some strange interaction with the setting of this focus ring and some other element of my app. Am I somehow screwing up the drawing stuff with the locking and unlocking focus? A bit out of my depth here.....
Is there perhaps a better way I can achieve this focus ring without triggering this (recursive?) -drawPage: behaviour?
All ideas welcome,
Martin
On Jan 7, 2013, at 11:10 AM, Martin Hewitson <email@hidden> wrote:
> Dear list,
>
> I have an app which has a main split view. In the left panel there is a text editor (NSTextView), in the right panel there is a PDFView. I find that when typing in the text view, the -drawPage: method of the PDFView is called about once every 200ms but only if the PDFView is displaying a (large) graphic. I have this method overridden because I do some additional drawing. The problem is that if the drawing of the PDF page is heavy (due to the complex graphic), then the responsiveness of the text view becomes noticeably poorer. In fact the responsiveness of the whole app is affected.
>
> The strange thing is, that this behaviour is only triggered if I have selected text in the PDF at least once since loading the PDF document. If text has never been selected, then the -drawPage: is called only a couple of times at the beginning or when scrolling (as expected), but not when typing in the text view or doing other non-pdf related actions. Clearing the selected text (by just clicking somewhere on the PDFView) doesn't rectify the problem - it persists until the app is restarted.
>
> Can anyone explain to me why the -drawPage: method of PDFView is being called when I'm typing in the text view? I'm pretty sure I'm not calling it anywhere in my app. I've also checked that -setNeedsDisplay: is not being called on the PDFView.
>
> Could this be a PDFKit bug?
>
> Best wishes,
>
> Martin
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden