]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/webview_webkit.mm
use GTK-specific method to delete selection
[wxWidgets.git] / src / osx / webview_webkit.mm
index 9659efdb082e97f570a10573e0f2ef237522bda5..59617c81cf2437d13a7daf337237a2b4d29bc80e 100644 (file)
@@ -645,10 +645,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,13 +906,11 @@ 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;");
-    NSString *result = [m_webView stringByEvaluatingJavaScriptFromString:
-                                  wxNSStringWithWxString(script)];
-    return wxStringWithNSString(result);
+    DOMRange* dr = [m_webView selectedDOMRange];
+    if ( !dr )
+        return wxString();
+
+    return wxStringWithNSString([dr markupString]);
 }
 
 wxString wxWebViewWebKit::GetPageText() const
@@ -1291,9 +1290,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 +1320,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];