Allow registering of custom wxWebView backends.
Add wxWebViewFactory as an abstract factory to provide backend creation. Remove old factory methods using wxWebViewBackend enum in favour of the new wxString based method. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73369 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -32,6 +32,14 @@ WX_CHECK_BUILD_OPTIONS("wxWEBVIEW")
|
||||
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[] = "wxWebView";
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[] = "about:blank";
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendIE[] = "wxWebViewIE";
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[] = "wxWebViewWebKit";
|
||||
|
||||
#ifdef __WXMSW__
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewIE";
|
||||
#else
|
||||
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewWebKit";
|
||||
#endif
|
||||
|
||||
wxIMPLEMENT_ABSTRACT_CLASS(wxWebView, wxControl);
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewEvent, wxCommandEvent);
|
||||
@@ -43,77 +51,61 @@ wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
|
||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
|
||||
wxDEFINE_EVENT( wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
|
||||
|
||||
wxStringWebViewFactoryMap wxWebView::m_factoryMap;
|
||||
|
||||
// static
|
||||
wxWebView* wxWebView::New(wxWebViewBackend backend)
|
||||
wxWebView* wxWebView::New(const wxString& backend)
|
||||
{
|
||||
switch (backend)
|
||||
{
|
||||
#if defined(wxUSE_WEBVIEW_WEBKIT) && \
|
||||
(defined(__WXGTK__) || defined(__WXOSX__))
|
||||
case wxWEB_VIEW_BACKEND_WEBKIT:
|
||||
return new wxWebViewWebKit();
|
||||
#endif
|
||||
wxStringWebViewFactoryMap::iterator iter = FindFactory(backend);
|
||||
|
||||
#if wxUSE_WEBVIEW_IE
|
||||
case wxWEB_VIEW_BACKEND_IE:
|
||||
return new wxWebViewIE();
|
||||
#endif
|
||||
|
||||
case wxWEB_VIEW_BACKEND_DEFAULT:
|
||||
|
||||
#if defined(wxUSE_WEBVIEW_WEBKIT) && \
|
||||
(defined(__WXGTK__) || defined(__WXOSX__))
|
||||
return new wxWebViewWebKit();
|
||||
#endif
|
||||
|
||||
#if wxUSE_WEBVIEW_IE
|
||||
return new wxWebViewIE();
|
||||
#endif
|
||||
|
||||
// fall-through intended
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
if(iter == m_factoryMap.end())
|
||||
return NULL;
|
||||
else
|
||||
return (*iter).second->Create();
|
||||
}
|
||||
|
||||
// static
|
||||
wxWebView* wxWebView::New(wxWindow* parent,
|
||||
wxWindowID id,
|
||||
const wxString& url,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
wxWebViewBackend backend,
|
||||
long style,
|
||||
const wxString& name)
|
||||
wxWebView* wxWebView::New(wxWindow* parent, wxWindowID id, const wxString& url,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
const wxString& backend, long style,
|
||||
const wxString& name)
|
||||
{
|
||||
switch (backend)
|
||||
{
|
||||
#if defined(wxUSE_WEBVIEW_WEBKIT) && \
|
||||
(defined(__WXGTK__) || defined(__WXOSX__))
|
||||
case wxWEB_VIEW_BACKEND_WEBKIT:
|
||||
return new wxWebViewWebKit(parent, id, url, pos, size, style, name);
|
||||
#endif
|
||||
wxStringWebViewFactoryMap::iterator iter = FindFactory(backend);
|
||||
|
||||
#if wxUSE_WEBVIEW_IE
|
||||
case wxWEB_VIEW_BACKEND_IE:
|
||||
return new wxWebViewIE(parent, id, url, pos, size, style, name);
|
||||
#endif
|
||||
if(iter == m_factoryMap.end())
|
||||
return NULL;
|
||||
else
|
||||
return (*iter).second->Create(parent, id, url, pos, size, style, name);
|
||||
|
||||
case wxWEB_VIEW_BACKEND_DEFAULT:
|
||||
}
|
||||
|
||||
#if defined(wxUSE_WEBVIEW_WEBKIT) && \
|
||||
(defined(__WXGTK__) || defined(__WXOSX__))
|
||||
return new wxWebViewWebKit(parent, id, url, pos, size, style, name);
|
||||
#endif
|
||||
// static
|
||||
void wxWebView::RegisterFactory(const wxString& backend,
|
||||
wxSharedPtr<wxWebViewFactory> factory)
|
||||
{
|
||||
m_factoryMap[backend] = factory;
|
||||
}
|
||||
|
||||
#if wxUSE_WEBVIEW_IE
|
||||
return new wxWebViewIE(parent, id, url, pos, size, style, name);
|
||||
#endif
|
||||
// static
|
||||
wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend)
|
||||
{
|
||||
// Initialise the map if needed
|
||||
if(m_factoryMap.empty())
|
||||
InitFactoryMap();
|
||||
|
||||
// fall-through intended
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
return m_factoryMap.find(backend);
|
||||
}
|
||||
|
||||
// static
|
||||
void wxWebView::InitFactoryMap()
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
RegisterFactory(wxWebViewBackendIE, wxSharedPtr<wxWebViewFactory>
|
||||
(new wxWebViewFactoryIE));
|
||||
#else
|
||||
RegisterFactory(wxWebViewBackendWebKit, wxSharedPtr<wxWebViewFactory>
|
||||
(new wxWebViewFactoryWebKit));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_WEBVIEW
|
||||
|
Reference in New Issue
Block a user