Diff
Modified: trunk/Source/WebCore/ChangeLog (87744 => 87745)
--- trunk/Source/WebCore/ChangeLog 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebCore/ChangeLog 2011-05-31 19:21:39 UTC (rev 87745)
@@ -1,3 +1,28 @@
+2011-05-31 Robin Dunn <[email protected]>
+
+ Reviewed by Kevin Ollivier.
+
+ [wx] Implement printing support for wxWidgets 2.9.x and above.
+
+ https://bugs.webkit.org/show_bug.cgi?id=61796
+
+ * platform/graphics/GraphicsContext.h:
+ * platform/graphics/wx/FontWx.cpp:
+ (WebCore::Font::drawGlyphs):
+ * platform/graphics/wx/GraphicsContextWx.cpp:
+ (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
+ (WebCore::GraphicsContext::drawRect):
+ (WebCore::GraphicsContext::drawLine):
+ (WebCore::GraphicsContext::drawEllipse):
+ (WebCore::GraphicsContext::strokeArc):
+ (WebCore::GraphicsContext::drawConvexPolygon):
+ (WebCore::GraphicsContext::fillRect):
+ (WebCore::GraphicsContext::drawLineForText):
+ (WebCore::GraphicsContext::scale):
+ (WebCore::GraphicsContext::currentScale):
+ * platform/wx/wxcode/win/non-kerned-drawing.cpp:
+ (WebCore::drawTextWithSpacing):
+
2011-05-31 Joseph Pecoraro <[email protected]>
Reviewed by Pavel Feldman.
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (87744 => 87745)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2011-05-31 19:21:39 UTC (rev 87745)
@@ -472,6 +472,9 @@
#endif
#if PLATFORM(WX)
+ // This is needed because of a bug whereby getting an HDC from a GDI+ context
+ // loses the scale operations applied to the context.
+ FloatSize currentScale();
bool inTransparencyLayer() const { return false; }
#endif
Modified: trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp (87744 => 87745)
--- trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp 2011-05-31 19:21:39 UTC (rev 87745)
@@ -77,7 +77,9 @@
// so we've created a function with platform dependent drawing implementations that
// will hopefully be folded into wx once the API has solidified.
// see platform/wx/wxcode/<platform> for the implementations.
+ graphicsContext->save();
drawTextWithSpacing(graphicsContext, font, color, glyphBuffer, from, numGlyphs, point);
+ graphicsContext->restore();
}
FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const
Modified: trunk/Source/WebCore/platform/graphics/wx/GraphicsContextWx.cpp (87744 => 87745)
--- trunk/Source/WebCore/platform/graphics/wx/GraphicsContextWx.cpp 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebCore/platform/graphics/wx/GraphicsContextWx.cpp 2011-05-31 19:21:39 UTC (rev 87745)
@@ -112,6 +112,7 @@
wxWindowDC* context;
#endif
int mswDCStateID;
+ FloatSize currentScale;
wxRegion gtkCurrentClipRgn;
wxRegion gtkPaintClipRgn;
};
@@ -120,7 +121,8 @@
context(0),
mswDCStateID(0),
gtkCurrentClipRgn(wxRegion()),
- gtkPaintClipRgn(wxRegion())
+ gtkPaintClipRgn(wxRegion()),
+ currentScale(1.0, 1.0)
{
}
@@ -216,8 +218,10 @@
if (paintingDisabled())
return;
+ save();
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height());
+ restore();
}
// This is only used to draw borders.
@@ -229,8 +233,10 @@
FloatPoint p1 = point1;
FloatPoint p2 = point2;
+ save();
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
m_data->context->DrawLine(point1.x(), point1.y(), point2.x(), point2.y());
+ restore();
}
// This method is only used to draw the little circles used in lists.
@@ -239,8 +245,10 @@
if (paintingDisabled())
return;
+ save();
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
m_data->context->DrawEllipse(rect.x(), rect.y(), rect.width(), rect.height());
+ restore();
}
void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan)
@@ -248,8 +256,10 @@
if (paintingDisabled())
return;
+ save();
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
m_data->context->DrawEllipticArc(rect.x(), rect.y(), rect.width(), rect.height(), startAngle, startAngle + angleSpan);
+ restore();
}
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
@@ -260,12 +270,14 @@
if (npoints <= 1)
return;
+ save();
wxPoint* polygon = new wxPoint[npoints];
for (size_t i = 0; i < npoints; i++)
polygon[i] = wxPoint(points[i].x(), points[i].y());
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
m_data->context->DrawPolygon((int)npoints, polygon);
delete [] polygon;
+ restore();
}
void GraphicsContext::clipConvexPolygon(size_t numPoints, const FloatPoint* points, bool antialiased)
@@ -284,13 +296,13 @@
if (paintingDisabled())
return;
- savePlatformState();
+ save();
m_data->context->SetPen(*wxTRANSPARENT_PEN);
m_data->context->SetBrush(wxBrush(color));
m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height());
- restorePlatformState();
+ restore();
}
void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color, ColorSpace colorSpace)
@@ -400,9 +412,11 @@
if (paintingDisabled())
return;
+ save();
FloatPoint endPoint = origin + FloatSize(width, 0);
m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), wxSOLID));
m_data->context->DrawLine(origin.x(), origin.y(), endPoint.x(), endPoint.y());
+ restore();
}
void GraphicsContext::drawLineForTextChecking(const FloatPoint& origin, float width, TextCheckingLineStyle style)
@@ -473,16 +487,20 @@
}
void GraphicsContext::scale(const FloatSize& scale)
-{
+{
#if USE(WXGC)
if (m_data->context) {
wxGraphicsContext* gc = m_data->context->GetGraphicsContext();
gc->Scale(scale.width(), scale.height());
+ m_data->currentScale = scale;
}
#endif
}
-
+FloatSize GraphicsContext::currentScale()
+{
+ return m_data->currentScale;
+}
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)
{
FloatRect result;
Modified: trunk/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp (87744 => 87745)
--- trunk/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp 2011-05-31 19:21:39 UTC (rev 87745)
@@ -24,6 +24,8 @@
*/
#include "config.h"
+
+#include "AffineTransform.h"
#include "GlyphBuffer.h"
#include "GraphicsContext.h"
#include "SimpleFontData.h"
@@ -82,6 +84,7 @@
float y = point.y() - font->fontMetrics().ascent();
float x = point.x();
+
#if USE(WXGC)
// when going from GdiPlus -> Gdi, any GdiPlus transformations are lost
// so we need to alter the coordinates to reflect their transformed point.
@@ -96,11 +99,25 @@
hdc = g->GetHDC();
}
x += (int)xtrans;
- y += (int)ytrans;
+ y += (int)ytrans;
#else
hdc = static_cast<HDC>(dc->GetHDC());
#endif
+ // if the context has been scaled, we must manually re-apply that scale
+ // to the HDC.
+ FloatSize scale = graphicsContext->currentScale();
+ if (scale != FloatSize(1.0, 1.0)) {
+ SetGraphicsMode(hdc, GM_ADVANCED);
+ XFORM xForm;
+ xForm.eM11 = scale.width();
+ xForm.eM12 = 0.0;
+ xForm.eM21 = 0.0;
+ xForm.eM22 = scale.height();
+ xForm.eDx = 0.0;
+ xForm.eDy = 0.0;
+ SetWorldTransform(hdc, &xForm);
+ }
// ExtTextOut wants the offsets as an array of ints, so extract them
// from the glyph buffer
const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
Modified: trunk/Source/WebKit/wx/ChangeLog (87744 => 87745)
--- trunk/Source/WebKit/wx/ChangeLog 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebKit/wx/ChangeLog 2011-05-31 19:21:39 UTC (rev 87745)
@@ -1,3 +1,29 @@
+2011-05-31 Robin Dunn <[email protected]>
+
+ Reviewed by Kevin Ollivier.
+
+ [wx] Implement printing support for wxWidgets 2.9.x and above.
+
+ https://bugs.webkit.org/show_bug.cgi?id=61796
+
+ * WebBrowserShell.cpp:
+ (wxWebBrowserShell::wxWebBrowserShell):
+ (wxWebBrowserShell::OnPrint):
+ * WebBrowserShell.h:
+ * WebFrame.cpp:
+ (wxWebFramePrintout::wxWebFramePrintout):
+ (wxWebFramePrintout::GetPageCount):
+ (wxWebFramePrintout::SetFirstPage):
+ (wxWebFramePrintout::SetLastPage):
+ (wxWebFramePrintout::InitializeWithPageSize):
+ (wxWebFramePrintout::OnBeginPrinting):
+ (wxWebFramePrintout::GetPageInfo):
+ (wxWebFramePrintout::HasPage):
+ (wxWebFramePrintout::OnPrintPage):
+ (wxWebFramePrintout::OnEndPrinting):
+ (wxWebFrame::Print):
+ * WebFrame.h:
+
2011-05-13 Jon Lee <[email protected]>
Reviewed by Simon Fraser.
Modified: trunk/Source/WebKit/wx/WebBrowserShell.cpp (87744 => 87745)
--- trunk/Source/WebKit/wx/WebBrowserShell.cpp 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebKit/wx/WebBrowserShell.cpp 2011-05-31 19:21:39 UTC (rev 87745)
@@ -93,6 +93,7 @@
EVT_MENU(ID_RUN_SCRIPT, wxWebBrowserShell::OnRunScript)
EVT_MENU(ID_EDIT_COMMAND, wxWebBrowserShell::OnEditCommand)
EVT_MENU(ID_GET_EDIT_COMMAND_STATE, wxWebBrowserShell::OnGetEditCommandState)
+ EVT_MENU(wxID_PRINT, wxWebBrowserShell::OnPrint)
END_EVENT_TABLE()
@@ -100,19 +101,20 @@
wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 500)),
m_checkBeforeLoad(false)
{
-
// create a menu bar
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(ID_NEW_WINDOW, _T("New Window\tCTRL+N"));
fileMenu->Append(ID_LOADFILE, _T("Open File...\tCTRL+O"));
fileMenu->Append(ID_LOADURL, _("Open Location...\tCTRL+L"));
+ fileMenu->AppendSeparator();
+ fileMenu->Append(wxID_PRINT, _("Print..."));
fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit this program"));
wxMenu *editMenu = new wxMenu;
editMenu->Append(wxID_CUT, _T("Cut\tCTRL+X"));
editMenu->Append(wxID_COPY, _T("Copy\tCTRL+C"));
editMenu->Append(wxID_PASTE, _T("Paste\tCTRL+V"));
-
+
wxMenu* viewMenu = new wxMenu;
viewMenu->AppendRadioItem(ID_BROWSE, _("Browse"));
viewMenu->AppendRadioItem(ID_EDIT, _("Edit"));
@@ -396,3 +398,9 @@
dialog->Destroy();
}
}
+
+void wxWebBrowserShell::OnPrint(wxCommandEvent& myEvent)
+{
+ if (webview && webview->GetMainFrame())
+ webview->GetMainFrame()->Print();
+}
Modified: trunk/Source/WebKit/wx/WebBrowserShell.h (87744 => 87745)
--- trunk/Source/WebKit/wx/WebBrowserShell.h 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebKit/wx/WebBrowserShell.h 2011-05-31 19:21:39 UTC (rev 87745)
@@ -72,6 +72,7 @@
void OnReload(wxCommandEvent& event);
void OnBrowse(wxCommandEvent& event);
void OnEdit(wxCommandEvent& event);
+ void OnPrint(wxCommandEvent& myEvent);
void OnMakeTextLarger(wxCommandEvent& event);
void OnMakeTextSmaller(wxCommandEvent& event);
Modified: trunk/Source/WebKit/wx/WebFrame.cpp (87744 => 87745)
--- trunk/Source/WebKit/wx/WebFrame.cpp 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebKit/wx/WebFrame.cpp 2011-05-31 19:21:39 UTC (rev 87745)
@@ -29,15 +29,18 @@
#include "Editor.h"
#include "Element.h"
#include "EventHandler.h"
+#include "FloatRect.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameView.h"
+#include "GraphicsContext.h"
#include "HitTestResult.h"
#include "HostWindow.h"
#include "HTMLFrameOwnerElement.h"
#include "markup.h"
#include "Page.h"
#include "PlatformString.h"
+#include "PrintContext.h"
#include "RenderTreeAsText.h"
#include "RenderObject.h"
#include "RenderView.h"
@@ -67,14 +70,111 @@
#include "WebFramePrivate.h"
#include "WebViewPrivate.h"
+#include <algorithm>
+
#include <wx/defs.h>
+#include <wx/dc.h>
#include <wx/dcbuffer.h>
+#include <wx/dcgraph.h>
+#include <wx/graphics.h>
+#include <wx/print.h>
+#include <wx/printdlg.h>
// Match Safari's min/max zoom sizes by default
#define MinimumTextSizeMultiplier 0.5f
#define MaximumTextSizeMultiplier 3.0f
#define TextSizeMultiplierRatio 1.2f
+using namespace std;
+
+// we need wxGraphicsContext and wxPrinterDC to work together,
+// which requires wx 2.9.x.
+#if wxCHECK_VERSION(2, 9, 1)
+class wxWebFramePrintout : public wxPrintout {
+public:
+ wxWebFramePrintout(WebCore::Frame* frame) :
+ m_frame(frame),
+ m_printContext(frame),
+ m_pageWidth(0.0),
+ m_fromPage(1),
+ m_toPage(1)
+ {
+ }
+
+ int GetPageCount() { return m_printContext.pageCount(); }
+ void SetFirstPage(int page) { m_fromPage = page; }
+ void SetLastPage(int page) { m_toPage = page; }
+
+ void InitializeWithPageSize(wxRect pageRect)
+ {
+ double mmToPixelsX = (double)wxGetDisplaySize().GetWidth() /
+ (double)wxGetDisplaySizeMM().GetWidth();
+ double mmToPixelsY = (double)wxGetDisplaySize().GetHeight() /
+ (double)wxGetDisplaySizeMM().GetHeight();
+ // convert mm to pixels
+ pageRect.x = pageRect.x * mmToPixelsX;
+ pageRect.y = pageRect.y * mmToPixelsY;
+ pageRect.width = pageRect.width * mmToPixelsX;
+ pageRect.height = pageRect.height * mmToPixelsY;
+
+ m_pageWidth = pageRect.width;
+ m_printContext.begin(m_pageWidth);
+
+ float pageHeight = pageRect.height;
+ m_printContext.computePageRects(WebCore::FloatRect(pageRect), /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
+ }
+
+ void OnBeginPrinting()
+ {
+ wxPrinterDC* pdc = dynamic_cast<wxPrinterDC*>(GetDC());
+ pdc->SetMapMode(wxMM_POINTS);
+ }
+
+ void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo)
+ {
+ if (minPage)
+ *minPage = 1;
+ if (maxPage)
+ *maxPage = m_printContext.pageCount();
+ if (pageFrom)
+ *pageFrom = m_fromPage;
+ if (pageTo)
+ *pageTo = m_toPage;
+ }
+
+ bool HasPage(int pageNum)
+ {
+ return pageNum <= m_printContext.pageCount() && pageNum >= m_fromPage && pageNum <= m_toPage;
+ }
+
+ bool OnPrintPage(int pageNum)
+ {
+ wxPrinterDC* pdc = dynamic_cast<wxPrinterDC*>(GetDC());
+
+ wxGCDC gcdc(*pdc);
+ if (!gcdc.IsOk())
+ return false;
+
+ WebCore::GraphicsContext ctx(&gcdc);
+ m_printContext.spoolPage(ctx, pageNum - 1, m_pageWidth);
+
+ return true;
+ }
+
+ void OnEndPrinting()
+ {
+ m_printContext.end();
+ }
+
+private:
+ float m_pageWidth;
+ int m_fromPage;
+ int m_toPage;
+ WebCore::Frame *m_frame;
+ WebCore::PrintContext m_printContext;
+};
+#endif
+
wxWebFrame::wxWebFrame(wxWebView* container, wxWebFrame* parent, WebViewFrameData* data) :
m_textMagnifier(1.0),
m_isInitialized(false),
@@ -456,6 +556,47 @@
}
+void wxWebFrame::Print()
+{
+#if wxCHECK_VERSION(2, 9, 1)
+ if (!m_impl->frame)
+ return;
+
+ wxPrintDialogData printdata;
+ printdata.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
+ printdata.GetPrintData().SetPaperId(wxPAPER_LETTER);
+ printdata.GetPrintData().SetNoCopies(1);
+
+ wxPageSetupDialogData pageSetup(printdata.GetPrintData());
+
+ wxRect paperSize = pageSetup.GetPaperSize();
+#ifdef __WXMSW__
+ // On Windows, the paper size apparently includes the non-printable areas of the page.
+ // Guesstimate the printable page margins until we find a better solution.
+ paperSize.Deflate(15, 15);
+#endif
+ wxWebFramePrintout* printout = new wxWebFramePrintout(m_impl->frame);
+ printout->InitializeWithPageSize(paperSize);
+
+ printdata.SetMinPage(1);
+ printdata.SetMaxPage(printout->GetPageCount());
+ printdata.SetFromPage(1);
+ printdata.SetToPage(printout->GetPageCount());
+
+ wxPrintDialog dialog(0, &printdata);
+ if (dialog.ShowModal() == wxID_OK) {
+ wxPrintDialogData data(dialog.GetPrintDialogData());
+ printout->SetFirstPage(data.GetFromPage());
+ printout->SetLastPage(data.GetToPage());
+ wxPrinter printer(&data);
+
+ printer.Print(0, printout, false);
+ }
+#else
+ wxFAIL_MSG(wxT("Printing is only supported in wxWidgets 2.9.1 and above."));
+#endif
+}
+
wxWebViewDOMElementInfo wxWebFrame::HitTest(const wxPoint& pos) const
{
wxWebViewDOMElementInfo domInfo;
Modified: trunk/Source/WebKit/wx/WebFrame.h (87744 => 87745)
--- trunk/Source/WebKit/wx/WebFrame.h 2011-05-31 18:53:57 UTC (rev 87744)
+++ trunk/Source/WebKit/wx/WebFrame.h 2011-05-31 19:21:39 UTC (rev 87745)
@@ -115,6 +115,7 @@
bool GoForward();
void Stop();
void Reload();
+ void Print();
bool CanGoBack();
bool CanGoForward();