[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:14:28 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit a3209ba66433314013f89302c0e2c058f64ff52d
Author: sullivan <sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Nov 21 02:01:02 2003 +0000

    WebCore:
    
            - WebCore part of <rdar://problem/3183124>: Support page-break-before/after with a value of "always"
    
            Dave wrote this part and we reviewed it together.
    
            * khtml/rendering/render_block.cpp:
            (khtml::RenderBlock::paintObject):
            if printing, check for CSS page break locations
            (khtml::RenderBlock::inRootBlockContext):
            new method, used to check whether we're in a context for which
            CSS page breaks are legal.
    
            * khtml/rendering/render_block.h:
            prototype for inRootBlockContext; this might be useful for
            other code later.
    
            * khtml/rendering/render_canvas.cpp:
            (RenderCanvas::setBestTruncatedAt):
            now takes a forcedBreak parameter which overrides others.
    
            * khtml/rendering/render_canvas.h:
            (khtml::RenderCanvas::setTruncatedAt):
            set default value for m_forcedPageBreak
    
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
            (-[WebCoreBridge computePageRects:withPageHeight:]):
            do the real work of pagination here
    
    WebKit:
    
            - WebKit part of <rdar://problem/3183124>: Support page-break-before/after with a value of "always"
    
            Dave and I wrote and reviewed this.
    
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView _setPrinting:pageWidth:adjustViewSize:]):
            reset page rects when printing status changes
            (-[WebHTMLView _availablePaperWidthForPrintOperation:]):
            new helper method to compute paper width taking margins into account
            (-[WebHTMLView _scaleFactorForPrintOperation:]):
            new helper method to compute how much we need to shrink to fit one page across
            (-[WebHTMLView _provideTotalScaleFactorForPrintOperation:]):
            we overrode this secret internal AppKit method to make shrink-to-fit work;
            we wrote bug 3491344 about the need for this to be public.
            (-[WebHTMLView knowsPageRange:]):
            new method, computes rects and returns YES
            (-[WebHTMLView rectForPage:]):
            new method, returns rect computed above
            (-[WebHTMLView _calculatePrintHeight]):
            new method, used by knowsPageRange
    
            * WebView.subproj/WebHTMLViewPrivate.h:
            new pageRects ivar
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5611 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 35b50d0..28cda47 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,33 @@
+2003-11-20  John Sullivan  <sullivan at apple.com>
+
+        - WebCore part of <rdar://problem/3183124>: Support page-break-before/after with a value of "always"
+
+        Dave wrote this part and we reviewed it together.
+
+        * khtml/rendering/render_block.cpp:
+        (khtml::RenderBlock::paintObject):
+        if printing, check for CSS page break locations
+        (khtml::RenderBlock::inRootBlockContext):
+        new method, used to check whether we're in a context for which
+        CSS page breaks are legal.
+        
+        * khtml/rendering/render_block.h:
+        prototype for inRootBlockContext; this might be useful for
+        other code later.
+        
+        * khtml/rendering/render_canvas.cpp:
+        (RenderCanvas::setBestTruncatedAt):
+        now takes a forcedBreak parameter which overrides others.
+        
+        * khtml/rendering/render_canvas.h:
+        (khtml::RenderCanvas::setTruncatedAt):
+        set default value for m_forcedPageBreak
+        
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge computePageRects:withPageHeight:]):
+        do the real work of pagination here
+
 2003-11-20  Chris Blumenberg  <cblu at apple.com>
 
 	Fixed: <rdar://problem/3491225>: Need UI and localized strings for <KEYGEN> support
diff --git a/WebCore/khtml/rendering/render_block.cpp b/WebCore/khtml/rendering/render_block.cpp
index 3491ecf..78b095c 100644
--- a/WebCore/khtml/rendering/render_block.cpp
+++ b/WebCore/khtml/rendering/render_block.cpp
@@ -1173,7 +1173,8 @@ void RenderBlock::paintObject(QPainter *p, int _x, int _y,
 
     // If we're a repositioned run-in, don't paint background/borders.
     bool inlineFlow = isInlineFlow();
-    
+    bool isPrinting = (p->device()->devType() == QInternal::Printer);
+
     // 1. paint background, borders etc
     if (!inlineFlow &&
         (paintAction == PaintActionElementBackground || paintAction == PaintActionChildBackground) &&
@@ -1195,12 +1196,24 @@ void RenderBlock::paintObject(QPainter *p, int _x, int _y,
     int scrolledY = _ty;
     if (style()->hidesOverflow() && m_layer)
         m_layer->subtractScrollOffset(scrolledX, scrolledY);
-    RenderObject *child = firstChild();
-    while(child != 0)
-    {
-        if(!child->layer() && !child->isFloating())
+    for (RenderObject *child = firstChild(); child; child = child->nextSibling()) {        
+        // Check for page-break-before: always, and if it's set, break and bail.
+        if (isPrinting && !childrenInline() && child->style()->pageBreakBefore() == PBALWAYS &&
+            inRootBlockContext() && (_ty + child->yPos()) > _y && (_ty + child->yPos()) < _y + _h) {
+            canvas()->setBestTruncatedAt(_ty + child->yPos(), this, true);
+            return;
+        }
+        
+        if (!child->layer() && !child->isFloating())
             child->paint(p, _x, _y, _w, _h, scrolledX, scrolledY, paintAction);
-        child = child->nextSibling();
+        
+        // Check for page-break-after: always, and if it's set, break and bail.
+        if (isPrinting && !childrenInline() && child->style()->pageBreakAfter() == PBALWAYS && 
+            inRootBlockContext() && (_ty + child->yPos() + child->height()) > _y && 
+            (_ty + child->yPos() + child->height()) < _y + _h) {
+            canvas()->setBestTruncatedAt(_ty + child->yPos() + child->height() + child->collapsedMarginBottom(), this, true);
+            return;
+        }
     }
     paintLineBoxDecorations(p, _x, _y, _w, _h, scrolledX, scrolledY, paintAction);
     
@@ -2564,6 +2577,17 @@ void RenderBlock::updateFirstLetter()
     }
 }
 
+bool RenderBlock::inRootBlockContext() const
+{
+    if (isTableCell() || isFloatingOrPositioned() || style()->hidesOverflow())
+        return false;
+    
+    if (isRoot() || isCanvas())
+        return true;
+    
+    return containingBlock()->inRootBlockContext();
+}
+
 const char *RenderBlock::renderName() const
 {
     if (isBody())
diff --git a/WebCore/khtml/rendering/render_block.h b/WebCore/khtml/rendering/render_block.h
index 9e64e18..5eb002e 100644
--- a/WebCore/khtml/rendering/render_block.h
+++ b/WebCore/khtml/rendering/render_block.h
@@ -185,6 +185,8 @@ public:
     virtual RenderBlock* firstLineBlock() const;
     virtual void updateFirstLetter();
     
+    bool inRootBlockContext() const;
+    
 #ifndef NDEBUG
     virtual void printTree(int indent=0) const;
     virtual void dump(QTextStream *stream, QString ind = "") const;
diff --git a/WebCore/khtml/rendering/render_canvas.cpp b/WebCore/khtml/rendering/render_canvas.cpp
index 6a99f81..802c86c 100644
--- a/WebCore/khtml/rendering/render_canvas.cpp
+++ b/WebCore/khtml/rendering/render_canvas.cpp
@@ -655,8 +655,18 @@ int RenderCanvas::docWidth() const
 #if APPLE_CHANGES
 // The idea here is to take into account what object is moving the pagination point, and
 // thus choose the best place to chop it.
-void RenderCanvas::setBestTruncatedAt(int y, RenderObject *forRenderer)
+void RenderCanvas::setBestTruncatedAt(int y, RenderObject *forRenderer, bool forcedBreak)
 {
+    // Nobody else can set a page break once we have a forced break.
+    if (m_forcedPageBreak) return;
+    
+    // Forced breaks always win over unforced breaks.
+    if (forcedBreak) {
+        m_forcedPageBreak = true;
+        m_bestTruncatedAt = y;
+        return;
+    }
+    
     // prefer the widest object who tries to move the pagination point
     int width = forRenderer->width();
     if (width > m_truncatorWidth) {
diff --git a/WebCore/khtml/rendering/render_canvas.h b/WebCore/khtml/rendering/render_canvas.h
index d48d9e0..fe57aae 100644
--- a/WebCore/khtml/rendering/render_canvas.h
+++ b/WebCore/khtml/rendering/render_canvas.h
@@ -74,12 +74,13 @@ public:
     void setPrintImages(bool enable) { m_printImages = enable; }
     bool printImages() const { return m_printImages; }
 #if APPLE_CHANGES
-    void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; }
-    void setBestTruncatedAt(int y, RenderObject *forRenderer);
+    void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_forcedPageBreak = false; }
+    void setBestTruncatedAt(int y, RenderObject *forRenderer, bool forcedBreak = false);
     int bestTruncatedAt() const { return m_bestTruncatedAt; }
 private:
     int m_bestTruncatedAt;
     int m_truncatorWidth;
+    bool m_forcedPageBreak;
 public:
 #else
     void setTruncatedAt(int y) { m_truncatedAt = y; }
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 864873c..725a961 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -151,6 +151,7 @@ typedef enum {
 - (BOOL)needsLayout;
 - (void)drawRect:(NSRect)rect;
 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit;
+- (NSArray*)computePageRects:(float)pageWidth withPageHeight:(float)pageHeight;
 
 - (void)setUsesInactiveTextBackgroundColor:(BOOL)uses;
 - (BOOL)usesInactiveTextBackgroundColor;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 591826e..397a009 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -442,6 +442,34 @@ static BOOL nowPrinting(WebCoreBridge *self)
 }
 
 // Vertical pagination hook from AppKit
+- (NSArray*)computePageRects: (float)printWidth withPageHeight: (float)printHeight
+{    
+    [self _setupRootForPrinting:YES];
+    NSMutableArray* pages = [[NSMutableArray alloc] initWithCapacity:5];
+    KHTMLView* view = _part->view();
+    NSView* documentView = view->getDocumentView();
+    if (!documentView)
+        return pages;
+    
+    float currPageHeight = printHeight;
+    float docHeight = NSHeight([documentView bounds]);
+    float pageX = NSMinX([documentView bounds]);
+    float pageWidth = NSWidth([documentView bounds]);
+    
+    // We need to give the part the opportunity to adjust the page height at each step.
+    for (float i = 0; i < docHeight; i += currPageHeight) {
+        float proposedBottom = kMin(docHeight, i + printHeight);
+        _part->adjustPageHeight(&proposedBottom, i, proposedBottom, i);
+        currPageHeight = proposedBottom - i;
+        NSValue* val = [NSValue valueWithRect: NSMakeRect(pageX, i, pageWidth, currPageHeight)];
+        [pages addObject: val];
+    }
+    [self _setupRootForPrinting:NO];
+    
+    return pages;
+}
+
+// This is to support the case where a webview is embedded in the view that's being printed
 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit
 {
     [self _setupRootForPrinting:YES];
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 3f1b61c..59c167a 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,29 @@
+2003-11-20  John Sullivan  <sullivan at apple.com>
+
+        - WebKit part of <rdar://problem/3183124>: Support page-break-before/after with a value of "always"
+
+        Dave and I wrote and reviewed this.
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _setPrinting:pageWidth:adjustViewSize:]):
+        reset page rects when printing status changes
+        (-[WebHTMLView _availablePaperWidthForPrintOperation:]):
+        new helper method to compute paper width taking margins into account
+        (-[WebHTMLView _scaleFactorForPrintOperation:]):
+        new helper method to compute how much we need to shrink to fit one page across
+        (-[WebHTMLView _provideTotalScaleFactorForPrintOperation:]):
+        we overrode this secret internal AppKit method to make shrink-to-fit work;
+        we wrote bug 3491344 about the need for this to be public.
+        (-[WebHTMLView knowsPageRange:]):
+        new method, computes rects and returns YES
+        (-[WebHTMLView rectForPage:]):
+        new method, returns rect computed above
+        (-[WebHTMLView _calculatePrintHeight]):
+        new method, used by knowsPageRange
+        
+        * WebView.subproj/WebHTMLViewPrivate.h:
+        new pageRects ivar
+
 2003-11-20  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Ken.
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 10d60ab..ba30928 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -76,6 +76,7 @@ static BOOL forceRealHitTest = NO;
 @interface WebHTMLView (WebHTMLViewPrivate)
 - (void)_setPrinting:(BOOL)printing pageWidth:(float)pageWidth adjustViewSize:(BOOL)adjustViewSize;
 - (void)_updateTextSizeMultiplier;
+- (float)_calculatePrintHeight;
 @end
 
 // Any non-zero value will do, but using somethign recognizable might help us debug some day.
@@ -1648,6 +1649,8 @@ static WebHTMLView *lastHitView = nil;
     }
 
     if (printing != _private->printing) {
+        [_private->pageRects release];
+        _private->pageRects = nil;
         _private->printing = printing;
         [self setNeedsToApplyStyles:YES];
         [self setNeedsLayout:YES];
@@ -1656,6 +1659,8 @@ static WebHTMLView *lastHitView = nil;
     }
 }
 
+// This is needed for the case where the webview is embedded in the view that's being printed.
+// It shouldn't be called when the webview is being printed directly.
 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit
 {
     // This helps when we print as part of a larger print process.
@@ -1666,32 +1671,71 @@ static WebHTMLView *lastHitView = nil;
     }
     
     [[self _bridge] adjustPageHeightNew:newBottom top:oldTop bottom:oldBottom limit:bottomLimit];
-
+    
     if (!wasInPrintingMode) {
         [self _setPrinting:NO pageWidth:0 adjustViewSize:NO];
     }
 }
 
-- (void)beginDocument
+- (float)_availablePaperWidthForPrintOperation:(NSPrintOperation *)printOperation
+{
+    NSPrintInfo *printInfo = [printOperation printInfo];
+    return [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin];
+}
+
+- (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation
 {
+    return [self _availablePaperWidthForPrintOperation:printOperation]/NSWidth([self bounds]);
+}
+
+// FIXME 3491344: This is a secret AppKit-internal method that we need to override in order
+// to get our shrink-to-fit to work with a custom pagination scheme. We can do this better
+// if AppKit makes it SPI/API.
+- (float)_provideTotalScaleFactorForPrintOperation:(NSPrintOperation *)printOperation 
+{
+    return [self _scaleFactorForPrintOperation:printOperation];
+}
+
+// Return the number of pages available for printing
+- (BOOL)knowsPageRange:(NSRangePointer)range {
     // Must do this explicit display here, because otherwise the view might redisplay while the print
     // sheet was up, using printer fonts (and looking different).
     [self displayIfNeeded];
     [[self window] setAutodisplay:NO];
-
+    
     // If we are a frameset just print with the layout we have onscreen, otherwise relayout
     // according to the paper size
-    float pageWidth = 0.0;
+    float layoutWidth = 0.0;
     if (![[self _bridge] isFrameSet]) {
-        NSPrintInfo *printInfo = [[NSPrintOperation currentOperation] printInfo];
-        pageWidth = ([printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin])*PrintingExtraWidthFactor;
+        layoutWidth = [self _availablePaperWidthForPrintOperation:[NSPrintOperation currentOperation]]*PrintingExtraWidthFactor;
     }
-    [self _setPrinting:YES pageWidth:pageWidth adjustViewSize:YES];	// will relayout
-
-    [super beginDocument];
+    [self _setPrinting:YES pageWidth:layoutWidth adjustViewSize:YES];	// will relayout
+    
     // There is a theoretical chance that someone could do some drawing between here and endDocument,
     // if something caused setNeedsDisplay after this point. If so, it's not a big tragedy, because
     // you'd simply see the printer fonts on screen. As of this writing, this does not happen with Safari.
+
+    range->location = 1;
+    float scaleFactor = [self _scaleFactorForPrintOperation:[NSPrintOperation currentOperation]];
+    _private->pageRects = [[self _bridge] computePageRects:NSWidth([self bounds]) 
+                                            withPageHeight:[self _calculatePrintHeight]/scaleFactor];
+    range->length = [_private->pageRects count];
+    return YES;
+}
+
+// Return the drawing rectangle for a particular page number
+- (NSRect)rectForPage:(int)page {
+    return [[_private->pageRects objectAtIndex: (page-1)] rectValue];
+}
+
+// Calculate the vertical size of the view that fits on a single page
+- (float)_calculatePrintHeight {
+    // Obtain the print info object for the current operation
+    NSPrintInfo *pi = [[NSPrintOperation currentOperation] printInfo];
+    
+    // Calculate the page height in points
+    NSSize paperSize = [pi paperSize];
+    return paperSize.height - [pi topMargin] - [pi bottomMargin];
 }
 
 - (void)endDocument
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.h b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
index ea56c57..1ca4c0e 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.h
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
@@ -43,6 +43,8 @@
     
     NSTimer *autoscrollTimer;
     NSEvent *autoscrollTriggerEvent;
+    
+    NSArray* pageRects;
 }
 @end
 
@@ -82,5 +84,4 @@
 
 - (void)_startAutoscrollTimer:(NSEvent *)event;
 - (void)_stopAutoscrollTimer;
-
 @end

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list