Adds parity to Qt's webview engine.
https://github.com/wxWidgets/wxWidgets/pull/26583
(8 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
I have to get a new Linux machine. Once I get that, I can look into adding support there too.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@vadz commented on this pull request.
Thanks, looks good! Just 2 minor comments that it would be nice to address before merging.
> +{
+ if (!m_impl->m_webView)
+ return false;
+
+ wxCOMPtr<ICoreWebView2_7> webView7;
+ if (FAILED(m_impl->m_webView->QueryInterface(IID_PPV_ARGS(&webView7))))
+ return false;
+
+ const wxString filePathCopy = filePath;
+ HRESULT hr = webView7->PrintToPdf(
+ filePath.wc_str(),
+ nullptr,
+ Callback<ICoreWebView2PrintToPdfCompletedHandler>(
+ [this, filePathCopy](HRESULT errorCode, BOOL isSuccessful) -> HRESULT
+ {
+ wxWebViewEvent event(wxEVT_WEBVIEW_PDF_SAVED, GetId(), filePathCopy, wxString());
It's better to allocate this event on heap and use QueueEvent(). Or, alternatively, use CallAfter() to generate this event directly from the main thread.
> + ? COREWEBVIEW2_PRINT_ORIENTATION_LANDSCAPE
+ : COREWEBVIEW2_PRINT_ORIENTATION_PORTRAIT);
+
+ wxSize paperSizeTenthsMM = wxThePrintPaperDatabase->GetSize(printData.GetPaperId());
+ if (paperSizeTenthsMM.x > 0 && paperSizeTenthsMM.y > 0)
+ {
+ double widthInches = paperSizeTenthsMM.x / 254.0;
+ double heightInches = paperSizeTenthsMM.y / 254.0;
+ printSettings->put_PageWidth(widthInches);
+ printSettings->put_PageHeight(heightInches);
+ }
+
+ printSettings->put_ShouldPrintHeaderAndFooter(FALSE);
+
+ const wxString filePathCopy = filePath;
+ hr = webView7->PrintToPdf(
Could we extract this code in a helper function taking (possibly null) print settings to avoid duplicating the lambda?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
Oh, and clang CI failure looks to be a real problem, apparently we are going to have to provide the UUID of ICoreWebView2_7 ourselves.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden commented on this pull request.
> +{
+ if (!m_impl->m_webView)
+ return false;
+
+ wxCOMPtr<ICoreWebView2_7> webView7;
+ if (FAILED(m_impl->m_webView->QueryInterface(IID_PPV_ARGS(&webView7))))
+ return false;
+
+ const wxString filePathCopy = filePath;
+ HRESULT hr = webView7->PrintToPdf(
+ filePath.wc_str(),
+ nullptr,
+ Callback<ICoreWebView2PrintToPdfCompletedHandler>(
+ [this, filePathCopy](HRESULT errorCode, BOOL isSuccessful) -> HRESULT
+ {
+ wxWebViewEvent event(wxEVT_WEBVIEW_PDF_SAVED, GetId(), filePathCopy, wxString());
Got it, using QueueEvent now.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> + ? COREWEBVIEW2_PRINT_ORIENTATION_LANDSCAPE
+ : COREWEBVIEW2_PRINT_ORIENTATION_PORTRAIT);
+
+ wxSize paperSizeTenthsMM = wxThePrintPaperDatabase->GetSize(printData.GetPaperId());
+ if (paperSizeTenthsMM.x > 0 && paperSizeTenthsMM.y > 0)
+ {
+ double widthInches = paperSizeTenthsMM.x / 254.0;
+ double heightInches = paperSizeTenthsMM.y / 254.0;
+ printSettings->put_PageWidth(widthInches);
+ printSettings->put_PageHeight(heightInches);
+ }
+
+ printSettings->put_ShouldPrintHeaderAndFooter(FALSE);
+
+ const wxString filePathCopy = filePath;
+ hr = webView7->PrintToPdf(
Done.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden pushed 2 commits.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
Oh, and clang CI failure looks to be a real problem, apparently we are going to have to provide the UUID of
ICoreWebView2_7ourselves.
Done.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden pushed 1 commit.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@vadz commented on this pull request.
Thanks, this looks good but GTK version could be tidied up a bit and maybe made safer.
In src/gtk/webview_webkit2.cpp:
> +} // extern "C"
+
+bool wxWebViewWebKit::PrintToPDF(const wxString& filePath)
+{
+ gchar* uri = g_filename_to_uri(filePath.utf8_str(), nullptr, nullptr);
+ if (!uri)
+ return false;
+
+ WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
+
+ wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
Could/should use wxGtkString uri instead.
In samples/webview/webview.cpp:
> + if (!m_browser->PrintToPDF(dlg.GetPath()))
+ wxLogError("PrintToPDF is not supported by this browser backend.");
+}
+
+#if wxUSE_PRINTING_ARCHITECTURE && (defined(__WXMSW__) || defined(__WXGTK__))
+void WebFrame::OnPrintToPDFWithSettings(wxCommandEvent& WXUNUSED(evt))
+{
+ wxArrayString paperChoices;
+ paperChoices.Add("Letter (Portrait)");
+ paperChoices.Add("Letter (Landscape)");
+ paperChoices.Add("A4 (Portrait)");
+ paperChoices.Add("A4 (Landscape)");
+ paperChoices.Add("Legal (Portrait)");
+ paperChoices.Add("Legal (Landscape)");
+
+ int sel = wxGetSingleChoiceIndex(
This is really just in case you'd like to improve it, but IMHO it would make for a nicer demo if the paper choice combobox was part of the file dialog itself (to which it can be added using SetCustomizeHook()).
In src/gtk/webview_webkit2.cpp:
> +struct wxWebViewGtkPDFData
+{
+ wxWebViewWebKit* webView;
+ wxString filePath;
+ WebKitPrintOperation* printop;
+};
+
+static void wxDoHandlePDFResult(gpointer user_data, int success)
+{
+ wxWebViewGtkPDFData* data = static_cast<wxWebViewGtkPDFData*>(user_data);
+ wxWebViewEvent event(wxEVT_WEBVIEW_PDF_SAVED, data->webView->GetId(),
+ data->filePath, wxString());
+ event.SetInt(success);
+ event.SetEventObject(data->webView);
+ data->webView->HandleWindowEvent(event);
+ g_object_unref(data->printop);
This should be arguably done in wxWebViewGtkPDFData dtor (which should be added).
In src/gtk/webview_webkit2.cpp:
> @@ -1525,6 +1527,99 @@ void wxWebViewWebKit::Print(const wxPrintData& printData, int WXUNUSED(flags)) } #endif // wxUSE_PRINTING_ARCHITECTURE +struct wxWebViewGtkPDFData
This struct should define a ctor to prevent it from being created with uninitialized fields.
In src/gtk/webview_webkit2.cpp:
> +
+#if wxUSE_PRINTING_ARCHITECTURE
+bool wxWebViewWebKit::PrintToPDF(const wxString& filePath, const wxPrintData& printData)
+{
+ gchar* uri = g_filename_to_uri(filePath.utf8_str(), nullptr, nullptr);
+ if (!uri)
+ return false;
+
+ WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
+
+ wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
Same as above.
In src/gtk/webview_webkit2.cpp:
> + wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
+
+ wxApplyPrintData(printop, settings, printData);
+
+ webkit_print_operation_set_print_settings(printop, settings);
+
+ wxWebViewGtkPDFData* data = new wxWebViewGtkPDFData{this, filePath, printop};
+ g_signal_connect(printop, "finished", G_CALLBACK(wxgtk_webview_webkit_pdf_finished), data);
+ g_signal_connect(printop, "failed", G_CALLBACK(wxgtk_webview_webkit_pdf_failed), data);
+
+ webkit_print_operation_print(printop);
What's going to happen if wxWebViewWebKit is destroyed (e.g. because the window containing it is closed) before the operation is finished? The pointer will probably leak, which may be not the worst thing, but I'm not sure if the code wouldn't crash, which would be worse.
Can a print operation be cancelled? If so, we should ideally do it from the dtor if one is in progress.
> @@ -1472,6 +1472,80 @@ void wxWebViewEdge::Print(const wxPrintData& printData, int flags)
}
#endif // wxUSE_PRINTING_ARCHITECTURE
+bool wxWebViewEdge::DoCallPrintToPdf(const wxString& filePath, ICoreWebView2PrintSettings* printSettings)
+{
+ wxCOMPtr<ICoreWebView2_7> webView7;
+ if (FAILED(m_impl->m_webView->QueryInterface(IID_PPV_ARGS(&webView7))))
+ return false;
Should we log some error here? It could be confusing to the user if the "Print to PDF" menu item simply did nothing, without any explanation.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden commented on this pull request.
> @@ -1472,6 +1472,80 @@ void wxWebViewEdge::Print(const wxPrintData& printData, int flags)
}
#endif // wxUSE_PRINTING_ARCHITECTURE
+bool wxWebViewEdge::DoCallPrintToPdf(const wxString& filePath, ICoreWebView2PrintSettings* printSettings)
+{
+ wxCOMPtr<ICoreWebView2_7> webView7;
+ if (FAILED(m_impl->m_webView->QueryInterface(IID_PPV_ARGS(&webView7))))
+ return false;
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden commented on this pull request.
In samples/webview/webview.cpp:
> + if (!m_browser->PrintToPDF(dlg.GetPath()))
+ wxLogError("PrintToPDF is not supported by this browser backend.");
+}
+
+#if wxUSE_PRINTING_ARCHITECTURE && (defined(__WXMSW__) || defined(__WXGTK__))
+void WebFrame::OnPrintToPDFWithSettings(wxCommandEvent& WXUNUSED(evt))
+{
+ wxArrayString paperChoices;
+ paperChoices.Add("Letter (Portrait)");
+ paperChoices.Add("Letter (Landscape)");
+ paperChoices.Add("A4 (Portrait)");
+ paperChoices.Add("A4 (Landscape)");
+ paperChoices.Add("Legal (Portrait)");
+ paperChoices.Add("Legal (Landscape)");
+
+ int sel = wxGetSingleChoiceIndex(
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden pushed 3 commits.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden commented on this pull request.
In src/gtk/webview_webkit2.cpp:
> +struct wxWebViewGtkPDFData
+{
+ wxWebViewWebKit* webView;
+ wxString filePath;
+ WebKitPrintOperation* printop;
+};
+
+static void wxDoHandlePDFResult(gpointer user_data, int success)
+{
+ wxWebViewGtkPDFData* data = static_cast<wxWebViewGtkPDFData*>(user_data);
+ wxWebViewEvent event(wxEVT_WEBVIEW_PDF_SAVED, data->webView->GetId(),
+ data->filePath, wxString());
+ event.SetInt(success);
+ event.SetEventObject(data->webView);
+ data->webView->HandleWindowEvent(event);
+ g_object_unref(data->printop);
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> @@ -1525,6 +1527,99 @@ void wxWebViewWebKit::Print(const wxPrintData& printData, int WXUNUSED(flags)) } #endif // wxUSE_PRINTING_ARCHITECTURE +struct wxWebViewGtkPDFData
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> +
+#if wxUSE_PRINTING_ARCHITECTURE
+bool wxWebViewWebKit::PrintToPDF(const wxString& filePath, const wxPrintData& printData)
+{
+ gchar* uri = g_filename_to_uri(filePath.utf8_str(), nullptr, nullptr);
+ if (!uri)
+ return false;
+
+ WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
+
+ wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> +} // extern "C"
+
+bool wxWebViewWebKit::PrintToPDF(const wxString& filePath)
+{
+ gchar* uri = g_filename_to_uri(filePath.utf8_str(), nullptr, nullptr);
+ if (!uri)
+ return false;
+
+ WebKitPrintOperation* printop = webkit_print_operation_new(m_web_view);
+
+ wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
done
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@Blake-Madden pushed 1 commit.
—
View it on GitHub or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
> + wxGtkObject<GtkPrintSettings> settings(gtk_print_settings_new());
+ // Do NOT translate this; this is the name of the "printer" that GTK looks up
+ gtk_print_settings_set_printer(settings, "Print to File");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
+ gtk_print_settings_set(settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri);
+ g_free(uri);
+
+ wxApplyPrintData(printop, settings, printData);
+
+ webkit_print_operation_set_print_settings(printop, settings);
+
+ wxWebViewGtkPDFData* data = new wxWebViewGtkPDFData{this, filePath, printop};
+ g_signal_connect(printop, "finished", G_CALLBACK(wxgtk_webview_webkit_pdf_finished), data);
+ g_signal_connect(printop, "failed", G_CALLBACK(wxgtk_webview_webkit_pdf_failed), data);
+
+ webkit_print_operation_print(printop);
On my OpenSuse at least, I don't have a change to cancel, it performs the PDF save asynchronously. But I've wrapped this in a wxWeakRef just in case.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
The Qt failure doesn't appear to be me:
tests\controls\gridtest.cpp(759): FAILED:
CHECK( colsize.GetCount() == 1 )
with expansion:
0 == 1
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
Yes, it's due to
Timed out waiting for mouse release to be processed
which is not related to the changes here.
I'll merge this soon, thanks for the updates!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()