 Chromium Code Reviews
 Chromium Code Reviews Issue 270613004:
  Implement "Copy image" for canvas (blink side).  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 270613004:
  Implement "Copy image" for canvas (blink side).  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 61 #include "core/editing/markup.h" | 61 #include "core/editing/markup.h" | 
| 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/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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); | 
| 431 if (!renderer) | |
| 430 return; | 432 return; | 
| 431 | 433 | 
| 432 RenderImage* renderer = toRenderImage(node->renderer()); | 434 Image* image = 0; | 
| 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:image/png"); | |
| 
Justin Novosad
2014/05/09 19:56:38
This URL does not seem useful. Why not leave urlSt
 | |
| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 return m_frame.spellChecker(); | 1240 return m_frame.spellChecker(); | 
| 1230 } | 1241 } | 
| 1231 | 1242 | 
| 1232 void Editor::toggleOverwriteModeEnabled() | 1243 void Editor::toggleOverwriteModeEnabled() | 
| 1233 { | 1244 { | 
| 1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1245 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 
| 1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1246 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 
| 1236 } | 1247 } | 
| 1237 | 1248 | 
| 1238 } // namespace WebCore | 1249 } // namespace WebCore | 
| OLD | NEW |