Title: [154900] trunk/Source/WebCore
- Revision
- 154900
- Author
- [email protected]
- Date
- 2013-08-30 11:02:36 -0700 (Fri, 30 Aug 2013)
Log Message
[Mac] No need for Pasteboard::getDataSelection
https://bugs.webkit.org/show_bug.cgi?id=120536
Reviewed by Anders Carlsson.
* editing/Editor.h: Added some Mac-only private member functions.
* editing/mac/EditorMac.mm:
(WebCore::Editor::selectionInWebArchiveFormat): Added.
(WebCore::Editor::adjustedSelectionRange): Added.
(WebCore::attributedStringForRange): Added.
(WebCore::dataInRTFDFormat): Added.
(WebCore::dataInRTFFormat): Added.
(WebCore::Editor::dataSelectionForPasteboard): Moved the implementation
of Pasteboard::getDataSelection here, refactoring to share code with the
writeSelectionToPasteboard function.
(WebCore::Editor::writeSelectionToPasteboard): Refactored to share code
with the new function above.
* platform/Pasteboard.h: Removed getDataSelection. One less layering violation.
* platform/mac/PasteboardMac.mm: Ditto.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (154899 => 154900)
--- trunk/Source/WebCore/ChangeLog 2013-08-30 18:00:36 UTC (rev 154899)
+++ trunk/Source/WebCore/ChangeLog 2013-08-30 18:02:36 UTC (rev 154900)
@@ -1,3 +1,27 @@
+2013-08-30 Darin Adler <[email protected]>
+
+ [Mac] No need for Pasteboard::getDataSelection
+ https://bugs.webkit.org/show_bug.cgi?id=120536
+
+ Reviewed by Anders Carlsson.
+
+ * editing/Editor.h: Added some Mac-only private member functions.
+
+ * editing/mac/EditorMac.mm:
+ (WebCore::Editor::selectionInWebArchiveFormat): Added.
+ (WebCore::Editor::adjustedSelectionRange): Added.
+ (WebCore::attributedStringForRange): Added.
+ (WebCore::dataInRTFDFormat): Added.
+ (WebCore::dataInRTFFormat): Added.
+ (WebCore::Editor::dataSelectionForPasteboard): Moved the implementation
+ of Pasteboard::getDataSelection here, refactoring to share code with the
+ writeSelectionToPasteboard function.
+ (WebCore::Editor::writeSelectionToPasteboard): Refactored to share code
+ with the new function above.
+
+ * platform/Pasteboard.h: Removed getDataSelection. One less layering violation.
+ * platform/mac/PasteboardMac.mm: Ditto.
+
2013-08-30 Rob Buis <[email protected]>
SVG error parsing empty path
Modified: trunk/Source/WebCore/editing/Editor.h (154899 => 154900)
--- trunk/Source/WebCore/editing/Editor.h 2013-08-30 18:00:36 UTC (rev 154899)
+++ trunk/Source/WebCore/editing/Editor.h 2013-08-30 18:02:36 UTC (rev 154900)
@@ -415,6 +415,11 @@
private:
explicit Editor(Frame&);
+#if PLATFORM(MAC)
+ PassRefPtr<SharedBuffer> selectionInWebArchiveFormat();
+ PassRefPtr<Range> adjustedSelectionRange();
+#endif
+
Frame& m_frame;
#if ENABLE(DELETION_UI)
OwnPtr<DeleteButtonController> m_deleteButtonController;
Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (154899 => 154900)
--- trunk/Source/WebCore/editing/mac/EditorMac.mm 2013-08-30 18:00:36 UTC (rev 154899)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm 2013-08-30 18:02:36 UTC (rev 154900)
@@ -268,22 +268,76 @@
return text;
}
+PassRefPtr<SharedBuffer> Editor::selectionInWebArchiveFormat()
+{
+ RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(&m_frame);
+ return archive ? SharedBuffer::wrapCFData(archive->rawDataRepresentation().get()) : 0;
+}
+
+PassRefPtr<Range> Editor::adjustedSelectionRange()
+{
+ // FIXME: Why do we need to adjust the selection to include the anchor tag it's in?
+ // Whoever wrote this code originally forgot to leave us a comment explaining the rationale.
+ RefPtr<Range> range = selectedRange();
+ Node* commonAncestor = range->commonAncestorContainer(IGNORE_EXCEPTION);
+ ASSERT(commonAncestor);
+ Node* enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(commonAncestor), HTMLNames::aTag);
+ if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(range->startPosition().anchorNode()), range->startPosition()) >= 0)
+ range->setStart(enclosingAnchor, 0, IGNORE_EXCEPTION);
+ return range;
+}
+
+static NSAttributedString *attributedStringForRange(Range& range)
+{
+ return [adoptNS([[WebHTMLConverter alloc] initWithDOMRange:kit(&range)]) attributedString];
+}
+
+static PassRefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *string)
+{
+ NSUInteger length = [string length];
+ return length ? SharedBuffer::wrapNSData([string RTFDFromRange:NSMakeRange(0, length) documentAttributes:nil]) : 0;
+}
+
+static PassRefPtr<SharedBuffer> dataInRTFFormat(NSAttributedString *string)
+{
+ NSUInteger length = [string length];
+ return length ? SharedBuffer::wrapNSData([string RTFFromRange:NSMakeRange(0, length) documentAttributes:nil]) : 0;
+}
+
PassRefPtr<SharedBuffer> Editor::dataSelectionForPasteboard(const String& pasteboardType)
{
- return Pasteboard::getDataSelection(&m_frame, pasteboardType);
+ // FIXME: The interface to this function is awkward. We'd probably be better off with three separate functions.
+ // As of this writing, this is only used in WebKit2 to implement the method -[WKView writeSelectionToPasteboard:types:],
+ // which is only used to support OS X services.
+
+ // FIXME: Does this function really need to use adjustedSelectionRange()? Because writeSelectionToPasteboard() just uses selectedRange().
+
+ if (pasteboardType == WebArchivePboardType)
+ return selectionInWebArchiveFormat();
+
+ if (pasteboardType == String(NSRTFDPboardType))
+ return dataInRTFDFormat(attributedStringForRange(*adjustedSelectionRange()));
+
+ if (pasteboardType == String(NSRTFPboardType)) {
+ NSAttributedString* attributedString = attributedStringForRange(*adjustedSelectionRange());
+ // FIXME: Why is this attachment character stripping needed here, but not needed in writeSelectionToPasteboard?
+ if ([attributedString containsAttachments])
+ attributedString = attributedStringByStrippingAttachmentCharacters(attributedString);
+ return dataInRTFFormat(attributedString);
+ }
+
+ return 0;
}
void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
{
+ NSAttributedString *attributedString = attributedStringForRange(*selectedRange());
+
PasteboardWebContent content;
content.canSmartCopyOrDelete = canSmartCopyOrDelete();
- if (RefPtr<LegacyWebArchive> webArchive = LegacyWebArchive::createFromSelection(&m_frame))
- content.dataInWebArchiveFormat = SharedBuffer::wrapCFData(webArchive->rawDataRepresentation().get());
- if (NSAttributedString *attributedString = [adoptNS([[WebHTMLConverter alloc] initWithDOMRange:kit(selectedRange().get())]) attributedString]) {
- if ([attributedString containsAttachments])
- content.dataInRTFDFormat = SharedBuffer::wrapNSData([attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil]);
- content.dataInRTFFormat = SharedBuffer::wrapNSData([attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil]);
- }
+ content.dataInWebArchiveFormat = selectionInWebArchiveFormat();
+ content.dataInRTFDFormat = [attributedString containsAttachments] ? dataInRTFDFormat(attributedString) : 0;
+ content.dataInRTFFormat = dataInRTFFormat(attributedString);
content.dataInStringFormat = stringSelectionForPasteboardWithImageAltText();
client()->getClientPasteboardDataForRange(selectedRange().get(), content.clientTypes, content.clientData);
Modified: trunk/Source/WebCore/platform/Pasteboard.h (154899 => 154900)
--- trunk/Source/WebCore/platform/Pasteboard.h 2013-08-30 18:00:36 UTC (rev 154899)
+++ trunk/Source/WebCore/platform/Pasteboard.h 2013-08-30 18:02:36 UTC (rev 154900)
@@ -55,7 +55,6 @@
#if PLATFORM(MAC)
#if PLATFORM(IOS)
-// FIXME: This is only temporary until Pasteboard is refactored for iOS.
extern NSString *WebArchivePboardType;
#else
extern const char* WebArchivePboardType;
@@ -103,7 +102,6 @@
String name() const { return m_pasteboardName; }
explicit Pasteboard(const String& pasteboardName);
- static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType); // FIXME: Layering violation.
#endif
#if PLATFORM(GTK)
Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (154899 => 154900)
--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2013-08-30 18:00:36 UTC (rev 154899)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2013-08-30 18:02:36 UTC (rev 154900)
@@ -138,39 +138,6 @@
m_changeCount = platformStrategies()->pasteboardStrategy()->setTypes(Vector<String>(), m_pasteboardName);
}
-PassRefPtr<SharedBuffer> Pasteboard::getDataSelection(Frame* frame, const String& pasteboardType)
-{
- if (pasteboardType == WebArchivePboardType) {
- RefPtr<LegacyWebArchive> archive = LegacyWebArchive::createFromSelection(frame);
- RetainPtr<CFDataRef> data = "" ? archive->rawDataRepresentation() : 0;
- return SharedBuffer::wrapNSData((NSData *)data.get());
- }
-
- RefPtr<Range> range = frame->editor().selectedRange();
- Node* commonAncestor = range->commonAncestorContainer(IGNORE_EXCEPTION);
- ASSERT(commonAncestor);
- Node* enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(commonAncestor), HTMLNames::aTag);
- if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(range->startPosition().anchorNode()), range->startPosition()) >= 0)
- range->setStart(enclosingAnchor, 0, IGNORE_EXCEPTION);
-
- NSAttributedString* attributedString = nil;
- RetainPtr<WebHTMLConverter> converter = adoptNS([[WebHTMLConverter alloc] initWithDOMRange:kit(range.get())]);
- if (converter)
- attributedString = [converter.get() attributedString];
-
- if (pasteboardType == String(NSRTFDPboardType)) {
- NSData *RTFDData = [attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
- return SharedBuffer::wrapNSData((NSData *)RTFDData);
- }
- if (pasteboardType == String(NSRTFPboardType)) {
- if ([attributedString containsAttachments])
- attributedString = attributedStringByStrippingAttachmentCharacters(attributedString);
- NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
- return SharedBuffer::wrapNSData((NSData *)RTFData);
- }
- return 0;
-}
-
void Pasteboard::setTypes(const PasteboardWebContent& content)
{
Vector<String> types;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes