]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/webview_webkit.mm
Make wxMSW stack walking methods work with Unicode identifiers.
[wxWidgets.git] / src / osx / webview_webkit.mm
index 0340ca7a02368b635cffc632bb06045edbac71b3..a311bb3d3489d984e12095dda8f93bc4dd0e95b7 100644 (file)
@@ -5,7 +5,6 @@
 // Author:      Jethro Grassie / Kevin Ollivier / Marianne Gagnon
 // Modified by:
 // Created:     2004-4-16
-// RCS-ID:      $Id$
 // Copyright:   (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -645,10 +644,11 @@ void wxWebViewWebKit::SetScrollPos(int pos)
 
 wxString wxWebViewWebKit::GetSelectedText() const
 {
-    NSString* selection = [[m_webView selectedDOMRange] markupString];
-    if (!selection) return wxEmptyString;
+    DOMRange* dr = [m_webView selectedDOMRange];
+    if ( !dr )
+        return wxString();
 
-    return wxStringWithNSString(selection);
+    return wxStringWithNSString([dr toString]);
 }
 
 void wxWebViewWebKit::RunScript(const wxString& javascript)
@@ -905,20 +905,18 @@ void wxWebViewWebKit::SelectAll()
 
 wxString wxWebViewWebKit::GetSelectedSource() const
 {
-    wxString script = ("var range = window.getSelection().getRangeAt(0);"
-                       "var element = document.createElement('div');"
-                       "element.appendChild(range.cloneContents());"
-                       "return element.innerHTML;");
-    id result = [[m_webView windowScriptObject]
-                   evaluateWebScript:wxNSStringWithWxString(script)];
-    return wxStringWithNSString([result stringValue]);
+    DOMRange* dr = [m_webView selectedDOMRange];
+    if ( !dr )
+        return wxString();
+
+    return wxStringWithNSString([dr markupString]);
 }
 
 wxString wxWebViewWebKit::GetPageText() const
 {
-    id result = [[m_webView windowScriptObject]
-                 evaluateWebScript:@"document.body.textContent"];
-    return wxStringWithNSString([result stringValue]);
+    NSString *result = [m_webView stringByEvaluatingJavaScriptFromString:
+                                  @"document.body.textContent"];
+    return wxStringWithNSString(result);
 }
 
 void wxWebViewWebKit::EnableHistory(bool enable)
@@ -1032,7 +1030,7 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
     if (webKitWindow && frame == [sender mainFrame]){
         NSString *url = [[[[frame dataSource] request] URL] absoluteString];
         wxString target = wxStringWithNSString([frame name]);
-        wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATED,
+        wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED,
                              webKitWindow->GetId(),
                              wxStringWithNSString( url ),
                              target);
@@ -1050,7 +1048,7 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
         NSString *url = [[[[frame dataSource] request] URL] absoluteString];
 
         wxString target = wxStringWithNSString([frame name]);
-        wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_LOADED,
+        wxWebViewEvent event(wxEVT_WEBVIEW_LOADED,
                              webKitWindow->GetId(),
                              wxStringWithNSString( url ),
                              target);
@@ -1150,7 +1148,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
 
         wxWebViewNavigationError type;
         wxString description = nsErrorToWxHtmlError(error, &type);
-               wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR,
+               wxWebViewEvent event(wxEVT_WEBVIEW_ERROR,
                                     webKitWindow->GetId(),
                              wxStringWithNSString( url ),
                              wxEmptyString);
@@ -1176,7 +1174,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
 
                wxWebViewNavigationError type;
         wxString description = nsErrorToWxHtmlError(error, &type);
-               wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR,
+               wxWebViewEvent event(wxEVT_WEBVIEW_ERROR,
                                     webKitWindow->GetId(),
                              wxStringWithNSString( url ),
                              wxEmptyString);
@@ -1192,7 +1190,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
                                          forFrame:(WebFrame *)frame
 {
     wxString target = wxStringWithNSString([frame name]);
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED,
+    wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED,
                          webKitWindow->GetId(),
                          webKitWindow->GetCurrentURL(),
                          target);
@@ -1224,7 +1222,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
     webKitWindow->m_busy = true;
     NSString *url = [[request URL] absoluteString];
     wxString target = wxStringWithNSString([frame name]);
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATING,
+    wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING,
                          webKitWindow->GetId(),
                          wxStringWithNSString( url ), target);
 
@@ -1251,7 +1249,7 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
     wxUnusedVar(actionInformation);
 
     NSString *url = [[request URL] absoluteString];
-    wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NEWWINDOW,
+    wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
                          webKitWindow->GetId(),
                          wxStringWithNSString( url ), "");
 
@@ -1291,9 +1289,23 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
     NSURLRequest *request = [self request];
        NSString* path = [[request URL] absoluteString];
 
+    id<NSURLProtocolClient> client = [self client];
+
     wxString wxpath = wxStringWithNSString(path);
     wxString scheme = wxStringWithNSString([[request URL] scheme]);
     wxFSFile* file = g_stringHandlerMap[scheme]->GetFile(wxpath);
+
+    if (!file)
+    {
+        NSError *error = [[NSError alloc] initWithDomain:NSURLErrorDomain
+                            code:NSURLErrorFileDoesNotExist
+                            userInfo:nil];
+
+        [client URLProtocol:self didFailWithError:error];
+
+        return;
+    }
+
     size_t length = file->GetStream()->GetLength();
 
 
@@ -1307,8 +1319,6 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
     file->GetStream()->Read(buffer, length);
     NSData *data = [[NSData alloc] initWithBytesNoCopy:buffer length:length];
 
-    id<NSURLProtocolClient> client = [self client];
-
     //We do not support caching anything yet
        [client URLProtocol:self didReceiveResponse:response
             cacheStoragePolicy:NSURLCacheStorageNotAllowed];