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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "core/events/ClipboardEvent.h" 62 #include "core/events/ClipboardEvent.h"
63 #include "core/events/KeyboardEvent.h" 63 #include "core/events/KeyboardEvent.h"
64 #include "core/events/ScopedEventQueue.h" 64 #include "core/events/ScopedEventQueue.h"
65 #include "core/events/TextEvent.h" 65 #include "core/events/TextEvent.h"
66 #include "core/fetch/ImageResource.h" 66 #include "core/fetch/ImageResource.h"
67 #include "core/fetch/ResourceFetcher.h" 67 #include "core/fetch/ResourceFetcher.h"
68 #include "core/frame/FrameView.h" 68 #include "core/frame/FrameView.h"
69 #include "core/frame/LocalFrame.h" 69 #include "core/frame/LocalFrame.h"
70 #include "core/frame/Settings.h" 70 #include "core/frame/Settings.h"
71 #include "core/frame/UseCounter.h" 71 #include "core/frame/UseCounter.h"
72 #include "core/html/HTMLCanvasElement.h"
72 #include "core/html/HTMLImageElement.h" 73 #include "core/html/HTMLImageElement.h"
73 #include "core/html/HTMLInputElement.h" 74 #include "core/html/HTMLInputElement.h"
74 #include "core/html/HTMLTextAreaElement.h" 75 #include "core/html/HTMLTextAreaElement.h"
75 #include "core/html/parser/HTMLParserIdioms.h" 76 #include "core/html/parser/HTMLParserIdioms.h"
76 #include "core/loader/EmptyClients.h" 77 #include "core/loader/EmptyClients.h"
77 #include "core/page/EditorClient.h" 78 #include "core/page/EditorClient.h"
78 #include "core/page/EventHandler.h" 79 #include "core/page/EventHandler.h"
79 #include "core/page/FocusController.h" 80 #include "core/page/FocusController.h"
80 #include "core/page/Page.h" 81 #include "core/page/Page.h"
81 #include "core/rendering/HitTestResult.h" 82 #include "core/rendering/HitTestResult.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 String html = createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs); 420 String html = createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
420 KURL url = selectedRange->startContainer()->document().url(); 421 KURL url = selectedRange->startContainer()->document().url();
421 pasteboard->writeHTML(html, url, plainText, canSmartCopyOrDelete()); 422 pasteboard->writeHTML(html, url, plainText, canSmartCopyOrDelete());
422 } 423 }
423 424
424 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const String& title) 425 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const String& title)
425 { 426 {
426 ASSERT(pasteboard); 427 ASSERT(pasteboard);
427 ASSERT(node); 428 ASSERT(node);
428 429
429 if (!(node->renderer() && node->renderer()->isImage())) 430 RenderObject* renderer = node->renderer();
yosin_UTC9 2014/06/20 04:24:10 It seems it is better to call |node->document().up
zino 2014/06/20 07:07:09 Done.
431 if (!renderer)
430 return; 432 return;
431 433
432 RenderImage* renderer = toRenderImage(node->renderer()); 434 Image* image = 0;
yosin_UTC9 2014/06/20 04:24:10 nit: How about having helper function to return |I
zino 2014/06/20 07:07:08 Done.
433 ImageResource* cachedImage = renderer->cachedImage(); 435 if (renderer->isImage()) {
434 if (!cachedImage || cachedImage->errorOccurred()) 436 RenderImage* renderImage = toRenderImage(renderer);
437 ImageResource* cachedImage = renderImage->cachedImage();
438 if (!cachedImage || cachedImage->errorOccurred())
439 return;
440 image = cachedImage->imageForRenderer(renderImage);
441 } else if (renderer->isCanvas()) {
442 image = toHTMLCanvasElement(node)->copiedImage();
443 } else {
435 return; 444 return;
436 Image* image = cachedImage->imageForRenderer(renderer); 445 }
437 ASSERT(image); 446 ASSERT(image);
438 447
439 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma geURL. 448 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma geURL.
440 AtomicString urlString; 449 AtomicString urlString;
441 if (isHTMLImageElement(*node) || isHTMLInputElement(*node)) 450 if (isHTMLImageElement(*node) || isHTMLInputElement(*node))
442 urlString = toElement(node)->getAttribute(srcAttr); 451 urlString = toElement(node)->getAttribute(srcAttr);
443 else if (isSVGImageElement(*node)) 452 else if (isSVGImageElement(*node))
444 urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr); 453 urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr);
445 else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node)) 454 else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node))
446 urlString = toElement(node)->imageSourceURL(); 455 urlString = toElement(node)->imageSourceURL();
456 else if (isHTMLCanvasElement(*node))
457 urlString = AtomicString("data:,[canvas]");
yosin_UTC9 2014/06/20 04:24:10 Just curiosity, what "data:,[canvas]" is? Where do
zino 2014/06/20 07:07:09 I thought that the URL is not needed in the case o
447 KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(strip LeadingAndTrailingHTMLSpaces(urlString)); 458 KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(strip LeadingAndTrailingHTMLSpaces(urlString));
448 459
449 pasteboard->writeImage(image, url, title); 460 pasteboard->writeImage(image, url, title);
450 } 461 }
451 462
452 // Returns whether caller should continue with "the default processing", which i s the same as 463 // Returns whether caller should continue with "the default processing", which i s the same as
453 // the event handler NOT setting the return value to false 464 // the event handler NOT setting the return value to false
454 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli cy policy, PasteMode pasteMode) 465 bool Editor::dispatchCPPEvent(const AtomicString &eventType, ClipboardAccessPoli cy policy, PasteMode pasteMode)
455 { 466 {
456 Node* target = findEventTargetFromSelection(); 467 Node* target = findEventTargetFromSelection();
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 1313 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
1303 } 1314 }
1304 1315
1305 void Editor::trace(Visitor* visitor) 1316 void Editor::trace(Visitor* visitor)
1306 { 1317 {
1307 visitor->trace(m_lastEditCommand); 1318 visitor->trace(m_lastEditCommand);
1308 visitor->trace(m_mark); 1319 visitor->trace(m_mark);
1309 } 1320 }
1310 1321
1311 } // namespace WebCore 1322 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/web/ContextMenuClientImpl.cpp » ('j') | Source/web/ContextMenuClientImpl.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698