WebCore:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Apr 2006 04:51:48 +0000 (04:51 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Apr 2006 04:51:48 +0000 (04:51 +0000)
        Reviewed by Darin.

        WebCore part of:
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
            a file: URL being pasted instead of just the file name
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
          REGRESSION: File's path doesn't appear after dragging file into input field

        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge isDragCaretRichlyEditable]): Added.
        * manual-tests/plain-text-paste.html: Added.
        * manual-tests/resources/plain-text-paste: Added.
        * manual-tests/resources/plain-text-paste/1.textClipping: Added.
        * manual-tests/resources/plain-text-paste/2.textClipping: Added.
        * manual-tests/resources/plain-text-paste/3.gif: Added.
        * manual-tests/resources/plain-text-paste/4.txt: Added.
        * manual-tests/resources/plain-text-paste/5.webloc: Added.

WebKit:

        Reviewed by Darin.

        WebKit part of:
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
            a file: URL being pasted instead of just the file name
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
          REGRESSION: File's path doesn't appear after dragging file into input field

        * WebView/WebHTMLView.m:
        (-[WebHTMLView _plainTextFromPasteboard:]): Added method that tries to copy AppKit
        text fields' logic for extracting plain text from the pasteboard.
        (-[WebHTMLView _pasteAsPlainTextWithPasteboard:]): Added helper method.
        (-[WebHTMLView _shouldInsertText:replacingDOMRange:givenAction:]):
        (-[WebHTMLView _shouldReplaceSelectionWithText:givenAction:]):
        (-[WebHTMLView readSelectionFromPasteboard:]): Paste as plain text if
        rich text is not allowed.
        (-[WebHTMLView validateUserInterfaceItem:]): Changed to not allow pasteAsRichText:
        if the paste is not going to be handled by the DOM and the selection
        does not allow pasting rich text.
        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): Paste as plain text if
        rich text is not allowed.
        (-[WebHTMLView paste:]): Ditto.
        (-[WebHTMLView pasteAsPlainText:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13990 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/manual-tests/plain-text-paste.html [new file with mode: 0644]
WebCore/manual-tests/resources/plain-text-paste/1.textClipping [new file with mode: 0644]
WebCore/manual-tests/resources/plain-text-paste/2.textClipping [new file with mode: 0644]
WebCore/manual-tests/resources/plain-text-paste/3.gif [new file with mode: 0644]
WebCore/manual-tests/resources/plain-text-paste/4.txt [new file with mode: 0644]
WebCore/manual-tests/resources/plain-text-paste/5.webloc [new file with mode: 0644]
WebKit/ChangeLog
WebKit/WebView/WebHTMLView.m

index f0c885170ecfb2ab88f0b22eadd1099f499a324b..f49081f0232f8fcf1d76927b842ab5312ea0d0bb 100644 (file)
@@ -1,3 +1,25 @@
+2006-04-20  Mitz Pettel  <opendarwin.org@mitzpettel.com>
+
+        Reviewed by Darin.
+
+        WebCore part of:
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
+          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
+            a file: URL being pasted instead of just the file name
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
+          REGRESSION: File's path doesn't appear after dragging file into input field
+
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge isDragCaretRichlyEditable]): Added.
+        * manual-tests/plain-text-paste.html: Added.
+        * manual-tests/resources/plain-text-paste: Added.
+        * manual-tests/resources/plain-text-paste/1.textClipping: Added.
+        * manual-tests/resources/plain-text-paste/2.textClipping: Added.
+        * manual-tests/resources/plain-text-paste/3.gif: Added.
+        * manual-tests/resources/plain-text-paste/4.txt: Added.
+        * manual-tests/resources/plain-text-paste/5.webloc: Added.
+
 2006-04-20  Darin Adler  <darin@apple.com>
 
         Reviewed by Adele.
index 60e1a51d4600c70842cc829cf97e691e16579997..b44cf8dbd451e610a599a4f515f86f7bbbd85ab9 100644 (file)
@@ -432,6 +432,7 @@ typedef enum {
 - (void)moveDragCaretToPoint:(NSPoint)point;
 - (void)removeDragCaret;
 - (DOMRange *)dragCaretDOMRange;
+- (BOOL)isDragCaretRichlyEditable;
 - (DOMRange *)editableDOMRangeForPoint:(NSPoint)point;
 - (DOMRange *)characterRangeAtPoint:(NSPoint)point;
 
index e73357debb7dfdd5febae0ed8b26d6749ec4f592..1873dcbe50e29eccf0222ca4a66ad5639ff801b7 100644 (file)
@@ -2083,6 +2083,11 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     return [DOMRange _rangeWith:m_frame->dragCaret().toRange().get()];
 }
 
+- (BOOL)isDragCaretRichlyEditable
+{
+    return m_frame->dragCaret().isContentRichlyEditable();
+}
+
 - (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
 {
     VisiblePosition position = [self _visiblePositionForPoint:point];
diff --git a/WebCore/manual-tests/plain-text-paste.html b/WebCore/manual-tests/plain-text-paste.html
new file mode 100644 (file)
index 0000000..c63e220
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+        "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+</head>
+<body>
+<p><b>BUG ID:</b> <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=8276">Bugzilla bug 8276</a> REGRESSION (NativeTextField): Pasting a Finder item into a text field results in a file: URL being pasted instead of just the file name
+<br><i>and</i><br> <b>BUG ID:</b> <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=8283">Bugzilla bug 8283</a> REGRESSION: File's path doesn't appear after dragging file into input field</p>
+
+<p id="test" style="background-color:skyblue; padding:3px;"><b>STEPS TO TEST:</b><br>
+1. Open <a href="resources/plain-text-paste/">this folder</a> in the Finder.<br>
+2. Drag each item from the Finder window into the corresponding field below.<br>
+3. Select item 5 in the Finder window and choose Copy &ldquo;5&rdquo; from the Finder&rsquo;s Edit menu.<br>
+4. Back in Safari, click inside the &ldquo;Paste item 5 here&rdquo; field and choose Paste from the Edit menu.
+</p>
+
+<p id="success" style="background-color:palegreen; padding:3px;"><b>TEST PASS:</b> 
+The fields&rsquo; contents will match the Expected Contents.
+</p>
+
+<p id="failure" style="background-color:#FF3300; padding:3px;"><b>TEST FAIL:</b>  
+The fields&rsquo; contents will NOT match the Expected Contents.
+</p>
+Plain text clipping
+<table cellspacing="0" cellpadding="5">
+    <col><col style="background: #ffc;">
+    <tr>
+        <td></td>
+        <td><b>Expected Contents</b></td>
+    </tr>
+    <tr>
+        <td>Drag item 1 here: <input></td>
+        <td>Plain text clipping</td>
+    </tr>
+    <tr>
+        <td>Drag item 2 here: <input></td>
+        <td>Styled text clipping</td>
+    </tr>
+    <tr>
+        <td>Drag item 3 here: <input></td>
+        <td><i>full path to 3.gif, starting with a / character</i></td>
+    </tr>
+    <tr>
+        <td>Drag item 4 here: <input></td>
+        <td><i>full path to 4.txt, starting with a / character</i></td>
+    </tr>
+    <tr>
+        <td>Drag item 5 here: <input></td>
+        <td>http://www.ibm.com/</td>
+    </tr>
+    <tr>
+        <td>Paste item 5 here: <input></td>
+        <td>5</td>
+    </tr>
+</body>
+</html>
diff --git a/WebCore/manual-tests/resources/plain-text-paste/1.textClipping b/WebCore/manual-tests/resources/plain-text-paste/1.textClipping
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/WebCore/manual-tests/resources/plain-text-paste/2.textClipping b/WebCore/manual-tests/resources/plain-text-paste/2.textClipping
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/WebCore/manual-tests/resources/plain-text-paste/3.gif b/WebCore/manual-tests/resources/plain-text-paste/3.gif
new file mode 100644 (file)
index 0000000..3aa2098
Binary files /dev/null and b/WebCore/manual-tests/resources/plain-text-paste/3.gif differ
diff --git a/WebCore/manual-tests/resources/plain-text-paste/4.txt b/WebCore/manual-tests/resources/plain-text-paste/4.txt
new file mode 100644 (file)
index 0000000..dee7357
--- /dev/null
@@ -0,0 +1 @@
+Plain text document
\ No newline at end of file
diff --git a/WebCore/manual-tests/resources/plain-text-paste/5.webloc b/WebCore/manual-tests/resources/plain-text-paste/5.webloc
new file mode 100644 (file)
index 0000000..e69de29
index afe2a088c9e82d67d58872a656a7f35f154ac492..0307ff3045cc5210a3d116f8f7f97a34f5bb4841 100644 (file)
@@ -1,3 +1,30 @@
+2006-04-20 Mitz Pettel  <opendarwin.org@mitzpettel.com>
+
+        Reviewed by Darin.
+
+        WebKit part of:
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
+          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
+            a file: URL being pasted instead of just the file name
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
+          REGRESSION: File's path doesn't appear after dragging file into input field
+
+        * WebView/WebHTMLView.m:
+        (-[WebHTMLView _plainTextFromPasteboard:]): Added method that tries to copy AppKit
+        text fields' logic for extracting plain text from the pasteboard.
+        (-[WebHTMLView _pasteAsPlainTextWithPasteboard:]): Added helper method.
+        (-[WebHTMLView _shouldInsertText:replacingDOMRange:givenAction:]):
+        (-[WebHTMLView _shouldReplaceSelectionWithText:givenAction:]):
+        (-[WebHTMLView readSelectionFromPasteboard:]): Paste as plain text if
+        rich text is not allowed.
+        (-[WebHTMLView validateUserInterfaceItem:]): Changed to not allow pasteAsRichText:
+        if the paste is not going to be handled by the DOM and the selection
+        does not allow pasting rich text.
+        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): Paste as plain text if
+        rich text is not allowed.
+        (-[WebHTMLView paste:]): Ditto.
+        (-[WebHTMLView pasteAsPlainText:]):
+
 2006-04-20  Darin Adler  <darin@apple.com>
 
         Reviewed by Adele.
index dcb22cca7430f7b381dfa6582f748cf18b7a1f6e..837ee1512d76b67a7231486fdccec56d9f790935 100644 (file)
@@ -182,8 +182,11 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
 @interface WebHTMLView (WebHTMLViewFileInternal)
 - (BOOL)_imageExistsAtPaths:(NSArray *)paths;
 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText;
+- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
+- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;
 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
+- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
 - (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;
 - (float)_calculatePrintHeight;
 - (void)_updateTextSizeMultiplier;
@@ -431,6 +434,43 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     return nil;
 }
 
+- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard
+{
+    NSArray *types = [pasteboard types];
+    
+    if ([types containsObject:NSStringPboardType])
+        return [pasteboard stringForType:NSStringPboardType];
+    
+    NSAttributedString *attributedString = nil;
+    NSString *string;
+
+    if ([types containsObject:NSRTFDPboardType])
+        attributedString = [[NSAttributedString alloc] initWithRTFD:[pasteboard dataForType:NSRTFDPboardType] documentAttributes:NULL];
+    if (attributedString == nil && [types containsObject:NSRTFPboardType])
+        attributedString = [[NSAttributedString alloc] initWithRTF:[pasteboard dataForType:NSRTFPboardType] documentAttributes:NULL];
+    if (attributedString != nil) {
+        string = [[attributedString string] copy];
+        [attributedString release];
+        return [string autorelease];
+    }
+    
+    if ([types containsObject:NSFilenamesPboardType]) {
+        string = [[pasteboard propertyListForType:NSFilenamesPboardType] componentsJoinedByString:@"\n"];
+        if (string != nil)
+            return string;
+    }
+    
+    NSURL *URL;
+    
+    if ((URL = [NSURL URLFromPasteboard:pasteboard])) {
+        string = [URL _web_userVisibleString];
+        if ([string length] > 0)
+            return string;
+    }
+    
+    return nil;
+}
+
 - (WebResource *)resourceForData:(NSData *)data preferredFilename:(NSString *)name
 {
     // This method is called by [NSAttributedString _documentFromRange::::] 
@@ -464,6 +504,13 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     }
 }
 
+- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard
+{
+    NSString *text = [self _plainTextFromPasteboard:pasteboard];
+    if ([self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionPasted])
+        [[self _bridge] replaceSelectionWithText:text selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+}
+
 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action
 {
     WebView *webView = [self _webView];
@@ -475,11 +522,15 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     }
 }
 
-- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action
+- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action
 {
     WebView *webView = [self _webView];
-    DOMRange *selectedRange = [self _selectedRange];
-    return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:selectedRange givenAction:action];
+    return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:range givenAction:action];
+}
+
+- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action
+{
+    return [self _shouldInsertText:text replacingDOMRange:[self _selectedRange] givenAction:action];
 }
 
 // Calculate the vertical size of the view that fits on a single page
@@ -1834,7 +1885,10 @@ static WebHTMLView *lastHitView = nil;
 
 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard
 {
-    [self _pasteWithPasteboard:pasteboard allowPlainText:YES];
+    if ([[self _bridge] isSelectionRichlyEditable])
+        [self _pasteWithPasteboard:pasteboard allowPlainText:YES];
+    else
+        [self _pasteAsPlainTextWithPasteboard:pasteboard];
     return YES;
 }
 
@@ -1979,8 +2033,10 @@ static WebHTMLView *lastHitView = nil;
             || action == @selector(_learnSpellingFromMenu:)
             || action == @selector(takeFindStringFromSelection:)) {
         return [self _hasSelection];
-    } else if (action == @selector(paste:) || action == @selector(pasteAsPlainText:) || action == @selector(pasteAsRichText:)) {
+    } else if (action == @selector(paste:) || action == @selector(pasteAsPlainText:)) {
         return [bridge mayDHTMLPaste] || [self _canPaste];
+    } else if (action == @selector(pasteAsRichText:)) {
+        return [bridge mayDHTMLPaste] || ([self _canPaste] && [[self _bridge] isSelectionRichlyEditable]);
     } else if (action == @selector(performFindPanelAction:)) {
         // FIXME: Not yet implemented.
         return NO;
@@ -2888,18 +2944,28 @@ done:
             BOOL didInsert = NO;
             if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
                 NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
-                BOOL chosePlainText;
-                DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
-                if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
-                    [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
-                    if ([self _isMoveDrag]) {
-                        BOOL smartMove = [[self _bridge] selectionGranularity] == WebBridgeSelectByWord && [self _canSmartReplaceWithPasteboard:pasteboard];
-                        [bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
-                    } else {
+                if ([self _isMoveDrag] || [bridge isDragCaretRichlyEditable]) { 
+                    BOOL chosePlainText;
+                    DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
+                    if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
+                        [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
+                        if ([self _isMoveDrag]) {
+                            BOOL smartMove = [bridge selectionGranularity] == WebBridgeSelectByWord && [self _canSmartReplaceWithPasteboard:pasteboard];
+                            [bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
+                        } else {
+                            [bridge setSelectionToDragCaret];
+                            [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
+                        }
+                        didInsert = YES;
+                    }
+                } else {
+                    NSString *text = [self _plainTextFromPasteboard:pasteboard];
+                    if (text && [self _shouldInsertText:text replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
+                        [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
                         [bridge setSelectionToDragCaret];
-                        [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
+                        [bridge replaceSelectionWithText:text selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+                        didInsert = YES;
                     }
-                    didInsert = YES;
                 }
             }
             [webView removeDragCaret];
@@ -3710,7 +3776,10 @@ done:
     if (![self _canPaste]) {
         return;
     }
-    [self _pasteWithPasteboard:[NSPasteboard generalPasteboard] allowPlainText:YES];
+    if ([[self _bridge] isSelectionRichlyEditable])
+        [self _pasteWithPasteboard:[NSPasteboard generalPasteboard] allowPlainText:YES];
+    else
+        [self _pasteAsPlainTextWithPasteboard:[NSPasteboard generalPasteboard]];
 }
 
 - (NSData *)_selectionStartFontAttributesAsRTF
@@ -3951,13 +4020,7 @@ done:
 {
     if (![self _canEdit])
         return;
-        
-    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
-    NSString *text = [pasteboard stringForType:NSStringPboardType];
-    WebFrameBridge *bridge = [self _bridge];
-    if ([self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionPasted]) {
-        [bridge replaceSelectionWithText:text selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
-    }
+    [self _pasteAsPlainTextWithPasteboard:[NSPasteboard generalPasteboard]];
 }
 
 - (void)pasteAsRichText:(id)sender