Title: [154260] trunk/Source/WebCore
Revision
154260
Author
[email protected]
Date
2013-08-18 21:18:31 -0700 (Sun, 18 Aug 2013)

Log Message

<https://webkit.org/b/119949> Factor Clipboard into drag and non-drag parts

Reviewed by Sam Weinig.

* dom/Clipboard.cpp:
(WebCore::Clipboard::Clipboard): Move the ClipboardType argument to go after the pasteboard.
Initialize strings more efficiently. Put drag-specific data members inside an if statement.
Replace m_clipboardType with m_forDrag.
(WebCore::Clipboard::createForCopyAndPaste): Moved function up to be close to constructor.
Removed explicit clipboard type since constructor now defaults to copy and paste style.
(WebCore::Clipboard::setAccessPolicy): Tweaked comment.
(WebCore::Clipboard::getData): Put drag-specific code inside #if ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setData): Ditto.
(WebCore::Clipboard::files): Ditto.
(WebCore::Clipboard::dropEffect): Added trivial non-drag versions of these functions to
be used when !ENABLE(DRAG_SUPPORT).
(WebCore::Clipboard::setDropEffect): Ditto.
(WebCore::Clipboard::effectAllowed): Ditto.
(WebCore::Clipboard::setEffectAllowed): Ditto.
(WebCore::Clipboard::createForDragAndDrop): Renamed Clipboard::create that takes DragData
to this, and kep the overload that does not as well. Made the DragData argument a const&.
(WebCore::Clipboard::canSetDragImage): Moved down here since it is drag-specific.
(WebCore::Clipboard::updateDragImage): Use m_shouldUpdateDragImage directly insted of
calling a dragStarted function.
(WebCore::dragOpFromIEOp): Moved this function down here to the drag-specific section.
(WebCore::IEOpFromDragOp): Ditto.
(WebCore::Clipboard::sourceOperation): Ditto.
(WebCore::Clipboard::destinationOperation): Ditto.
(WebCore::Clipboard::setSourceOperation): Ditto.
(WebCore::Clipboard::setDestinationOperation): Ditto.

* dom/Clipboard.h: Removed unneeded include of "Node.h" and added and removed forward
class declarations as required. Removed non-helpful comment. Made ClipboardType a private
implementation detail. Moved functions that are not part of the DOM API down to a separate
section lower down in the class, and sorted the functions to match the order they appear
in the IDL file. Removed isForCopyAndPaste and isForDragAndDrop. Changed dropEffect and
effectAllowed to not be inlined. Moved the long comment before canSetDragImage into the
implementation since it's an implementation detail. Since this class is no longer polymorphic,
use only private, not protected. Make m_dragImageElement an Element, not a Node.

* dom/Clipboard.idl: Removed flags to tell bindings how to deal with null strings, since
these string properties can never return null strings anyway.

* page/DragController.cpp:
(WebCore::DragController::dragExited): Updated to call the new createForDragAndDrop function.
(WebCore::DragController::performDrag): Ditto.
(WebCore::DragController::tryDHTMLDrag): Ditto.

* platform/mac/ClipboardMac.mm: Added now-needed include of Element.h since Clipboard.h no
longer includes it.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (154259 => 154260)


--- trunk/Source/WebCore/ChangeLog	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/ChangeLog	2013-08-19 04:18:31 UTC (rev 154260)
@@ -1,3 +1,56 @@
+2013-08-17  Darin Adler  <[email protected]>
+
+        <https://webkit.org/b/119949> Factor Clipboard into drag and non-drag parts
+
+        Reviewed by Sam Weinig.
+
+        * dom/Clipboard.cpp:
+        (WebCore::Clipboard::Clipboard): Move the ClipboardType argument to go after the pasteboard.
+        Initialize strings more efficiently. Put drag-specific data members inside an if statement.
+        Replace m_clipboardType with m_forDrag.
+        (WebCore::Clipboard::createForCopyAndPaste): Moved function up to be close to constructor.
+        Removed explicit clipboard type since constructor now defaults to copy and paste style.
+        (WebCore::Clipboard::setAccessPolicy): Tweaked comment.
+        (WebCore::Clipboard::getData): Put drag-specific code inside #if ENABLE(DRAG_SUPPORT).
+        (WebCore::Clipboard::setData): Ditto.
+        (WebCore::Clipboard::files): Ditto.
+        (WebCore::Clipboard::dropEffect): Added trivial non-drag versions of these functions to
+        be used when !ENABLE(DRAG_SUPPORT).
+        (WebCore::Clipboard::setDropEffect): Ditto.
+        (WebCore::Clipboard::effectAllowed): Ditto.
+        (WebCore::Clipboard::setEffectAllowed): Ditto.
+        (WebCore::Clipboard::createForDragAndDrop): Renamed Clipboard::create that takes DragData
+        to this, and kep the overload that does not as well. Made the DragData argument a const&.
+        (WebCore::Clipboard::canSetDragImage): Moved down here since it is drag-specific.
+        (WebCore::Clipboard::updateDragImage): Use m_shouldUpdateDragImage directly insted of
+        calling a dragStarted function.
+        (WebCore::dragOpFromIEOp): Moved this function down here to the drag-specific section.
+        (WebCore::IEOpFromDragOp): Ditto.
+        (WebCore::Clipboard::sourceOperation): Ditto.
+        (WebCore::Clipboard::destinationOperation): Ditto.
+        (WebCore::Clipboard::setSourceOperation): Ditto.
+        (WebCore::Clipboard::setDestinationOperation): Ditto.
+
+        * dom/Clipboard.h: Removed unneeded include of "Node.h" and added and removed forward
+        class declarations as required. Removed non-helpful comment. Made ClipboardType a private
+        implementation detail. Moved functions that are not part of the DOM API down to a separate
+        section lower down in the class, and sorted the functions to match the order they appear
+        in the IDL file. Removed isForCopyAndPaste and isForDragAndDrop. Changed dropEffect and
+        effectAllowed to not be inlined. Moved the long comment before canSetDragImage into the
+        implementation since it's an implementation detail. Since this class is no longer polymorphic,
+        use only private, not protected. Make m_dragImageElement an Element, not a Node.
+
+        * dom/Clipboard.idl: Removed flags to tell bindings how to deal with null strings, since
+        these string properties can never return null strings anyway.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::dragExited): Updated to call the new createForDragAndDrop function.
+        (WebCore::DragController::performDrag): Ditto.
+        (WebCore::DragController::tryDHTMLDrag): Ditto.
+
+        * platform/mac/ClipboardMac.mm: Added now-needed include of Element.h since Clipboard.h no
+        longer includes it.
+
 2013-08-18  David Kilzer  <[email protected]>
 
         WebCore fails to build with trunk clang: error: 'register' storage class specifier is deprecated [-Werror,-Wdeprecated-register]

Modified: trunk/Source/WebCore/dom/Clipboard.cpp (154259 => 154260)


--- trunk/Source/WebCore/dom/Clipboard.cpp	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/dom/Clipboard.cpp	2013-08-19 04:18:31 UTC (rev 154260)
@@ -56,17 +56,28 @@
 
 #endif
 
-Clipboard::Clipboard(ClipboardAccessPolicy policy, ClipboardType clipboardType, PassOwnPtr<Pasteboard> pasteboard, bool forFileDrag)
+Clipboard::Clipboard(ClipboardAccessPolicy policy, PassOwnPtr<Pasteboard> pasteboard, ClipboardType type, bool forFileDrag)
     : m_policy(policy)
-    , m_dropEffect("uninitialized")
-    , m_effectAllowed("uninitialized")
-    , m_dragStarted(false)
-    , m_clipboardType(clipboardType)
     , m_pasteboard(pasteboard)
+#if ENABLE(DRAG_SUPPORT)
+    , m_forDrag(type != CopyAndPaste)
     , m_forFileDrag(forFileDrag)
+    , m_dropEffect(ASCIILiteral("uninitialized"))
+    , m_effectAllowed(ASCIILiteral("uninitialized"))
+    , m_shouldUpdateDragImage(false)
+#endif
 {
+#if !ENABLE(DRAG_SUPPORT)
+    ASSERT_UNUSED(type, type == CopyAndPaste);
+    ASSERT_UNUSED(forFileDrag, !forFileDrag);
+#endif
 }
 
+PassRefPtr<Clipboard> Clipboard::createForCopyAndPaste(ClipboardAccessPolicy policy)
+{
+    return adoptRef(new Clipboard(policy, policy == ClipboardWritable ? Pasteboard::createPrivate() : Pasteboard::createForCopyAndPaste()));
+}
+
 Clipboard::~Clipboard()
 {
 #if ENABLE(DRAG_SUPPORT)
@@ -77,7 +88,7 @@
     
 void Clipboard::setAccessPolicy(ClipboardAccessPolicy policy)
 {
-    // once you go numb, can never go back
+    // Once the clipboard goes numb, it can never go back.
     ASSERT(m_policy != ClipboardNumb || policy == ClipboardNumb);
     m_policy = policy;
 }
@@ -97,126 +108,6 @@
     return m_policy == ClipboardWritable;
 }
 
-bool Clipboard::canSetDragImage() const
-{
-    return m_clipboardType == DragAndDrop && (m_policy == ClipboardImageWritable || m_policy == ClipboardWritable);
-}
-
-// These "conversion" methods are called by both WebCore and WebKit, and never make sense to JS, so we don't
-// worry about security for these. They don't allow access to the pasteboard anyway.
-
-static DragOperation dragOpFromIEOp(const String& op)
-{
-    // yep, it's really just this fixed set
-    if (op == "uninitialized")
-        return DragOperationEvery;
-    if (op == "none")
-        return DragOperationNone;
-    if (op == "copy")
-        return DragOperationCopy;
-    if (op == "link")
-        return DragOperationLink;
-    if (op == "move")
-        return (DragOperation)(DragOperationGeneric | DragOperationMove);
-    if (op == "copyLink")
-        return (DragOperation)(DragOperationCopy | DragOperationLink);
-    if (op == "copyMove")
-        return (DragOperation)(DragOperationCopy | DragOperationGeneric | DragOperationMove);
-    if (op == "linkMove")
-        return (DragOperation)(DragOperationLink | DragOperationGeneric | DragOperationMove);
-    if (op == "all")
-        return DragOperationEvery;
-    return DragOperationPrivate;  // really a marker for "no conversion"
-}
-
-static String IEOpFromDragOp(DragOperation op)
-{
-    bool moveSet = !!((DragOperationGeneric | DragOperationMove) & op);
-    
-    if ((moveSet && (op & DragOperationCopy) && (op & DragOperationLink))
-        || (op == DragOperationEvery))
-        return "all";
-    if (moveSet && (op & DragOperationCopy))
-        return "copyMove";
-    if (moveSet && (op & DragOperationLink))
-        return "linkMove";
-    if ((op & DragOperationCopy) && (op & DragOperationLink))
-        return "copyLink";
-    if (moveSet)
-        return "move";
-    if (op & DragOperationCopy)
-        return "copy";
-    if (op & DragOperationLink)
-        return "link";
-    return "none";
-}
-
-DragOperation Clipboard::sourceOperation() const
-{
-    DragOperation op = dragOpFromIEOp(m_effectAllowed);
-    ASSERT(op != DragOperationPrivate);
-    return op;
-}
-
-DragOperation Clipboard::destinationOperation() const
-{
-    DragOperation op = dragOpFromIEOp(m_dropEffect);
-    ASSERT(op == DragOperationCopy || op == DragOperationNone || op == DragOperationLink || op == (DragOperation)(DragOperationGeneric | DragOperationMove) || op == DragOperationEvery);
-    return op;
-}
-
-void Clipboard::setSourceOperation(DragOperation op)
-{
-    ASSERT_ARG(op, op != DragOperationPrivate);
-    m_effectAllowed = IEOpFromDragOp(op);
-}
-
-void Clipboard::setDestinationOperation(DragOperation op)
-{
-    ASSERT_ARG(op, op == DragOperationCopy || op == DragOperationNone || op == DragOperationLink || op == DragOperationGeneric || op == DragOperationMove || op == (DragOperation)(DragOperationGeneric | DragOperationMove));
-    m_dropEffect = IEOpFromDragOp(op);
-}
-
-void Clipboard::setDropEffect(const String &effect)
-{
-    if (!isForDragAndDrop())
-        return;
-
-    // The attribute must ignore any attempts to set it to a value other than none, copy, link, and move. 
-    if (effect != "none" && effect != "copy"  && effect != "link" && effect != "move")
-        return;
-
-    // FIXME: The spec actually allows this in all circumstances, even though there's no point in
-    // setting the drop effect when this condition is not true.
-    if (canReadTypes())
-        m_dropEffect = effect;
-}
-
-void Clipboard::setEffectAllowed(const String &effect)
-{
-    if (!isForDragAndDrop())
-        return;
-
-    if (dragOpFromIEOp(effect) == DragOperationPrivate) {
-        // This means that there was no conversion, and the effectAllowed that
-        // we are passed isn't a valid effectAllowed, so we should ignore it,
-        // and not set m_effectAllowed.
-
-        // The attribute must ignore any attempts to set it to a value other than 
-        // none, copy, copyLink, copyMove, link, linkMove, move, all, and uninitialized.
-        return;
-    }
-
-
-    if (canWriteData())
-        m_effectAllowed = effect;
-}
-    
-PassRefPtr<Clipboard> Clipboard::createForCopyAndPaste(ClipboardAccessPolicy policy)
-{
-    return adoptRef(new Clipboard(policy, CopyAndPaste, policy == ClipboardWritable ? Pasteboard::createPrivate() : Pasteboard::createForCopyAndPaste()));
-}
-
 bool Clipboard::hasData()
 {
     return m_pasteboard->hasData();
@@ -240,17 +131,27 @@
 
 String Clipboard::getData(const String& type) const
 {
-    if (!canReadData() || m_forFileDrag)
+    if (!canReadData())
         return String();
 
+#if ENABLE(DRAG_SUPPORT)
+    if (m_forFileDrag)
+        return String();
+#endif
+
     return m_pasteboard->readString(type);
 }
 
 bool Clipboard::setData(const String& type, const String& data)
 {
-    if (!canWriteData() || m_forFileDrag)
+    if (!canWriteData())
         return false;
 
+#if ENABLE(DRAG_SUPPORT)
+    if (m_forFileDrag)
+        return false;
+#endif
+
     return m_pasteboard->writeString(type, data);
 }
 
@@ -262,14 +163,20 @@
     return m_pasteboard->types();
 }
 
-// FIXME: We could cache the computed fileList if necessary
-// Currently each access gets a new copy, setData() modifications to the
-// clipboard are not reflected in any FileList objects the page has accessed and stored
 PassRefPtr<FileList> Clipboard::files() const
 {
-    if (!canReadData() || (m_clipboardType == DragAndDrop && !m_forFileDrag))
+    // FIXME: We could cache the computed file list if it was necessary and helpful.
+    // Currently, each access gets a new copy, and thus setData() modifications to the
+    // clipboard are not reflected in any FileList objects the page has accessed and stored.
+
+    if (!canReadData())
         return FileList::create();
 
+#if ENABLE(DRAG_SUPPORT)
+    if (m_forDrag && !m_forFileDrag)
+        return FileList::create();
+#endif
+
     Vector<String> filenames = m_pasteboard->readFilenames();
     RefPtr<FileList> fileList = FileList::create();
     for (size_t i = 0; i < filenames.size(); ++i)
@@ -279,25 +186,49 @@
 
 #if !ENABLE(DRAG_SUPPORT)
 
+String Clipboard::dropEffect() const
+{
+    return ASCIILiteral("none");
+}
+
+void Clipboard::setDropEffect(const String&)
+{
+}
+
+String Clipboard::effectAllowed() const
+{
+    return ASCIILiteral("uninitialized");
+}
+
+void Clipboard::setEffectAllowed(const String&)
+{
+}
+
 void Clipboard::setDragImage(Element*, int, int)
 {
 }
 
 #else
 
-// FIXME: Should be named createForDragAndDrop.
-// FIXME: Should take const DragData& instead of DragData*.
-// FIXME: Should not take Frame*.
-PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame*)
+PassRefPtr<Clipboard> Clipboard::createForDragAndDrop()
 {
-    return adoptRef(new Clipboard(policy, DragAndDrop, Pasteboard::createForDragAndDrop(*dragData), dragData->containsFiles()));
+    return adoptRef(new Clipboard(ClipboardWritable, Pasteboard::createForDragAndDrop(), DragAndDrop));
 }
 
-PassRefPtr<Clipboard> Clipboard::createForDragAndDrop()
+PassRefPtr<Clipboard> Clipboard::createForDragAndDrop(ClipboardAccessPolicy policy, const DragData& dragData)
 {
-    return adoptRef(new Clipboard(ClipboardWritable, DragAndDrop, Pasteboard::createForDragAndDrop()));
+    return adoptRef(new Clipboard(policy, Pasteboard::createForDragAndDrop(dragData), DragAndDrop, dragData.containsFiles()));
 }
 
+bool Clipboard::canSetDragImage() const
+{
+    // Note that the spec doesn't actually allow drag image modification outside the dragstart
+    // event. This capability is maintained for backwards compatiblity for ports that have
+    // supported this in the past. On many ports, attempting to set a drag image outside the
+    // dragstart operation is a no-op anyway.
+    return m_forDrag && (m_policy == ClipboardImageWritable || m_policy == ClipboardWritable);
+}
+
 void Clipboard::setDragImage(Element* element, int x, int y)
 {
     if (!canSetDragImage())
@@ -329,7 +260,7 @@
 {
     // Don't allow setting the image if we haven't started dragging yet; we'll rely on the dragging code
     // to install this drag image as part of getting the drag kicked off.
-    if (!dragStarted())
+    if (!m_shouldUpdateDragImage)
         return;
 
     IntPoint computedHotSpot;
@@ -366,6 +297,117 @@
     m_clipboard->updateDragImage();
 }
 
+static DragOperation dragOpFromIEOp(const String& operation)
+{
+    if (operation == "uninitialized")
+        return DragOperationEvery;
+    if (operation == "none")
+        return DragOperationNone;
+    if (operation == "copy")
+        return DragOperationCopy;
+    if (operation == "link")
+        return DragOperationLink;
+    if (operation == "move")
+        return (DragOperation)(DragOperationGeneric | DragOperationMove);
+    if (operation == "copyLink")
+        return (DragOperation)(DragOperationCopy | DragOperationLink);
+    if (operation == "copyMove")
+        return (DragOperation)(DragOperationCopy | DragOperationGeneric | DragOperationMove);
+    if (operation == "linkMove")
+        return (DragOperation)(DragOperationLink | DragOperationGeneric | DragOperationMove);
+    if (operation == "all")
+        return DragOperationEvery;
+    return DragOperationPrivate; // really a marker for "no conversion"
+}
+
+static const char* IEOpFromDragOp(DragOperation operation)
+{
+    bool isGenericMove = operation & (DragOperationGeneric | DragOperationMove);
+
+    if ((isGenericMove && (operation & DragOperationCopy) && (operation & DragOperationLink)) || operation == DragOperationEvery)
+        return "all";
+    if (isGenericMove && (operation & DragOperationCopy))
+        return "copyMove";
+    if (isGenericMove && (operation & DragOperationLink))
+        return "linkMove";
+    if ((operation & DragOperationCopy) && (operation & DragOperationLink))
+        return "copyLink";
+    if (isGenericMove)
+        return "move";
+    if (operation & DragOperationCopy)
+        return "copy";
+    if (operation & DragOperationLink)
+        return "link";
+    return "none";
+}
+
+DragOperation Clipboard::sourceOperation() const
+{
+    DragOperation operation = dragOpFromIEOp(m_effectAllowed);
+    ASSERT(operation != DragOperationPrivate);
+    return operation;
+}
+
+DragOperation Clipboard::destinationOperation() const
+{
+    DragOperation operation = dragOpFromIEOp(m_dropEffect);
+    ASSERT(operation == DragOperationCopy || operation == DragOperationNone || operation == DragOperationLink || operation == (DragOperation)(DragOperationGeneric | DragOperationMove) || operation == DragOperationEvery);
+    return operation;
+}
+
+void Clipboard::setSourceOperation(DragOperation operation)
+{
+    ASSERT_ARG(operation, operation != DragOperationPrivate);
+    m_effectAllowed = IEOpFromDragOp(operation);
+}
+
+void Clipboard::setDestinationOperation(DragOperation operation)
+{
+    ASSERT_ARG(operation, operation == DragOperationCopy || operation == DragOperationNone || operation == DragOperationLink || operation == DragOperationGeneric || operation == DragOperationMove || operation == (DragOperation)(DragOperationGeneric | DragOperationMove));
+    m_dropEffect = IEOpFromDragOp(operation);
+}
+
+String Clipboard::dropEffect() const
+{
+    return m_dropEffect == "uninitialized" ? ASCIILiteral("none") : m_dropEffect;
+}
+
+void Clipboard::setDropEffect(const String& effect)
+{
+    if (!m_forDrag)
+        return;
+
+    if (effect != "none" && effect != "copy" && effect != "link" && effect != "move")
+        return;
+
+    // FIXME: The spec allows this in all circumstances. There is probably no value
+    // in ignoring attempts to change it.
+    if (!canReadTypes())
+        return;
+
+    m_dropEffect = effect;
+}
+
+String Clipboard::effectAllowed() const
+{
+    return m_effectAllowed;
+}
+
+void Clipboard::setEffectAllowed(const String& effect)
+{
+    if (!m_forDrag)
+        return;
+
+    // Ignore any attempts to set it to an unknown value.
+    if (dragOpFromIEOp(effect) == DragOperationPrivate)
+        return;
+
+    if (!canWriteData())
+        return;
+
+    m_effectAllowed = effect;
+}
+
 #endif // ENABLE(DRAG_SUPPORT)
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Clipboard.h (154259 => 154260)


--- trunk/Source/WebCore/dom/Clipboard.h	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/dom/Clipboard.h	2013-08-19 04:18:31 UTC (rev 154260)
@@ -29,7 +29,9 @@
 #include "DragActions.h"
 #include "DragImage.h"
 #include "IntPoint.h"
-#include "Node.h"
+#include <wtf/ListHashSet.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -37,104 +39,83 @@
     class DataTransferItemList;
     class DragData;
     class DragImageLoader;
+    class Element;
     class FileList;
-    class Frame;
     class Pasteboard;
-    class Range;
 
-    // State available during IE's events for drag and drop and copy/paste
     class Clipboard : public RefCounted<Clipboard> {
     public:
-        // Whether this clipboard is serving a drag-drop or copy-paste request.
-        enum ClipboardType {
-            CopyAndPaste,
-            DragAndDrop,
-        };
-        
-        static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*);
+        static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy);
 
         ~Clipboard();
 
-        bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
-        bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
-
-        String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
+        String dropEffect() const;
         void setDropEffect(const String&);
-        bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
-        String effectAllowed() const { return m_effectAllowed; }
+
+        String effectAllowed() const;
         void setEffectAllowed(const String&);
-    
+
+        ListHashSet<String> types() const;
+
+        PassRefPtr<FileList> files() const;
+
         void clearData(const String& type);
         void clearData();
 
-        void setDragImage(Element*, int x, int y);
-
         String getData(const String& type) const;
+
         bool setData(const String& type, const String& data);
-    
-        ListHashSet<String> types() const;
-        PassRefPtr<FileList> files() const;
 
-        CachedImage* dragImage() const { return m_dragImage.get(); }
-        Node* dragImageElement() const { return m_dragImageElement.get(); }
-        
-        DragImageRef createDragImage(IntPoint& dragLocation) const;
+        void setDragImage(Element*, int x, int y);
 
-        bool hasData();
+#if ENABLE(DATA_TRANSFER_ITEMS)
+        PassRefPtr<DataTransferItemList> items() = 0;
+#endif
 
         void setAccessPolicy(ClipboardAccessPolicy);
         bool canReadTypes() const;
         bool canReadData() const;
         bool canWriteData() const;
-        // Note that the spec doesn't actually allow drag image modification outside the dragstart
-        // event. This capability is maintained for backwards compatiblity for ports that have
-        // supported this in the past. On many ports, attempting to set a drag image outside the
-        // dragstart operation is a no-op anyway.
-        bool canSetDragImage() const;
 
+        Pasteboard& pasteboard() { return *m_pasteboard; }
+
+#if ENABLE(DRAG_SUPPORT)
+        static PassRefPtr<Clipboard> createForDragAndDrop();
+        static PassRefPtr<Clipboard> createForDragAndDrop(ClipboardAccessPolicy, const DragData&);
+
+        bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
+        bool hasData();
+
         DragOperation sourceOperation() const;
         DragOperation destinationOperation() const;
         void setSourceOperation(DragOperation);
         void setDestinationOperation(DragOperation);
-        
-        void setDragHasStarted() { m_dragStarted = true; }
 
-#if ENABLE(DATA_TRANSFER_ITEMS)
-        PassRefPtr<DataTransferItemList> items() = 0;
+        void setDragHasStarted() { m_shouldUpdateDragImage = true; }
+        DragImageRef createDragImage(IntPoint& dragLocation) const;
+        void updateDragImage();
 #endif
-        
-        static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy);
 
-        Pasteboard& pasteboard() { return *m_pasteboard; }
+    private:
+        enum ClipboardType { CopyAndPaste, DragAndDrop };
+        Clipboard(ClipboardAccessPolicy, PassOwnPtr<Pasteboard>, ClipboardType = CopyAndPaste, bool forFileDrag = false);
 
 #if ENABLE(DRAG_SUPPORT)
-        static PassRefPtr<Clipboard> createForDragAndDrop();
-
-        void updateDragImage();
+        bool canSetDragImage() const;
 #endif
 
-    protected:
-        Clipboard(ClipboardAccessPolicy, ClipboardType, PassOwnPtr<Pasteboard>, bool forFileDrag = false);
-
-        bool dragStarted() const { return m_dragStarted; }
-        
-    private:
-        // Instead of using this member directly, prefer to use the can*() methods above.
         ClipboardAccessPolicy m_policy;
+        OwnPtr<Pasteboard> m_pasteboard;
+
+#if ENABLE(DRAG_SUPPORT)
+        bool m_forDrag;
+        bool m_forFileDrag;
         String m_dropEffect;
         String m_effectAllowed;
-        bool m_dragStarted;
-        ClipboardType m_clipboardType;
-        
-    protected:
+        bool m_shouldUpdateDragImage;
         IntPoint m_dragLocation;
         CachedResourceHandle<CachedImage> m_dragImage;
-        RefPtr<Node> m_dragImageElement;
-
-    private:
-        OwnPtr<Pasteboard> m_pasteboard;
-        bool m_forFileDrag;
-#if ENABLE(DRAG_SUPPORT)
+        RefPtr<Element> m_dragImageElement;
         OwnPtr<DragImageLoader> m_dragImageLoader;
 #endif
     };

Modified: trunk/Source/WebCore/dom/Clipboard.idl (154259 => 154260)


--- trunk/Source/WebCore/dom/Clipboard.idl	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/dom/Clipboard.idl	2013-08-19 04:18:31 UTC (rev 154260)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,11 +25,13 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 [
     SkipVTableValidation
 ] interface Clipboard {
-             [TreatReturnedNullStringAs=Undefined] attribute DOMString dropEffect;
-             [TreatReturnedNullStringAs=Undefined] attribute DOMString effectAllowed;
+    attribute DOMString dropEffect;
+    attribute DOMString effectAllowed;
+
     [CustomGetter] readonly attribute Array types;
     readonly attribute FileList files;
 
@@ -40,4 +42,3 @@
 
     [Conditional=DATA_TRANSFER_ITEMS] readonly attribute DataTransferItemList items;
 };
-

Modified: trunk/Source/WebCore/page/DragController.cpp (154259 => 154260)


--- trunk/Source/WebCore/page/DragController.cpp	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/page/DragController.cpp	2013-08-19 04:18:31 UTC (rev 154260)
@@ -196,7 +196,7 @@
 
     if (RefPtr<FrameView> v = mainFrame->view()) {
         ClipboardAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? ClipboardReadable : ClipboardTypesReadable;
-        RefPtr<Clipboard> clipboard = Clipboard::create(policy, dragData, mainFrame);
+        RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(policy, *dragData);
         clipboard->setSourceOperation(dragData->draggingSourceOperationMask());
         mainFrame->eventHandler().cancelDragAndDrop(createMouseEvent(dragData), clipboard.get());
         clipboard->setAccessPolicy(ClipboardNumb);    // invalidate clipboard here for security
@@ -222,7 +222,7 @@
         bool preventedDefault = false;
         if (mainFrame->view()) {
             // Sending an event can result in the destruction of the view and part.
-            RefPtr<Clipboard> clipboard = Clipboard::create(ClipboardReadable, dragData, mainFrame.get());
+            RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(ClipboardReadable, *dragData);
             clipboard->setSourceOperation(dragData->draggingSourceOperationMask());
             preventedDefault = mainFrame->eventHandler().performDragAndDrop(createMouseEvent(dragData), clipboard.get());
             clipboard->setAccessPolicy(ClipboardNumb); // Invalidate clipboard here for security
@@ -614,7 +614,7 @@
         return false;
 
     ClipboardAccessPolicy policy = m_documentUnderMouse->securityOrigin()->isLocal() ? ClipboardReadable : ClipboardTypesReadable;
-    RefPtr<Clipboard> clipboard = Clipboard::create(policy, dragData, mainFrame.get());
+    RefPtr<Clipboard> clipboard = Clipboard::createForDragAndDrop(policy, *dragData);
     DragOperation srcOpMask = dragData->draggingSourceOperationMask();
     clipboard->setSourceOperation(srcOpMask);
 

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (154259 => 154260)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-08-19 03:05:22 UTC (rev 154259)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-08-19 04:18:31 UTC (rev 154260)
@@ -32,6 +32,7 @@
 #import "DragClient.h"
 #import "DragController.h"
 #import "DragData.h"
+#import "Element.h"
 #import "Frame.h"
 #import "FrameSnapshottingMac.h"
 #import "Page.h"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to