Changeset 13990 in webkit


Ignore:
Timestamp:
Apr 20, 2006 9:51:48 PM (18 years ago)
Author:
adele
Message:

WebCore:

Reviewed by Darin.

WebCore part of:

a file: URL being pasted instead of just the file name

  • 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:

a file: URL being pasted instead of just the file name

  • 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:]):
Location:
trunk
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r13989 r13990  
     12006-04-20  Mitz Pettel  <opendarwin.org@mitzpettel.com>
     2
     3        Reviewed by Darin.
     4
     5        WebCore part of:
     6        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
     7          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
     8            a file: URL being pasted instead of just the file name
     9        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
     10          REGRESSION: File's path doesn't appear after dragging file into input field
     11
     12        * bridge/mac/WebCoreFrameBridge.h:
     13        * bridge/mac/WebCoreFrameBridge.mm:
     14        (-[WebCoreFrameBridge isDragCaretRichlyEditable]): Added.
     15        * manual-tests/plain-text-paste.html: Added.
     16        * manual-tests/resources/plain-text-paste: Added.
     17        * manual-tests/resources/plain-text-paste/1.textClipping: Added.
     18        * manual-tests/resources/plain-text-paste/2.textClipping: Added.
     19        * manual-tests/resources/plain-text-paste/3.gif: Added.
     20        * manual-tests/resources/plain-text-paste/4.txt: Added.
     21        * manual-tests/resources/plain-text-paste/5.webloc: Added.
     22
    1232006-04-20  Darin Adler  <darin@apple.com>
    224
  • trunk/WebCore/bridge/mac/WebCoreFrameBridge.h

    r13890 r13990  
    433433- (void)removeDragCaret;
    434434- (DOMRange *)dragCaretDOMRange;
     435- (BOOL)isDragCaretRichlyEditable;
    435436- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point;
    436437- (DOMRange *)characterRangeAtPoint:(NSPoint)point;
  • trunk/WebCore/bridge/mac/WebCoreFrameBridge.mm

    r13901 r13990  
    20842084}
    20852085
     2086- (BOOL)isDragCaretRichlyEditable
     2087{
     2088    return m_frame->dragCaret().isContentRichlyEditable();
     2089}
     2090
    20862091- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
    20872092{
  • trunk/WebKit/ChangeLog

    r13989 r13990  
     12006-04-20 Mitz Pettel  <opendarwin.org@mitzpettel.com>
     2
     3        Reviewed by Darin.
     4
     5        WebKit part of:
     6        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8276
     7          REGRESSION (NativeTextField): Pasting a Finder item into a text field results in
     8            a file: URL being pasted instead of just the file name
     9        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8283
     10          REGRESSION: File's path doesn't appear after dragging file into input field
     11
     12        * WebView/WebHTMLView.m:
     13        (-[WebHTMLView _plainTextFromPasteboard:]): Added method that tries to copy AppKit
     14        text fields' logic for extracting plain text from the pasteboard.
     15        (-[WebHTMLView _pasteAsPlainTextWithPasteboard:]): Added helper method.
     16        (-[WebHTMLView _shouldInsertText:replacingDOMRange:givenAction:]):
     17        (-[WebHTMLView _shouldReplaceSelectionWithText:givenAction:]):
     18        (-[WebHTMLView readSelectionFromPasteboard:]): Paste as plain text if
     19        rich text is not allowed.
     20        (-[WebHTMLView validateUserInterfaceItem:]): Changed to not allow pasteAsRichText:
     21        if the paste is not going to be handled by the DOM and the selection
     22        does not allow pasting rich text.
     23        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): Paste as plain text if
     24        rich text is not allowed.
     25        (-[WebHTMLView paste:]): Ditto.
     26        (-[WebHTMLView pasteAsPlainText:]):
     27
    1282006-04-20  Darin Adler  <darin@apple.com>
    229
  • trunk/WebKit/WebView/WebHTMLView.m

    r13890 r13990  
    183183- (BOOL)_imageExistsAtPaths:(NSArray *)paths;
    184184- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText;
     185- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;
    185186- (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
     187- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;
    186188- (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
     189- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
    187190- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;
    188191- (float)_calculatePrintHeight;
     
    432435}
    433436
     437- (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard
     438{
     439    NSArray *types = [pasteboard types];
     440   
     441    if ([types containsObject:NSStringPboardType])
     442        return [pasteboard stringForType:NSStringPboardType];
     443   
     444    NSAttributedString *attributedString = nil;
     445    NSString *string;
     446
     447    if ([types containsObject:NSRTFDPboardType])
     448        attributedString = [[NSAttributedString alloc] initWithRTFD:[pasteboard dataForType:NSRTFDPboardType] documentAttributes:NULL];
     449    if (attributedString == nil && [types containsObject:NSRTFPboardType])
     450        attributedString = [[NSAttributedString alloc] initWithRTF:[pasteboard dataForType:NSRTFPboardType] documentAttributes:NULL];
     451    if (attributedString != nil) {
     452        string = [[attributedString string] copy];
     453        [attributedString release];
     454        return [string autorelease];
     455    }
     456   
     457    if ([types containsObject:NSFilenamesPboardType]) {
     458        string = [[pasteboard propertyListForType:NSFilenamesPboardType] componentsJoinedByString:@"\n"];
     459        if (string != nil)
     460            return string;
     461    }
     462   
     463    NSURL *URL;
     464   
     465    if ((URL = [NSURL URLFromPasteboard:pasteboard])) {
     466        string = [URL _web_userVisibleString];
     467        if ([string length] > 0)
     468            return string;
     469    }
     470   
     471    return nil;
     472}
     473
    434474- (WebResource *)resourceForData:(NSData *)data preferredFilename:(NSString *)name
    435475{
     
    465505}
    466506
     507- (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard
     508{
     509    NSString *text = [self _plainTextFromPasteboard:pasteboard];
     510    if ([self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionPasted])
     511        [[self _bridge] replaceSelectionWithText:text selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
     512}
     513
    467514- (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action
    468515{
     
    476523}
    477524
     525- (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action
     526{
     527    WebView *webView = [self _webView];
     528    return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:range givenAction:action];
     529}
     530
    478531- (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action
    479532{
    480     WebView *webView = [self _webView];
    481     DOMRange *selectedRange = [self _selectedRange];
    482     return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:selectedRange givenAction:action];
     533    return [self _shouldInsertText:text replacingDOMRange:[self _selectedRange] givenAction:action];
    483534}
    484535
     
    18351886- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard
    18361887{
    1837     [self _pasteWithPasteboard:pasteboard allowPlainText:YES];
     1888    if ([[self _bridge] isSelectionRichlyEditable])
     1889        [self _pasteWithPasteboard:pasteboard allowPlainText:YES];
     1890    else
     1891        [self _pasteAsPlainTextWithPasteboard:pasteboard];
    18381892    return YES;
    18391893}
     
    19802034            || action == @selector(takeFindStringFromSelection:)) {
    19812035        return [self _hasSelection];
    1982     } else if (action == @selector(paste:) || action == @selector(pasteAsPlainText:) || action == @selector(pasteAsRichText:)) {
     2036    } else if (action == @selector(paste:) || action == @selector(pasteAsPlainText:)) {
    19832037        return [bridge mayDHTMLPaste] || [self _canPaste];
     2038    } else if (action == @selector(pasteAsRichText:)) {
     2039        return [bridge mayDHTMLPaste] || ([self _canPaste] && [[self _bridge] isSelectionRichlyEditable]);
    19842040    } else if (action == @selector(performFindPanelAction:)) {
    19852041        // FIXME: Not yet implemented.
     
    28892945            if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
    28902946                NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
    2891                 BOOL chosePlainText;
    2892                 DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
    2893                 if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
    2894                     [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
    2895                     if ([self _isMoveDrag]) {
    2896                         BOOL smartMove = [[self _bridge] selectionGranularity] == WebBridgeSelectByWord && [self _canSmartReplaceWithPasteboard:pasteboard];
    2897                         [bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
    2898                     } else {
     2947                if ([self _isMoveDrag] || [bridge isDragCaretRichlyEditable]) {
     2948                    BOOL chosePlainText;
     2949                    DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
     2950                    if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
     2951                        [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
     2952                        if ([self _isMoveDrag]) {
     2953                            BOOL smartMove = [bridge selectionGranularity] == WebBridgeSelectByWord && [self _canSmartReplaceWithPasteboard:pasteboard];
     2954                            [bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
     2955                        } else {
     2956                            [bridge setSelectionToDragCaret];
     2957                            [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
     2958                        }
     2959                        didInsert = YES;
     2960                    }
     2961                } else {
     2962                    NSString *text = [self _plainTextFromPasteboard:pasteboard];
     2963                    if (text && [self _shouldInsertText:text replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
     2964                        [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
    28992965                        [bridge setSelectionToDragCaret];
    2900                         [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
     2966                        [bridge replaceSelectionWithText:text selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
     2967                        didInsert = YES;
    29012968                    }
    2902                     didInsert = YES;
    29032969                }
    29042970            }
     
    37113777        return;
    37123778    }
    3713     [self _pasteWithPasteboard:[NSPasteboard generalPasteboard] allowPlainText:YES];
     3779    if ([[self _bridge] isSelectionRichlyEditable])
     3780        [self _pasteWithPasteboard:[NSPasteboard generalPasteboard] allowPlainText:YES];
     3781    else
     3782        [self _pasteAsPlainTextWithPasteboard:[NSPasteboard generalPasteboard]];
    37143783}
    37153784
     
    39524021    if (![self _canEdit])
    39534022        return;
    3954        
    3955     NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
    3956     NSString *text = [pasteboard stringForType:NSStringPboardType];
    3957     WebFrameBridge *bridge = [self _bridge];
    3958     if ([self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionPasted]) {
    3959         [bridge replaceSelectionWithText:text selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
    3960     }
     4023    [self _pasteAsPlainTextWithPasteboard:[NSPasteboard generalPasteboard]];
    39614024}
    39624025
Note: See TracChangeset for help on using the changeset viewer.