Commit 1664cc28 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Move Google code out of third_party/.

In https://codereview.chromium.org/2674002, Google code was put into
the third_party/mozilla/NSPasteboard+Utils.h|mm files. This was not
imported code from Mozilla and did not belong there.

This utility code is moved into a Chromium file (with slight
modernization.)

The lawyers have approved this.

BUG=none
TEST=no visible change intended

Change-Id: Icf3a91d10d7d52757b7dd220b2703acf3ff45b4d
Reviewed-on: https://chromium-review.googlesource.com/c/1355525Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612379}
parent a4207c78
......@@ -18,6 +18,7 @@
#include "content/public/common/drop_data.h"
#include "third_party/blink/public/platform/web_input_event.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
#include "ui/base/clipboard/clipboard_util_mac.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/dragdrop/cocoa_dnd_util.h"
......@@ -387,7 +388,7 @@ GetRenderWidgetHostAtPoint:(const NSPoint&)viewPoint
NSString* html = [pboard stringForType:ui::kChromeDragImageHTMLPboardType];
data->html = base::NullableString16(base::SysNSStringToUTF16(html), false);
} else if ([types containsObject:NSRTFPboardType]) {
NSString* html = [pboard htmlFromRtf];
NSString* html = ui::ClipboardUtil::GetHTMLFromRTFOnPasteboard(pboard);
data->html = base::NullableString16(base::SysNSStringToUTF16(html), false);
}
......
......@@ -60,11 +60,3 @@ MOZILLA_EXPORT extern NSString* const kWebURLsWithTitlesPboardType;
- (BOOL) containsURLDataConvertingTextToURL:(BOOL)convertTextToURL;
@end
@interface NSPasteboard(ChromiumHTMLUtils)
// Returns the HTML converted from RTF data on the pasteboard. If there is
// none, returns an empty string.
- (NSString*)htmlFromRtf;
@end
......@@ -284,28 +284,3 @@ NSString* const kWebURLsWithTitlesPboardType = @"WebURLsWithTitlesPboardType";
return NO;
}
@end
@implementation NSPasteboard(ChromiumHTMLUtils)
// Convert the RTF to HTML via an NSAttributedString.
- (NSString*)htmlFromRtf {
if (![[self types] containsObject:NSRTFPboardType])
return @"";
NSAttributedString* attributed =
[[[NSAttributedString alloc]
initWithRTF:[self dataForType:NSRTFPboardType]
documentAttributes:nil] autorelease];
NSDictionary* attributeDict =
[NSDictionary dictionaryWithObject:NSHTMLTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
NSData* htmlData =
[attributed dataFromRange:NSMakeRange(0, [attributed length])
documentAttributes:attributeDict
error:nil];
// According to the docs, NSHTMLTextDocumentType is UTF8.
return [[[NSString alloc]
initWithData:htmlData encoding:NSUTF8StringEncoding] autorelease];
}
@end
......@@ -30,7 +30,6 @@ Local modifications:
modified to accept an additional parameter convertingTextToURL:, which
indicates whether the string contents of the pasteboard should be
interpreted as a URL if possible.
- -[NSPasteboard htmlFromRtf] was added to do rtf->html conversion.
- NSWorkspace+Utils.m was modified to compile on the x86_64 architecture.
- MOZILLA_EXPORT was added to some constants in NSPasteboard+Utils.h.
- +[NSWorkspace(CaminoDefaultBrowserAdditions) isLeopardOrHigher] hidden since
......
......@@ -281,9 +281,11 @@ void ClipboardMac::ReadHTML(ClipboardType type,
@[ NSHTMLPboardType, NSRTFPboardType, NSPasteboardTypeString ];
NSString* bestType = [pb availableTypeFromArray:supportedTypes];
if (bestType) {
NSString* contents = [pb stringForType:bestType];
NSString* contents;
if ([bestType isEqualToString:NSRTFPboardType])
contents = [pb htmlFromRtf];
contents = ClipboardUtil::GetHTMLFromRTFOnPasteboard(pb);
else
contents = [pb stringForType:bestType];
*markup = base::SysNSStringToUTF16(contents);
}
......
......@@ -63,16 +63,21 @@ class UI_BASE_EXPORT ClipboardUtil {
// and its associated data.
static void AddDataToPasteboard(NSPasteboard* pboard, NSPasteboardItem* item);
// Returns whether the operation was succesful. On success, the two arrays are
// guaranteed to be equal length, and are populated with strings of |urls| and
// |titles|.
// Returns whether the operation was successful. On success, the two arrays
// are guaranteed to be equal length, and are populated with strings of |urls|
// and |titles|.
static bool URLsAndTitlesFromPasteboard(NSPasteboard* pboard,
NSArray** urls,
NSArray** titles);
// Gets the NSPasteboard specified from the clipboard type.
static NSPasteboard* PasteboardFromType(ui::ClipboardType type);
// If there is RTF data on the pasteboard, returns an HTML version of it.
// Otherwise returns nil.
static NSString* GetHTMLFromRTFOnPasteboard(NSPasteboard* pboard);
};
}
} // namespace ui
#endif // UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_MAC_H_
......@@ -193,4 +193,25 @@ NSPasteboard* ClipboardUtil::PasteboardFromType(ui::ClipboardType type) {
return [NSPasteboard pasteboardWithName:type_string];
}
// static
NSString* ClipboardUtil::GetHTMLFromRTFOnPasteboard(NSPasteboard* pboard) {
NSData* rtfData = [pboard dataForType:NSRTFPboardType];
if (!rtfData)
return nil;
NSAttributedString* attributed =
[[[NSAttributedString alloc] initWithRTF:rtfData
documentAttributes:nil] autorelease];
NSData* htmlData =
[attributed dataFromRange:NSMakeRange(0, [attributed length])
documentAttributes:@{
NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType
}
error:nil];
// According to the docs, NSHTMLTextDocumentType is UTF8.
return [[[NSString alloc] initWithData:htmlData
encoding:NSUTF8StringEncoding] autorelease];
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment