#include "config.h"
#include "core/page/PrintContext.h"
-#include "core/frame/Frame.h"
#include "core/frame/FrameView.h"
-#include "core/platform/graphics/GraphicsContext.h"
+#include "core/frame/LocalFrame.h"
#include "core/rendering/RenderView.h"
-#include "wtf/text/WTFString.h"
+#include "platform/graphics/GraphicsContext.h"
namespace WebCore {
// behavior matches MacIE and Mozilla, at least)
const float printingMaximumShrinkFactor = 2;
-PrintContext::PrintContext(Frame* frame)
+PrintContext::PrintContext(LocalFrame* frame)
: m_frame(frame)
, m_isPrinting(false)
, m_linkedDestinationsValid(false)
return;
if (userScaleFactor <= 0) {
- LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
+ WTF_LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
return;
}
pageHeight -= headerHeight + footerHeight;
if (pageHeight <= 0) {
- LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
+ WTF_LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
return;
}
FloatSize minLayoutSize = m_frame->resizePageRectsKeepingRatio(originalPageSize, FloatSize(width * printingMinimumShrinkFactor, height * printingMinimumShrinkFactor));
// This changes layout, so callers need to make sure that they don't paint to screen while in printing mode.
- m_frame->setPrinting(true, minLayoutSize, originalPageSize, printingMaximumShrinkFactor / printingMinimumShrinkFactor, AdjustViewSize);
-}
-
-float PrintContext::computeAutomaticScaleFactor(const FloatSize& availablePaperSize)
-{
- if (!m_frame->view())
- return 1;
-
- bool useViewWidth = true;
- if (m_frame->document() && m_frame->document()->renderView())
- useViewWidth = m_frame->document()->renderView()->style()->isHorizontalWritingMode();
-
- float viewLogicalWidth = useViewWidth ? m_frame->view()->contentsWidth() : m_frame->view()->contentsHeight();
- if (viewLogicalWidth < 1)
- return 1;
-
- float maxShrinkToFitScaleFactor = 1 / printingMaximumShrinkFactor;
- float shrinkToFitScaleFactor = (useViewWidth ? availablePaperSize.width() : availablePaperSize.height()) / viewLogicalWidth;
- return max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
+ m_frame->setPrinting(true, minLayoutSize, originalPageSize, printingMaximumShrinkFactor / printingMinimumShrinkFactor);
}
void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
ctx.restore();
}
-void PrintContext::spoolRect(GraphicsContext& ctx, const IntRect& rect)
-{
- // FIXME: Not correct for vertical text.
- ctx.save();
- ctx.translate(-rect.x(), -rect.y());
- ctx.clip(rect);
- m_frame->view()->paintContents(&ctx, rect);
- ctx.restore();
-}
-
void PrintContext::end()
{
ASSERT(m_isPrinting);
m_isPrinting = false;
- m_frame->setPrinting(false, FloatSize(), FloatSize(), 0, AdjustViewSize);
+ m_frame->setPrinting(false, FloatSize(), FloatSize(), 0);
m_linkedDestinations.clear();
m_linkedDestinationsValid = false;
}
if (!box)
return -1;
- Frame* frame = element->document().frame();
+ LocalFrame* frame = element->document().frame();
FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels);
PrintContext printContext(frame);
printContext.begin(pageRect.width(), pageRect.height());
}
}
-String PrintContext::pageProperty(Frame* frame, const char* propertyName, int pageNumber)
+String PrintContext::pageProperty(LocalFrame* frame, const char* propertyName, int pageNumber)
{
Document* document = frame->document();
PrintContext printContext(frame);
return String("pageProperty() unimplemented for: ") + propertyName;
}
-bool PrintContext::isPageBoxVisible(Frame* frame, int pageNumber)
+bool PrintContext::isPageBoxVisible(LocalFrame* frame, int pageNumber)
{
return frame->document()->isPageBoxVisible(pageNumber);
}
-String PrintContext::pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
+String PrintContext::pageSizeAndMarginsInPixels(LocalFrame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
{
IntSize pageSize(width, height);
frame->document()->pageSizeAndMarginsInPixels(pageNumber, pageSize, marginTop, marginRight, marginBottom, marginLeft);
String::number(marginTop) + ' ' + String::number(marginRight) + ' ' + String::number(marginBottom) + ' ' + String::number(marginLeft);
}
-int PrintContext::numberOfPages(Frame* frame, const FloatSize& pageSizeInPixels)
+int PrintContext::numberOfPages(LocalFrame* frame, const FloatSize& pageSizeInPixels)
{
frame->document()->updateLayout();
return printContext.pageCount();
}
-void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
+void PrintContext::spoolAllPagesWithBoundaries(LocalFrame* frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
{
if (!frame->document() || !frame->view() || !frame->document()->renderer())
return;