Diff
Modified: trunk/Source/WebCore/ChangeLog (213596 => 213597)
--- trunk/Source/WebCore/ChangeLog 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/ChangeLog 2017-03-08 22:14:26 UTC (rev 213597)
@@ -1,3 +1,33 @@
+2017-03-07 Anders Carlsson <[email protected]>
+
+ Use the new code path when dragging web contents
+ https://bugs.webkit.org/show_bug.cgi?id=169298
+
+ Reviewed by Beth Dakin.
+
+ * editing/Editor.h:
+ * editing/cocoa/EditorCocoa.mm:
+ (WebCore::Editor::writeSelection):
+ Add a new function that writes the selection to a writer object.
+
+ * page/DragController.cpp:
+ (WebCore::DragController::startDrag):
+ Use the new writeSelection if mustUseLegacyDragClient is false.
+
+ * platform/PasteboardWriterData.cpp:
+ (WebCore::PasteboardWriterData::WebContent::WebContent):
+ (WebCore::PasteboardWriterData::WebContent::~WebContent):
+ (WebCore::PasteboardWriterData::setWebContent):
+ * platform/PasteboardWriterData.h:
+ Add getters and setters.
+
+ * platform/mac/PasteboardWriter.mm:
+ (WebCore::toUTIUnlessAlreadyUTI):
+ Add a helper.
+
+ (WebCore::createPasteboardWriter):
+ Convert web content to pasteboard types.
+
2017-03-08 Dave Hyatt <[email protected]>
CSS Multicolumn should not clip columns horizontally
Modified: trunk/Source/WebCore/editing/Editor.h (213596 => 213597)
--- trunk/Source/WebCore/editing/Editor.h 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/editing/Editor.h 2017-03-08 22:14:26 UTC (rev 213597)
@@ -66,6 +66,7 @@
class KeyboardEvent;
class KillRing;
class Pasteboard;
+class PasteboardWriterData;
class SharedBuffer;
class Font;
class SpellCheckRequest;
@@ -469,6 +470,7 @@
#if PLATFORM(COCOA) || PLATFORM(GTK)
WEBCORE_EXPORT void writeSelectionToPasteboard(Pasteboard&);
WEBCORE_EXPORT void writeImageToPasteboard(Pasteboard&, Element& imageElement, const URL&, const String& title);
+ void writeSelection(PasteboardWriterData&);
#endif
#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS)
Modified: trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm (213596 => 213597)
--- trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2017-03-08 22:14:26 UTC (rev 213597)
@@ -171,6 +171,25 @@
pasteboard.write(content);
}
+void Editor::writeSelection(PasteboardWriterData& pasteboardWriterData)
+{
+ NSAttributedString *attributedString = attributedStringFromRange(*selectedRange());
+
+ PasteboardWriterData::WebContent webContent;
+ webContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
+ webContent.dataInWebArchiveFormat = selectionInWebArchiveFormat();
+ webContent.dataInRTFDFormat = attributedString.containsAttachments ? dataInRTFDFormat(attributedString) : nullptr;
+ webContent.dataInRTFFormat = dataInRTFFormat(attributedString);
+ // FIXME: Why don't we want this on iOS?
+#if PLATFORM(MAC)
+ webContent.dataInHTMLFormat = selectionInHTMLFormat();
+#endif
+ webContent.dataInStringFormat = stringSelectionForPasteboardWithImageAltText();
+ client()->getClientPasteboardDataForRange(selectedRange().get(), webContent.clientTypes, webContent.clientData);
+
+ pasteboardWriterData.setWebContent(WTFMove(webContent));
+}
+
RefPtr<SharedBuffer> Editor::selectionInWebArchiveFormat()
{
RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(&m_frame);
Modified: trunk/Source/WebCore/page/DragController.cpp (213596 => 213597)
--- trunk/Source/WebCore/page/DragController.cpp 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/page/DragController.cpp 2017-03-08 22:14:26 UTC (rev 213597)
@@ -875,14 +875,18 @@
pasteboardWriterData.setPlainText(WTFMove(plainText));
}
} else {
- mustUseLegacyDragClient = true;
-
+ if (mustUseLegacyDragClient) {
#if PLATFORM(COCOA) || PLATFORM(GTK)
- src.editor().writeSelectionToPasteboard(dataTransfer.pasteboard());
+ src.editor().writeSelectionToPasteboard(dataTransfer.pasteboard());
#else
- // FIXME: Convert all other platforms to match Mac and delete this.
- dataTransfer.pasteboard().writeSelection(*selectionRange, src.editor().canSmartCopyOrDelete(), src, IncludeImageAltTextForDataTransfer);
+ // FIXME: Convert all other platforms to match Mac and delete this.
+ dataTransfer.pasteboard().writeSelection(*selectionRange, src.editor().canSmartCopyOrDelete(), src, IncludeImageAltTextForDataTransfer);
#endif
+ } else {
+#if PLATFORM(COCOA)
+ src.editor().writeSelection(pasteboardWriterData);
+#endif
+ }
}
src.editor().didWriteSelectionToPasteboard();
Modified: trunk/Source/WebCore/platform/PasteboardWriterData.cpp (213596 => 213597)
--- trunk/Source/WebCore/platform/PasteboardWriterData.cpp 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/platform/PasteboardWriterData.cpp 2017-03-08 22:14:26 UTC (rev 213597)
@@ -26,6 +26,8 @@
#include "config.h"
#include "PasteboardWriterData.h"
+#include "SharedBuffer.h"
+
namespace WebCore {
PasteboardWriterData::PasteboardWriterData()
@@ -36,6 +38,14 @@
{
}
+PasteboardWriterData::WebContent::WebContent()
+{
+}
+
+PasteboardWriterData::WebContent::~WebContent()
+{
+}
+
bool PasteboardWriterData::isEmpty() const
{
if (m_plainText)
@@ -61,4 +71,11 @@
m_url = WTFMove(url);
}
+void PasteboardWriterData::setWebContent(WebContent webContent)
+{
+ ASSERT(!m_webContent);
+
+ m_webContent = webContent;
}
+
+}
Modified: trunk/Source/WebCore/platform/PasteboardWriterData.h (213596 => 213597)
--- trunk/Source/WebCore/platform/PasteboardWriterData.h 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/platform/PasteboardWriterData.h 2017-03-08 22:14:26 UTC (rev 213597)
@@ -31,6 +31,8 @@
namespace WebCore {
+class SharedBuffer;
+
class PasteboardWriterData final {
public:
PasteboardWriterData();
@@ -43,6 +45,25 @@
String text;
};
+ struct WebContent {
+ WebContent();
+ ~WebContent();
+
+#if PLATFORM(COCOA)
+ bool canSmartCopyOrDelete;
+ RefPtr<SharedBuffer> dataInWebArchiveFormat;
+ RefPtr<SharedBuffer> dataInRTFDFormat;
+ RefPtr<SharedBuffer> dataInRTFFormat;
+ // FIXME: Why don't we want this on iOS?
+#if PLATFORM(MAC)
+ String dataInHTMLFormat;
+#endif
+ String dataInStringFormat;
+ Vector<String> clientTypes;
+ Vector<RefPtr<SharedBuffer>> clientData;
+#endif
+ };
+
const std::optional<PlainText>& plainText() const { return m_plainText; }
void setPlainText(PlainText);
@@ -59,9 +80,13 @@
const std::optional<URL>& url() const { return m_url; }
void setURL(URL);
+ const std::optional<WebContent>& webContent() const { return m_webContent; }
+ void setWebContent(WebContent);
+
private:
std::optional<PlainText> m_plainText;
std::optional<URL> m_url;
+ std::optional<WebContent> m_webContent;
};
}
Modified: trunk/Source/WebCore/platform/mac/PasteboardWriter.mm (213596 => 213597)
--- trunk/Source/WebCore/platform/mac/PasteboardWriter.mm 2017-03-08 22:10:45 UTC (rev 213596)
+++ trunk/Source/WebCore/platform/mac/PasteboardWriter.mm 2017-03-08 22:14:26 UTC (rev 213597)
@@ -30,6 +30,7 @@
#import "NSPasteboardSPI.h"
#import "PasteboardWriterData.h"
+#import "SharedBuffer.h"
namespace WebCore {
@@ -38,6 +39,16 @@
return adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)pasteboardType, nullptr));
}
+static RetainPtr<NSString> toUTIUnlessAlreadyUTI(NSString *type)
+{
+ if (UTTypeIsDeclared((__bridge CFStringRef)type) || UTTypeIsDynamic((__bridge CFStringRef)type)) {
+ // This is already a UTI.
+ return type;
+ }
+
+ return toUTI(type);
+}
+
RetainPtr<id <NSPasteboardWriting>> createPasteboardWriter(const PasteboardWriterData& data)
{
auto pasteboardItem = adoptNS([[NSPasteboardItem alloc] init]);
@@ -46,7 +57,7 @@
[pasteboardItem setString:plainText->text forType:NSPasteboardTypeString];
if (plainText->canSmartCopyOrDelete) {
auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));
- [pasteboardItem setData:nil forType:smartPasteType.get()];
+ [pasteboardItem setData:[NSData data] forType:smartPasteType.get()];
}
}
@@ -83,6 +94,28 @@
[pasteboardItem setString:userVisibleString forType:NSPasteboardTypeString];
}
+ if (auto& webContent = data.webContent()) {
+ if (webContent->canSmartCopyOrDelete) {
+ auto smartPasteType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)_NXSmartPaste, nullptr));
+ [pasteboardItem setData:[NSData data] forType:smartPasteType.get()];
+ }
+ if (webContent->dataInWebArchiveFormat) {
+ auto webArchiveType = adoptNS((__bridge NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)@"Apple Web Archive pasteboard type", nullptr));
+ [pasteboardItem setData:webContent->dataInWebArchiveFormat->createNSData().get() forType:webArchiveType.get()];
+ }
+ if (webContent->dataInRTFDFormat)
+ [pasteboardItem setData:webContent->dataInRTFDFormat->createNSData().get() forType:NSPasteboardTypeRTFD];
+ if (webContent->dataInRTFFormat)
+ [pasteboardItem setData:webContent->dataInRTFFormat->createNSData().get() forType:NSPasteboardTypeRTF];
+ if (!webContent->dataInHTMLFormat.isNull())
+ [pasteboardItem setString:webContent->dataInHTMLFormat forType:NSPasteboardTypeHTML];
+ if (!webContent->dataInStringFormat.isNull())
+ [pasteboardItem setString:webContent->dataInStringFormat forType:NSPasteboardTypeString];
+
+ for (unsigned i = 0; i < webContent->clientTypes.size(); ++i)
+ [pasteboardItem setData:webContent->clientData[i]->createNSData().get() forType:toUTIUnlessAlreadyUTI(webContent->clientTypes[i]).get()];
+ }
+
return pasteboardItem;
}