Commit 3492e98b authored by enrica@apple.com's avatar enrica@apple.com

Reviewed Adam Roben and Darin Adler.

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: http://svn.webkit.org/repository/webkit/trunk@77870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 280d8e3e
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.
......@@ -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)
......
......@@ -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)
......
......@@ -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());
......
......@@ -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)
......@@ -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);
}
......
......@@ -28,9 +28,16 @@
#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)
......@@ -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
......@@ -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
......
......@@ -27,14 +27,25 @@
#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;
}
}
......@@ -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)
}
}
}
......@@ -26,10 +26,11 @@
#ifndef WCDataObject_h
#define WCDataObject_h
#include <wtf/Forward.h>
#include <wtf/Vector.h>
#include "DragData.h"
#include <ShlObj.h>
#include <objidl.h>