On Jan 7, 2013, at 10:02 PM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:

> Yes, that's right. But doesn't help the problem, unfortunately. The PDFView 
> is not the first responder when I'm typing, so the 'fault' is triggered when 
> the PDFView first becomes first responder then the NSSetFocusRingStyle part 
> of the code is called. The fault then persists.

Ah, I understand better now. I thought the NSSetFocusRingStyle part was getting 
called every time, but it seems it's only called the one time when the PDFView 
gets first responder (when you select something in the PDF). Thereafter, even 
after the PDFView is no longer first responder, you are seeing symptoms 
consistent with an infinite loop of drawing which causes invalidation which 
causes drawing again, etc.

On Jan 8, 2013, at 3:59 AM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:
> 
> On Jan 8, 2013, at 09:21 AM, Kyle Sluder <k...@ksluder.com> wrote:
[...]
>> Is there any particular reason you can't use the old 
>> -setKeyboardFocusRingNeedsDisplayInRect: method and draw your focus ring in 
>> your own graphics context in -drawRect:?
> 
> Maybe not. I just didn't know about this, but I will read up on it. However, 
> as far as my tests show, -drawRect: is never called on PDFView.

You're already calling setKeyboardFocusRingNeedsDisplayInRect: in 
become/resignFirstResponder, which seems like the right place. But I notice 
Apple's "Dicey" example project uses NSSetFocusRingStyle differently than you 
do. It pushes and pops the graphics state -- and thus, I believe, the clipping 
region -- instead of doing lockFocus on the superview. I bet this is how it 
avoids the infinite invalidating.

I think Kyle is suggesting something like what Apple does (taken from 
<http://developer.apple.com/library/mac/#samplecode/Dicey/Listings/DCDie_m.html>):

        [NSGraphicsContext saveGraphicsState];
        NSSetFocusRingStyle(NSFocusRingOnly);
        path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(bounds, 
-focusRectOffset, -focusRectOffset)  cornerRadius:(radius + (focusRectOffset / 
bounds.size.width))];
        [path fill];
        [NSGraphicsContext restoreGraphicsState];

(I got to the "Dicey" code from the "Related Sample Code" link in the docs for 
NSSetFocusRingStyle.)

--Andy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to