2 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "ChromeClientWx.h"
33 #include "DatabaseTracker.h"
35 #include "FileChooser.h"
36 #include "FileIconLoader.h"
37 #include "FloatRect.h"
39 #include "FrameLoadRequest.h"
41 #include "NavigationAction.h"
42 #include "NotImplemented.h"
43 #include "PlatformString.h"
44 #include "SecurityOrigin.h"
45 #include "PopupMenuWx.h"
46 #include "SearchPopupMenuWx.h"
47 #include "WindowFeatures.h"
51 #include <wx/wxprec.h>
55 #include <wx/textdlg.h>
56 #include <wx/tooltip.h>
58 #include "WebBrowserShell.h"
60 #include "WebViewPrivate.h"
64 wxWebKitWindowFeatures wkFeaturesforWindowFeatures(const WindowFeatures& features)
66 wxWebKitWindowFeatures wkFeatures;
67 wkFeatures.menuBarVisible = features.menuBarVisible;
68 wkFeatures.statusBarVisible = features.statusBarVisible;
69 wkFeatures.toolBarVisible = features.toolBarVisible;
70 wkFeatures.locationBarVisible = features.locationBarVisible;
71 wkFeatures.scrollbarsVisible = features.scrollbarsVisible;
72 wkFeatures.resizable = features.resizable;
73 wkFeatures.fullscreen = features.fullscreen;
74 wkFeatures.dialog = features.dialog;
79 ChromeClientWx::ChromeClientWx(wxWebView* webView)
84 ChromeClientWx::~ChromeClientWx()
88 void ChromeClientWx::chromeDestroyed()
93 void ChromeClientWx::setWindowRect(const FloatRect&)
98 FloatRect ChromeClientWx::windowRect()
104 FloatRect ChromeClientWx::pageRect()
110 void ChromeClientWx::focus()
115 void ChromeClientWx::unfocus()
120 bool ChromeClientWx::canTakeFocus(FocusDirection)
126 void ChromeClientWx::takeFocus(FocusDirection)
131 void ChromeClientWx::focusedNodeChanged(Node*)
135 void ChromeClientWx::focusedFrameChanged(Frame*)
139 Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures& features, const NavigationAction&)
142 wxWebViewNewWindowEvent wkEvent(m_webView);
144 wxWebKitWindowFeatures wkFeatures = wkFeaturesforWindowFeatures(features);
145 wkEvent.SetWindowFeatures(wkFeatures);
147 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
148 if (wxWebView* webView = wkEvent.GetWebView()) {
149 WebViewPrivate* impl = webView->m_impl;
158 Page* ChromeClientWx::createModalDialog(Frame*, const FrameLoadRequest&)
164 void ChromeClientWx::show()
169 bool ChromeClientWx::canRunModal()
175 void ChromeClientWx::runModal()
180 void ChromeClientWx::setToolbarsVisible(bool)
185 bool ChromeClientWx::toolbarsVisible()
191 void ChromeClientWx::setStatusbarVisible(bool)
196 bool ChromeClientWx::statusbarVisible()
202 void ChromeClientWx::setScrollbarsVisible(bool)
207 bool ChromeClientWx::scrollbarsVisible()
213 void ChromeClientWx::setMenubarVisible(bool)
218 bool ChromeClientWx::menubarVisible()
224 void ChromeClientWx::setResizable(bool)
229 void ChromeClientWx::addMessageToConsole(MessageSource source,
232 const String& message,
233 unsigned int lineNumber,
234 const String& sourceID)
237 wxWebViewConsoleMessageEvent wkEvent(m_webView);
238 wkEvent.SetMessage(message);
239 wkEvent.SetLineNumber(lineNumber);
240 wkEvent.SetSourceID(sourceID);
241 wkEvent.SetLevel(static_cast<wxWebViewConsoleMessageLevel>(level));
242 m_webView->GetEventHandler()->ProcessEvent(wkEvent);
246 bool ChromeClientWx::canRunBeforeUnloadConfirmPanel()
252 bool ChromeClientWx::runBeforeUnloadConfirmPanel(const String& string,
255 wxMessageDialog dialog(NULL, string, wxT("Confirm Action?"), wxYES_NO);
256 return dialog.ShowModal() == wxYES;
259 void ChromeClientWx::closeWindowSoon()
265 Sites for testing prompts:
266 Alert - just type in a bad web address or http://www.htmlite.com/JS002.php
267 Prompt - http://www.htmlite.com/JS007.php
268 Confirm - http://www.htmlite.com/JS006.php
271 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string)
274 wxWebViewAlertEvent wkEvent(m_webView);
275 wkEvent.SetMessage(string);
276 if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent))
277 wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
281 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string)
285 wxWebViewConfirmEvent wkEvent(m_webView);
286 wkEvent.SetMessage(string);
287 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent))
288 result = wkEvent.GetReturnCode() == wxID_YES;
290 wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
292 result = (dialog.ShowModal() == wxID_YES);
298 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
301 wxWebViewPromptEvent wkEvent(m_webView);
302 wkEvent.SetMessage(message);
303 wkEvent.SetResponse(defaultValue);
304 if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
305 result = wkEvent.GetResponse();
309 wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
311 if (dialog.ShowModal() == wxID_OK) {
312 result = dialog.GetValue();
320 void ChromeClientWx::setStatusbarText(const String&)
325 bool ChromeClientWx::shouldInterruptJavaScript()
331 KeyboardUIMode ChromeClientWx::keyboardUIMode()
334 return KeyboardAccessDefault;
337 IntRect ChromeClientWx::windowResizerRect() const
343 void ChromeClientWx::invalidateWindow(const IntRect& rect, bool immediate)
349 void ChromeClientWx::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
351 invalidateContentsAndWindow(rect, immediate);
354 void ChromeClientWx::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
359 m_webView->RefreshRect(rect);
366 IntRect ChromeClientWx::windowToScreen(const IntRect& rect) const
372 IntPoint ChromeClientWx::screenToWindow(const IntPoint& point) const
378 PlatformPageClient ChromeClientWx::platformPageClient() const
383 void ChromeClientWx::contentsSizeChanged(Frame*, const IntSize&) const
388 void ChromeClientWx::scrollBackingStore(int dx, int dy,
389 const IntRect& scrollViewRect,
390 const IntRect& clipRect)
395 void ChromeClientWx::updateBackingStore()
400 void ChromeClientWx::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags)
405 void ChromeClientWx::setToolTip(const String& tip, TextDirection)
407 wxToolTip* tooltip = m_webView->GetToolTip();
408 if (!tooltip || tooltip->GetTip() != wxString(tip))
409 m_webView->SetToolTip(tip);
412 void ChromeClientWx::print(Frame* frame)
414 wxWebFrame* webFrame = kit(frame);
416 wxWebViewPrintFrameEvent event(m_webView);
417 event.SetWebFrame(webFrame);
418 if (!m_webView->GetEventHandler()->ProcessEvent(event))
419 webFrame->Print(true);
424 void ChromeClientWx::exceededDatabaseQuota(Frame*, const String&)
426 unsigned long long quota = 5 * 1024 * 1024;
428 if (wxWebFrame* webFrame = m_webView->GetMainFrame())
429 if (Frame* frame = webFrame->GetFrame())
430 if (Document* document = frame->document())
431 if (!DatabaseTracker::tracker().hasEntryForOrigin(document->securityOrigin()))
432 DatabaseTracker::tracker().setQuota(document->securityOrigin(), quota);
436 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
437 void ChromeClientWx::reachedMaxAppCacheSize(int64_t spaceNeeded)
442 void ChromeClientWx::reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t)
448 void ChromeClientWx::scroll(const IntSize&, const IntRect&, const IntRect&)
450 m_webView->Refresh();
454 void ChromeClientWx::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
459 void ChromeClientWx::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* loader)
461 loader->notifyFinished(Icon::createIconForFiles(filenames));
464 void ChromeClientWx::setCursor(const Cursor& cursor)
466 if (m_webView && cursor.impl())
467 m_webView->SetCursor(*cursor.impl());
470 void ChromeClientWx::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
472 // See the comment in WebCore/page/ChromeClient.h
476 bool ChromeClientWx::selectItemWritingDirectionIsNatural()
481 bool ChromeClientWx::selectItemAlignmentFollowsMenuWritingDirection()
486 PassRefPtr<PopupMenu> ChromeClientWx::createPopupMenu(PopupMenuClient* client) const
488 return adoptRef(new PopupMenuWx(client));
491 PassRefPtr<SearchPopupMenu> ChromeClientWx::createSearchPopupMenu(PopupMenuClient* client) const
493 return adoptRef(new SearchPopupMenuWx(client));