summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-19 15:01:22 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-19 15:01:22 +0000
commit07f7352f819918267f080ece5b46db05362d9de1 (patch)
tree28bd16518296d9d088ec9179de3d9573f0d9e679 /webkit
parentf01bf641f130b9f3a32e20b7dfa13426d9f26f6c (diff)
downloadchromium_src-07f7352f819918267f080ece5b46db05362d9de1.zip
chromium_src-07f7352f819918267f080ece5b46db05362d9de1.tar.gz
chromium_src-07f7352f819918267f080ece5b46db05362d9de1.tar.bz2
add computePageRectsForFrame from FrameWin to resolve a link error.
Review URL: http://codereview.chromium.org/3167 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/bridge/mac/FrameMac.mm52
1 files changed, 52 insertions, 0 deletions
diff --git a/webkit/port/bridge/mac/FrameMac.mm b/webkit/port/bridge/mac/FrameMac.mm
index 16dde644..2324e67 100644
--- a/webkit/port/bridge/mac/FrameMac.mm
+++ b/webkit/port/bridge/mac/FrameMac.mm
@@ -723,4 +723,56 @@ void Frame::setUserStyleSheet(const String& styleSheet)
d->m_doc->setUserStyleSheet(styleSheet);
}
+void computePageRectsForFrame(WebCore::Frame* frame, const WebCore::IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, Vector<IntRect>& pages, int& outPageHeight)
+{
+ ASSERT(frame);
+
+ pages.clear();
+ outPageHeight = 0;
+
+ 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;
+ }
+
+ if (userScaleFactor <= 0) {
+ LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
+ return;
+ }
+
+ float ratio = static_cast<float>(printRect.height()) / static_cast<float>(printRect.width());
+
+ float pageWidth = (float) root->docWidth();
+ float pageHeight = pageWidth * ratio;
+ outPageHeight = (int) pageHeight; // this is the height of the page adjusted by margins
+ pageHeight -= (headerHeight + footerHeight);
+
+ if (pageHeight <= 0) {
+ LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
+ return;
+ }
+
+ float currPageHeight = pageHeight / userScaleFactor;
+ float docHeight = root->layer()->height();
+ float docWidth = root->layer()->width();
+ float currPageWidth = pageWidth / userScaleFactor;
+
+
+ // always return at least one page, since empty files should print a blank page
+ float printedPagesHeight = 0.0;
+ do {
+ float proposedBottom = std::min(docHeight, printedPagesHeight + pageHeight);
+ frame->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight);
+ currPageHeight = max(1.0f, proposedBottom - printedPagesHeight);
+
+ pages.append(IntRect(0,printedPagesHeight,currPageWidth,currPageHeight));
+ printedPagesHeight += currPageHeight;
+ } while (printedPagesHeight < docHeight);
+}
+
} // namespace WebCore