Reviewed Adam Roben and Darin Adler.
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Feb 2011 01:34:24 +0000 (01:34 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Feb 2011 01:34:24 +0000 (01:34 +0000)
Source/WebCore:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775
<rdar://problem/8514409>

* loader/EmptyClients.h: Removed createDragImageFromLink.
* page/DragClient.h: Ditto.
* page/DragController.cpp:
(WebCore::DragController::startDrag): changed call to createDragImageFromLink.
* platform/DragImage.h:
* platform/mac/DragImageMac.mm:
(WebCore::createDragImageForLink): Moved from DragClient.
* platform/win/ClipboardUtilitiesWin.cpp: Added a series of functions
to de-serialize the drag data from the map into an IDataObject.
(WebCore::getWebLocData):
(WebCore::texthtmlFormat):
(WebCore::createGlobalData):
(WebCore::getFullCFHTML):
(WebCore::urlWFormat):
(WebCore::urlFormat):
(WebCore::filenameWFormat):
(WebCore::filenameFormat):
(WebCore::htmlFormat):
(WebCore::smartPasteFormat):
(WebCore::getURL):
(WebCore::getPlainText):
(WebCore::getTextHTML):
(WebCore::ClipboardDataItem::ClipboardDataItem):
(WebCore::getStringData):
(WebCore::getUtf8Data):
(WebCore::getCFData):
(WebCore::setUCharData):
(WebCore::setCharData):
(WebCore::setCFData):
(WebCore::getClipboardMap):
(WebCore::getClipboardData):
(WebCore::setClipboardData):
* platform/win/ClipboardUtilitiesWin.h:
* platform/win/DragImageWin.cpp: Moved createDragImageForLink from DragClient
to a platform specific file in WebCore. It makes a lot more sense here, since
the drag image is always created in WebCore for all the other content types
except for links.
(WebCore::dragLabelFont):
(WebCore::createDragImageForLink):
* platform/win/WCDataObject.cpp: Added new way to
construct a WCDataObject from a DragDataMap.
(WebCore::WCDataObject::createInstance):
(WebCore::WCDataObject::clearData):
* platform/win/WCDataObject.h:

Source/WebKit/chromium:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* src/DragClientImpl.cpp:
* src/DragClientImpl.h:

Source/WebKit/efl:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/DragClientEfl.cpp:
* WebCoreSupport/DragClientEfl.h:

Source/WebKit/gtk:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/DragClientGtk.cpp:
* WebCoreSupport/DragClientGtk.h:

Source/WebKit/haiku:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/DragClientHaiku.cpp:
* WebCoreSupport/DragClientHaiku.h:

Source/WebKit/mac:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/WebDragClient.h:
* WebCoreSupport/WebDragClient.mm:
(WebDragClient::startDrag):

Source/WebKit/qt:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/DragClientQt.cpp:
* WebCoreSupport/DragClientQt.h:

Source/WebKit/win:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/WebDragClient.cpp:
(WebDragClient::startDrag):
* WebCoreSupport/WebDragClient.h:

Source/WebKit/wince:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebCoreSupport/DragClientWinCE.cpp:
* WebCoreSupport/DragClientWinCE.h:

Source/WebKit/wx:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775

Removed createDragImageForLink from DragClient.

* WebKitSupport/DragClientWx.cpp:
* WebKitSupport/DragClientWx.h:

Source/WebKit2:

WebKit2: drag and drop support on Windows.
https://bugs.webkit.org/show_bug.cgi?id=52775
<rdar://problem/8514409>

This patch contains the remaining work to support
a WebKit window as drag source on Windows.
I've added the code to generate the image for dragging a link as
well as the steps necessary to package the HBITMAP into a SharedMemory
object and send it over to the UI process where DoDragDrop is performed.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setDragImage):
(WebKit::WebPageProxy::startDragDrop):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebDragClient.cpp:
(WebKit::WebDragClient::startDrag): Made startDrag for
platforms other than Windows and Mac.
* WebProcess/WebCoreSupport/WebDragClient.h:
* WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
(WebKit::WebDragClient::startDrag):
* WebProcess/WebCoreSupport/win/WebDragClientWin.cpp: Added.
(WebKit::draggingSourceOperationMaskToDragCursors):
(WebKit::WebDragClient::startDrag):
* WebProcess/WebCoreSupport/win/WebDragSource.cpp: Added.
This object implements the IDropSource interface.
(WebDragSource::createInstance):
(WebDragSource::WebDragSource):
(WebDragSource::QueryInterface):
(WebDragSource::AddRef):
(WebDragSource::Release):
(WebDragSource::QueryContinueDrag):
(WebDragSource::GiveFeedback):
* WebProcess/WebCoreSupport/win/WebDragSource.h: Added.
* win/WebKit2.vcproj:

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

50 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/DragClient.h
Source/WebCore/page/DragController.cpp
Source/WebCore/platform/DragImage.cpp
Source/WebCore/platform/DragImage.h
Source/WebCore/platform/mac/DragImageMac.mm
Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp
Source/WebCore/platform/win/ClipboardUtilitiesWin.h
Source/WebCore/platform/win/DragImageWin.cpp
Source/WebCore/platform/win/WCDataObject.cpp
Source/WebCore/platform/win/WCDataObject.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/DragClientImpl.cpp
Source/WebKit/chromium/src/DragClientImpl.h
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/WebCoreSupport/DragClientEfl.cpp
Source/WebKit/efl/WebCoreSupport/DragClientEfl.h
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp
Source/WebKit/gtk/WebCoreSupport/DragClientGtk.h
Source/WebKit/haiku/ChangeLog
Source/WebKit/haiku/WebCoreSupport/DragClientHaiku.cpp
Source/WebKit/haiku/WebCoreSupport/DragClientHaiku.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebDragClient.h
Source/WebKit/mac/WebCoreSupport/WebDragClient.mm
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/DragClientQt.cpp
Source/WebKit/qt/WebCoreSupport/DragClientQt.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebDragClient.cpp
Source/WebKit/win/WebCoreSupport/WebDragClient.h
Source/WebKit/wince/ChangeLog
Source/WebKit/wince/WebCoreSupport/DragClientWinCE.cpp
Source/WebKit/wince/WebCoreSupport/DragClientWinCE.h
Source/WebKit/wx/ChangeLog
Source/WebKit/wx/WebKitSupport/DragClientWx.cpp
Source/WebKit/wx/WebKitSupport/DragClientWx.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.h
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm
Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragClientWin.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.h [new file with mode: 0644]
Source/WebKit2/win/WebKit2.vcproj

index ad1936a..0eb0e39 100644 (file)
@@ -1,3 +1,56 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+        <rdar://problem/8514409>
+
+        * loader/EmptyClients.h: Removed createDragImageFromLink.
+        * page/DragClient.h: Ditto.
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag): changed call to createDragImageFromLink.
+        * platform/DragImage.h:
+        * platform/mac/DragImageMac.mm:
+        (WebCore::createDragImageForLink): Moved from DragClient.
+        * platform/win/ClipboardUtilitiesWin.cpp: Added a series of functions
+        to de-serialize the drag data from the map into an IDataObject.
+        (WebCore::getWebLocData):
+        (WebCore::texthtmlFormat):
+        (WebCore::createGlobalData):
+        (WebCore::getFullCFHTML):
+        (WebCore::urlWFormat):
+        (WebCore::urlFormat):
+        (WebCore::filenameWFormat):
+        (WebCore::filenameFormat):
+        (WebCore::htmlFormat):
+        (WebCore::smartPasteFormat):
+        (WebCore::getURL):
+        (WebCore::getPlainText):
+        (WebCore::getTextHTML):
+        (WebCore::ClipboardDataItem::ClipboardDataItem):
+        (WebCore::getStringData):
+        (WebCore::getUtf8Data):
+        (WebCore::getCFData):
+        (WebCore::setUCharData):
+        (WebCore::setCharData):
+        (WebCore::setCFData):
+        (WebCore::getClipboardMap):
+        (WebCore::getClipboardData):
+        (WebCore::setClipboardData):
+        * platform/win/ClipboardUtilitiesWin.h:
+        * platform/win/DragImageWin.cpp: Moved createDragImageForLink from DragClient
+        to a platform specific file in WebCore. It makes a lot more sense here, since
+        the drag image is always created in WebCore for all the other content types
+        except for links.
+        (WebCore::dragLabelFont):
+        (WebCore::createDragImageForLink):
+        * platform/win/WCDataObject.cpp: Added new way to
+        construct a WCDataObject from a DragDataMap.
+        (WebCore::WCDataObject::createInstance):
+        (WebCore::WCDataObject::clearData):
+        * platform/win/WCDataObject.h:
+
 2011-02-07  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r77848.
index 23faa57..7ac3c4d 100644 (file)
@@ -552,7 +552,6 @@ public:
     virtual DragDestinationAction actionMaskForDrag(DragData*) { return DragDestinationActionNone; }
     virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint&) { return DragSourceActionNone; }
     virtual void startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool) { }
-    virtual DragImageRef createDragImageForLink(KURL&, const String&, Frame*) { return 0; }
     virtual void dragControllerDestroyed() { }
 };
 #endif // ENABLE(DRAG_SUPPORT)
index 4f343a0..8f73baa 100644 (file)
@@ -62,7 +62,6 @@ namespace WebCore {
         virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint& windowPoint) = 0;
         
         virtual void startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame*, bool linkDrag = false) = 0;
-        virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*) = 0;
         
         virtual void dragControllerDestroyed() = 0;
 #if PLATFORM(MAC)
index 849feea..b258e9d 100644 (file)
@@ -739,7 +739,7 @@ bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation s
 
         m_client->willPerformDragSourceAction(DragSourceActionLink, dragOrigin, clipboard);
         if (!dragImage) {
-            dragImage = m_client->createDragImageForLink(linkURL, dragSource.textContent(), src);
+            dragImage = createDragImageForLink(linkURL, dragSource.textContent(), src);
             IntSize size = dragImageSize(dragImage);
             m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset);
             dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
index 5fcafc1..a071466 100644 (file)
@@ -73,6 +73,13 @@ DragImageRef createDragImageForSelection(Frame* frame)
     return image;
 }
 
+#if !PLATFORM(MAC) && !PLATFORM(WIN)
+DragImageRef createDragImageForLink(KURL&, const String&, Frame*)
+{
+    return 0;
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(DRAG_SUPPORT)
index a4aad47..6bd86a6 100644 (file)
@@ -96,6 +96,7 @@ namespace WebCore {
     DragImageRef createDragImageFromImage(Image*);
     DragImageRef createDragImageForSelection(Frame*);    
     DragImageRef createDragImageIconForCachedImage(CachedImage*);
+    DragImageRef createDragImageForLink(KURL&, const String& label, Frame*);
     void deleteDragImage(DragImageRef);
 }
 
index f444b6e..7f540a5 100644 (file)
 
 #if ENABLE(DRAG_SUPPORT)
 #import "CachedImage.h"
+#import "Font.h"
+#import "FontDescription.h"
+#import "FontSelector.h"
 #import "Image.h"
 #import "KURL.h"
 #import "ResourceResponse.h"
+#import "Settings.h"
+#import "StringTruncator.h"
+#import "TextRun.h"
+#import "WebCoreTextRenderer.h"
 
 namespace WebCore {
 
@@ -98,7 +105,101 @@ RetainPtr<NSImage> createDragImageIconForCachedImage(CachedImage* image)
     
     return [[NSWorkspace sharedWorkspace] iconForFileType:extension];
 }
-    
+
+
+const float DragLabelBorderX = 4;
+//Keep border_y in synch with DragController::LinkDragBorderInset
+const float DragLabelBorderY = 2;
+const float DragLabelRadius = 5;
+const float LabelBorderYOffset = 2;
+
+const float MinDragLabelWidthBeforeClip = 120;
+const float MaxDragLabelWidth = 320;
+
+const float DragLinkLabelFontsize = 11;
+const float DragLinkUrlFontSize = 10;
+
+DragImageRef createDragImageForLink(KURL& url, const String& title, Frame* frame)
+{
+    if (!frame)
+        return nil;
+    NSString *label = 0;
+    if (!title.isEmpty())
+        label = title;
+    NSURL *cocoaURL = url;
+    NSString *urlString = [cocoaURL _web_userVisibleString];
+
+    BOOL drawURLString = YES;
+    BOOL clipURLString = NO;
+    BOOL clipLabelString = NO;
+
+    if (!label) {
+        drawURLString = NO;
+        label = urlString;
+    }
+
+    NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DragLinkLabelFontsize]
+                                                           toHaveTrait:NSBoldFontMask];
+    NSFont *urlFont = [NSFont systemFontOfSize:DragLinkUrlFontSize];
+    NSSize labelSize;
+    labelSize.width = [label _web_widthWithFont: labelFont];
+    labelSize.height = [labelFont ascender] - [labelFont descender];
+    if (labelSize.width > MaxDragLabelWidth){
+        labelSize.width = MaxDragLabelWidth;
+        clipLabelString = YES;
+    }
+
+    NSSize imageSize;
+    imageSize.width = labelSize.width + DragLabelBorderX * 2;
+    imageSize.height = labelSize.height + DragLabelBorderY * 2;
+    if (drawURLString) {
+        NSSize urlStringSize;
+        urlStringSize.width = [urlString _web_widthWithFont: urlFont];
+        urlStringSize.height = [urlFont ascender] - [urlFont descender];
+        imageSize.height += urlStringSize.height;
+        if (urlStringSize.width > MaxDragLabelWidth) {
+            imageSize.width = max(MaxDragLabelWidth + DragLabelBorderY * 2, MinDragLabelWidthBeforeClip);
+            clipURLString = YES;
+        } else
+            imageSize.width = max(labelSize.width + DragLabelBorderX * 2, urlStringSize.width + DragLabelBorderX * 2);
+    }
+    NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
+    [dragImage lockFocus];
+
+    [[NSColor colorWithDeviceRed: 0.7f green: 0.7f blue: 0.7f alpha: 0.8f] set];
+
+    // Drag a rectangle with rounded corners
+    NSBezierPath *path = [NSBezierPath bezierPath];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(0, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(0, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
+    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
+
+    [path appendBezierPathWithRect: NSMakeRect(DragLabelRadius, 0, imageSize.width - DragLabelRadius * 2, imageSize.height)];
+    [path appendBezierPathWithRect: NSMakeRect(0, DragLabelRadius, DragLabelRadius + 10, imageSize.height - 2 * DragLabelRadius)];
+    [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DragLabelRadius - 20, DragLabelRadius, DragLabelRadius + 20, imageSize.height - 2 * DragLabelRadius)];
+    [path fill];
+
+    NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
+    NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
+    if (drawURLString) {
+        if (clipURLString)
+            urlString = [WebStringTruncator centerTruncateString: urlString toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:urlFont];
+
+       [urlString _web_drawDoubledAtPoint:NSMakePoint(DragLabelBorderX, DragLabelBorderY - [urlFont descender]) 
+                             withTopColor:topColor bottomColor:bottomColor font:urlFont];
+    }
+
+    if (clipLabelString)
+        label = [WebStringTruncator rightTruncateString: label toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:labelFont];
+    [label _web_drawDoubledAtPoint:NSMakePoint (DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize])
+                      withTopColor:topColor bottomColor:bottomColor font:labelFont];
+
+    [dragImage unlockFocus];
+
+    return dragImage;
+}
+   
 } // namespace WebCore
 
 #endif // ENABLE(DRAG_SUPPORT)
index 629ad99..62a57fc 100644 (file)
@@ -31,6 +31,7 @@
 #include "PlatformString.h"
 #include "TextEncoding.h"
 #include "markup.h"
+#include <shlobj.h>
 #include <shlwapi.h>
 #include <wininet.h> // for INTERNET_MAX_URL_LENGTH
 #include <wtf/StringExtras.h>
@@ -619,7 +620,19 @@ bool containsHTML(const DragDataMap* data)
 }
 
 typedef void (*GetStringFunction)(IDataObject*, FORMATETC*, Vector<String>&);
-typedef HashMap<UINT, GetStringFunction> ClipboardFormatMap;
+typedef void (*SetStringFunction)(IDataObject*, FORMATETC*, const Vector<String>&);
+
+struct ClipboardDataItem {
+    GetStringFunction getString;
+    SetStringFunction setString;
+    FORMATETC* format;
+
+    ClipboardDataItem(FORMATETC* format, GetStringFunction getString, SetStringFunction setString): format(format), getString(getString), setString(setString) { }
+};
+
+typedef HashMap<UINT, ClipboardDataItem*> ClipboardFormatMap;
+
+// Getter functions.
 
 template<typename T> void getStringData(IDataObject* data, FORMATETC* format, Vector<String>& dataStrings)
 {
@@ -642,7 +655,7 @@ void getUtf8Data(IDataObject* data, FORMATETC* format, Vector<String>& dataStrin
 }
 
 #if PLATFORM(CF)
-void getCfData(IDataObject* data, FORMATETC* format, Vector<String>& dataStrings)
+void getCFData(IDataObject* data, FORMATETC* format, Vector<String>& dataStrings)
 {
     STGMEDIUM store;
     if (FAILED(data->GetData(format, &store)))
@@ -665,26 +678,93 @@ void getCfData(IDataObject* data, FORMATETC* format, Vector<String>& dataStrings
 }
 #endif
 
-void getClipboardData(IDataObject *dataObject, FORMATETC* format, Vector<String>& dataStrings)
+// Setter functions.
+
+void setUCharData(IDataObject* data, FORMATETC* format, const Vector<String>& dataStrings)
+{
+    STGMEDIUM medium = {0};
+    medium.tymed = TYMED_HGLOBAL;
+
+    medium.hGlobal = createGlobalData(dataStrings.first());
+    if (!medium.hGlobal)
+        return;
+    data->SetData(format, &medium, FALSE);
+    ::GlobalFree(medium.hGlobal);
+}
+
+void setUtf8Data(IDataObject* data, FORMATETC* format, const Vector<String>& dataStrings)
+{
+    STGMEDIUM medium = {0};
+    medium.tymed = TYMED_HGLOBAL;
+
+    CString charString = dataStrings.first().utf8();
+    size_t stringLength = charString.length();
+    medium.hGlobal = ::GlobalAlloc(GPTR, stringLength + 1);
+    if (!medium.hGlobal)
+        return;
+    char* buffer = static_cast<char*>(::GlobalLock(medium.hGlobal));
+    memcpy(buffer, charString.data(), stringLength);
+    buffer[stringLength] = 0;
+    ::GlobalUnlock(medium.hGlobal);
+    data->SetData(format, &medium, FALSE);
+    ::GlobalFree(medium.hGlobal);
+}
+
+#if PLATFORM(CF)
+void setCFData(IDataObject* data, FORMATETC* format, const Vector<String>& dataStrings)
+{
+    STGMEDIUM medium = {0};
+    SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * (dataStrings.first().length() + 2));
+    medium.hGlobal = ::GlobalAlloc(GHND | GMEM_SHARE, dropFilesSize);
+    if (!medium.hGlobal) 
+        return;
+
+    DROPFILES* dropFiles = reinterpret_cast<DROPFILES *>(::GlobalLock(medium.hGlobal));
+    dropFiles->pFiles = sizeof(DROPFILES);
+    dropFiles->fWide = TRUE;
+    String filename = dataStrings.first();
+    wcscpy(reinterpret_cast<LPWSTR>(dropFiles + 1), filename.charactersWithNullTermination());    
+    ::GlobalUnlock(medium.hGlobal);
+    data->SetData(format, &medium, FALSE);
+    ::GlobalFree(medium.hGlobal);
+}
+#endif
+
+static const ClipboardFormatMap& getClipboardMap()
 {
     static ClipboardFormatMap formatMap;
     if (formatMap.isEmpty()) {
-        formatMap.add(htmlFormat()->cfFormat, getUtf8Data);
-        formatMap.add(texthtmlFormat()->cfFormat, getStringData<UChar>);
-        formatMap.add(plainTextFormat()->cfFormat, getStringData<char>);
-        formatMap.add(plainTextWFormat()->cfFormat, getStringData<UChar>);
+        formatMap.add(htmlFormat()->cfFormat, new ClipboardDataItem(htmlFormat(), getUtf8Data, setUtf8Data));
+        formatMap.add(texthtmlFormat()->cfFormat, new ClipboardDataItem(texthtmlFormat(), getStringData<UChar>, setUCharData));
+        formatMap.add(plainTextFormat()->cfFormat,  new ClipboardDataItem(plainTextFormat(), getStringData<char>, setUtf8Data));
+        formatMap.add(plainTextWFormat()->cfFormat,  new ClipboardDataItem(plainTextWFormat(), getStringData<UChar>, setUCharData));
 #if PLATFORM(CF)
-        formatMap.add(cfHDropFormat()->cfFormat, getCfData);
+        formatMap.add(cfHDropFormat()->cfFormat,  new ClipboardDataItem(cfHDropFormat(), getCFData, setCFData));
 #endif
-        formatMap.add(filenameFormat()->cfFormat, getStringData<char>);
-        formatMap.add(filenameWFormat()->cfFormat, getStringData<UChar>);
-        formatMap.add(urlFormat()->cfFormat, getStringData<char>);
-        formatMap.add(urlWFormat()->cfFormat, getStringData<UChar>);
+        formatMap.add(filenameFormat()->cfFormat,  new ClipboardDataItem(filenameFormat(), getStringData<char>, setUtf8Data));
+        formatMap.add(filenameWFormat()->cfFormat,  new ClipboardDataItem(filenameWFormat(), getStringData<UChar>, setUCharData));
+        formatMap.add(urlFormat()->cfFormat,  new ClipboardDataItem(urlFormat(), getStringData<char>, setUtf8Data));
+        formatMap.add(urlWFormat()->cfFormat,  new ClipboardDataItem(urlWFormat(), getStringData<UChar>, setUCharData));
     }
-    ClipboardFormatMap::iterator found = formatMap.find(format->cfFormat);
+    return formatMap;
+}
+
+void getClipboardData(IDataObject* dataObject, FORMATETC* format, Vector<String>& dataStrings)
+{
+    const ClipboardFormatMap& formatMap = getClipboardMap();
+    ClipboardFormatMap::const_iterator found = formatMap.find(format->cfFormat);
+    if (found == formatMap.end())
+        return;
+    found->second->getString(dataObject, found->second->format, dataStrings);
+}
+
+void setClipboardData(IDataObject* dataObject, UINT format, const Vector<String>& dataStrings)
+{
+    const ClipboardFormatMap& formatMap = getClipboardMap();
+    ClipboardFormatMap::const_iterator found = formatMap.find(format);
     if (found == formatMap.end())
         return;
-    found->second(dataObject, format, dataStrings);
+    found->second->setString(dataObject, found->second->format, dataStrings);
 }
 
 } // namespace WebCore
index d1362b3..36508d4 100644 (file)
@@ -75,6 +75,7 @@ String getCFHTML(IDataObject*, bool& success);
 String getCFHTML(const DragDataMap*);
 
 void getClipboardData(IDataObject*, FORMATETC* fetc, Vector<String>& dataStrings);
+void setClipboardData(IDataObject*, UINT format, const Vector<String>& dataStrings);
 
 } // namespace WebCore
 
index 135e9d0..4e5d168 100644 (file)
 #include "DragImage.h"
 
 #include "CachedImage.h"
+#include "Font.h"
+#include "FontDescription.h"
+#include "FontSelector.h"
+#include "Frame.h"
 #include "GraphicsContext.h"
 #include "Image.h"
 #include "RetainPtr.h"
+#include "Settings.h"
+#include "StringTruncator.h"
+#include "TextRun.h"
+#include "WebCoreTextRenderer.h"
 
 #include <windows.h>
 
 namespace WebCore {
 
+HBITMAP allocImage(HDC, IntSize, PlatformGraphicsContext** targetRef);
+void deallocContext(PlatformGraphicsContext* target);
+
 IntSize dragImageSize(DragImageRef image)
 {
     if (!image)
@@ -79,5 +90,141 @@ DragImageRef createDragImageIconForCachedImage(CachedImage* image)
 
     return iconInfo.hbmColor;
 }
+
+const float DragLabelBorderX = 4;
+// Keep border_y in synch with DragController::LinkDragBorderInset.
+const float DragLabelBorderY = 2;
+const float DragLabelRadius = 5;
+const float LabelBorderYOffset = 2;
+
+const float MinDragLabelWidthBeforeClip = 120;
+const float MaxDragLabelWidth = 200;
+const float MaxDragLabelStringWidth = (MaxDragLabelWidth - 2 * DragLabelBorderX);
+
+const float DragLinkLabelFontsize = 11;
+const float DragLinkUrlFontSize = 10;
+
+static Font dragLabelFont(int size, bool bold, FontRenderingMode renderingMode)
+{
+    NONCLIENTMETRICS metrics;
+    metrics.cbSize = sizeof(metrics);
+    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
+
+    FontDescription description;
+    description.setWeight(bold ? FontWeightBold : FontWeightNormal);
+
+    FontFamily family;
+    family.setFamily(metrics.lfSmCaptionFont.lfFaceName);
+    description.setFamily(family);
+    description.setSpecifiedSize((float)size);
+    description.setComputedSize((float)size);
+    description.setRenderingMode(renderingMode);
+    Font result = Font(description, 0, 0); 
+    result.update(0);
+    return result;
+}
+
+DragImageRef createDragImageForLink(KURL& url, const String& inLabel, Frame* frame)
+{
+    // This is more or less an exact match for the Mac OS X code.
+
+    const Font* labelFont;
+    const Font* urlFont;
+
+    if (frame->settings() && frame->settings()->fontRenderingMode() == AlternateRenderingMode) {
+        static const Font alternateRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, AlternateRenderingMode);
+        static const Font alternateRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, AlternateRenderingMode);
+        labelFont = &alternateRenderingModeLabelFont;
+        urlFont = &alternateRenderingModeURLFont;
+    } else {
+        static const Font normalRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, NormalRenderingMode);
+        static const Font normalRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, NormalRenderingMode);
+        labelFont = &normalRenderingModeLabelFont;
+        urlFont = &normalRenderingModeURLFont;
+    }
+
+    bool drawURLString = true;
+    bool clipURLString = false;
+    bool clipLabelString = false;
+
+    String urlString = url.string(); 
+    String label = inLabel;
+    if (label.isEmpty()) {
+        drawURLString = false;
+        label = urlString;
+    }
+
+    // First step in drawing the link drag image width.
+    TextRun labelRun(label.impl());
+    TextRun urlRun(urlString.impl());
+    IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent());
+
+    if (labelSize.width() > MaxDragLabelStringWidth) {
+        labelSize.setWidth(MaxDragLabelStringWidth);
+        clipLabelString = true;
+    }
+    
+    IntSize urlStringSize;
+    IntSize imageSize(labelSize.width() + DragLabelBorderX * 2, labelSize.height() + DragLabelBorderY * 2);
+
+    if (drawURLString) {
+        urlStringSize.setWidth(urlFont->width(urlRun));
+        urlStringSize.setHeight(urlFont->fontMetrics().ascent() + urlFont->fontMetrics().descent()); 
+        imageSize.setHeight(imageSize.height() + urlStringSize.height());
+        if (urlStringSize.width() > MaxDragLabelStringWidth) {
+            imageSize.setWidth(MaxDragLabelWidth);
+            clipURLString = true;
+        } else
+            imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + DragLabelBorderX * 2);
+    }
+
+    // We now know how big the image needs to be, so we create and
+    // fill the background
+    HBITMAP image = 0;
+    HDC dc = GetDC(0);
+    HDC workingDC = CreateCompatibleDC(dc);
+    if (!workingDC) {
+        ReleaseDC(0, dc);
+        return 0;
+    }
+
+    PlatformGraphicsContext* contextRef;
+    image = allocImage(workingDC, imageSize, &contextRef);
+    if (!image) {
+        DeleteDC(workingDC);
+        ReleaseDC(0, dc);
+        return 0;
+    }
+        
+    SelectObject(workingDC, image);
+    GraphicsContext context(contextRef);
+    // On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha
+    // for drag images on win, so we use 1
+    static const Color backgroundColor(140, 140, 140);
+    static const IntSize radii(DragLabelRadius, DragLabelRadius);
+    IntRect rect(0, 0, imageSize.width(), imageSize.height());
+    context.fillRoundedRect(rect, radii, radii, radii, radii, backgroundColor, ColorSpaceDeviceRGB);
+    // Draw the text
+    static const Color topColor(0, 0, 0, 255); // original alpha = 0.75
+    static const Color bottomColor(255, 255, 255, 127); // original alpha = 0.5
+    if (drawURLString) {
+        if (clipURLString)
+            urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DragLabelBorderX * 2.0f), *urlFont, false);
+        IntPoint textPos(DragLabelBorderX, imageSize.height() - (LabelBorderYOffset + urlFont->fontMetrics().descent()));
+        WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor);
+    }
     
+    if (clipLabelString)
+        label = StringTruncator::rightTruncate(label, imageSize.width() - (DragLabelBorderX * 2.0f), *labelFont, false);
+
+    IntPoint textPos(DragLabelBorderX, DragLabelBorderY + labelFont->pixelSize());
+    WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor);
+
+    deallocContext(contextRef);
+    DeleteDC(workingDC);
+    ReleaseDC(0, dc);
+    return image;
+}
+
 }
index 6b4c859..0c03ce0 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "WCDataObject.h"
 
+#include "ClipboardUtilitiesWin.h"
+#include "DragData.h"
 #include "PlatformString.h"
 
 namespace WebCore {
@@ -160,6 +162,17 @@ HRESULT WCDataObject::createInstance(WCDataObject** result)
     return S_OK;
 }
 
+HRESULT WCDataObject::createInstance(WCDataObject** result, const DragDataMap& dataMap)
+{
+    if (!result)
+        return E_POINTER;
+    *result = new WCDataObject;
+
+    for (DragDataMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it)
+        setClipboardData(*result, it->first, it->second);
+    return S_OK;
+}
+
 WCDataObject::WCDataObject()
 : m_ref(1)
 {
@@ -380,5 +393,4 @@ void WCDataObject::clearData(CLIPFORMAT format)
     }
 }
 
-
 }
index 133115d..e5fa298 100644 (file)
 #ifndef WCDataObject_h
 #define WCDataObject_h
 
-#include <wtf/Forward.h>
-#include <wtf/Vector.h>
+#include "DragData.h"
 #include <ShlObj.h>
 #include <objidl.h>
+#include <wtf/Forward.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -56,6 +57,7 @@ public:
     void clearData(CLIPFORMAT);
     
     static HRESULT createInstance(WCDataObject**);
+    static HRESULT createInstance(WCDataObject**, const DragDataMap&);
 private:
     WCDataObject();
     virtual ~WCDataObject();
index 985ee70..4ae70dd 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+        
+        * src/DragClientImpl.cpp:
+        * src/DragClientImpl.h:
+
 2011-02-04  Charlie Reis  <creis@chromium.org>
 
         Reviewed by Mihai Parparita.
index 9874401..4c896a7 100644 (file)
@@ -96,12 +96,6 @@ void DragClientImpl::startDrag(DragImageRef dragImage,
         offsetPoint);
 }
 
-DragImageRef DragClientImpl::createDragImageForLink(KURL&, const String& label, Frame*)
-{
-    // FIXME
-    return 0;
-}
-
 void DragClientImpl::dragControllerDestroyed()
 {
     // Our lifetime is bound to the WebViewImpl.
index dac7acd..b48206a 100644 (file)
@@ -62,8 +62,6 @@ public:
         WebCore::Clipboard* clipboard,
         WebCore::Frame* frame,
         bool isLinkDrag = false);
-    virtual WebCore::DragImageRef createDragImageForLink(
-        WebCore::KURL&, const WTF::String& label, WebCore::Frame*);
     virtual void dragControllerDestroyed();
 
 private:
index 6d88801..fcff9ad 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/DragClientEfl.cpp:
+        * WebCoreSupport/DragClientEfl.h:
+
 2011-02-07  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Andreas Kling.
index d6610e1..b1f68e0 100644 (file)
@@ -60,11 +60,6 @@ void DragClientEfl::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Cl
     notImplemented();
 }
 
-DragImageRef DragClientEfl::createDragImageForLink(KURL&, const String& label, Frame*)
-{
-    return 0;
-}
-
 void DragClientEfl::dragControllerDestroyed()
 {
     delete this;
index f73116c..ff098a9 100644 (file)
@@ -45,7 +45,6 @@ public:
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint);
 
     virtual void startDrag(WebCore::DragImageRef dragImage, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag = false);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const WTF::String& label, WebCore::Frame*);
 
     virtual void dragControllerDestroyed();
 };
index 16a7089..d6e0946 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/DragClientGtk.cpp:
+        * WebCoreSupport/DragClientGtk.h:
+
 2011-02-07  Joone Hur  <joone.hur@collabora.co.uk>
 
         Reviewed by Martin Robinson.
index 836ec28..33ab4fa 100644 (file)
@@ -151,12 +151,6 @@ void DragClient::drawDragIconWindow(GtkWidget* widget, cairo_t* context)
     cairo_fill(context);
 }
 
-DragImageRef DragClient::createDragImageForLink(KURL&, const String&, Frame*)
-{
-    notImplemented();
-    return 0;
-}
-
 void DragClient::dragControllerDestroyed()
 {
     delete this;
index 3a16ae5..4135ea3 100644 (file)
@@ -50,7 +50,6 @@ namespace WebKit {
         virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint);
 
         virtual void startDrag(WebCore::DragImageRef dragImage, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag = false);
-        virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const WTF::String& label, WebCore::Frame*);
 
         virtual void dragControllerDestroyed();
 
index 62a5dc2..7de886c 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/DragClientHaiku.cpp:
+        * WebCoreSupport/DragClientHaiku.h:
+
 2011-02-07  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Andreas Kling.
index 8964c69..4a8f9f4 100644 (file)
@@ -64,11 +64,5 @@ void DragClientHaiku::startDrag(DragImageRef dragImage, const IntPoint&, const I
     notImplemented();
 }
 
-DragImageRef DragClientHaiku::createDragImageForLink(KURL&, const String&, Frame*)
-{
-    notImplemented();
-    return 0;
-}
-
 } // namespace WebCore
 
index b184322..40860e3 100644 (file)
@@ -39,7 +39,6 @@ namespace WebCore {
         virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*);
         virtual void startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin,
                                const IntPoint& eventPos, Clipboard*, Frame*, bool linkDrag = false);
-        virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*);
     };
 
 } // namespace WebCore
index 132d0e0..a769d1d 100644 (file)
@@ -1,3 +1,16 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/WebDragClient.h:
+        * WebCoreSupport/WebDragClient.mm:
+        (WebDragClient::startDrag):
+
 2011-02-03  Yury Semikhatsky  <yurys@chromium.org>
 
         Reviewed by Pavel Feldman.
index 216a2fb..34a5c2e 100644 (file)
@@ -36,7 +36,6 @@ public:
     virtual void dragControllerDestroyed();
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint);
     virtual void startDrag(WebCore::DragImageRef dragImage, const WebCore::IntPoint& dragPos, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL& url, const WTF::String& label, WebCore::Frame*);
     virtual void declareAndWriteDragImage(NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*);
 private:
     WebView* m_webView;
index b3af658..5a7d597 100644 (file)
 
 using namespace WebCore;
 
-const float DragLabelBorderX = 4;
-//Keep border_y in synch with DragController::LinkDragBorderInset
-const float DragLabelBorderY = 2;
-const float DragLabelRadius = 5;
-const float LabelBorderYOffset = 2;
-
-const float MinDragLabelWidthBeforeClip = 120;
-const float MaxDragLabelWidth = 320;
-
-const float DragLinkLabelFontsize = 11;
-const float DragLinkUrlFontSize = 10;
-
 WebDragClient::WebDragClient(WebView* webView)
     : m_webView(webView) 
 {
@@ -132,87 +120,6 @@ void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const
         [topHTMLView dragImage:dragNSImage at:at offset:NSZeroSize event:event pasteboard:pasteboard source:sourceHTMLView slideBack:YES];
 }
 
-DragImageRef WebDragClient::createDragImageForLink(KURL& url, const String& title, Frame* frame)
-{
-    if (!frame)
-        return nil;
-    NSString *label = 0;
-    if (!title.isEmpty())
-        label = title;
-    NSURL *cocoaURL = url;
-    NSString *urlString = [cocoaURL _web_userVisibleString];
-
-    BOOL drawURLString = YES;
-    BOOL clipURLString = NO;
-    BOOL clipLabelString = NO;
-
-    if (!label) {
-        drawURLString = NO;
-        label = urlString;
-    }
-
-    NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DragLinkLabelFontsize]
-                                                           toHaveTrait:NSBoldFontMask];
-    NSFont *urlFont = [NSFont systemFontOfSize:DragLinkUrlFontSize];
-    NSSize labelSize;
-    labelSize.width = [label _web_widthWithFont: labelFont];
-    labelSize.height = [labelFont ascender] - [labelFont descender];
-    if (labelSize.width > MaxDragLabelWidth){
-        labelSize.width = MaxDragLabelWidth;
-        clipLabelString = YES;
-    }
-
-    NSSize imageSize;
-    imageSize.width = labelSize.width + DragLabelBorderX * 2;
-    imageSize.height = labelSize.height + DragLabelBorderY * 2;
-    if (drawURLString) {
-        NSSize urlStringSize;
-        urlStringSize.width = [urlString _web_widthWithFont: urlFont];
-        urlStringSize.height = [urlFont ascender] - [urlFont descender];
-        imageSize.height += urlStringSize.height;
-        if (urlStringSize.width > MaxDragLabelWidth) {
-            imageSize.width = max(MaxDragLabelWidth + DragLabelBorderY * 2, MinDragLabelWidthBeforeClip);
-            clipURLString = YES;
-        } else
-              imageSize.width = max(labelSize.width + DragLabelBorderX * 2, urlStringSize.width + DragLabelBorderX * 2);
-    }
-    NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
-    [dragImage lockFocus];
-
-    [[NSColor colorWithDeviceRed: 0.7f green: 0.7f blue: 0.7f alpha: 0.8f] set];
-
-    // Drag a rectangle with rounded corners
-    NSBezierPath *path = [NSBezierPath bezierPath];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
-
-    [path appendBezierPathWithRect: NSMakeRect(DragLabelRadius, 0, imageSize.width - DragLabelRadius * 2, imageSize.height)];
-    [path appendBezierPathWithRect: NSMakeRect(0, DragLabelRadius, DragLabelRadius + 10, imageSize.height - 2 * DragLabelRadius)];
-    [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DragLabelRadius - 20, DragLabelRadius, DragLabelRadius + 20, imageSize.height - 2 * DragLabelRadius)];
-    [path fill];
-
-    NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
-    NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
-    if (drawURLString) {
-        if (clipURLString)
-            urlString = [WebStringTruncator centerTruncateString: urlString toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:urlFont];
-
-       [urlString _web_drawDoubledAtPoint:NSMakePoint(DragLabelBorderX, DragLabelBorderY - [urlFont descender]) 
-                             withTopColor:topColor bottomColor:bottomColor font:urlFont];
-    }
-
-    if (clipLabelString)
-        label = [WebStringTruncator rightTruncateString: label toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:labelFont];
-    [label _web_drawDoubledAtPoint:NSMakePoint (DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize])
-                      withTopColor:topColor bottomColor:bottomColor font:labelFont];
-
-    [dragImage unlockFocus];
-
-    return dragImage;
-}
-
 void WebDragClient::declareAndWriteDragImage(NSPasteboard* pasteboard, DOMElement* element, NSURL* URL, NSString* title, WebCore::Frame* frame) 
 {
     ASSERT(pasteboard);
index 93a7cf8..7fd9a33 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/DragClientQt.cpp:
+        * WebCoreSupport/DragClientQt.h:
+
 2011-02-06  Robert Hogan  <robert@webkit.org>
 
         Reviewed by Andreas Kling.
index f136328..8996b52 100644 (file)
@@ -110,9 +110,4 @@ void DragClientQt::startDrag(DragImageRef dragImage, const IntPoint&, const IntP
 }
 
 
-DragImageRef DragClientQt::createDragImageForLink(KURL&, const String&, Frame*)
-{
-    return 0;
-}
-
 } // namespace WebCore
index 4c83191..38b463b 100644 (file)
@@ -37,7 +37,6 @@ public:
     virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint&);
     virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*);    
     virtual void startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame*, bool linkDrag = false);
-    virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*);
 private:
     QWebPage* m_webPage;
 };
index 2d8700d..da62397 100644 (file)
@@ -1,3 +1,16 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/WebDragClient.cpp:
+        (WebDragClient::startDrag):
+        * WebCoreSupport/WebDragClient.h:
+
 2011-02-06  Ryosuke Niwa  <rniwa@webkit.org>
 
         Reviewed by Darin Adler.
index 3ec19c4..c232867 100644 (file)
 #include <WebCore/ClipboardWin.h>
 #include <WebCore/DragController.h>
 #include <WebCore/DragData.h>
-#include <WebCore/Font.h>
-#include <WebCore/FontDescription.h>
-#include <WebCore/FontSelector.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/Page.h>
-#include <WebCore/Settings.h>
-#include <WebCore/StringTruncator.h>
-#include <WebCore/TextRun.h>
-#include <WebCore/WebCoreTextRenderer.h>
 #pragma warning(pop) 
 
-namespace WebCore {
-    HBITMAP allocImage(HDC dc, IntSize size, PlatformGraphicsContext** targetRef);
-    void deallocContext(PlatformGraphicsContext* target);
-}
-
-
-#define DRAG_LABEL_BORDER_X             4
-// Keep border_y in synch with DragController::LinkDragBorderInset
-#define DRAG_LABEL_BORDER_Y             2
-#define DRAG_LABEL_RADIUS               5
-#define DRAG_LABEL_BORDER_Y_OFFSET              2
-
-#define MIN_DRAG_LABEL_WIDTH_BEFORE_CLIP        120
-
-// Observation says max size is 200x200
-#define MAX_DRAG_LABEL_WIDTH                    200
-#define MAX_DRAG_LABEL_STRING_WIDTH             (MAX_DRAG_LABEL_WIDTH - 2 * DRAG_LABEL_BORDER_X)
-
-#define DRAG_LINK_LABEL_FONT_SIZE   11
-#define DRAG_LINK_URL_FONT_SIZE   10
-
 using namespace WebCore;
 
 static DWORD draggingSourceOperationMaskToDragCursors(DragOperation op)
@@ -197,129 +169,6 @@ void WebDragClient::startDrag(DragImageRef image, const IntPoint& imageOrigin, c
     }
 }
 
-static Font dragLabelFont(int size, bool bold, FontRenderingMode renderingMode)
-{
-    NONCLIENTMETRICS metrics;
-    metrics.cbSize = sizeof(metrics);
-    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0);
-    FontDescription desc;
-    desc.setWeight(bold ? FontWeightBold : FontWeightNormal);
-    FontFamily family;
-    family.setFamily(metrics.lfSmCaptionFont.lfFaceName);
-    desc.setFamily(family);
-    desc.setSpecifiedSize((float)size);
-    desc.setComputedSize((float)size);
-    desc.setRenderingMode(renderingMode);
-    Font result = Font(desc, 0, 0); 
-    result.update(0);
-    return result;
-}
-
-DragImageRef WebDragClient::createDragImageForLink(KURL& url, const String& inLabel, Frame* frame)
-{
-    // This is more or less an exact match for the Mac OS X code.
-
-    const Font* labelFont;
-    const Font* urlFont;
-
-    if (frame->settings() && frame->settings()->fontRenderingMode() == AlternateRenderingMode) {
-        static const Font alternateRenderingModeLabelFont = dragLabelFont(DRAG_LINK_LABEL_FONT_SIZE, true, AlternateRenderingMode);
-        static const Font alternateRenderingModeURLFont = dragLabelFont(DRAG_LINK_URL_FONT_SIZE, false, AlternateRenderingMode);
-        labelFont = &alternateRenderingModeLabelFont;
-        urlFont = &alternateRenderingModeURLFont;
-    } else {
-        static const Font normalRenderingModeLabelFont = dragLabelFont(DRAG_LINK_LABEL_FONT_SIZE, true, NormalRenderingMode);
-        static const Font normalRenderingModeURLFont = dragLabelFont(DRAG_LINK_URL_FONT_SIZE, false, NormalRenderingMode);
-        labelFont = &normalRenderingModeLabelFont;
-        urlFont = &normalRenderingModeURLFont;
-    }
-
-    bool drawURLString = true;
-    bool clipURLString = false;
-    bool clipLabelString = false;
-
-    String urlString = url.string(); 
-    String label = inLabel;
-    if (label.isEmpty()) {
-        drawURLString = false;
-        label = urlString;
-    }
-
-    //First step in drawing the link drag image width
-    TextRun labelRun(label.impl());
-    TextRun urlRun(urlString.impl());
-    IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent());
-
-    if (labelSize.width() > MAX_DRAG_LABEL_STRING_WIDTH){
-        labelSize.setWidth(MAX_DRAG_LABEL_STRING_WIDTH);
-        clipLabelString = true;
-    }
-    
-    IntSize urlStringSize;
-    IntSize imageSize(labelSize.width() + DRAG_LABEL_BORDER_X * 2, 
-                      labelSize.height() + DRAG_LABEL_BORDER_Y * 2);
-
-    if (drawURLString) {
-        urlStringSize.setWidth(urlFont->width(urlRun));
-        urlStringSize.setHeight(urlFont->fontMetrics().ascent() + urlFont->fontMetrics().descent()); 
-        imageSize.setHeight(imageSize.height() + urlStringSize.height());
-        if (urlStringSize.width() > MAX_DRAG_LABEL_STRING_WIDTH) {
-            imageSize.setWidth(MAX_DRAG_LABEL_WIDTH);
-            clipURLString = true;
-        } else {
-            imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + DRAG_LABEL_BORDER_X * 2);
-        }
-    }
-
-    // We now know how big the image needs to be, so we create and
-    // fill the background
-    HBITMAP image = 0;
-    HDC dc = GetDC(0);
-    HDC workingDC = CreateCompatibleDC(dc);
-    if (!workingDC) {
-        ReleaseDC(0, dc);
-        return 0;
-    }
-
-    PlatformGraphicsContext* contextRef;
-    image = allocImage(workingDC, imageSize, &contextRef);
-    if (!image) {
-        DeleteDC(workingDC);
-        ReleaseDC(0, dc);
-        return 0;
-    }
-        
-    ::SelectObject(workingDC, image);
-    GraphicsContext context(contextRef);
-    // On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha
-    // for drag images on win, so we use 1
-    static const Color backgroundColor(140, 140, 140);
-    static const IntSize radii(DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS);
-    IntRect rect(0, 0, imageSize.width(), imageSize.height());
-    context.fillRoundedRect(rect, radii, radii, radii, radii, backgroundColor, ColorSpaceDeviceRGB);
-    // Draw the text
-    static const Color topColor(0, 0, 0, 255); //original alpha = 0.75
-    static const Color bottomColor(255, 255, 255, 127); //original alpha = 0.5
-    if (drawURLString) {
-        if (clipURLString)
-            urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DRAG_LABEL_BORDER_X * 2.0f), *urlFont, false);
-        IntPoint textPos(DRAG_LABEL_BORDER_X, imageSize.height() - (DRAG_LABEL_BORDER_Y_OFFSET + urlFont->fontMetrics().descent()));
-        WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor);
-    }
-    
-    if (clipLabelString)
-        label = StringTruncator::rightTruncate(label, imageSize.width() - (DRAG_LABEL_BORDER_X * 2.0f), *labelFont, false);
-
-    IntPoint textPos(DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y + labelFont->pixelSize());
-    WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor);
-
-    deallocContext(contextRef);
-    DeleteDC(workingDC);
-    ReleaseDC(0, dc);
-    return image;
-}
-
 void WebDragClient::dragControllerDestroyed()
 {
     delete this;
index da2d208..303edd6 100644 (file)
@@ -39,7 +39,6 @@ public:
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint&);
     virtual void willPerformDragSourceAction(WebCore::DragSourceAction, const WebCore::IntPoint&, WebCore::Clipboard*);
     virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint&, const WebCore::IntPoint&, WebCore::Clipboard*, WebCore::Frame*, bool);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const WTF::String&, WebCore::Frame*);
 private:
     WebView* m_webView;
 };
index 17e49c9..c3ee10b 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebCoreSupport/DragClientWinCE.cpp:
+        * WebCoreSupport/DragClientWinCE.h:
+
 2011-02-06  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Martin Robinson.
index 1fc4379..904c61a 100644 (file)
@@ -58,12 +58,6 @@ void DragClientWinCE::startDrag(DragImageRef, const IntPoint&, const IntPoint&,
     notImplemented();
 }
 
-DragImageRef DragClientWinCE::createDragImageForLink(KURL&, const String& label, Frame*)
-{
-    notImplemented();
-    return 0;
-}
-
 void DragClientWinCE::dragControllerDestroyed()
 {
     delete this;
index dc5168c..ec81f30 100644 (file)
@@ -38,7 +38,6 @@ public:
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint&);
 
     virtual void startDrag(WebCore::DragImageRef, const WebCore::IntPoint&, const WebCore::IntPoint&, WebCore::Clipboard*, WebCore::Frame*, bool = false);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const WTF::String&, WebCore::Frame*);
 
     virtual void dragControllerDestroyed();
 };
index 5bc3f50..c7db0c4 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+
+        Removed createDragImageForLink from DragClient.
+
+        * WebKitSupport/DragClientWx.cpp:
+        * WebKitSupport/DragClientWx.h:
+
 2011-02-07  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Andreas Kling.
index fb6905b..75744ba 100644 (file)
@@ -68,10 +68,4 @@ void DragClientWx::startDrag(DragImageRef dragImage,
     notImplemented();
 }
 
-DragImageRef DragClientWx::createDragImageForLink(KURL&, const String& label, Frame*)
-{
-    notImplemented();
-    return 0;
-}
-
 }
index afb54fb..45425c4 100644 (file)
@@ -39,7 +39,6 @@ public:
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint&);
         
     virtual void startDrag(WebCore::DragImageRef dragImage, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag = false);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const WTF::String& label, WebCore::Frame*);
 };
 
 }
index c842408..e9c38b7 100644 (file)
@@ -1,3 +1,43 @@
+2011-02-07  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed Adam Roben and Darin Adler.
+
+        WebKit2: drag and drop support on Windows.
+        https://bugs.webkit.org/show_bug.cgi?id=52775
+        <rdar://problem/8514409>
+        
+        This patch contains the remaining work to support
+        a WebKit window as drag source on Windows.
+        I've added the code to generate the image for dragging a link as
+        well as the steps necessary to package the HBITMAP into a SharedMemory
+        object and send it over to the UI process where DoDragDrop is performed.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setDragImage):
+        (WebKit::WebPageProxy::startDragDrop):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebDragClient.cpp:
+        (WebKit::WebDragClient::startDrag): Made startDrag for
+        platforms other than Windows and Mac.
+        * WebProcess/WebCoreSupport/WebDragClient.h:
+        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
+        (WebKit::WebDragClient::startDrag):
+        * WebProcess/WebCoreSupport/win/WebDragClientWin.cpp: Added.
+        (WebKit::draggingSourceOperationMaskToDragCursors):
+        (WebKit::WebDragClient::startDrag):
+        * WebProcess/WebCoreSupport/win/WebDragSource.cpp: Added.
+        This object implements the IDropSource interface.
+        (WebDragSource::createInstance):
+        (WebDragSource::WebDragSource):
+        (WebDragSource::QueryInterface):
+        (WebDragSource::AddRef):
+        (WebDragSource::Release):
+        (WebDragSource::QueryContinueDrag):
+        (WebDragSource::GiveFeedback):
+        * WebProcess/WebCoreSupport/win/WebDragSource.h: Added.
+        * win/WebKit2.vcproj:
+
 2011-02-07  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam Weinig.
index 2c8338c..42fe666 100644 (file)
 #include "WebProtectionSpace.h"
 #include "WebSecurityOrigin.h"
 #include "WebURLRequest.h"
+#if PLATFORM(WIN)
+#include "WebDragSource.h"
+#include <WebCore/BitmapInfo.h>
+#include <WebCore/COMPtr.h>
+#include <WebCore/WCDataObject.h>
+#include <shlobj.h>
+#endif
 #include <WebCore/DragData.h>
 #include <WebCore/FloatRect.h>
 #include <WebCore/MIMETypeRegistry.h>
@@ -667,6 +674,63 @@ void WebPageProxy::setDragImage(const WebCore::IntPoint& clientPosition, const I
 }
 #endif
 
+#if PLATFORM(WIN)
+
+void WebPageProxy::startDragDrop(const IntPoint& imageOrigin, const IntPoint& dragPoint, uint64_t okEffect, 
+    const HashMap<UINT, Vector<String> >& dataMap, const IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag)
+{
+    COMPtr<WCDataObject> dataObject;
+    WCDataObject::createInstance(&dataObject, dataMap);
+
+    RefPtr<SharedMemory> memoryBuffer = SharedMemory::create(dragImageHandle, SharedMemory::ReadOnly);
+    if (!memoryBuffer)
+        return;
+
+    RefPtr<WebDragSource> source = WebDragSource::createInstance();
+    if (!source)
+        return;
+
+    COMPtr<IDragSourceHelper> helper;
+    if (FAILED(::CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper))))
+        return;
+
+    BitmapInfo bitmapInfo = BitmapInfo::create(dragImageSize);
+    void* bits;
+    OwnPtr<HBITMAP> hbmp(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &bits, 0, 0));
+    memcpy(bits, memoryBuffer->data(), memoryBuffer->size());
+
+    SHDRAGIMAGE sdi;
+    sdi.sizeDragImage.cx = bitmapInfo.bmiHeader.biWidth;
+    sdi.sizeDragImage.cy = bitmapInfo.bmiHeader.biHeight;
+    sdi.crColorKey = 0xffffffff;
+    sdi.hbmpDragImage = hbmp.leakPtr();
+    sdi.ptOffset.x = dragPoint.x() - imageOrigin.x();
+    sdi.ptOffset.y = dragPoint.y() - imageOrigin.y();
+    if (isLinkDrag)
+        sdi.ptOffset.y = bitmapInfo.bmiHeader.biHeight - sdi.ptOffset.y;
+
+    helper->InitializeFromBitmap(&sdi, dataObject.get());
+
+    DWORD effect = DROPEFFECT_NONE;
+
+    DragOperation operation = DragOperationNone;
+    if (::DoDragDrop(dataObject.get(), source.get(), okEffect, &effect) == DRAGDROP_S_DROP) {
+        if (effect & DROPEFFECT_COPY)
+            operation = DragOperationCopy;
+        else if (effect & DROPEFFECT_LINK)
+            operation = DragOperationLink;
+        else if (effect & DROPEFFECT_MOVE)
+            operation = DragOperationMove;
+    }
+    POINT globalPoint;
+    ::GetCursorPos(&globalPoint);
+    POINT localPoint = globalPoint;
+    ::ScreenToClient(m_pageClient->nativeWindow(), &localPoint);
+
+    dragEnded(localPoint, globalPoint, operation);
+}
+#endif
+
 void WebPageProxy::dragEnded(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t operation)
 {
     if (!isValid())
index 7529c61..a989568 100644 (file)
@@ -310,6 +310,9 @@ public:
 #if PLATFORM(MAC)
     void setDragImage(const WebCore::IntPoint& clientPosition, const WebCore::IntSize& imageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag);
 #endif
+#if PLATFORM(WIN)
+    void startDragDrop(const WebCore::IntPoint& imagePoint, const WebCore::IntPoint& dragPoint, uint64_t okEffect, const HashMap<UINT, Vector<String> >& dataMap, const WebCore::IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag);
+#endif
     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
 
index f97f3a8..200a390 100644 (file)
@@ -200,4 +200,7 @@ messages -> WebPageProxy {
 #if PLATFORM(MAC)
     SetDragImage(WebCore::IntPoint clientPosition, WebCore::IntSize imageSize, WebKit::SharedMemory::Handle dragImage, bool linkDrag)
 #endif
+#if PLATFORM(WIN)
+    StartDragDrop(WebCore::IntPoint imagePoint, WebCore::IntPoint dragPoint, uint64_t okEffect, HashMap<UINT,Vector<String> > dataMap, WebCore::IntSize dragImageSize, WebKit::SharedMemory::Handle dragImage, bool linkDrag)
+#endif
 }
index 931f487..9e348cd 100644 (file)
@@ -51,16 +51,10 @@ DragSourceAction WebDragClient::dragSourceActionMaskForPoint(const IntPoint& win
     return DragSourceActionAny;
 }
 
-#if !PLATFORM(MAC)
+#if !PLATFORM(MAC) && !PLATFORM(WIN)
 void WebDragClient::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool)
 {
 }
-
-DragImageRef WebDragClient::createDragImageForLink(KURL&, const String&, Frame*)
-{
-    notImplemented();
-    return 0;
-}
 #endif
 
 void WebDragClient::dragControllerDestroyed()
index 6f7cf85..389680a 100644 (file)
@@ -46,7 +46,6 @@ private:
     virtual WebCore::DragSourceAction dragSourceActionMaskForPoint(const WebCore::IntPoint& windowPoint);
 
     virtual void startDrag(WebCore::DragImageRef dragImage, const WebCore::IntPoint& dragImageOrigin, const WebCore::IntPoint& eventPos, WebCore::Clipboard*, WebCore::Frame*, bool linkDrag = false);
-    virtual WebCore::DragImageRef createDragImageForLink(WebCore::KURL&, const String& label, WebCore::Frame*);
 
 #if PLATFORM(MAC)
     virtual void declareAndWriteDragImage(NSPasteboard*, DOMElement*, NSURL*, NSString*, WebCore::Frame*);
index 7338382..66590dc 100644 (file)
@@ -47,18 +47,6 @@ using namespace WebCore;
 
 namespace WebKit {
 
-const float DragLabelBorderX = 4;
-//Keep border_y in synch with DragController::LinkDragBorderInset
-const float DragLabelBorderY = 2;
-const float DragLabelRadius = 5;
-const float LabelBorderYOffset = 2;
-
-const float MinDragLabelWidthBeforeClip = 120;
-const float MaxDragLabelWidth = 320;
-
-const float DragLinkLabelFontsize = 11;
-const float DragLinkUrlFontSize = 10;
-
 using namespace WebCore;
 
 static Font& fontFromNSFont(NSFont *font)
@@ -100,88 +88,6 @@ void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& at, const
     m_page->send(Messages::WebPageProxy::SetDragImage(clientPoint, IntSize([dragNSImage size]), handle, linkDrag));
 }
 
-DragImageRef WebDragClient::createDragImageForLink(KURL& url, const String& title, Frame* frame)
-{
-    if (!frame)
-        return nil;
-    NSString *label = 0;
-    if (!title.isEmpty())
-        label = title;
-    NSURL *cocoaURL = url;
-    NSString *urlString = [cocoaURL _web_userVisibleString];
-    
-    BOOL drawURLString = YES;
-    BOOL clipURLString = NO;
-    BOOL clipLabelString = NO;
-    
-    if (!label) {
-        drawURLString = NO;
-        label = urlString;
-    }
-    
-    NSFont *labelFont = [[NSFontManager sharedFontManager] convertFont:[NSFont systemFontOfSize:DragLinkLabelFontsize]
-                                                           toHaveTrait:NSBoldFontMask];
-    NSFont *urlFont = [NSFont systemFontOfSize:DragLinkUrlFontSize];
-    NSSize labelSize;
-    labelSize.width = [label _web_widthWithFont: labelFont];
-    labelSize.height = [labelFont ascender] - [labelFont descender];
-    if (labelSize.width > MaxDragLabelWidth){
-        labelSize.width = MaxDragLabelWidth;
-        clipLabelString = YES;
-    }
-    
-    NSSize imageSize;
-    imageSize.width = labelSize.width + DragLabelBorderX * 2;
-    imageSize.height = labelSize.height + DragLabelBorderY * 2;
-    if (drawURLString) {
-        NSSize urlStringSize;
-        urlStringSize.width = [urlString _web_widthWithFont: urlFont];
-        urlStringSize.height = [urlFont ascender] - [urlFont descender];
-        imageSize.height += urlStringSize.height;
-        if (urlStringSize.width > MaxDragLabelWidth) {
-            imageSize.width = max(MaxDragLabelWidth + DragLabelBorderY * 2, MinDragLabelWidthBeforeClip);
-            clipURLString = YES;
-        } else
-            imageSize.width = max(labelSize.width + DragLabelBorderX * 2, urlStringSize.width + DragLabelBorderX * 2);
-    }
-    NSImage *dragImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
-    [dragImage lockFocus];
-    
-    [[NSColor colorWithDeviceRed: 0.7f green: 0.7f blue: 0.7f alpha: 0.8f] set];
-    
-    // Drag a rectangle with rounded corners
-    NSBezierPath *path = [NSBezierPath bezierPath];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(0, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, imageSize.height - DragLabelRadius * 2, DragLabelRadius * 2, DragLabelRadius * 2)];
-    [path appendBezierPathWithOvalInRect: NSMakeRect(imageSize.width - DragLabelRadius * 2, 0, DragLabelRadius * 2, DragLabelRadius * 2)];
-    
-    [path appendBezierPathWithRect: NSMakeRect(DragLabelRadius, 0, imageSize.width - DragLabelRadius * 2, imageSize.height)];
-    [path appendBezierPathWithRect: NSMakeRect(0, DragLabelRadius, DragLabelRadius + 10, imageSize.height - 2 * DragLabelRadius)];
-    [path appendBezierPathWithRect: NSMakeRect(imageSize.width - DragLabelRadius - 20, DragLabelRadius, DragLabelRadius + 20, imageSize.height - 2 * DragLabelRadius)];
-    [path fill];
-    
-    NSColor *topColor = [NSColor colorWithDeviceWhite:0.0f alpha:0.75f];
-    NSColor *bottomColor = [NSColor colorWithDeviceWhite:1.0f alpha:0.5f];
-    if (drawURLString) {
-        if (clipURLString)
-            //urlString = [WebStringTruncator centerTruncateString: urlString toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:urlFont];
-            urlString = StringTruncator::centerTruncate(urlString, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(urlFont));       
-        [urlString _web_drawDoubledAtPoint:NSMakePoint(DragLabelBorderX, DragLabelBorderY - [urlFont descender]) 
-                              withTopColor:topColor bottomColor:bottomColor font:urlFont];
-    }
-    
-    if (clipLabelString)
-        //label = [WebStringTruncator rightTruncateString: label toWidth:imageSize.width - (DragLabelBorderX * 2) withFont:labelFont];
-        label = StringTruncator::rightTruncate(label, imageSize.width - (DragLabelBorderX * 2), fontFromNSFont(labelFont));
-    [label _web_drawDoubledAtPoint:NSMakePoint (DragLabelBorderX, imageSize.height - LabelBorderYOffset - [labelFont pointSize])
-                      withTopColor:topColor bottomColor:bottomColor font:labelFont];
-    
-    [dragImage unlockFocus];
-    
-    return dragImage;
-}
-
 static void writeURL(NSPasteboard* pasteboard, NSURL* URL, NSString* title, NSArray* types)
 {
     ASSERT(URL);
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragClientWin.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragClientWin.cpp
new file mode 100644 (file)
index 0000000..7381096
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebDragClient.h"
+
+#include "ShareableBitmap.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebPage.h"
+#include "WebPageProxyMessages.h"
+#include <WebCore/BitmapInfo.h>
+#include <WebCore/COMPtr.h>
+#include <WebCore/ClipboardWin.h>
+#include <WebCore/DragController.h>
+#include <WebCore/Frame.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/Page.h>
+#include <shlobj.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static DWORD draggingSourceOperationMaskToDragCursors(DragOperation op)
+{
+    DWORD result = DROPEFFECT_NONE;
+    if (op == DragOperationEvery)
+        return DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE; 
+    if (op & DragOperationCopy)
+        result |= DROPEFFECT_COPY; 
+    if (op & DragOperationLink)
+        result |= DROPEFFECT_LINK; 
+    if (op & DragOperationMove)
+        result |= DROPEFFECT_MOVE;
+    if (op & DragOperationGeneric)
+        result |= DROPEFFECT_MOVE;
+    return result;
+}
+
+void WebDragClient::startDrag(DragImageRef image, const IntPoint& imageOrigin, const IntPoint& dragPoint, Clipboard* clipboard, Frame* frame, bool isLink)
+{
+    COMPtr<IDataObject> dataObject = static_cast<ClipboardWin*>(clipboard)->dataObject();
+
+    if (!dataObject)
+        return;
+
+    OwnPtr<HDC> bitmapDC(CreateCompatibleDC(0));
+    BITMAPINFO bitmapInfo = {0};
+    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    GetDIBits(bitmapDC.get(), image, 0, 0, 0, &bitmapInfo, DIB_RGB_COLORS);
+    if (bitmapInfo.bmiHeader.biSizeImage <= 0)
+        bitmapInfo.bmiHeader.biSizeImage = bitmapInfo.bmiHeader.biWidth * abs(bitmapInfo.bmiHeader.biHeight) * (bitmapInfo.bmiHeader.biBitCount + 7) / 8;
+    
+    RefPtr<SharedMemory> memoryBuffer = SharedMemory::create(bitmapInfo.bmiHeader.biSizeImage);
+
+    bitmapInfo.bmiHeader.biCompression = BI_RGB;
+    GetDIBits(bitmapDC.get(), image, 0, bitmapInfo.bmiHeader.biHeight, memoryBuffer->data(), &bitmapInfo, DIB_RGB_COLORS);       
+
+    SharedMemory::Handle handle;
+    if (!memoryBuffer->createHandle(handle, SharedMemory::ReadOnly))
+        return;
+    DWORD okEffect = draggingSourceOperationMaskToDragCursors(m_page->corePage()->dragController()->sourceDragOperation());
+    DragData dragData(dataObject.get(), IntPoint(), IntPoint(), DragOperationNone);
+    m_page->send(Messages::WebPageProxy::StartDragDrop(imageOrigin, dragPoint, okEffect, dragData.dragDataMap(), IntSize(bitmapInfo.bmiHeader.biWidth, bitmapInfo.bmiHeader.biHeight), handle, isLink), m_page->pageID());
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.cpp
new file mode 100644 (file)
index 0000000..b4f1414
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "WebDragSource.h"
+
+#include <WebCore/Cursor.h>
+#include <WebCore/DragActions.h>
+#include <WebCore/EventHandler.h>
+#include <WebCore/Frame.h>
+#include <WebCore/Page.h>
+#include <WebCore/PlatformMouseEvent.h>
+#include <wtf/CurrentTime.h>
+
+using namespace WebCore;
+
+PassRefPtr<WebDragSource> WebDragSource::createInstance()
+{
+    return adoptRef(new WebDragSource);
+}
+
+WebDragSource::WebDragSource()
+{
+}
+
+HRESULT WebDragSource::QueryInterface(REFIID riid, void** ppvObject)
+{
+    *ppvObject = 0;
+    if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropSource)) {
+        *ppvObject = this;
+        AddRef();
+
+        return S_OK;
+    }
+
+    return E_NOINTERFACE;
+}
+
+ULONG WebDragSource::AddRef(void)
+{
+    ref();
+    return refCount();
+}
+
+ULONG WebDragSource::Release(void)
+{
+    deref();
+    return refCount();
+}
+
+HRESULT WebDragSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfState)
+{
+    if (fEscapePressed)
+        return DRAGDROP_S_CANCEL;
+
+    if (grfState & (MK_LBUTTON | MK_RBUTTON))
+        return S_OK;
+
+    return DRAGDROP_S_DROP;
+}
+
+HRESULT WebDragSource::GiveFeedback(DWORD dwEffect)
+{
+    return DRAGDROP_S_USEDEFAULTCURSORS;
+}
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.h b/Source/WebKit2/WebProcess/WebCoreSupport/win/WebDragSource.h
new file mode 100644 (file)
index 0000000..c2c5f3f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef WebDragSource_h
+#define WebDragSource_h
+
+#include <WTF/RefCounted.h>
+#include <WebCore/COMPtr.h>
+#include <objidl.h>
+
+class WebDragSource : public IDropSource, public RefCounted<WebDragSource> {
+public:
+    static PassRefPtr<WebDragSource> createInstance();
+
+private:
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);        
+    virtual ULONG STDMETHODCALLTYPE AddRef();
+    virtual ULONG STDMETHODCALLTYPE Release();
+    virtual HRESULT STDMETHODCALLTYPE QueryContinueDrag(BOOL fEscapePressed, DWORD grfState);
+    virtual HRESULT STDMETHODCALLTYPE GiveFeedback(DWORD dwEffect);
+    WebDragSource();
+};
+
+#endif // !WebDragSource_h
index f5fe3b0..c627d24 100755 (executable)
                                        Name="win"
                                        >
                                        <File
+                                               RelativePath="..\WebProcess\WebCoreSupport\win\WebDragClientWin.cpp"
+                                               >
+                                       </File>
+                                       <File
+                                               RelativePath="..\WebProcess\WebCoreSupport\win\WebDragSource.cpp"
+                                               >
+                                       </File>
+                                       <File
+                                               RelativePath="..\WebProcess\WebCoreSupport\win\WebDragSource.h"
+                                               >
+                                       </File>
+                                       <File
                                                RelativePath="..\WebProcess\WebCoreSupport\win\WebContextMenuClientWin.cpp"
                                                >
                                        </File>