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

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


The following commit has been merged in the debian/unstable branch:
commit f1eacac3a737dccc73c3bc6eb8e056d494dc3c1d
Author: trey <trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jun 11 19:21:33 2004 +0000

    WebCore:
    
    	Prep work for latest delegate API for dragging.  In addition, I also straightened out all
    	the cases of DHTML setting a drag image or setting pasteboard data, and how that would
    	override WebKit's default behavior (which follows how WinIE does things).
    
            Reviewed by Chris.
    
            * khtml/rendering/render_object.cpp:
            (RenderObject::draggableNode):  Obey new params for whether a DHTML or UserAgent (i.e.,
    	WebKit) drag source is allowed.
            * khtml/rendering/render_object.h:
            * kwq/KWQKHTMLPart.h:
            * kwq/KWQKHTMLPart.mm:
            (KWQKHTMLPart::dispatchDragSrcEvent):  Setting pasteboard data was moved out of here, now
    	caller's responsibility.
            (KWQKHTMLPart::khtmlMouseMoveEvent):  Ask bridge for allowable drag actions (DHTML vs UA).
    	Only send drag events if DHTML is allowed.  Only generate a drag image if the source is
    	a DHTML element.  Note whether event handler set any pasteboard	data, and pass that fact
    	to WebKit.
            (KWQKHTMLPart::dragSourceMovedTo): Only send drag events if DHTML is allowed.
            (KWQKHTMLPart::dragSourceEndedAt): Only send drag events if DHTML is allowed.
            * kwq/WebCoreBridge.h:
    
    WebKit:
    
    	Prep work for latest delegate API for dragging.  In addition, I also straightened out all
    	the cases of DHTML setting a drag image or setting pasteboard data, and how that would
    	override WebKit's default behavior (which follows how WinIE does things).
    
            Reviewed by Chris.
    
            * Misc.subproj/WebNSViewExtras.h:
            * Misc.subproj/WebNSViewExtras.m:
            (-[NSView _web_dragImage:archive:rect:URL:title:event:dragImage:dragLocation:writePasteboard:]):
    	New args to allow WebCore override of dragImage and pasteboard data.
            * WebCoreSupport.subproj/WebBridge.m:
            (-[WebBridge allowDHTMLDrag:UADrag:]):  New method to return the drag action info to WC.
            (-[WebBridge startDraggingImage:at:operation:event:sourceIsDHTML:DHTMLWroteData:]):
    	Pass along new args.
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView _startDraggingImage:at:operation:event:sourceIsDHTML:DHTMLWroteData:]):
    	Allow WebCore to override drag image and pasteboard data for any type of drag.
            (-[WebHTMLView mouseDragged:]):  Pass NO for new args.
            * WebView.subproj/WebHTMLViewPrivate.h:
            * WebView.subproj/WebImageView.m:
            (-[WebImageView mouseDragged:]):  Pass NO/nil for new args.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6817 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d2d5b6e..4a96206 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,27 @@
+2004-07-10  Trey Matteson  <trey at apple.com>
+
+	Prep work for latest delegate API for dragging.  In addition, I also straightened out all
+	the cases of DHTML setting a drag image or setting pasteboard data, and how that would
+	override WebKit's default behavior (which follows how WinIE does things).
+
+        Reviewed by Chris.
+
+        * khtml/rendering/render_object.cpp:
+        (RenderObject::draggableNode):  Obey new params for whether a DHTML or UserAgent (i.e.,
+	WebKit) drag source is allowed.
+        * khtml/rendering/render_object.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::dispatchDragSrcEvent):  Setting pasteboard data was moved out of here, now
+	caller's responsibility.
+        (KWQKHTMLPart::khtmlMouseMoveEvent):  Ask bridge for allowable drag actions (DHTML vs UA).
+	Only send drag events if DHTML is allowed.  Only generate a drag image if the source is
+	a DHTML element.  Note whether event handler set any pasteboard	data, and pass that fact
+	to WebKit.
+        (KWQKHTMLPart::dragSourceMovedTo): Only send drag events if DHTML is allowed.  
+        (KWQKHTMLPart::dragSourceEndedAt): Only send drag events if DHTML is allowed.  
+        * kwq/WebCoreBridge.h:
+
 2004-06-11  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Trey
diff --git a/WebCore/khtml/rendering/render_object.cpp b/WebCore/khtml/rendering/render_object.cpp
index 65816a5..0669840 100644
--- a/WebCore/khtml/rendering/render_object.cpp
+++ b/WebCore/khtml/rendering/render_object.cpp
@@ -1376,27 +1376,37 @@ bool RenderObject::shouldSelect() const
     return true;
 }
 
-DOM::NodeImpl* RenderObject::draggableNode() const
+DOM::NodeImpl* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, bool& dhtmlWillDrag) const
 {
+    if (!dhtmlOK && !uaOK)
+        return 0;
+
     const RenderObject* curr = this;
     while (curr) {
         DOM::NodeImpl *elt = curr->element();
         if (elt && elt->nodeType() == Node::TEXT_NODE) {
             // Since there's no way for the author to address the -khtml-user-drag style for a text node,
             // we use our own judgement.
-            if (canvas()->view()->part()->shouldDragAutoNode(curr->node()))
+            if (uaOK && canvas()->view()->part()->shouldDragAutoNode(curr->node())) {
+                dhtmlWillDrag = false;
                 return curr->node();
-            else if (curr->shouldSelect())
+            } else if (curr->shouldSelect()) {
                 // In this case we have a click in the unselected portion of text.  If this text is
                 // selectable, we want to start the selection process instead of looking for a parent
                 // to try to drag.
                 return 0;
+            }
         } else {
             EUserDrag dragMode = curr->style()->userDrag();
-            if (dragMode == DRAG_ELEMENT)
+            if (dhtmlOK && dragMode == DRAG_ELEMENT) {
+                dhtmlWillDrag = true;
                 return curr->node();
-            else if (dragMode == DRAG_AUTO && canvas()->view()->part()->shouldDragAutoNode(curr->node()))
+            } else if (uaOK && dragMode == DRAG_AUTO
+                       && canvas()->view()->part()->shouldDragAutoNode(curr->node()))
+            {
+                dhtmlWillDrag = false;
                 return curr->node();
+            }
         }
         curr = curr->parent();
     }
diff --git a/WebCore/khtml/rendering/render_object.h b/WebCore/khtml/rendering/render_object.h
index 931cbf5..2c852f4 100644
--- a/WebCore/khtml/rendering/render_object.h
+++ b/WebCore/khtml/rendering/render_object.h
@@ -701,7 +701,7 @@ public:
     virtual void setSelectionState(SelectionState) {}
     bool shouldSelect() const;
 
-    DOM::NodeImpl* draggableNode() const;
+    DOM::NodeImpl* draggableNode(bool dhtmlOK, bool uaOK, bool& dhtmlWillDrag) const;
 
     /**
      * Returns the content coordinates of the caret within this render object.
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index d9dc301..3486db6 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -328,7 +328,7 @@ private:
     static NSView *documentViewForNode(DOM::NodeImpl *);
     
     bool dragHysteresisExceeded(float dragLocationX, float dragLocationY) const;
-    bool dispatchDragSrcEvent(int eventId, const QPoint &loc, bool declareTypes, NSImage **dragImage, NSPoint *dragLoc, unsigned *op) const;
+    bool dispatchDragSrcEvent(int eventId, const QPoint &loc, NSImage **dragImage, NSPoint *dragLoc, unsigned *op) const;
 
     NSImage *KWQKHTMLPart::imageFromRect(NSRect rect) const;
 
@@ -376,6 +376,8 @@ private:
     bool _dragSrcIsLink;
     bool _dragSrcIsImage;
     bool _dragSrcInSelection;
+    bool _dragSrcMayBeDHTML, _dragSrcMayBeUA;   // Are DHTML and/or the UserAgent allowed to drag out?
+    bool _dragSrcIsDHTML;
     
     mutable DOM::Node _elementToDraw;
 };
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index d1ce678..c201f4e 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -1905,18 +1905,12 @@ bool KWQKHTMLPart::dragHysteresisExceeded(float dragLocationX, float dragLocatio
     return deltaX >= threshold || deltaY >= threshold;
 }
 
-// returns if we should continue "default processing", i.e., whether eventhandler canceled
-bool KWQKHTMLPart::dispatchDragSrcEvent(int eventId, const QPoint &loc, bool declareTypes, NSImage **dragImage, NSPoint *dragLoc, NSDragOperation *op) const
+// returns if we should continue "default processing", i.e., whether to start up the drag
+bool KWQKHTMLPart::dispatchDragSrcEvent(int eventId, const QPoint &loc, NSImage **dragImage, NSPoint *dragLoc, NSDragOperation *op) const
 {
-    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
-    if (declareTypes) {
-        // Must be done before ondragstart adds types and data to the pboard,
-        // also done for security, as it erases data from the last drag
-        [pasteboard declareTypes:[NSArray array] owner:nil];
-    }
-    KWQClipboard *clipboard = new KWQClipboard(true, pasteboard, KWQClipboard::Writable);
+    KWQClipboard *clipboard = new KWQClipboard(true, [NSPasteboard pasteboardWithName:NSDragPboard], KWQClipboard::Writable);
     clipboard->ref();
-    bool DHTMLBailed = d->m_view->dispatchDragEvent(eventId, _dragSrc.handle(), loc, clipboard);
+    bool noDefaultProc = d->m_view->dispatchDragEvent(eventId, _dragSrc.handle(), loc, clipboard);
     clipboard->becomeNumb();    // invalidate clipboard here for security
 
     if (dragImage) {
@@ -1938,7 +1932,7 @@ bool KWQKHTMLPart::dispatchDragSrcEvent(int eventId, const QPoint &loc, bool dec
     }
 
     clipboard->deref();
-    return !DHTMLBailed;
+    return !noDefaultProc;
 }
 
 void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
@@ -1956,10 +1950,20 @@ void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
         }
 
 	if (_mouseDownMayStartDrag && _dragSrc.isNull()) {
+            BOOL tempFlag1, tempFlag2;
+            [_bridge allowDHTMLDrag:&tempFlag1 UADrag:&tempFlag2];
+            _dragSrcMayBeDHTML = tempFlag1;
+            _dragSrcMayBeUA = tempFlag2;
+            if (!_dragSrcMayBeDHTML && !_dragSrcMayBeUA) {
+                _mouseDownMayStartDrag = false;     // no element is draggable
+            }
+        }
+        
+        if (_mouseDownMayStartDrag && _dragSrc.isNull()) {
             // try to find an element that wants to be dragged
             RenderObject::NodeInfo nodeInfo(true, false);
             renderer()->layer()->nodeAtPoint(nodeInfo, _mouseDownX, _mouseDownY);
-            _dragSrc = nodeInfo.innerNode()->renderer()->draggableNode();
+            _dragSrc = nodeInfo.innerNode()->renderer()->draggableNode(_dragSrcMayBeDHTML, _dragSrcMayBeUA, _dragSrcIsDHTML);
             if (_dragSrc.isNull()) {
                 _mouseDownMayStartDrag = false;     // no element is draggable
             } else {
@@ -1983,24 +1987,38 @@ void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
                 NSImage *dragImage = nil;
                 NSPoint dragLoc = NSZeroPoint;
                 NSDragOperation srcOp = NSDragOperationNone;
-                if (dispatchDragSrcEvent(EventImpl::DRAGSTART_EVENT, QPoint(dragLocation), true, &dragImage, &dragLoc, &srcOp)) {
-                    if (!dragImage && !_dragSrcIsLink && !_dragSrcIsImage && !_dragSrcInSelection) {
-                        // Element accepted, but didn't supply an image, and WebKit won't be making one
-                        // either - so we make a default one
-                        NSRect imageRect;
-                        dragImage = elementImage(_dragSrc, &imageRect);
-                        dragLoc.x = _mouseDownX - imageRect.origin.x;
-                        dragLoc.y = imageRect.size.height - (_mouseDownY - imageRect.origin.y);
+                BOOL wcWrotePasteboard = NO;
+                if (_dragSrcMayBeDHTML) {
+                    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+                    // Must be done before ondragstart adds types and data to the pboard,
+                    // also done for security, as it erases data from the last drag
+                    [pasteboard declareTypes:[NSArray array] owner:nil];
+
+                    if (dispatchDragSrcEvent(EventImpl::DRAGSTART_EVENT, QPoint(dragLocation), &dragImage, &dragLoc, &srcOp)) {
+                        NSArray *types = [pasteboard types];
+                        wcWrotePasteboard = types && [types count] > 0;
+
+                        if (!dragImage && _dragSrcIsDHTML) {
+                            // Element accepted, but didn't supply an image, and WebKit won't be making one
+                            // either - so we make a default one
+                            NSRect imageRect;
+                            dragImage = elementImage(_dragSrc, &imageRect);
+                            dragLoc.x = _mouseDownX - imageRect.origin.x;
+                            dragLoc.y = imageRect.size.height - (_mouseDownY - imageRect.origin.y);
+                        }
+                    } else {
+                        _mouseDownMayStartDrag = false;  // ondragstart makes us bail
                     }
-                    if ([_bridge startDraggingImage:dragImage at:dragLoc operation:srcOp event:_currentEvent]) {
+                }
+
+                if (_mouseDownMayStartDrag) {
+                    if ([_bridge startDraggingImage:dragImage at:dragLoc operation:srcOp event:_currentEvent sourceIsDHTML:_dragSrcIsDHTML DHTMLWroteData:wcWrotePasteboard]) {
                         // Prevent click handling from taking place once we start dragging.
                         d->m_view->invalidateClick();
-                    } else {
+                    } else if (_dragSrcMayBeDHTML) {
                         // WebKit canned the drag at the last minute - we owe _dragSrc a DRAGEND event
-                        dispatchDragSrcEvent(EventImpl::DRAGEND_EVENT, QPoint(dragLocation), false, NULL, NULL, NULL);
+                        dispatchDragSrcEvent(EventImpl::DRAGEND_EVENT, QPoint(dragLocation), NULL, NULL, NULL);
                     }
-                } else {
-                    _mouseDownMayStartDrag = false;
                 }
             }
 
@@ -2032,11 +2050,11 @@ void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
 
 void KWQKHTMLPart::dragSourceMovedTo(const QPoint &loc)
 {
-    if (!_dragSrc.isNull()) {
+    if (!_dragSrc.isNull() && _dragSrcMayBeDHTML) {
         NSImage *dragImage = nil;
         NSPoint dragLoc = NSZeroPoint;
         // for now we don't care if event handler cancels default behavior, since there is none
-        dispatchDragSrcEvent(EventImpl::DRAG_EVENT, loc, false, &dragImage, &dragLoc, NULL);
+        dispatchDragSrcEvent(EventImpl::DRAG_EVENT, loc, &dragImage, &dragLoc, NULL);
         if (dragImage) {
             [_bridge setDraggingImage:dragImage at:dragLoc];
         }
@@ -2045,9 +2063,9 @@ void KWQKHTMLPart::dragSourceMovedTo(const QPoint &loc)
 
 void KWQKHTMLPart::dragSourceEndedAt(const QPoint &loc)
 {
-    if (!_dragSrc.isNull()) {
+    if (!_dragSrc.isNull() && _dragSrcMayBeDHTML) {
         // for now we don't care if event handler cancels default behavior, since there is none
-        dispatchDragSrcEvent(EventImpl::DRAGEND_EVENT, loc, false, NULL, NULL, NULL);
+        dispatchDragSrcEvent(EventImpl::DRAGEND_EVENT, loc, NULL, NULL, NULL);
     }
 }
 
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 6e7f619..18d2462 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -427,7 +427,8 @@ typedef enum {
 
 - (NSString *)MIMETypeForPath:(NSString *)path;
 
-- (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event;
+- (void)allowDHTMLDrag:(BOOL *)flagDHTML UADrag:(BOOL *)flagUA;
+- (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData;
 - (void)setDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc;
 - (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
 - (BOOL)mayStartDragWithMouseDragged:(NSEvent *)event;
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 7e74e4c..c74c553 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,27 @@
+2004-07-10  Trey Matteson  <trey at apple.com>
+
+	Prep work for latest delegate API for dragging.  In addition, I also straightened out all
+	the cases of DHTML setting a drag image or setting pasteboard data, and how that would
+	override WebKit's default behavior (which follows how WinIE does things).
+
+        Reviewed by Chris.
+
+        * Misc.subproj/WebNSViewExtras.h:
+        * Misc.subproj/WebNSViewExtras.m:
+        (-[NSView _web_dragImage:archive:rect:URL:title:event:dragImage:dragLocation:writePasteboard:]):
+	New args to allow WebCore override of dragImage and pasteboard data.
+        * WebCoreSupport.subproj/WebBridge.m:
+        (-[WebBridge allowDHTMLDrag:UADrag:]):  New method to return the drag action info to WC.
+        (-[WebBridge startDraggingImage:at:operation:event:sourceIsDHTML:DHTMLWroteData:]):
+	Pass along new args.
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _startDraggingImage:at:operation:event:sourceIsDHTML:DHTMLWroteData:]):
+	Allow WebCore to override drag image and pasteboard data for any type of drag.
+        (-[WebHTMLView mouseDragged:]):  Pass NO for new args.
+        * WebView.subproj/WebHTMLViewPrivate.h:
+        * WebView.subproj/WebImageView.m:
+        (-[WebImageView mouseDragged:]):  Pass NO/nil for new args.
+
 === 144 ===
 
 2004-06-10  Kevin Decker  <kdecker at apple.com>
diff --git a/WebKit/Misc.subproj/WebNSViewExtras.h b/WebKit/Misc.subproj/WebNSViewExtras.h
index 4cdb1f2..d3b36b5 100644
--- a/WebKit/Misc.subproj/WebNSViewExtras.h
+++ b/WebKit/Misc.subproj/WebNSViewExtras.h
@@ -46,5 +46,8 @@
                   rect:(NSRect)rect
                    URL:(NSURL *)URL
                  title:(NSString *)title
-                 event:(NSEvent *)event;
+                 event:(NSEvent *)event
+             dragImage:(NSImage *)dragImageOverride
+          dragLocation:(NSPoint)dragLocOverride
+       writePasteboard:(BOOL)writePB;
 @end
diff --git a/WebKit/Misc.subproj/WebNSViewExtras.m b/WebKit/Misc.subproj/WebNSViewExtras.m
index 7b787d8..9c3a0d8 100644
--- a/WebKit/Misc.subproj/WebNSViewExtras.m
+++ b/WebKit/Misc.subproj/WebNSViewExtras.m
@@ -184,11 +184,13 @@
                    URL:(NSURL *)URL
                  title:(NSString *)title
                  event:(NSEvent *)event
+             dragImage:(NSImage *)dragImageOverride
+          dragLocation:(NSPoint)dragLocOverride
+       writePasteboard:(BOOL)writePB
 {
     NSPoint mouseDownPoint = [self convertPoint:[event locationInWindow] fromView:nil];
     NSImage *dragImage;
     NSPoint origin;
-    NSSize offset;
 
     NSString *filename = [URL _web_suggestedFilenameWithMIMEType:[image MIMEType]];
     NSString *fileType = [filename pathExtension];
@@ -196,44 +198,49 @@
         fileType = @"";
     }
     
-    if ([image size].height * [image size].width <= WebMaxOriginalImageArea) {
-        NSSize originalSize = rect.size;
-        origin = rect.origin;
-        
-        dragImage = [[image copy] autorelease];
-        [dragImage setScalesWhenResized:YES];
-        [dragImage setSize:originalSize];
-    
-        [dragImage _web_scaleToMaxSize:WebMaxDragImageSize];
-        NSSize newSize = [dragImage size];
-    
-        [dragImage _web_dissolveToFraction:WebDragImageAlpha];
-    
-        NSPoint currentPoint = [self convertPoint:[[_window currentEvent] locationInWindow] fromView:nil];
-    
-        // Properly orient the drag image and orient it differently if it's smaller than the original
-        origin.x = mouseDownPoint.x - (((mouseDownPoint.x - origin.x) / originalSize.width) * newSize.width);
-        origin.y = origin.y + originalSize.height;
-        origin.y = mouseDownPoint.y - (((mouseDownPoint.y - origin.y) / originalSize.height) * newSize.height);
-    
-        offset = NSMakeSize(currentPoint.x - mouseDownPoint.x, currentPoint.y - mouseDownPoint.y);
+    if (dragImageOverride) {
+        dragImage = dragImageOverride;
+        origin = dragLocOverride;
     } else {
-        dragImage = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];
-        offset = NSMakeSize([dragImage size].width - WebDragIconRightInset, -WebDragIconBottomInset);
-        origin = NSMakePoint(mouseDownPoint.x - offset.width, mouseDownPoint.y - offset.height);
+        if ([image size].height * [image size].width <= WebMaxOriginalImageArea) {
+            NSSize originalSize = rect.size;
+            origin = rect.origin;
+            
+            dragImage = [[image copy] autorelease];
+            [dragImage setScalesWhenResized:YES];
+            [dragImage setSize:originalSize];
+        
+            [dragImage _web_scaleToMaxSize:WebMaxDragImageSize];
+            NSSize newSize = [dragImage size];
+        
+            [dragImage _web_dissolveToFraction:WebDragImageAlpha];
+
+            // Properly orient the drag image and orient it differently if it's smaller than the original
+            origin.x = mouseDownPoint.x - (((mouseDownPoint.x - origin.x) / originalSize.width) * newSize.width);
+            origin.y = origin.y + originalSize.height;
+            origin.y = mouseDownPoint.y - (((mouseDownPoint.y - origin.y) / originalSize.height) * newSize.height);
+        } else {
+            dragImage = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];
+            NSSize offset = NSMakeSize([dragImage size].width - WebDragIconRightInset, -WebDragIconBottomInset);
+            origin = NSMakePoint(mouseDownPoint.x - offset.width, mouseDownPoint.y - offset.height);
+        }
     }
 
     NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
-    NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
-    [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImage]];
-    [pasteboard declareTypes:types owner:self];    
-    [pasteboard _web_writeImage:image URL:URL title:title archive:archive types:types];
-    [types release];
-
-    id source = [[NSFilePromiseDragSource alloc] initWithSource:(id)self];
-    [source setTypes:[NSArray arrayWithObject:fileType] onPasteboard:pasteboard];
-    
-    [self dragImage:dragImage at:origin offset:offset event:event pasteboard:pasteboard source:source slideBack:YES];
+    id source = nil;
+    if (writePB) {
+        NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
+        [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImage]];
+        [pasteboard declareTypes:types owner:self];    
+        [pasteboard _web_writeImage:image URL:URL title:title archive:archive types:types];
+        [types release];
+
+        source = [[NSFilePromiseDragSource alloc] initWithSource:(id)self];
+        [source setTypes:[NSArray arrayWithObject:fileType] onPasteboard:pasteboard];
+    }
+
+    // Per kwebster, offset arg is ignored
+    [self dragImage:dragImage at:origin offset:NSZeroSize event:event pasteboard:pasteboard source:source slideBack:YES];
 }
 
 @end
diff --git a/WebKit/WebCoreSupport.subproj/WebBridge.m b/WebKit/WebCoreSupport.subproj/WebBridge.m
index 6d43bea..3e010a6 100644
--- a/WebKit/WebCoreSupport.subproj/WebBridge.m
+++ b/WebKit/WebCoreSupport.subproj/WebBridge.m
@@ -987,11 +987,18 @@ static BOOL loggedObjectCacheSize = NO;
     return [type length] == 0 ? @"application/octet-stream" : type;
 }
 
-- (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event
+- (void)allowDHTMLDrag:(BOOL *)flagDHTML UADrag:(BOOL *)flagUA
+{
+    // FIXME: call up to the WebView, then out to the delegate for the drag action
+    *flagDHTML = YES;
+    *flagUA = YES;
+}
+
+- (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData
 {
     WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
     ASSERT([docView isKindOfClass:[WebHTMLView class]]);
-    return [docView _startDraggingImage:dragImage at:dragLoc operation:op event:event];
+    return [docView _startDraggingImage:dragImage at:dragLoc operation:op event:event sourceIsDHTML:flag DHTMLWroteData:dhtmlWroteData];
 }
 
 - (void)setDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 132b057..1390a7e 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -783,7 +783,7 @@ static WebHTMLView *lastHitView = nil;
     return dragImage;
 }
 
-- (BOOL)_startDraggingImage:(NSImage *)wcDragImage at:(NSPoint)wcDragLoc operation:(NSDragOperation)op event:(NSEvent *)mouseDraggedEvent
+- (BOOL)_startDraggingImage:(NSImage *)wcDragImage at:(NSPoint)wcDragLoc operation:(NSDragOperation)op event:(NSEvent *)mouseDraggedEvent sourceIsDHTML:(BOOL)srcIsDHTML DHTMLWroteData:(BOOL)dhtmlWroteData
 {
     // Once we start a drag session we may not get a mouseup, so clear this out here as well as mouseUp:
     _private->firstMouseDownEvent = nil;
@@ -801,28 +801,47 @@ static WebHTMLView *lastHitView = nil;
     NSPoint mouseDraggedPoint = [self convertPoint:[mouseDraggedEvent locationInWindow] fromView:nil];
     _private->webCoreDragOp = op;     // will be DragNone if WebCore doesn't care
     NSImage *dragImage = nil;
-    
-    if (imageURL) {
+    NSPoint dragLoc;
+
+    // We allow WebCore to override the drag image, even if its a link, image or text we're dragging.
+    // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp.
+    // We could verify that ActionDHTML is allowed, although WebCore does claim to respect the action.
+    if (wcDragImage) {
+        dragImage = wcDragImage;
+        // wcDragLoc is the cursor position relative to the lower-left corner of the image.
+        // We add in the Y dimension because we are a flipped view, so adding moves the image down.
+        if (linkURL) {
+            // see HACK below
+            dragLoc = NSMakePoint(mouseDraggedPoint.x - wcDragLoc.x, mouseDraggedPoint.y + wcDragLoc.y);
+        } else {
+            dragLoc = NSMakePoint(mouseDownPoint.x - wcDragLoc.x, mouseDownPoint.y + wcDragLoc.y);
+        }
+    } else if (imageURL) {
+        // This image is only for the benefit of the delegate!?  _web_dragImage figures out its own version
         dragImage = [[[element objectForKey:WebElementImageKey] copy] autorelease];
         [dragImage _web_dissolveToFraction:WebDragImageAlpha];
+        dragLoc = NSZeroPoint;  // unused below, _web_dragImage figures out the location
     } else if (linkURL) {
         dragImage = [self _dragImageForLinkElement:element];
+        NSSize offset = NSMakeSize([dragImage size].width / 2, -DRAG_LABEL_BORDER_Y);
+        dragLoc = NSMakePoint(mouseDraggedPoint.x - offset.width, mouseDraggedPoint.y - offset.height);
     } else if (isSelected) {
         dragImage = [[self _bridge] selectionImage];
         [dragImage _web_dissolveToFraction:WebDragImageAlpha];
+        NSRect visibleSelectionRect = [[self _bridge] visibleSelectionRect];
+        dragLoc = NSMakePoint(NSMinX(visibleSelectionRect), NSMaxY(visibleSelectionRect));
     } else {
-        //FIXME - for which of these types should WC control the image?
-        if (wcDragImage) {
-            dragImage = wcDragImage;
-        } else {
-            NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"missing_image" ofType:@"tiff"];
-            dragImage = [[[NSImage alloc] initWithContentsOfFile:imagePath] autorelease];
-        }
+        ASSERT(srcIsDHTML);
+        // WebCore should have given us an image, but we'll make one up
+        NSString *imagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"missing_image" ofType:@"tiff"];
+        dragImage = [[[NSImage alloc] initWithContentsOfFile:imagePath] autorelease];
+        NSSize imageSize = [dragImage size];
+        dragLoc = NSMakePoint(mouseDownPoint.x - imageSize.width/2, mouseDownPoint.y + imageSize.height/2);
     }
     
     ASSERT(dragImage != nil);
-    
     WebView *webView = [self _webView];
+    //??? use srcIsDHTML to determine DragDestAction
     if (![[webView _UIDelegateForwarder] webView:webView
                        shouldBeginDragForElement:element 
                                        dragImage:dragImage 
@@ -831,6 +850,7 @@ static WebHTMLView *lastHitView = nil;
         return YES;   
     }
     
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
     // note per kwebster, the offset arg below is always ignored in positioning the image
     if (imageURL) {
         _private->draggingImageURL = [imageURL retain];
@@ -841,50 +861,43 @@ static WebHTMLView *lastHitView = nil;
                         rect:[[element objectForKey:WebElementImageRectKey] rectValue]
                          URL:linkURL ? linkURL : imageURL
                        title:[element objectForKey:WebElementImageAltStringKey]
-                       event:_private->mouseDownEvent];
-        
+                       event:_private->mouseDownEvent
+                   dragImage:wcDragImage
+                dragLocation:wcDragLoc
+             writePasteboard:!dhtmlWroteData];
     } else if (linkURL) {
-        NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
-        NSArray *types = [NSPasteboard _web_writableTypesForURL];
-        [pasteboard declareTypes:types owner:self];
-        [pasteboard _web_writeURL:linkURL andTitle:[element objectForKey:WebElementLinkLabelKey] types:types];
-        NSSize offset = NSMakeSize([dragImage size].width / 2, -DRAG_LABEL_BORDER_Y);
+        if (!dhtmlWroteData) {
+            NSArray *types = [NSPasteboard _web_writableTypesForURL];
+            [pasteboard declareTypes:types owner:self];
+            [pasteboard _web_writeURL:linkURL andTitle:[element objectForKey:WebElementLinkLabelKey] types:types];            
+        }
+        // HACK:  We should pass the mouseDown event instead of the mouseDragged!  This hack gets rid of
+        // a flash of the image at the mouseDown location when the drag starts.
         [self dragImage:dragImage
-                     at:NSMakePoint(mouseDraggedPoint.x - offset.width, mouseDraggedPoint.y - offset.height)
-                 offset:offset
+                     at:dragLoc
+                 offset:NSZeroSize
                   event:mouseDraggedEvent
              pasteboard:pasteboard
                  source:self
               slideBack:NO];
-        
     } else if (isSelected) {
-        NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
-        [self _writeSelectionToPasteboard:pasteboard];
-        NSRect visibleSelectionRect = [[self _bridge] visibleSelectionRect];
+        if (!dhtmlWroteData) {
+            [self _writeSelectionToPasteboard:pasteboard];
+        }
         [self dragImage:dragImage
-                     at:NSMakePoint(NSMinX(visibleSelectionRect), NSMaxY(visibleSelectionRect))
-                 offset:NSMakeSize(mouseDraggedPoint.x - mouseDownPoint.x, mouseDraggedPoint.y - mouseDownPoint.y)
+                     at:dragLoc
+                 offset:NSZeroSize
                   event:_private->mouseDownEvent
              pasteboard:pasteboard
                  source:self
               slideBack:YES];
     } else {
         // FIXME - need slideback control for WC
-        // FIXME - is offset totally ignored by the CG-based system? seems like it to me
-        NSPoint dragLoc;
-        if (wcDragImage) {
-            // wcDragLoc is the cursor position relative to the lower-left corner of the image.
-            // We add in the Y dimension because we are a flipped view, so adding moves the image down.
-            dragLoc = NSMakePoint(mouseDownPoint.x - wcDragLoc.x, mouseDownPoint.y + wcDragLoc.y);
-        } else {
-            NSSize imageSize = [dragImage size];
-            dragLoc = NSMakePoint(mouseDownPoint.x - imageSize.width/2, mouseDownPoint.y + imageSize.height/2);
-        }
         [self dragImage:dragImage
                      at:dragLoc
-                 offset:NSMakeSize(mouseDraggedPoint.x - mouseDownPoint.x, mouseDraggedPoint.y - mouseDownPoint.y)
+                 offset:NSZeroSize
                   event:_private->mouseDownEvent
-             pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
+             pasteboard:pasteboard
                  source:self
               slideBack:YES];
     }
@@ -1845,7 +1858,7 @@ static void FlipImageSpec(CoreDragImageSpec* imageSpec) {
         // Handle the drag directly instead of getting callbacks from WebCore.
         // FIXME - how does this play with DHTML dragging?
         if ([self _mayStartDragWithMouseDragged:event]) {
-            [self _startDraggingImage:nil at:NSZeroPoint operation:NSDragOperationNone event:event];
+            [self _startDraggingImage:nil at:NSZeroPoint operation:NSDragOperationNone event:event sourceIsDHTML:NO DHTMLWroteData:NO];
         }
     } else if (!_private->ignoringMouseDraggedEvents) {
         [[self _bridge] mouseDragged:event];
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.h b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
index 667fe20..444bd70 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.h
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
@@ -45,7 +45,7 @@
 - (void)_frameOrBoundsChanged;
 
 - (NSImage *)_dragImageForLinkElement:(NSDictionary *)element;
-- (BOOL)_startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event;
+- (BOOL)_startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData;
 - (void)_setDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc;
 - (void)_handleAutoscrollForMouseDragged:(NSEvent *)event;
 - (BOOL)_mayStartDragWithMouseDragged:(NSEvent *)event;
diff --git a/WebKit/WebView.subproj/WebImageView.m b/WebKit/WebView.subproj/WebImageView.m
index d969caa..99c34ef 100644
--- a/WebKit/WebView.subproj/WebImageView.m
+++ b/WebKit/WebView.subproj/WebImageView.m
@@ -248,7 +248,10 @@
                     rect:[self drawingRect]
                      URL:[rep URL]
                    title:nil
-                   event:mouseDraggedEvent];
+                   event:mouseDraggedEvent
+               dragImage:nil
+            dragLocation:NSZeroPoint
+         writePasteboard:YES];
 }
 
 - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list