[webkit-reviews] patch for webview bustage after trying to print invalid page range

Maciej Stachowiak mjs at apple.com
Mon Jun 13 16:57:56 PDT 2005


Assuming you tested, r=me.

On Jun 13, 2005, at 4:34 PM, John Sullivan wrote:

> 2005-06-13  John Sullivan  <sullivan at apple.com>
>
>         Reviewed by NOBODY (OOPS!).
>
>         - fixed <rdar://problem/4145905> WebView: Attempting to  
> print an invalid page range
>         results in unusable window
>
>         * WebView.subproj/WebHTMLView.m:
>         (-[WebHTMLView _endPrintMode:]):
>         new method, extracted from identical code in beginDocument  
> and endDocument. This method must be called
>         once to counterbalance the code called from knowsPageRange  
> that turns on "printing mode".
>         (-[WebHTMLView knowsPageRange:]):
>         after turning on "printing mode", queue up a delayed call  
> to _endPrintMode:. If there's an early
>         error in the print mechanism such that beginDocument is  
> never called, this will cleanly end "printing
>         mode" and make the webview usable again.
>         (-[WebHTMLView beginDocument]):
>         cancel any delayed call to _endPrintMode:. If we get this  
> far along in printing, then we don't need
>         the failsafe call to _endPrintMode: that was set up in  
> knowsPageRange:. Also, call extracted method
>         (-[WebHTMLView endDocument]):
>         call extracted method
>
> Index: WebView.subproj/WebHTMLView.m
> ===================================================================
> RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLView.m,v
> retrieving revision 1.449
> diff -u -r1.449 WebHTMLView.m
> --- WebView.subproj/WebHTMLView.m    13 Jun 2005 03:28:08 -0000     
> 1.449
> +++ WebView.subproj/WebHTMLView.m    13 Jun 2005 23:11:42 -0000
> @@ -3148,6 +3148,11 @@
>      [self _setPrinting:YES minimumPageWidth:pageWidth  
> maximumPageWidth:pageWidth adjustViewSize:YES];
> }
> +- (void)_endPrintMode:(id)unused
> +{
> +    [self _setPrinting:NO minimumPageWidth:0.0 maximumPageWidth: 
> 0.0 adjustViewSize:YES];
> +    [[self window] setAutodisplay:YES];
> +}
> // Return the number of pages available for printing
> - (BOOL)knowsPageRange:(NSRangePointer)range {
> @@ -3166,6 +3171,11 @@
>          maxLayoutWidth = paperWidth*PrintingMaximumShrinkFactor;
>      }
>      [self _setPrinting:YES minimumPageWidth:minLayoutWidth  
> maximumPageWidth:maxLayoutWidth adjustViewSize:YES]; // will relayout
> +    // Certain types of errors, including invalid page ranges, can  
> cause beginDocument and
> +    // endDocument to be skipped after we've put ourselves in  
> print mode (see 4145905). In those cases
> +    // we need to get out of print mode without relying on any  
> more callbacks from the printing mechanism.
> +    // If we get as far as beginDocument without trouble, then  
> this delayed request will be cancelled.
> +    [self performSelector:@selector(_endPrintMode:) withObject:nil  
> afterDelay:0];
>      [[self _webView] _adjustPrintingMarginsForHeaderAndFooter];
>
>      // There is a theoretical chance that someone could do some  
> drawing between here and endDocument,
> @@ -3207,12 +3217,16 @@
> - (void)beginDocument
> {
>      NS_DURING
> +        // From now on we'll get a chance to call _endPrintMode:  
> in either beginDocument or
> +        // endDocument, so we can cancel the "just in case"  
> pending call.
> +        [NSObject cancelPreviousPerformRequestsWithTarget:self
> +                                                 selector:@selector 
> (_endPrintMode:)
> +                                                   object:nil];
>          [super beginDocument];
>      NS_HANDLER
>          // Exception during [super beginDocument] means that  
> endDocument will not get called,
>          // so we need to clean up our "print mode" here.
> -        [self _setPrinting:NO minimumPageWidth:0.0  
> maximumPageWidth:0.0 adjustViewSize:YES];
> -        [[self window] setAutodisplay:YES];
> +        [self _endPrintMode:nil];
>      NS_ENDHANDLER
> }
> @@ -3220,8 +3234,7 @@
> {
>      [super endDocument];
>      // Note sadly at this point [NSGraphicsContext  
> currentContextDrawingToScreen] is still NO
> -    [self _setPrinting:NO minimumPageWidth:0.0 maximumPageWidth: 
> 0.0 adjustViewSize:YES];
> -    [[self window] setAutodisplay:YES];
> +    [self _endPrintMode:nil];
> }
> - (BOOL)_interceptEditingKeyEvent:(NSEvent *)event
>
> _______________________________________________
> webkit-reviews mailing list
> webkit-reviews at opendarwin.org
> http://www.opendarwin.org/mailman/listinfo/webkit-reviews
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/webkit-reviews/attachments/20050613/b82864a7/attachment.html


More information about the webkit-reviews mailing list