[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

sullivan sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:24:38 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit deb73251470e9bb5e1ebf36ea2f98c3818095265
Author: sullivan <sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 29 02:16:33 2004 +0000

    Tests:
    
            Reviewed by Dave.
    
            * Blot/blot-tasks.txt:
            Mentioned NSTextView's (and therefore Mail's) option-Escape behavior here
            since we will probably have to implement it also; clarified a comment.
    
    WebCore:
    
            Reviewed by Dave.
    
            * khtml/rendering/render_text.cpp:
            (RenderText::paintObject):
            Increment s in the while() clause so it is incremented even
            after a continue statement. This fixes an infinite loop I ran
            into in the printing code path at certain scaled print sizes
            on certain pages.
    
    WebKit:
    
            More header/footer work: refactored the header/footer code so it could
            be easily reused by other WebDocument classes; used it from WebImageView
            and WebTextView; removed the page count parameters because it's possible
            (though currently nasty, see 3543078) to determine this in the client.
    
            Reviewed by Dave.
    
            * Misc.subproj/WebNSPrintOperationExtras.h Added.
            * Misc.subproj/WebNSPrintOperationExtras.m Added.
            (-[NSPrintOperation _web_pageSetupScaleFactor]):
            new convenience method.
    
            * WebView.subproj/WebUIDelegatePrivate.h:
            Removed page index and page count parameters from delegate methods.
    
            * WebView.subproj/WebViewPrivate.h:
            New private category for header/footer printing methods so that different
            WebDocument methods can share almost all of the code.
    
            * WebView.subproj/WebView.m:
            (-[WebView _headerHeight]):
            (-[WebView _footerHeight]):
            (-[WebView _drawHeaderInRect:]):
            (-[WebView _drawFooterInRect:]):
            (-[WebView _adjustPrintingMarginsForHeaderAndFooter]):
            (-[WebView _drawHeaderAndFooter]):
            Moved all of these methods here, formerly in WebHTMLView. Removed the
            page index and page count parameters.
    
            * WebView.subproj/WebHTMLView.m:
            Removed all the header/footer code that's now in WebView.m, and the
            method that's now -[NSPrintOperation _web_pageSetupScaleFactor]
            (-[WebHTMLView _setPrinting:minimumPageWidth:maximumPageWidth:adjustViewSize:]):
            call methods differently that have now been moved
            (-[WebHTMLView _scaleFactorForPrintOperation:]):
            ditto
            (-[WebHTMLView knowsPageRange:]):
            ditto
            (-[WebHTMLView drawPageBorderWithSize:]):
            now just turns around and calls -[WebView _drawHeaderAndFooter]
    
            * WebView.subproj/WebImageView.m:
            (-[WebImageView drawPageBorderWithSize:]):
            new method, just calls -[WebView _drawHeaderAndFooter]
            (-[WebImageView beginDocument]):
            now calls -[WebView _adjustPrintMarginsForHeaderAndFooter], also moved in file.
            (-[WebImageView endDocument]):
            just moved in file.
    
            * WebView.subproj/WebTextView.m:
            (-[WebTextView drawPageBorderWithSize:]):
            new method, just calls -[WebView _drawHeaderAndFooter]
            (-[WebTextView knowsPageRange:]):
            overridden to call -[WebView _adjustPrintMarginsForHeaderAndFooter]
    
            * WebKit.pbproj/project.pbxproj:
            updated for added files
    
    WebBrowser:
    
            Some header/footer cleanup.
    
            Reviewed by Dave.
    
            * BrowserWebViewPrinting.m:
            (-[BrowserWebView webView:drawHeaderInRect:]):
            Removed obsolete page index and count parameters.
            Use displayName rather than currentTitle because it works for all
            document types (currentTitle didn't work for plain text pages).
            (-[BrowserWebView webView:drawFooterInRect:]):
            Removed obsolete page index and count parameters.
            Did some AppKit hackery to get the total document page count in a way that
            works for any print operation. Now handles the case where the page count
            is unknown (by printing "Page <x>" instead of "Page <x> of <n>"). Also added
            a 1 pixel offset to the footer's baseline to work around AppKit bug where
            the descenders in the footer were getting slightly clipped at some scale
            factors.
    
            * English.lproj/Localizable.strings:
            updated for these changes
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6004 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index b3b1bcf..f3f1cf4 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,14 @@
+2004-01-28  John Sullivan  <sullivan at apple.com>
+
+        Reviewed by Dave.
+
+        * khtml/rendering/render_text.cpp:
+        (RenderText::paintObject):
+        Increment s in the while() clause so it is incremented even
+        after a continue statement. This fixes an infinite loop I ran
+        into in the printing code path at certain scaled print sizes
+        on certain pages.
+
 2004-01-28  Chris Blumenberg  <cblu at apple.com>
 
 	Fixed: <rdar://problem/3543041>: when pasting an image, cursor should be after the image, not before
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index 59d8926..49535af 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -776,9 +776,7 @@ void RenderText::paintObject(QPainter *p, int /*x*/, int y, int /*w*/, int h,
         }
 #endif
 
-        s = s->nextTextBox();
-        
-    } while (s && s->checkVerticalPoint(y, ty, h));
+    } while (((s = s->nextTextBox()) != 0) && s->checkVerticalPoint(y, ty, h));
 
 #if APPLE_CHANGES
     } // end of for loop
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index dc814e8..320373d 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,64 @@
+2004-01-28  John Sullivan  <sullivan at apple.com>
+
+        More header/footer work: refactored the header/footer code so it could
+        be easily reused by other WebDocument classes; used it from WebImageView
+        and WebTextView; removed the page count parameters because it's possible
+        (though currently nasty, see 3543078) to determine this in the client.
+
+        Reviewed by Dave.
+
+        * Misc.subproj/WebNSPrintOperationExtras.h Added.
+        * Misc.subproj/WebNSPrintOperationExtras.m Added.
+        (-[NSPrintOperation _web_pageSetupScaleFactor]):
+        new convenience method.
+                
+        * WebView.subproj/WebUIDelegatePrivate.h:
+        Removed page index and page count parameters from delegate methods.
+        
+        * WebView.subproj/WebViewPrivate.h:
+        New private category for header/footer printing methods so that different
+        WebDocument methods can share almost all of the code.
+        
+        * WebView.subproj/WebView.m:
+        (-[WebView _headerHeight]):
+        (-[WebView _footerHeight]):
+        (-[WebView _drawHeaderInRect:]):
+        (-[WebView _drawFooterInRect:]):
+        (-[WebView _adjustPrintingMarginsForHeaderAndFooter]):
+        (-[WebView _drawHeaderAndFooter]):
+        Moved all of these methods here, formerly in WebHTMLView. Removed the
+        page index and page count parameters.
+
+        * WebView.subproj/WebHTMLView.m:
+        Removed all the header/footer code that's now in WebView.m, and the
+        method that's now -[NSPrintOperation _web_pageSetupScaleFactor]
+        (-[WebHTMLView _setPrinting:minimumPageWidth:maximumPageWidth:adjustViewSize:]):
+        call methods differently that have now been moved
+        (-[WebHTMLView _scaleFactorForPrintOperation:]):
+        ditto
+        (-[WebHTMLView knowsPageRange:]):
+        ditto
+        (-[WebHTMLView drawPageBorderWithSize:]):
+        now just turns around and calls -[WebView _drawHeaderAndFooter]
+        
+        * WebView.subproj/WebImageView.m:
+        (-[WebImageView drawPageBorderWithSize:]):
+        new method, just calls -[WebView _drawHeaderAndFooter]
+        (-[WebImageView beginDocument]):
+        now calls -[WebView _adjustPrintMarginsForHeaderAndFooter], also moved in file.
+        (-[WebImageView endDocument]):
+        just moved in file.
+
+        * WebView.subproj/WebTextView.m:
+        (-[WebTextView drawPageBorderWithSize:]):
+        new method, just calls -[WebView _drawHeaderAndFooter]        
+        (-[WebTextView knowsPageRange:]):
+        overridden to call -[WebView _adjustPrintMarginsForHeaderAndFooter]
+        
+        * WebKit.pbproj/project.pbxproj:
+        updated for added files
+
+
 2004-01-28  Chris Blumenberg  <cblu at apple.com>
 
 	Fixed: <rdar://problem/3197222>: need context menu items for back, forward, refresh.
diff --git a/WebKit/Misc.subproj/WebNSPrintOperationExtras.h b/WebKit/Misc.subproj/WebNSPrintOperationExtras.h
new file mode 100644
index 0000000..903a726
--- /dev/null
+++ b/WebKit/Misc.subproj/WebNSPrintOperationExtras.h
@@ -0,0 +1,16 @@
+//
+//  WebNSPrintOperationExtras.h
+//  WebKit
+//
+//  Created by John Sullivan on Wed Jan 28 2004.
+//  Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface NSPrintOperation (WebKitExtras)
+
+- (float)_web_pageSetupScaleFactor;
+
+ at end
diff --git a/WebKit/Misc.subproj/WebNSPrintOperationExtras.m b/WebKit/Misc.subproj/WebNSPrintOperationExtras.m
new file mode 100644
index 0000000..39ddfad
--- /dev/null
+++ b/WebKit/Misc.subproj/WebNSPrintOperationExtras.m
@@ -0,0 +1,19 @@
+//
+//  WebNSPrintOperationExtras.m
+//  WebKit
+//
+//  Created by John Sullivan on Wed Jan 28 2004.
+//  Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+//
+
+#import "WebNSPrintOperationExtras.h"
+
+
+ at implementation NSPrintOperation (WebKitExtras)
+
+- (float)_web_pageSetupScaleFactor
+{
+    return [[[[self printInfo] dictionary] objectForKey:NSPrintScalingFactor] floatValue];
+}
+
+ at end
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index e2e3a2a..3e38696 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -333,6 +333,7 @@
 				BE887C01056D3A6E009BB3E7,
 				84723BE5056D719E0044BFEA,
 				830E81850585375700AD0891,
+				EDD1A5C805C83987008E3150,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -450,6 +451,7 @@
 				BE887C02056D3A6E009BB3E7,
 				84723BE6056D719E0044BFEA,
 				830E81860585375700AD0891,
+				EDD1A5C905C83987008E3150,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -556,6 +558,8 @@
 				8398847B03426FB000BC5F5E,
 				ED2B2474033A2DA800C1A526,
 				ED2B2475033A2DA800C1A526,
+				EDD1A5C605C83987008E3150,
+				EDD1A5C705C83987008E3150,
 				BE6DC39904C62C4E004D0EF6,
 				BE6DC39A04C62C4E004D0EF6,
 				F508946902B71D59018A9CD4,
@@ -3131,6 +3135,34 @@
 			settings = {
 			};
 		};
+		EDD1A5C605C83987008E3150 = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.c.h;
+			path = WebNSPrintOperationExtras.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		EDD1A5C705C83987008E3150 = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			lastKnownFileType = sourcecode.c.objc;
+			path = WebNSPrintOperationExtras.m;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		EDD1A5C805C83987008E3150 = {
+			fileRef = EDD1A5C605C83987008E3150;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		EDD1A5C905C83987008E3150 = {
+			fileRef = EDD1A5C705C83987008E3150;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 //ED0
 //ED1
 //ED2
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 06e445b..97b305e 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -18,6 +18,7 @@
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebNSPasteboardExtras.h>
+#import "WebNSPrintOperationExtras.h"
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPluginController.h>
 #import <WebKit/WebTextRenderer.h>
@@ -83,10 +84,7 @@ static BOOL forceRealHitTest = NO;
 - (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize;
 - (void)_updateTextSizeMultiplier;
 - (float)_calculatePrintHeight;
-- (float)_footerHeight;
-- (float)_headerHeight;
 - (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation;
-- (float)_userScaleFactorForPrintOperation:(NSPrintOperation *)printOperation;
 @end
 
 // Any non-zero value will do, but using somethign recognizable might help us debug some day.
@@ -1676,95 +1674,6 @@ static WebHTMLView *lastHitView = nil;
 {
 }
 
-//#define DEBUG_HEADER_AND_FOOTER
-
-- (float)_headerHeight
-{
-    // FIXME: headers and footers are only drawn for HTMLView, not for other views
-    // such as plain text or standalone images
-    if ([[[self _webView] UIDelegate] respondsToSelector:@selector(webViewHeaderHeight:)]) {
-        return [[[self _webView] UIDelegate] webViewHeaderHeight:[self _webView]];
-    }
-
-#ifdef DEBUG_HEADER_AND_FOOTER
-    return 25;
-#else
-    return 0;
-#endif
-}
-
-- (float)_footerHeight
-{
-    // FIXME: headers and footers are only drawn for HTMLView, not for other views
-    // such as plain text or standalone images
-    if ([[[self _webView] UIDelegate] respondsToSelector:@selector(webViewFooterHeight:)]) {
-        return [[[self _webView] UIDelegate] webViewFooterHeight:[self _webView]];
-    }
-    
-#ifdef DEBUG_HEADER_AND_FOOTER
-    return 50;
-#else
-    return 0;
-#endif
-}
-
-- (void)_drawHeaderInRect:(NSRect)rect
-{
-#ifdef DEBUG_HEADER_AND_FOOTER
-    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
-    [currentContext saveGraphicsState];
-    [[NSColor yellowColor] set];
-    NSRectFill(rect);
-    [currentContext restoreGraphicsState];
-#endif
-    
-    // FIXME: headers and footers are only drawn for HTMLView, not for other views
-    // such as plain text or standalone images
-    if ([[[self _webView] UIDelegate] respondsToSelector:@selector(webView:drawHeaderInRect:forPage:of:)]) {
-        NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
-        [currentContext saveGraphicsState];
-        NSRectClip(rect);
-        [[[self _webView] UIDelegate] webView:[self _webView] 
-                             drawHeaderInRect:rect 
-                                      forPage:[[NSPrintOperation currentOperation] currentPage] 
-                                           of:[_private->pageRects count]];
-        [currentContext restoreGraphicsState];
-    }
-}
-
-- (void)_drawFooterInRect:(NSRect)rect
-{
-#ifdef DEBUG_HEADER_AND_FOOTER
-    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
-    [currentContext saveGraphicsState];
-    [[NSColor cyanColor] set];
-    NSRectFill(rect);
-    [currentContext restoreGraphicsState];
-#endif
-    
-    // FIXME: headers and footers are only drawn for HTMLView, not for other views
-    // such as plain text or standalone images
-    if ([[[self _webView] UIDelegate] respondsToSelector:@selector(webView:drawFooterInRect:forPage:of:)]) {
-        NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
-        [currentContext saveGraphicsState];
-        NSRectClip(rect);
-        [[[self _webView] UIDelegate] webView:[self _webView] 
-                             drawFooterInRect:rect 
-                                      forPage:[[NSPrintOperation currentOperation] currentPage] 
-                                           of:[_private->pageRects count]];
-        [currentContext restoreGraphicsState];
-    }
-}
-
-- (void)_adjustPrintingMarginsForHeaderAndFooter
-{
-    NSPrintOperation *operation = [NSPrintOperation currentOperation];
-    NSPrintInfo *info = [[NSPrintOperation currentOperation] printInfo];
-    float userScale = [self _userScaleFactorForPrintOperation:operation];
-    [info setTopMargin:[info topMargin] + [self _headerHeight]*userScale];
-    [info setBottomMargin:[info bottomMargin] + [self _footerHeight]*userScale];
-}
-
 // Does setNeedsDisplay:NO as a side effect when printing is ending.
 // pageWidth != 0 implies we will relayout to a new width
 - (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize
@@ -1789,7 +1698,7 @@ static WebHTMLView *lastHitView = nil;
         [self setNeedsLayout:YES];
         [self layoutToMinimumPageWidth:minPageWidth maximumPageWidth:maxPageWidth adjustingViewSize:adjustViewSize];
         if (printing) {
-            [self _adjustPrintingMarginsForHeaderAndFooter];
+            [[self _webView] _adjustPrintingMarginsForHeaderAndFooter];
         } else {
             // Can't do this when starting printing or nested printing won't work, see 3491427.
             [self setNeedsDisplay:NO];
@@ -1821,11 +1730,6 @@ static WebHTMLView *lastHitView = nil;
     return [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin];
 }
 
-- (float)_userScaleFactorForPrintOperation:(NSPrintOperation *)printOperation
-{
-	return [[[[printOperation printInfo] dictionary] objectForKey:NSPrintScalingFactor] floatValue];
-}
-
 - (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation
 {
     float viewWidth = NSWidth([self bounds]);
@@ -1834,7 +1738,7 @@ static WebHTMLView *lastHitView = nil;
         return 1.0;
     }
 	
-    float userScaleFactor = [self _userScaleFactorForPrintOperation:printOperation];
+    float userScaleFactor = [printOperation _web_pageSetupScaleFactor];
     float maxShrinkToFitScaleFactor = 1/PrintingMaximumShrinkFactor;
     float shrinkToFitScaleFactor = [self _availablePaperWidthForPrintOperation:printOperation]/viewWidth;
     return userScaleFactor * MAX(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
@@ -1871,8 +1775,9 @@ static WebHTMLView *lastHitView = nil;
     // you'd simply see the printer fonts on screen. As of this writing, this does not happen with Safari.
 
     range->location = 1;
-    float totalScaleFactor = [self _scaleFactorForPrintOperation:[NSPrintOperation currentOperation]];
-    float userScaleFactor = [self _userScaleFactorForPrintOperation:[NSPrintOperation currentOperation]];
+    NSPrintOperation *printOperation = [NSPrintOperation currentOperation];
+    float totalScaleFactor = [self _scaleFactorForPrintOperation:printOperation];
+    float userScaleFactor = [printOperation _web_pageSetupScaleFactor];
     [_private->pageRects release];
     _private->pageRects = [[[self _bridge] computePageRectsWithPrintWidth:NSWidth([self bounds])/userScaleFactor
                                                              printHeight:[self _calculatePrintHeight]/totalScaleFactor] retain];
@@ -1897,21 +1802,8 @@ static WebHTMLView *lastHitView = nil;
 
 - (void)drawPageBorderWithSize:(NSSize)borderSize
 {
-    ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));
-    
-    // The header and footer rect height scales with the page, but the width is always
-    // all the way across the printed page (inset by printing margins).
-    float userScale = [self _userScaleFactorForPrintOperation:[NSPrintOperation currentOperation]];
-    NSPrintInfo *printInfo = [[NSPrintOperation currentOperation] printInfo];
-    float headerFooterLeft = [printInfo leftMargin]/userScale;
-    float headerFooterWidth = (borderSize.width - ([printInfo leftMargin] + [printInfo rightMargin]))/userScale;
-    NSRect footerRect = NSMakeRect(headerFooterLeft, [printInfo bottomMargin]/userScale - [self _footerHeight] , 
-                                   headerFooterWidth, [self _footerHeight]);
-    NSRect headerRect = NSMakeRect(headerFooterLeft, (borderSize.height - [printInfo topMargin])/userScale, 
-                                   headerFooterWidth, [self _headerHeight]);
-    
-    [self _drawHeaderInRect:headerRect];
-    [self _drawFooterInRect:footerRect];
+    ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));    
+    [[self _webView] _drawHeaderAndFooter];
 }
 
 - (void)endDocument
diff --git a/WebKit/WebView.subproj/WebImageView.m b/WebKit/WebView.subproj/WebImageView.m
index b2171cf..60f9fbf 100644
--- a/WebKit/WebView.subproj/WebImageView.m
+++ b/WebKit/WebView.subproj/WebImageView.m
@@ -15,6 +15,7 @@
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebViewPrivate.h>
+#import <WebKit/WebUIDelegatePrivate.h>
 
 #import <WebCore/WebCoreImageRenderer.h>
 
@@ -111,18 +112,6 @@
     needsLayout = NO;
 }
 
-- (void)beginDocument
-{
-    [self adjustFrameSize];
-    [super beginDocument];
-}
-
-- (void)endDocument
-{
-    [super endDocument];
-    [self adjustFrameSize];
-}
-
 - (void)setDataSource:(WebDataSource *)dataSource
 {
     ASSERT(!rep);
@@ -278,4 +267,27 @@
     return [rep image];
 }
 
+#pragma mark PRINTING
+
+- (void)drawPageBorderWithSize:(NSSize)borderSize
+{
+    ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));
+    // FIXME: How to determine the number of pages required to print the whole image?
+    [[self webView] _drawHeaderAndFooter];
+}
+
+- (void)beginDocument
+{
+    [self adjustFrameSize];
+    [[self webView] _adjustPrintingMarginsForHeaderAndFooter];
+    [super beginDocument];
+}
+
+- (void)endDocument
+{
+    [super endDocument];
+    [self adjustFrameSize];
+}
+
+
 @end
diff --git a/WebKit/WebView.subproj/WebTextView.m b/WebKit/WebView.subproj/WebTextView.m
index bd31412..008ae84 100644
--- a/WebKit/WebView.subproj/WebTextView.m
+++ b/WebKit/WebView.subproj/WebTextView.m
@@ -289,6 +289,20 @@
     return resign;
 }
 
+#pragma mark PRINTING
+
+- (void)drawPageBorderWithSize:(NSSize)borderSize
+{
+    ASSERT(NSEqualSizes(borderSize, [[[NSPrintOperation currentOperation] printInfo] paperSize]));
+    [[[self _web_parentWebFrameView] _webView] _drawHeaderAndFooter];
+}
+
+- (BOOL)knowsPageRange:(NSRangePointer)range {
+    // Waiting for beginDocument to adjust the printing margins is too late.
+    [[[self _web_parentWebFrameView] _webView] _adjustPrintingMarginsForHeaderAndFooter];
+    return [super knowsPageRange:range];
+}
+
 @end
 
 @implementation WebTextView (TextSizing)
diff --git a/WebKit/WebView.subproj/WebUIDelegatePrivate.h b/WebKit/WebView.subproj/WebUIDelegatePrivate.h
index a70569d..2dc7b4d 100644
--- a/WebKit/WebView.subproj/WebUIDelegatePrivate.h
+++ b/WebKit/WebView.subproj/WebUIDelegatePrivate.h
@@ -11,7 +11,7 @@
 
 - (float)webViewHeaderHeight:(WebView *)sender;
 - (float)webViewFooterHeight:(WebView *)sender;
-- (void)webView:(WebView *)sender drawHeaderInRect:(NSRect)rect forPage:(unsigned)pageIndex of:(unsigned)pageCount;
-- (void)webView:(WebView *)sender drawFooterInRect:(NSRect)rect forPage:(unsigned)pageIndex of:(unsigned)pageCount;
+- (void)webView:(WebView *)sender drawHeaderInRect:(NSRect)rect;
+- (void)webView:(WebView *)sender drawFooterInRect:(NSRect)rect;
 
 @end
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index bcd49e5..4bc1ddb 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -30,6 +30,7 @@
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
 #import <WebKit/WebNSPasteboardExtras.h>
+#import "WebNSPrintOperationExtras.h"
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPluginDatabase.h>
@@ -40,6 +41,7 @@
 #import <WebKit/WebTextRepresentation.h>
 #import <WebKit/WebTextRenderer.h>
 #import <WebKit/WebUIDelegate.h>
+#import <WebKit/WebUIDelegatePrivate.h>
 
 #import <WebCore/WebCoreEncodings.h>
 #import <WebCore/WebCoreSettings.h>
@@ -1956,6 +1958,101 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
 
 @end
 
+ at implementation WebView (WebViewPrintingPrivate)
+
+- (float)_headerHeight
+{
+    if ([[self UIDelegate] respondsToSelector:@selector(webViewHeaderHeight:)]) {
+        return [[self UIDelegate] webViewHeaderHeight:self];
+    }
+    
+#ifdef DEBUG_HEADER_AND_FOOTER
+    return 25;
+#else
+    return 0;
+#endif
+}
+
+- (float)_footerHeight
+{
+    if ([[self UIDelegate] respondsToSelector:@selector(webViewFooterHeight:)]) {
+        return [[self UIDelegate] webViewFooterHeight:self];
+    }
+    
+#ifdef DEBUG_HEADER_AND_FOOTER
+    return 50;
+#else
+    return 0;
+#endif
+}
+
+- (void)_drawHeaderInRect:(NSRect)rect
+{
+#ifdef DEBUG_HEADER_AND_FOOTER
+    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
+    [currentContext saveGraphicsState];
+    [[NSColor yellowColor] set];
+    NSRectFill(rect);
+    [currentContext restoreGraphicsState];
+#endif
+    
+    if ([[self UIDelegate] respondsToSelector:@selector(webView:drawHeaderInRect:)]) {
+        NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
+        [currentContext saveGraphicsState];
+        NSRectClip(rect);
+        [[self UIDelegate] webView:self drawHeaderInRect:rect]; 
+        [currentContext restoreGraphicsState];
+    }
+}
+
+- (void)_drawFooterInRect:(NSRect)rect
+{
+#ifdef DEBUG_HEADER_AND_FOOTER
+    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
+    [currentContext saveGraphicsState];
+    [[NSColor cyanColor] set];
+    NSRectFill(rect);
+    [currentContext restoreGraphicsState];
+#endif
+    
+    if ([[self UIDelegate] respondsToSelector:@selector(webView:drawFooterInRect:)]) {
+        NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
+        [currentContext saveGraphicsState];
+        NSRectClip(rect);
+        [[self UIDelegate] webView:self drawFooterInRect:rect];
+        [currentContext restoreGraphicsState];
+    }
+}
+
+- (void)_adjustPrintingMarginsForHeaderAndFooter
+{
+    NSPrintOperation *op = [NSPrintOperation currentOperation];
+    NSPrintInfo *info = [op printInfo];
+    float scale = [op _web_pageSetupScaleFactor];
+    [info setTopMargin:[info topMargin] + [self _headerHeight]*scale];
+    [info setBottomMargin:[info bottomMargin] + [self _footerHeight]*scale];
+}
+
+- (void)_drawHeaderAndFooter
+{
+    // The header and footer rect height scales with the page, but the width is always
+    // all the way across the printed page (inset by printing margins).
+    NSPrintOperation *op = [NSPrintOperation currentOperation];
+    float scale = [op _web_pageSetupScaleFactor];
+    NSPrintInfo *printInfo = [op printInfo];
+    NSSize paperSize = [printInfo paperSize];
+    float headerFooterLeft = [printInfo leftMargin]/scale;
+    float headerFooterWidth = (paperSize.width - ([printInfo leftMargin] + [printInfo rightMargin]))/scale;
+    NSRect footerRect = NSMakeRect(headerFooterLeft, [printInfo bottomMargin]/scale - [self _footerHeight] , 
+                                   headerFooterWidth, [self _footerHeight]);
+    NSRect headerRect = NSMakeRect(headerFooterLeft, (paperSize.height - [printInfo topMargin])/scale, 
+                                   headerFooterWidth, [self _headerHeight]);
+    
+    [self _drawHeaderInRect:headerRect];
+    [self _drawFooterInRect:footerRect];
+}
+ at end
+
 @implementation WebView (WebDebugBinding)
 
 - (void)addObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
diff --git a/WebKit/WebView.subproj/WebViewPrivate.h b/WebKit/WebView.subproj/WebViewPrivate.h
index 6432932..5920d50 100644
--- a/WebKit/WebView.subproj/WebViewPrivate.h
+++ b/WebKit/WebView.subproj/WebViewPrivate.h
@@ -264,9 +264,31 @@ Could be worth adding to the API.
 
 @end
 
+ at interface WebView (WebViewPrintingPrivate)
+/*!
+    @method _adjustPrintingMarginsForHeaderAndFooter:
+    @abstract Increase the top and bottom margins for the current print operation to
+    account for the header and footer height. 
+    @discussion Called by <WebDocument> implementors once when a print job begins. If the
+    <WebDocument> implementor implements knowsPageRange:, this should be called from there.
+    Otherwise this should be called from beginDocument. The <WebDocument> implementors need
+    to also call _drawHeaderAndFooter.
+*/
+- (void)_adjustPrintingMarginsForHeaderAndFooter;
+
+/*!
+    @method _drawHeaderAndFooter
+    @abstract Gives the WebView's UIDelegate a chance to draw a header and footer on the
+    printed page. 
+    @discussion This should be called by <WebDocument> implementors from an override of
+    drawPageBorderWithSize:.
+*/
+- (void)_drawHeaderAndFooter;
+ at end
+
 @interface _WebSafeForwarder : NSObject
 {
-    id target;	// Non-retainted.  Don't retain delegates;
+    id target;	// Non-retained.  Don't retain delegates;
     id defaultTarget;
     Class templateClass;
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list