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

trey trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:36:41 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 6ca443f0c0ab0e79c42e859195965c4357f228ea
Author: trey <trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Apr 12 00:34:36 2003 +0000

    WebCore:
    
    	3148002 - printing shouldn't depend on the size of the window
    
    	The basic strategy is copied from khtmlview's print method:  We reset the width
    	of the document to the paper width minus margins, and relayout before paginating
    	and printing.
    
            Reviewed by Richard.
    
            * khtml/rendering/render_root.cpp:
            (RenderRoot::layout):  Always resize our view, even when doing a layout when in
    	printing mode.  It's necessary to change the view size because we rely on the AppKit
    	built-in pagination, which operates using the view geometry.
            * kwq/KWQKHTMLPart.h:
            * kwq/KWQKHTMLPart.mm:
            (KWQKHTMLPart::forceLayoutForPageWidth):  New method to do a layout given a
    	specific width.
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
            (-[WebCoreBridge _setPrintingMode:]):  Helper routine to take the RenderRoot in
    	and out of printing mode.
            (-[WebCoreBridge forceLayout]):  Turn printing mode on/off.
            (-[WebCoreBridge forceLayoutForPageWidth:]):  Turn printing mode on/off.
    	New glue routine to call part.
            (-[WebCoreBridge drawRect:withPainter:]):  Turn printing mode on/off.
            (-[WebCoreBridge drawRect:]):  Test paintDevice type instead of graphics context
    	to determine printing mode.  The latter is still on when we are wrapping up the
    	job and want to be setting things back to normal.
            (-[WebCoreBridge adjustFrames:]):  Ditto.
            (-[WebCoreBridge adjustPageHeightNew:top:bottom:limit:]):  Turn printing mode on/off.
    
    WebKit:
    
    	3148002 - printing shouldn't depend on the size of the window
    
    	The basic strategy is copied from khtmlview's print method:  We reset the width
    	of the document to the paper width minus margins, and relayout before paginating
    	and printing.
    
            Reviewed by Richard.
    
            * WebKit.pbproj/project.pbxproj:  Someone is using an old version...
            * WebView.subproj/WebDynamicScrollBarsView.m:
            (-[WebDynamicScrollBarsView reflectScrolledClipView:]):  Don't do the dynamic
    	scrollbar update magic when printing.
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView layoutToPageWidth:]):  New routine, basically the old layout
    	method with a new parameter.  If we're given an width, we call a different
    	bridge method.
            (-[WebHTMLView layout]):  Just call above method with width==0
            (-[WebHTMLView drawRect:]):  Protect setting/resetting of graphics context and
    	additional clip with a DURING/HANDLER.  I saw an assertion failure that could
    	be explained by this, so this is mostly a beartrap for that problem.
            (-[WebHTMLView _setPrinting:pageWidth:]):  Pass page width through to others.
            (-[WebHTMLView beginDocument]):  If we are not in a frame set, do a layout
    	using the page width.
            (-[WebHTMLView endDocument]):  Pass 0 to new pageWidth: arg.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4084 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index d9f1471..19f8d94 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,35 @@
+2003-04-11  Trey Matteson  <trey at apple.com>
+
+	3148002 - printing shouldn't depend on the size of the window
+
+	The basic strategy is copied from khtmlview's print method:  We reset the width
+	of the document to the paper width minus margins, and relayout before paginating
+	and printing.
+
+        Reviewed by Richard.
+
+        * khtml/rendering/render_root.cpp:
+        (RenderRoot::layout):  Always resize our view, even when doing a layout when in
+	printing mode.  It's necessary to change the view size because we rely on the AppKit
+	built-in pagination, which operates using the view geometry.
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::forceLayoutForPageWidth):  New method to do a layout given a
+	specific width.
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge _setPrintingMode:]):  Helper routine to take the RenderRoot in
+	and out of printing mode.
+        (-[WebCoreBridge forceLayout]):  Turn printing mode on/off.
+        (-[WebCoreBridge forceLayoutForPageWidth:]):  Turn printing mode on/off.
+	New glue routine to call part.
+        (-[WebCoreBridge drawRect:withPainter:]):  Turn printing mode on/off.
+        (-[WebCoreBridge drawRect:]):  Test paintDevice type instead of graphics context
+	to determine printing mode.  The latter is still on when we are wrapping up the
+	job and want to be setting things back to normal.
+        (-[WebCoreBridge adjustFrames:]):  Ditto.
+        (-[WebCoreBridge adjustPageHeightNew:top:bottom:limit:]):  Turn printing mode on/off.
+
 2003-04-11  Darin Adler  <darin at apple.com>
 
         Reviewed by Richard.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d9f1471..19f8d94 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,35 @@
+2003-04-11  Trey Matteson  <trey at apple.com>
+
+	3148002 - printing shouldn't depend on the size of the window
+
+	The basic strategy is copied from khtmlview's print method:  We reset the width
+	of the document to the paper width minus margins, and relayout before paginating
+	and printing.
+
+        Reviewed by Richard.
+
+        * khtml/rendering/render_root.cpp:
+        (RenderRoot::layout):  Always resize our view, even when doing a layout when in
+	printing mode.  It's necessary to change the view size because we rely on the AppKit
+	built-in pagination, which operates using the view geometry.
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::forceLayoutForPageWidth):  New method to do a layout given a
+	specific width.
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge _setPrintingMode:]):  Helper routine to take the RenderRoot in
+	and out of printing mode.
+        (-[WebCoreBridge forceLayout]):  Turn printing mode on/off.
+        (-[WebCoreBridge forceLayoutForPageWidth:]):  Turn printing mode on/off.
+	New glue routine to call part.
+        (-[WebCoreBridge drawRect:withPainter:]):  Turn printing mode on/off.
+        (-[WebCoreBridge drawRect:]):  Test paintDevice type instead of graphics context
+	to determine printing mode.  The latter is still on when we are wrapping up the
+	job and want to be setting things back to normal.
+        (-[WebCoreBridge adjustFrames:]):  Ditto.
+        (-[WebCoreBridge adjustPageHeightNew:top:bottom:limit:]):  Turn printing mode on/off.
+
 2003-04-11  Darin Adler  <darin at apple.com>
 
         Reviewed by Richard.
diff --git a/WebCore/khtml/rendering/render_root.cpp b/WebCore/khtml/rendering/render_root.cpp
index 165233a..2576fdc 100644
--- a/WebCore/khtml/rendering/render_root.cpp
+++ b/WebCore/khtml/rendering/render_root.cpp
@@ -154,13 +154,19 @@ void RenderRoot::layout()
 
     RenderBlock::layout();
 
+#ifdef APPLE_CHANGES
+    // always do the resizeContents, since we need the view to change size for Cocoa builtin
+    // pagination to work
+    m_view->resizeContents(docWidth(), docHeight());
+    if (!m_printingMode) {
+#else
     if (!m_printingMode) {
         m_view->resizeContents(docWidth(), docHeight());
+#endif
         setWidth( m_viewportWidth = m_view->visibleWidth() );
         setHeight(  m_viewportHeight = m_view->visibleHeight() );
     }
 
-
     // ### we could maybe do the call below better and only pass true if the docsize changed.
     layoutPositionedObjects( true );
 
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index e62552c..17bf730 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -142,6 +142,7 @@ public:
     using KHTMLPart::xmlDocImpl;
     khtml::RenderObject *renderer();
     void forceLayout();
+    void forceLayoutForPageWidth(float pageWidth);
     void paint(QPainter *, const QRect &);
     void paintSelectionOnly(QPainter *p, const QRect &rect);
 
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 6b75ad6..c979497 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -1033,6 +1033,20 @@ void KWQKHTMLPart::forceLayout()
     }
 }
 
+void KWQKHTMLPart::forceLayoutForPageWidth(float pageWidth)
+{
+    // Dumping externalRepresentation(_part->renderer()).ascii() is a good trick to see
+    // the state of things before and after the layout
+    RenderRoot *root = static_cast<khtml::RenderRoot *>(xmlDocImpl()->renderer());
+    if (root) {
+        // This magic is basically copied from khtmlview::print
+        root->setWidth((int)ceil(pageWidth));
+        root->setLayouted(false);
+        root->setMinMaxKnown(false);
+        forceLayout();
+    }
+}
+
 void KWQKHTMLPart::runJavaScriptAlert(const QString &message)
 {
     [_bridge runJavaScriptAlertPanelWithMessage:message.getNSString()];
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 463c9ce..f2f489c 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -143,6 +143,7 @@ enum FrameBorderStyle {
 
 - (void)reapplyStylesForDeviceType:(WebCoreDeviceType)deviceType;
 - (void)forceLayout;
+- (void)forceLayoutForPageWidth:(float)pageWidth;
 - (BOOL)needsLayout;
 - (void)adjustFrames:(NSRect)rect;
 - (void)drawRect:(NSRect)rect;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index c160075..711d5da 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -72,6 +72,7 @@ using khtml::RenderImage;
 using khtml::RenderObject;
 using khtml::RenderPart;
 using khtml::RenderStyle;
+using khtml::RenderRoot;
 
 using KJS::SavedProperties;
 
@@ -326,23 +327,51 @@ static bool initializedObjectCacheSize = FALSE;
     return _part->reparseConfiguration();
 }
 
+static BOOL nowPrinting(WebCoreBridge *self)
+{
+    DocumentImpl *doc = self->_part->xmlDocImpl();
+    return doc && doc->paintDevice()->devType() == QInternal::Printer;
+}
+
+// Set or unset the printing mode in the view.  We only toy with this if we're printing.
+- (void)_setupRootForPrinting:(BOOL)onOrOff
+{
+    if (nowPrinting(self)) {
+        RenderRoot *root = static_cast<khtml::RenderRoot *>(_part->xmlDocImpl()->renderer());
+        if (root) {
+            root->setPrintingMode(onOrOff);
+        }
+    }
+}
+
 - (void)forceLayout
 {
+    [self _setupRootForPrinting:YES];
     _part->forceLayout();
+    [self _setupRootForPrinting:NO];
+}
+
+- (void)forceLayoutForPageWidth:(float)pageWidth
+{
+    [self _setupRootForPrinting:YES];
+    _part->forceLayoutForPageWidth(pageWidth);
+    [self _setupRootForPrinting:NO];
 }
 
 - (void)drawRect:(NSRect)rect withPainter:(QPainter *)p
 {
+    [self _setupRootForPrinting:YES];
     if (_drawSelectionOnly) {
         _part->paintSelectionOnly(p, QRect(rect));
     } else {
         _part->paint(p, QRect(rect));
     }
+    [self _setupRootForPrinting:NO];
 }
 
 - (void)drawRect:(NSRect)rect
 {
-    QPainter painter(![[NSGraphicsContext currentContext] isDrawingToScreen]);
+    QPainter painter(nowPrinting(self));
     [self drawRect:rect withPainter:&painter];
 }
 
@@ -353,7 +382,7 @@ static bool initializedObjectCacheSize = FALSE;
     // layout and do a draw with rendering disabled to
     // correctly adjust the frames.
     [self forceLayout];
-    QPainter painter(![[NSGraphicsContext currentContext] isDrawingToScreen]);
+    QPainter painter(nowPrinting(self));
     painter.setPaintingDisabled(YES);
     [self drawRect:rect withPainter:&painter];
 }
@@ -361,7 +390,9 @@ static bool initializedObjectCacheSize = FALSE;
 // Vertical pagination hook from AppKit
 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit
 {
+    [self _setupRootForPrinting:YES];
     _part->adjustPageHeight(newBottom, oldTop, oldBottom, bottomLimit);
+    [self _setupRootForPrinting:NO];
 }
 
 - (NSObject *)copyDOMNode:(NodeImpl *)node copier:(id <WebCoreDOMTreeCopier>)copier
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index b572f09..e44ff96 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,30 @@
+2003-04-11  Trey Matteson  <trey at apple.com>
+
+	3148002 - printing shouldn't depend on the size of the window
+
+	The basic strategy is copied from khtmlview's print method:  We reset the width
+	of the document to the paper width minus margins, and relayout before paginating
+	and printing.
+
+        Reviewed by Richard.
+
+        * WebKit.pbproj/project.pbxproj:  Someone is using an old version...
+        * WebView.subproj/WebDynamicScrollBarsView.m:
+        (-[WebDynamicScrollBarsView reflectScrolledClipView:]):  Don't do the dynamic
+	scrollbar update magic when printing.
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView layoutToPageWidth:]):  New routine, basically the old layout
+	method with a new parameter.  If we're given an width, we call a different
+	bridge method.
+        (-[WebHTMLView layout]):  Just call above method with width==0
+        (-[WebHTMLView drawRect:]):  Protect setting/resetting of graphics context and
+	additional clip with a DURING/HANDLER.  I saw an assertion failure that could
+	be explained by this, so this is mostly a beartrap for that problem.
+        (-[WebHTMLView _setPrinting:pageWidth:]):  Pass page width through to others.
+        (-[WebHTMLView beginDocument]):  If we are not in a frame set, do a layout
+	using the page width.
+        (-[WebHTMLView endDocument]):  Pass 0 to new pageWidth: arg.
+
 2003-04-08  Trey Matteson  <trey at apple.com>
 
 	3220349 - assertion failure in [WebFrame _recursiveGoToItem:...] hitting Back while loading movie
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index 691d6a6..23551c0 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -184,7 +184,6 @@
 </dict>
 </plist>
 ";
-			shouldUseHeadermap = 0;
 		};
 		0867D69DFE84028FC02AAC07 = {
 			buildActionMask = 2147483647;
diff --git a/WebKit/WebView.subproj/WebDynamicScrollBarsView.m b/WebKit/WebView.subproj/WebDynamicScrollBarsView.m
index b2fd7fe..2225fe8 100644
--- a/WebKit/WebView.subproj/WebDynamicScrollBarsView.m
+++ b/WebKit/WebView.subproj/WebDynamicScrollBarsView.m
@@ -82,7 +82,7 @@
         // The underlying cause is some problem in the NSText machinery, but I was not
         // able to pin it down.
         static BOOL inUpdateScrollers;
-        if (!inUpdateScrollers) {
+        if (!inUpdateScrollers && [[NSGraphicsContext currentContext] isDrawingToScreen]) {
             inUpdateScrollers = YES;
             [self updateScrollers];
             inUpdateScrollers = NO;
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index ae72bb4..2f0d184 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -290,8 +290,9 @@
     _private->needsToApplyStyles = NO;
 }
 
-
-- (void)layout
+// Do a layout, but set up a new fixed width for the purposes of doing printing layout.
+// pageWidth==0 implies a non-printing layout
+- (void)layoutToPageWidth:(float)pageWidth
 {
     [self reapplyStyles];
     
@@ -308,7 +309,11 @@
 #endif
 
     LOG(View, "%@ doing layout", self);
-    [[self _bridge] forceLayout];
+    if (pageWidth > 0.0) {
+        [[self _bridge] forceLayoutForPageWidth:pageWidth];
+    } else {
+        [[self _bridge] forceLayout];
+    }
     _private->needsLayout = NO;
     
     _private->lastLayoutSize = [(NSClipView *)[self superview] documentVisibleRect].size;
@@ -321,6 +326,10 @@
 #endif
 }
 
+- (void)layout
+{
+    [self layoutToPageWidth:0.0];
+}
 
 - (NSMenu *)menuForEvent:(NSEvent *)theEvent
 {    
@@ -330,8 +339,8 @@
     return [[self _controller] _menuForElement:element];
 }
 
-// Search from the end of the currently selected location, or from the beginning of the document if nothing
-// is selected.
+// Search from the end of the currently selected location, or from the beginning of the
+// document if nothing is selected.
 - (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag
 {
     return [[self _bridge] searchFor: string direction: forward caseSensitive: caseFlag];
@@ -505,23 +514,30 @@
     
     ASSERT([[self superview] isKindOfClass:[WebClipView class]]);
     [(WebClipView *)[self superview] setAdditionalClip:rect];
-    
-    NSView *focusView = [NSView focusView];
-    if ([WebTextRenderer shouldBufferTextDrawing] && focusView)
-        [textRendererFactory startCoalesceTextDrawing];
 
-    //double start = CFAbsoluteTimeGetCurrent();
-    [[self _bridge] drawRect:rect];
-    //LOG(Timing, "draw time %e", CFAbsoluteTimeGetCurrent() - start);
+    NS_DURING {
+        NSView *focusView = [NSView focusView];
+        if ([WebTextRenderer shouldBufferTextDrawing] && focusView)
+            [textRendererFactory startCoalesceTextDrawing];
 
-    if ([WebTextRenderer shouldBufferTextDrawing] && focusView)
-        [textRendererFactory endCoalesceTextDrawing];
+        //double start = CFAbsoluteTimeGetCurrent();
+        [[self _bridge] drawRect:rect];
+        //LOG(Timing, "draw time %e", CFAbsoluteTimeGetCurrent() - start);
 
-    [(WebClipView *)[self superview] resetAdditionalClip];
-    
-    [self _drawBorder: [[self _bridge] frameBorderStyle]];
+        if ([WebTextRenderer shouldBufferTextDrawing] && focusView)
+            [textRendererFactory endCoalesceTextDrawing];
+
+        [(WebClipView *)[self superview] resetAdditionalClip];
 
-    [NSGraphicsContext restoreGraphicsState];
+        [self _drawBorder: [[self _bridge] frameBorderStyle]];
+
+        [NSGraphicsContext restoreGraphicsState];
+    } NS_HANDLER {
+        [(WebClipView *)[self superview] resetAdditionalClip];
+        [NSGraphicsContext restoreGraphicsState];
+        ERROR("Exception caught while drawing: %@", localException);
+        [localException raise];
+    } NS_ENDHANDLER
 
 #ifdef DEBUG_LAYOUT
     NSRect vframe = [self frame];
@@ -754,7 +770,8 @@
 }
 
 // Does setNeedsDisplay:NO as a side effect. Useful for begin/endDocument.
-- (void)_setPrinting:(BOOL)printing
+// pageWidth != 0 implies we will relayout to a new width
+- (void)_setPrinting:(BOOL)printing pageWidth:(float)pageWidth
 {
     WebFrame *frame = [self _frame];
     NSArray *subframes = [frame children];
@@ -764,16 +781,15 @@
         WebFrame *subframe = [subframes objectAtIndex:i];
         WebFrameView *frameView = [subframe frameView];
         if ([frameView isDocumentHTML]) {
-            [(WebHTMLView *)[frameView documentView] _setPrinting:printing];
+            [(WebHTMLView *)[frameView documentView] _setPrinting:printing pageWidth:0];
         }
     }
 
     if (printing != _private->printing) {
         _private->printing = printing;
-        
         [self setNeedsToApplyStyles:YES];
         [self setNeedsLayout:YES];
-        [self layout];
+        [self layoutToPageWidth:pageWidth];
         [self setNeedsDisplay:NO];
     }
 }
@@ -789,7 +805,16 @@
     // sheet was up, using printer fonts (and looking different).
     [self displayIfNeeded];
     [[self window] setAutodisplay:NO];
-    [self _setPrinting:YES];
+
+    // If we are a frameset just print with the layout we have onscreen, otherwise relayout
+    // according to the paper size
+    float pageWidth = 0.0;
+    if (![[self _bridge] isFrameSet]) {
+        NSPrintInfo *printInfo = [[NSPrintOperation currentOperation] printInfo];
+        pageWidth = [printInfo paperSize].width - [printInfo leftMargin] - [printInfo rightMargin];
+    }
+    [self _setPrinting:YES pageWidth:pageWidth];	// will relayout
+
     [super beginDocument];
     // 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
@@ -799,7 +824,8 @@
 - (void)endDocument
 {
     [super endDocument];
-    [self _setPrinting:NO];
+    // Note sadly at this point [NSGraphicsContext currentContextDrawingToScreen] is still NO 
+    [self _setPrinting:NO pageWidth:0.0];
     [[self window] setAutodisplay:YES];
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list