2007-04-09 Andrew Wellington <proton@wiretapped.net>
authorandrew <andrew@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Apr 2007 11:48:45 +0000 (11:48 +0000)
committerandrew <andrew@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Apr 2007 11:48:45 +0000 (11:48 +0000)
        Reviewed by Justin Garcia.

        Layout test for http://bugs.webkit.org/show_bug.cgi?id=12959
        "REGRESSION: Edit -> Copy not enabled on standalone images"

        * editing/pasteboard/copy-standalone-image-expected.checksum: Added.
        * editing/pasteboard/copy-standalone-image-expected.png: Added.
        * editing/pasteboard/copy-standalone-image-expected.txt: Added.
        * editing/pasteboard/copy-standalone-image.html: Added.

2007-04-09  Andrew Wellington  <proton@wiretapped.net>

        Reviewed by Justin Garcia.

        Fix for http://bugs.webkit.org/show_bug.cgi?id=12959
        "REGRESSION: Edit -> Copy not enabled on standalone images"

        * dom/Document.h: Add support for determining if a document is an image
        (WebCore::Document::isImageDocument):
        * editing/Editor.cpp:
        (WebCore::Editor::canCopy): Image documents are copyable
        (WebCore::Editor::copy): If copying an image document, call appropriate pasteboard methods
        * loader/ImageDocument.h:
        (WebCore::ImageDocument::isImageDocument): Override to return true for image documents
        * platform/Pasteboard.h: Add new writeImage function to pasteboard
        * platform/mac/PasteboardMac.mm:
        (WebCore::Pasteboard::writeImage): Add writeImage implementation that takes Node and URL
        * platform/qt/PasteboardQt.cpp:
        (WebCore::Pasteboard::writeImage): Stub for Qt implementation of pasteboard

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@20802 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/copy-standalone-image-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-standalone-image-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-standalone-image-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-standalone-image.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.h
WebCore/editing/Editor.cpp
WebCore/loader/ImageDocument.h
WebCore/platform/Pasteboard.h
WebCore/platform/mac/PasteboardMac.mm
WebCore/platform/qt/PasteboardQt.cpp

index 122da11..fc3ef3f 100644 (file)
@@ -1,3 +1,15 @@
+2007-04-09  Andrew Wellington  <proton@wiretapped.net>
+
+        Reviewed by Justin Garcia.
+        
+        Layout test for http://bugs.webkit.org/show_bug.cgi?id=12959
+        "REGRESSION: Edit -> Copy not enabled on standalone images"
+
+        * editing/pasteboard/copy-standalone-image-expected.checksum: Added.
+        * editing/pasteboard/copy-standalone-image-expected.png: Added.
+        * editing/pasteboard/copy-standalone-image-expected.txt: Added.
+        * editing/pasteboard/copy-standalone-image.html: Added.
+
 2007-04-06  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Beth Dakin.
diff --git a/LayoutTests/editing/pasteboard/copy-standalone-image-expected.checksum b/LayoutTests/editing/pasteboard/copy-standalone-image-expected.checksum
new file mode 100644 (file)
index 0000000..07d9170
--- /dev/null
@@ -0,0 +1 @@
+26bb3f7102642ad149b1a343a58a0298
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/copy-standalone-image-expected.png b/LayoutTests/editing/pasteboard/copy-standalone-image-expected.png
new file mode 100644 (file)
index 0000000..dfee86b
Binary files /dev/null and b/LayoutTests/editing/pasteboard/copy-standalone-image-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/copy-standalone-image-expected.txt b/LayoutTests/editing/pasteboard/copy-standalone-image-expected.txt
new file mode 100644 (file)
index 0000000..40f4ab5
--- /dev/null
@@ -0,0 +1,31 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of P > DIV > BODY > HTML > #document to 1 of P > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 354x18
+          text run at (0,0) width 354: "This is an automatic test of copying an image document."
+      RenderBlock {P} at (0,34) size 784x36
+        RenderText {#text} at (0,0) size 759x36
+          text run at (0,0) width 759: "To perform this test manually, click once in the image frame, choose Edit -> Copy then click in the red box and paste the"
+          text run at (0,18) width 355: "image. If the image pastes successfully the test is passed."
+      RenderBlock (anonymous) at (0,86) size 784x154
+        RenderPartObject {IFRAME} at (0,0) size 304x154 [border: (2px solid #0000FF)]
+          layer at (0,0) size 300x150
+            RenderView at (0,0) size 300x150
+          layer at (0,0) size 300x107
+            RenderBlock {HTML} at (0,0) size 300x107
+              RenderBody {BODY} at (0,0) size 300x107
+                RenderImage {IMG} at (0,0) size 76x103
+        RenderText {#text} at (0,0) size 0x0
+      RenderBlock {DIV} at (0,240) size 784x131 [border: (2px solid #FF0000)]
+        RenderBlock {P} at (14,14) size 756x103
+          RenderImage {IMG} at (0,0) size 76x103
+caret: position 1 of child 0 {IMG} of child 0 {P} of child 7 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/copy-standalone-image.html b/LayoutTests/editing/pasteboard/copy-standalone-image.html
new file mode 100644 (file)
index 0000000..9d28299
--- /dev/null
@@ -0,0 +1,41 @@
+<html> 
+<head>
+<script>
+if (window.layoutTestController)
+     layoutTestController.dumpEditingCallbacks();
+
+function editingTest() {
+    frames['imageframe'].document.execCommand("Copy");
+    
+    var s = window.getSelection();
+    var e = document.getElementById("dest");
+    s.setPosition(e, 0);
+    document.execCommand("Paste");
+}
+</script>
+<style>
+.editable { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+
+iframe {
+    border: 2px solid blue; 
+}
+</style>
+</head>
+<body>
+
+<p>This is an automatic test of copying an image document.</p>
+<p>To perform this test manually, click once in the image frame, choose Edit -> Copy
+then click in the red box and paste the image. If the image pastes successfully the
+test is passed.</p>
+
+<iframe name="imageframe" src="../abe.jpg" onload="javascript:editingTest()">
+</iframe>
+
+<div id="dest" class="editable" contenteditable="true"> </div>
+
+</body>
+</html>
index de299f9..7e084c6 100644 (file)
@@ -1,3 +1,23 @@
+2007-04-09  Andrew Wellington  <proton@wiretapped.net>
+
+        Reviewed by Justin Garcia.
+        
+        Fix for http://bugs.webkit.org/show_bug.cgi?id=12959
+        "REGRESSION: Edit -> Copy not enabled on standalone images"
+
+        * dom/Document.h: Add support for determining if a document is an image
+        (WebCore::Document::isImageDocument):
+        * editing/Editor.cpp:
+        (WebCore::Editor::canCopy): Image documents are copyable
+        (WebCore::Editor::copy): If copying an image document, call appropriate pasteboard methods
+        * loader/ImageDocument.h:
+        (WebCore::ImageDocument::isImageDocument): Override to return true for image documents
+        * platform/Pasteboard.h: Add new writeImage function to pasteboard
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writeImage): Add writeImage implementation that takes Node and URL
+        * platform/qt/PasteboardQt.cpp:
+        (WebCore::Pasteboard::writeImage): Stub for Qt implementation of pasteboard
+
 2007-04-08  Oliver Hunt  <oliver@apple.com>
 
         rs=Adam.
index 5922eef..17c09e5 100644 (file)
@@ -236,6 +236,7 @@ public:
     // Other methods (not part of DOM)
     virtual bool isDocumentNode() const { return true; }
     virtual bool isHTMLDocument() const { return false; }
+    virtual bool isImageDocument() const { return false; }
 #if ENABLE(SVG)
     virtual bool isSVGDocument() const { return false; }
 #endif
index 28dd3e9..6441af6 100644 (file)
@@ -154,6 +154,13 @@ bool Editor::canCut() const
 
 bool Editor::canCopy() const
 {
+    if (m_frame->document() && m_frame->document()->isImageDocument()) {
+        Document* doc = m_frame->document();
+        if (doc->body() && doc->body()->firstChild() &&
+            doc->body()->firstChild()->hasTagName(imgTag))  
+            return true;
+    }
+        
     SelectionController* selectionController = m_frame->selectionController();
     return selectionController->isRange() && !selectionController->isInPasswordField();
 }
@@ -1414,7 +1421,16 @@ void Editor::copy()
         systemBeep();
         return;
     }
-    Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
+    if (m_frame->document() && m_frame->document()->isImageDocument()) {
+        Document* doc = m_frame->document();
+
+        if (doc->body() && doc->body()->firstChild() &&
+            doc->body()->firstChild()->hasTagName(imgTag))
+            Pasteboard::generalPasteboard()->writeImage(doc->body()->firstChild(), KURL(doc->URL()));
+        else
+            return;
+    } else
+        Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
     didWriteSelectionToPasteboard();
 }
 
index 544e578..7531205 100644 (file)
@@ -36,6 +36,8 @@ class ImageDocument : public HTMLDocument
 public:
     ImageDocument(DOMImplementation*, FrameView* = 0);
 
+    virtual bool isImageDocument() const { return true; }
+    
     virtual Tokenizer* createTokenizer();
 };
     
index c0e74d8..adea5ae 100644 (file)
@@ -60,6 +60,7 @@ class DocumentFragment;
 class Frame;
 class HitTestResult;
 class KURL;
+class Node;
 class Range;
 class String;
     
@@ -75,6 +76,7 @@ public:
     void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*);
     void writeURL(const KURL&, const String&, Frame* = 0);
     void writeImage(const HitTestResult&);
+    void writeImage(Node* imageNode, const KURL& url);
 #if PLATFORM(MAC)
     void writeFileWrapperAsRTFDAttachment(NSFileWrapper*);
 #endif
index a25d94e..dd6b0e3 100644 (file)
@@ -304,6 +304,32 @@ void Pasteboard::writeImage(const HitTestResult& result)
         writeFileWrapperAsRTFDAttachment(fileWrapperForImage(imageResource, URL));
 }
 
+void Pasteboard::writeImage(Node* imageNode, const KURL& url)
+{
+    NSURL *URL = url.getNSURL();
+    ASSERT(URL);
+
+    Frame* frame = imageNode->document()->frame();
+    NSString *title = imageNode->document()->title();
+    
+    NSArray *types = writableTypesForImage();
+    [m_pasteboard declareTypes:types owner:nil];
+    writeURL(m_pasteboard, types, URL, title, frame);
+
+    if (!imageNode->renderer() || !imageNode->renderer()->isImage())
+        return;
+    RenderImage* renderer = static_cast<RenderImage*>(imageNode->renderer());
+    CachedImage* imageResource = renderer->cachedImage();
+    if (!imageResource)
+        return;
+    String MIMEType = imageResource->response().mimeType();
+    ASSERT(MimeTypeRegistry::isSupportedImageResourceMIMEType(MIMEType));
+
+    [m_pasteboard setData:[imageResource->image()->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType];
+    
+    writeFileWrapperAsRTFDAttachment(fileWrapperForImage(imageResource, URL));
+}
+
 bool Pasteboard::canSmartReplace()
 {
     return [[m_pasteboard types] containsObject:WebSmartPastePboardType];
index ed03e14..7beb079 100644 (file)
@@ -79,6 +79,11 @@ void Pasteboard::writeImage(const HitTestResult&)
     notImplemented();
 }
 
+void Pasteboard::writeImage(Node* imageNode, const KURL& url)
+{
+    notImplemented();    
+}
+
 void Pasteboard::clear()
 {
     notImplemented();