2 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "wx/wxprec.h"
37 class WebViewFrameData;
45 #if WXMAKINGDLL_WEBKIT
46 #define WXDLLIMPEXP_WEBKIT WXEXPORT
47 #elif defined(WXUSINGDLL_WEBKIT)
48 #define WXDLLIMPEXP_WEBKIT WXIMPORT
50 #define WXDLLIMPEXP_WEBKIT
54 #define WXDLLIMPEXP_WEBKIT
57 class WXDLLIMPEXP_WEBKIT wxWebView : public wxScrolledWindow
59 // ChromeClientWx needs to get the Page* stored by the wxWebView
60 // for the createWindow function.
61 friend class WebCore::ChromeClientWx;
66 %pythonAppend wxWebView "self._setOORInfo(self)"
68 wxWebView(wxWindow* parent, int id = wxID_ANY,
69 const wxPoint& point = wxDefaultPosition,
70 const wxSize& size = wxDefaultSize,
71 WebViewFrameData* data = NULL); // For wxWebView internal data passing
77 void LoadURL(wxString url);
91 //bool CanGetPageSource();
92 wxString GetPageSource();
93 void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
95 wxString RunScript(const wxString& javascript);
97 bool CanIncreaseTextSize() const;
98 void IncreaseTextSize();
99 bool CanDecreaseTextSize() const;
100 void DecreaseTextSize();
101 void MakeEditable(bool enable);
102 bool IsEditable() const { return m_isEditable; }
104 wxString GetPageTitle() const { return m_title; }
105 void SetPageTitle(const wxString& title) { m_title = title; }
109 // event handlers (these functions should _not_ be virtual)
110 void OnPaint(wxPaintEvent& event);
111 void OnSize(wxSizeEvent& event);
112 void OnMouseEvents(wxMouseEvent& event);
113 void OnKeyEvents(wxKeyEvent& event);
114 void OnSetFocus(wxFocusEvent& event);
115 void OnKillFocus(wxFocusEvent& event);
116 void OnActivate(wxActivateEvent& event);
119 // any class wishing to process wxWindows events must use this macro
121 DECLARE_EVENT_TABLE()
123 float m_textMagnifier;
125 bool m_isInitialized;
126 bool m_beingDestroyed;
127 WebViewPrivate* m_impl;
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
137 wxWEBVIEW_STATE_START = 1,
138 wxWEBVIEW_STATE_NEGOTIATING = 2,
139 wxWEBVIEW_STATE_REDIRECTING = 4,
140 wxWEBVIEW_STATE_TRANSFERRING = 8,
141 wxWEBVIEW_STATE_STOP = 16,
142 wxWEBVIEW_STATE_FAILED = 32
146 wxWEBVIEW_NAV_LINK_CLICKED = 1,
147 wxWEBVIEW_NAV_BACK_NEXT = 2,
148 wxWEBVIEW_NAV_FORM_SUBMITTED = 4,
149 wxWEBVIEW_NAV_RELOAD = 8,
150 wxWEBVIEW_NAV_FORM_RESUBMITTED = 16,
151 wxWEBVIEW_NAV_OTHER = 32
154 class WXDLLIMPEXP_WEBKIT wxWebViewDOMElementInfo
157 wxWebViewDOMElementInfo();
159 ~wxWebViewDOMElementInfo() { }
161 wxString GetTagName() const { return m_tagName; }
162 void SetTagName(const wxString& name) { m_tagName = name; }
164 bool IsSelected() const { return m_isSelected; }
165 void SetSelected(bool sel) { m_isSelected = sel; }
167 wxString GetText() const { return m_text; }
168 void SetText(const wxString& text) { m_text = text; }
170 wxString GetImageSrc() const { return m_imageSrc; }
171 void SetImageSrc(const wxString& src) { m_imageSrc = src; }
173 wxString GetLink() const { return m_link; }
174 void SetLink(const wxString& link) { m_link = link; }
185 class WXDLLIMPEXP_WEBKIT wxWebViewBeforeLoadEvent : public wxCommandEvent
188 DECLARE_DYNAMIC_CLASS( wxWebViewBeforeLoadEvent )
192 bool IsCancelled() const { return m_cancelled; }
193 void Cancel(bool cancel = true) { m_cancelled = cancel; }
194 wxString GetURL() const { return m_url; }
195 void SetURL(const wxString& url) { m_url = url; }
196 void SetNavigationType(int navType) { m_navType = navType; }
197 int GetNavigationType() const { return m_navType; }
199 wxWebViewBeforeLoadEvent( wxWindow* win = (wxWindow*) NULL );
200 wxEvent *Clone(void) const { return new wxWebViewBeforeLoadEvent(*this); }
208 class WXDLLIMPEXP_WEBKIT wxWebViewStateChangedEvent : public wxCommandEvent
211 DECLARE_DYNAMIC_CLASS( wxWebViewStateChangedEvent )
215 int GetState() const { return m_state; }
216 void SetState(const int state) { m_state = state; }
217 wxString GetURL() const { return m_url; }
218 void SetURL(const wxString& url) { m_url = url; }
220 wxWebViewStateChangedEvent( wxWindow* win = (wxWindow*) NULL );
221 wxEvent *Clone(void) const { return new wxWebViewStateChangedEvent(*this); }
228 class WXDLLIMPEXP_WEBKIT wxWebViewNewWindowEvent : public wxCommandEvent
231 DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent )
235 wxString GetURL() const { return m_url; }
236 void SetURL(const wxString& url) { m_url = url; }
238 wxWebViewNewWindowEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
239 wxEvent *Clone(void) const { return new wxWebViewNewWindowEvent(*this); }
245 class WXDLLIMPEXP_WEBKIT wxWebViewRightClickEvent : public wxCommandEvent
248 DECLARE_DYNAMIC_CLASS( wxWebViewRightClickEvent )
252 wxWebViewRightClickEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
253 wxEvent *Clone(void) const { return new wxWebViewRightClickEvent(*this); }
255 wxWebViewDOMElementInfo GetInfo() const { return m_info; }
256 void SetInfo(wxWebViewDOMElementInfo info) { m_info = info; }
258 wxPoint GetPosition() const { return m_position; }
259 void SetPosition(wxPoint pos) { m_position = pos; }
262 wxWebViewDOMElementInfo m_info;
266 typedef void (wxEvtHandler::*wxWebViewStateChangedEventFunction)(wxWebViewStateChangedEvent&);
267 typedef void (wxEvtHandler::*wxWebViewBeforeLoadEventFunction)(wxWebViewBeforeLoadEvent&);
268 typedef void (wxEvtHandler::*wxWebViewNewWindowEventFunction)(wxWebViewNewWindowEvent&);
269 typedef void (wxEvtHandler::*wxWebViewRightClickEventFunction)(wxWebViewRightClickEvent&);
272 BEGIN_DECLARE_EVENT_TYPES()
273 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_BEFORE_LOAD, wxID_ANY)
274 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_STATE_CHANGED, wxID_ANY)
275 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_NEW_WINDOW, wxID_ANY)
276 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RIGHT_CLICK, wxID_ANY)
277 END_DECLARE_EVENT_TYPES()
280 #define EVT_WEBVIEW_STATE_CHANGED(func) \
281 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_STATE_CHANGED, \
284 (wxObjectEventFunction) \
285 (wxWebViewStateChangedEventFunction) & func, \
286 static_cast<wxObject*>(NULL)),
288 #define EVT_WEBVIEW_BEFORE_LOAD(func) \
289 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_BEFORE_LOAD, \
292 (wxObjectEventFunction) \
293 (wxWebViewBeforeLoadEventFunction) & func, \
294 static_cast<wxObject*>(NULL)),
296 #define EVT_WEBVIEW_NEW_WINDOW(func) \
297 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_BEFORE_LOAD, \
300 (wxObjectEventFunction) \
301 (wxWebViewBeforeLoadEventFunction) & func, \
302 static_cast<wxObject*>(NULL)),
304 #define EVT_WEBVIEW_RIGHT_CLICK(func) \
305 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_RIGHT_CLICK, \
308 (wxObjectEventFunction) \
309 (wxWebViewRightClickEventFunction) & func, \
310 static_cast<wxObject*>(NULL)),
312 #endif // ifndef WXWEBVIEW_H