Reviewed by Anders.
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2007 17:51:52 +0000 (17:51 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2007 17:51:52 +0000 (17:51 +0000)
        Made image document copying more cross-platform.

        All layout tests pass.

        * editing/Editor.cpp:
        (WebCore::imageNodeFromImageDocument): Added.
        (WebCore::Editor::canCopy): Called imageNodeFromImageDocument.
        (WebCore::Editor::copy): Ditto.
        (WebCore::Editor::copyImage): Updated for changes to Pasteboard.
        * platform/Pasteboard.h: Made writeImage more general, which allowed
        getting rid of its second incarnation.
        * platform/gdk/TemporaryLinkStubs.cpp:
        * platform/mac/PasteboardMac.mm:
        (WebCore::Pasteboard::writeImage): Collapsed logic from the two
        writeImage methods into one.
        (Pasteboard::writeImage): Updated for Pasteboard changes.
        * platform/qt/PasteboardQt.cpp:
        (WebCore::Pasteboard::writeImage): Ditto.

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

WebCore/ChangeLog
WebCore/editing/Editor.cpp
WebCore/platform/Pasteboard.h
WebCore/platform/gdk/TemporaryLinkStubs.cpp
WebCore/platform/mac/PasteboardMac.mm
WebCore/platform/qt/PasteboardQt.cpp

index ed9cce0..72eb408 100644 (file)
@@ -1,3 +1,26 @@
+2007-04-11  Adam Roben  <aroben@apple.com>
+
+        Reviewed by Anders.
+
+        Made image document copying more cross-platform.
+
+        All layout tests pass.
+
+        * editing/Editor.cpp:
+        (WebCore::imageNodeFromImageDocument): Added.
+        (WebCore::Editor::canCopy): Called imageNodeFromImageDocument.
+        (WebCore::Editor::copy): Ditto.
+        (WebCore::Editor::copyImage): Updated for changes to Pasteboard.
+        * platform/Pasteboard.h: Made writeImage more general, which allowed
+        getting rid of its second incarnation.
+        * platform/gdk/TemporaryLinkStubs.cpp:
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writeImage): Collapsed logic from the two
+        writeImage methods into one.
+        (Pasteboard::writeImage): Updated for Pasteboard changes.
+        * platform/qt/PasteboardQt.cpp:
+        (WebCore::Pasteboard::writeImage): Ditto.
+
 2007-04-11  Darin Adler  <darin@apple.com>
 
         * css/CSSValueKeywords.in: Fix a comment.
index 6441af6..4cfa397 100644 (file)
@@ -152,14 +152,32 @@ bool Editor::canCut() const
     return canCopy() && canDelete();
 }
 
+static Node* imageNodeFromImageDocument(Document* document)
+{
+    if (!document)
+        return 0;
+    
+    if (!document->isImageDocument())
+        return 0;
+    
+    HTMLElement* body = document->body();
+    if (!body)
+        return 0;
+    
+    Node* node = body->firstChild();
+    if (!node)
+        return 0;
+    
+    if (!node->hasTagName(imgTag))
+        return 0;
+    
+    return node;
+}
+
 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;
-    }
+    if (imageNodeFromImageDocument(m_frame->document()))
+        return true;
         
     SelectionController* selectionController = m_frame->selectionController();
     return selectionController->isRange() && !selectionController->isInPasswordField();
@@ -1421,16 +1439,13 @@ void Editor::copy()
         systemBeep();
         return;
     }
-    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
+    
+    Document* document = m_frame->document();
+    if (Node* node = imageNodeFromImageDocument(document))
+        Pasteboard::generalPasteboard()->writeImage(node, document->URL(), document->title());
+    else
         Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
+    
     didWriteSelectionToPasteboard();
 }
 
@@ -1481,7 +1496,11 @@ void Editor::copyURL(const KURL& url, const String& title)
 
 void Editor::copyImage(const HitTestResult& result)
 {
-    Pasteboard::generalPasteboard()->writeImage(result);
+    KURL url = result.absoluteLinkURL();
+    if (url.isEmpty())
+        url = result.absoluteImageURL();
+
+    Pasteboard::generalPasteboard()->writeImage(result.innerNonSharedNode(), url, result.altDisplayString());
 }
 
 bool Editor::isContinuousSpellCheckingEnabled()
index adea5ae..a7a3ba6 100644 (file)
@@ -75,8 +75,7 @@ public:
     static Pasteboard* generalPasteboard();
     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);
+    void writeImage(Node*, const KURL&, const String& title);
 #if PLATFORM(MAC)
     void writeFileWrapperAsRTFDAttachment(NSFileWrapper*);
 #endif
index 2a6f54e..4089bec 100644 (file)
@@ -295,7 +295,7 @@ void Editor::markMisspellings(const Selection&) { notImplementedGdk(); }
 Pasteboard* Pasteboard::generalPasteboard() { notImplementedGdk(); return 0; }
 void Pasteboard::writeSelection(Range*, bool, Frame*) { notImplementedGdk(); }
 void Pasteboard::writeURL(const KURL&, const String&, Frame*) { notImplementedGdk(); }
-void Pasteboard::writeImage(const HitTestResult&) { notImplementedGdk(); }
+void Pasteboard::writeImage(Node*, const KURL&, const String&) { notImplementedGdk(); }
 void Pasteboard::clear() { notImplementedGdk(); }
 bool Pasteboard::canSmartReplace() { notImplementedGdk(); return false; }
 PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText) { notImplementedGdk(); return 0; }
index dd6b0e3..dc2b061 100644 (file)
@@ -269,65 +269,31 @@ void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper)
     [m_pasteboard setData:RTFDData forType:NSRTFDPboardType];
 }
 
-void Pasteboard::writeImage(const HitTestResult& result)
-{    
-    KURL coreURL = result.absoluteLinkURL();
-    if (coreURL.isEmpty())
-        coreURL = result.absoluteImageURL();
-    NSURL *URL = coreURL.getNSURL();
-    ASSERT(URL);
-
-    Node* node = result.innerNonSharedNode();
-    if (!node)
-        return;
-
-    NSString *title = result.altDisplayString().isNull() ? nil : (NSString*)(result.altDisplayString());
+void Pasteboard::writeImage(Node* node, const KURL& url, const String& title)
+{
+    ASSERT(node);
     Frame* frame = node->document()->frame();
 
+    NSURL *URL = url.getNSURL();
+    ASSERT(URL);
+
     NSArray* types = writableTypesForImage();
     [m_pasteboard declareTypes:types owner:nil];
-    writeURL(m_pasteboard, types, URL, title, frame);
-
-    Image* coreImage = result.image();
-    ASSERT(coreImage);
-    if (!coreImage)
-        return;
-    [m_pasteboard setData:[coreImage->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType];
+    writeURL(m_pasteboard, types, URL, nsStringNilIfEmpty(title), frame);
 
+    ASSERT(node->renderer() && node->renderer()->isImage());
     RenderImage* renderer = static_cast<RenderImage*>(node->renderer());
-    CachedResource* imageResource = static_cast<CachedResource*>(renderer->cachedImage());
-    ASSERT(imageResource);
-    String MIMEType = imageResource->response().mimeType();
-    ASSERT(MimeTypeRegistry::isSupportedImageResourceMIMEType(MIMEType));
-
-    if (imageResource)
-        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();
+    CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage());
+    ASSERT(cachedImage);
+    Image* image = cachedImage->image();
+    ASSERT(image);
     
-    NSArray *types = writableTypesForImage();
-    [m_pasteboard declareTypes:types owner:nil];
-    writeURL(m_pasteboard, types, URL, title, frame);
+    [m_pasteboard setData:[image->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType];
 
-    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();
+    String MIMEType = cachedImage->response().mimeType();
     ASSERT(MimeTypeRegistry::isSupportedImageResourceMIMEType(MIMEType));
 
-    [m_pasteboard setData:[imageResource->image()->getNSImage() TIFFRepresentation] forType:NSTIFFPboardType];
-    
-    writeFileWrapperAsRTFDAttachment(fileWrapperForImage(imageResource, URL));
+    writeFileWrapperAsRTFDAttachment(fileWrapperForImage(cachedImage, URL));
 }
 
 bool Pasteboard::canSmartReplace()
index 7beb079..98aaba1 100644 (file)
@@ -74,16 +74,11 @@ void Pasteboard::writeURL(const KURL&, const String&, Frame*)
     notImplemented();
 }
 
-void Pasteboard::writeImage(const HitTestResult&)
+void Pasteboard::writeImage(Node*, const KURL&, const String&)
 {
     notImplemented();
 }
 
-void Pasteboard::writeImage(Node* imageNode, const KURL& url)
-{
-    notImplemented();    
-}
-
 void Pasteboard::clear()
 {
     notImplemented();