webview_webkit.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: include/wx/osx/webkit.h
  3. // Purpose: wxWebViewWebKit - embeddable web kit control,
  4. // OS X implementation of web view component
  5. // Author: Jethro Grassie / Kevin Ollivier / Marianne Gagnon
  6. // Modified by:
  7. // Created: 2004-4-16
  8. // Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_WEBKIT_H
  12. #define _WX_WEBKIT_H
  13. #include "wx/setup.h"
  14. #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
  15. || defined(__WXOSX_CARBON__))
  16. #include "wx/control.h"
  17. #include "wx/webview.h"
  18. #include "wx/osx/core/objcid.h"
  19. // ----------------------------------------------------------------------------
  20. // Web Kit Control
  21. // ----------------------------------------------------------------------------
  22. class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView
  23. {
  24. public:
  25. wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit);
  26. wxWebViewWebKit() {}
  27. wxWebViewWebKit(wxWindow *parent,
  28. wxWindowID winID = wxID_ANY,
  29. const wxString& strURL = wxWebViewDefaultURLStr,
  30. const wxPoint& pos = wxDefaultPosition,
  31. const wxSize& size = wxDefaultSize, long style = 0,
  32. const wxString& name = wxWebViewNameStr)
  33. {
  34. Create(parent, winID, strURL, pos, size, style, name);
  35. }
  36. bool Create(wxWindow *parent,
  37. wxWindowID winID = wxID_ANY,
  38. const wxString& strURL = wxWebViewDefaultURLStr,
  39. const wxPoint& pos = wxDefaultPosition,
  40. const wxSize& size = wxDefaultSize, long style = 0,
  41. const wxString& name = wxWebViewNameStr);
  42. virtual ~wxWebViewWebKit();
  43. virtual bool CanGoBack() const;
  44. virtual bool CanGoForward() const;
  45. virtual void GoBack();
  46. virtual void GoForward();
  47. virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
  48. virtual void Stop();
  49. virtual wxString GetPageSource() const;
  50. virtual wxString GetPageText() const;
  51. virtual void Print();
  52. virtual void LoadURL(const wxString& url);
  53. virtual wxString GetCurrentURL() const;
  54. virtual wxString GetCurrentTitle() const;
  55. virtual wxWebViewZoom GetZoom() const;
  56. virtual void SetZoom(wxWebViewZoom zoom);
  57. virtual void SetZoomType(wxWebViewZoomType zoomType);
  58. virtual wxWebViewZoomType GetZoomType() const;
  59. virtual bool CanSetZoomType(wxWebViewZoomType type) const;
  60. virtual bool IsBusy() const { return m_busy; }
  61. //History functions
  62. virtual void ClearHistory();
  63. virtual void EnableHistory(bool enable = true);
  64. virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
  65. virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
  66. virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
  67. //Undo / redo functionality
  68. virtual bool CanUndo() const;
  69. virtual bool CanRedo() const;
  70. virtual void Undo();
  71. virtual void Redo();
  72. //Find function
  73. virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT)
  74. {
  75. wxUnusedVar(text);
  76. wxUnusedVar(flags);
  77. return wxNOT_FOUND;
  78. }
  79. //Clipboard functions
  80. virtual bool CanCut() const { return true; }
  81. virtual bool CanCopy() const { return true; }
  82. virtual bool CanPaste() const { return true; }
  83. virtual void Cut();
  84. virtual void Copy();
  85. virtual void Paste();
  86. //Editing functions
  87. virtual void SetEditable(bool enable = true);
  88. virtual bool IsEditable() const;
  89. //Selection
  90. virtual void DeleteSelection();
  91. virtual bool HasSelection() const;
  92. virtual void SelectAll();
  93. virtual wxString GetSelectedText() const;
  94. virtual wxString GetSelectedSource() const;
  95. virtual void ClearSelection();
  96. void RunScript(const wxString& javascript);
  97. //Virtual Filesystem Support
  98. virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
  99. virtual void* GetNativeBackend() const { return m_webView; }
  100. // ---- methods not from the parent (common) interface
  101. bool CanGetPageSource() const;
  102. void SetScrollPos(int pos);
  103. int GetScrollPos();
  104. bool CanIncreaseTextSize() const;
  105. void IncreaseTextSize();
  106. bool CanDecreaseTextSize() const;
  107. void DecreaseTextSize();
  108. float GetWebkitZoom() const;
  109. void SetWebkitZoom(float zoom);
  110. // don't hide base class virtuals
  111. virtual void SetScrollPos( int orient, int pos, bool refresh = true )
  112. { return wxControl::SetScrollPos(orient, pos, refresh); }
  113. virtual int GetScrollPos( int orient ) const
  114. { return wxControl::GetScrollPos(orient); }
  115. //we need to resize the webview when the control size changes
  116. void OnSize(wxSizeEvent &event);
  117. void OnMove(wxMoveEvent &event);
  118. void OnMouseEvents(wxMouseEvent &event);
  119. bool m_busy;
  120. protected:
  121. virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
  122. DECLARE_EVENT_TABLE()
  123. void MacVisibilityChanged();
  124. private:
  125. wxWindow *m_parent;
  126. wxWindowID m_windowID;
  127. wxString m_pageTitle;
  128. wxObjCID m_webView;
  129. // we may use this later to setup our own mouse events,
  130. // so leave it in for now.
  131. void* m_webKitCtrlEventHandler;
  132. //It should be WebView*, but WebView is an Objective-C class
  133. //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
  134. };
  135. class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory
  136. {
  137. public:
  138. virtual wxWebView* Create() { return new wxWebViewWebKit; }
  139. virtual wxWebView* Create(wxWindow* parent,
  140. wxWindowID id,
  141. const wxString& url = wxWebViewDefaultURLStr,
  142. const wxPoint& pos = wxDefaultPosition,
  143. const wxSize& size = wxDefaultSize,
  144. long style = 0,
  145. const wxString& name = wxWebViewNameStr)
  146. { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
  147. };
  148. #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
  149. #endif // _WX_WEBKIT_H_