diff --git a/include/wx/msw/private/webview_edge.h b/include/wx/msw/private/webview_edge.h index ef89c18bae..f78d984395 100644 --- a/include/wx/msw/private/webview_edge.h +++ b/include/wx/msw/private/webview_edge.h @@ -46,6 +46,7 @@ public: EventRegistrationToken m_newWindowRequestedToken = { }; EventRegistrationToken m_documentTitleChangedToken = { }; EventRegistrationToken m_contentLoadingToken = { }; + EventRegistrationToken m_containsFullScreenElementChangedToken = { }; // WebView Event handlers HRESULT OnNavigationStarting(ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args); @@ -54,6 +55,7 @@ public: HRESULT OnNewWindowRequested(ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args); HRESULT OnDocumentTitleChanged(ICoreWebView2* sender, IUnknown* args); HRESULT OnContentLoading(ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args); + HRESULT OnContainsFullScreenElementChanged(ICoreWebView2* sender, IUnknown* args); HRESULT OnEnvironmentCreated(HRESULT result, ICoreWebView2Environment* environment); HRESULT OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController); diff --git a/include/wx/webview.h b/include/wx/webview.h index 9a0997ab36..8b9ac048b3 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -294,6 +294,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_LOADED, wxWebViewEv wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_ERROR, wxWebViewEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_NEWWINDOW, wxWebViewEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_FULLSCREEN_CHANGED, wxWebViewEvent); typedef void (wxEvtHandler::*wxWebViewEventFunction) (wxWebViewEvent&); diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 9decc0f56b..2785eab067 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -428,6 +428,10 @@ public: @event{EVT_WEBVIEW_TITLE_CHANGED(id, func)} Process a @c wxEVT_WEBVIEW_TITLE_CHANGED event, generated when the page title changes. Use GetString to get the title. + @event{EVT_WEBVIEW_FULL_SCREEN_CHANGED(id, func)} + Process a @c EVT_WEBVIEW_FULL_SCREEN_CHANGED event, generated when + the page wants to enter or leave fullscreen. Use GetInt to get the status. + Currently only implemented for the edge backend. @endEventTable @since 2.9.3 diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 1349692c79..ac9512ed89 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -120,6 +120,7 @@ public: void OnDocumentLoaded(wxWebViewEvent& evt); void OnNewWindow(wxWebViewEvent& evt); void OnTitleChanged(wxWebViewEvent& evt); + void OnFullScreenChanged(wxWebViewEvent& evt); void OnSetPage(wxCommandEvent& evt); void OnViewSourceRequest(wxCommandEvent& evt); void OnViewTextRequest(wxCommandEvent& evt); @@ -536,6 +537,7 @@ WebFrame::WebFrame(const wxString& url) : Bind(wxEVT_WEBVIEW_ERROR, &WebFrame::OnError, this, m_browser->GetId()); Bind(wxEVT_WEBVIEW_NEWWINDOW, &WebFrame::OnNewWindow, this, m_browser->GetId()); Bind(wxEVT_WEBVIEW_TITLE_CHANGED, &WebFrame::OnTitleChanged, this, m_browser->GetId()); + Bind(wxEVT_WEBVIEW_FULLSCREEN_CHANGED, &WebFrame::OnFullScreenChanged, this, m_browser->GetId()); // Connect the menu events Bind(wxEVT_MENU, &WebFrame::OnSetPage, this, setPage->GetId()); @@ -897,6 +899,12 @@ void WebFrame::OnTitleChanged(wxWebViewEvent& evt) wxLogMessage("%s", "Title changed; title='" + evt.GetString() + "'"); } +void WebFrame::OnFullScreenChanged(wxWebViewEvent & evt) +{ + wxLogMessage("Full screen changed; status = %d", evt.GetInt()); + ShowFullScreen(evt.GetInt() != 0); +} + void WebFrame::OnSetPage(wxCommandEvent& WXUNUSED(evt)) { m_browser->SetPage diff --git a/src/common/webview.cpp b/src/common/webview.cpp index d88771feb8..74558b4ee4 100644 --- a/src/common/webview.cpp +++ b/src/common/webview.cpp @@ -48,6 +48,7 @@ wxDEFINE_EVENT( wxEVT_WEBVIEW_LOADED, wxWebViewEvent ); wxDEFINE_EVENT( wxEVT_WEBVIEW_ERROR, wxWebViewEvent ); wxDEFINE_EVENT( wxEVT_WEBVIEW_NEWWINDOW, wxWebViewEvent ); wxDEFINE_EVENT( wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent ); +wxDEFINE_EVENT( wxEVT_WEBVIEW_FULLSCREEN_CHANGED, wxWebViewEvent); wxStringWebViewFactoryMap wxWebView::m_factoryMap; diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index f2ffdea8c3..00b3efa62d 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -72,6 +72,7 @@ wxWebViewEdgeImpl::~wxWebViewEdgeImpl() m_webView->remove_NewWindowRequested(m_newWindowRequestedToken); m_webView->remove_DocumentTitleChanged(m_documentTitleChangedToken); m_webView->remove_ContentLoading(m_contentLoadingToken); + m_webView->remove_ContainsFullScreenElementChanged(m_containsFullScreenElementChangedToken); } } @@ -296,6 +297,22 @@ HRESULT wxWebViewEdgeImpl::OnContentLoading(ICoreWebView2* WXUNUSED(sender), ICo return S_OK; } +HRESULT wxWebViewEdgeImpl::OnContainsFullScreenElementChanged(ICoreWebView2* WXUNUSED(sender), IUnknown* WXUNUSED(args)) +{ + BOOL containsFullscreenEvent; + HRESULT hr = m_webView->get_ContainsFullScreenElement(&containsFullscreenEvent); + if (FAILED(hr)) + return hr; + + wxWebViewEvent event(wxEVT_WEBVIEW_FULLSCREEN_CHANGED, m_ctrl->GetId(), + m_ctrl->GetCurrentURL(), ""); + event.SetEventObject(m_ctrl); + event.SetInt(containsFullscreenEvent); + m_ctrl->HandleWindowEvent(event); + + return S_OK; +} + HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Controller* webViewController) { if (FAILED(result)) @@ -341,6 +358,10 @@ HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Control Callback( this, &wxWebViewEdgeImpl::OnContentLoading).Get(), &m_contentLoadingToken); + m_webView->add_ContainsFullScreenElementChanged( + Callback( + this, &wxWebViewEdgeImpl::OnContainsFullScreenElementChanged).Get(), + &m_containsFullScreenElementChangedToken); if (m_pendingContextMenuEnabled != -1) {