📄 pasteboardmac.mm
字号:
[s replaceOccurrencesOfString:NonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])]; [pasteboard setString:s forType:NSStringPboardType]; [s release]; } if ([types containsObject:WebSmartPastePboardType]) { [pasteboard setData:nil forType:WebSmartPastePboardType]; }} void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame){ Pasteboard::writeSelection(m_pasteboard.get(), selectedRange, canSmartCopyOrDelete, frame);}void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame){ if (WebArchivePboardType == nil) Pasteboard::generalPasteboard(); //Initialises pasteboard types if (types == nil) { types = writableTypesForURL(); [pasteboard declareTypes:types owner:nil]; } ASSERT(!url.isEmpty()); NSURL *cocoaURL = url; NSString *userVisibleString = frame->editor()->client()->userVisibleString(cocoaURL); NSString *title = (NSString*)titleStr; if ([title length] == 0) { title = [[cocoaURL path] lastPathComponent]; if ([title length] == 0) title = userVisibleString; } if ([types containsObject:WebURLsWithTitlesPboardType]) [pasteboard setPropertyList:[NSArray arrayWithObjects:[NSArray arrayWithObject:userVisibleString], [NSArray arrayWithObject:(NSString*)titleStr.stripWhiteSpace()], nil] forType:WebURLsWithTitlesPboardType]; if ([types containsObject:NSURLPboardType]) [cocoaURL writeToPasteboard:pasteboard]; if ([types containsObject:WebURLPboardType]) [pasteboard setString:userVisibleString forType:WebURLPboardType]; if ([types containsObject:WebURLNamePboardType]) [pasteboard setString:title forType:WebURLNamePboardType]; if ([types containsObject:NSStringPboardType]) [pasteboard setString:userVisibleString forType:NSStringPboardType];} void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame){ Pasteboard::writeURL(m_pasteboard.get(), nil, url, titleStr, frame);}static NSFileWrapper* fileWrapperForImage(CachedResource* resource, NSURL *url){ SharedBuffer* coreData = resource->data(); NSData *data = [[[NSData alloc] initWithBytes:coreData->data() length:coreData->size()] autorelease]; NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease]; String coreMIMEType = resource->response().mimeType(); NSString *MIMEType = nil; if (!coreMIMEType.isNull()) MIMEType = coreMIMEType; [wrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, MIMEType)]; return wrapper;}void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper){ NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper]; NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attachment]; [attachment release]; NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil]; [m_pasteboard.get() setData:RTFDData forType:NSRTFDPboardType];}void Pasteboard::writeImage(Node* node, const KURL& url, const String& title){ ASSERT(node); Frame* frame = node->document()->frame(); NSURL *cocoaURL = url; ASSERT(cocoaURL); ASSERT(node->renderer() && node->renderer()->isImage()); RenderImage* renderer = toRenderImage(node->renderer()); CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage()); ASSERT(cachedImage); if (cachedImage->errorOccurred()) return; NSArray* types = writableTypesForImage(); [m_pasteboard.get() declareTypes:types owner:nil]; writeURL(m_pasteboard.get(), types, cocoaURL, nsStringNilIfEmpty(title), frame); Image* image = cachedImage->image(); ASSERT(image); [m_pasteboard.get() setData:[image->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType]; String MIMEType = cachedImage->response().mimeType(); ASSERT(MIMETypeRegistry::isSupportedImageResourceMIMEType(MIMEType)); writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, cocoaURL));}bool Pasteboard::canSmartReplace(){ return [[m_pasteboard.get() types] containsObject:WebSmartPastePboardType];}String Pasteboard::plainText(Frame* frame){ NSArray *types = [m_pasteboard.get() types]; if ([types containsObject:NSStringPboardType]) return [[m_pasteboard.get() stringForType:NSStringPboardType] precomposedStringWithCanonicalMapping]; NSAttributedString *attributedString = nil; NSString *string; if ([types containsObject:NSRTFDPboardType]) attributedString = [[NSAttributedString alloc] initWithRTFD:[m_pasteboard.get() dataForType:NSRTFDPboardType] documentAttributes:NULL]; if (attributedString == nil && [types containsObject:NSRTFPboardType]) attributedString = [[NSAttributedString alloc] initWithRTF:[m_pasteboard.get() dataForType:NSRTFPboardType] documentAttributes:NULL]; if (attributedString != nil) { string = [[attributedString string] precomposedStringWithCanonicalMapping]; [attributedString release]; return string; } if ([types containsObject:NSFilenamesPboardType]) { string = [[[m_pasteboard.get() propertyListForType:NSFilenamesPboardType] componentsJoinedByString:@"\n"] precomposedStringWithCanonicalMapping]; if (string != nil) return string; } if (NSURL *url = [NSURL URLFromPasteboard:m_pasteboard.get()]) { // FIXME: using the editorClient to call into webkit, for now, since // calling _web_userVisibleString from WebCore involves migrating a sizable web of // helper code that should either be done in a separate patch or figured out in another way. string = frame->editor()->client()->userVisibleString(url); if ([string length] > 0) return [string precomposedStringWithCanonicalMapping]; } return String(); }PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText){ NSArray *types = [m_pasteboard.get() types]; chosePlainText = false; if ([types containsObject:NSHTMLPboardType]) { NSString *HTMLString = [m_pasteboard.get() stringForType:NSHTMLPboardType]; // This is a hack to make Microsoft's HTML pasteboard data work. See 3778785. if ([HTMLString hasPrefix:@"Version:"]) { NSRange range = [HTMLString rangeOfString:@"<html" options:NSCaseInsensitiveSearch]; if (range.location != NSNotFound) { HTMLString = [HTMLString substringFromIndex:range.location]; } } if ([HTMLString length] != 0) { RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), HTMLString, ""); if (fragment) return fragment.release(); } } if (allowPlainText && [types containsObject:NSStringPboardType]) { chosePlainText = true; RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), [m_pasteboard.get() stringForType:NSStringPboardType]); if (fragment) return fragment.release(); } return 0;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -