Move common wxWebView code to base class

Removes duplicate code in the various webview backends
This commit is contained in:
Tobias Taschner
2021-02-04 14:49:26 +01:00
parent 0d82348328
commit b351e7762d
10 changed files with 200 additions and 485 deletions

View File

@@ -82,9 +82,7 @@ public:
void SetZoomType(wxWebViewZoomType) wxOVERRIDE;
wxWebViewZoomType GetZoomType() const wxOVERRIDE;
bool CanSetZoomType(wxWebViewZoomType) const wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom) wxOVERRIDE;
virtual void SetZoomFactor(float) wxOVERRIDE;
//Clipboard functions

View File

@@ -60,9 +60,6 @@ public:
virtual void Stop() 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 wxString GetCurrentURL() const wxOVERRIDE;
virtual wxString GetCurrentTitle() const wxOVERRIDE;
@@ -73,49 +70,25 @@ public:
virtual void Print() wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom 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
virtual bool CanUndo() const wxOVERRIDE;
virtual bool CanRedo() const wxOVERRIDE;
virtual void Undo() wxOVERRIDE;
virtual void Redo() wxOVERRIDE;
//Find function
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) wxOVERRIDE;
//Editing functions
virtual void SetEditable(bool enable = true) 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 bool IsContextMenuEnabled() const wxOVERRIDE;
virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE;
virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE;
bool QueryCommandEnabled(const wxString& command) const;
void ExecCommand(const wxString& command);
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) wxOVERRIDE;
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE;

View File

@@ -56,17 +56,13 @@ public:
virtual void GoForward() wxOVERRIDE;
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE;
virtual void Stop() wxOVERRIDE;
virtual wxString GetPageSource() const wxOVERRIDE;
virtual wxString GetPageText() const wxOVERRIDE;
virtual void Print() wxOVERRIDE;
virtual void LoadURL(const wxString& url) wxOVERRIDE;
virtual wxString GetCurrentURL() const wxOVERRIDE;
virtual wxString GetCurrentTitle() const wxOVERRIDE;
virtual wxWebViewZoom GetZoom() const wxOVERRIDE;
virtual float GetZoomFactor() const wxOVERRIDE;
virtual void SetZoom(wxWebViewZoom zoom) wxOVERRIDE;
virtual void SetZoomFactor(float zoom) wxOVERRIDE;
virtual void SetZoomType(wxWebViewZoomType zoomType) wxOVERRIDE;
@@ -88,34 +84,10 @@ public:
virtual void Undo() 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
virtual void SetEditable(bool enable = true) wxOVERRIDE;
virtual bool IsEditable() const wxOVERRIDE;
//Selection
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
@@ -136,8 +108,6 @@ private:
WX_NSObject m_UIDelegate;
bool RunScriptSync(const wxString& javascript, wxString* output = NULL);
bool QueryCommandEnabled(const wxString& command) const;
void ExecCommand(const wxString& command);
};
class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory

View File

@@ -171,8 +171,8 @@ public:
virtual wxString GetCurrentTitle() const = 0;
virtual wxString GetCurrentURL() const = 0;
// TODO: handle choosing a frame when calling GetPageSource()?
virtual wxString GetPageSource() const = 0;
virtual wxString GetPageText() const = 0;
virtual wxString GetPageSource() const;
virtual wxString GetPageText() const;
virtual bool IsBusy() const = 0;
virtual bool IsContextMenuEnabled() const { return m_showMenu; }
virtual bool IsAccessToDevToolsEnabled() const { return false; }
@@ -208,28 +208,28 @@ public:
//Zoom
virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
virtual wxWebViewZoom GetZoom() const = 0;
virtual wxWebViewZoom GetZoom() const;
virtual float GetZoomFactor() 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 SetZoomType(wxWebViewZoomType zoomType) = 0;
//Selection
virtual void SelectAll() = 0;
virtual bool HasSelection() const = 0;
virtual void DeleteSelection() = 0;
virtual wxString GetSelectedText() const = 0;
virtual wxString GetSelectedSource() const = 0;
virtual void ClearSelection() = 0;
virtual void SelectAll() ;
virtual bool HasSelection() const;
virtual void DeleteSelection();
virtual wxString GetSelectedText() const;
virtual wxString GetSelectedSource() const;
virtual void ClearSelection();
//Clipboard functions
virtual bool CanCut() const = 0;
virtual bool CanCopy() const = 0;
virtual bool CanPaste() const = 0;
virtual void Cut() = 0;
virtual void Copy() = 0;
virtual void Paste() = 0;
virtual bool CanCut() const;
virtual bool CanCopy() const;
virtual bool CanPaste() const;
virtual void Cut();
virtual void Copy();
virtual void Paste();
//Undo / redo functionality
virtual bool CanUndo() const = 0;
@@ -240,11 +240,14 @@ public:
//Get the pointer to the underlying native engine.
virtual void* GetNativeBackend() const = 0;
//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:
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
// the_same variable from being used twice in more than one call.
int m_runScriptCount;

View File

@@ -550,12 +550,12 @@ public:
@return The HTML source code, or an empty string if no page is currently
shown.
*/
virtual wxString GetPageSource() const = 0;
virtual wxString GetPageSource() const;
/**
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).
@@ -702,36 +702,36 @@ public:
@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.
@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.
@note This always returns @c true on the macOS WebKit backend.
*/
virtual bool CanPaste() const = 0;
virtual bool CanPaste() const;
/**
Copies the current selection.
*/
virtual void Copy() = 0;
virtual void Copy();
/**
Cuts the current selection.
*/
virtual void Cut() = 0;
virtual void Cut();
/**
Pastes the current data.
*/
virtual void Paste() = 0;
virtual void Paste();
/**
@name Context Menu
@@ -842,34 +842,34 @@ public:
/**
Clears the current selection.
*/
virtual void ClearSelection() = 0;
virtual void ClearSelection();
/**
Deletes the current selection. Note that for @c wxWEBVIEW_BACKEND_WEBKIT
the selection must be editable, either through SetEditable or the
correct HTML attribute.
*/
virtual void DeleteSelection() = 0;
virtual void DeleteSelection();
/**
Returns the currently selected source, if any.
*/
virtual wxString GetSelectedSource() const = 0;
virtual wxString GetSelectedSource() const;
/**
Returns the currently selected text, if any.
*/
virtual wxString GetSelectedText() const = 0;
virtual wxString GetSelectedText() const;
/**
Returns @true if there is a current selection.
*/
virtual bool HasSelection() const = 0;
virtual bool HasSelection() const;
/**
Selects the entire page.
*/
virtual void SelectAll() = 0;
virtual void SelectAll();
/**
@name Undo / Redo
@@ -917,7 +917,7 @@ public:
on the macOS WebKit backend.
@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
@@ -937,7 +937,7 @@ public:
as provided by @c wxWebViewZoom.
@return The current level of zoom.
*/
virtual wxWebViewZoom GetZoom() const = 0;
virtual wxWebViewZoom GetZoom() const;
/**
Get the zoom factor of the page.
@@ -958,7 +958,7 @@ public:
steps provided by @c wxWebViewZoom.
@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.

View File

@@ -51,6 +51,166 @@ wxDEFINE_EVENT( wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent );
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
wxASSERT(false);
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;
default:
wxASSERT(false);
}
}
bool wxWebView::QueryCommandEnabled(const wxString& command) const
{
wxString resultStr;
const_cast<wxWebView*>(this)->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;
const_cast<wxWebView*>(this)->RunScript("document.documentElement.outerHTML;", &text);
return text;
}
wxString wxWebView::GetPageText() const
{
wxString text;
const_cast<wxWebView*>(this)->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;
const_cast<wxWebView*>(this)->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;
const_cast<wxWebView*>(this)->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
wxWebView* wxWebView::New(const wxString& backend)
{
@@ -103,7 +263,7 @@ wxVersionInfo wxWebView::GetBackendVersionInfo(const wxString& backend)
return wxVersionInfo();
}
// static
// static
wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend)
{
// Initialise the map, it checks internally for existing factories

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
{
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)
{
SetWebkitZoom(zoom);

View File

@@ -909,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
{
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)
{
SetWebkitZoom(zoom);

View File

@@ -508,20 +508,6 @@ void wxWebViewEdge::Reload(wxWebViewReloadFlags WXUNUSED(flags))
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
{
return m_impl->m_isBusy;
@@ -565,21 +551,6 @@ void wxWebViewEdge::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
{
double old_zoom_factor = 0.0;
@@ -587,69 +558,11 @@ float wxWebViewEdge::GetZoomFactor() const
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)
{
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
{
return QueryCommandEnabled("undo");
@@ -670,12 +583,6 @@ void wxWebViewEdge::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
void wxWebViewEdge::SetEditable(bool WXUNUSED(enable))
{
@@ -687,41 +594,6 @@ bool wxWebViewEdge::IsEditable() const
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)
{
wxCOMPtr<ICoreWebView2Settings> settings(m_impl->GetSettings());
@@ -774,22 +646,9 @@ void* wxWebViewEdge::GetNativeBackend() const
return m_impl->m_webView;
}
bool wxWebViewEdge::QueryCommandEnabled(const wxString& command) const
void wxWebViewEdge::MSWSetBrowserExecutableDir(const wxString & path)
{
wxString resultStr;
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)
{
RunScript(wxString::Format("document.execCommand('%s');", command));
}
void wxWebViewEdge::MSWSetBrowserExecutableDir(const wxString & path)
{
wxWebViewEdgeImpl::ms_browserExecutableDir = path;
wxWebViewEdgeImpl::ms_browserExecutableDir = path;
}
bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output)

View File

@@ -222,13 +222,6 @@ void wxWebViewWebKit::Stop()
[m_webView stopLoading];
}
wxString wxWebViewWebKit::GetPageSource() const
{
wxString text;
const_cast<wxWebViewWebKit*>(this)->RunScript("document.documentElement.outerHTML;", &text);
return text;
}
void wxWebViewWebKit::Print()
{
@@ -309,13 +302,6 @@ bool wxWebViewWebKit::CanSetZoomType(wxWebViewZoomType type) const
}
}
wxString wxWebViewWebKit::GetSelectedText() 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;
@@ -404,72 +390,11 @@ wxString wxWebViewWebKit::GetCurrentTitle() const
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
{
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)
{
m_webView.magnification = zoom;
@@ -485,57 +410,6 @@ void wxWebViewWebKit::DoSetPage(const wxString& src, const wxString& baseUrl)
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)
{
if ( !m_webView )
@@ -615,19 +489,6 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> 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
//------------------------------------------------------------