Peter Hosey avatar Peter Hosey committed 6ae6091

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.

Comments (0)

Files changed (1)

Plugins/Displays/WebKit/GrowlWebKitWindowController.m

 - (NSData *)PNGRepresentation;
 @end
 
+@interface GrowlWebKitWindowController ()
+- (void) viewIsReady:(GrowlWebKitWindowView *)view;
+@end
+
 @implementation GrowlWebKitWindowController
 
 #define GrowlWebKitDurationPrefDefault				5.0
 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
 	if (frame != [sender mainFrame]) return;
 
+	if ([[[frame frameView] documentView] frame].size.height < 2.0f) {
+		//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.
+		[self performSelector:@selector(viewIsReady:) withObject:sender afterDelay:0.0];
+	} else {
+		//It really is done, so just call through directly.
+		[self viewIsReady:(GrowlWebKitWindowView *)sender];
+	}
+}
+- (void) viewIsReady:(GrowlWebKitWindowView *)view {
 	NSWindow *myWindow = [self window];
 	if ([myWindow isFlushWindowDisabled])
 		[myWindow enableFlushWindow];
 
-	GrowlWebKitWindowView *view = (GrowlWebKitWindowView *)sender;
 	[view sizeToFit];
 
 	//Update our new frame
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.