#include "config.h"
#include "runtime.h"
#include "FrameWin.h"
#include "TransformationMatrix.h"
#include "FloatRect.h"
#include "Document.h"
#include "RenderView.h"
#include "Settings.h"
using std::min;
namespace WebCore {
void computePageRectsForFrame(Frame* frame, const 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 = static_cast<float>(root->overflowWidth());
float pageHeight = pageWidth * ratio;
outPageHeight = static_cast<int>(pageHeight); 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;
float printedPagesHeight = 0.0f;
do {
float proposedBottom = min(docHeight, printedPagesHeight + pageHeight);
frame->view()->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight);
currPageHeight = max(1.0f, proposedBottom - printedPagesHeight);
pages.append(IntRect(0, printedPagesHeight, currPageWidth, currPageHeight));
printedPagesHeight += currPageHeight;
} while (printedPagesHeight < docHeight);
}
DragImageRef Frame::dragImageForSelection()
{
if (selection()->isRange())
return imageFromSelection(this, false);
return 0;
}
}