Index: Source/core/editing/Editor.cpp |
diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp |
index 01b7554bca9700dce716dd382c9acc41252bb6b9..aaa7439a69297738ef17fc2bef86b108214c2e6c 100644 |
--- a/Source/core/editing/Editor.cpp |
+++ b/Source/core/editing/Editor.cpp |
@@ -68,6 +68,7 @@ |
#include "core/frame/LocalFrame.h" |
#include "core/frame/Settings.h" |
#include "core/frame/UseCounter.h" |
+#include "core/html/HTMLCanvasElement.h" |
#include "core/html/HTMLImageElement.h" |
#include "core/html/HTMLInputElement.h" |
#include "core/html/HTMLTextAreaElement.h" |
@@ -420,20 +421,38 @@ void Editor::writeSelectionToPasteboard(Pasteboard* pasteboard, Range* selectedR |
pasteboard->writeHTML(html, url, plainText, canSmartCopyOrDelete()); |
} |
+static Image* imageFromNode(const Node& node) |
+{ |
+ node.document().updateLayoutIgnorePendingStylesheets(); |
+ RenderObject* renderer = node.renderer(); |
+ if (!renderer) |
+ return nullptr; |
+ |
+ if (renderer->isCanvas()) |
+ return toHTMLCanvasElement(node).copiedImage(); |
+ |
+ if (renderer->isImage()) { |
+ RenderImage* renderImage = toRenderImage(renderer); |
+ if (!renderImage) |
+ return nullptr; |
+ |
+ ImageResource* cachedImage = renderImage->cachedImage(); |
+ if (!cachedImage || cachedImage->errorOccurred()) |
+ return nullptr; |
+ return cachedImage->imageForRenderer(renderImage); |
+ } |
+ |
+ return nullptr; |
+} |
+ |
static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const String& title) |
{ |
ASSERT(pasteboard); |
ASSERT(node); |
- if (!(node->renderer() && node->renderer()->isImage())) |
- return; |
- |
- RenderImage* renderer = toRenderImage(node->renderer()); |
- ImageResource* cachedImage = renderer->cachedImage(); |
- if (!cachedImage || cachedImage->errorOccurred()) |
+ Image* image = imageFromNode(*node); |
+ if (!image) |
return; |
- Image* image = cachedImage->imageForRenderer(renderer); |
- ASSERT(image); |
// FIXME: This should probably be reconciled with HitTestResult::absoluteImageURL. |
AtomicString urlString; |
@@ -441,7 +460,7 @@ static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const |
urlString = toElement(node)->getAttribute(srcAttr); |
else if (isSVGImageElement(*node)) |
urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr); |
- else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node)) |
+ else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node) || isHTMLCanvasElement(*node)) |
urlString = toElement(node)->imageSourceURL(); |
KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString)); |