Bug 14623 - Need drawRect called on WebView subclass
Summary: Need drawRect called on WebView subclass
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: 419.x
Hardware: Mac OS X 10.4
: P3 Enhancement
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2007-07-14 22:23 PDT by Jim Casper
Modified: 2007-12-10 06:34 PST (History)
1 user (show)

See Also:


Attachments
Minimal test app demonstrating drawRect not getting called in WebView subclass (30.68 KB, application/octet-stream)
2007-07-15 15:39 PDT, Jim Casper
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Casper 2007-07-14 22:23:37 PDT
I have found (along with others in the past) that drawRect is not called on subclasses of WebView because the normal AppKit view drawing is bypassed. I would like to request that drawRect be called on WebView subclasses or a replacement method introduced so that drawing on top of a WebView can be done.

My needs in this case are pretty simple - I just want to draw a highlighting frame around the view borders indicating that the view is a drop target for drag and drop.
Comment 1 Mark Rowe (bdash) 2007-07-15 09:45:22 PDT
A very simple workaround would be to use an overlay window, similar to how the web inspector highlights the "active" node in a document.  Looking at the WebView implementation, it doesn't implement drawRect: itself nor does it appear to prevent it from being called.  The real drawing work is done by subviews such as WebFrameView and WebHTMLView.  It's not clear from my quick flick through the code why what you describe would not work.
Comment 2 Jim Casper 2007-07-15 14:14:23 PDT
(In reply to comment #1)
> A very simple workaround would be to use an overlay window, similar to how the
> web inspector highlights the "active" node in a document.  Looking at the
> WebView implementation, it doesn't implement drawRect: itself nor does it
> appear to prevent it from being called.  The real drawing work is done by
> subviews such as WebFrameView and WebHTMLView.  It's not clear from my quick
> flick through the code why what you describe would not work.
> 

I don't pretend to understand the inner workings of WebKit, but I did find on Google someone who mentioned WebKit bypassing the normal AppKit flow. I found in the file WebHTMLView.mm the following: 

// Don't let AppKit even draw subviews. We take care of that.
- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:

I did not find anything that would prevent WebView's drawRect from being called, but in a small test project I again found it to not be called.

I'll give your overlay method a try. Thanks for your quick reply.
Comment 3 Mark Rowe (bdash) 2007-07-15 15:07:42 PDT
WebHTMLView is a subview of the WebView, so I don't think it's trickery using _recursiveDisplayRectIfNeededIgnoringOpacity can interfere with the rendering of WebView itself.  It'd be great if you could attach a minimal application demonstrating an attempt to override drawRect: so we're both looking at the same situation.
Comment 4 Jim Casper 2007-07-15 15:39:18 PDT
Created attachment 15525 [details]
Minimal test app demonstrating drawRect not getting called in WebView subclass
Comment 5 Jim Casper 2007-07-15 15:41:40 PDT
Comment on attachment 15525 [details]
Minimal test app demonstrating drawRect not getting called in WebView subclass

After thinking about it more, drawRect probably won't help me anyway since I need to draw on top of subviews, not under them. I will go with your overlay window method.
Comment 6 Mark Rowe (bdash) 2007-09-16 02:48:10 PDT
<rdar://problem/5484863>