webview_webkit.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: include/gtk/wx/webview.h
  3. // Purpose: GTK webkit backend for web view component
  4. // Author: Robert Roebling, Marianne Gagnon
  5. // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_GTK_WEBKITCTRL_H_
  9. #define _WX_GTK_WEBKITCTRL_H_
  10. #include "wx/defs.h"
  11. #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
  12. #include "wx/sharedptr.h"
  13. #include "wx/webview.h"
  14. typedef struct _WebKitWebView WebKitWebView;
  15. //-----------------------------------------------------------------------------
  16. // wxWebViewWebKit
  17. //-----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
  19. {
  20. public:
  21. wxWebViewWebKit();
  22. wxWebViewWebKit(wxWindow *parent,
  23. wxWindowID id = wxID_ANY,
  24. const wxString& url = wxWebViewDefaultURLStr,
  25. const wxPoint& pos = wxDefaultPosition,
  26. const wxSize& size = wxDefaultSize, long style = 0,
  27. const wxString& name = wxWebViewNameStr)
  28. {
  29. Create(parent, id, url, pos, size, style, name);
  30. }
  31. virtual bool Create(wxWindow *parent,
  32. wxWindowID id = wxID_ANY,
  33. const wxString& url = wxWebViewDefaultURLStr,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize, long style = 0,
  36. const wxString& name = wxWebViewNameStr);
  37. virtual ~wxWebViewWebKit();
  38. virtual bool Enable( bool enable = true );
  39. // implementation
  40. // --------------
  41. static wxVisualAttributes
  42. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  43. virtual void Stop();
  44. virtual void LoadURL(const wxString& url);
  45. virtual void GoBack();
  46. virtual void GoForward();
  47. virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
  48. virtual bool CanGoBack() const;
  49. virtual bool CanGoForward() const;
  50. virtual void ClearHistory();
  51. virtual void EnableContextMenu(bool enable = true);
  52. virtual void EnableHistory(bool enable = true);
  53. virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
  54. virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
  55. virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
  56. virtual wxString GetCurrentURL() const;
  57. virtual wxString GetCurrentTitle() const;
  58. virtual wxString GetPageSource() const;
  59. virtual wxString GetPageText() const;
  60. virtual void Print();
  61. virtual bool IsBusy() const;
  62. void SetZoomType(wxWebViewZoomType);
  63. wxWebViewZoomType GetZoomType() const;
  64. bool CanSetZoomType(wxWebViewZoomType) const;
  65. virtual wxWebViewZoom GetZoom() const;
  66. virtual void SetZoom(wxWebViewZoom);
  67. //Clipboard functions
  68. virtual bool CanCut() const;
  69. virtual bool CanCopy() const;
  70. virtual bool CanPaste() const;
  71. virtual void Cut();
  72. virtual void Copy();
  73. virtual void Paste();
  74. //Undo / redo functionality
  75. virtual bool CanUndo() const;
  76. virtual bool CanRedo() const;
  77. virtual void Undo();
  78. virtual void Redo();
  79. //Find function
  80. virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT);
  81. //Editing functions
  82. virtual void SetEditable(bool enable = true);
  83. virtual bool IsEditable() const;
  84. //Selection
  85. virtual void DeleteSelection();
  86. virtual bool HasSelection() const;
  87. virtual void SelectAll();
  88. virtual wxString GetSelectedText() const;
  89. virtual wxString GetSelectedSource() const;
  90. virtual void ClearSelection();
  91. virtual void RunScript(const wxString& javascript);
  92. //Virtual Filesystem Support
  93. virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
  94. virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; }
  95. virtual void* GetNativeBackend() const { return m_web_view; }
  96. /** TODO: check if this can be made private
  97. * The native control has a getter to check for busy state, but except in
  98. * very recent versions of webkit this getter doesn't say everything we need
  99. * (namely it seems to stay indefinitely busy when loading is cancelled by
  100. * user)
  101. */
  102. bool m_busy;
  103. wxString m_vfsurl;
  104. //We use this flag to stop recursion when we load a page from the navigation
  105. //callback, mainly when loading a VFS page
  106. bool m_guard;
  107. //This flag is use to indicate when a navigation event is the result of a
  108. //create-web-view signal and so we need to send a new window event
  109. bool m_creating;
  110. protected:
  111. virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
  112. virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
  113. private:
  114. void ZoomIn();
  115. void ZoomOut();
  116. void SetWebkitZoom(float level);
  117. float GetWebkitZoom() const;
  118. //Find helper function
  119. void FindClear();
  120. // focus event handler: calls GTKUpdateBitmap()
  121. void GTKOnFocus(wxFocusEvent& event);
  122. WebKitWebView *m_web_view;
  123. int m_historyLimit;
  124. wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList;
  125. //variables used for Find()
  126. int m_findFlags;
  127. wxString m_findText;
  128. int m_findPosition;
  129. int m_findCount;
  130. wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
  131. };
  132. class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory
  133. {
  134. public:
  135. virtual wxWebView* Create() { return new wxWebViewWebKit; }
  136. virtual wxWebView* Create(wxWindow* parent,
  137. wxWindowID id,
  138. const wxString& url = wxWebViewDefaultURLStr,
  139. const wxPoint& pos = wxDefaultPosition,
  140. const wxSize& size = wxDefaultSize,
  141. long style = 0,
  142. const wxString& name = wxWebViewNameStr)
  143. { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
  144. };
  145. #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
  146. #endif