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

mjs mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:18:20 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 51e8fadcd1464770035a27fa729d26721b96d805
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 2 05:37:36 2003 +0000

    WebCore:
    
            Reviewed by Darin.
    
    	- fixed 3130831 - HOMEPAGE: JavaScript that tries to intercept onmousedown fails, image gets dragged instead
    	- fixed 3125554 - while dragging to select text in a nested frame, you can start dragging a link or image
    
            * kwq/KWQKHTMLPart.h:
            * kwq/KWQKHTMLPart.mm:
    	(KWQKHTMLPart::KWQKHTMLPart): Initialize new mouseDownMayStartDrag
    	and mouseDownMayStartSelect methods.
            (KWQKHTMLPart::khtmlMousePressEvent): Make sure a mouse down
    	won't be used to start a drag or selection if the default action
    	is prevented on the mouse down event.
    	(KWQKHTMLPart::mouseDown): Since the default action wasn't
    	prevented, decide if this might be the start of a drag or
    	selection.
            (KWQKHTMLPart::khtmlMouseMoveEvent): On a drag or selection, call
    	back to the bridge to handle selection or autoscrolling
    	appropriately.
    	* kwq/WebCoreBridge.h: Prototype new methods.
    
    WebKit:
    
    	Reviewed by Darin.
    
    	- fixed 3130831 - HOMEPAGE: JavaScript that tries to intercept onmousedown fails, image gets dragged instead
    	- fixed 3125554 - while dragging to select text in a nested frame, you can start dragging a link or image
    
            * WebCoreSupport.subproj/WebBridge.m:
            (-[WebBridge handleMouseDragged:]): New method; call through the WebHTMLView.
            (-[WebBridge mayStartDragWithMouseDown:]): Likewise.
            (-[WebBridge handleAutoscrollForMouseDragged:]): Likewise.
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView mouseDragged:]): Instead of doing drag handling
    	here, just pass the event to WebCore.
    	(-[WebHTMLView draggedImage:endedAt:operation:]): Send a fake
    	mousemove event instead of sending the current event (likely a
    	mouse up as if it were a mouse move).
            * WebView.subproj/WebHTMLViewPrivate.h:
            * WebView.subproj/WebHTMLViewPrivate.m:
            (-[WebHTMLViewPrivate dealloc]): Release drag element if any.
            (-[WebHTMLView _dragImageForElement:]): New method. Split out the
    	code to make the special drag image for links.
    	(-[WebHTMLView _handleMouseDragged:]): Move all the drag handling
    	here. This method will get called only if WebCore hasn't blocked
    	default drag handling.
            (-[WebHTMLView _handleAutoscrollForMouseDragged:]): Do
    	autoscroll. Autoscroll is still lame, we need a timer.
            (-[WebHTMLView _mayStartDragWithMouseDown:]): Determine if the element
    	is a link or image and so may be dragged; remember the drag element.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3229 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 0a0e940..83f6727 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,25 @@
+2002-12-31  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Darin.
+
+	- fixed 3130831 - HOMEPAGE: JavaScript that tries to intercept onmousedown fails, image gets dragged instead
+	- fixed 3125554 - while dragging to select text in a nested frame, you can start dragging a link or image
+	
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+	(KWQKHTMLPart::KWQKHTMLPart): Initialize new mouseDownMayStartDrag
+	and mouseDownMayStartSelect methods.
+        (KWQKHTMLPart::khtmlMousePressEvent): Make sure a mouse down
+	won't be used to start a drag or selection if the default action
+	is prevented on the mouse down event.
+	(KWQKHTMLPart::mouseDown): Since the default action wasn't
+	prevented, decide if this might be the start of a drag or
+	selection.
+        (KWQKHTMLPart::khtmlMouseMoveEvent): On a drag or selection, call
+	back to the bridge to handle selection or autoscrolling
+	appropriately.
+	* kwq/WebCoreBridge.h: Prototype new methods.
+
 2003-01-01  Darin Adler  <darin at apple.com>
 
         Reviewed by Don.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 0a0e940..83f6727 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,25 @@
+2002-12-31  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Darin.
+
+	- fixed 3130831 - HOMEPAGE: JavaScript that tries to intercept onmousedown fails, image gets dragged instead
+	- fixed 3125554 - while dragging to select text in a nested frame, you can start dragging a link or image
+	
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+	(KWQKHTMLPart::KWQKHTMLPart): Initialize new mouseDownMayStartDrag
+	and mouseDownMayStartSelect methods.
+        (KWQKHTMLPart::khtmlMousePressEvent): Make sure a mouse down
+	won't be used to start a drag or selection if the default action
+	is prevented on the mouse down event.
+	(KWQKHTMLPart::mouseDown): Since the default action wasn't
+	prevented, decide if this might be the start of a drag or
+	selection.
+        (KWQKHTMLPart::khtmlMouseMoveEvent): On a drag or selection, call
+	back to the bridge to handle selection or autoscrolling
+	appropriately.
+	* kwq/WebCoreBridge.h: Prototype new methods.
+
 2003-01-01  Darin Adler  <darin at apple.com>
 
         Reviewed by Don.
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index 8801f10..00b18f6 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -195,6 +195,8 @@ private:
     NSView *_mouseDownView;
     bool _mouseDownWasInSubframe;
     bool _sendingEventToSubview;
+    bool _mouseDownMayStartDrag;
+    bool _mouseDownMayStartSelect;
     
     static NSEvent *_currentEvent;
     static NSResponder *_firstResponderAtMouseDownTime;
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 59bf689..6ccf495 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -123,6 +123,8 @@ KWQKHTMLPart::KWQKHTMLPart()
     , _ownsView(false)
     , _mouseDownView(nil)
     , _sendingEventToSubview(false)
+    , _mouseDownMayStartDrag(false)
+    , _mouseDownMayStartSelect(false)
     , _formSubmittedFlag(false)
 {
     // Must init the cache before connecting to any signals
@@ -760,6 +762,14 @@ bool KWQKHTMLPart::closeURL()
 
 void KWQKHTMLPart::khtmlMousePressEvent(MousePressEvent *event)
 {
+    // If we got the event back, that must mean it wasn't prevented,
+    // so it's allowed to start a drag or selection.
+    if ([_bridge mayStartDragWithMouseDown:_currentEvent]) {
+	_mouseDownMayStartDrag = true;
+    } else {
+	_mouseDownMayStartSelect = true;
+    }
+
     if (!passWidgetMouseDownEventToWidget(event)) {
         // We don't do this at the start of mouse down handling (before calling into WebCore),
         // because we don't want to do it until we know we didn't hit a widget.
@@ -889,14 +899,33 @@ void KWQKHTMLPart::khtmlMouseMoveEvent(MouseMoveEvent *event)
     } else {
     	view = mouseDownViewIfStillGood();
     }
-    if (!view) {
-        KHTMLPart::khtmlMouseMoveEvent(event);
-        return;
+
+    if (view) {
+	_sendingEventToSubview = true;
+	[view mouseDragged:_currentEvent];
+	_sendingEventToSubview = false;
+	return;
     }
-    
-    _sendingEventToSubview = true;
-    [view mouseDragged:_currentEvent];
-    _sendingEventToSubview = false;
+
+    if ([_currentEvent type] == NSLeftMouseDragged) {
+	if (_mouseDownMayStartDrag) {
+	    [_bridge handleMouseDragged:_currentEvent];
+	    return;
+	} else if (_mouseDownMayStartSelect) {
+	    // we use khtml's selection but our own autoscrolling
+	    [_bridge handleAutoscrollForMouseDragged:_currentEvent];
+	} else {
+	    return;
+	}
+    } else {
+	// If we allowed the other side of the bridge to handle a drag
+	// last time, then m_bMousePressed might still be set. So we
+	// clear it now to make sure the next move after a drag
+	// doesn't look like a drag.
+	d->m_bMousePressed = false;
+    }
+
+    KHTMLPart::khtmlMouseMoveEvent(event);
 }
 
 void KWQKHTMLPart::khtmlMouseReleaseEvent(MouseReleaseEvent *event)
@@ -1027,6 +1056,8 @@ void KWQKHTMLPart::mouseDown(NSEvent *event)
 
     QMouseEvent kEvent(QEvent::MouseButtonPress, QPoint([event locationInWindow]),
         buttonForCurrentEvent(), stateForCurrentEvent(), [event clickCount]);
+    _mouseDownMayStartDrag = false;
+    _mouseDownMayStartSelect = false;
     d->m_view->viewportMousePressEvent(&kEvent);
     
     [_firstResponderAtMouseDownTime release];
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index 8692d2d..eaa9095 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -253,6 +253,10 @@ enum FrameBorderStyle {
 
 - (NSString *)MIMETypeForPath:(NSString *)path;
 
+- (void)handleMouseDragged:(NSEvent *)event;
+- (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
+- (BOOL)mayStartDragWithMouseDown:(NSEvent *)event;
+
 @end
 
 // This interface definition allows those who hold a WebCoreBridge * to call all the methods
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 0262e69..c74904b 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,33 @@
+2002-12-31  Maciej Stachowiak  <mjs at apple.com>
+
+	Reviewed by Darin.
+
+	- fixed 3130831 - HOMEPAGE: JavaScript that tries to intercept onmousedown fails, image gets dragged instead
+	- fixed 3125554 - while dragging to select text in a nested frame, you can start dragging a link or image
+
+        * WebCoreSupport.subproj/WebBridge.m:
+        (-[WebBridge handleMouseDragged:]): New method; call through the WebHTMLView.
+        (-[WebBridge mayStartDragWithMouseDown:]): Likewise.
+        (-[WebBridge handleAutoscrollForMouseDragged:]): Likewise.
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView mouseDragged:]): Instead of doing drag handling
+	here, just pass the event to WebCore.
+	(-[WebHTMLView draggedImage:endedAt:operation:]): Send a fake
+	mousemove event instead of sending the current event (likely a
+	mouse up as if it were a mouse move).
+        * WebView.subproj/WebHTMLViewPrivate.h:
+        * WebView.subproj/WebHTMLViewPrivate.m:
+        (-[WebHTMLViewPrivate dealloc]): Release drag element if any.
+        (-[WebHTMLView _dragImageForElement:]): New method. Split out the
+	code to make the special drag image for links.
+	(-[WebHTMLView _handleMouseDragged:]): Move all the drag handling
+	here. This method will get called only if WebCore hasn't blocked
+	default drag handling.
+        (-[WebHTMLView _handleAutoscrollForMouseDragged:]): Do
+	autoscroll. Autoscroll is still lame, we need a timer.
+        (-[WebHTMLView _mayStartDragWithMouseDown:]): Determine if the element
+	is a link or image and so may be dragged; remember the drag element.
+
 2003-01-01  Richard Williamson   <rjw at apple.com>
 
         Correct fix for 3137430 that doesn't always effectively disable
diff --git a/WebKit/WebCoreSupport.subproj/WebBridge.m b/WebKit/WebCoreSupport.subproj/WebBridge.m
index b0df127..71a8279 100644
--- a/WebKit/WebCoreSupport.subproj/WebBridge.m
+++ b/WebKit/WebCoreSupport.subproj/WebBridge.m
@@ -565,4 +565,32 @@ static BOOL loggedObjectCacheSize = NO;
     return [[WebFileTypeMappings sharedMappings] MIMETypeForExtension:extension];
 }
 
+- (void)handleMouseDragged:(NSEvent *)event
+{
+    WebHTMLView *docView = (WebHTMLView *)[[frame webView] documentView];
+
+    ASSERT ([docView isKindOfClass:[WebHTMLView class]]);
+
+    [docView _handleMouseDragged:event];
+}
+
+- (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
+{
+    WebHTMLView *docView = (WebHTMLView *)[[frame webView] documentView];
+
+    ASSERT ([docView isKindOfClass:[WebHTMLView class]]);
+
+    [docView _handleAutoscrollForMouseDragged:event];
+}
+
+- (BOOL)mayStartDragWithMouseDown:(NSEvent *)event
+{
+    WebHTMLView *docView = (WebHTMLView *)[[frame webView] documentView];
+
+    ASSERT ([docView isKindOfClass:[WebHTMLView class]]);
+
+    return [docView _mayStartDragWithMouseDown:event];
+}
+
+
 @end
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 76c6137..91d87f5 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -21,31 +21,13 @@
 #import <WebKit/WebIconLoader.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebNSImageExtras.h>
-#import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
-#import <WebKit/WebPreferences.h>
 #import <WebKit/WebPluginController.h>
-#import <WebKit/WebStringTruncator.h>
 #import <WebKit/WebTextRenderer.h>
 #import <WebKit/WebTextRendererFactory.h>
 #import <WebKit/WebViewPrivate.h>
 
-// Needed for the mouse moved notification.
 #import <AppKit/NSResponder_Private.h>
-
-// These are a little larger than typical because dragging links is a fairly
-// advanced feature that can confuse non-power-users
-#define DragStartXHysteresis  		10.0
-#define DragStartYHysteresis  		10.0
-
-#define DRAG_LABEL_BORDER_X		4.0
-#define DRAG_LABEL_BORDER_Y		2.0
-#define DRAG_LABEL_RADIUS	5
-
-#define MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP	120.0
-
-#import <CoreGraphics/CGStyle.h>
-#import <CoreGraphics/CGSTypes.h>
 #import <CoreGraphics/CGContextGState.h>
 
 @implementation WebHTMLView
@@ -618,7 +600,7 @@
     // drag hysteresis.
     [_private->mouseDownEvent release];
     _private->mouseDownEvent = [event retain];
-    
+
     // Let khtml get a chance to deal with the event.
     [[self _bridge] mouseDown:event];
 }
@@ -642,147 +624,7 @@
 
 - (void)mouseDragged:(NSEvent *)event
 {
-    // If the frame has a provisional data source, this view may be released.
-    // Don't allow drag because drag callbacks will reference this released view.
-    if([[self _frame] provisionalDataSource]){
-        return;
-    }
-    
-    // Ensure that we're visible wrt the event location.
-    BOOL didScroll = [self autoscroll:event];
-
-    NSPoint mouseDownPoint = [_private->mouseDownEvent locationInWindow];
-    if (didScroll){
-        mouseDownPoint.x = -FLT_MAX;
-        mouseDownPoint.y = -FLT_MAX;
-    }
-    
-    // Now do WebKit dragging.
-    float deltaX = ABS([event locationInWindow].x - mouseDownPoint.x);
-    float deltaY = ABS([event locationInWindow].y - mouseDownPoint.y);
-
-    NSPoint point = [self convertPoint:mouseDownPoint fromView:nil];
-    NSDictionary *element = [self _elementAtPoint: point];
-    NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
-    NSURL *imageURL = [element objectForKey: WebElementImageURLKey];
-
-    [_private->draggingImageURL release];
-    _private->draggingImageURL = nil;
-    
-    if ((deltaX >= DragStartXHysteresis || deltaY >= DragStartYHysteresis) && !didScroll){
-        if((imageURL && [[WebPreferences standardPreferences] willLoadImagesAutomatically]) || (!imageURL && linkURL)){
-            
-            if (imageURL){
-                _private->draggingImageURL = [imageURL retain];
-                
-                [self _web_dragPromisedImage:[element objectForKey:WebElementImageKey]
-                                      origin:[[element objectForKey:WebElementImageLocationKey] pointValue]
-                                         URL:linkURL ? linkURL : imageURL
-                                    fileType:[[imageURL path] pathExtension]
-                                       title:[element objectForKey:WebElementImageAltStringKey]
-                                       event:_private->mouseDownEvent];
-            }else if (linkURL) {
-                BOOL drawURLString = YES;
-                BOOL clipURLString = NO;
-                                                
-                NSString *label = [element objectForKey: WebElementLinkLabelKey];
-                NSString *urlString = [linkURL absoluteString];
-                
-                if (!label){
-                    drawURLString = NO;
-                    label = urlString;
-                }
-                
-                // FIXME: This mega-block of code needs to be cleaned-up or put into another method.
-                NSFont *labelFont = [NSFont systemFontOfSize: 12.0];
-                NSFont *urlFont = [NSFont systemFontOfSize: 8.0];
-                NSDictionary *labelAttributes = [NSDictionary dictionaryWithObjectsAndKeys: labelFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
-                NSDictionary *urlAttributes = [NSDictionary dictionaryWithObjectsAndKeys: urlFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
-                NSSize labelSize = [label sizeWithAttributes: labelAttributes];
-                NSSize imageSize, urlStringSize;
-                imageSize.width += labelSize.width + DRAG_LABEL_BORDER_X * 2;
-                imageSize.height += labelSize.height + DRAG_LABEL_BORDER_Y *2;
-                if (drawURLString){
-                    urlStringSize = [urlString sizeWithAttributes: urlAttributes];
-                    imageSize.height += urlStringSize.height;
-                    // Clip the url string to 2.5 times the width of the label.
-                    if (urlStringSize.width > MAX(2.5 * labelSize.width, MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP)){
-                        imageSize.width = MAX((labelSize.width * 2.5) + DRAG_LABEL_BORDER_X * 2, MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP);
-                        clipURLString = YES;
-                    }
-                    else
-                        imageSize.width = MAX(labelSize.width + DRAG_LABEL_BORDER_X * 2, urlStringSize.width + DRAG_LABEL_BORDER_X * 2);
-                }
-                NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
-                [dragImage lockFocus];
-
-                [[NSColor colorWithCalibratedRed: 0.5 green: 0.5 blue: 0.5 alpha: 0.8] set];
-
-                // Drag a rectangle with rounded corners/
-                NSBezierPath *path = [NSBezierPath bezierPath];
-                [path appendBezierPathWithOvalInRect: NSMakeRect(0,0, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
-                [path appendBezierPathWithOvalInRect: NSMakeRect(0,imageSize.height - DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
-                [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2, imageSize.height - DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
-                [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2,0, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
-            
-                [path appendBezierPathWithRect: NSMakeRect(DRAG_LABEL_RADIUS, 0, imageSize.width - DRAG_LABEL_RADIUS * 2, imageSize.height)];
-                [path appendBezierPathWithRect: NSMakeRect(0, DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 10, imageSize.height - 2 * DRAG_LABEL_RADIUS)];
-                [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS - 20,DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 20, imageSize.height - 2 * DRAG_LABEL_RADIUS)];
-                [path fill];
-            
-                // Draw the label with a slight shadow.
-                CGShadowStyle shadow;
-                CGSGenericObj style;
-                
-                shadow.version    = 0;
-                shadow.elevation  = kCGShadowElevationDefault;
-                shadow.azimuth    = 136.869995;
-                shadow.ambient    = 0.317708;
-                shadow.height     = 2.187500;
-                shadow.radius     = 1.875000;
-                shadow.saturation = kCGShadowSaturationDefault;
-                style = CGStyleCreateShadow(&shadow);
-                [NSGraphicsContext saveGraphicsState];
-                CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
-
-                if (drawURLString){
-                    if (clipURLString) {
-                        urlString = [WebStringTruncator rightTruncateString: urlString toWidth:imageSize.width - (DRAG_LABEL_BORDER_X * 2) withFont:urlFont];
-                    }
-                    [urlString drawAtPoint: NSMakePoint(DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y) withAttributes: urlAttributes];
-                }
-                [label drawAtPoint: NSMakePoint (DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y + urlStringSize.height) withAttributes: labelAttributes];
-
-                [NSGraphicsContext restoreGraphicsState];
-                CGStyleRelease(style);
-
-                [dragImage unlockFocus];
-
-                NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
-                [pasteboard _web_writeURL:linkURL andTitle:label withOwner:self];
-
-                NSPoint mousePoint = [self convertPoint:[event locationInWindow] fromView:nil];
-                NSSize centerOffset = NSMakeSize(imageSize.width / 2, -DRAG_LABEL_BORDER_Y);
-                NSPoint imagePoint = NSMakePoint(mousePoint.x - centerOffset.width, mousePoint.y - centerOffset.height);
-
-                [self dragImage:dragImage
-                             at:imagePoint
-                         offset:centerOffset
-                          event:event
-                     pasteboard:pasteboard
-                         source:self
-                      slideBack:NO];
-            }
-            
-            return;
-        }
-    }
-
-    // Give khtml a crack at the event only if we haven't started,
-    // or potentially started, a drag
-    if (!linkURL && !imageURL){
-        [[self _bridge] mouseDragged:event];
-    }
+    [[self _bridge] mouseDragged:event];
 }
 
 - (unsigned)draggingSourceOperationMaskForLocal:(BOOL)isLocal
@@ -794,7 +636,7 @@
 {
     // During a drag, we don't get any mouseMoved or flagsChanged events.
     // So after the drag we need to explicitly update the mouseover state.
-    [self _updateMouseoverWithEvent:[NSApp currentEvent]];
+    [self _updateMouseoverWithFakeEvent];
 
     // Reregister for drag types because they were unregistered before the drag.
     [[self _web_parentWebView] _reregisterDraggedTypes];
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.h b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
index 9daf761..8bc636e 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.h
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
@@ -27,6 +27,7 @@
     BOOL subviewsSetAside;
 
     NSEvent *mouseDownEvent;
+    NSDictionary *dragElement;
 
     NSURL *draggingImageURL;
     
@@ -44,6 +45,7 @@
 
 // Modifier (flagsChanged) tracking SPI
 + (void)_postFlagsChangedEvent:(NSEvent *)flagsChangedEvent;
+- (void)_updateMouseoverWithFakeEvent;
 
 - (NSDictionary *)_elementAtPoint:(NSPoint)point;
 
@@ -59,4 +61,9 @@
 
 - (void)_frameOrBoundsChanged;
 
+- (NSImage *)_dragImageForElement:(NSDictionary *)element;
+- (void)_handleMouseDragged:(NSEvent *)event;
+- (void)_handleAutoscrollForMouseDragged:(NSEvent *)event;
+- (BOOL)_mayStartDragWithMouseDown:(NSEvent *)event;
+
 @end
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.m b/WebKit/WebView.subproj/WebHTMLViewPrivate.m
index 3c11376..24f576f 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.m
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.m
@@ -19,11 +19,31 @@
 #import <WebKit/WebFramePrivate.h>
 #import <WebKit/WebHTMLView.h>
 #import <WebKit/WebImageRenderer.h>
-#import <WebKit/WebNetscapePluginEmbeddedView.h>
+#import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
+#import <WebKit/WebNetscapePluginEmbeddedView.h>
+#import <WebKit/WebPreferences.h>
+#import <WebKit/WebStringTruncator.h>
 #import <WebKit/WebViewPrivate.h>
 #import <WebKit/WebWindowOperationsDelegate.h>
 
+
+// These are a little larger than typical because dragging links is a fairly
+// advanced feature that can confuse non-power-users
+#define DragStartXHysteresis  		10.0
+#define DragStartYHysteresis  		10.0
+
+#define DRAG_LABEL_BORDER_X		4.0
+#define DRAG_LABEL_BORDER_Y		2.0
+#define DRAG_LABEL_RADIUS	5
+
+#define MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP	120.0
+
+#import <CoreGraphics/CGStyle.h>
+#import <CoreGraphics/CGSTypes.h>
+#import <CoreGraphics/CGContextGState.h>
+
+
 static BOOL forceRealHitTest = NO;
 
 @interface NSView (AppKitSecretsIKnowAbout)
@@ -63,6 +83,7 @@ static BOOL forceRealHitTest = NO;
 - (void)dealloc
 {
     [mouseDownEvent release];
+    [dragElement release];
     [draggingImageURL release];
     [super dealloc];
 }
@@ -345,6 +366,173 @@ static BOOL forceRealHitTest = NO;
 #endif
 }
 
+
+-(NSImage *)_dragImageForElement:(NSDictionary *)element
+{
+    NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
+
+    BOOL drawURLString = YES;
+    BOOL clipURLString = NO;
+    
+    NSString *label = [element objectForKey: WebElementLinkLabelKey];
+    NSString *urlString = [linkURL absoluteString];
+    
+    if (!label) {
+	drawURLString = NO;
+	label = urlString;
+    }
+    
+    // FIXME: This mega-block of code needs to be cleaned-up or put into another method.
+    NSFont *labelFont = [NSFont systemFontOfSize: 12.0];
+    NSFont *urlFont = [NSFont systemFontOfSize: 8.0];
+    NSDictionary *labelAttributes = [NSDictionary dictionaryWithObjectsAndKeys: labelFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
+    NSDictionary *urlAttributes = [NSDictionary dictionaryWithObjectsAndKeys: urlFont, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
+    NSSize labelSize = [label sizeWithAttributes: labelAttributes];
+    NSSize imageSize, urlStringSize;
+    imageSize.width += labelSize.width + DRAG_LABEL_BORDER_X * 2;
+    imageSize.height += labelSize.height + DRAG_LABEL_BORDER_Y *2;
+    if (drawURLString) {
+	urlStringSize = [urlString sizeWithAttributes: urlAttributes];
+	imageSize.height += urlStringSize.height;
+	// Clip the url string to 2.5 times the width of the label.
+	if (urlStringSize.width > MAX(2.5 * labelSize.width, MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP)) {
+	    imageSize.width = MAX((labelSize.width * 2.5) + DRAG_LABEL_BORDER_X * 2, MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP);
+	    clipURLString = YES;
+	} else {
+	    imageSize.width = MAX(labelSize.width + DRAG_LABEL_BORDER_X * 2, urlStringSize.width + DRAG_LABEL_BORDER_X * 2);
+	}
+    }
+    NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
+    [dragImage lockFocus];
+    
+    [[NSColor colorWithCalibratedRed: 0.5 green: 0.5 blue: 0.5 alpha: 0.8] set];
+    
+    // Drag a rectangle with rounded corners/
+    NSBezierPath *path = [NSBezierPath bezierPath];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(0,0, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(0,imageSize.height - DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2, imageSize.height - DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS * 2,0, DRAG_LABEL_RADIUS * 2, DRAG_LABEL_RADIUS * 2)];
+    
+    [path appendBezierPathWithRect: NSMakeRect(DRAG_LABEL_RADIUS, 0, imageSize.width - DRAG_LABEL_RADIUS * 2, imageSize.height)];
+    [path appendBezierPathWithRect: NSMakeRect(0, DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 10, imageSize.height - 2 * DRAG_LABEL_RADIUS)];
+    [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DRAG_LABEL_RADIUS - 20,DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS + 20, imageSize.height - 2 * DRAG_LABEL_RADIUS)];
+    [path fill];
+    
+    // Draw the label with a slight shadow.
+    CGShadowStyle shadow;
+    CGSGenericObj style;
+    
+    shadow.version    = 0;
+    shadow.elevation  = kCGShadowElevationDefault;
+    shadow.azimuth    = 136.869995;
+    shadow.ambient    = 0.317708;
+    shadow.height     = 2.187500;
+    shadow.radius     = 1.875000;
+    shadow.saturation = kCGShadowSaturationDefault;
+    style = CGStyleCreateShadow(&shadow);
+    [NSGraphicsContext saveGraphicsState];
+    CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
+    
+    if (drawURLString) {
+	if (clipURLString) {
+	    urlString = [WebStringTruncator rightTruncateString: urlString toWidth:imageSize.width - (DRAG_LABEL_BORDER_X * 2) withFont:urlFont];
+	}
+	[urlString drawAtPoint: NSMakePoint(DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y) withAttributes: urlAttributes];
+    }
+    [label drawAtPoint: NSMakePoint (DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y + urlStringSize.height) withAttributes: labelAttributes];
+    
+    [NSGraphicsContext restoreGraphicsState];
+    CGStyleRelease(style);
+    
+    [dragImage unlockFocus];
+    
+    return dragImage;
+}
+
+- (void)_handleMouseDragged:(NSEvent *)event
+{
+    // If the frame has a provisional data source, this view may be released.
+    // Don't allow drag because drag callbacks will reference this released view.
+    if ([[self _frame] provisionalDataSource]) {
+	return;
+    }
+    
+    NSPoint mouseDownPoint = [_private->mouseDownEvent locationInWindow];
+    float deltaX = ABS([event locationInWindow].x - mouseDownPoint.x);
+    float deltaY = ABS([event locationInWindow].y - mouseDownPoint.y);
+
+    NSDictionary *element = _private->dragElement;
+
+    NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
+    NSURL *imageURL = [element objectForKey: WebElementImageURLKey];
+
+    [_private->draggingImageURL release];
+    _private->draggingImageURL = nil;
+
+    // We must have started over something draggable:
+    ASSERT((imageURL && [[WebPreferences standardPreferences] willLoadImagesAutomatically]) || (!imageURL && linkURL)); 
+
+    // drag hysteresis hasn't ben met yet but we don't want to do
+    // other drag actions like selection.
+    if (deltaX < DragStartXHysteresis && deltaY < DragStartYHysteresis) {
+	return;
+    }
+
+    if (imageURL) {
+	_private->draggingImageURL = [imageURL retain];
+	
+	[self _web_dragPromisedImage:[element objectForKey:WebElementImageKey]
+	      origin:[[element objectForKey:WebElementImageLocationKey] pointValue]
+	      URL:linkURL ? linkURL : imageURL
+	      fileType:[[imageURL path] pathExtension]
+	      title:[element objectForKey:WebElementImageAltStringKey]
+	      event:_private->mouseDownEvent];
+    } else if (linkURL) {
+	NSImage *dragImage = [self _dragImageForElement:element];
+	NSString *label = [element objectForKey: WebElementLinkLabelKey];
+	
+	NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+	[pasteboard _web_writeURL:linkURL andTitle:label withOwner:self];
+	
+	NSSize imageSize = [dragImage size];
+	NSPoint mousePoint = [self convertPoint:[event locationInWindow] fromView:nil];
+	NSSize centerOffset = NSMakeSize(imageSize.width / 2, -DRAG_LABEL_BORDER_Y);
+	NSPoint imagePoint = NSMakePoint(mousePoint.x - centerOffset.width, mousePoint.y - centerOffset.height);
+	
+	[self dragImage:dragImage
+	      at:imagePoint
+	      offset:centerOffset
+	      event:event
+	      pasteboard:pasteboard
+	      source:self
+	      slideBack:NO];
+    }
+}
+
+- (void)_handleAutoscrollForMouseDragged:(NSEvent *)event
+{
+    // FIXME: this really needs to be based on a timer
+    [self autoscroll:event];
+}
+
+- (BOOL)_mayStartDragWithMouseDown:(NSEvent *)event
+{
+    NSPoint mouseDownPoint = [event locationInWindow];
+
+    NSPoint point = [self convertPoint:mouseDownPoint fromView:nil];
+
+    NSDictionary *element = [[self _elementAtPoint: point] retain];
+    [_private->dragElement release];
+    _private->dragElement = element;
+
+    NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
+    NSURL *imageURL = [element objectForKey: WebElementImageURLKey];
+
+    // are we over something draggable?
+    return (imageURL && [[WebPreferences standardPreferences] willLoadImagesAutomatically]) || (!imageURL && linkURL);
+}
+
 @end
 
 @implementation NSView (WebHTMLViewPrivate)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list