Diff
Modified: trunk/Source/WebKit/wx/ChangeLog (102714 => 102715)
--- trunk/Source/WebKit/wx/ChangeLog 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/ChangeLog 2011-12-13 23:50:44 UTC (rev 102715)
@@ -1,3 +1,29 @@
+2011-12-11 Robin Dunn <[email protected]>
+
+ Add a URL argument to the wxWebView constructor,
+ and fix page calculations and margins on Windows and Mac.
+ https://bugs.webkit.org/show_bug.cgi?id=74316
+
+ Reviewed by Kevin Ollivier.
+
+ * WebBrowserShell.cpp:
+ (wxWebBrowserShell::wxWebBrowserShell):
+ * WebBrowserShell.h:
+ * WebFrame.cpp:
+ (wxWebFramePrintout::wxWebFramePrintout):
+ (wxWebFramePrintout::~wxWebFramePrintout):
+ (wxWebFramePrintout::InitializeWithPageSize):
+ (wxWebFramePrintout::OnPreparePrinting):
+ (wxWebFramePrintout::OnPrintPage):
+ (wxWebFramePrintout::OnEndPrinting):
+ (wxWebFrame::Print):
+ * WebView.cpp:
+ (wxWebView::wxWebView):
+ (wxWebView::Create):
+ * WebView.h:
+ * bindings/python/samples/simple.py:
+ (TestPanel.__init__):
+
2011-12-07 Mary Wu <[email protected]>
Change function name InitializeLoggingChannelsIfNecessary to follow coding style guideline
Modified: trunk/Source/WebKit/wx/WebBrowserShell.cpp (102714 => 102715)
--- trunk/Source/WebKit/wx/WebBrowserShell.cpp 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/WebBrowserShell.cpp 2011-12-13 23:50:44 UTC (rev 102715)
@@ -97,7 +97,7 @@
END_EVENT_TABLE()
-wxWebBrowserShell::wxWebBrowserShell(const wxString& title) :
+wxWebBrowserShell::wxWebBrowserShell(const wxString& title, const wxString& url) :
wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600, 500)),
m_checkBeforeLoad(false)
{
@@ -167,7 +167,7 @@
SetToolBar(toolbar);
// Create the wxWebView Window
- webview = new wxWebView((wxWindow*)this, ID_WEBVIEW, wxDefaultPosition, wxSize(200, 200));
+ webview = new wxWebView((wxWindow*)this, url, ID_WEBVIEW, wxDefaultPosition, wxSize(200, 200));
webview->SetBackgroundColour(*wxWHITE);
// create a status bar just for fun (by default with 1 pane only)
Modified: trunk/Source/WebKit/wx/WebBrowserShell.h (102714 => 102715)
--- trunk/Source/WebKit/wx/WebBrowserShell.h 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/WebBrowserShell.h 2011-12-13 23:50:44 UTC (rev 102715)
@@ -44,7 +44,7 @@
#if SWIG
%pythonAppend wxWebBrowserShell "self._setOORInfo(self)"
#endif
- wxWebBrowserShell(const wxString& title);
+ wxWebBrowserShell(const wxString& title, const wxString& url = ""
#ifndef SWIG
~wxWebBrowserShell();
Modified: trunk/Source/WebKit/wx/WebFrame.cpp (102714 => 102715)
--- trunk/Source/WebKit/wx/WebFrame.cpp 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/WebFrame.cpp 2011-12-13 23:50:44 UTC (rev 102715)
@@ -98,10 +98,17 @@
m_printContext(frame),
m_pageWidth(0.0),
m_fromPage(1),
- m_toPage(1)
+ m_toPage(1),
+ m_isPrinting(false)
{
}
+ ~wxWebFramePrintout()
+ {
+ if (m_isPrinting)
+ m_printContext.end();
+ }
+
int GetPageCount() { return m_printContext.pageCount(); }
void SetFirstPage(int page) { m_fromPage = page; }
void SetLastPage(int page) { m_toPage = page; }
@@ -109,24 +116,23 @@
void InitializeWithPageSize(wxRect pageRect, bool isMM = true)
{
if (isMM) {
- 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;
+ double mmToPoints = 2.8346;
+ // convert mm to points
+ pageRect.x = pageRect.x * mmToPoints;
+ pageRect.y = pageRect.y * mmToPoints;
+ pageRect.width = pageRect.width * mmToPoints;
+ pageRect.height = pageRect.height * mmToPoints;
}
m_pageWidth = pageRect.width;
m_printContext.begin(m_pageWidth);
+ // isPrinting is from the perspective of the PrintContext, so we need this when we call begin.
+ m_isPrinting = true;
float pageHeight = pageRect.height;
m_printContext.computePageRects(WebCore::FloatRect(pageRect), /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight);
}
- void OnBeginPrinting()
+ void OnPreparePrinting()
{
wxPrinterDC* pdc = dynamic_cast<wxPrinterDC*>(GetDC());
pdc->SetMapMode(wxMM_POINTS);
@@ -135,7 +141,12 @@
pdc->GetSize(&pixelsW, &pixelsH);
pixelsW = pdc->DeviceToLogicalXRel(pixelsW);
pixelsH = pdc->DeviceToLogicalYRel(pixelsH);
- InitializeWithPageSize(wxRect(0, 0, pixelsW, pixelsH - 40), false);
+#if __WXMSW__
+ // on Windows, the context has no margins, so add them ourselves.
+ pixelsW -= 30;
+ pixelsH -= 30;
+#endif
+ InitializeWithPageSize(wxRect(0, 0, pixelsW, pixelsH), false);
}
void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo)
@@ -167,6 +178,10 @@
ASSERT(renderer);
wxGraphicsContext* context = renderer->CreateContext(*pdc);
wxGCDC gcdc(context);
+#if __WXMSW__
+ // see comment above about Windows contexts not having margins set.
+ gcdc.SetDeviceOrigin(15, 15);
+#endif
if (!gcdc.IsOk())
return false;
@@ -178,13 +193,15 @@
void OnEndPrinting()
{
- m_printContext.end();
+ m_printContext.end();
+ m_isPrinting = false;
}
private:
float m_pageWidth;
int m_fromPage;
int m_toPage;
+ bool m_isPrinting;
WebCore::Frame *m_frame;
WebCore::PrintContext m_printContext;
};
@@ -612,42 +629,51 @@
printdata.GetPrintData().SetNoCopies(1);
#if wxCHECK_VERSION(2, 9, 2)
printdata.GetPrintData().ConvertFromNative();
-#else
- // due to wx bugs, we cannot get the actual native default paper type before showing the dialog until 2.9.2,
- // so pick a common default instead.
- printdata.GetPrintData().SetPaperId(wxPAPER_LETTER);
#endif
+ // make sure we have a valid paper type, if we don't, the to / from pages will both be 0
+ // and the dialog won't show.
+ if (printdata.GetPrintData().GetPaperId() == wxPAPER_NONE)
+ printdata.GetPrintData().SetPaperId(wxPAPER_LETTER);
+
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.
+ // The paper size includes the non-printable areas of the page.
+ // Guesstimate the printable page margins until we find a way to precisely
+ // calculate the margins used by the device context on Mac.
paperSize.Deflate(15, 15);
-#endif
+
wxWebFramePrintout* printout = new wxWebFramePrintout(m_impl->frame);
printout->InitializeWithPageSize(paperSize);
+ int pages = printout->GetPageCount();
+ ASSERT(pages > 0);
+
printdata.SetMinPage(1);
- printdata.SetMaxPage(printout->GetPageCount());
+ printdata.SetMaxPage(pages);
printdata.SetFromPage(1);
- printdata.SetToPage(printout->GetPageCount());
+ printdata.SetToPage(pages);
+ bool shouldPrint = true;
if (showDialog) {
wxPrintDialog dialog(0, &printdata);
- if (dialog.ShowModal() == wxID_OK) {
+ shouldPrint = (dialog.ShowModal() == wxID_OK);
+ if (shouldPrint) {
printdata = dialog.GetPrintDialogData();
printout->SetFirstPage(printdata.GetFromPage());
printout->SetLastPage(printdata.GetToPage());
- } else
- return;
+ }
}
- wxPrinter printer(&printdata);
+ if (shouldPrint) {
+ wxPrinter printer(&printdata);
+ printer.Print(0, printout, false);
+ }
+
+ if (printout)
+ delete printout;
- printer.Print(0, printout, false);
-
#else
wxFAIL_MSG(wxT("Printing is only supported in wxWidgets 2.9.1 and above."));
#endif
Modified: trunk/Source/WebKit/wx/WebView.cpp (102714 => 102715)
--- trunk/Source/WebKit/wx/WebView.cpp 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/WebView.cpp 2011-12-13 23:50:44 UTC (rev 102715)
@@ -348,7 +348,7 @@
{
}
-wxWebView::wxWebView(wxWindow* parent, int id, const wxPoint& position,
+wxWebView::wxWebView(wxWindow* parent, const wxString& url, int id, const wxPoint& position,
const wxSize& size, long style, const wxString& name) :
m_textMagnifier(1.0),
m_isInitialized(false),
@@ -356,10 +356,10 @@
m_mouseWheelZooms(false),
m_title(wxEmptyString)
{
- Create(parent, id, position, size, style, name);
+ Create(parent, url, id, position, size, style, name);
}
-bool wxWebView::Create(wxWindow* parent, int id, const wxPoint& position,
+bool wxWebView::Create(wxWindow* parent, const wxString& url, int id, const wxPoint& position,
const wxSize& size, long style, const wxString& name)
{
#if OS(DARWIN)
@@ -421,7 +421,7 @@
// we need to do this so that objects like the focusController are properly
// initialized so that the activate handler is run properly.
- LoadURL(wxT("about:blank"));
+ LoadURL(url);
m_isInitialized = true;
Modified: trunk/Source/WebKit/wx/WebView.h (102714 => 102715)
--- trunk/Source/WebKit/wx/WebView.h 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/WebView.h 2011-12-13 23:50:44 UTC (rev 102715)
@@ -116,7 +116,9 @@
%pythonAppend wxWebView() ""
#endif
- wxWebView(wxWindow* parent, int id = wxID_ANY,
+ wxWebView(wxWindow* parent,
+ const wxString& url = ""
+ int id = wxID_ANY,
const wxPoint& point = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
@@ -127,7 +129,9 @@
wxWebView();
#endif
- bool Create(wxWindow* parent, int id = wxID_ANY,
+ bool Create(wxWindow* parent,
+ const wxString& url = ""
+ int id = wxID_ANY,
const wxPoint& point = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
Modified: trunk/Source/WebKit/wx/bindings/python/samples/simple.py (102714 => 102715)
--- trunk/Source/WebKit/wx/bindings/python/samples/simple.py 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Source/WebKit/wx/bindings/python/samples/simple.py 2011-12-13 23:50:44 UTC (rev 102715)
@@ -44,7 +44,7 @@
sizer = wx.BoxSizer(wx.VERTICAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.webview = wx.webview.WebView(self, -1)
+ self.webview = wx.webview.WebView(self, self.current, -1)
btn = wx.Button(self, -1, "Open", style=wx.BU_EXACTFIT)
@@ -82,7 +82,6 @@
sizer.Add(btnSizer, 0, wx.EXPAND)
sizer.Add(self.webview, 1, wx.EXPAND)
- self.webview.LoadURL(self.current)
self.location.Append(self.current)
self.webview.Bind(wx.webview.EVT_WEBVIEW_LOAD, self.OnStateChanged)
Modified: trunk/Tools/ChangeLog (102714 => 102715)
--- trunk/Tools/ChangeLog 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Tools/ChangeLog 2011-12-13 23:50:44 UTC (rev 102715)
@@ -1,3 +1,15 @@
+2011-12-13 Robin Dunn <[email protected]>
+
+ [wx] Add a URL argument to wxWebView constructor.
+ https://bugs.webkit.org/show_bug.cgi?id=74316
+
+ Reviewed by Kevin Ollivier.
+
+ * DumpRenderTree/wx/DumpRenderTreeWx.cpp:
+ (MyApp::OnInit):
+ * wx/browser/browser.cpp:
+ (MyApp::OnInit):
+
2011-12-13 Raphael Kubo da Costa <[email protected]>
watchlist: Add watchlist for EFL, CMake and libsoup code and put myself on it.
Modified: trunk/Tools/DumpRenderTree/wx/DumpRenderTreeWx.cpp (102714 => 102715)
--- trunk/Tools/DumpRenderTree/wx/DumpRenderTreeWx.cpp 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Tools/DumpRenderTree/wx/DumpRenderTreeWx.cpp 2011-12-13 23:50:44 UTC (rev 102715)
@@ -293,7 +293,7 @@
wxInitAllImageHandlers();
// create the main application window
- wxWebBrowserShell* webFrame = new wxWebBrowserShell(_T("wxWebKit DumpRenderTree App"));
+ wxWebBrowserShell* webFrame = new wxWebBrowserShell(_T("wxWebKit DumpRenderTree App"), "about:blank");
SetTopWindow(webFrame);
webView = webFrame->webview;
webView->SetSize(wxSize(maxViewWidth, maxViewHeight));
Modified: trunk/Tools/wx/browser/browser.cpp (102714 => 102715)
--- trunk/Tools/wx/browser/browser.cpp 2011-12-13 23:50:23 UTC (rev 102714)
+++ trunk/Tools/wx/browser/browser.cpp 2011-12-13 23:50:44 UTC (rev 102715)
@@ -51,7 +51,7 @@
// create the main application window
// see WebKit/wx/WebFrame.cpp for how to write a shell around wxWebView.
- wxWebBrowserShell *frame = new wxWebBrowserShell(_T("wxWebKit Test App"));
+ wxWebBrowserShell *frame = new wxWebBrowserShell(_T("wxWebKit Test App"), "http://www.webkit.org");
#ifndef NDEBUG
frame->ShowDebugMenu(true);