+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
}
-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();
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)