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;
42 class FrameLoaderClientWx;
47 #if WXMAKINGDLL_WEBKIT
48 #define WXDLLIMPEXP_WEBKIT WXEXPORT
49 #elif defined(WXUSINGDLL_WEBKIT)
50 #define WXDLLIMPEXP_WEBKIT WXIMPORT
52 #define WXDLLIMPEXP_WEBKIT
56 #define WXDLLIMPEXP_WEBKIT
59 extern WXDLLIMPEXP_WEBKIT const wxChar* wxWebViewNameStr;
61 class WXDLLIMPEXP_WEBKIT wxWebView : public wxWindow
63 // ChromeClientWx needs to get the Page* stored by the wxWebView
64 // for the createWindow function.
65 friend class WebCore::ChromeClientWx;
66 friend class WebCore::FrameLoaderClientWx;
71 %pythonAppend wxWebView "self._setOORInfo(self)"
72 %pythonAppend wxWebView() ""
75 wxWebView(wxWindow* parent, int id = wxID_ANY,
76 const wxPoint& point = wxDefaultPosition,
77 const wxSize& size = wxDefaultSize,
79 const wxString& name = wxWebViewNameStr); // For wxWebView internal data passing
81 %rename(PreWebView) wxWebView();
86 bool Create(wxWindow* parent, int id = wxID_ANY,
87 const wxPoint& point = wxDefaultPosition,
88 const wxSize& size = wxDefaultSize,
90 const wxString& name = wxWebViewNameStr); // For wxWebView internal data passing
96 void LoadURL(const wxString& url);
113 //bool CanGetPageSource();
114 wxString GetPageSource();
115 void SetPageSource(const wxString& source, const wxString& baseUrl = wxEmptyString);
117 wxString GetInnerText();
118 wxString GetAsMarkup();
119 wxString GetExternalRepresentation();
121 wxString RunScript(const wxString& javascript);
123 bool CanIncreaseTextSize() const;
124 void IncreaseTextSize();
125 bool CanDecreaseTextSize() const;
126 void DecreaseTextSize();
127 void MakeEditable(bool enable);
128 bool IsEditable() const { return m_isEditable; }
130 wxString GetPageTitle() const { return m_title; }
131 void SetPageTitle(const wxString& title) { m_title = title; }
133 wxWebFrame* GetMainFrame() { return m_mainFrame; }
137 // event handlers (these functions should _not_ be virtual)
138 void OnPaint(wxPaintEvent& event);
139 void OnSize(wxSizeEvent& event);
140 void OnMouseEvents(wxMouseEvent& event);
141 void OnKeyEvents(wxKeyEvent& event);
142 void OnSetFocus(wxFocusEvent& event);
143 void OnKillFocus(wxFocusEvent& event);
144 void OnActivate(wxActivateEvent& event);
147 // any class wishing to process wxWindows events must use this macro
149 DECLARE_EVENT_TABLE()
150 DECLARE_DYNAMIC_CLASS(wxWebView)
152 float m_textMagnifier;
154 bool m_isInitialized;
155 bool m_beingDestroyed;
156 WebViewPrivate* m_impl;
157 wxWebFrame* m_mainFrame;
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
167 wxWEBVIEW_LOAD_STARTED = 1,
168 wxWEBVIEW_LOAD_NEGOTIATING = 2,
169 wxWEBVIEW_LOAD_REDIRECTING = 4,
170 wxWEBVIEW_LOAD_TRANSFERRING = 8,
171 wxWEBVIEW_LOAD_STOPPED = 16,
172 wxWEBVIEW_LOAD_FAILED = 32,
173 wxWEBVIEW_LOAD_DL_COMPLETED = 64,
174 wxWEBVIEW_LOAD_DOC_COMPLETED = 128,
175 wxWEBVIEW_LOAD_ONLOAD_HANDLED = 256,
176 wxWEBVIEW_LOAD_WINDOW_OBJECT_CLEARED = 512
180 wxWEBVIEW_NAV_LINK_CLICKED = 1,
181 wxWEBVIEW_NAV_BACK_NEXT = 2,
182 wxWEBVIEW_NAV_FORM_SUBMITTED = 4,
183 wxWEBVIEW_NAV_RELOAD = 8,
184 wxWEBVIEW_NAV_FORM_RESUBMITTED = 16,
185 wxWEBVIEW_NAV_OTHER = 32
188 class WXDLLIMPEXP_WEBKIT wxWebViewDOMElementInfo
191 wxWebViewDOMElementInfo();
193 ~wxWebViewDOMElementInfo() { }
195 wxString GetTagName() const { return m_tagName; }
196 void SetTagName(const wxString& name) { m_tagName = name; }
198 bool IsSelected() const { return m_isSelected; }
199 void SetSelected(bool sel) { m_isSelected = sel; }
201 wxString GetText() const { return m_text; }
202 void SetText(const wxString& text) { m_text = text; }
204 wxString GetImageSrc() const { return m_imageSrc; }
205 void SetImageSrc(const wxString& src) { m_imageSrc = src; }
207 wxString GetLink() const { return m_link; }
208 void SetLink(const wxString& link) { m_link = link; }
219 class WXDLLIMPEXP_WEBKIT wxWebViewBeforeLoadEvent : public wxCommandEvent
222 DECLARE_DYNAMIC_CLASS( wxWebViewBeforeLoadEvent )
226 bool IsCancelled() const { return m_cancelled; }
227 void Cancel(bool cancel = true) { m_cancelled = cancel; }
228 wxString GetURL() const { return m_url; }
229 void SetURL(const wxString& url) { m_url = url; }
230 void SetNavigationType(int navType) { m_navType = navType; }
231 int GetNavigationType() const { return m_navType; }
233 wxWebViewBeforeLoadEvent( wxWindow* win = (wxWindow*) NULL );
234 wxEvent *Clone(void) const { return new wxWebViewBeforeLoadEvent(*this); }
242 class WXDLLIMPEXP_WEBKIT wxWebViewLoadEvent : public wxCommandEvent
245 DECLARE_DYNAMIC_CLASS( wxWebViewLoadEvent )
249 int GetState() const { return m_state; }
250 void SetState(const int state) { m_state = state; }
251 wxString GetURL() const { return m_url; }
252 void SetURL(const wxString& url) { m_url = url; }
254 wxWebViewLoadEvent( wxWindow* win = (wxWindow*) NULL );
255 wxEvent *Clone(void) const { return new wxWebViewLoadEvent(*this); }
262 class WXDLLIMPEXP_WEBKIT wxWebViewNewWindowEvent : public wxCommandEvent
265 DECLARE_DYNAMIC_CLASS( wxWebViewNewWindowEvent )
269 wxString GetURL() const { return m_url; }
270 void SetURL(const wxString& url) { m_url = url; }
271 wxString GetTargetName() const { return m_targetName; }
272 void SetTargetName(const wxString& name) { m_targetName = name; }
274 wxWebViewNewWindowEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
275 wxEvent *Clone(void) const { return new wxWebViewNewWindowEvent(*this); }
279 wxString m_targetName;
282 class WXDLLIMPEXP_WEBKIT wxWebViewRightClickEvent : public wxCommandEvent
285 DECLARE_DYNAMIC_CLASS( wxWebViewRightClickEvent )
289 wxWebViewRightClickEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
290 wxEvent *Clone(void) const { return new wxWebViewRightClickEvent(*this); }
292 wxWebViewDOMElementInfo GetInfo() const { return m_info; }
293 void SetInfo(wxWebViewDOMElementInfo info) { m_info = info; }
295 wxPoint GetPosition() const { return m_position; }
296 void SetPosition(wxPoint pos) { m_position = pos; }
299 wxWebViewDOMElementInfo m_info;
303 class WXDLLIMPEXP_WEBKIT wxWebViewConsoleMessageEvent : public wxCommandEvent
306 DECLARE_DYNAMIC_CLASS( wxWebViewConsoleMessageEvent )
310 wxString GetMessage() const { return m_message; }
311 void SetMessage(const wxString& message) { m_message = message; }
313 unsigned int GetLineNumber() const { return m_lineNumber; }
314 void SetLineNumber(unsigned int lineNumber) { m_lineNumber = lineNumber; }
316 wxString GetSourceID() const { return m_sourceID; }
317 void SetSourceID(const wxString& sourceID) { m_sourceID = sourceID; }
319 wxWebViewConsoleMessageEvent( wxWindow* win = (wxWindow*) NULL );
320 wxEvent *Clone(void) const { return new wxWebViewConsoleMessageEvent(*this); }
323 unsigned int m_lineNumber;
328 class WXDLLIMPEXP_WEBKIT wxWebViewReceivedTitleEvent : public wxCommandEvent
331 DECLARE_DYNAMIC_CLASS( wxWebViewReceivedTitleEvent )
335 wxString GetTitle() const { return m_title; }
336 void SetTitle(const wxString& title) { m_title = title; }
338 wxWebViewReceivedTitleEvent( wxWindow* win = static_cast<wxWindow*>(NULL));
339 wxEvent *Clone(void) const { return new wxWebViewReceivedTitleEvent(*this); }
346 typedef void (wxEvtHandler::*wxWebViewLoadEventFunction)(wxWebViewLoadEvent&);
347 typedef void (wxEvtHandler::*wxWebViewBeforeLoadEventFunction)(wxWebViewBeforeLoadEvent&);
348 typedef void (wxEvtHandler::*wxWebViewNewWindowEventFunction)(wxWebViewNewWindowEvent&);
349 typedef void (wxEvtHandler::*wxWebViewRightClickEventFunction)(wxWebViewRightClickEvent&);
350 typedef void (wxEvtHandler::*wxWebViewConsoleMessageEventFunction)(wxWebViewConsoleMessageEvent&);
351 typedef void (wxEvtHandler::*wxWebViewReceivedTitleEventFunction)(wxWebViewReceivedTitleEvent&);
354 BEGIN_DECLARE_EVENT_TYPES()
355 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_BEFORE_LOAD, wxID_ANY)
356 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_LOAD, wxID_ANY)
357 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_NEW_WINDOW, wxID_ANY)
358 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RIGHT_CLICK, wxID_ANY)
359 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_CONSOLE_MESSAGE, wxID_ANY)
360 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBKIT, wxEVT_WEBVIEW_RECEIVED_TITLE, wxID_ANY)
361 END_DECLARE_EVENT_TYPES()
364 #define EVT_WEBVIEW_LOAD(winid, func) \
365 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_LOAD, \
368 (wxObjectEventFunction) \
369 (wxWebViewLoadEventFunction) & func, \
370 static_cast<wxObject*>(NULL)),
372 #define EVT_WEBVIEW_BEFORE_LOAD(winid, func) \
373 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_BEFORE_LOAD, \
376 (wxObjectEventFunction) \
377 (wxWebViewBeforeLoadEventFunction) & func, \
378 static_cast<wxObject*>(NULL)),
380 #define EVT_WEBVIEW_NEW_WINDOW(winid, func) \
381 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_NEW_WINDOW, \
384 (wxObjectEventFunction) \
385 (wxWebViewNewWindowEventFunction) & func, \
386 static_cast<wxObject*>(NULL)),
388 #define EVT_WEBVIEW_RIGHT_CLICK(winid, func) \
389 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_RIGHT_CLICK, \
392 (wxObjectEventFunction) \
393 (wxWebViewRightClickEventFunction) & func, \
394 static_cast<wxObject*>(NULL)),
396 #define EVT_WEBVIEW_CONSOLE_MESSAGE(winid, func) \
397 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_CONSOLE_MESSAGE, \
400 (wxObjectEventFunction) \
401 (wxWebViewConsoleMessageEventFunction) & func, \
402 static_cast<wxObject*>(NULL)),
404 #define EVT_WEBVIEW_RECEIVED_TITLE(winid, func) \
405 DECLARE_EVENT_TABLE_ENTRY( wxEVT_WEBVIEW_RECEIVED_TITLE, \
408 (wxObjectEventFunction) \
409 (wxWebViewReceivedTitleEventFunction) & func, \
410 static_cast<wxObject*>(NULL)),
412 #endif // ifndef WXWEBVIEW_H