Merge branch 'msw_edge_fixed' of https://github.com/TcT2k/wxWidgets

Allow using a fixed Edge version with wxWebViewEdge and other
wxWebView-related improvements and refactoring.

See https://github.com/wxWidgets/wxWidgets/pull/2212
This commit is contained in:
Vadim Zeitlin
2021-02-06 14:22:42 +01:00
16 changed files with 352 additions and 517 deletions

View File

@@ -82,9 +82,7 @@ public:
void SetZoomType(wxWebViewZoomType) wxOVERRIDE; void SetZoomType(wxWebViewZoomType) wxOVERRIDE;
wxWebViewZoomType GetZoomType() const wxOVERRIDE; wxWebViewZoomType GetZoomType() const wxOVERRIDE;
bool CanSetZoomType(wxWebViewZoomType) const wxOVERRIDE; bool CanSetZoomType(wxWebViewZoomType) const wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE; virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom) wxOVERRIDE;
virtual void SetZoomFactor(float) wxOVERRIDE; virtual void SetZoomFactor(float) wxOVERRIDE;
//Clipboard functions //Clipboard functions
@@ -116,7 +114,7 @@ public:
virtual wxString GetSelectedSource() const wxOVERRIDE; virtual wxString GetSelectedSource() const wxOVERRIDE;
virtual void ClearSelection() wxOVERRIDE; virtual void ClearSelection() wxOVERRIDE;
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
//Virtual Filesystem Support //Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
@@ -163,7 +161,7 @@ private:
bool CanExecuteEditingCommand(const gchar* command) const; bool CanExecuteEditingCommand(const gchar* command) const;
void SetupWebExtensionServer(); void SetupWebExtensionServer();
GDBusProxy *GetExtensionProxy() const; GDBusProxy *GetExtensionProxy() const;
bool RunScriptSync(const wxString& javascript, wxString* output = NULL); bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const;
#endif #endif
WebKitWebView *m_web_view; WebKitWebView *m_web_view;
@@ -198,6 +196,9 @@ public:
long style = 0, long style = 0,
const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE
{ return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
#if wxUSE_WEBVIEW_WEBKIT2
virtual wxVersionInfo GetVersionInfo() wxOVERRIDE;
#endif
}; };

View File

@@ -66,6 +66,8 @@ public:
ICoreWebView2Settings* GetSettings(); ICoreWebView2Settings* GetSettings();
static wxDynamicLibrary ms_loaderDll; static wxDynamicLibrary ms_loaderDll;
static wxString ms_browserExecutableDir;
static wxString ms_version;
static bool Initialize(); static bool Initialize();

View File

@@ -60,9 +60,6 @@ public:
virtual void Stop() wxOVERRIDE; virtual void Stop() wxOVERRIDE;
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE; virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE;
virtual wxString GetPageSource() const wxOVERRIDE;
virtual wxString GetPageText() const wxOVERRIDE;
virtual bool IsBusy() const wxOVERRIDE; virtual bool IsBusy() const wxOVERRIDE;
virtual wxString GetCurrentURL() const wxOVERRIDE; virtual wxString GetCurrentURL() const wxOVERRIDE;
virtual wxString GetCurrentTitle() const wxOVERRIDE; virtual wxString GetCurrentTitle() const wxOVERRIDE;
@@ -73,55 +70,33 @@ public:
virtual void Print() wxOVERRIDE; virtual void Print() wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE; virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom zoom) wxOVERRIDE;
virtual void SetZoomFactor(float zoom) wxOVERRIDE; virtual void SetZoomFactor(float zoom) wxOVERRIDE;
//Clipboard functions
virtual bool CanCut() const wxOVERRIDE;
virtual bool CanCopy() const wxOVERRIDE;
virtual bool CanPaste() const wxOVERRIDE;
virtual void Cut() wxOVERRIDE;
virtual void Copy() wxOVERRIDE;
virtual void Paste() wxOVERRIDE;
//Undo / redo functionality //Undo / redo functionality
virtual bool CanUndo() const wxOVERRIDE; virtual bool CanUndo() const wxOVERRIDE;
virtual bool CanRedo() const wxOVERRIDE; virtual bool CanRedo() const wxOVERRIDE;
virtual void Undo() wxOVERRIDE; virtual void Undo() wxOVERRIDE;
virtual void Redo() wxOVERRIDE; virtual void Redo() wxOVERRIDE;
//Find function
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) wxOVERRIDE;
//Editing functions //Editing functions
virtual void SetEditable(bool enable = true) wxOVERRIDE; virtual void SetEditable(bool enable = true) wxOVERRIDE;
virtual bool IsEditable() const wxOVERRIDE; virtual bool IsEditable() const wxOVERRIDE;
//Selection
virtual void SelectAll() wxOVERRIDE;
virtual bool HasSelection() const wxOVERRIDE;
virtual void DeleteSelection() wxOVERRIDE;
virtual wxString GetSelectedText() const wxOVERRIDE;
virtual wxString GetSelectedSource() const wxOVERRIDE;
virtual void ClearSelection() wxOVERRIDE;
virtual void EnableContextMenu(bool enable = true) wxOVERRIDE; virtual void EnableContextMenu(bool enable = true) wxOVERRIDE;
virtual bool IsContextMenuEnabled() const wxOVERRIDE; virtual bool IsContextMenuEnabled() const wxOVERRIDE;
virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE; virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE;
virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE; virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE;
bool QueryCommandEnabled(const wxString& command) const; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
void ExecCommand(const wxString& command);
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE;
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
virtual void* GetNativeBackend() const wxOVERRIDE; virtual void* GetNativeBackend() const wxOVERRIDE;
static void MSWSetBrowserExecutableDir(const wxString& path);
protected: protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE; virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE;
@@ -132,7 +107,7 @@ private:
void OnShow(wxShowEvent& event); void OnShow(wxShowEvent& event);
bool RunScriptSync(const wxString& javascript, wxString* output = NULL); bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const;
wxDECLARE_DYNAMIC_CLASS(wxWebViewEdge); wxDECLARE_DYNAMIC_CLASS(wxWebViewEdge);
}; };
@@ -152,6 +127,7 @@ public:
return new wxWebViewEdge(parent, id, url, pos, size, style, name); return new wxWebViewEdge(parent, id, url, pos, size, style, name);
} }
virtual bool IsAvailable() wxOVERRIDE; virtual bool IsAvailable() wxOVERRIDE;
virtual wxVersionInfo GetVersionInfo() wxOVERRIDE;
}; };
#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_EDGE && defined(__WXMSW__) #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_EDGE && defined(__WXMSW__)

View File

@@ -131,7 +131,7 @@ public:
virtual wxString GetSelectedSource() const wxOVERRIDE; virtual wxString GetSelectedSource() const wxOVERRIDE;
virtual void ClearSelection() wxOVERRIDE; virtual void ClearSelection() wxOVERRIDE;
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
//Virtual Filesystem Support //Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
@@ -192,6 +192,7 @@ public:
long style = 0, long style = 0,
const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE
{ return new wxWebViewIE(parent, id, url, pos, size, style, name); } { return new wxWebViewIE(parent, id, url, pos, size, style, name); }
virtual wxVersionInfo GetVersionInfo() wxOVERRIDE;
}; };
#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__) #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__)

View File

@@ -56,17 +56,13 @@ public:
virtual void GoForward() wxOVERRIDE; virtual void GoForward() wxOVERRIDE;
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE; virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE;
virtual void Stop() wxOVERRIDE; virtual void Stop() wxOVERRIDE;
virtual wxString GetPageSource() const wxOVERRIDE;
virtual wxString GetPageText() const wxOVERRIDE;
virtual void Print() wxOVERRIDE; virtual void Print() wxOVERRIDE;
virtual void LoadURL(const wxString& url) wxOVERRIDE; virtual void LoadURL(const wxString& url) wxOVERRIDE;
virtual wxString GetCurrentURL() const wxOVERRIDE; virtual wxString GetCurrentURL() const wxOVERRIDE;
virtual wxString GetCurrentTitle() const wxOVERRIDE; virtual wxString GetCurrentTitle() const wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE; virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom zoom) wxOVERRIDE;
virtual void SetZoomFactor(float zoom) wxOVERRIDE; virtual void SetZoomFactor(float zoom) wxOVERRIDE;
virtual void SetZoomType(wxWebViewZoomType zoomType) wxOVERRIDE; virtual void SetZoomType(wxWebViewZoomType zoomType) wxOVERRIDE;
@@ -88,35 +84,11 @@ public:
virtual void Undo() wxOVERRIDE; virtual void Undo() wxOVERRIDE;
virtual void Redo() wxOVERRIDE; virtual void Redo() wxOVERRIDE;
//Find function
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) wxOVERRIDE
{
wxUnusedVar(text);
wxUnusedVar(flags);
return wxNOT_FOUND;
}
//Clipboard functions
virtual bool CanCut() const wxOVERRIDE { return true; }
virtual bool CanCopy() const wxOVERRIDE { return true; }
virtual bool CanPaste() const wxOVERRIDE { return true; }
virtual void Cut() wxOVERRIDE;
virtual void Copy() wxOVERRIDE;
virtual void Paste() wxOVERRIDE;
//Editing functions //Editing functions
virtual void SetEditable(bool enable = true) wxOVERRIDE; virtual void SetEditable(bool enable = true) wxOVERRIDE;
virtual bool IsEditable() const wxOVERRIDE; virtual bool IsEditable() const wxOVERRIDE;
//Selection bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE;
virtual void DeleteSelection() wxOVERRIDE;
virtual bool HasSelection() const wxOVERRIDE;
virtual void SelectAll() wxOVERRIDE;
virtual wxString GetSelectedText() const wxOVERRIDE;
virtual wxString GetSelectedSource() const wxOVERRIDE;
virtual void ClearSelection() wxOVERRIDE;
bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE;
//Virtual Filesystem Support //Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;
@@ -135,9 +107,7 @@ private:
WX_NSObject m_navigationDelegate; WX_NSObject m_navigationDelegate;
WX_NSObject m_UIDelegate; WX_NSObject m_UIDelegate;
bool RunScriptSync(const wxString& javascript, wxString* output = NULL); bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const;
bool QueryCommandEnabled(const wxString& command) const;
void ExecCommand(const wxString& command);
}; };
class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory

View File

@@ -22,6 +22,7 @@ bool DecodeString(const wxString& in, wxString* out)
// String has to chart with a quote // String has to chart with a quote
if (*(ch++) != '"') if (*(ch++) != '"')
return false; return false;
out->clear();
out->reserve(buf.length()); out->reserve(buf.length());
const wchar_t* end = buf.data() + buf.length() - 1; const wchar_t* end = buf.data() + buf.length() - 1;
for (; ch < end; ++ch) for (; ch < end; ++ch)

View File

@@ -18,6 +18,7 @@
#include "wx/sstream.h" #include "wx/sstream.h"
#include "wx/sharedptr.h" #include "wx/sharedptr.h"
#include "wx/vector.h" #include "wx/vector.h"
#include "wx/versioninfo.h"
#if defined(__WXOSX__) #if defined(__WXOSX__)
#include "wx/osx/webviewhistoryitem_webkit.h" #include "wx/osx/webviewhistoryitem_webkit.h"
@@ -120,6 +121,7 @@ public:
long style = 0, long style = 0,
const wxString& name = wxASCII_STR(wxWebViewNameStr)) = 0; const wxString& name = wxASCII_STR(wxWebViewNameStr)) = 0;
virtual bool IsAvailable() { return true; } virtual bool IsAvailable() { return true; }
virtual wxVersionInfo GetVersionInfo() { return wxVersionInfo(); }
}; };
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebViewFactory>, wxStringWebViewFactoryMap); WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebViewFactory>, wxStringWebViewFactoryMap);
@@ -158,6 +160,7 @@ public:
static void RegisterFactory(const wxString& backend, static void RegisterFactory(const wxString& backend,
wxSharedPtr<wxWebViewFactory> factory); wxSharedPtr<wxWebViewFactory> factory);
static bool IsBackendAvailable(const wxString& backend); static bool IsBackendAvailable(const wxString& backend);
static wxVersionInfo GetBackendVersionInfo(const wxString& backend = wxASCII_STR(wxWebViewBackendDefault));
// General methods // General methods
virtual void EnableContextMenu(bool enable = true) virtual void EnableContextMenu(bool enable = true)
@@ -168,8 +171,8 @@ public:
virtual wxString GetCurrentTitle() const = 0; virtual wxString GetCurrentTitle() const = 0;
virtual wxString GetCurrentURL() const = 0; virtual wxString GetCurrentURL() const = 0;
// TODO: handle choosing a frame when calling GetPageSource()? // TODO: handle choosing a frame when calling GetPageSource()?
virtual wxString GetPageSource() const = 0; virtual wxString GetPageSource() const;
virtual wxString GetPageText() const = 0; virtual wxString GetPageText() const;
virtual bool IsBusy() const = 0; virtual bool IsBusy() const = 0;
virtual bool IsContextMenuEnabled() const { return m_showMenu; } virtual bool IsContextMenuEnabled() const { return m_showMenu; }
virtual bool IsAccessToDevToolsEnabled() const { return false; } virtual bool IsAccessToDevToolsEnabled() const { return false; }
@@ -178,7 +181,7 @@ public:
virtual void Print() = 0; virtual void Print() = 0;
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0; virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) = 0; virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) = 0;
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) = 0; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const = 0;
virtual void SetEditable(bool enable = true) = 0; virtual void SetEditable(bool enable = true) = 0;
void SetPage(const wxString& html, const wxString& baseUrl) void SetPage(const wxString& html, const wxString& baseUrl)
{ {
@@ -205,28 +208,28 @@ public:
//Zoom //Zoom
virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0; virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
virtual wxWebViewZoom GetZoom() const = 0; virtual wxWebViewZoom GetZoom() const;
virtual float GetZoomFactor() const = 0; virtual float GetZoomFactor() const = 0;
virtual wxWebViewZoomType GetZoomType() const = 0; virtual wxWebViewZoomType GetZoomType() const = 0;
virtual void SetZoom(wxWebViewZoom zoom) = 0; virtual void SetZoom(wxWebViewZoom zoom);
virtual void SetZoomFactor(float zoom) = 0; virtual void SetZoomFactor(float zoom) = 0;
virtual void SetZoomType(wxWebViewZoomType zoomType) = 0; virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
//Selection //Selection
virtual void SelectAll() = 0; virtual void SelectAll() ;
virtual bool HasSelection() const = 0; virtual bool HasSelection() const;
virtual void DeleteSelection() = 0; virtual void DeleteSelection();
virtual wxString GetSelectedText() const = 0; virtual wxString GetSelectedText() const;
virtual wxString GetSelectedSource() const = 0; virtual wxString GetSelectedSource() const;
virtual void ClearSelection() = 0; virtual void ClearSelection();
//Clipboard functions //Clipboard functions
virtual bool CanCut() const = 0; virtual bool CanCut() const;
virtual bool CanCopy() const = 0; virtual bool CanCopy() const;
virtual bool CanPaste() const = 0; virtual bool CanPaste() const;
virtual void Cut() = 0; virtual void Cut();
virtual void Copy() = 0; virtual void Copy();
virtual void Paste() = 0; virtual void Paste();
//Undo / redo functionality //Undo / redo functionality
virtual bool CanUndo() const = 0; virtual bool CanUndo() const = 0;
@@ -237,14 +240,17 @@ public:
//Get the pointer to the underlying native engine. //Get the pointer to the underlying native engine.
virtual void* GetNativeBackend() const = 0; virtual void* GetNativeBackend() const = 0;
//Find function //Find function
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) = 0; virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT);
protected: protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0; virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
bool QueryCommandEnabled(const wxString& command) const;
void ExecCommand(const wxString& command);
// Count the number of calls to RunScript() in order to prevent // Count the number of calls to RunScript() in order to prevent
// the_same variable from being used twice in more than one call. // the_same variable from being used twice in more than one call.
int m_runScriptCount; mutable int m_runScriptCount;
private: private:
static void InitFactoryMap(); static void InitFactoryMap();

View File

@@ -231,6 +231,13 @@ public:
@since 3.1.5 @since 3.1.5
*/ */
virtual bool IsAvailable(); virtual bool IsAvailable();
/**
Retrieve the version information about this backend implementation.
@since 3.1.5
*/
virtual wxVersionInfo GetVersionInfo(const wxString& backend);
}; };
/** /**
@@ -330,6 +337,16 @@ public:
- Make sure to add a note about using the WebView2 SDK to your application - Make sure to add a note about using the WebView2 SDK to your application
documentation, as required by its licence documentation, as required by its licence
If enabled and available at runtime edge will be selected as the default
backend. If you require the IE backend use @c wxWEBVIEW_BACKEND_IE when
using wxWebView::New().
If your application should use a
<a href="https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#fixed-version-distribution-mode">
fixed version</a> of the WebView2 runtime you must use
wxWebViewEdge::MSWSetBrowserExecutableDir() to specify its usage before
using the edge backend.
@par wxWEBVIEW_WEBKIT (GTK) @par wxWEBVIEW_WEBKIT (GTK)
Under GTK the WebKit backend uses Under GTK the WebKit backend uses
@@ -486,6 +503,12 @@ public:
*/ */
static bool IsBackendAvailable(const wxString& backend); static bool IsBackendAvailable(const wxString& backend);
/**
Retrieve the version information about the backend implementation.
@since 3.1.5
*/
static wxVersionInfo GetBackendVersionInfo(const wxString& backend = wxWebViewBackendDefault);
/** /**
Get the title of the current web page, or its URL/path if title is not Get the title of the current web page, or its URL/path if title is not
@@ -531,12 +554,12 @@ public:
@return The HTML source code, or an empty string if no page is currently @return The HTML source code, or an empty string if no page is currently
shown. shown.
*/ */
virtual wxString GetPageSource() const = 0; virtual wxString GetPageSource() const;
/** /**
Get the text of the current page. Get the text of the current page.
*/ */
virtual wxString GetPageText() const = 0; virtual wxString GetPageText() const;
/** /**
Returns whether the web control is currently busy (e.g.\ loading a page). Returns whether the web control is currently busy (e.g.\ loading a page).
@@ -637,7 +660,7 @@ public:
version 3.1.1. version 3.1.1.
@return @true if there is a result, @false if there is an error. @return @true if there is a result, @false if there is an error.
*/ */
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) = 0; virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const = 0;
/** /**
Set the editable property of the web control. Enabling allows the user Set the editable property of the web control. Enabling allows the user
@@ -683,36 +706,36 @@ public:
@note This always returns @c true on the macOS WebKit backend. @note This always returns @c true on the macOS WebKit backend.
*/ */
virtual bool CanCopy() const = 0; virtual bool CanCopy() const;
/** /**
Returns @true if the current selection can be cut. Returns @true if the current selection can be cut.
@note This always returns @c true on the macOS WebKit backend. @note This always returns @c true on the macOS WebKit backend.
*/ */
virtual bool CanCut() const = 0; virtual bool CanCut() const;
/** /**
Returns @true if data can be pasted. Returns @true if data can be pasted.
@note This always returns @c true on the macOS WebKit backend. @note This always returns @c true on the macOS WebKit backend.
*/ */
virtual bool CanPaste() const = 0; virtual bool CanPaste() const;
/** /**
Copies the current selection. Copies the current selection.
*/ */
virtual void Copy() = 0; virtual void Copy();
/** /**
Cuts the current selection. Cuts the current selection.
*/ */
virtual void Cut() = 0; virtual void Cut();
/** /**
Pastes the current data. Pastes the current data.
*/ */
virtual void Paste() = 0; virtual void Paste();
/** /**
@name Context Menu @name Context Menu
@@ -823,34 +846,34 @@ public:
/** /**
Clears the current selection. Clears the current selection.
*/ */
virtual void ClearSelection() = 0; virtual void ClearSelection();
/** /**
Deletes the current selection. Note that for @c wxWEBVIEW_BACKEND_WEBKIT Deletes the current selection. Note that for @c wxWEBVIEW_BACKEND_WEBKIT
the selection must be editable, either through SetEditable or the the selection must be editable, either through SetEditable or the
correct HTML attribute. correct HTML attribute.
*/ */
virtual void DeleteSelection() = 0; virtual void DeleteSelection();
/** /**
Returns the currently selected source, if any. Returns the currently selected source, if any.
*/ */
virtual wxString GetSelectedSource() const = 0; virtual wxString GetSelectedSource() const;
/** /**
Returns the currently selected text, if any. Returns the currently selected text, if any.
*/ */
virtual wxString GetSelectedText() const = 0; virtual wxString GetSelectedText() const;
/** /**
Returns @true if there is a current selection. Returns @true if there is a current selection.
*/ */
virtual bool HasSelection() const = 0; virtual bool HasSelection() const;
/** /**
Selects the entire page. Selects the entire page.
*/ */
virtual void SelectAll() = 0; virtual void SelectAll();
/** /**
@name Undo / Redo @name Undo / Redo
@@ -898,7 +921,7 @@ public:
on the macOS WebKit backend. on the macOS WebKit backend.
@since 2.9.5 @since 2.9.5
*/ */
virtual long Find(const wxString& text, wxWebViewFindFlags flags = wxWEBVIEW_FIND_DEFAULT) = 0; virtual long Find(const wxString& text, wxWebViewFindFlags flags = wxWEBVIEW_FIND_DEFAULT);
/** /**
@name Zoom @name Zoom
@@ -918,7 +941,7 @@ public:
as provided by @c wxWebViewZoom. as provided by @c wxWebViewZoom.
@return The current level of zoom. @return The current level of zoom.
*/ */
virtual wxWebViewZoom GetZoom() const = 0; virtual wxWebViewZoom GetZoom() const;
/** /**
Get the zoom factor of the page. Get the zoom factor of the page.
@@ -939,7 +962,7 @@ public:
steps provided by @c wxWebViewZoom. steps provided by @c wxWebViewZoom.
@param zoom How much to zoom (scale) the HTML document. @param zoom How much to zoom (scale) the HTML document.
*/ */
virtual void SetZoom(wxWebViewZoom zoom) = 0; virtual void SetZoom(wxWebViewZoom zoom);
/** /**
Set the zoom factor of the page. Set the zoom factor of the page.

View File

@@ -30,6 +30,9 @@
#if wxUSE_WEBVIEW_IE #if wxUSE_WEBVIEW_IE
#include "wx/msw/webview_ie.h" #include "wx/msw/webview_ie.h"
#endif #endif
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h" #include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h" #include "wx/webviewfshandler.h"
#include "wx/numdlg.h" #include "wx/numdlg.h"
@@ -37,6 +40,7 @@
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/fs_arc.h" #include "wx/fs_arc.h"
#include "wx/fs_mem.h" #include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#ifndef wxHAS_IMAGES_IN_RESOURCES #ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm" #include "../sample.xpm"
@@ -370,20 +374,23 @@ WebFrame::WebFrame(const wxString& url) :
// Create a log window // Create a log window
new wxLogWindow(this, _("Logging"), true, false); new wxLogWindow(this, _("Logging"), true, false);
// Create the webview #if wxUSE_WEBVIEW_EDGE
wxString backend = wxWebViewBackendDefault; // Check if a fixed version of edge is present in
#ifdef __WXMSW__ // $executable_path/edge_fixed and use it
if (wxWebView::IsBackendAvailable(wxWebViewBackendEdge)) wxFileName edgeFixedDir(wxStandardPaths::Get().GetExecutablePath());
edgeFixedDir.SetFullName("");
edgeFixedDir.AppendDir("edge_fixed");
if (edgeFixedDir.DirExists())
{ {
wxLogMessage("Using Edge backend"); wxWebViewEdge::MSWSetBrowserExecutableDir(edgeFixedDir.GetFullPath());
backend = wxWebViewBackendEdge; wxLogMessage("Using fixed edge version");
}
else
{
wxLogMessage("Edge backend not available");
} }
#endif #endif
m_browser = wxWebView::New(backend); // Create the webview
m_browser = wxWebView::New();
// Log backend information
wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(),
wxWebView::GetBackendVersionInfo().ToString());
#ifdef __WXMAC__ #ifdef __WXMAC__
// With WKWebView handlers need to be registered before creation // With WKWebView handlers need to be registered before creation
m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs"))); m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));

View File

@@ -34,7 +34,7 @@ extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendEdge[] = "wxWebViewE
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[] = "wxWebViewWebKit"; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[] = "wxWebViewWebKit";
#ifdef __WXMSW__ #ifdef __WXMSW__
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewIE"; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "";
#else #else
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewWebKit"; extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewWebKit";
#endif #endif
@@ -51,6 +51,163 @@ wxDEFINE_EVENT( wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent );
wxStringWebViewFactoryMap wxWebView::m_factoryMap; wxStringWebViewFactoryMap wxWebView::m_factoryMap;
wxWebViewZoom wxWebView::GetZoom() const
{
float zoom = GetZoomFactor();
// arbitrary way to map float zoom to our common zoom enum
if (zoom <= 0.55)
{
return wxWEBVIEW_ZOOM_TINY;
}
else if (zoom > 0.55 && zoom <= 0.85)
{
return wxWEBVIEW_ZOOM_SMALL;
}
else if (zoom > 0.85 && zoom <= 1.15)
{
return wxWEBVIEW_ZOOM_MEDIUM;
}
else if (zoom > 1.15 && zoom <= 1.45)
{
return wxWEBVIEW_ZOOM_LARGE;
}
else if (zoom > 1.45)
{
return wxWEBVIEW_ZOOM_LARGEST;
}
// to shut up compilers, this can never be reached logically
wxFAIL_MSG("unreachable");
return wxWEBVIEW_ZOOM_MEDIUM;
}
void wxWebView::SetZoom(wxWebViewZoom zoom)
{
// arbitrary way to map our common zoom enum to float zoom
switch (zoom)
{
case wxWEBVIEW_ZOOM_TINY:
SetZoomFactor(0.4f);
break;
case wxWEBVIEW_ZOOM_SMALL:
SetZoomFactor(0.7f);
break;
case wxWEBVIEW_ZOOM_MEDIUM:
SetZoomFactor(1.0f);
break;
case wxWEBVIEW_ZOOM_LARGE:
SetZoomFactor(1.3f);
break;
case wxWEBVIEW_ZOOM_LARGEST:
SetZoomFactor(1.6f);
break;
}
}
bool wxWebView::QueryCommandEnabled(const wxString& command) const
{
wxString resultStr;
RunScript(
wxString::Format("function f(){ return document.queryCommandEnabled('%s'); } f();", command), &resultStr);
return resultStr.IsSameAs("true", false);
}
void wxWebView::ExecCommand(const wxString& command)
{
RunScript(wxString::Format("document.execCommand('%s');", command));
}
wxString wxWebView::GetPageSource() const
{
wxString text;
RunScript("document.documentElement.outerHTML;", &text);
return text;
}
wxString wxWebView::GetPageText() const
{
wxString text;
RunScript("document.body.innerText;", &text);
return text;
}
bool wxWebView::CanCut() const
{
return QueryCommandEnabled("cut");
}
bool wxWebView::CanCopy() const
{
return QueryCommandEnabled("copy");
}
bool wxWebView::CanPaste() const
{
return QueryCommandEnabled("paste");
}
void wxWebView::Cut()
{
ExecCommand("cut");
}
void wxWebView::Copy()
{
ExecCommand("copy");
}
void wxWebView::Paste()
{
ExecCommand("paste");
}
wxString wxWebView::GetSelectedText() const
{
wxString text;
RunScript("window.getSelection().toString();", &text);
return text;
}
wxString wxWebView::GetSelectedSource() const
{
// TODO: could probably be implemented by script similar to GetSelectedText()
return wxString();
}
void wxWebView::DeleteSelection()
{
ExecCommand("delete");
}
bool wxWebView::HasSelection() const
{
wxString rangeCountStr;
RunScript("window.getSelection().rangeCount;", &rangeCountStr);
return rangeCountStr != "0";
}
void wxWebView::ClearSelection()
{
//We use javascript as selection isn't exposed at the moment in webkit
RunScript("window.getSelection().removeAllRanges();");
}
void wxWebView::SelectAll()
{
RunScript("window.getSelection().selectAllChildren(document.body);");
}
long wxWebView::Find(const wxString& WXUNUSED(text), int WXUNUSED(flags))
{
// TODO: could probably be implemented by script
return -1;
}
// static // static
wxWebView* wxWebView::New(const wxString& backend) wxWebView* wxWebView::New(const wxString& backend)
{ {
@@ -94,12 +251,36 @@ bool wxWebView::IsBackendAvailable(const wxString& backend)
return false; return false;
} }
wxVersionInfo wxWebView::GetBackendVersionInfo(const wxString& backend)
{
wxStringWebViewFactoryMap::iterator iter = FindFactory(backend);
if (iter != m_factoryMap.end())
return iter->second->GetVersionInfo();
else
return wxVersionInfo();
}
// static // static
wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend) wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend)
{ {
// Initialise the map, it checks internally for existing factories // Initialise the map, it checks internally for existing factories
InitFactoryMap(); InitFactoryMap();
#ifdef __WXMSW__
// Use edge as default backend on MSW if available
if (backend.empty())
{
wxStringWebViewFactoryMap::iterator defaultBackend =
m_factoryMap.find(wxWebViewBackendIE);
#if wxUSE_WEBVIEW_EDGE
wxStringWebViewFactoryMap::iterator edgeFactory = m_factoryMap.find(wxWebViewBackendEdge);
if (edgeFactory->second->IsAvailable())
return edgeFactory;
#endif
return defaultBackend;
}
else
#endif
return m_factoryMap.find(backend); return m_factoryMap.find(backend);
} }

View File

@@ -750,67 +750,12 @@ wxString wxWebViewWebKit::GetPageSource() const
} }
wxWebViewZoom wxWebViewWebKit::GetZoom() const
{
float zoom = GetWebkitZoom();
// arbitrary way to map float zoom to our common zoom enum
if (zoom <= 0.65)
{
return wxWEBVIEW_ZOOM_TINY;
}
if (zoom <= 0.90)
{
return wxWEBVIEW_ZOOM_SMALL;
}
if (zoom <= 1.15)
{
return wxWEBVIEW_ZOOM_MEDIUM;
}
if (zoom <= 1.45)
{
return wxWEBVIEW_ZOOM_LARGE;
}
return wxWEBVIEW_ZOOM_LARGEST;
}
float wxWebViewWebKit::GetZoomFactor() const float wxWebViewWebKit::GetZoomFactor() const
{ {
return GetWebkitZoom(); return GetWebkitZoom();
} }
void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom)
{
// arbitrary way to map our common zoom enum to float zoom
switch (zoom)
{
case wxWEBVIEW_ZOOM_TINY:
SetWebkitZoom(0.6f);
break;
case wxWEBVIEW_ZOOM_SMALL:
SetWebkitZoom(0.8f);
break;
case wxWEBVIEW_ZOOM_MEDIUM:
SetWebkitZoom(1.0f);
break;
case wxWEBVIEW_ZOOM_LARGE:
SetWebkitZoom(1.3);
break;
case wxWEBVIEW_ZOOM_LARGEST:
SetWebkitZoom(1.6);
break;
default:
wxFAIL;
}
}
void wxWebViewWebKit::SetZoomFactor(float zoom) void wxWebViewWebKit::SetZoomFactor(float zoom)
{ {
SetWebkitZoom(zoom); SetWebkitZoom(zoom);
@@ -975,7 +920,7 @@ wxString wxWebViewWebKit::GetPageText() const
wxConvUTF8); wxConvUTF8);
} }
bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) const
{ {
wxCHECK_MSG( m_web_view, false, wxCHECK_MSG( m_web_view, false,
wxS("wxWebView must be created before calling RunScript()") ); wxS("wxWebView must be created before calling RunScript()") );

View File

@@ -507,6 +507,16 @@ wxgtk_authorize_authenticated_peer_cb(GDBusAuthObserver *,
} // extern "C" } // extern "C"
//-----------------------------------------------------------------------------
// wxWebViewFactoryWebKit
//-----------------------------------------------------------------------------
wxVersionInfo wxWebViewFactoryWebKit::GetVersionInfo()
{
return wxVersionInfo("webkit2", webkit_get_major_version(),
webkit_get_minor_version(), webkit_get_micro_version());
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxWebViewWebKit // wxWebViewWebKit
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -899,65 +909,11 @@ wxString wxWebViewWebKit::GetPageSource() const
} }
wxWebViewZoom wxWebViewWebKit::GetZoom() const
{
float zoom = GetWebkitZoom();
// arbitrary way to map float zoom to our common zoom enum
if (zoom <= 0.65f)
{
return wxWEBVIEW_ZOOM_TINY;
}
if (zoom <= 0.90f)
{
return wxWEBVIEW_ZOOM_SMALL;
}
if (zoom <= 1.15f)
{
return wxWEBVIEW_ZOOM_MEDIUM;
}
if (zoom <= 1.45f)
{
return wxWEBVIEW_ZOOM_LARGE;
}
return wxWEBVIEW_ZOOM_LARGEST;
}
float wxWebViewWebKit::GetZoomFactor() const float wxWebViewWebKit::GetZoomFactor() const
{ {
return GetWebkitZoom(); return GetWebkitZoom();
} }
void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom)
{
// arbitrary way to map our common zoom enum to float zoom
switch (zoom)
{
case wxWEBVIEW_ZOOM_TINY:
SetWebkitZoom(0.6f);
break;
case wxWEBVIEW_ZOOM_SMALL:
SetWebkitZoom(0.8f);
break;
case wxWEBVIEW_ZOOM_MEDIUM:
SetWebkitZoom(1.0f);
break;
case wxWEBVIEW_ZOOM_LARGE:
SetWebkitZoom(1.3);
break;
case wxWEBVIEW_ZOOM_LARGEST:
SetWebkitZoom(1.6);
break;
default:
wxFAIL;
}
}
void wxWebViewWebKit::SetZoomFactor(float zoom) void wxWebViewWebKit::SetZoomFactor(float zoom)
{ {
SetWebkitZoom(zoom); SetWebkitZoom(zoom);
@@ -1174,7 +1130,7 @@ static void wxgtk_run_javascript_cb(GObject *,
} // extern "C" } // extern "C"
// Run the given script synchronously and return its result in output. // Run the given script synchronously and return its result in output.
bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output) bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output) const
{ {
GAsyncResult *result = NULL; GAsyncResult *result = NULL;
webkit_web_view_run_javascript(m_web_view, webkit_web_view_run_javascript(m_web_view,
@@ -1237,7 +1193,7 @@ bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output
return true; return true;
} }
bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) const
{ {
wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount); wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount);

View File

@@ -19,6 +19,7 @@
#include "wx/log.h" #include "wx/log.h"
#include "wx/stdpaths.h" #include "wx/stdpaths.h"
#include "wx/thread.h" #include "wx/thread.h"
#include "wx/tokenzr.h"
#include "wx/private/jsscriptwrapper.h" #include "wx/private/jsscriptwrapper.h"
#include "wx/private/json.h" #include "wx/private/json.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
@@ -52,6 +53,8 @@ CreateCoreWebView2EnvironmentWithOptions_t wxCreateCoreWebView2EnvironmentWithOp
GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2BrowserVersionString = NULL; GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2BrowserVersionString = NULL;
wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll; wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll;
wxString wxWebViewEdgeImpl::ms_browserExecutableDir;
wxString wxWebViewEdgeImpl::ms_version;
wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview): wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview):
m_ctrl(webview) m_ctrl(webview)
@@ -85,7 +88,7 @@ bool wxWebViewEdgeImpl::Create()
wxString userDataPath = wxStandardPaths::Get().GetUserLocalDataDir(); wxString userDataPath = wxStandardPaths::Get().GetUserLocalDataDir();
HRESULT hr = wxCreateCoreWebView2EnvironmentWithOptions( HRESULT hr = wxCreateCoreWebView2EnvironmentWithOptions(
nullptr, ms_browserExecutableDir.wc_str(),
userDataPath.wc_str(), userDataPath.wc_str(),
nullptr, nullptr,
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(this, Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(this,
@@ -127,12 +130,14 @@ bool wxWebViewEdgeImpl::Initialize()
// Check if a Edge browser can be found by the loader DLL // Check if a Edge browser can be found by the loader DLL
wxCoTaskMemPtr<wchar_t> versionStr; wxCoTaskMemPtr<wchar_t> versionStr;
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(NULL, &versionStr); HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(
ms_browserExecutableDir.wc_str(), &versionStr);
if (FAILED(hr) || !versionStr) if (FAILED(hr) || !versionStr)
{ {
wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr); wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr);
return false; return false;
} }
ms_version = versionStr;
ms_loaderDll.Attach(loaderDll.Detach()); ms_loaderDll.Attach(loaderDll.Detach());
@@ -503,20 +508,6 @@ void wxWebViewEdge::Reload(wxWebViewReloadFlags WXUNUSED(flags))
m_impl->m_webView->Reload(); m_impl->m_webView->Reload();
} }
wxString wxWebViewEdge::GetPageSource() const
{
wxString text;
const_cast<wxWebViewEdge*>(this)->RunScript("document.documentElement.outerHTML;", &text);
return text;
}
wxString wxWebViewEdge::GetPageText() const
{
wxString text;
const_cast<wxWebViewEdge*>(this)->RunScript("document.body.innerText;", &text);
return text;
}
bool wxWebViewEdge::IsBusy() const bool wxWebViewEdge::IsBusy() const
{ {
return m_impl->m_isBusy; return m_impl->m_isBusy;
@@ -560,21 +551,6 @@ void wxWebViewEdge::Print()
RunScript("window.print();"); RunScript("window.print();");
} }
wxWebViewZoom wxWebViewEdge::GetZoom() const
{
double old_zoom_factor = 0.0;
m_impl->m_webViewController->get_ZoomFactor(&old_zoom_factor);
if (old_zoom_factor > 1.7)
return wxWEBVIEW_ZOOM_LARGEST;
if (old_zoom_factor > 1.3)
return wxWEBVIEW_ZOOM_LARGE;
if (old_zoom_factor > 0.8)
return wxWEBVIEW_ZOOM_MEDIUM;
if (old_zoom_factor > 0.6)
return wxWEBVIEW_ZOOM_SMALL;
return wxWEBVIEW_ZOOM_TINY;
}
float wxWebViewEdge::GetZoomFactor() const float wxWebViewEdge::GetZoomFactor() const
{ {
double old_zoom_factor = 0.0; double old_zoom_factor = 0.0;
@@ -582,69 +558,11 @@ float wxWebViewEdge::GetZoomFactor() const
return old_zoom_factor; return old_zoom_factor;
} }
void wxWebViewEdge::SetZoom(wxWebViewZoom zoom)
{
double old_zoom_factor = 0.0;
m_impl->m_webViewController->get_ZoomFactor(&old_zoom_factor);
double zoom_factor = 1.0;
switch (zoom)
{
case wxWEBVIEW_ZOOM_LARGEST:
zoom_factor = 2.0;
break;
case wxWEBVIEW_ZOOM_LARGE:
zoom_factor = 1.5;
break;
case wxWEBVIEW_ZOOM_MEDIUM:
zoom_factor = 1.0;
break;
case wxWEBVIEW_ZOOM_SMALL:
zoom_factor = 0.75;
break;
case wxWEBVIEW_ZOOM_TINY:
zoom_factor = 0.5;
break;
default:
break;
}
SetZoomFactor(zoom_factor);
}
void wxWebViewEdge::SetZoomFactor(float zoom) void wxWebViewEdge::SetZoomFactor(float zoom)
{ {
m_impl->m_webViewController->put_ZoomFactor(zoom); m_impl->m_webViewController->put_ZoomFactor(zoom);
} }
bool wxWebViewEdge::CanCut() const
{
return QueryCommandEnabled("cut");
}
bool wxWebViewEdge::CanCopy() const
{
return QueryCommandEnabled("copy");
}
bool wxWebViewEdge::CanPaste() const
{
return QueryCommandEnabled("paste");
}
void wxWebViewEdge::Cut()
{
ExecCommand("cut");
}
void wxWebViewEdge::Copy()
{
ExecCommand("copy");
}
void wxWebViewEdge::Paste()
{
ExecCommand("paste");
}
bool wxWebViewEdge::CanUndo() const bool wxWebViewEdge::CanUndo() const
{ {
return QueryCommandEnabled("undo"); return QueryCommandEnabled("undo");
@@ -665,12 +583,6 @@ void wxWebViewEdge::Redo()
ExecCommand("redo"); ExecCommand("redo");
} }
long wxWebViewEdge::Find(const wxString& WXUNUSED(text), int WXUNUSED(flags))
{
// TODO: not implemented in SDK (could probably be implemented by script)
return -1;
}
//Editing functions //Editing functions
void wxWebViewEdge::SetEditable(bool WXUNUSED(enable)) void wxWebViewEdge::SetEditable(bool WXUNUSED(enable))
{ {
@@ -682,41 +594,6 @@ bool wxWebViewEdge::IsEditable() const
return false; return false;
} }
void wxWebViewEdge::SelectAll()
{
RunScript("window.getSelection().selectAllChildren(document);");
}
bool wxWebViewEdge::HasSelection() const
{
wxString rangeCountStr;
const_cast<wxWebViewEdge*>(this)->RunScript("window.getSelection().rangeCount;", &rangeCountStr);
return rangeCountStr != "0";
}
void wxWebViewEdge::DeleteSelection()
{
ExecCommand("delete");
}
wxString wxWebViewEdge::GetSelectedText() const
{
wxString selectedText;
const_cast<wxWebViewEdge*>(this)->RunScript("window.getSelection().toString();", &selectedText);
return selectedText;
}
wxString wxWebViewEdge::GetSelectedSource() const
{
// TODO: not implemented in SDK (could probably be implemented by script)
return wxString();
}
void wxWebViewEdge::ClearSelection()
{
RunScript("window.getSelection().empty();");
}
void wxWebViewEdge::EnableContextMenu(bool enable) void wxWebViewEdge::EnableContextMenu(bool enable)
{ {
wxCOMPtr<ICoreWebView2Settings> settings(m_impl->GetSettings()); wxCOMPtr<ICoreWebView2Settings> settings(m_impl->GetSettings());
@@ -769,20 +646,12 @@ void* wxWebViewEdge::GetNativeBackend() const
return m_impl->m_webView; return m_impl->m_webView;
} }
bool wxWebViewEdge::QueryCommandEnabled(const wxString& command) const void wxWebViewEdge::MSWSetBrowserExecutableDir(const wxString & path)
{ {
wxString resultStr; wxWebViewEdgeImpl::ms_browserExecutableDir = path;
const_cast<wxWebViewEdge*>(this)->RunScript(
wxString::Format("function f(){ return document.queryCommandEnabled('%s'); } f();", command), &resultStr);
return resultStr.IsSameAs("true", false);
} }
void wxWebViewEdge::ExecCommand(const wxString& command) bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output) const
{
RunScript(wxString::Format("document.execCommand('%s');", command));
}
bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output)
{ {
bool scriptExecuted = false; bool scriptExecuted = false;
@@ -818,7 +687,7 @@ bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output)
return true; return true;
} }
bool wxWebViewEdge::RunScript(const wxString& javascript, wxString* output) bool wxWebViewEdge::RunScript(const wxString& javascript, wxString* output) const
{ {
wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount); wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount);
@@ -869,6 +738,22 @@ bool wxWebViewFactoryEdge::IsAvailable()
return wxWebViewEdgeImpl::Initialize(); return wxWebViewEdgeImpl::Initialize();
} }
wxVersionInfo wxWebViewFactoryEdge::GetVersionInfo()
{
IsAvailable(); // Make sure ms_version string is initialized (if available)
long major = 0,
minor = 0,
micro = 0;
wxStringTokenizer tk(wxWebViewEdgeImpl::ms_version, ". ");
// Ignore the return value because if the version component is missing
// or invalid (i.e. non-numeric), the only thing we can do is to ignore
// it anyhow.
tk.GetNextToken().ToLong(&major);
tk.GetNextToken().ToLong(&minor);
tk.GetNextToken().ToLong(&micro);
return wxVersionInfo("Microsoft Edge WebView2", major, minor, micro);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Module ensuring all global/singleton objects are destroyed on shutdown. // Module ensuring all global/singleton objects are destroyed on shutdown.

View File

@@ -19,6 +19,7 @@
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/dynlib.h" #include "wx/dynlib.h"
#include "wx/scopeguard.h" #include "wx/scopeguard.h"
#include "wx/tokenzr.h"
#include "wx/msw/missing.h" #include "wx/msw/missing.h"
#include "wx/msw/private.h" #include "wx/msw/private.h"
@@ -51,6 +52,25 @@ enum //Internal find flags
} }
// wxWebViewFactoryIE
wxVersionInfo wxWebViewFactoryIE::GetVersionInfo()
{
wxRegKey key(wxRegKey::HKLM, "Software\\Microsoft\\Internet Explorer");
wxString value;
key.QueryValue("Version", value);
long major = 0,
minor = 0,
micro = 0;
wxStringTokenizer tk(value, ". ");
// Ignore the return value because if the version component is missing
// or invalid (i.e. non-numeric), the only thing we can do is to ignore
// it anyhow.
tk.GetNextToken().ToLong(&major);
tk.GetNextToken().ToLong(&minor);
tk.GetNextToken().ToLong(&micro);
return wxVersionInfo("Internet Explorer", major, minor, micro);
}
//Convenience function for error conversion //Convenience function for error conversion
#define WX_ERROR_CASE(error, wxerror) \ #define WX_ERROR_CASE(error, wxerror) \
case error: \ case error: \
@@ -1009,7 +1029,7 @@ bool CallEval(const wxString& code,
return scriptAO.Invoke("eval", DISPATCH_METHOD, *varResult, 1, &varCode); return scriptAO.Invoke("eval", DISPATCH_METHOD, *varResult, 1, &varCode);
} }
bool wxWebViewIE::RunScript(const wxString& javascript, wxString* output) bool wxWebViewIE::RunScript(const wxString& javascript, wxString* output) const
{ {
wxCOMPtr<IHTMLDocument2> document(m_impl->GetDocument()); wxCOMPtr<IHTMLDocument2> document(m_impl->GetDocument());
if ( !document ) if ( !document )

View File

@@ -222,13 +222,6 @@ void wxWebViewWebKit::Stop()
[m_webView stopLoading]; [m_webView stopLoading];
} }
wxString wxWebViewWebKit::GetPageSource() const
{
wxString text;
const_cast<wxWebViewWebKit*>(this)->RunScript("document.documentElement.outerHTML;", &text);
return text;
}
void wxWebViewWebKit::Print() void wxWebViewWebKit::Print()
{ {
@@ -309,14 +302,7 @@ bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType type) const
} }
} }
wxString wxWebViewWebKit::GetSelectedText() const bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output) const
{
wxString text;
const_cast<wxWebViewWebKit*>(this)->RunScript("window.getSelection().toString();", &text);
return text;
}
bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output)
{ {
__block bool scriptExecuted = false; __block bool scriptExecuted = false;
__block wxString outputStr; __block wxString outputStr;
@@ -359,7 +345,7 @@ bool wxWebViewWebKit::RunScriptSync(const wxString& javascript, wxString* output
return scriptSuccess; return scriptSuccess;
} }
bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) bool wxWebViewWebKit::RunScript(const wxString& javascript, wxString* output) const
{ {
wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount); wxJSScriptWrapper wrapJS(javascript, &m_runScriptCount);
@@ -404,72 +390,11 @@ wxString wxWebViewWebKit::GetCurrentTitle() const
return wxCFStringRef::AsString(m_webView.title); return wxCFStringRef::AsString(m_webView.title);
} }
wxWebViewZoom wxWebViewWebKit::GetZoom() const
{
float zoom = GetZoomFactor();
// arbitrary way to map float zoom to our common zoom enum
if (zoom <= 0.55)
{
return wxWEBVIEW_ZOOM_TINY;
}
else if (zoom > 0.55 && zoom <= 0.85)
{
return wxWEBVIEW_ZOOM_SMALL;
}
else if (zoom > 0.85 && zoom <= 1.15)
{
return wxWEBVIEW_ZOOM_MEDIUM;
}
else if (zoom > 1.15 && zoom <= 1.45)
{
return wxWEBVIEW_ZOOM_LARGE;
}
else if (zoom > 1.45)
{
return wxWEBVIEW_ZOOM_LARGEST;
}
// to shut up compilers, this can never be reached logically
wxASSERT(false);
return wxWEBVIEW_ZOOM_MEDIUM;
}
float wxWebViewWebKit::GetZoomFactor() const float wxWebViewWebKit::GetZoomFactor() const
{ {
return m_webView.magnification; return m_webView.magnification;
} }
void wxWebViewWebKit::SetZoom(wxWebViewZoom zoom)
{
// arbitrary way to map our common zoom enum to float zoom
switch (zoom)
{
case wxWEBVIEW_ZOOM_TINY:
SetZoomFactor(0.4f);
break;
case wxWEBVIEW_ZOOM_SMALL:
SetZoomFactor(0.7f);
break;
case wxWEBVIEW_ZOOM_MEDIUM:
SetZoomFactor(1.0f);
break;
case wxWEBVIEW_ZOOM_LARGE:
SetZoomFactor(1.3);
break;
case wxWEBVIEW_ZOOM_LARGEST:
SetZoomFactor(1.6);
break;
default:
wxASSERT(false);
}
}
void wxWebViewWebKit::SetZoomFactor(float zoom) void wxWebViewWebKit::SetZoomFactor(float zoom)
{ {
m_webView.magnification = zoom; m_webView.magnification = zoom;
@@ -485,57 +410,6 @@ void wxWebViewWebKit::DoSetPage(const wxString& src, const wxString& baseUrl)
wxCFStringRef( baseUrl ).AsNSString()]]; wxCFStringRef( baseUrl ).AsNSString()]];
} }
void wxWebViewWebKit::Cut()
{
ExecCommand("cut");
}
void wxWebViewWebKit::Copy()
{
ExecCommand("copy");
}
void wxWebViewWebKit::Paste()
{
ExecCommand("paste");
}
void wxWebViewWebKit::DeleteSelection()
{
ExecCommand("delete");
}
bool wxWebViewWebKit::HasSelection() const
{
wxString rangeCountStr;
const_cast<wxWebViewWebKit*>(this)->RunScript("window.getSelection().rangeCount;", &rangeCountStr);
return rangeCountStr != "0";
}
void wxWebViewWebKit::ClearSelection()
{
//We use javascript as selection isn't exposed at the moment in webkit
RunScript("window.getSelection().removeAllRanges();");
}
void wxWebViewWebKit::SelectAll()
{
RunScript("window.getSelection().selectAllChildren(document.body);");
}
wxString wxWebViewWebKit::GetSelectedSource() const
{
// TODO: not implemented in SDK (could probably be implemented by script)
return wxString();
}
wxString wxWebViewWebKit::GetPageText() const
{
wxString text;
const_cast<wxWebViewWebKit*>(this)->RunScript("document.body.innerText;", &text);
return text;
}
void wxWebViewWebKit::EnableHistory(bool enable) void wxWebViewWebKit::EnableHistory(bool enable)
{ {
if ( !m_webView ) if ( !m_webView )
@@ -615,19 +489,6 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
m_handlers[handler->GetName()] = handler; m_handlers[handler->GetName()] = handler;
} }
bool wxWebViewWebKit::QueryCommandEnabled(const wxString& command) const
{
wxString resultStr;
const_cast<wxWebViewWebKit*>(this)->RunScript(
wxString::Format("function f(){ return document.queryCommandEnabled('%s'); } f();", command), &resultStr);
return resultStr.IsSameAs("true", false);
}
void wxWebViewWebKit::ExecCommand(const wxString& command)
{
RunScript(wxString::Format("document.execCommand('%s');", command));
}
//------------------------------------------------------------ //------------------------------------------------------------
// Listener interfaces // Listener interfaces
//------------------------------------------------------------ //------------------------------------------------------------

View File

@@ -174,7 +174,7 @@ TEST_CASE_METHOD(WebViewTestCase, "WebView", "[wxWebView]")
CHECK(m_browser->GetBackwardHistory().size() == 2); CHECK(m_browser->GetBackwardHistory().size() == 2);
} }
#if !defined(__WXOSX__) #if !defined(__WXOSX__) && (!defined(wxUSE_WEBVIEW_EDGE) || !wxUSE_WEBVIEW_EDGE)
SECTION("Editable") SECTION("Editable")
{ {
CHECK(!m_browser->IsEditable()); CHECK(!m_browser->IsEditable());
@@ -209,7 +209,7 @@ TEST_CASE_METHOD(WebViewTestCase, "WebView", "[wxWebView]")
CHECK(m_browser->HasSelection()); CHECK(m_browser->HasSelection());
CHECK(m_browser->GetSelectedText() == "Some strong text"); CHECK(m_browser->GetSelectedText() == "Some strong text");
#if !defined(__WXOSX__) #if !defined(__WXOSX__) && (!defined(wxUSE_WEBVIEW_EDGE) || !wxUSE_WEBVIEW_EDGE)
// The web engine doesn't necessarily represent the HTML in the same way as // The web engine doesn't necessarily represent the HTML in the same way as
// we used above, e.g. IE uses upper case for all the tags while WebKit // we used above, e.g. IE uses upper case for all the tags while WebKit
// under OS X inserts plenty of its own <span> tags, so don't test for // under OS X inserts plenty of its own <span> tags, so don't test for
@@ -258,7 +258,7 @@ TEST_CASE_METHOD(WebViewTestCase, "WebView", "[wxWebView]")
ENSURE_LOADED; ENSURE_LOADED;
wxString result; wxString result;
#if wxUSE_WEBVIEW_IE #if wxUSE_WEBVIEW_IE && !wxUSE_WEBVIEW_EDGE
CHECK(wxWebViewIE::MSWSetModernEmulationLevel()); CHECK(wxWebViewIE::MSWSetModernEmulationLevel());
// Define a specialized scope guard ensuring that we reset the emulation // Define a specialized scope guard ensuring that we reset the emulation