[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

cblu cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:43:45 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit cd5226ee3eede107d060bea06f93b42df50e3ac5
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jun 4 18:02:19 2004 +0000

    	Fixed: <rdar://problem/3674921>: (can't drag an image from Desktop to Blot document)
    
            Reviewed by mjs.
    
            * WebView.subproj/WebDataSource.m:
            (-[WebDataSource _imageElementWithImageResource:]): factored out from _documentFragmentWithImageResource:
            (-[WebDataSource _documentFragmentWithImageResource:]): call _imageElementWithImageResource:
            * WebView.subproj/WebDataSourcePrivate.h:
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView _imageExistsAtPaths:]): new
            (-[WebHTMLView _documentFragmentWithPaths:]): new
            (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:]): handle NSFilenamesPboardType
            (+[WebHTMLView _insertablePasteboardTypes]): include NSFilenamesPboardType
            (-[WebHTMLView _canProcessDragWithDraggingInfo:]): check for NSFilenamesPboardType and check that the files are images
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6764 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index a55d7ba..99652ed 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,20 @@
+2004-06-04  Chris Blumenberg  <cblu at apple.com>
+
+	Fixed: <rdar://problem/3674921>: (can't drag an image from Desktop to Blot document)
+
+        Reviewed by mjs.
+
+        * WebView.subproj/WebDataSource.m:
+        (-[WebDataSource _imageElementWithImageResource:]): factored out from _documentFragmentWithImageResource:
+        (-[WebDataSource _documentFragmentWithImageResource:]): call _imageElementWithImageResource:
+        * WebView.subproj/WebDataSourcePrivate.h:
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _imageExistsAtPaths:]): new
+        (-[WebHTMLView _documentFragmentWithPaths:]): new
+        (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:]): handle NSFilenamesPboardType
+        (+[WebHTMLView _insertablePasteboardTypes]): include NSFilenamesPboardType
+        (-[WebHTMLView _canProcessDragWithDraggingInfo:]): check for NSFilenamesPboardType and check that the files are images
+
 2004-06-04  Richard Williamson   <rjw at apple.com>
 
         Fixed crasher from last checkin.
diff --git a/WebKit/WebView.subproj/WebDataSource.m b/WebKit/WebView.subproj/WebDataSource.m
index e7d868c..91ce89e 100644
--- a/WebKit/WebView.subproj/WebDataSource.m
+++ b/WebKit/WebView.subproj/WebDataSource.m
@@ -39,7 +39,6 @@
 #import <Foundation/NSDictionary_NSURLExtras.h>
 #import <Foundation/NSString_NSURLExtras.h>
 #import <Foundation/NSURLConnection.h>
-#import <Foundation/NSURLFileTypeMappings.h>
 #import <Foundation/NSURLRequest.h>
 #import <Foundation/NSURLResponsePrivate.h>
 
@@ -200,17 +199,24 @@
     return archive;
 }
 
-- (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource
+- (DOMElement *)_imageElementWithImageResource:(WebResource *)resource
 {
     ASSERT(resource);
     [self addSubresource:resource];
+    
+    DOMElement *imageElement = [[[self _bridge] DOMDocument] createElement:@"img"];
+    
+    // FIXME: calling _web_originalDataAsString on a file URL returns an absolute path. Workaround this.
+    NSURL *URL = [resource URL];
+    [imageElement setAttribute:@"src" :[URL isFileURL] ? [URL absoluteString] : [URL _web_originalDataAsString]];
+    
+    return imageElement;
+}
 
-    DOMDocument *document = [[self _bridge] DOMDocument];
-    DOMDocumentFragment *fragment = [document createDocumentFragment];
-    DOMElement *imageElement = [document createElement:@"img"];
-    [imageElement setAttribute:@"src" :[[resource URL] _web_originalDataAsString]];
-    [fragment appendChild:imageElement];
-
+- (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource
+{
+    DOMDocumentFragment *fragment = [[[self _bridge] DOMDocument] createDocumentFragment];
+    [fragment appendChild:[self _imageElementWithImageResource:resource]];
     return fragment;
 }
 
diff --git a/WebKit/WebView.subproj/WebDataSourcePrivate.h b/WebKit/WebView.subproj/WebDataSourcePrivate.h
index 0dbc668..05e2b6d 100644
--- a/WebKit/WebView.subproj/WebDataSourcePrivate.h
+++ b/WebKit/WebView.subproj/WebDataSourcePrivate.h
@@ -9,6 +9,7 @@
 #import <WebKit/WebDataSource.h>
 
 @class DOMDocumentFragment;
+ at class DOMElement;
 @class DOMRange;
 @class NSError;
 @class NSURLRequest;
@@ -128,6 +129,7 @@
 - (void)_addSubframeArchives:(NSArray *)subframeArchives;
 - (WebArchive *)_popSubframeArchiveWithName:(NSString *)frameName;
 
+- (DOMElement *)_imageElementWithImageResource:(WebResource *)resource;
 - (DOMDocumentFragment *)_documentFragmentWithImageResource:(WebResource *)resource;
 - (DOMDocumentFragment *)_documentFragmentWithArchive:(WebArchive *)archive;
 - (void)_replaceSelectionWithArchive:(WebArchive *)archive selectReplacement:(BOOL)selectReplacement;
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 155bd55..b39aee6 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -21,6 +21,7 @@
 #import <WebKit/WebHTMLViewInternal.h>
 #import <WebKit/WebHTMLRepresentationPrivate.h>
 #import <WebKit/WebImageRenderer.h>
+#import <WebKit/WebImageRendererFactory.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitNSStringExtras.h>
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
@@ -46,6 +47,7 @@
 
 #import <Foundation/NSFileManager_NSURLExtras.h>
 #import <Foundation/NSURL_NSURLExtras.h>
+#import <Foundation/NSURLFileTypeMappings.h>
 
 #import <CoreGraphics/CGContextGState.h>
 
@@ -80,6 +82,7 @@
 static BOOL forceRealHitTest = NO;
 
 @interface WebHTMLView (WebFileInternal)
+- (BOOL)_imageExistsAtPaths:(NSArray *)paths;
 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
@@ -143,6 +146,50 @@ static WebElementOrTextFilter *elementOrTextFilterInstance = nil;
 
 @implementation WebHTMLView (WebFileInternal)
 
+- (BOOL)_imageExistsAtPaths:(NSArray *)paths
+{
+    NSURLFileTypeMappings *mappings = [NSURLFileTypeMappings sharedMappings];
+    NSArray *imageMIMETypes = [[WebImageRendererFactory sharedFactory] supportedMIMETypes];
+    NSEnumerator *enumerator = [paths objectEnumerator];
+    NSString *path;
+    
+    while ((path = [enumerator nextObject]) != nil) {
+        NSString *MIMEType = [mappings MIMETypeForExtension:[path pathExtension]];
+        if ([imageMIMETypes containsObject:MIMEType]) {
+            return YES;
+        }
+    }
+    
+    return NO;
+}
+
+- (DOMDocumentFragment *)_documentFragmentWithPaths:(NSArray *)paths
+{
+    DOMDocumentFragment *fragment = [[[self _bridge] DOMDocument] createDocumentFragment];
+    NSURLFileTypeMappings *mappings = [NSURLFileTypeMappings sharedMappings];
+    NSArray *imageMIMETypes = [[WebImageRendererFactory sharedFactory] supportedMIMETypes];
+    NSEnumerator *enumerator = [paths objectEnumerator];
+    WebDataSource *dataSource = [self _dataSource];
+    NSString *path;
+    
+    while ((path = [enumerator nextObject]) != nil) {
+        NSString *MIMEType = [mappings MIMETypeForExtension:[path pathExtension]];
+        if ([imageMIMETypes containsObject:MIMEType]) {
+            WebResource *resource = [[WebResource alloc] initWithData:[NSData dataWithContentsOfFile:path]
+                                                                  URL:[NSURL fileURLWithPath:path]
+                                                             MIMEType:MIMEType 
+                                                     textEncodingName:nil
+                                                            frameName:nil];
+            if (resource) {
+                [fragment appendChild:[dataSource _imageElementWithImageResource:resource]];
+                [resource release];
+            }
+        }
+    }
+    
+    return [fragment firstChild] != nil ? fragment : nil;
+}
+
 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
 {
     NSArray *types = [pasteboard types];
@@ -158,6 +205,13 @@ static WebElementOrTextFilter *elementOrTextFilterInstance = nil;
         }
     }
     
+    if ([types containsObject:NSFilenamesPboardType]) {
+        DOMDocumentFragment *fragment = [self _documentFragmentWithPaths:[pasteboard propertyListForType:NSFilenamesPboardType]];
+        if (fragment != nil) {
+            return fragment;
+        }
+    }
+    
     NSURL *URL;
     
     if ([types containsObject:NSHTMLPboardType]) {
@@ -593,7 +647,7 @@ static WebHTMLView *lastHitView = nil;
     static NSArray *types = nil;
     if (!types) {
         types = [[NSArray alloc] initWithObjects:WebArchivePboardType, NSHTMLPboardType,
-            NSTIFFPboardType, NSPICTPboardType, NSURLPboardType, 
+            NSFilenamesPboardType, NSTIFFPboardType, NSPICTPboardType, NSURLPboardType, 
             NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil];
     }
     return types;
@@ -1736,17 +1790,27 @@ static WebHTMLView *lastHitView = nil;
 
 - (BOOL)_canProcessDragWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo
 {
-    if ([[draggingInfo draggingPasteboard] availableTypeFromArray:[WebHTMLView _insertablePasteboardTypes]] != nil) {
-        NSPoint point = [self convertPoint:[draggingInfo draggingLocation] fromView:nil];
-        NSDictionary *element = [self elementAtPoint:point];
-        if ([[self _webView] isEditable] || [[element objectForKey:WebElementDOMNodeKey] isContentEditable]) {
-            if (_private->initiatedDrag && [[element objectForKey:WebElementIsSelectedKey] boolValue]) {
-                // Can't drag onto the selection being dragged.
-                return NO;
-            }
-            return YES;
+    NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
+    NSMutableSet *types = [NSMutableSet setWithArray:[pasteboard types]];
+    [types intersectSet:[NSSet setWithArray:[WebHTMLView _insertablePasteboardTypes]]];
+    if ([types count] == 0) {
+        return NO;
+    } else if ([types count] == 1 && 
+               [types containsObject:NSFilenamesPboardType] && 
+               ![self _imageExistsAtPaths:[pasteboard propertyListForType:NSFilenamesPboardType]]) {
+        return NO;
+    }
+    
+    NSPoint point = [self convertPoint:[draggingInfo draggingLocation] fromView:nil];
+    NSDictionary *element = [self elementAtPoint:point];
+    if ([[self _webView] isEditable] || [[element objectForKey:WebElementDOMNodeKey] isContentEditable]) {
+        if (_private->initiatedDrag && [[element objectForKey:WebElementIsSelectedKey] boolValue]) {
+            // Can't drag onto the selection being dragged.
+            return NO;
         }
+        return YES;
     }
+    
     return NO;
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list