Merge the new wxWebView classes from the SOC2011_WEBVIEW branch.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69049 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2011-09-10 18:09:12 +00:00
54 changed files with 11232 additions and 11 deletions

View File

@@ -102,6 +102,7 @@
# define WXMAKINGDLL_RICHTEXT
# define WXMAKINGDLL_MEDIA
# define WXMAKINGDLL_STC
# define WXMAKINGDLL_WEBVIEW
#endif /* WXMAKINGDLL */
/*
@@ -274,6 +275,17 @@
# define WXDLLIMPEXP_DATA_STC(type) type
#endif
#ifdef WXMAKINGDLL_WEBVIEW
# define WXDLLIMPEXP_WEBVIEW WXEXPORT
# define WXDLLIMPEXP_DATA_WEBVIEW(type) WXEXPORT type
#elif defined(WXUSINGDLL)
# define WXDLLIMPEXP_WEBVIEW WXIMPORT
# define WXDLLIMPEXP_DATA_WEBVIEW(type) WXIMPORT type
#else /* not making nor using DLL */
# define WXDLLIMPEXP_WEBVIEW
# define WXDLLIMPEXP_DATA_WEBVIEW(type) type
#endif
/*
GCC warns about using __attribute__ (and also __declspec in mingw32 case) on
forward declarations while MSVC complains about forward declarations without
@@ -295,6 +307,7 @@
#define WXDLLIMPEXP_FWD_RICHTEXT
#define WXDLLIMPEXP_FWD_MEDIA
#define WXDLLIMPEXP_FWD_STC
#define WXDLLIMPEXP_FWD_WEBVIEW
#else
#define WXDLLIMPEXP_FWD_BASE WXDLLIMPEXP_BASE
#define WXDLLIMPEXP_FWD_NET WXDLLIMPEXP_NET
@@ -310,6 +323,7 @@
#define WXDLLIMPEXP_FWD_RICHTEXT WXDLLIMPEXP_RICHTEXT
#define WXDLLIMPEXP_FWD_MEDIA WXDLLIMPEXP_MEDIA
#define WXDLLIMPEXP_FWD_STC WXDLLIMPEXP_STC
#define WXDLLIMPEXP_FWD_WEBVIEW WXDLLIMPEXP_WEBVIEW
#endif
/* for backwards compatibility, define suffix-less versions too */

View File

@@ -0,0 +1,159 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/gtk/wx/webview.h
// Purpose: GTK webkit backend for web view component
// Author: Robert Roebling, Marianne Gagnon
// Id: $Id$
// Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_WEBKITCTRL_H_
#define _WX_GTK_WEBKITCTRL_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
#include "webkit/webkit.h"
#include "wx/sharedptr.h"
#include "wx/webview.h"
//-----------------------------------------------------------------------------
// wxWebViewWebKit
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
{
public:
wxWebViewWebKit() { Init(); }
wxWebViewWebKit(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxWebViewNameStr)
{
Init();
Create(parent, id, url, pos, size, style, name);
}
virtual bool Create(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxWebViewNameStr);
virtual bool Enable( bool enable = true );
// implementation
// --------------
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
virtual void Stop();
virtual void LoadURL(const wxString& url);
virtual void GoBack();
virtual void GoForward();
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
virtual bool CanGoBack() const;
virtual bool CanGoForward() const;
virtual void ClearHistory();
virtual void EnableHistory(bool enable = true);
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
virtual wxString GetCurrentURL() const;
virtual wxString GetCurrentTitle() const;
virtual wxString GetPageSource() const;
virtual wxString GetPageText() const;
//We do not want to hide the other overloads
using wxWebView::SetPage;
virtual void SetPage(const wxString& html, const wxString& baseUrl);
virtual void Print();
virtual bool IsBusy() const;
void SetZoomType(wxWebViewZoomType);
wxWebViewZoomType GetZoomType() const;
bool CanSetZoomType(wxWebViewZoomType) const;
virtual wxWebViewZoom GetZoom() const;
virtual void SetZoom(wxWebViewZoom);
//Clipboard functions
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;
virtual bool CanRedo() const;
virtual void Undo();
virtual void Redo();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable() const;
//Selection
virtual void DeleteSelection();
virtual bool HasSelection() const;
virtual void SelectAll();
virtual wxString GetSelectedText() const;
virtual wxString GetSelectedSource() const;
virtual void ClearSelection();
virtual void RunScript(const wxString& javascript);
//Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; }
/** FIXME: hack to work around signals being received too early */
bool m_ready;
/** TODO: check if this can be made private
* The native control has a getter to check for busy state, but except in
* very recent versions of webkit this getter doesn't say everything we need
* (namely it seems to stay indefinitely busy when loading is cancelled by
* user)
*/
bool m_busy;
wxString m_vfsurl;
//We use this flag to stop recursion when we load a page from the navigation
//callback, mainly when loading a VFS page
bool m_guard;
protected:
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
private:
void ZoomIn();
void ZoomOut();
void SetWebkitZoom(float level);
float GetWebkitZoom() const;
// focus event handler: calls GTKUpdateBitmap()
void GTKOnFocus(wxFocusEvent& event);
GtkWidget *web_view;
gint m_historyLimit;
wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;
wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
};
#endif // wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
#endif

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/gtk/webviewhistoryitem.h
// Purpose: wxWebViewHistoryItem header for GTK
// Author: Steven Lamerton
// Id: $Id$
// Copyright: (c) 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_WEBVIEWHISTORYITEM_H_
#define _WX_GTK_WEBVIEWHISTORYITEM_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
#include "webkit/webkit.h"
class WXDLLIMPEXP_WEBVIEW wxWebViewHistoryItem
{
public:
wxWebViewHistoryItem(const wxString& url, const wxString& title) :
m_url(url), m_title(title) {}
wxString GetUrl() { return m_url; }
wxString GetTitle() { return m_title; }
friend class wxWebViewWebKit;
private:
wxString m_url, m_title;
WebKitWebHistoryItem* m_histItem;
};
#endif // wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
#endif // _WX_GTK_WEBVIEWHISTORYITEM_H_

View File

@@ -408,6 +408,14 @@
# define wxUSE_MEDIACTRL 0
# endif
# endif
# if wxUSE_WEB
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxWebView requires wxActiveXContainer under MSW"
# else
# undef wxUSE_WEB
# define wxUSE_WEB 0
# endif
# endif
#endif /* !wxUSE_ACTIVEX */
#if !wxUSE_THREADS
@@ -421,6 +429,18 @@
# endif
#endif /* !wxUSE_THREADS */
#if !wxUSE_OLE_AUTOMATION
# if wxUSE_WEB
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxWebView requires wxUSE_OLE_AUTOMATION under MSW"
# else
# undef wxUSE_WEB
# define wxUSE_WEB 0
# endif
# endif
#endif /* !wxUSE_OLE_AUTOMATION */
#if defined(__WXUNIVERSAL__) && wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW && !wxUSE_POSTSCRIPT
# undef wxUSE_POSTSCRIPT
# define wxUSE_POSTSCRIPT 1

View File

@@ -514,6 +514,77 @@ typedef struct
#endif
#endif
// Various definitions are missing from mingw
// Used by webview_ie.cpp
#ifdef __MINGW32__
typedef enum CommandStateChangeConstants {
CSC_UPDATECOMMANDS = (int) 0xFFFFFFFF,
CSC_NAVIGATEFORWARD = 0x1,
CSC_NAVIGATEBACK = 0x2
} CommandStateChangeConstants;
#define DISPID_COMMANDSTATECHANGE 105
#define DISPID_NAVIGATECOMPLETE2 252
#define DISPID_NAVIGATEERROR 271
#define DISPID_NEWWINDOW3 273
#define INET_E_ERROR_FIRST 0x800C0002L
#define INET_E_INVALID_URL 0x800C0002L
#define INET_E_NO_SESSION 0x800C0003L
#define INET_E_CANNOT_CONNECT 0x800C0004L
#define INET_E_RESOURCE_NOT_FOUND 0x800C0005L
#define INET_E_OBJECT_NOT_FOUND 0x800C0006L
#define INET_E_DATA_NOT_AVAILABLE 0x800C0007L
#define INET_E_DOWNLOAD_FAILURE 0x800C0008L
#define INET_E_AUTHENTICATION_REQUIRED 0x800C0009L
#define INET_E_NO_VALID_MEDIA 0x800C000AL
#define INET_E_CONNECTION_TIMEOUT 0x800C000BL
#define INET_E_INVALID_REQUEST 0x800C000CL
#define INET_E_UNKNOWN_PROTOCOL 0x800C000DL
#define INET_E_SECURITY_PROBLEM 0x800C000EL
#define INET_E_CANNOT_LOAD_DATA 0x800C000FL
#define INET_E_CANNOT_INSTANTIATE_OBJECT 0x800C0010L
#define INET_E_QUERYOPTION_UNKNOWN 0x800C0013L
#define INET_E_REDIRECT_FAILED 0x800C0014L
#define INET_E_REDIRECT_TO_DIR 0x800C0015L
#define INET_E_CANNOT_LOCK_REQUEST 0x800C0016L
#define INET_E_USE_EXTEND_BINDING 0x800C0017L
#define INET_E_TERMINATED_BIND 0x800C0018L
#define INET_E_INVALID_CERTIFICATE 0x800C0019L
#define INET_E_CODE_DOWNLOAD_DECLINED 0x800C0100L
#define INET_E_RESULT_DISPATCHED 0x800C0200L
#define INET_E_CANNOT_REPLACE_SFP_FILE 0x800C0300L
#define INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY 0x800C0500L
#define INET_E_CODE_INSTALL_SUPPRESSED 0x800C0400L
#define REFRESH_NORMAL 0
#define REFRESH_COMPLETELY 3
#endif
// For Visual C++ 6 and MinGW32. Used by webview_ie.cpp
#if defined (__MINGW32__) || (_MSC_VER < 1300)
enum
{
OLECMDID_OPTICAL_ZOOM = 63
};
#endif
#ifndef INET_E_INVALID_CERTIFICATE
#define INET_E_INVALID_CERTIFICATE 0x800C0019L
#endif
#ifndef INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY
#define INET_E_CODE_INSTALL_BLOCKED_BY_HASH_POLICY 0x800C0500L
#endif
#ifndef INET_E_CODE_INSTALL_SUPPRESSED
#define INET_E_CODE_INSTALL_SUPPRESSED 0x800C0400L
#endif
#ifndef DISPID_NEWWINDOW3
#define DISPID_NEWWINDOW3 273
#endif
/*

View File

@@ -705,6 +705,24 @@
// Recommended setting: 1
#define wxUSE_STC 1
// Use wxWidget's web viewing classes
//
// Default is 1
//
// Recommended setting: 1
#define wxUSE_WEBVIEW 1
// Use the IE wxWebView backend
//
// Default is 1 on MSW
//
// Recommended setting: 1
#ifdef __WXMSW__
#define wxUSE_WEBVIEW_IE 1
#else
#define wxUSE_WEBVIEW_IE 0
#endif
// Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
// 2D drawing API. (Still somewhat experimental)

230
include/wx/msw/webview_ie.h Normal file
View File

@@ -0,0 +1,230 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/msw/webviewie.h
// Purpose: wxMSW IE wxWebView backend
// Author: Marianne Gagnon
// Id: $Id$
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef wxWebViewIE_H
#define wxWebViewIE_H
#include "wx/setup.h"
#if wxUSE_WEBVIEW_IE && defined(__WXMSW__)
#include "wx/control.h"
#include "wx/webview.h"
#include "wx/msw/ole/automtn.h"
#include "wx/msw/ole/activex.h"
#include "wx/sharedptr.h"
#include "wx/vector.h"
struct IHTMLDocument2;
class wxFSFile;
class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
{
public:
wxWebViewIE() {}
wxWebViewIE(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxWebViewNameStr)
{
Create(parent, id, url, pos, size, style, name);
}
bool Create(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxWebViewNameStr);
virtual void LoadURL(const wxString& url);
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
virtual bool CanGoForward() const;
virtual bool CanGoBack() const;
virtual void GoBack();
virtual void GoForward();
virtual void ClearHistory();
virtual void EnableHistory(bool enable = true);
virtual void Stop();
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
virtual wxString GetPageSource() const;
virtual wxString GetPageText() const;
virtual bool IsBusy() const;
virtual wxString GetCurrentURL() const;
virtual wxString GetCurrentTitle() const;
virtual void SetZoomType(wxWebViewZoomType);
virtual wxWebViewZoomType GetZoomType() const;
virtual bool CanSetZoomType(wxWebViewZoomType) const;
virtual void Print();
virtual void SetPage(const wxString& html, const wxString& baseUrl);
virtual wxWebViewZoom GetZoom() const;
virtual void SetZoom(wxWebViewZoom zoom);
//Clipboard functions
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;
virtual bool CanRedo() const;
virtual void Undo();
virtual void Redo();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable() const;
//Selection
virtual void SelectAll();
virtual bool HasSelection() const;
virtual void DeleteSelection();
virtual wxString GetSelectedText() const;
virtual wxString GetSelectedSource() const;
virtual void ClearSelection();
virtual void RunScript(const wxString& javascript);
//Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
// ---- IE-specific methods
// FIXME: I seem to be able to access remote webpages even in offline mode...
bool IsOfflineMode();
void SetOfflineMode(bool offline);
wxWebViewZoom GetIETextZoom() const;
void SetIETextZoom(wxWebViewZoom level);
wxWebViewZoom GetIEOpticalZoom() const;
void SetIEOpticalZoom(wxWebViewZoom level);
void onActiveXEvent(wxActiveXEvent& evt);
void onEraseBg(wxEraseEvent&) {}
DECLARE_EVENT_TABLE();
private:
wxActiveXContainer* m_container;
wxAutomationObject m_ie;
IWebBrowser2* m_webBrowser;
DWORD m_dwCookie;
//We store the current zoom type;
wxWebViewZoomType m_zoomType;
/** The "Busy" property of IWebBrowser2 does not always return busy when
* we'd want it to; this variable may be set to true in cases where the
* Busy property is false but should be true.
*/
bool m_isBusy;
//We manage our own history, the history list contains the history items
//which are added as documentcomplete events arrive, unless we are loading
//an item from the history. The position is stored as an int, and reflects
//where we are in the history list.
wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
int m_historyPosition;
bool m_historyLoadingFromList;
bool m_historyEnabled;
//Generic helper functions for IHtmlDocument commands
bool CanExecCommand(wxString command) const;
void ExecCommand(wxString command);
IHTMLDocument2* GetDocument() const;
wxDECLARE_DYNAMIC_CLASS(wxWebViewIE);
};
class VirtualProtocol : public IInternetProtocol
{
protected:
ULONG m_refCount;
IInternetProtocolSink* m_protocolSink;
wxString m_html;
VOID * fileP;
wxFSFile* m_file;
wxSharedPtr<wxWebViewHandler> m_handler;
public:
VirtualProtocol(wxSharedPtr<wxWebViewHandler> handler);
~VirtualProtocol();
//IUnknown
ULONG STDMETHODCALLTYPE AddRef();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
ULONG STDMETHODCALLTYPE Release();
//IInternetProtocolRoot
HRESULT STDMETHODCALLTYPE Abort(HRESULT WXUNUSED(hrReason),
DWORD WXUNUSED(dwOptions))
{ return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE Continue(PROTOCOLDATA *WXUNUSED(pProtocolData))
{ return S_OK; }
HRESULT STDMETHODCALLTYPE Resume() { return S_OK; }
HRESULT STDMETHODCALLTYPE Start(LPCWSTR szUrl,
IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo,
DWORD grfPI,
HANDLE_PTR dwReserved);
HRESULT STDMETHODCALLTYPE Suspend() { return S_OK; }
HRESULT STDMETHODCALLTYPE Terminate(DWORD WXUNUSED(dwOptions)) { return S_OK; }
//IInternetProtocol
HRESULT STDMETHODCALLTYPE LockRequest(DWORD WXUNUSED(dwOptions))
{ return S_OK; }
HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER WXUNUSED(dlibMove),
DWORD WXUNUSED(dwOrigin),
ULARGE_INTEGER* WXUNUSED(plibNewPosition))
{ return E_FAIL; }
HRESULT STDMETHODCALLTYPE UnlockRequest() { return S_OK; }
};
class ClassFactory : public IClassFactory
{
private:
ULONG m_refCount;
public:
ClassFactory(wxSharedPtr<wxWebViewHandler> handler) : m_handler(handler) {}
//IUnknown
ULONG STDMETHODCALLTYPE AddRef();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
ULONG STDMETHODCALLTYPE Release();
//IClassFactory
HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
REFIID riid, void** ppvObject);
HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
private:
wxSharedPtr<wxWebViewHandler> m_handler;
};
#endif // wxUSE_WEBVIEW_IE && defined(__WXMSW__)
#endif // wxWebViewIE_H

View File

@@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/msw/webviewhistoryitem.h
// Purpose: wxWebViewHistoryItem header for MSW
// Author: Steven Lamerton
// Id: $Id$
// Copyright: (c) 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_WEBVIEWHISTORYITEM_H_
#define _WX_MSW_WEBVIEWHISTORYITEM_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW_IE && defined(__WXMSW__)
class WXDLLIMPEXP_WEBVIEW wxWebViewHistoryItem
{
public:
wxWebViewHistoryItem(const wxString& url, const wxString& title) :
m_url(url), m_title(title) {}
wxString GetUrl() { return m_url; }
wxString GetTitle() { return m_title; }
private:
wxString m_url, m_title;
};
#endif // wxUSE_WEBVIEW_IE && defined(__WXMSW__)
#endif // _WX_MSW_WEBVIEWHISTORYITEM_H_

View File

@@ -0,0 +1,163 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/osx/webkit.h
// Purpose: wxWebViewWebKit - embeddable web kit control,
// OS X implementation of web view component
// Author: Jethro Grassie / Kevin Ollivier / Marianne Gagnon
// Modified by:
// Created: 2004-4-16
// RCS-ID: $Id$
// Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEBKIT_H
#define _WX_WEBKIT_H
#include "wx/setup.h"
#if wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
|| defined(__WXOSX_CARBON__))
#include "wx/control.h"
#include "wx/webview.h"
// ----------------------------------------------------------------------------
// Web Kit Control
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
{
public:
wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
wxWebViewWebKit() {}
wxWebViewWebKit(wxWindow *parent,
wxWindowID winID = wxID_ANY,
const wxString& strURL = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxWebViewNameStr)
{
Create(parent, winID, strURL, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID winID = wxID_ANY,
const wxString& strURL = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0,
const wxString& name = wxWebViewNameStr);
virtual ~wxWebViewWebKit();
virtual bool CanGoBack() const;
virtual bool CanGoForward() const;
virtual void GoBack();
virtual void GoForward();
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
virtual void Stop();
virtual wxString GetPageSource() const;
virtual wxString GetPageText() const;
//We do not want to hide the other overloads
using wxWebView::SetPage;
virtual void SetPage(const wxString& html, const wxString& baseUrl);
virtual void Print();
virtual void LoadURL(const wxString& url);
virtual wxString GetCurrentURL() const;
virtual wxString GetCurrentTitle() const;
virtual wxWebViewZoom GetZoom() const;
virtual void SetZoom(wxWebViewZoom zoom);
virtual void SetZoomType(wxWebViewZoomType zoomType);
virtual wxWebViewZoomType GetZoomType() const;
virtual bool CanSetZoomType(wxWebViewZoomType type) const;
virtual bool IsBusy() const { return m_busy; }
//History functions
virtual void ClearHistory();
virtual void EnableHistory(bool enable = true);
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
//Undo / redo functionality
virtual bool CanUndo() const;
virtual bool CanRedo() const;
virtual void Undo();
virtual void Redo();
//Clipboard functions
virtual bool CanCut() const { return true; }
virtual bool CanCopy() const { return true; }
virtual bool CanPaste() const { return true; }
virtual void Cut();
virtual void Copy();
virtual void Paste();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable() const;
//Selection
virtual void DeleteSelection();
virtual bool HasSelection() const;
virtual void SelectAll();
virtual wxString GetSelectedText() const;
virtual wxString GetSelectedSource() const;
virtual void ClearSelection();
void RunScript(const wxString& javascript);
//Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
// ---- methods not from the parent (common) interface
bool CanGetPageSource() const;
void SetScrollPos(int pos);
int GetScrollPos();
bool CanIncreaseTextSize() const;
void IncreaseTextSize();
bool CanDecreaseTextSize() const;
void DecreaseTextSize();
float GetWebkitZoom() const;
void SetWebkitZoom(float zoom);
// don't hide base class virtuals
virtual void SetScrollPos( int orient, int pos, bool refresh = true )
{ return wxControl::SetScrollPos(orient, pos, refresh); }
virtual int GetScrollPos( int orient ) const
{ return wxControl::GetScrollPos(orient); }
//we need to resize the webview when the control size changes
void OnSize(wxSizeEvent &event);
void OnMove(wxMoveEvent &event);
void OnMouseEvents(wxMouseEvent &event);
bool m_busy;
protected:
DECLARE_EVENT_TABLE()
void MacVisibilityChanged();
private:
wxWindow *m_parent;
wxWindowID m_windowID;
wxString m_pageTitle;
struct objc_object *m_webView;
// we may use this later to setup our own mouse events,
// so leave it in for now.
void* m_webKitCtrlEventHandler;
//It should be WebView*, but WebView is an Objective-C class
//TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
};
#endif // wxUSE_WEBKIT
#endif // _WX_WEBKIT_H_

View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/osx/webviewhistoryitem.h
// Purpose: wxWebViewHistoryItem header for OSX
// Author: Steven Lamerton
// Id: $Id$
// Copyright: (c) 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OSX_WEBVIEWHISTORYITEM_H_
#define _WX_OSX_WEBVIEWHISTORYITEM_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
|| defined(__WXOSX_CARBON__))
class WXDLLIMPEXP_WEBVIEW wxWebViewHistoryItem
{
public:
wxWebViewHistoryItem(const wxString& url, const wxString& title) :
m_url(url), m_title(title) {}
wxString GetUrl() { return m_url; }
wxString GetTitle() { return m_title; }
friend class wxWebViewWebKit;
private:
wxString m_url, m_title;
struct objc_object *m_histItem;
};
#endif // wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX_MAC__)
#endif // _WX_OSX_WEBVIEWHISTORYITEM_H_

View File

@@ -701,6 +701,34 @@
// Recommended setting: 1
#define wxUSE_STC 1
// Use wxWidget's web viewing classes
//
// Default is 1
//
// Recommended setting: 1
#define wxUSE_WEBVIEW 1
// Use the IE wxWebView backend
//
// Default is 1 on MSW
//
// Recommended setting: 1
#ifdef __WXMSW__
#define wxUSE_WEBVIEW_IE 1
#else
#define wxUSE_WEBVIEW_IE 0
#endif
// Use the WebKit wxWebView backend
//
// Default is 1 on GTK and OSX
//
// Recommended setting: 1
#if defined(__WXGTK__) || defined(__WXOSX__)
#define wxUSE_WEBVIEW_WEBKIT 1
#else
#define wxUSE_WEBVIEW_WEBKIT 0
#endif
// Enable the new wxGraphicsPath and wxGraphicsContext classes for an advanced
// 2D drawing API. (Still somewhat experimental)

235
include/wx/webview.h Normal file
View File

@@ -0,0 +1,235 @@
/////////////////////////////////////////////////////////////////////////////
// Name: webview.h
// Purpose: Common interface and events for web view component
// Author: Marianne Gagnon
// Id: $Id$
// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEB_VIEW_H_
#define _WX_WEB_VIEW_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW
#include "wx/control.h"
#include "wx/event.h"
#include "wx/sstream.h"
#include "wx/sharedptr.h"
#include "wx/vector.h"
#include "wx/osx/webviewhistoryitem_webkit.h"
#include "wx/gtk/webviewhistoryitem_webkit.h"
#include "wx/msw/webviewhistoryitem_ie.h"
class wxFSFile;
class wxFileSystem;
enum wxWebViewZoom
{
wxWEB_VIEW_ZOOM_TINY,
wxWEB_VIEW_ZOOM_SMALL,
wxWEB_VIEW_ZOOM_MEDIUM,
wxWEB_VIEW_ZOOM_LARGE,
wxWEB_VIEW_ZOOM_LARGEST
};
enum wxWebViewZoomType
{
//Scales entire page, including images
wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
wxWEB_VIEW_ZOOM_TYPE_TEXT
};
enum wxWebViewNavigationError
{
wxWEB_NAV_ERR_CONNECTION,
wxWEB_NAV_ERR_CERTIFICATE,
wxWEB_NAV_ERR_AUTH,
wxWEB_NAV_ERR_SECURITY,
wxWEB_NAV_ERR_NOT_FOUND,
wxWEB_NAV_ERR_REQUEST,
wxWEB_NAV_ERR_USER_CANCELLED,
wxWEB_NAV_ERR_OTHER
};
enum wxWebViewReloadFlags
{
//Default, may access cache
wxWEB_VIEW_RELOAD_DEFAULT,
wxWEB_VIEW_RELOAD_NO_CACHE
};
enum wxWebViewBackend
{
wxWEB_VIEW_BACKEND_DEFAULT,
wxWEB_VIEW_BACKEND_WEBKIT,
wxWEB_VIEW_BACKEND_IE
};
//Base class for custom scheme handlers
class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
{
public:
wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
virtual ~wxWebViewHandler() {}
virtual wxString GetName() const { return m_scheme; }
virtual wxFSFile* GetFile(const wxString &uri) = 0;
private:
wxString m_scheme;
};
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];
extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
{
public:
virtual bool Create(wxWindow* parent,
wxWindowID id,
const wxString& url,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name) = 0;
static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
static wxWebView* New(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT,
long style = 0,
const wxString& name = wxWebViewNameStr);
//General methods
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 bool IsBusy() const = 0;
virtual bool IsEditable() const = 0;
virtual void LoadURL(const wxString& url) = 0;
virtual void Print() = 0;
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
virtual void RunScript(const wxString& javascript) = 0;
virtual void SetEditable(bool enable = true) = 0;
virtual void SetPage(const wxString& html, const wxString& baseUrl) = 0;
virtual void SetPage(wxInputStream& html, wxString baseUrl)
{
wxStringOutputStream stream;
stream.Write(html);
SetPage(stream.GetString(), baseUrl);
}
virtual void Stop() = 0;
//History
virtual bool CanGoBack() const = 0;
virtual bool CanGoForward() const = 0;
virtual void GoBack() = 0;
virtual void GoForward() = 0;
virtual void ClearHistory() = 0;
virtual void EnableHistory(bool enable = true) = 0;
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
//Zoom
virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
virtual wxWebViewZoom GetZoom() const = 0;
virtual wxWebViewZoomType GetZoomType() const = 0;
virtual void SetZoom(wxWebViewZoom 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;
//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;
//Undo / redo functionality
virtual bool CanUndo() const = 0;
virtual bool CanRedo() const = 0;
virtual void Undo() = 0;
virtual void Redo() = 0;
wxDECLARE_ABSTRACT_CLASS(wxWebView);
};
class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent
{
public:
wxWebViewEvent() {}
wxWebViewEvent(wxEventType type, int id, const wxString url,
const wxString target)
: wxNotifyEvent(type, id), m_url(url), m_target(target)
{}
const wxString& GetURL() const { return m_url; }
const wxString& GetTarget() const { return m_target; }
virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
private:
wxString m_url;
wxString m_target;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
};
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
typedef void (wxEvtHandler::*wxWebViewEventFunction)
(wxWebViewEvent&);
#define wxWebViewEventHandler(func) \
wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
#define EVT_WEB_VIEW_NAVIGATING(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
wxWebViewEventHandler(fn))
#define EVT_WEB_VIEW_NAVIGATED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
wxWebViewEventHandler(fn))
#define EVT_WEB_VIEW_LOADED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
wxWebViewEventHandler(fn))
#define EVT_WEB_VIEW_ERRROR(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
wxWebViewEventHandler(fn))
#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
wxWebViewEventHandler(fn))
#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
wxWebViewEventHandler(fn))
#endif // wxUSE_WEBVIEW
#endif // _WX_WEB_VIEW_H_

View File

@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////
// Name: webviewarchivehandler.h
// Purpose: Custom webview handler to allow archive browsing
// Author: Steven Lamerton
// Id: $Id$
// Copyright: (c) 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEB_VIEW_FILE_HANDLER_H_
#define _WX_WEB_VIEW_FILE_HANDLER_H_
#include "wx/setup.h"
#if wxUSE_WEBVIEW
class wxFSFile;
class wxFileSystem;
#include "wx/webview.h"
//Loads from uris such as scheme:///C:/example/example.html or archives such as
//scheme:///C:/example/example.zip;protocol=zip/example.html
class WXDLLIMPEXP_WEBVIEW wxWebViewArchiveHandler : public wxWebViewHandler
{
public:
wxWebViewArchiveHandler(const wxString& scheme);
virtual ~wxWebViewArchiveHandler() {}
virtual wxFSFile* GetFile(const wxString &uri);
private:
wxFileSystem* m_fileSystem;
};
#endif // wxUSE_WEBVIEW
#endif // _WX_WEB_VIEW_FILE_HANDLER_H_