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

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: addressed nits Created 6 years, 5 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
« no previous file with comments | « no previous file | Source/web/ContextMenuClientImpl.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "core/events/ClipboardEvent.h" 61 #include "core/events/ClipboardEvent.h"
62 #include "core/events/KeyboardEvent.h" 62 #include "core/events/KeyboardEvent.h"
63 #include "core/events/ScopedEventQueue.h" 63 #include "core/events/ScopedEventQueue.h"
64 #include "core/events/TextEvent.h" 64 #include "core/events/TextEvent.h"
65 #include "core/fetch/ImageResource.h" 65 #include "core/fetch/ImageResource.h"
66 #include "core/fetch/ResourceFetcher.h" 66 #include "core/fetch/ResourceFetcher.h"
67 #include "core/frame/FrameView.h" 67 #include "core/frame/FrameView.h"
68 #include "core/frame/LocalFrame.h" 68 #include "core/frame/LocalFrame.h"
69 #include "core/frame/Settings.h" 69 #include "core/frame/Settings.h"
70 #include "core/frame/UseCounter.h" 70 #include "core/frame/UseCounter.h"
71 #include "core/html/HTMLCanvasElement.h"
71 #include "core/html/HTMLImageElement.h" 72 #include "core/html/HTMLImageElement.h"
72 #include "core/html/HTMLInputElement.h" 73 #include "core/html/HTMLInputElement.h"
73 #include "core/html/HTMLTextAreaElement.h" 74 #include "core/html/HTMLTextAreaElement.h"
74 #include "core/html/parser/HTMLParserIdioms.h" 75 #include "core/html/parser/HTMLParserIdioms.h"
75 #include "core/loader/EmptyClients.h" 76 #include "core/loader/EmptyClients.h"
76 #include "core/page/EditorClient.h" 77 #include "core/page/EditorClient.h"
77 #include "core/page/EventHandler.h" 78 #include "core/page/EventHandler.h"
78 #include "core/page/FocusController.h" 79 #include "core/page/FocusController.h"
79 #include "core/page/Page.h" 80 #include "core/page/Page.h"
80 #include "core/rendering/HitTestResult.h" 81 #include "core/rendering/HitTestResult.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 pasteAsFragment(fragment, canSmartReplaceWithPasteboard(pasteboard), cho sePlainText); 414 pasteAsFragment(fragment, canSmartReplaceWithPasteboard(pasteboard), cho sePlainText);
414 } 415 }
415 416
416 void Editor::writeSelectionToPasteboard(Pasteboard* pasteboard, Range* selectedR ange, const String& plainText) 417 void Editor::writeSelectionToPasteboard(Pasteboard* pasteboard, Range* selectedR ange, const String& plainText)
417 { 418 {
418 String html = createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs); 419 String html = createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
419 KURL url = selectedRange->startContainer()->document().url(); 420 KURL url = selectedRange->startContainer()->document().url();
420 pasteboard->writeHTML(html, url, plainText, canSmartCopyOrDelete()); 421 pasteboard->writeHTML(html, url, plainText, canSmartCopyOrDelete());
421 } 422 }
422 423
424 static Image* imageFromNode(const Node& node)
425 {
426 node.document().updateLayoutIgnorePendingStylesheets();
427 RenderObject* renderer = node.renderer();
428 if (!renderer)
429 return nullptr;
430
431 if (renderer->isCanvas())
432 return toHTMLCanvasElement(node).copiedImage();
433
434 if (renderer->isImage()) {
435 RenderImage* renderImage = toRenderImage(renderer);
436 if (!renderImage)
437 return nullptr;
438
439 ImageResource* cachedImage = renderImage->cachedImage();
440 if (!cachedImage || cachedImage->errorOccurred())
441 return nullptr;
442 return cachedImage->imageForRenderer(renderImage);
443 }
444
445 return nullptr;
446 }
447
423 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const String& title) 448 static void writeImageNodeToPasteboard(Pasteboard* pasteboard, Node* node, const String& title)
424 { 449 {
425 ASSERT(pasteboard); 450 ASSERT(pasteboard);
426 ASSERT(node); 451 ASSERT(node);
427 452
428 if (!(node->renderer() && node->renderer()->isImage())) 453 Image* image = imageFromNode(*node);
454 if (!image)
429 return; 455 return;
430 456
431 RenderImage* renderer = toRenderImage(node->renderer());
432 ImageResource* cachedImage = renderer->cachedImage();
433 if (!cachedImage || cachedImage->errorOccurred())
434 return;
435 Image* image = cachedImage->imageForRenderer(renderer);
436 ASSERT(image);
437
438 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma geURL. 457 // FIXME: This should probably be reconciled with HitTestResult::absoluteIma geURL.
439 AtomicString urlString; 458 AtomicString urlString;
440 if (isHTMLImageElement(*node) || isHTMLInputElement(*node)) 459 if (isHTMLImageElement(*node) || isHTMLInputElement(*node))
441 urlString = toElement(node)->getAttribute(srcAttr); 460 urlString = toElement(node)->getAttribute(srcAttr);
442 else if (isSVGImageElement(*node)) 461 else if (isSVGImageElement(*node))
443 urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr); 462 urlString = toElement(node)->getAttribute(XLinkNames::hrefAttr);
444 else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node)) 463 else if (isHTMLEmbedElement(*node) || isHTMLObjectElement(*node) || isHTMLCa nvasElement(*node))
445 urlString = toElement(node)->imageSourceURL(); 464 urlString = toElement(node)->imageSourceURL();
446 KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(strip LeadingAndTrailingHTMLSpaces(urlString)); 465 KURL url = urlString.isEmpty() ? KURL() : node->document().completeURL(strip LeadingAndTrailingHTMLSpaces(urlString));
447 466
448 pasteboard->writeImage(image, url, title); 467 pasteboard->writeImage(image, url, title);
449 } 468 }
450 469
451 // Returns whether caller should continue with "the default processing", which i s the same as 470 // Returns whether caller should continue with "the default processing", which i s the same as
452 // the event handler NOT setting the return value to false 471 // the event handler NOT setting the return value to false
453 bool Editor::dispatchCPPEvent(const AtomicString &eventType, DataTransferAccessP olicy policy, PasteMode pasteMode) 472 bool Editor::dispatchCPPEvent(const AtomicString &eventType, DataTransferAccessP olicy policy, PasteMode pasteMode)
454 { 473 {
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 1278 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
1260 } 1279 }
1261 1280
1262 void Editor::trace(Visitor* visitor) 1281 void Editor::trace(Visitor* visitor)
1263 { 1282 {
1264 visitor->trace(m_lastEditCommand); 1283 visitor->trace(m_lastEditCommand);
1265 visitor->trace(m_mark); 1284 visitor->trace(m_mark);
1266 } 1285 }
1267 1286
1268 } // namespace WebCore 1287 } // namespace WebCore
OLDNEW
« 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