WebKit/wx/WebKitSupport/ChromeClientWx.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 #if ENABLE(DATABASE)
       
    32 #include "DatabaseTracker.h"
       
    33 #endif
       
    34 #include "FileChooser.h"
       
    35 #include "FloatRect.h"
       
    36 #include "Frame.h"
       
    37 #include "FrameLoadRequest.h"
       
    38 #include "Icon.h"
       
    39 #include "NotImplemented.h"
       
    40 #include "PlatformString.h"
       
    41 #include "WindowFeatures.h"
       
    42 
       
    43 #include <stdio.h>
       
    44 
       
    45 #include <wx/wxprec.h>
       
    46 #ifndef WX_PRECOMP
       
    47     #include <wx/wx.h>
       
    48 #endif
       
    49 #include <wx/textdlg.h>
       
    50 #include <wx/tooltip.h>
       
    51 
       
    52 #include "WebBrowserShell.h"
       
    53 #include "WebView.h"
       
    54 #include "WebViewPrivate.h"
       
    55 
       
    56 namespace WebCore {
       
    57 
       
    58 wxWebKitWindowFeatures wkFeaturesforWindowFeatures(const WindowFeatures& features)
       
    59 {
       
    60     wxWebKitWindowFeatures wkFeatures;
       
    61     wkFeatures.menuBarVisible = features.menuBarVisible;
       
    62     wkFeatures.statusBarVisible = features.statusBarVisible;
       
    63     wkFeatures.toolBarVisible = features.toolBarVisible;
       
    64     wkFeatures.locationBarVisible = features.locationBarVisible;
       
    65     wkFeatures.scrollbarsVisible = features.scrollbarsVisible;
       
    66     wkFeatures.resizable = features.resizable;
       
    67     wkFeatures.fullscreen = features.fullscreen;
       
    68     wkFeatures.dialog = features.dialog;
       
    69     
       
    70     return wkFeatures;
       
    71 }
       
    72 
       
    73 ChromeClientWx::ChromeClientWx(wxWebView* webView)
       
    74 {
       
    75     m_webView = webView;
       
    76 }
       
    77 
       
    78 ChromeClientWx::~ChromeClientWx()
       
    79 {
       
    80 }
       
    81 
       
    82 void ChromeClientWx::chromeDestroyed()
       
    83 {
       
    84     notImplemented();
       
    85 }
       
    86 
       
    87 void ChromeClientWx::setWindowRect(const FloatRect&)
       
    88 {
       
    89     notImplemented();
       
    90 }
       
    91 
       
    92 FloatRect ChromeClientWx::windowRect()
       
    93 {
       
    94     notImplemented();
       
    95     return FloatRect();
       
    96 }
       
    97 
       
    98 FloatRect ChromeClientWx::pageRect()
       
    99 {
       
   100     notImplemented();
       
   101     return FloatRect();
       
   102 }
       
   103 
       
   104 float ChromeClientWx::scaleFactor()
       
   105 {
       
   106     notImplemented();
       
   107     return 0.0;
       
   108 }
       
   109 
       
   110 void ChromeClientWx::focus()
       
   111 {
       
   112     notImplemented();
       
   113 }
       
   114 
       
   115 void ChromeClientWx::unfocus()
       
   116 {
       
   117     notImplemented();
       
   118 }
       
   119 
       
   120 bool ChromeClientWx::canTakeFocus(FocusDirection)
       
   121 {
       
   122     notImplemented();
       
   123     return false;
       
   124 }
       
   125 
       
   126 void ChromeClientWx::takeFocus(FocusDirection)
       
   127 {
       
   128     notImplemented();
       
   129 }
       
   130 
       
   131 void ChromeClientWx::focusedNodeChanged(Node*)
       
   132 {
       
   133 }
       
   134 
       
   135 Page* ChromeClientWx::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features)
       
   136 {
       
   137     Page* myPage = 0;
       
   138     wxWebViewNewWindowEvent wkEvent(m_webView);
       
   139     wkEvent.SetURL(request.resourceRequest().url().string());
       
   140     
       
   141     wxWebKitWindowFeatures wkFeatures = wkFeaturesforWindowFeatures(features);
       
   142     wkEvent.SetWindowFeatures(wkFeatures);
       
   143     
       
   144     if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
       
   145         if (wxWebView* webView = wkEvent.GetWebView()) {
       
   146             WebViewPrivate* impl = webView->m_impl;
       
   147             if (impl)
       
   148                 myPage = impl->page;
       
   149         }
       
   150     }
       
   151     
       
   152     return myPage;
       
   153 }
       
   154 
       
   155 Page* ChromeClientWx::createModalDialog(Frame*, const FrameLoadRequest&)
       
   156 {
       
   157     notImplemented();
       
   158     return 0;
       
   159 }
       
   160 
       
   161 void ChromeClientWx::show()
       
   162 {
       
   163     notImplemented();
       
   164 }
       
   165 
       
   166 bool ChromeClientWx::canRunModal()
       
   167 {
       
   168     notImplemented();
       
   169     return false;
       
   170 }
       
   171 
       
   172 void ChromeClientWx::runModal()
       
   173 {
       
   174     notImplemented();
       
   175 }
       
   176 
       
   177 void ChromeClientWx::setToolbarsVisible(bool)
       
   178 {
       
   179     notImplemented();
       
   180 }
       
   181 
       
   182 bool ChromeClientWx::toolbarsVisible()
       
   183 {
       
   184     notImplemented();
       
   185     return false;
       
   186 }
       
   187 
       
   188 void ChromeClientWx::setStatusbarVisible(bool)
       
   189 {
       
   190     notImplemented();
       
   191 }
       
   192 
       
   193 bool ChromeClientWx::statusbarVisible()
       
   194 {
       
   195     notImplemented();
       
   196     return false;
       
   197 }
       
   198 
       
   199 void ChromeClientWx::setScrollbarsVisible(bool)
       
   200 {
       
   201     notImplemented();
       
   202 }
       
   203 
       
   204 bool ChromeClientWx::scrollbarsVisible()
       
   205 {
       
   206     notImplemented();
       
   207     return false;
       
   208 }
       
   209 
       
   210 void ChromeClientWx::setMenubarVisible(bool)
       
   211 {
       
   212     notImplemented();
       
   213 }
       
   214 
       
   215 bool ChromeClientWx::menubarVisible()
       
   216 {
       
   217     notImplemented();
       
   218     return false;
       
   219 }
       
   220 
       
   221 void ChromeClientWx::setResizable(bool)
       
   222 {
       
   223     notImplemented();
       
   224 }
       
   225 
       
   226 void ChromeClientWx::addMessageToConsole(MessageSource source,
       
   227                                           MessageType type,
       
   228                                           MessageLevel level,
       
   229                                           const String& message,
       
   230                                           unsigned int lineNumber,
       
   231                                           const String& sourceID)
       
   232 {
       
   233     if (m_webView) {
       
   234         wxWebViewConsoleMessageEvent wkEvent(m_webView);
       
   235         wkEvent.SetMessage(message);
       
   236         wkEvent.SetLineNumber(lineNumber);
       
   237         wkEvent.SetSourceID(sourceID);
       
   238         wkEvent.SetLevel(static_cast<wxWebViewConsoleMessageLevel>(level));
       
   239         m_webView->GetEventHandler()->ProcessEvent(wkEvent);
       
   240     }
       
   241 }
       
   242 
       
   243 bool ChromeClientWx::canRunBeforeUnloadConfirmPanel()
       
   244 {
       
   245     notImplemented();
       
   246     return true;
       
   247 }
       
   248 
       
   249 bool ChromeClientWx::runBeforeUnloadConfirmPanel(const String& string,
       
   250                                                   Frame* frame)
       
   251 {
       
   252     wxMessageDialog dialog(NULL, string, wxT("Confirm Action?"), wxYES_NO);
       
   253     return dialog.ShowModal() == wxYES;
       
   254 }
       
   255 
       
   256 void ChromeClientWx::closeWindowSoon()
       
   257 {
       
   258     notImplemented();
       
   259 }
       
   260 
       
   261 /*
       
   262     Sites for testing prompts: 
       
   263     Alert - just type in a bad web address or http://www.htmlite.com/JS002.php
       
   264     Prompt - http://www.htmlite.com/JS007.php
       
   265     Confirm - http://www.htmlite.com/JS006.php
       
   266 */
       
   267 
       
   268 void ChromeClientWx::runJavaScriptAlert(Frame* frame, const String& string)
       
   269 {
       
   270     if (m_webView) {
       
   271         wxWebViewAlertEvent wkEvent(m_webView);
       
   272         wkEvent.SetMessage(string);
       
   273         if (!m_webView->GetEventHandler()->ProcessEvent(wkEvent))
       
   274             wxMessageBox(string, wxT("JavaScript Alert"), wxOK);
       
   275     }
       
   276 }
       
   277 
       
   278 bool ChromeClientWx::runJavaScriptConfirm(Frame* frame, const String& string)
       
   279 {
       
   280     bool result = false;
       
   281     if (m_webView) {
       
   282         wxWebViewConfirmEvent wkEvent(m_webView);
       
   283         wkEvent.SetMessage(string);
       
   284         if (m_webView->GetEventHandler()->ProcessEvent(wkEvent))
       
   285             result = wkEvent.GetReturnCode() == wxID_YES;
       
   286         else {
       
   287             wxMessageDialog dialog(NULL, string, wxT("JavaScript Confirm"), wxYES_NO);
       
   288             dialog.Centre();
       
   289             result = (dialog.ShowModal() == wxID_YES);
       
   290         }
       
   291     }
       
   292     return result;
       
   293 }
       
   294 
       
   295 bool ChromeClientWx::runJavaScriptPrompt(Frame* frame, const String& message, const String& defaultValue, String& result)
       
   296 {
       
   297     if (m_webView) {
       
   298         wxWebViewPromptEvent wkEvent(m_webView);
       
   299         wkEvent.SetMessage(message);
       
   300         wkEvent.SetResponse(defaultValue);
       
   301         if (m_webView->GetEventHandler()->ProcessEvent(wkEvent)) {
       
   302             result = wkEvent.GetResponse();
       
   303             return true;
       
   304         }
       
   305         else {
       
   306             wxTextEntryDialog dialog(NULL, message, wxT("JavaScript Prompt"), wxEmptyString, wxOK | wxCANCEL);
       
   307             dialog.Centre();
       
   308             if (dialog.ShowModal() == wxID_OK) {
       
   309                 result = dialog.GetValue();
       
   310                 return true;
       
   311             }
       
   312         }
       
   313     }
       
   314     return false;
       
   315 }
       
   316 
       
   317 void ChromeClientWx::setStatusbarText(const String&)
       
   318 {
       
   319     notImplemented();
       
   320 }
       
   321 
       
   322 bool ChromeClientWx::shouldInterruptJavaScript()
       
   323 {
       
   324     notImplemented();
       
   325     return false;
       
   326 }
       
   327 
       
   328 bool ChromeClientWx::tabsToLinks() const
       
   329 {
       
   330     notImplemented();
       
   331     return false;
       
   332 }
       
   333 
       
   334 IntRect ChromeClientWx::windowResizerRect() const
       
   335 {
       
   336     notImplemented();
       
   337     return IntRect();
       
   338 }
       
   339 
       
   340 void ChromeClientWx::invalidateWindow(const IntRect& rect, bool immediate)
       
   341 {
       
   342     if (immediate)
       
   343         m_webView->Update();
       
   344 }
       
   345 
       
   346 void ChromeClientWx::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
       
   347 {
       
   348     invalidateContentsAndWindow(rect, immediate);
       
   349 }
       
   350 
       
   351 void ChromeClientWx::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
       
   352 {
       
   353     if (!m_webView)
       
   354         return;
       
   355 
       
   356     m_webView->RefreshRect(rect);
       
   357 
       
   358     if (immediate) {
       
   359         m_webView->Update();
       
   360     }
       
   361 }
       
   362 
       
   363 IntRect ChromeClientWx::windowToScreen(const IntRect& rect) const
       
   364 {
       
   365     notImplemented();
       
   366     return rect;
       
   367 }
       
   368 
       
   369 IntPoint ChromeClientWx::screenToWindow(const IntPoint& point) const
       
   370 {
       
   371     notImplemented();
       
   372     return point;
       
   373 }
       
   374 
       
   375 PlatformPageClient ChromeClientWx::platformPageClient() const
       
   376 {
       
   377     return m_webView;
       
   378 }
       
   379 
       
   380 void ChromeClientWx::contentsSizeChanged(Frame*, const IntSize&) const
       
   381 {
       
   382     notImplemented();
       
   383 }
       
   384 
       
   385 void ChromeClientWx::scrollBackingStore(int dx, int dy, 
       
   386                     const IntRect& scrollViewRect, 
       
   387                     const IntRect& clipRect)
       
   388 {
       
   389     notImplemented();
       
   390 }
       
   391 
       
   392 void ChromeClientWx::updateBackingStore()
       
   393 {
       
   394     notImplemented();
       
   395 }
       
   396 
       
   397 void ChromeClientWx::mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags)
       
   398 {
       
   399     notImplemented();
       
   400 }
       
   401 
       
   402 void ChromeClientWx::setToolTip(const String& tip, TextDirection)
       
   403 {
       
   404     wxToolTip* tooltip = m_webView->GetToolTip();
       
   405     if (!tooltip || tooltip->GetTip() != wxString(tip))
       
   406         m_webView->SetToolTip(tip);
       
   407 }
       
   408 
       
   409 void ChromeClientWx::print(Frame*)
       
   410 {
       
   411     notImplemented();
       
   412 }
       
   413 
       
   414 #if ENABLE(DATABASE)
       
   415 void ChromeClientWx::exceededDatabaseQuota(Frame*, const String&)
       
   416 {
       
   417     unsigned long long quota = 5 * 1024 * 1024;
       
   418 
       
   419     if (wxWebFrame* webFrame = m_webView->GetMainFrame())
       
   420         if (Frame* frame = webFrame->GetFrame())
       
   421             if (Document* document = frame->document())
       
   422                 if (!DatabaseTracker::tracker().hasEntryForOrigin(document->securityOrigin()))
       
   423                     DatabaseTracker::tracker().setQuota(document->securityOrigin(), quota);
       
   424 }
       
   425 #endif
       
   426 
       
   427 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
       
   428 void ChromeClientWx::reachedMaxAppCacheSize(int64_t spaceNeeded)
       
   429 {
       
   430     notImplemented();
       
   431 }
       
   432 #endif
       
   433 
       
   434 void ChromeClientWx::scroll(const IntSize&, const IntRect&, const IntRect&)
       
   435 {
       
   436     m_webView->Refresh();
       
   437     notImplemented();
       
   438 }
       
   439 
       
   440 void ChromeClientWx::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
       
   441 {
       
   442     notImplemented();
       
   443 }
       
   444 
       
   445 void ChromeClientWx::chooseIconForFiles(const Vector<String>& filenames, FileChooser* chooser)
       
   446 {
       
   447     chooser->iconLoaded(Icon::createIconForFiles(filenames));
       
   448 }
       
   449 
       
   450 void ChromeClientWx::setCursor(const Cursor&)
       
   451 {
       
   452     notImplemented();
       
   453 }
       
   454 
       
   455 void ChromeClientWx::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
       
   456 {
       
   457     // See the comment in WebCore/page/ChromeClient.h
       
   458     notImplemented();
       
   459 }
       
   460 
       
   461 }