Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Unified Diff: Source/core/editing/Editor.cpp

Issue 270613004: Implement "Copy image" for canvas (blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed nits Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/web/ContextMenuClientImpl.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « no previous file | Source/web/ContextMenuClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698