Changeset 85064 in webkit


Ignore:
Timestamp:
Apr 27, 2011 11:15:56 AM (13 years ago)
Author:
Martin Robinson
Message:

2011-02-03 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] editing/pasteboard/copy-standalone-image.html fails
https://bugs.webkit.org/show_bug.cgi?id=53645

Unskip the test and add new expected results for it.

  • platform/gtk/Skipped: Unskip this test as it is now passing.
  • platform/gtk/editing/pasteboard/copy-standalone-image-expected.checksum:
  • platform/gtk/editing/pasteboard/copy-standalone-image-expected.png:
  • platform/gtk/editing/pasteboard/copy-standalone-image-expected.txt:

2011-02-03 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] editing/pasteboard/copy-standalone-image.html fails
https://bugs.webkit.org/show_bug.cgi?id=53645

When writing an image to the clipboard, also write the URL and title
into the markup and URL portion. This change also abstracts a helper
imageToMarkup into markup.{cpp/h} from several different locations
throughout the platform layer.

  • editing/markup.h: Added new function definition.
  • editing/markup.cpp: (WebCore::imageToMarkup): Add this function which turns an image URL and element into some markup representing that image, while preserving non-src attributes.
  • platform/chromium/ClipboardChromium.cpp: Move the imageToMarkup helper to markup.cpp.
  • platform/gtk/PasteboardGtk.cpp: (WebCore::getURLForImageNode): Add this helper which gets the appropriate image URL for a variety of image tag types. (WebCore::Pasteboard::writeImage): Write the image URL and title to the markup and URL portions of the clipboard. This will ensure that images paste properly back into WebKit.
  • platform/win/ClipboardWin.cpp: Remove the imageToMarkup helper and the one from markup.h
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r85063 r85064  
     12011-02-03  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] editing/pasteboard/copy-standalone-image.html fails
     6        https://bugs.webkit.org/show_bug.cgi?id=53645
     7
     8        Unskip the test and add new expected results for it.
     9
     10        * platform/gtk/Skipped: Unskip this test as it is now passing.
     11        * platform/gtk/editing/pasteboard/copy-standalone-image-expected.checksum:
     12        * platform/gtk/editing/pasteboard/copy-standalone-image-expected.png:
     13        * platform/gtk/editing/pasteboard/copy-standalone-image-expected.txt:
     14
    1152011-04-27  Kenneth Russell  <kbr@google.com>
    216
  • trunk/LayoutTests/platform/gtk/Skipped

    r85061 r85064  
    391391fast/forms/select-script-onchange.html
    392392fast/html/tab-order.html
    393 
    394 # Images do not seem to copy and paste properly
    395 # https://bugs.webkit.org/show_bug.cgi?id=53645
    396 editing/pasteboard/copy-standalone-image.html
    397393
    398394# The box isn't empty after a test run with this test.
  • trunk/LayoutTests/platform/gtk/editing/pasteboard/copy-standalone-image-expected.txt

    r77444 r85064  
    22EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
    33EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
     4EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
     5EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 1 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
     6EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
     7EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
    48layer at (0,0) size 800x600
    59  RenderView at (0,0) size 800x600
     
    2327                RenderImage {IMG} at (0,0) size 76x103
    2428        RenderText {#text} at (0,0) size 0x0
    25       RenderBlock {DIV} at (0,243) size 784x56 [border: (2px solid #FF0000)]
    26 caret: position 0 of child 7 {DIV} of body
     29      RenderBlock {DIV} at (0,243) size 784x131 [border: (2px solid #FF0000)]
     30        RenderImage {IMG} at (14,14) size 76x103
     31        RenderText {#text} at (0,0) size 0x0
     32caret: position 1 of child 0 {IMG} of child 7 {DIV} of body
  • trunk/Source/WebCore/ChangeLog

    r85058 r85064  
     12011-02-03  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] editing/pasteboard/copy-standalone-image.html fails
     6        https://bugs.webkit.org/show_bug.cgi?id=53645
     7
     8        When writing an image to the clipboard, also write the URL and title
     9        into the markup and URL portion. This change also abstracts a helper
     10        imageToMarkup into markup.{cpp/h} from several different locations
     11        throughout the platform layer.
     12
     13        * editing/markup.h: Added new function definition.
     14        * editing/markup.cpp:
     15        (WebCore::imageToMarkup): Add this function which turns an image URL
     16        and element into some markup representing that image, while preserving
     17        non-src attributes.
     18        * platform/chromium/ClipboardChromium.cpp: Move the imageToMarkup helper
     19        to markup.cpp.
     20        * platform/gtk/PasteboardGtk.cpp:
     21        (WebCore::getURLForImageNode): Add this helper which gets the appropriate
     22        image URL for a variety of image tag types.
     23        (WebCore::Pasteboard::writeImage): Write the image URL and title to the
     24        markup and URL portions of the clipboard. This will ensure that images
     25        paste properly back into WebKit.
     26        * platform/win/ClipboardWin.cpp: Remove the imageToMarkup helper and the
     27        one from markup.h
     28
    1292011-04-27  Steve Block  <steveblock@google.com>
    230
  • trunk/Source/WebCore/editing/markup.cpp

    r84311 r85064  
    11/*
    22 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2008, 2009 Google Inc.
     4 * Copyright (C) 2011 Igalia S.L.
    35 *
    46 * Redistribution and use in source and binary forms, with or without
     
    915917}
    916918
    917 }
     919String imageToMarkup(const KURL& url, Element* element)
     920{
     921    Vector<UChar> markup;
     922    append(markup, "<img src=\"");
     923    append(markup, url.string());
     924    append(markup, "\"");
     925
     926    NamedNodeMap* attrs = element->attributes();
     927    unsigned length = attrs->length();
     928    for (unsigned i = 0; i < length; ++i) {
     929        Attribute* attr = attrs->attributeItem(i);
     930        if (attr->localName() == "src")
     931            continue;
     932        append(markup, " ");
     933        append(markup, attr->localName());
     934        append(markup, "=\"");
     935        appendCharactersReplacingEntities(markup, attr->value().characters(), attr->value().length(), EntityMaskInAttributeValue);
     936        append(markup, "\"");
     937    }
     938
     939    append(markup, "/>");
     940    return String::adopt(markup);
     941}
     942
     943}
  • trunk/Source/WebCore/editing/markup.h

    r69994 r85064  
    3636    class Document;
    3737    class DocumentFragment;
     38    class Element;
    3839    class KURL;
    3940    class Node;
     
    5758
    5859    String urlToMarkup(const KURL&, const String& title);
     60    String imageToMarkup(const KURL&, Element*);
    5961}
    6062
  • trunk/Source/WebCore/platform/chromium/ClipboardChromium.cpp

    r81620 r85064  
    196196}
    197197
    198 static String imageToMarkup(const String& url, Element* element)
    199 {
    200     StringBuilder markup;
    201     markup.append("<img src=\"");
    202     markup.append(url);
    203     markup.append('"');
    204     // Copy over attributes.  If we are dragging an image, we expect things like
    205     // the id to be copied as well.
    206     NamedNodeMap* attrs = element->attributes();
    207     unsigned length = attrs->length();
    208     for (unsigned i = 0; i < length; ++i) {
    209         Attribute* attr = attrs->attributeItem(i);
    210         if (attr->localName() == "src")
    211             continue;
    212         markup.append(' ');
    213         markup.append(attr->localName());
    214         markup.append("=\"");
    215         String escapedAttr = attr->value();
    216         escapedAttr.replace("\"", "&quot;");
    217         markup.append(escapedAttr);
    218         markup.append('"');
    219     }
    220 
    221     markup.append("/>");
    222     return markup.toString();
    223 }
    224 
    225198static CachedImage* getCachedImage(Element* element)
    226199{
     
    282255        return;
    283256
    284     String fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL));
     257    KURL fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL));
    285258    if (fullURL.isEmpty())
    286259        return;
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r75009 r85064  
    2424#include "DocumentFragment.h"
    2525#include "Frame.h"
     26#include "GOwnPtrGtk.h"
     27#include "HTMLNames.h"
     28#include "HTMLParserIdioms.h"
     29#include "KURL.h"
    2630#include "NotImplemented.h"
    2731#include "PlatformString.h"
     
    2933#include "Image.h"
    3034#include "RenderImage.h"
    31 #include "KURL.h"
    3235#include "markup.h"
     36#include <gtk/gtk.h>
    3337#include <wtf/gobject/GRefPtr.h>
    3438#include <wtf/text/CString.h>
    3539
    36 #include <gtk/gtk.h>
     40#if ENABLE(SVG)
     41#include "SVGNames.h"
     42#include "XLinkNames.h"
     43#endif
    3744
    3845namespace WebCore {
     
    9299}
    93100
    94 void Pasteboard::writeImage(Node* node, const KURL&, const String&)
     101static KURL getURLForImageNode(Node* node)
    95102{
    96     GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
     103    // FIXME: Later this code should be shared with Chromium somehow. Chances are all platforms want it.
     104    AtomicString urlString;
     105    if (node->hasTagName(HTMLNames::imgTag) || node->hasTagName(HTMLNames::inputTag))
     106        urlString = static_cast<Element*>(node)->getAttribute(HTMLNames::srcAttr);
     107#if ENABLE(SVG)
     108    else if (node->hasTagName(SVGNames::imageTag))
     109        urlString = static_cast<Element*>(node)->getAttribute(XLinkNames::hrefAttr);
     110#endif
     111    else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) {
     112        Element* element = static_cast<Element*>(node);
     113        urlString = element->getAttribute(element->imageSourceAttributeName());
     114    }
     115    return urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
     116}
    97117
    98     ASSERT(node && node->renderer() && node->renderer()->isImage());
     118void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
     119{
     120    ASSERT(node);
     121    ASSERT(node->renderer());
    99122    RenderImage* renderer = toRenderImage(node->renderer());
    100123    CachedImage* cachedImage = renderer->cachedImage();
     
    104127    ASSERT(image);
    105128
     129    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
     130    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     131
     132    KURL url = getURLForImageNode(node);
     133    if (!url.isEmpty()) {
     134        dataObject->setURL(url, title);
     135
     136        // This image may be an SVG, embed, or object tag, so do not write the image
     137        // tag markup in those cases. Eventually we may want to support passing markup
     138        // for these tag types.
     139        if (node->hasTagName(HTMLNames::imgTag))
     140            dataObject->setMarkup(imageToMarkup(url, static_cast<Element*>(node)));
     141    }
     142
    106143    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());
    107     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    108144    dataObject->setImage(pixbuf.get());
     145
    109146    m_helper->writeClipboardContents(clipboard);
    110147}
  • trunk/Source/WebCore/platform/win/ClipboardWin.cpp

    r83067 r85064  
    632632}
    633633
    634 static String imageToMarkup(const String& url)
    635 {
    636     String markup("<img src=\"");
    637     markup.append(url);
    638     markup.append("\"/>");
    639     return markup;
    640 }
    641 
    642634static CachedImage* getCachedImage(Element* element)
    643635{
     
    699691        return;
    700692
    701     String fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL)).string();
     693    KURL fullURL = frame->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(imageURL));
    702694    if (fullURL.isEmpty())
    703695        return;
     
    707699    // Put img tag on the clipboard referencing the image
    708700    Vector<char> data;
    709     markupToCFHTML(imageToMarkup(fullURL), "", data);
     701    markupToCFHTML(imageToMarkup(fullURL, element), "", data);
    710702    medium.hGlobal = createGlobalData(data);
    711703    if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
Note: See TracChangeset for help on using the changeset viewer.