Reviewed by Steve.
WebCore:
<rdar://problem/
5079175> Added parameters headerHeight and footerHeight to
computePageRectsForFrame() so we can account for the header and footer when
calculating page heights for this frame.
* bridge/win/FrameWin.cpp:
(WebCore::computePageRectsForFrame):
* bridge/win/FrameWin.h:
WebKit/win:
<rdar://problem/
5079175> Printing header and footer
* Interfaces/IWebUIDelegate.idl: added methods for header/footer drawing.
* WebFrame.cpp:
(WebFrame::headerAndFooterHeights): ask client for the header and
footer heights via IWebUIDelegate2 methods.
(WebFrame::computePageRects): pass in header and footer heights when
calculating page rect heights.
(WebFrame::spoolPages): ask client to draw header and footer via
IWebUIDelegate2 methods.
* WebFrame.h:
* WebKitGraphics.cpp:
(DrawTextAtPoint): the code assumes color has 4 components - might as well
assert it.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@24826
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-08-02 Ada Chan <adachan@apple.com>
+
+ Reviewed by Steve.
+
+ <rdar://problem/5079175> Added parameters headerHeight and footerHeight to
+ computePageRectsForFrame() so we can account for the header and footer when
+ calculating page heights for this frame.
+
+ * bridge/win/FrameWin.cpp:
+ (WebCore::computePageRectsForFrame):
+ * bridge/win/FrameWin.h:
+
2007-08-02 Alice Liu <alice.liu@apple.com>
Reviewed by Kevin McCullough.
}
-Vector<IntRect> computePageRectsForFrame(Frame* frame, const IntRect& printRect, float userScaleFactor)
+Vector<IntRect> computePageRectsForFrame(Frame* frame, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor)
{
ASSERT(frame);
float pageWidth = (float) root->docWidth();
float pageHeight = pageWidth * ratio;
+ pageHeight -= (headerHeight + footerHeight);
if (pageHeight <= 0) {
LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
namespace WebCore {
HBITMAP imageFromSelection(Frame* frame, bool forceWhiteText);
- Vector<IntRect> computePageRectsForFrame(Frame*, const IntRect& printRect, float userScaleFactor);
+ Vector<IntRect> computePageRectsForFrame(Frame*, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor);
}
+2007-08-02 Ada Chan <adachan@apple.com>
+
+ Reviewed by Steve.
+
+ <rdar://problem/5079175> Printing header and footer
+
+ * Interfaces/IWebUIDelegate.idl: added methods for header/footer drawing.
+ * WebFrame.cpp:
+ (WebFrame::headerAndFooterHeights): ask client for the header and
+ footer heights via IWebUIDelegate2 methods.
+ (WebFrame::computePageRects): pass in header and footer heights when
+ calculating page rect heights.
+ (WebFrame::spoolPages): ask client to draw header and footer via
+ IWebUIDelegate2 methods.
+ * WebFrame.h:
+ * WebKitGraphics.cpp:
+ (DrawTextAtPoint): the code assumes color has 4 components - might as well
+ assert it.
+
2007-08-01 Steve Falkenburg <sfalken@apple.com>
Build mod: Fix sln to match configs in vcproj.
first WebView that displayed a directory listing, so this will only be called once.
*/
HRESULT ftpDirectoryTemplatePath([in] IWebView* webView, [out, retval] BSTR* path);
+
+/*!
+ @method webViewHeaderHeight:
+ @param webView The WebView sending the delegate method
+ @abstract Reserve a height for the printed page header.
+ @result The height to reserve for the printed page header, return 0.0 to not reserve any space for a header.
+ @discussion The height returned will be used to calculate the rect passed to webView:drawHeaderInRect:.
+
+ - (float)webViewHeaderHeight:(WebView *)sender;
+*/
+ HRESULT webViewHeaderHeight([in] IWebView* webView, [out, retval] float* result);
+
+/*!
+ @method webViewFooterHeight:
+ @param webView The WebView sending the delegate method
+ @abstract Reserve a height for the printed page footer.
+ @result The height to reserve for the printed page footer, return 0.0 to not reserve any space for a footer.
+ @discussion The height returned will be used to calculate the rect passed to webView:drawFooterInRect:.
+
+ - (float)webViewFooterHeight:(WebView *)sender;
+*/
+ HRESULT webViewFooterHeight([in] IWebView* webView, [out, retval] float* result);
+
+/*!
+ @method webView:drawHeaderInRect:
+ @param webView The WebView sending the delegate method
+ @param rect The NSRect reserved for the header of the page
+ @abstract The delegate should draw a header for the sender in the supplied rect.
+
+ - (void)webView:(WebView *)sender drawHeaderInRect:(NSRect)rect;
+*/
+ HRESULT drawHeaderInRect([in] IWebView* webView, [in] RECT* rect, [in] OLE_HANDLE drawingContext);
+
+/*!
+ @method webView:drawFooterInRect:
+ @param webView The WebView sending the delegate method
+ @param rect The NSRect reserved for the footer of the page
+ @abstract The delegate should draw a footer for the sender in the supplied rect.
+
+ - (void)webView:(WebView *)sender drawFooterInRect:(NSRect)rect;
+*/
+ HRESULT drawFooterInRect([in] IWebView* webView, [in] RECT* rect, [in] OLE_HANDLE drawingContext, [in] UINT pageIndex, [in] UINT pageCount);
+
}
return S_OK;
}
+void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight)
+{
+ if (headerHeight)
+ *headerHeight = 0;
+ if (footerHeight)
+ *footerHeight = 0;
+ float height = 0;
+ COMPtr<IWebUIDelegate> ui;
+ if (FAILED(d->webView->uiDelegate(&ui)))
+ return;
+ COMPtr<IWebUIDelegate2> ui2;
+ if (FAILED(ui->QueryInterface(IID_IWebUIDelegate2, (void**) &ui2)))
+ return;
+ if (headerHeight && SUCCEEDED(ui2->webViewHeaderHeight(d->webView, &height)))
+ *headerHeight = height;
+ if (footerHeight && SUCCEEDED(ui2->webViewFooterHeight(d->webView, &height)))
+ *footerHeight = height;
+}
+
const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC)
{
ASSERT(m_inPrintingMode);
if (!printDC)
return m_pageRects;
- m_pageRects = computePageRectsForFrame(coreFrame, printerRect(printDC), 1.0);
+ // adjust the page rect by the header and footer
+ float headerHeight = 0, footerHeight = 0;
+ headerAndFooterHeights(&headerHeight, &footerHeight);
+ m_pageRects = computePageRectsForFrame(coreFrame, printerRect(printDC), headerHeight, footerHeight, 1.0);
return m_pageRects;
}
if (!coreFrame || !coreFrame->document())
return E_FAIL;
+ UINT pageCount = (UINT) m_pageRects.size();
PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;
- if (m_pageRects.size() == 0 || startPage > m_pageRects.size()) {
+ if (!pageCount || startPage > pageCount) {
ASSERT_NOT_REACHED();
return E_FAIL;
}
startPage--;
if (endPage == 0)
- endPage = (UINT)m_pageRects.size();
+ endPage = pageCount;
+ COMPtr<IWebUIDelegate> ui;
+ if (FAILED(d->webView->uiDelegate(&ui)))
+ return E_FAIL;
+ // FIXME: we can return early after the updated app is released
+ COMPtr<IWebUIDelegate2> ui2;
+ if (FAILED(ui->QueryInterface(IID_IWebUIDelegate2, (void**) &ui2)))
+ ui2 = 0;
+
+ float headerHeight = 0, footerHeight = 0;
+ headerAndFooterHeights(&headerHeight, &footerHeight);
GraphicsContext spoolCtx(pctx);
for (UINT ii = startPage; ii < endPage; ii++) {
CGFloat scale = (float)mediaBox.size.width/ (float)pageRect.width();
CGAffineTransform ctm = CGContextGetBaseCTM(pctx);
ctm = CGAffineTransformScale(ctm, -scale, -scale);
- ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()));
+ ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
CGContextScaleCTM(pctx, scale, scale);
- CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()));
+ CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header
CGContextSetBaseCTM(pctx, ctm);
coreFrame->paint(&spoolCtx, pageRect);
+ if (ui2) {
+ CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);
+
+ int x = pageRect.x();
+ int y = 0;
+ if (headerHeight) {
+ RECT headerRect = {x, y, x+pageRect.width(), y+(int)headerHeight};
+ ui2->drawHeaderInRect(d->webView, &headerRect, (OLE_HANDLE)(LONG64)pctx);
+ }
+
+ if (footerHeight) {
+ y = (int)(mediaBox.size.height/scale - footerHeight);
+ RECT footerRect = {x, y, x+pageRect.width(), y+(int)footerHeight};
+ ui2->drawFooterInRect(d->webView, &footerRect, (OLE_HANDLE)(LONG64)pctx, ii+1, pageCount);
+ }
+ }
+
CGContextEndPage(pctx);
CGContextRestoreGState(pctx);
}
void loadURLIntoChild(const WebCore::KURL&, const WebCore::String& referrer, WebFrame* childFrame);
const Vector<WebCore::IntRect>& computePageRects(HDC printDC);
void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
+ void headerAndFooterHeights(float*, float*);
protected:
ULONG m_refCount;
{
GraphicsContext context(cgContext);
+ ASSERT(CGColorGetNumberOfComponents(color) == 4); // this code assumes the CGColorRef has 4 components
const CGFloat* components = CGColorGetComponents(color);
Color textColor((int)(components[0] * 255), (int)(components[1] * 255), (int)(components[2] * 255), (int)(components[3] * 255));