Diff
Modified: trunk/Source/WebCore/ChangeLog (153977 => 153978)
--- trunk/Source/WebCore/ChangeLog 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/ChangeLog 2013-08-13 05:58:19 UTC (rev 153978)
@@ -1,3 +1,60 @@
+2013-06-16 Darin Adler <[email protected]>
+
+ Move Clipboard::declareAndWriteDragImage to DragController
+ https://bugs.webkit.org/show_bug.cgi?id=117683
+
+ Reviewed by Brent Fulgham.
+
+ * dom/Clipboard.h: Removed declareAndWriteDragImage.
+
+ * page/DragController.cpp:
+ (WebCore::selectImageBeforeDragging): Half of the old prepareClipboardForImageDrag
+ is now refactored into this function.
+ (WebCore::DragController::startDrag): Where we called prepareClipboardForImageDrag,
+ instead call selectImageBeforeDragging and declareAndWriteDragImage. This is needed
+ because declareAndWriteDragImage needs to be a member function, for Mac at least.
+
+ * page/DragController.h: Added declareAndWriteDragImage.
+
+ * page/efl/DragControllerEfl.cpp:
+ (WebCore::DragController::declareAndWriteDragImage): Added empty placeholder.
+ It would be better to delete this file rather than having these placeholders.
+ I don't think EFL actually has drag support, and it makes work to have to keep
+ source files up to date that are really unused.
+
+ * page/gtk/DragControllerGtk.cpp:
+ (WebCore::DragController::declareAndWriteDragImage): Added. Calls Pasteboard::writeImage.
+ * page/mac/DragControllerMac.mm:
+ (WebCore::DragController::declareAndWriteDragImage): Added. Calls to DragClient, which
+ does the work.
+ * page/qt/DragControllerQt.cpp:
+ (WebCore::DragController::declareAndWriteDragImage): Added. Calls Pasteboard::writeImage.
+ * page/win/DragControllerWin.cpp:
+ (WebCore::DragController::declareAndWriteDragImage): Added. Uses Pasteboard functions to
+ do the work.
+
+ * platform/Clipboard.h: Changed the pasteboard function to return a non-const reference.
+ For now, it's not clear what const will mean for pasteboards, and it's currently not
+ possible to write to a const pasteboard, which we need to do in the new
+ DragController::declareAndWriteDragImage functions.
+
+ * platform/Pasteboard.h: Added a new writeMarkup function, implemented only for Windows
+ at this time.
+
+ * platform/efl/ClipboardEfl.cpp: Deleted declareAndWriteDragImage.
+ * platform/gtk/ClipboardGtk.cpp: Ditto.
+ * platform/ios/ClipboardIOS.h: Ditto.
+ * platform/ios/ClipboardIOS.mm: Ditto.
+ * platform/mac/ClipboardMac.mm: Ditto.
+ * platform/qt/ClipboardQt.cpp: Ditto.
+ * platform/win/ClipboardWin.cpp: Ditto.
+
+ * platform/win/PasteboardWin.cpp:
+ (WebCore::Pasteboard::writePlainTextToDataObject): Took out a pointless line of code.
+ (WebCore::Pasteboard::writeMarkup): Added. Currently implemented only for Windows.
+ This factors out a significant piece of DragController::declareAndWriteDragImage,
+ and will probably be handy for other platforms later.
+
2013-08-12 Ryosuke Niwa <[email protected]>
Fix NULL de-refernce in HTMLAnchorElement::sendPings when settings doesn't exist
Modified: trunk/Source/WebCore/dom/Clipboard.h (153977 => 153978)
--- trunk/Source/WebCore/dom/Clipboard.h 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/dom/Clipboard.h 2013-08-13 05:58:19 UTC (rev 153978)
@@ -101,9 +101,6 @@
Node* dragImageElement() const { return m_dragImageElement.get(); }
LEGACY_VIRTUAL DragImageRef createDragImage(IntPoint& dragLocation) const LEGACY_PURE;
-#if ENABLE(DRAG_SUPPORT)
- LEGACY_VIRTUAL void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) LEGACY_PURE;
-#endif
LEGACY_VIRTUAL void writeURL(const KURL&, const String&, Frame*) LEGACY_PURE;
LEGACY_VIRTUAL void writeRange(Range*, Frame*) LEGACY_PURE;
LEGACY_VIRTUAL void writePlainText(const String&) LEGACY_PURE;
@@ -136,7 +133,7 @@
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS)
static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy);
- const Pasteboard& pasteboard() { return *m_pasteboard; }
+ Pasteboard& pasteboard() { return *m_pasteboard; }
#endif
#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) && ENABLE(DRAG_SUPPORT)
Modified: trunk/Source/WebCore/page/DragController.cpp (153977 => 153978)
--- trunk/Source/WebCore/page/DragController.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/DragController.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -701,14 +701,11 @@
cachedImage->image() : 0;
}
-static void prepareClipboardForImageDrag(Frame* source, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
+static void selectElement(Element* element)
{
- if (node->isContentRichlyEditable()) {
- RefPtr<Range> range = source->document()->createRange();
- range->selectNode(node, ASSERT_NO_EXCEPTION);
- source->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
- }
- clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, source);
+ RefPtr<Range> range = element->document()->createRange();
+ range->selectNode(element);
+ element->document()->frame()->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM));
}
static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage)
@@ -809,14 +806,15 @@
m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y());
}
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false);
- } else if (!imageURL.isEmpty() && element && image && !image->isNull()
- && (m_dragSourceAction & DragSourceActionImage)) {
+ } else if (!imageURL.isEmpty() && element && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) {
// We shouldn't be starting a drag for an image that can't provide an extension.
// This is an early detection for problems encountered later upon drop.
ASSERT(!image->filenameExtension().isEmpty());
if (!clipboard->hasData()) {
m_draggingImageURL = imageURL;
- prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, hitTestResult.altDisplayString());
+ if (element->isContentRichlyEditable())
+ selectElement(element);
+ declareAndWriteDragImage(clipboard, element, !linkURL.isEmpty() ? linkURL : imageURL, hitTestResult.altDisplayString());
}
m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard);
Modified: trunk/Source/WebCore/page/DragController.h (153977 => 153978)
--- trunk/Source/WebCore/page/DragController.h 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/DragController.h 2013-08-13 05:58:19 UTC (rev 153978)
@@ -41,12 +41,9 @@
class Frame;
class FrameSelection;
class HTMLInputElement;
- class Image;
class IntRect;
- class Node;
class Page;
class PlatformMouseEvent;
- class Range;
struct DragSession;
struct DragState;
@@ -113,6 +110,7 @@
void doImageDrag(Element*, const IntPoint&, const IntRect&, Clipboard*, Frame*, IntPoint&);
void doSystemDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool forLink);
void cleanupAfterSystemDrag();
+ void declareAndWriteDragImage(Clipboard*, Element*, const KURL&, const String& label);
Page* m_page;
DragClient* m_client;
Modified: trunk/Source/WebCore/page/efl/DragControllerEfl.cpp (153977 => 153978)
--- trunk/Source/WebCore/page/efl/DragControllerEfl.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/efl/DragControllerEfl.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -64,6 +64,11 @@
}
void DragController::cleanupAfterSystemDrag()
-{}
+{
+}
+void DragController::declareAndWriteDragImage(Clipboard*, Element*, const KURL&, const String&)
+{
}
+
+}
Modified: trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp (153977 => 153978)
--- trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -26,10 +26,13 @@
#include "config.h"
#include "DragController.h"
+#include "Clipboard.h"
#include "DragData.h"
+#include "Element.h"
#include "Frame.h"
#include "FrameView.h"
#include "Page.h"
+#include "Pasteboard.h"
namespace WebCore {
@@ -66,4 +69,9 @@
{
}
+void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
+{
+ clipboard->pasteboard().writeImage(element, url, label);
}
+
+}
Modified: trunk/Source/WebCore/page/mac/DragControllerMac.mm (153977 => 153978)
--- trunk/Source/WebCore/page/mac/DragControllerMac.mm 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/mac/DragControllerMac.mm 2013-08-13 05:58:19 UTC (rev 153978)
@@ -27,10 +27,15 @@
#import "DragController.h"
#if ENABLE(DRAG_SUPPORT)
+#import "Clipboard.h"
+#import "DOMElementInternal.h"
+#import "DragClient.h"
#import "DragData.h"
+#import "Element.h"
#import "Frame.h"
#import "FrameView.h"
#import "Page.h"
+#import "Pasteboard.h"
namespace WebCore {
@@ -79,6 +84,11 @@
dragEnded();
}
+void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
+{
+ client()->declareAndWriteDragImage(clipboard->pasteboard().name(), kit(element), url, label, element->document()->frame());
+}
+
} // namespace WebCore
#endif // ENABLE(DRAG_SUPPORT)
Modified: trunk/Source/WebCore/page/qt/DragControllerQt.cpp (153977 => 153978)
--- trunk/Source/WebCore/page/qt/DragControllerQt.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/qt/DragControllerQt.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -26,10 +26,13 @@
#include "config.h"
#include "DragController.h"
+#include "Clipboard.h"
#include "DragData.h"
+#include "Element.h"
#include "Frame.h"
#include "FrameView.h"
#include "Page.h"
+#include "Pasteboard.h"
namespace WebCore {
@@ -68,4 +71,9 @@
{
}
+void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
+{
+ clipboard->pasteboard().writeImage(element, url, label);
}
+
+}
Modified: trunk/Source/WebCore/page/win/DragControllerWin.cpp (153977 => 153978)
--- trunk/Source/WebCore/page/win/DragControllerWin.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/page/win/DragControllerWin.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -66,4 +66,18 @@
{
}
+void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
+{
+ Pasteboard* pasteboard = clipboard->pasteboard();
+
+ // FIXME: Do we really need this check?
+ if (!pasteboard->writableDataObject())
+ return;
+
+ // Order is important here for Explorer's sake
+ pasteboard->writeURLToWritableDataObject(url, label);
+ pasteboard->writeImageToDataObject(element, url);
+ pasteboard->writeMarkup(createMarkup(element, IncludeNode, 0, ResolveAllURLs));
}
+
+}
Modified: trunk/Source/WebCore/platform/Pasteboard.h (153977 => 153978)
--- trunk/Source/WebCore/platform/Pasteboard.h 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/Pasteboard.h 2013-08-13 05:58:19 UTC (rev 153978)
@@ -131,6 +131,7 @@
bool writeString(const String& type, const String& data);
void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);
+ void writeMarkup(const String& markup);
void writePlainText(const String&, SmartReplaceOption);
#if !PLATFORM(IOS)
void writeURL(const KURL&, const String&, Frame* = 0);
Modified: trunk/Source/WebCore/platform/efl/ClipboardEfl.cpp (153977 => 153978)
--- trunk/Source/WebCore/platform/efl/ClipboardEfl.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/efl/ClipboardEfl.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -33,13 +33,6 @@
return 0;
}
-#if ENABLE(DRAG_SUPPORT)
-void Clipboard::declareAndWriteDragImage(Element*, const KURL&, const String&, Frame*)
-{
- notImplemented();
-}
-#endif
-
#if ENABLE(DATA_TRANSFER_ITEMS)
PassRefPtr<DataTransferItemList> Clipboard::items()
{
Modified: trunk/Source/WebCore/platform/gtk/ClipboardGtk.cpp (153977 => 153978)
--- trunk/Source/WebCore/platform/gtk/ClipboardGtk.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/gtk/ClipboardGtk.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -42,9 +42,4 @@
return 0; // We do not have enough information to create a drag image, use the default icon.
}
-void Clipboard::declareAndWriteDragImage(Element* element, const KURL& url, const String& label, Frame* frame)
-{
- m_pasteboard->writeImage(element->toNode(), url, label);
}
-
-}
Modified: trunk/Source/WebCore/platform/ios/ClipboardIOS.h (153977 => 153978)
--- trunk/Source/WebCore/platform/ios/ClipboardIOS.h 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/ios/ClipboardIOS.h 2013-08-13 05:58:19 UTC (rev 153978)
@@ -59,9 +59,6 @@
virtual void setDragImageElement(Node *, const IntPoint&) OVERRIDE;
virtual DragImageRef createDragImage(IntPoint& dragLoc) const OVERRIDE;
-#if ENABLE(DRAG_SUPPORT)
- virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) OVERRIDE;
-#endif
virtual void writeRange(Range*, Frame*) OVERRIDE;
virtual void writeURL(const KURL&, const String&, Frame*) OVERRIDE;
virtual void writePlainText(const String&) OVERRIDE;
Modified: trunk/Source/WebCore/platform/ios/ClipboardIOS.mm (153977 => 153978)
--- trunk/Source/WebCore/platform/ios/ClipboardIOS.mm 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/ios/ClipboardIOS.mm 2013-08-13 05:58:19 UTC (rev 153978)
@@ -272,15 +272,6 @@
{
}
-#if ENABLE(DRAG_SUPPORT)
-void ClipboardIOS::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
-{
- ASSERT(frame);
- if (Page* page = frame->page())
- page->dragController()->client()->declareAndWriteDragImage(m_pasteboard.get(), kit(element), url, title, frame);
-}
-#endif // ENABLE(DRAG_SUPPORT)
-
DragImageRef ClipboardIOS::createDragImage(IntPoint&) const
{
return 0;
Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (153977 => 153978)
--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm 2013-08-13 05:58:19 UTC (rev 153978)
@@ -40,13 +40,6 @@
#import "PlatformStrategies.h"
namespace WebCore {
-
-void Clipboard::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
-{
- ASSERT(frame);
- if (Page* page = frame->page())
- page->dragController()->client()->declareAndWriteDragImage(m_pasteboard->name(), kit(element), url, title, frame);
-}
DragImageRef Clipboard::createDragImage(IntPoint& location) const
{
Modified: trunk/Source/WebCore/platform/qt/ClipboardQt.cpp (153977 => 153978)
--- trunk/Source/WebCore/platform/qt/ClipboardQt.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/qt/ClipboardQt.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -56,9 +56,4 @@
return 0; // We do not have enough information to create a drag image, use the default icon.
}
-void Clipboard::declareAndWriteDragImage(Element* element, const KURL& url, const String& label, Frame* frame)
-{
- m_pasteboard->writeImage(element->toNode(), url, label);
}
-
-}
Modified: trunk/Source/WebCore/platform/win/ClipboardWin.cpp (153977 => 153978)
--- trunk/Source/WebCore/platform/win/ClipboardWin.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/win/ClipboardWin.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -58,31 +58,4 @@
return result;
}
-#if ENABLE(DRAG_SUPPORT)
-void Clipboard::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame)
-{
- // Order is important here for Explorer's sake
- if (!m_pasteboard->writableDataObject())
- return;
- m_pasteboard->writeURLToWritableDataObject(url, title);
- m_pasteboard->writeImageToDataObject(element, url);
- AtomicString imageURL = element->getAttribute(HTMLNames::srcAttr);
- if (imageURL.isEmpty())
- return;
-
- KURL fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL));
- if (fullURL.isEmpty())
- return;
- STGMEDIUM medium = {0};
- medium.tymed = TYMED_HGLOBAL;
-
- // Put img tag on the clipboard referencing the image
- Vector<char> data;
- markupToCFHTML(createMarkup(element, IncludeNode, 0, ResolveAllURLs), "", data);
- medium.hGlobal = createGlobalData(data);
- if (medium.hGlobal && FAILED(m_pasteboard->writableDataObject()->SetData(htmlFormat(), &medium, TRUE)))
- ::GlobalFree(medium.hGlobal);
-}
-#endif
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (153977 => 153978)
--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2013-08-13 05:55:56 UTC (rev 153977)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2013-08-13 05:58:19 UTC (rev 153978)
@@ -504,8 +504,6 @@
medium.hGlobal = createGlobalData(str);
if (medium.hGlobal && FAILED(m_writableDataObject->SetData(plainTextWFormat(), &medium, TRUE)))
::GlobalFree(medium.hGlobal);
-
- medium.hGlobal = 0;
}
void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
@@ -1056,4 +1054,17 @@
WebCore::writeURL(m_writableDataObject.get(), url, title, true, false);
}
+void Pasteboard::writeMarkup(const String& markup)
+{
+ Vector<char> data;
+ markupToCFHTML(markup, "", data);
+
+ STGMEDIUM medium = {0};
+ medium.tymed = TYMED_HGLOBAL;
+
+ medium.hGlobal = createGlobalData(data);
+ if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
+ GlobalFree(medium.hGlobal);
+}
+
} // namespace WebCore