void Pasteboard::writeImage(Node* node, const KURL&, const String& title) { ASSERT(node); if (!(node->renderer() && node->renderer()->isImage())) return; RenderImage* renderer = toRenderImage(node->renderer()); CachedImage* cachedImage = renderer->cachedImage(); if (!cachedImage || cachedImage->errorOccurred()) return; Image* image = cachedImage->imageForRenderer(renderer); ASSERT(image); NativeImagePtr bitmap = image->nativeImageForCurrentFrame(); if (!bitmap) return; // If the image is wrapped in a link, |url| points to the target of the // link. This isn't useful to us, so get the actual image URL. AtomicString urlString; if (node->hasTagName(HTMLNames::imgTag) || node->hasTagName(HTMLNames::inputTag)) urlString = static_cast<Element*>(node)->getAttribute(HTMLNames::srcAttr); #if ENABLE(SVG) else if (node->hasTagName(SVGNames::imageTag)) urlString = static_cast<Element*>(node)->getAttribute(XLinkNames::hrefAttr); #endif else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) { Element* element = static_cast<Element*>(node); urlString = element->getAttribute(element->imageSourceAttributeName()); } KURL url = urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString)); WebKit::WebImage webImage = bitmap->bitmap(); WebKit::Platform::current()->clipboard()->writeImage(webImage, WebKit::WebURL(url), WebKit::WebString(title)); }
WebImage& WebImage::operator=(const PassRefPtr<Image>& image) { NativeImagePtr p; if (image.get() && (p = image->nativeImageForCurrentFrame())) assign(p->bitmap()); else reset(); return *this; }
void PlatformSupport::clipboardWriteImage(NativeImagePtr image, const KURL& sourceURL, const String& title) { #if WEBKIT_USING_SKIA WebImage webImage(image->bitmap()); #else WebImage webImage(image); #endif webKitPlatformSupport()->clipboard()->writeImage(webImage, sourceURL, title); }