Commit 5ae15617 authored by darin@apple.com's avatar darin@apple.com

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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153978 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bd6c5771
2013-06-16 Darin Adler <darin@apple.com>
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 <rniwa@webkit.org>
Fix NULL de-refernce in HTMLAnchorElement::sendPings when settings doesn't exist
......@@ -101,9 +101,6 @@ namespace WebCore {
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 @@ namespace WebCore {
#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)
......
......@@ -701,14 +701,11 @@ static Image* getImage(Element* element)
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 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
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);
......
......@@ -41,12 +41,9 @@ namespace WebCore {
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 @@ namespace WebCore {
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;
......
......@@ -64,6 +64,11 @@ const IntSize& DragController::maxDragImageSize()
}
void DragController::cleanupAfterSystemDrag()
{}
{
}
void DragController::declareAndWriteDragImage(Clipboard*, Element*, const KURL&, const String&)
{
}
}
......@@ -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::cleanupAfterSystemDrag()
{
}
void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
{
clipboard->pasteboard().writeImage(element, url, label);
}
}
......@@ -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 @@ void DragController::cleanupAfterSystemDrag()
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)
......@@ -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::cleanupAfterSystemDrag()
{
}
void DragController::declareAndWriteDragImage(Clipboard* clipboard, Element* element, const KURL& url, const String& label)
{
clipboard->pasteboard().writeImage(element, url, label);
}
}
......@@ -66,4 +66,18 @@ void DragController::cleanupAfterSystemDrag()
{
}
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));
}
}
......@@ -131,6 +131,7 @@ public:
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);
......
......@@ -33,13 +33,6 @@ DragImageRef Clipboard::createDragImage(IntPoint&) const
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()
{
......
......@@ -42,9 +42,4 @@ DragImageRef Clipboard::createDragImage(IntPoint& location) const
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);
}
}
......@@ -59,9 +59,6 @@ public:
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;
......
......@@ -272,15 +272,6 @@ void ClipboardIOS::writeURL(const KURL&, const String&, Frame*)
{
}
#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;
......
......@@ -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
{
......
......@@ -56,9 +56,4 @@ DragImageRef Clipboard::createDragImage(IntPoint& location) const
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);
}
}
......@@ -58,31 +58,4 @@ DragImageRef Clipboard::createDragImage(IntPoint& dragLocation) const
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
......@@ -504,8 +504,6 @@ void Pasteboard::writePlainTextToDataObject(const String& text, SmartReplaceOpti
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 @@ void Pasteboard::writeURLToWritableDataObject(const KURL& url, const String& tit
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment