Workaround for the 1-pt-tall-notification-window problem (#108).
authorPeter Hosey <hg@boredzo.org>
Mon Feb 08 07:41:51 2010 -0800 (2010-02-08)
changeset 45866ae6091ed8c6
parent 4585 24284121d2cc
child 4587 143e3f0ba924
Workaround for the 1-pt-tall-notification-window problem (#108).

The problem seems to be that WebKit hasn't finished laying out the content, even by the time of webView:didFinishLoadForFrame:. It may be that WebKit is getting distracted and laying out other notifications before it finishes the first.

An apparent fix is to only attempt to get and use the size after a delay, at least when the size isn't already in yet. I'm not yet certain that this is a real fix, but it at least makes the problem much less frequent, to the point that I'm no longer able to reproduce it.
Plugins/Displays/WebKit/GrowlWebKitWindowController.m
     1.1 --- a/Plugins/Displays/WebKit/GrowlWebKitWindowController.m	Mon Feb 08 03:51:30 2010 -0800
     1.2 +++ b/Plugins/Displays/WebKit/GrowlWebKitWindowController.m	Mon Feb 08 07:41:51 2010 -0800
     1.3 @@ -45,6 +45,10 @@
     1.4  - (NSData *)PNGRepresentation;
     1.5  @end
     1.6  
     1.7 +@interface GrowlWebKitWindowController ()
     1.8 +- (void) viewIsReady:(GrowlWebKitWindowView *)view;
     1.9 +@end
    1.10 +
    1.11  @implementation GrowlWebKitWindowController
    1.12  
    1.13  #define GrowlWebKitDurationPrefDefault				5.0
    1.14 @@ -253,11 +257,19 @@
    1.15  - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
    1.16  	if (frame != [sender mainFrame]) return;
    1.17  
    1.18 +	if ([[[frame frameView] documentView] frame].size.height < 2.0f) {
    1.19 +		//Finished loading it may be, but it's not finished rendering, in which case the document view's height will be 1 px. Not good for sizing to fit. So, try again one cycle of the run loop from now.
    1.20 +		[self performSelector:@selector(viewIsReady:) withObject:sender afterDelay:0.0];
    1.21 +	} else {
    1.22 +		//It really is done, so just call through directly.
    1.23 +		[self viewIsReady:(GrowlWebKitWindowView *)sender];
    1.24 +	}
    1.25 +}
    1.26 +- (void) viewIsReady:(GrowlWebKitWindowView *)view {
    1.27  	NSWindow *myWindow = [self window];
    1.28  	if ([myWindow isFlushWindowDisabled])
    1.29  		[myWindow enableFlushWindow];
    1.30  
    1.31 -	GrowlWebKitWindowView *view = (GrowlWebKitWindowView *)sender;
    1.32  	[view sizeToFit];
    1.33  
    1.34  	//Update our new frame