2007-08-24 Jon Honeycutt <jhoneycutt@apple.com>
authorhoneycutt <honeycutt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2007 22:54:42 +0000 (22:54 +0000)
committerhoneycutt <honeycutt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2007 22:54:42 +0000 (22:54 +0000)
        Reviewed by Darin.

        <rdar://problem/5433236> Print preview of empty txt file crashes Safari
        Fix: Adjust computePageRectsForFrame to always return at least one
        page rect, even if document height is zero.

        * WebCore.vcproj/WebCore.vcproj:
        * bridge/win/FrameWin.h: Added Vector& parameter to
        computePagesRectsForFrame; changed its return type to void.
        * bridge/win/FrameWin.cpp:
        (WebCore::computePageRectsForFrame): Reordered the loop that inserts
        rects into the vector.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25218 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/win/FrameWin.cpp
WebCore/bridge/win/FrameWin.h

index 9496500af83bb798d5e70623baefcfb9e8fca1e8..3548b241de99870e7a88c08ea0e45960d23e50d8 100644 (file)
@@ -1,3 +1,18 @@
+2007-08-24  Jon Honeycutt  <jhoneycutt@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/5433236> Print preview of empty txt file crashes Safari
+        Fix: Adjust computePageRectsForFrame to always return at least one 
+        page rect, even if document height is zero.
+
+        * WebCore.vcproj/WebCore.vcproj:
+        * bridge/win/FrameWin.h: Added Vector& parameter to 
+        computePagesRectsForFrame; changed its return type to void.
+        * bridge/win/FrameWin.cpp:
+        (WebCore::computePageRectsForFrame): Reordered the loop that inserts
+        rects into the vector.
+
 2007-08-24  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Oliver
index 4b6b466198cfdaa67ac99fed5221b2231d911ce4..c43928f251e4006a321834001333c6d533eb89d5 100644 (file)
@@ -84,24 +84,25 @@ KJS::Bindings::Instance* Frame::createScriptInstanceForWidget(Widget* widget)
 }
 
 
-Vector<IntRect> computePageRectsForFrame(Frame* frame, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor)
+void computePageRectsForFrame(Frame* frame, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor,Vector<IntRect>& pages)
 {
     ASSERT(frame);
 
-    Vector<IntRect> pages;
+    pages.clear();
 
-    if (!frame->document() || !frame->view()|| !frame->document()->renderer()) return pages;
+    if (!frame->document() || !frame->view() || !frame->document()->renderer())
+        return;
  
     RenderView* root = static_cast<RenderView *>(frame->document()->renderer());
 
     if (!root) {
         LOG_ERROR("document to be printed has no renderer");
-        return pages;
+        return;
     }
 
     if (userScaleFactor <= 0) {
         LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
-        return pages;
+        return;
     }
     
     float ratio = (float)printRect.height() / (float)printRect.width();
@@ -112,28 +113,25 @@ Vector<IntRect> computePageRectsForFrame(Frame* frame, const IntRect& printRect,
 
     if (pageHeight <= 0) {
         LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
-        return pages;
+        return;
     }
 
     float currPageHeight = pageHeight / userScaleFactor;
     float docHeight      = root->layer()->height();
     float docWidth       = root->layer()->width();
     float currPageWidth  = pageWidth / userScaleFactor;
+
     
-    for (float i = 0; i < docHeight; i += currPageHeight) {
-        float proposedBottom = min(docHeight, i + pageHeight);
-        frame->adjustPageHeight(&proposedBottom, i, proposedBottom, i);
-        currPageHeight = max(1.0f, proposedBottom - i);
+    // always return at least one page, since empty files should print a blank page
+    float printedPagesHeight = 0.0;
+    do {
+        float proposedBottom = min(docHeight, printedPagesHeight + pageHeight);
+        frame->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight);
+        currPageHeight = max(1.0f, proposedBottom - printedPagesHeight);
        
-        int x = 0;
-        int y = i;
-        int wide = currPageWidth;
-        int high = currPageHeight;
-        IntRect pageRect(x, y, wide, high);
-        pages.append(pageRect);
-    }
-    
-    return pages;
+        pages.append(IntRect(0,printedPagesHeight,currPageWidth,currPageHeight));
+        printedPagesHeight += currPageHeight;
+    } while (printedPagesHeight < docHeight);
 }
 
 static void drawRectIntoContext(IntRect rect, FrameView* view, GraphicsContext* gc)
index caa0cd6c1bc4f3e0da907244f217e166c7b6ad45..a12bdc00138ebe7d47540f00df46499fe1036d71 100644 (file)
@@ -34,7 +34,7 @@ typedef struct HBITMAP__* HBITMAP;
 namespace WebCore {
 
     HBITMAP imageFromSelection(Frame* frame, bool forceWhiteText);
-    Vector<IntRect> computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor);
+    void computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor,Vector<IntRect>& pages);
 
 }