add support for dragging images.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2007 11:08:58 +0000 (11:08 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2007 11:08:58 +0000 (11:08 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27313 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/DragImage.h
WebCore/platform/qt/ClipboardQt.cpp
WebCore/platform/qt/ClipboardQt.h

index 821c70115423641e573d9699df55e0f47b0226c5..4dce2eb2ec589f5563ec09c3add35ff35ee00166 100644 (file)
@@ -1,3 +1,21 @@
+2007-10-31  Lars Knoll  <lars@trolltech.com>
+
+        Reviewed by Simon.
+
+        add support for dragging images.
+
+        WARNING: NO TEST CASES ADDED OR CHANGED
+
+        * platform/DragImage.h:
+        * platform/qt/ClipboardQt.cpp:
+        (WebCore::ClipboardQt::clearData):
+        (WebCore::ClipboardQt::setDragImage):
+        (WebCore::ClipboardQt::setDragImageElement):
+        (WebCore::ClipboardQt::createDragImage):
+        (WebCore::getCachedImage):
+        (WebCore::ClipboardQt::declareAndWriteDragImage):
+        * platform/qt/ClipboardQt.h:
+
 2007-10-31  Lars Knoll  <lars@trolltech.com>
 
         Reviewed by Simon.
index 27e263482fdbdbbeeebedc33ec3051a0fb1a62cb..4c0d257f71517581aa1ca635dfde165577b9a86f 100644 (file)
@@ -37,7 +37,7 @@
 class NSImage;
 #endif
 #elif PLATFORM(QT)
-class QImage;
+class QPixmap;
 #elif PLATFORM(WIN)
 typedef struct HBITMAP__* HBITMAP;
 #elif PLATFORM(WX)
@@ -59,7 +59,7 @@ namespace WebCore {
 #if PLATFORM(MAC)
     typedef RetainPtr<NSImage> DragImageRef;
 #elif PLATFORM(QT)
-    typedef QImage* DragImageRef;
+    typedef QPixmap* DragImageRef;
 #elif PLATFORM(WIN)
     typedef HBITMAP DragImageRef;
 #elif PLATFORM(WX)
index c092e3c95592e399f632868d5ce624891fc2ed6f..1dacf394bc7c1f536fa2bcd5e1e8328983e4075a 100644 (file)
@@ -1,5 +1,7 @@
 /*
  * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Trolltech ASA
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "ClipboardQt.h"
 
-#include "NotImplemented.h"
+#include "CachedImage.h"
+#include "CSSHelper.h"
 #include "DeprecatedString.h"
 #include "Document.h"
+#include "Element.h"
 #include "Frame.h"
+#include "HTMLNames.h"
+#include "Image.h"
 #include "IntPoint.h"
 #include "KURL.h"
 #include "PlatformString.h"
 #include "Range.h"
+#include "RenderImage.h"
 #include "StringHash.h"
 #include <QList>
 #include <QMimeData>
@@ -85,7 +92,7 @@ void ClipboardQt::clearData(const String& type)
         return;
 
     ASSERT(m_writableData);
-    notImplemented();
+    m_writableData->removeFormat(type);
 }
 
 void ClipboardQt::clearAllData() 
@@ -135,34 +142,82 @@ HashSet<String> ClipboardQt::types() const
     return result;
 }
 
-void ClipboardQt::setDragImage(CachedImage*, const IntPoint&
+void ClipboardQt::setDragImage(CachedImage* image, const IntPoint& point
 {
-    if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
-        return;
+    setDragImage(image, 0, point);
+}
 
-    notImplemented();
+void ClipboardQt::setDragImageElement(Node* node, const IntPoint& point)
+{
+    setDragImage(0, node, point);
 }
 
-void ClipboardQt::setDragImageElement(Node*, const IntPoint&)
+void ClipboardQt::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
 {
     if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
         return;
 
-    notImplemented();
+    if (m_dragImage)
+        m_dragImage->deref(this);
+    m_dragImage = image;
+    if (m_dragImage)
+        m_dragImage->ref(this);
+    
+    m_dragLoc = loc;
+    m_dragImageElement = node;
 }
 
 DragImageRef ClipboardQt::createDragImage(IntPoint& dragLoc) const
-{ 
-    notImplemented();
+{
+    if (!m_dragImage)
+        return 0;
+    dragLoc = m_dragLoc;
+    return m_dragImage->image()->getPixmap();
+}
+
+
+static CachedImage* getCachedImage(Element* element)
+{
+    // Attempt to pull CachedImage from element
+    ASSERT(element);
+    RenderObject* renderer = element->renderer();
+    if (!renderer || !renderer->isImage()) 
+        return 0;
+    
+    RenderImage* image = static_cast<RenderImage*>(renderer);
+    if (image->cachedImage() && !image->cachedImage()->errorOccurred())
+        return image->cachedImage();
+
     return 0;
 }
 
-void ClipboardQt::declareAndWriteDragImage(Element*, const KURL&, const String&, Frame* frame) 
+void ClipboardQt::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame) 
 {
     ASSERT(frame);
     ASSERT(m_writableData);
+    Q_UNUSED(url);
+    Q_UNUSED(title);
+
+    //WebCore::writeURL(m_writableDataObject.get(), url, title, true, false);
 
-    notImplemented();
+    CachedImage* cachedImage = getCachedImage(element);
+    if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
+        return;
+    QPixmap *pixmap = cachedImage->image()->getPixmap();
+    if (pixmap)
+        m_writableData->setImageData(pixmap);
+
+    AtomicString imageURL = element->getAttribute(HTMLNames::srcAttr);
+    if (imageURL.isEmpty()) 
+        return;
+
+    String fullURL = frame->document()->completeURL(parseURL(imageURL));
+    if (fullURL.isEmpty()) 
+        return;
+
+    QList<QUrl> urls;
+    urls.append(QUrl(fullURL));
+    m_writableData->setUrls(urls);
 }
 
 void ClipboardQt::writeURL(const KURL& url, const String&, Frame* frame) 
index 0063b4e0dd75a3ddebf9b8b153b555c9b694c296..6e54bcd91e727aeb3f9446c6a013b4a921268238 100644 (file)
@@ -27,6 +27,7 @@
 #define ClipboardQt_h
 
 #include "Clipboard.h"
+#include "CachedResourceClient.h"
 #include "ClipboardAccessPolicy.h"
 
 class QMimeData;
@@ -36,7 +37,7 @@ namespace WebCore {
     class CachedImage;
 
     // State available during IE's events for drag and drop and copy/paste
-    class ClipboardQt : public Clipboard {
+    class ClipboardQt : public Clipboard, public CachedResourceClient {
     public:
         ClipboardQt(ClipboardAccessPolicy policy, const QMimeData* readableClipboard);
         
@@ -66,6 +67,8 @@ namespace WebCore {
         void invalidateWritableData() { m_writableData = 0; }
         
     private:
+        void setDragImage(CachedImage* image, Node *node, const IntPoint &loc);
+        
         const QMimeData* m_readableData;
         QMimeData* m_writableData;
     };