1 /*
2 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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.
26 */
27
28 #include "config.h"
29 #include "ChromeClientWx.h"
30 #include "Console.h"
31 #include "FileChooser.h"
32 #include "FloatRect.h"
33 #include "FrameLoadRequest.h"
34 #include "NotImplemented.h"
35 #include "PlatformString.h"
36
37 #include <stdio.h>
38
39 #include <wx/wxprec.h>
40 #ifndef WX_PRECOMP
41 #include <wx/wx.h>
42 #endif
43 #include <wx/textdlg.h>
44 #include <wx/tooltip.h>
45
46 #include "WebBrowserShell.h"
47 #include "WebView.h"
48 #include "WebViewPrivate.h"
49
50 namespace WebCore {
51
ChromeClientWx(wxWebView * webView)52 ChromeClientWx::ChromeClientWx(wxWebView* webView)
53 {
54 m_webView = webView;
55 }
56
~ChromeClientWx()57 ChromeClientWx::~ChromeClientWx()
58 {
59 }
60
chromeDestroyed()61 void ChromeClientWx::chromeDestroyed()
62 {
63 notImplemented();
64 }
65
setWindowRect(const FloatRect &)66 void ChromeClientWx::setWindowRect(const FloatRect&)
67 {
68 notImplemented();
69 }
70
windowRect()71 FloatRect ChromeClientWx::windowRect()
72 {
73 notImplemented();
74 return FloatRect();
75 }
76
pageRect()77 FloatRect ChromeClientWx::pageRect()
78 {
79 notImplemented();
80 return FloatRect();
81 }
82
scaleFactor()83 float ChromeClientWx::scaleFactor()
84 {
85 notImplemented();
86 return 0.0;
87 }
88
focus()89 void ChromeClientWx::focus()
90 {
91 notImplemented();
92 }
93
unfocus()94 void ChromeClientWx::unfocus()
95 {
96 notImplemented();
97 }
98
canTakeFocus(FocusDirection)99 bool ChromeClientWx::canTakeFocus(FocusDirection)
100 {
101 notImplemented();
102 return false;
103 }
104
takeFocus(FocusDirection)105 void ChromeClientWx::takeFocus(FocusDirection)
106 {
107 notImplemented();
108 }
109
110
createWindow(Frame *,const FrameLoadRequest & request,const WindowFeatures &)111 Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures&)
112 {
113
114 // FIXME: Create a EVT_WEBKIT_NEW_WINDOW event, and only run this code
115 // when that event is not handled.
116
117 Page* myPage = 0;
118 wxWebBrowserShell* newFrame = new wxWebBrowserShell(wxTheApp->GetAppName());
119
120 if (newFrame->webview) {
121 newFrame->webview->LoadURL(request.resourceRequest().url().string());
122 newFrame->Show(true);
123
124 WebViewPrivate* impl = newFrame->webview->m_impl;
125 if (impl)
126 myPage = impl->page;
127 }
128
129 return myPage;
130 }
131
createModalDialog(Frame *,const FrameLoadRequest &)132 Page* ChromeClientWx::createModalDialog(Frame*, const FrameLoadRequest&)
133 {
134 notImplemented();
135 return 0;
136 }
137
show()138 void ChromeClientWx::show()
139 {
140 notImplemented();
141 }
142
canRunModal()143 bool ChromeClientWx::canRunModal()
144 {
145 notImplemented();
146 return false;
147 }
148
runModal()149 void ChromeClientWx::runModal()
150 {
151 notImplemented();
152 }
153
setToolbarsVisible(bool)154 void ChromeClientWx::setToolbarsVisible(bool)
155 {
156 notImplemented();
157 }
158
toolbarsVisible()159 bool ChromeClientWx::toolbarsVisible()
160 {
161 notImplemented();
162 return false;
163 }
164
setStatusbarVisible(bool)165 void ChromeClientWx::setStatusbarVisible(bool)
166 {
167 notImplemented();
168 }
169
statusbarVisible()170 bool ChromeClientWx::statusbarVisible()
171 {
172 notImplemented();
173 return false;
174 }
175
setScrollbarsVisible(bool)176 void ChromeClientWx::setScrollbarsVisible(bool)
177 {
178 notImplemented();
179 }
180
scrollbarsVisible()181 bool ChromeClientWx::scrollbarsVisible()
182 {
183 notImplemented();
184 return false;
185 }
186
setMenubarVisible(bool)187 void ChromeClientWx::setMenubarVisible(bool)
188 {
189 notImplemented();
190 }
191
menubarVisible()192 bool ChromeClientWx::menubarVisible()
193 {
194 notImplemented();
195 return false;
196 }
197
setResizable(bool)198 void ChromeClientWx::setResizable(bool)
199 {
200 notImplemented();
201 }
202
addMessageToConsole(MessageSource source,MessageType type,MessageLevel level,const String & message,unsigned int lineNumber,const String & sourceID)203 void ChromeClientWx::addMessageToConsole(MessageSource source,
204 MessageType type,
205 MessageLevel level,
206 const String& message,
207 unsigned int lineNumber,
208 const String& sourceID)
209 {
210 if (m_webView) {
211 wxWebViewConsoleMessageEvent wkEvent(m_webView);
212 wkEvent.SetMessage(message);
213 wkEvent.SetLineNumber(lineNumber);
214 wkEvent.SetSourceID(sourceID);
215 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
216 }
217 }
218
canRunBeforeUnloadConfirmPanel()219 bool ChromeClientWx::canRunBeforeUnloadConfirmPanel()
220 {
221 notImplemented();
222 return true;
223 }
224
runBeforeUnloadConfirmPanel(const String & string,Frame * frame)225 bool ChromeClientWx::runBeforeUnloadConfirmPanel(const String& string,
226 Frame* frame)
227 {
228 wxMessageDialog dialog(NULL, string, wxT("Confirm Action?"), wxYES_NO);
229 return dialog.ShowModal() == wxYES;
230 }
231
closeWindowSoon()232 void ChromeClientWx::closeWindowSoon()
233 {
234 notImplemented();
235 }
236
237 /*
238 Sites for testing prompts:
239 Alert - just type in a bad web address or http://www.htmlite.com/JS002.php
240 Prompt - http://www.htmlite.com/JS007.php
241 Confirm - http://www.htmlite.com/JS006.php
242 */
243
runJavaScriptAlert(Frame * frame,const String & string)244 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string)
245 {
246 if (m_webView) {
247 wxWebViewAlertEvent wkEvent(m_webView);
248 wkEvent.SetMessage(string);
249 if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent))
250 wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
251 }
252 }
253
runJavaScriptConfirm(Frame * frame,const String & string)254 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string)
255 {
256 bool result = false;
257 if (m_webView) {
258 wxWebViewConfirmEvent wkEvent(m_webView);
259 wkEvent.SetMessage(string);
260 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent))
261 result = wkEvent.GetReturnCode() == wxID_YES;
262 else {
263 wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
264 dialog.Centre();
265 result = (dialog.ShowModal() == wxID_YES);
266 }
267 }
268 return result;
269 }
270
runJavaScriptPrompt(Frame * frame,const String & message,const String & defaultValue,String & result)271 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
272 {
273 if (m_webView) {
274 wxWebViewPromptEvent wkEvent(m_webView);
275 wkEvent.SetMessage(message);
276 wkEvent.SetResponse(defaultValue);
277 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
278 result = wkEvent.GetResponse();
279 return true;
280 }
281 else {
282 wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
283 dialog.Centre();
284 if (dialog.ShowModal() == wxID_OK) {
285 result = dialog.GetValue();
286 return true;
287 }
288 }
289 }
290 return false;
291 }
292
setStatusbarText(const String &)293 void ChromeClientWx::setStatusbarText(const String&)
294 {
295 notImplemented();
296 }
297
shouldInterruptJavaScript()298 bool ChromeClientWx::shouldInterruptJavaScript()
299 {
300 notImplemented();
301 return false;
302 }
303
tabsToLinks() const304 bool ChromeClientWx::tabsToLinks() const
305 {
306 notImplemented();
307 return false;
308 }
309
windowResizerRect() const310 IntRect ChromeClientWx::windowResizerRect() const
311 {
312 notImplemented();
313 return IntRect();
314 }
315
repaint(const IntRect & rect,bool contentChanged,bool immediate,bool repaintContentOnly)316 void ChromeClientWx::repaint(const IntRect& rect, bool contentChanged, bool immediate, bool repaintContentOnly)
317 {
318 if (!m_webView)
319 return;
320
321 if (contentChanged)
322 m_webView->RefreshRect(rect);
323
324 if (immediate) {
325 m_webView->Update();
326 }
327 }
328
windowToScreen(const IntRect & rect) const329 IntRect ChromeClientWx::windowToScreen(const IntRect& rect) const
330 {
331 notImplemented();
332 return rect;
333 }
334
screenToWindow(const IntPoint & point) const335 IntPoint ChromeClientWx::screenToWindow(const IntPoint& point) const
336 {
337 notImplemented();
338 return point;
339 }
340
platformWindow() const341 PlatformWidget ChromeClientWx::platformWindow() const
342 {
343 return 0;
344 }
345
contentsSizeChanged(Frame *,const IntSize &) const346 void ChromeClientWx::contentsSizeChanged(Frame*, const IntSize&) const
347 {
348 notImplemented();
349 }
350
scrollBackingStore(int dx,int dy,const IntRect & scrollViewRect,const IntRect & clipRect)351 void ChromeClientWx::scrollBackingStore(int dx, int dy,
352 const IntRect& scrollViewRect,
353 const IntRect& clipRect)
354 {
355 notImplemented();
356 }
357
updateBackingStore()358 void ChromeClientWx::updateBackingStore()
359 {
360 notImplemented();
361 }
362
mouseDidMoveOverElement(const HitTestResult &,unsigned modifierFlags)363 void ChromeClientWx::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags)
364 {
365 notImplemented();
366 }
367
setToolTip(const String & tip,TextDirection)368 void ChromeClientWx::setToolTip(const String& tip, TextDirection)
369 {
370 wxToolTip* tooltip = m_webView->GetToolTip();
371 if (!tooltip || tooltip->GetTip() != wxString(tip))
372 m_webView->SetToolTip(tip);
373 }
374
print(Frame *)375 void ChromeClientWx::print(Frame*)
376 {
377 notImplemented();
378 }
379
380 #if ENABLE(DATABASE)
exceededDatabaseQuota(Frame *,const String &)381 void ChromeClientWx::exceededDatabaseQuota(Frame*, const String&)
382 {
383 notImplemented();
384 }
385 #endif
386
387 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
reachedMaxAppCacheSize(int64_t spaceNeeded)388 void ChromeClientWx::reachedMaxAppCacheSize(int64_t spaceNeeded)
389 {
390 notImplemented();
391 }
392 #endif
393
scroll(const IntSize &,const IntRect &,const IntRect &)394 void ChromeClientWx::scroll(const IntSize&, const IntRect&, const IntRect&)
395 {
396 notImplemented();
397 }
398
runOpenPanel(Frame *,PassRefPtr<FileChooser>)399 void ChromeClientWx::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
400 {
401 notImplemented();
402 }
403
setCursor(PlatformCursorHandle)404 bool ChromeClientWx::setCursor(PlatformCursorHandle)
405 {
406 notImplemented();
407 return false;
408 }
409
requestGeolocationPermissionForFrame(Frame *,Geolocation *)410 void ChromeClientWx::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
411 {
412 // See the comment in WebCore/page/ChromeClient.h
413 notImplemented();
414 }
415
416 }
417