diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index 803f8b0b29..08dfff02bb 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -14,8 +14,7 @@ #include "wx/setup.h" -#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \ - || defined(__WXOSX_CARBON__)) +#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__) #include "wx/control.h" #include "wx/webview.h" diff --git a/include/wx/osx/webviewhistoryitem_webkit.h b/include/wx/osx/webviewhistoryitem_webkit.h index f1c2d5f655..5a7d8cc5b4 100644 --- a/include/wx/osx/webviewhistoryitem_webkit.h +++ b/include/wx/osx/webviewhistoryitem_webkit.h @@ -11,8 +11,7 @@ #include "wx/setup.h" -#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \ - || defined(__WXOSX_CARBON__)) +#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__) #include "wx/osx/core/objcid.h" diff --git a/src/common/webview.cpp b/src/common/webview.cpp index afaf3ffd09..965576ae65 100644 --- a/src/common/webview.cpp +++ b/src/common/webview.cpp @@ -17,7 +17,7 @@ #include "wx/webview.h" -#if defined(__WXOSX_COCOA__) || defined(__WXOSX_CARBON__) +#if defined(__WXOSX__) #include "wx/osx/webview_webkit.h" #elif defined(__WXGTK__) #include "wx/gtk/webview_webkit.h" diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index ab7586544f..0722975f80 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -13,8 +13,7 @@ #include "wx/osx/webview_webkit.h" -#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \ - || defined(__WXOSX_CARBON__)) +#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__) // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,12 +27,26 @@ #include "wx/hashmap.h" #include "wx/filesys.h" +#if wxOSX_USE_IPHONE +#include +#else #include #include #include - +#endif #include +// using native types to get compile errors and warnings + +#if wxOSX_USE_COCOA_OR_CARBON +typedef WebView OSXWebView; +#elif wxOSX_USE_IPHONE +typedef UIWebView OSXWebView; +#else +#error "unsupport OSX variant" +#endif + + #define DEBUG_WEBKIT_SIZING 0 // ---------------------------------------------------------------------------- @@ -357,6 +370,12 @@ bool wxWebViewWebKit::Create(wxWindow *parent, GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_webKitCtrlEventHandler); SetPeer(peer); +#elif wxOSX_USE_IPHONE + CGRect r = wxOSXGetFrameForControl( this, pos , size ) ; + m_webView = [[UIWebView alloc] initWithFrame:r]; + + SetPeer( new wxWidgetIPhoneImpl( this, m_webView ) ); + #else NSRect r = wxOSXGetFrameForControl( this, pos , size ) ; m_webView = [[WebView alloc] initWithFrame:r @@ -373,8 +392,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent, [m_webView setHidden:false]; - // Register event listener interfaces +#if wxOSX_USE_IPHONE +#else WebViewLoadDelegate* loadDelegate = [[WebViewLoadDelegate alloc] initWithWxWindow: this]; @@ -390,7 +410,7 @@ bool wxWebViewWebKit::Create(wxWindow *parent, [[WebViewUIDelegate alloc] initWithWxWindow: this]; [m_webView setUIDelegate:uiDelegate]; - +#endif //Register our own class for custom scheme handling [NSURLProtocol registerClass:[WebViewCustomProtocol class]]; @@ -400,6 +420,8 @@ bool wxWebViewWebKit::Create(wxWindow *parent, wxWebViewWebKit::~wxWebViewWebKit() { +#if wxOSX_USE_IPHONE +#else WebViewLoadDelegate* loadDelegate = [m_webView frameLoadDelegate]; WebViewPolicyDelegate* policyDelegate = [m_webView policyDelegate]; WebViewUIDelegate* uiDelegate = [m_webView UIDelegate]; @@ -415,6 +437,7 @@ wxWebViewWebKit::~wxWebViewWebKit() if (uiDelegate) [uiDelegate release]; +#endif } // ---------------------------------------------------------------------------- @@ -442,7 +465,7 @@ void wxWebViewWebKit::GoBack() if ( !m_webView ) return; - [(WebView*)m_webView goBack]; + [(OSXWebView*)m_webView goBack]; } void wxWebViewWebKit::GoForward() @@ -450,7 +473,7 @@ void wxWebViewWebKit::GoForward() if ( !m_webView ) return; - [(WebView*)m_webView goForward]; + [(OSXWebView*)m_webView goForward]; } void wxWebViewWebKit::Reload(wxWebViewReloadFlags flags) @@ -849,7 +872,7 @@ void wxWebViewWebKit::Cut() if ( !m_webView ) return; - [(WebView*)m_webView cut:m_webView]; + [(OSXWebView*)m_webView cut:m_webView]; } void wxWebViewWebKit::Copy() @@ -857,7 +880,7 @@ void wxWebViewWebKit::Copy() if ( !m_webView ) return; - [(WebView*)m_webView copy:m_webView]; + [(OSXWebView*)m_webView copy:m_webView]; } void wxWebViewWebKit::Paste() @@ -865,7 +888,7 @@ void wxWebViewWebKit::Paste() if ( !m_webView ) return; - [(WebView*)m_webView paste:m_webView]; + [(OSXWebView*)m_webView paste:m_webView]; } void wxWebViewWebKit::DeleteSelection() @@ -873,7 +896,7 @@ void wxWebViewWebKit::DeleteSelection() if ( !m_webView ) return; - [(WebView*)m_webView deleteSelection]; + [(OSXWebView*)m_webView deleteSelection]; } bool wxWebViewWebKit::HasSelection() const @@ -1000,6 +1023,9 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr handler) // Listener interfaces //------------------------------------------------------------ +#if wxOSX_USE_IPHONE +#else + // NB: I'm still tracking this down, but it appears the Cocoa window // still has these events fired on it while the Carbon control is being // destroyed. Therefore, we must be careful to check both the existence @@ -1253,6 +1279,8 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out) } @end +#endif + @implementation WebViewCustomProtocol + (BOOL)canInitWithRequest:(NSURLRequest *)request