#18851: wxWebViewBackendEdge, always invisible if parent is hidden at construction
----------------------+------------------------
Reporter: ericj | Owner:
Type: defect | Status: confirmed
Priority: normal | Milestone:
Component: WebView | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 1 |
----------------------+------------------------
Changes (by pb101):
* cc: pbfordev@… (removed)
Comment:
I have looked into this and it seems that for some reason,
`wxWebViewEdge::OnShow()` is not called as expected. At first I thought
that show event (`WM_SHOWWINDOW`) is not sent to a window completely
covered by another window (`wxWebView` by the actual webview2 control) but
this is is not the case.
It seems that show event is not sent to deeper nested `wxWindow`s. For
example, in the code below, the hierarchy is ''MyFrame'' -> ''m_panel'' ->
''subPanel''. When toggling ''m_panel'' visibility, ''m_panel'' receives
the show event but its child, ''subPanel'', does not. ''subPanel''
receives the event only when the frame is closed.
{{{
#!cpp
#include <wx/wx.h>
class MyFrame: public wxFrame
{
public:
MyFrame() : wxFrame (nullptr, wxID_ANY, "Test")
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxButton* button = new wxButton(this, wxID_ANY, "Toggle Panel");
button->Bind(wxEVT_BUTTON,
[this](wxCommandEvent&){ m_panel->Show(!m_panel->IsShown());
Layout(); });
mainSizer->Add(button, wxSizerFlags().Expand().Border());
m_panel = new wxPanel(this);
#if 0
m_panel->Bind(wxEVT_SHOW,
[this](wxShowEvent&){ wxLogMessage("m_panel wxEVT_SHOW"); });
#endif
wxPanel* subPanel = new wxPanel(m_panel, wxID_ANY, wxPoint(25,
25), wxSize(200, 200));
subPanel->SetBackgroundColour(*wxRED);
subPanel->Bind(wxEVT_SHOW,
[this](wxShowEvent&){ wxLogMessage("subPanel wxEVT_SHOW"); });
mainSizer->Add(m_panel, wxSizerFlags(1).Expand().Border());
SetSizer(mainSizer);
}
private:
wxPanel* m_panel;
};
class MyApp : public wxApp
{
public:
bool OnInit() override
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
}}}
So, this simple change fixes the webview2 issue but it is obviously a
wrong thing to do.
{{{
#!diff
src/msw/webview_edge.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp
index 2dba6fffb1..7f37e50f90 100644
--- a/src/msw/webview_edge.cpp
+++ b/src/msw/webview_edge.cpp
@@ -357,7 +357,8 @@ ICoreWebView2Settings*
wxWebViewEdgeImpl::GetSettings()
wxWebViewEdge::~wxWebViewEdge()
{
- Unbind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
+ if ( GetParent() )
+ GetParent()->Unbind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
delete m_impl;
}
@@ -382,7 +383,7 @@ bool wxWebViewEdge::Create(wxWindow* parent,
if (!m_impl->Create())
return false;
Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this);
- Bind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
+ GetParent()->Bind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
LoadURL(url);
return true;
}}}
--
Ticket URL: <
https://trac.wxwidgets.org/ticket/18851#comment:6>