Title: [149982] trunk/Source/WebCore
Revision
149982
Author
[email protected]
Date
2013-05-12 22:19:32 -0700 (Sun, 12 May 2013)

Log Message

[Mac] Move setData from ClipboardMac to PasteboardMac
https://bugs.webkit.org/show_bug.cgi?id=116006

Reviewed by Anders Carlsson.

* dom/Clipboard.cpp:
(WebCore::Clipboard::setData): Added. Calls through to Pasteboard
after doing checks needed at this level.

* dom/Clipboard.h: Made setData non-virtual in non-legacy case.

* platform/Pasteboard.h: Updated includes and forward declarations.
Removed static member function cocoaTypeFromHTMLClipboardType, since
it can now be private to PasteboardMac. Added static member function
addHTMLClipboardTypesForCocoaType, which is shared between the
ClipboardMac and PasteboardMac files for now. Added writeString.

* platform/mac/ClipboardMac.h: Removed setData.

* platform/mac/ClipboardMac.mm: Removed utiTypeFromCocoaType,
addHTMLClipboardTypesForCocoaType, and setData.
(WebCore::ClipboardMac::types): Call addHTMLClipboardTypesForCocoaType
as a Pasteboard static member function, for now.

* platform/mac/PasteboardMac.mm:
(WebCore::cocoaTypeFromHTMLClipboardType): Added. Moved from ClipboardMac.
(WebCore::Pasteboard::readString): Changed to call
cocoaTypeFromHTMLClipboardType as a file-local function, not a member
function (in fact, we didn't need to repeat the class name before, either,
so this is just removing something we didn't need).
(WebCore::utiTypeFromCocoaType): Added. Moved from ClipboardMac.
(WebCore::Pasteboard::addHTMLClipboardTypesForCocoaType): Ditto.
(WebCore::Pasteboard::writeString): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149981 => 149982)


--- trunk/Source/WebCore/ChangeLog	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/ChangeLog	2013-05-13 05:19:32 UTC (rev 149982)
@@ -1,5 +1,41 @@
 2013-05-12  Darin Adler  <[email protected]>
 
+        [Mac] Move setData from ClipboardMac to PasteboardMac
+        https://bugs.webkit.org/show_bug.cgi?id=116006
+
+        Reviewed by Anders Carlsson.
+
+        * dom/Clipboard.cpp:
+        (WebCore::Clipboard::setData): Added. Calls through to Pasteboard
+        after doing checks needed at this level.
+
+        * dom/Clipboard.h: Made setData non-virtual in non-legacy case.
+
+        * platform/Pasteboard.h: Updated includes and forward declarations.
+        Removed static member function cocoaTypeFromHTMLClipboardType, since
+        it can now be private to PasteboardMac. Added static member function
+        addHTMLClipboardTypesForCocoaType, which is shared between the
+        ClipboardMac and PasteboardMac files for now. Added writeString.
+
+        * platform/mac/ClipboardMac.h: Removed setData.
+
+        * platform/mac/ClipboardMac.mm: Removed utiTypeFromCocoaType,
+        addHTMLClipboardTypesForCocoaType, and setData.
+        (WebCore::ClipboardMac::types): Call addHTMLClipboardTypesForCocoaType
+        as a Pasteboard static member function, for now.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::cocoaTypeFromHTMLClipboardType): Added. Moved from ClipboardMac.
+        (WebCore::Pasteboard::readString): Changed to call
+        cocoaTypeFromHTMLClipboardType as a file-local function, not a member
+        function (in fact, we didn't need to repeat the class name before, either,
+        so this is just removing something we didn't need).
+        (WebCore::utiTypeFromCocoaType): Added. Moved from ClipboardMac.
+        (WebCore::Pasteboard::addHTMLClipboardTypesForCocoaType): Ditto.
+        (WebCore::Pasteboard::writeString): Ditto.
+
+2013-05-12  Darin Adler  <[email protected]>
+
         [Mac] Move getData from ClipboardMac to PasteboardMac
         https://bugs.webkit.org/show_bug.cgi?id=116005
 

Modified: trunk/Source/WebCore/dom/Clipboard.cpp (149981 => 149982)


--- trunk/Source/WebCore/dom/Clipboard.cpp	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/dom/Clipboard.cpp	2013-05-13 05:19:32 UTC (rev 149982)
@@ -283,6 +283,14 @@
     return m_pasteboard->readString(type);
 }
 
+bool Clipboard::setData(const String& type, const String& data)
+{
+    if (!canWriteData() || m_forFileDrag)
+        return false;
+
+    return m_pasteboard->writeString(type, data);
+}
+
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Clipboard.h (149981 => 149982)


--- trunk/Source/WebCore/dom/Clipboard.h	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/dom/Clipboard.h	2013-05-13 05:19:32 UTC (rev 149982)
@@ -82,7 +82,7 @@
         LEGACY_VIRTUAL void clearData(const String& type) LEGACY_PURE;
         LEGACY_VIRTUAL void clearAllData() LEGACY_PURE;
         LEGACY_VIRTUAL String getData(const String& type) const LEGACY_PURE;
-        virtual bool setData(const String& type, const String& data) = 0;
+        LEGACY_VIRTUAL bool setData(const String& type, const String& data) LEGACY_PURE;
     
         // extensions beyond IE's API
         virtual ListHashSet<String> types() const = 0;

Modified: trunk/Source/WebCore/platform/Pasteboard.h (149981 => 149982)


--- trunk/Source/WebCore/platform/Pasteboard.h	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2013-05-13 05:19:32 UTC (rev 149982)
@@ -29,25 +29,22 @@
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
+
 #if PLATFORM(MAC)
+#include <wtf/ListHashSet.h>
 #include <wtf/RetainPtr.h>
 #endif
+
 #if PLATFORM(GTK)
 #include <PasteboardHelper.h>
 #endif
-#include <wtf/Vector.h>
 
 // FIXME: This class is too high-level to be in the platform directory, since it
 // uses the DOM and makes calls to Editor. It should either be divested of its
 // knowledge of the frame and editor or moved into the editing directory.
 
-#if PLATFORM(MAC)
-OBJC_CLASS NSAttributedString;
-OBJC_CLASS NSFileWrapper;
-OBJC_CLASS NSArray;
-#endif
-
 #if PLATFORM(WIN)
 #include <windows.h>
 typedef struct HWND__* HWND;
@@ -63,7 +60,6 @@
 extern const char* WebURLsWithTitlesPboardType;
 #endif
 
-class ArchiveResource;
 class Clipboard;
 class DocumentFragment;
 class Frame;
@@ -93,8 +89,8 @@
     static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType);
 
     // Functions needed temporarily until all code from ClipboardMac is moved to PasteboardMac.
-    static String cocoaTypeFromHTMLClipboardType(const String& type);
     static Vector<String> absoluteURLsFromPasteboardFilenames(const String& pasteboardName, bool _onlyFirstURL_ = false);
+    static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName);
 #endif
     
     static Pasteboard* generalPasteboard();
@@ -103,6 +99,7 @@
 
     String readString(const String& type);
 
+    bool writeString(const String& type, const String& data);
     void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);
     void writePlainText(const String&, SmartReplaceOption);
     void writeURL(const KURL&, const String&, Frame* = 0);

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.h (149981 => 149982)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.h	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.h	2013-05-13 05:19:32 UTC (rev 149982)
@@ -52,9 +52,7 @@
     }
 
     virtual ~ClipboardMac();
-    
-    bool setData(const String& type, const String& data);
-    
+
     // extensions beyond IE's API
     virtual ListHashSet<String> types() const;
     virtual PassRefPtr<FileList> files() const;

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (149981 => 149982)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2013-05-13 05:19:32 UTC (rev 149982)
@@ -70,83 +70,6 @@
         m_dragImage->removeClient(this);
 }
 
-static String utiTypeFromCocoaType(const String& type)
-{
-    if (RetainPtr<CFStringRef> utiType = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, type.createCFString().get(), 0))) {
-        if (RetainPtr<CFStringRef> mimeType = adoptCF(UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType)))
-            return String(mimeType.get());
-    }
-    return String();
-}
-
-static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName)
-{
-    // UTI may not do these right, so make sure we get the right, predictable result
-    if (cocoaType == String(NSStringPboardType)) {
-        resultTypes.add("text/plain");
-        return;
-    }
-    if (cocoaType == String(NSURLPboardType)) {
-        resultTypes.add("text/uri-list");
-        return;
-    }
-    if (cocoaType == String(NSFilenamesPboardType)) {
-        // If file list is empty, add nothing.
-        // Note that there is a chance that the file list count could have changed since we grabbed the types array.
-        // However, this is not really an issue for us doing a sanity check here.
-        Vector<String> fileList;
-        platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
-        if (!fileList.isEmpty()) {
-            // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
-            // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
-            resultTypes.add("text/uri-list");
-            resultTypes.add("Files");
-        }
-        return;
-    }
-    String utiType = utiTypeFromCocoaType(cocoaType);
-    if (!utiType.isEmpty()) {
-        resultTypes.add(utiType);
-        return;
-    }
-    // No mapping, just pass the whole string though
-    resultTypes.add(cocoaType);
-}
-
-bool ClipboardMac::setData(const String &type, const String &data)
-{
-    if (!canWriteData() || m_clipboardContents == DragAndDropFiles)
-        return false;
-    // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
-
-    const String& cocoaType = Pasteboard::cocoaTypeFromHTMLClipboardType(type);
-    String cocoaData = data;
-
-    if (cocoaType == String(NSURLPboardType) || cocoaType == String(kUTTypeFileURL)) {
-        NSURL *url = "" URLWithString:cocoaData];
-        if ([url isFileURL])
-            return false;
-
-        Vector<String> types;
-        types.append(cocoaType);
-        platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName);
-        platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName);
-
-        return true;
-    }
-
-    if (!cocoaType.isEmpty()) {
-        // everything else we know of goes on the pboard as a string
-        Vector<String> types;
-        types.append(cocoaType);
-        platformStrategies()->pasteboardStrategy()->addTypes(types, m_pasteboardName);
-        platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName);
-        return true;
-    }
-
-    return false;
-}
-
 ListHashSet<String> ClipboardMac::types() const
 {
     if (!canReadTypes())
@@ -167,7 +90,7 @@
         if (types[i] == "NeXT plain ascii pasteboard type")
             continue;   // skip this ancient type that gets auto-supplied by some system conversion
 
-        addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName);
+        Pasteboard::addHTMLClipboardTypesForCocoaType(result, types[i], m_pasteboardName);
     }
 
     return result;

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (149981 => 149982)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-13 04:44:46 UTC (rev 149981)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-05-13 05:19:32 UTC (rev 149982)
@@ -27,7 +27,6 @@
 #import "Pasteboard.h"
 
 #import "CachedImage.h"
-#import "ClipboardMac.h"
 #import "DOMRangeInternal.h"
 #import "Document.h"
 #import "DocumentFragment.h"
@@ -596,7 +595,7 @@
     return !types.isEmpty();
 }
 
-String Pasteboard::cocoaTypeFromHTMLClipboardType(const String& type)
+static String cocoaTypeFromHTMLClipboardType(const String& type)
 {
     // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-datatransfer-setdata
     String qType = type.lower();
@@ -680,7 +679,7 @@
 
 String Pasteboard::readString(const String& type)
 {
-    const String& cocoaType = Pasteboard::cocoaTypeFromHTMLClipboardType(type);
+    const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
     String cocoaValue;
 
     // Grab the value off the pasteboard corresponding to the cocoaType
@@ -703,4 +702,77 @@
     return String();
 }
 
+static String utiTypeFromCocoaType(const String& type)
+{
+    if (RetainPtr<CFStringRef> utiType = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, type.createCFString().get(), 0))) {
+        if (RetainPtr<CFStringRef> mimeType = adoptCF(UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType)))
+            return String(mimeType.get());
+    }
+    return String();
 }
+
+void Pasteboard::addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes, const String& cocoaType, const String& pasteboardName)
+{
+    // UTI may not do these right, so make sure we get the right, predictable result
+    if (cocoaType == String(NSStringPboardType)) {
+        resultTypes.add("text/plain");
+        return;
+    }
+    if (cocoaType == String(NSURLPboardType)) {
+        resultTypes.add("text/uri-list");
+        return;
+    }
+    if (cocoaType == String(NSFilenamesPboardType)) {
+        // If file list is empty, add nothing.
+        // Note that there is a chance that the file list count could have changed since we grabbed the types array.
+        // However, this is not really an issue for us doing a sanity check here.
+        Vector<String> fileList;
+        platformStrategies()->pasteboardStrategy()->getPathnamesForType(fileList, String(NSFilenamesPboardType), pasteboardName);
+        if (!fileList.isEmpty()) {
+            // It is unknown if NSFilenamesPboardType always implies NSURLPboardType in Cocoa,
+            // but NSFilenamesPboardType should imply both 'text/uri-list' and 'Files'
+            resultTypes.add("text/uri-list");
+            resultTypes.add("Files");
+        }
+        return;
+    }
+    String utiType = utiTypeFromCocoaType(cocoaType);
+    if (!utiType.isEmpty()) {
+        resultTypes.add(utiType);
+        return;
+    }
+    // No mapping, just pass the whole string though
+    resultTypes.add(cocoaType);
+}
+
+bool Pasteboard::writeString(const String& type, const String& data)
+{
+    const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
+    String cocoaData = data;
+
+    if (cocoaType == String(NSURLPboardType) || cocoaType == String(kUTTypeFileURL)) {
+        NSURL *url = "" URLWithString:cocoaData];
+        if ([url isFileURL])
+            return false;
+
+        Vector<String> types;
+        types.append(cocoaType);
+        platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName);
+        platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName);
+
+        return true;
+    }
+
+    if (!cocoaType.isEmpty()) {
+        // everything else we know of goes on the pboard as a string
+        Vector<String> types;
+        types.append(cocoaType);
+        platformStrategies()->pasteboardStrategy()->addTypes(types, m_pasteboardName);
+        platformStrategies()->pasteboardStrategy()->setStringForType(cocoaData, cocoaType, m_pasteboardName);
+        return true;
+    }
+
+    return false;
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to