// Purpose: Common interface and events for web view component
// Author: Marianne Gagnon
// Id: $Id$
-// Copyright: (c) 2010 Marianne Gagnon
+// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEB_VIEW_H_
#define _WX_WEB_VIEW_H_
-#include "wx/defs.h"
+#include "wx/setup.h"
#if wxUSE_WEB
#include <wx/control.h>
#include <wx/event.h>
#include <wx/sstream.h>
+#include "wx/sharedptr.h"
+#include "wx/vector.h"
+
+#include "wx/osx/webhistoryitem_webkit.h"
+#include "wx/gtk/webhistoryitem_webkit.h"
+#include "wx/msw/webhistoryitem_ie.h"
+
+class wxFSFile;
+class wxFileSystem;
+
/**
* Zoom level in web view component
enum wxWebNavigationError
{
/** Connection error (timeout, etc.) */
- wxWEB_NAV_ERR_CONNECTION = 1,
+ wxWEB_NAV_ERR_CONNECTION,
/** Invalid certificate */
- wxWEB_NAV_ERR_CERTIFICATE = 2,
+ wxWEB_NAV_ERR_CERTIFICATE,
/** Authentication required */
- wxWEB_NAV_ERR_AUTH = 3,
+ wxWEB_NAV_ERR_AUTH,
/** Other security error */
- wxWEB_NAV_ERR_SECURITY = 4,
+ wxWEB_NAV_ERR_SECURITY,
/** Requested resource not found */
- wxWEB_NAV_ERR_NOT_FOUND = 5,
+ wxWEB_NAV_ERR_NOT_FOUND,
/** Invalid request/parameters (e.g. bad URL, bad protocol,
* unsupported resource type) */
- wxWEB_NAV_ERR_REQUEST = 6,
+ wxWEB_NAV_ERR_REQUEST,
/** The user cancelled (e.g. in a dialog) */
- wxWEB_NAV_ERR_USER_CANCELLED = 7,
+ wxWEB_NAV_ERR_USER_CANCELLED,
/** Another (exotic) type of error that didn't fit in other categories*/
- wxWEB_NAV_ERR_OTHER = 8
+ wxWEB_NAV_ERR_OTHER
};
/** Type of refresh */
enum wxWebViewReloadFlags
{
/** Default reload, will access cache */
- wxWEB_VIEW_RELOAD_DEFAULT = 0,
+ wxWEB_VIEW_RELOAD_DEFAULT,
/** Reload the current view without accessing the cache */
- wxWEB_VIEW_RELOAD_NO_CACHE = 1
+ wxWEB_VIEW_RELOAD_NO_CACHE
};
* engine for the current platform*/
wxWEB_VIEW_BACKEND_DEFAULT,
- /** The OSX-native WebKit web engine */
- wxWEB_VIEW_BACKEND_OSX_WEBKIT,
-
- /** The GTK port of the WebKit engine */
- wxWEB_VIEW_BACKEND_GTK_WEBKIT,
+ /** The WebKit web engine */
+ wxWEB_VIEW_BACKEND_WEBKIT,
/** Use Microsoft Internet Explorer as web engine */
wxWEB_VIEW_BACKEND_IE
};
-extern WXDLLIMPEXP_DATA_CORE(const char) wxWebViewNameStr[];
-extern WXDLLIMPEXP_DATA_CORE(const char) wxWebViewDefaultURLStr[];
+//Base class for custom scheme handlers
+class WXDLLIMPEXP_WEB wxWebHandler
+{
+public:
+ virtual wxString GetName() const = 0;
+ virtual wxFSFile* GetFile(const wxString &uri) = 0;
+ virtual wxString CombineURIs(const wxString &baseuri, const wxString &newuri) = 0;
+};
-/**
- * @class wxWebView
- *
- * This control may be used to render web (HTML / CSS / javascript) documents.
- * Capabilities of the HTML renderer will depend upon the backed.
- * TODO: describe each backend and its capabilities here
- *
- * Note that errors are generally reported asynchronously though the
- * wxEVT_COMMAND_WEB_VIEW_ERROR event described below.
- *
- * @beginEventEmissionTable{wxWebNavigationEvent}
- * @event{EVT_BUTTON(id, func)}
- *
- * @event{EVT_WEB_VIEW_NAVIGATING(id, func)}
- * Process a wxEVT_COMMAND_WEB_VIEW_NAVIGATING event, generated before trying
- * to get a resource. This event may be vetoed to prevent navigating to this
- * resource. Note that if the displayed HTML document has several frames, one
- * such event will be generated per frame.
- *
- * @event{EVT_WEB_VIEW_NAVIGATED(id, func)}
- * Process a wxEVT_COMMAND_WEB_VIEW_NAVIGATED event generated after it was
- * confirmed that a resource would be requested. This event may not be vetoed.
- * Note that if the displayed HTML document has several frames, one such event
- * will be generated per frame.
- *
- * @event{EVT_WEB_VIEW_LOADED(id, func)}
- * Process a wxEVT_COMMAND_WEB_VIEW_LOADED event generated when the document
- * is fully loaded and displayed.
- *
- * @event{EVT_WEB_VIEW_ERRROR(id, func)}
- * Process a wxEVT_COMMAND_WEB_VIEW_ERROR event generated when a navigation
- * error occurs.
- * The integer associated with this event will be a wxWebNavigationError item.
- * The string associated with this event may contain a backend-specific more
- * precise error message/code.
- *
- * @endEventTable
- */
-class wxWebView : public wxControl
+extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewNameStr[];
+extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewDefaultURLStr[];
+
+class WXDLLIMPEXP_WEB wxWebView : public wxControl
{
public:
*/
virtual void LoadUrl(const wxString& url) = 0;
+ virtual void ClearHistory() = 0;
+ virtual void EnableHistory(bool enable = true) = 0;
+ virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetBackwardHistory() = 0;
+ virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetForwardHistory() = 0;
+ virtual void LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item) = 0;
+
/**
* Stop the current page loading process, if any.
* May trigger an error event of type wxWEB_NAV_ERR_USER_CANCELLED.
* shown
*/
virtual wxString GetPageSource() = 0;
+ virtual wxString GetPageText() = 0;
/**
* Get the zoom factor of the page
SetPage(stream.GetString(), baseUrl);
}
- // TODO:
- // wxString GetSelection(); // maybe?
- // void SetSelection(...); // maybe?
+ virtual void SetEditable(bool enable = true) = 0;
+ virtual bool IsEditable() = 0;
- // void MakeEditable(bool enable = true); // maybe?
- // bool IsEditable(); // maybe?
+ virtual void SelectAll() = 0;
+ virtual bool HasSelection() = 0;
+ virtual void DeleteSelection() = 0;
+ virtual wxString GetSelectedText() = 0;
+ virtual wxString GetSelectedSource() = 0;
+ virtual void ClearSelection() = 0;
+ virtual void RunScript(const wxString& javascript) = 0;
+
+ // TODO:
// void EnableJavascript(bool enabled); // maybe?
- // wxString RunScript(const wxString& javascript); // maybe?
+ // // maybe?
// void SetScrollPos(int pos); // maybe?
// int GetScrollPos(); // maybe?
// virtual bool IsOfflineMode() = 0; // maybe?
// virtual void SetOfflineMode(bool offline) = 0; // maybe?
- // TODO: offer API to control the opening of new frames
- // (through <a target="..."> as well as through javascript), OR
- // provide a behavior consistent across ports.
- // - OSX : I receive an event for new frames opened with HTML target, and
- // currently block them all.
- // - IE : The DISPID_NEWWINDOW2 event looks like it should work, but I
- // receive way too many of them. A new IE instance opens.
- // - GTK : All frame open requests are blocked. A slot exists that I could
- // connect to to be notified if ever needed
-
/**
* Opens a print dialog so that the user may print the currently
* displayed page.
* Returns whether the web control is currently busy (e.g. loading a page)
*/
virtual bool IsBusy() = 0;
-};
-//class WXDLLIMPEXP_FWD_HTML wxWebNavigationEvent;
+ //Clipboard functions
+ virtual bool CanCut() = 0;
+ virtual bool CanCopy() = 0;
+ virtual bool CanPaste() = 0;
+ virtual void Cut() = 0;
+ virtual void Copy() = 0;
+ virtual void Paste() = 0;
+
+ //Undo / redo functionality
+ virtual bool CanUndo() = 0;
+ virtual bool CanRedo() = 0;
+ virtual void Undo() = 0;
+ virtual void Redo() = 0;
-// FIXME: get those WXDLLIMPEXP_HTML & DECLARE_DYNAMIC_CLASS right...
-//wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_HTML, wxEVT_COMMAND_WEB_VIEW_NAVIGATE,
-// wxWebNavigationEvent );
+ //Virtual Filesystem Support
+ virtual void RegisterHandler(wxWebHandler* handler) = 0;
+ wxDECLARE_ABSTRACT_CLASS(wxWebView);
+};
-// FIXME: get those WXDLLIMPEXP_HTML & DECLARE_DYNAMIC_CLASS right...
-class wxWebNavigationEvent : public wxCommandEvent
+class WXDLLIMPEXP_WEB wxWebNavigationEvent : public wxCommandEvent
{
public:
wxWebNavigationEvent() {}
- wxWebNavigationEvent(wxEventType type, int id, const wxString href,
+ wxWebNavigationEvent(wxEventType type, int id, const wxString url,
const wxString target, bool canVeto)
: wxCommandEvent(type, id)
{
- m_href = href;
+ m_url = url;
m_target = target;
m_vetoed = false;
m_canVeto = canVeto;
/**
* Get the URL being visited
*/
- const wxString& GetHref() const { return m_href; }
+ const wxString& GetURL() const { return m_url; }
/**
* Get the target (frame or window) in which the URL that caused this event
void Veto() { wxASSERT(m_canVeto); m_vetoed = true; }
private:
- wxString m_href;
+ wxString m_url;
wxString m_target;
bool m_canVeto;
bool m_vetoed;
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebNavigationEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebNavigationEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebNavigationEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebNavigationEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebNavigationEvent );
typedef void (wxEvtHandler::*wxWebNavigationEventFunction)
(wxWebNavigationEvent&);
wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
wxHtmlNavigatingEventHandler(fn))
+#define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
+ wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
+ wxHtmlNavigatingEventHandler(fn))
+
+#define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
+ wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
+ wxHtmlNavigatingEventHandler(fn))
+
#endif // wxUSE_WEB
#endif // _WX_WEB_VIEW_H_