Image alt text not included in plain-text version when copying
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2013 01:33:10 +0000 (01:33 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2013 01:33:10 +0000 (01:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=11200

Reviewed by Ryosuke Niwa.

Source/WebCore:

Add a setting to enable copying image alt text to the clipboard and drag and drop pasteboard.
This setting is disabled by default, so each port can enable if they want to match IE10 and
Firefox's behavior.

Test: editing/pasteboard/copy-image-with-alt-text.html

* editing/Editor.cpp:
(WebCore::Editor::cut): Explicitly ask that the selection on the pasteboard as being for the clipboard.
(WebCore::Editor::copy): Explicitly ask that the selection on the pasteboard as being for the clipboard.
(WebCore::Editor::selectedText): Add a private version of selectedText() that can choose between having image alt text or not.
(WebCore::Editor::selectedTextForClipboard): Ask for image alt text if the setting is enabled.
* editing/Editor.h:
* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator): Add a bool to keep track of whether or not to emit image alt text.
(WebCore::TextIterator::handleReplacedElement): If there's alt text, point the iterator to it.
* editing/TextIterator.h:
(TextIterator):
* editing/mac/EditorMac.mm:
(WebCore::Editor::takeFindStringFromSelection): Use the same text as on the clipboard.
(WebCore::Editor::writeSelectionToPasteboard): Don't include image alt text since this is
used by Services.
(WebCore::Editor::stringSelectionForPasteboard): Don't include image alt text since this is
used by Services.
* page/DragController.cpp:
(WebCore::DragController::startDrag): Use image alt text (matches Firefox).
* page/Settings.in: Add a setting that disables image alt text by default.
* platform/Pasteboard.h:
* platform/blackberry/PasteboardBlackBerry.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::writeRange): Use clipboard text when writing ranges (used by d&d).
* platform/chromium/PasteboardChromium.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/efl/PasteboardEfl.cpp:
(WebCore::Pasteboard::writeSelection): Update function param.
* platform/gtk/ClipboardGtk.cpp:
(WebCore::ClipboardGtk::writeRange): Use clipboard text when writing ranges (used by d&d).
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::writeRange): Use clipboard text when writing ranges (used by d&d).
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::getStringSelection): Use ShouldSerializeSelectedTextForClipboard to determine whether the selected
text is for the clipboard or not.
(WebCore::Pasteboard::writeSelectionForTypes): Pass ShouldSerializeSelectedTextForClipboard through.
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/qt/ClipboardQt.cpp:
(WebCore::ClipboardQt::writeRange): Use clipboard text when writing ranges (used by d&d).
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/win/ClipboardWin.cpp:
(WebCore::ClipboardWin::writeRange): Use clipboard text when writing ranges (used by d&d).
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/wince/PasteboardWinCE.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* platform/wx/PasteboardWx.cpp:
(WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
* rendering/RenderImage.h:
(WebCore::RenderImage::altText): Add a getter for the alt text.

LayoutTests:

* editing/pasteboard/copy-image-with-alt-text-expected.txt: Added.
* editing/pasteboard/copy-image-with-alt-text.html: Added.

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

27 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/copy-image-with-alt-text-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-image-with-alt-text.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/TextIterator.h
Source/WebCore/editing/mac/EditorMac.mm
Source/WebCore/page/DragController.cpp
Source/WebCore/page/Settings.in
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp
Source/WebCore/platform/chromium/ClipboardChromium.cpp
Source/WebCore/platform/chromium/PasteboardChromium.cpp
Source/WebCore/platform/efl/PasteboardEfl.cpp
Source/WebCore/platform/gtk/ClipboardGtk.cpp
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/mac/ClipboardMac.mm
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/qt/ClipboardQt.cpp
Source/WebCore/platform/qt/PasteboardQt.cpp
Source/WebCore/platform/win/ClipboardWin.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/platform/wince/PasteboardWinCE.cpp
Source/WebCore/platform/wx/PasteboardWx.cpp
Source/WebCore/rendering/RenderImage.h

index 033fed6..1042af2 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-25  Tony Chang  <tony@chromium.org>
+
+        Image alt text not included in plain-text version when copying
+        https://bugs.webkit.org/show_bug.cgi?id=11200
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/pasteboard/copy-image-with-alt-text-expected.txt: Added.
+        * editing/pasteboard/copy-image-with-alt-text.html: Added.
+
 2013-03-25  James Robinson  <jamesr@chromium.org>
 
         Update chromium mac 10.6 and 10.8 baselines for r146826.
diff --git a/LayoutTests/editing/pasteboard/copy-image-with-alt-text-expected.txt b/LayoutTests/editing/pasteboard/copy-image-with-alt-text-expected.txt
new file mode 100644 (file)
index 0000000..b21ce19
--- /dev/null
@@ -0,0 +1,31 @@
+This tests that image alt text makes it to the clipboard. This test requires DRT or WTR. The first two dumps should not include alt text and the third and forth dumps should include alt text.
+
+Dump of markup 1:
+|   <shadow:root>
+|     <div>
+|       "Here is an emoticon [], some more text [], an empty alt tag [], no alt tag [] and two consecutive images []."
+|       "
+
+"
+
+Dump of markup 2:
+| <div>
+|   "Here is an emoticon [], some more text [], an empty alt tag [], no alt tag [] and two consecutive images []."
+| <div>
+|   <#selection-caret>
+|   <br>
+
+Dump of markup 3:
+|   <shadow:root>
+|     <div>
+|       "Here is an emoticon [:)], some more text [sample text], an empty alt tag [], no alt tag [] and two consecutive images [firstsecond]."
+|       "
+
+"
+
+Dump of markup 4:
+| <div>
+|   "Here is an emoticon [:)], some more text [sample text], an empty alt tag [], no alt tag [] and two consecutive images [firstsecond]."
+| <div>
+|   <#selection-caret>
+|   <br>
diff --git a/LayoutTests/editing/pasteboard/copy-image-with-alt-text.html b/LayoutTests/editing/pasteboard/copy-image-with-alt-text.html
new file mode 100644 (file)
index 0000000..517b81f
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../editing.js"></script>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+Markup.description("This tests that image alt text makes it to the clipboard. This test requires DRT or WTR."
+    + " The first two dumps should not include alt text and the third and forth dumps should include alt text.");
+Markup.noAutoDump();
+
+function runTest()
+{
+    var test = document.getElementById("test");
+    execSetSelectionCommand(test, 0, test.nextSibling, 0);
+    execCopyCommand();
+
+    document.getElementById("textarea-result").value = "";
+    document.getElementById("textarea-result").focus();
+    execPasteCommand();
+    Markup.dump("textarea-result");
+
+    document.getElementById("content-editable-result").innerHTML = "";
+    selection.setPosition(document.getElementById("content-editable-result"), 0);
+    execPasteAndMatchStyleCommand();
+    Markup.dump("content-editable-result");
+}
+
+window.onload = function()
+{
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    runTest();
+    if (window.internals)
+        internals.settings.setSelectionIncludesAltImageText(true);
+    runTest();
+
+    Markup.notifyDone();
+};
+</script>
+</head>
+<body>
+
+<div id="test">Here is an emoticon [<img src="resources/apple.gif" alt=":)">],
+some more text [<img alt="sample text">],
+an empty alt tag [<img alt="">],
+no alt tag [<img src="resources/apple.gif">]
+and two consecutive images [<img src="resources/apple.gif" alt="first"><img src="resources/apple.gif" alt="second">].</div>
+<textarea id="textarea-result" style="width: 100%; height: 5em;"></textarea>
+<div id="content-editable-result" contentEditable="true"></div>
+</body>
+</html>
index a1d045b..5c9b75d 100644 (file)
@@ -1,3 +1,71 @@
+2013-03-25  Tony Chang  <tony@chromium.org>
+
+        Image alt text not included in plain-text version when copying
+        https://bugs.webkit.org/show_bug.cgi?id=11200
+
+        Reviewed by Ryosuke Niwa.
+
+        Add a setting to enable copying image alt text to the clipboard and drag and drop pasteboard.
+        This setting is disabled by default, so each port can enable if they want to match IE10 and
+        Firefox's behavior.
+
+        Test: editing/pasteboard/copy-image-with-alt-text.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::cut): Explicitly ask that the selection on the pasteboard as being for the clipboard.
+        (WebCore::Editor::copy): Explicitly ask that the selection on the pasteboard as being for the clipboard.
+        (WebCore::Editor::selectedText): Add a private version of selectedText() that can choose between having image alt text or not.
+        (WebCore::Editor::selectedTextForClipboard): Ask for image alt text if the setting is enabled.
+        * editing/Editor.h:
+        * editing/TextIterator.cpp:
+        (WebCore::TextIterator::TextIterator): Add a bool to keep track of whether or not to emit image alt text.
+        (WebCore::TextIterator::handleReplacedElement): If there's alt text, point the iterator to it.
+        * editing/TextIterator.h:
+        (TextIterator):
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::takeFindStringFromSelection): Use the same text as on the clipboard.
+        (WebCore::Editor::writeSelectionToPasteboard): Don't include image alt text since this is
+        used by Services.
+        (WebCore::Editor::stringSelectionForPasteboard): Don't include image alt text since this is
+        used by Services.
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag): Use image alt text (matches Firefox).
+        * page/Settings.in: Add a setting that disables image alt text by default.
+        * platform/Pasteboard.h:
+        * platform/blackberry/PasteboardBlackBerry.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::ClipboardChromium::writeRange): Use clipboard text when writing ranges (used by d&d).
+        * platform/chromium/PasteboardChromium.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/efl/PasteboardEfl.cpp:
+        (WebCore::Pasteboard::writeSelection): Update function param.
+        * platform/gtk/ClipboardGtk.cpp:
+        (WebCore::ClipboardGtk::writeRange): Use clipboard text when writing ranges (used by d&d).
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/mac/ClipboardMac.mm:
+        (WebCore::ClipboardMac::writeRange): Use clipboard text when writing ranges (used by d&d).
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::getStringSelection): Use ShouldSerializeSelectedTextForClipboard to determine whether the selected
+        text is for the clipboard or not.
+        (WebCore::Pasteboard::writeSelectionForTypes): Pass ShouldSerializeSelectedTextForClipboard through.
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/qt/ClipboardQt.cpp:
+        (WebCore::ClipboardQt::writeRange): Use clipboard text when writing ranges (used by d&d).
+        * platform/qt/PasteboardQt.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/win/ClipboardWin.cpp:
+        (WebCore::ClipboardWin::writeRange): Use clipboard text when writing ranges (used by d&d).
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/wince/PasteboardWinCE.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * platform/wx/PasteboardWx.cpp:
+        (WebCore::Pasteboard::writeSelection): Add ShouldSerializeSelectedTextForClipboard parameter.
+        * rendering/RenderImage.h:
+        (WebCore::RenderImage::altText): Add a getter for the alt text.
+
 2013-03-25  Dean Jackson  <dino@apple.com>
 
         Remove autostart hashing code from WebCore
index 17c2561..d8bf81a 100644 (file)
@@ -1043,10 +1043,10 @@ void Editor::cut()
     if (shouldDeleteRange(selection.get())) {
         updateMarkersForWordsAffectedByEditing(true);
         if (enclosingTextFormControl(m_frame->selection()->start())) {
-            Pasteboard::generalPasteboard()->writePlainText(selectedText(),
+            Pasteboard::generalPasteboard()->writePlainText(selectedTextForClipboard(),
                 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
         } else
-            Pasteboard::generalPasteboard()->writeSelection(selection.get(), canSmartCopyOrDelete(), m_frame);
+            Pasteboard::generalPasteboard()->writeSelection(selection.get(), canSmartCopyOrDelete(), m_frame, IncludeImageAltTextForClipboard);
         didWriteSelectionToPasteboard();
         deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
     }
@@ -1063,14 +1063,14 @@ void Editor::copy()
 
     willWriteSelectionToPasteboard(selectedRange());
     if (enclosingTextFormControl(m_frame->selection()->start())) {
-        Pasteboard::generalPasteboard()->writePlainText(selectedText(),
+        Pasteboard::generalPasteboard()->writePlainText(selectedTextForClipboard(),
             canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
     } else {
         Document* document = m_frame->document();
         if (HTMLImageElement* imageElement = imageElementFromImageDocument(document))
             Pasteboard::generalPasteboard()->writeImage(imageElement, document->url(), document->title());
         else
-            Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame);
+            Pasteboard::generalPasteboard()->writeSelection(selectedRange().get(), canSmartCopyOrDelete(), m_frame, IncludeImageAltTextForClipboard);
     }
 
     didWriteSelectionToPasteboard();
@@ -2613,8 +2613,20 @@ void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection,
 
 String Editor::selectedText() const
 {
+    return selectedText(TextIteratorDefaultBehavior);
+}
+
+String Editor::selectedTextForClipboard() const
+{
+    if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageText())
+        return selectedText(TextIteratorEmitsImageAltText);
+    return selectedText();
+}
+
+String Editor::selectedText(TextIteratorBehavior behavior) const
+{
     // We remove '\0' characters because they are not visibly rendered to the user.
-    return plainText(m_frame->selection()->toNormalizedRange().get()).replace(0, "");
+    return plainText(m_frame->selection()->toNormalizedRange().get(), behavior).replace(0, "");
 }
 
 IntRect Editor::firstRectForRange(Range* range) const
index 5bd5a40..2429c3d 100644 (file)
@@ -38,6 +38,7 @@
 #include "FrameDestructionObserver.h"
 #include "FrameSelection.h"
 #include "TextChecking.h"
+#include "TextIterator.h"
 #include "VisibleSelection.h"
 #include "WritingDirection.h"
 
@@ -355,6 +356,7 @@ public:
     Node* findEventTargetFrom(const VisibleSelection& selection) const;
 
     String selectedText() const;
+    String selectedTextForClipboard() const;
     bool findString(const String&, FindOptions);
     // FIXME: Switch callers over to the FindOptions version and retire this one.
     bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
@@ -442,6 +444,8 @@ private:
     void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange);
     TextCheckingTypeMask resolveTextCheckingTypeMask(TextCheckingTypeMask);
 
+    String selectedText(TextIteratorBehavior) const;
+
     void selectComposition();
     enum SetCompositionMode { ConfirmComposition, CancelComposition };
     void setComposition(const String&, SetCompositionMode);
index 3e471e0..b815222 100644 (file)
@@ -38,6 +38,7 @@
 #include "InlineTextBox.h"
 #include "NodeTraversal.h"
 #include "Range.h"
+#include "RenderImage.h"
 #include "RenderTableCell.h"
 #include "RenderTableRow.h"
 #include "RenderTextControl.h"
@@ -266,6 +267,7 @@ TextIterator::TextIterator(const Range* r, TextIteratorBehavior behavior)
     , m_emitsObjectReplacementCharacters(behavior & TextIteratorEmitsObjectReplacementCharacters)
     , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
     , m_shouldStop(false)
+    , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
 {
     if (!r)
         return;
@@ -688,10 +690,18 @@ bool TextIterator::handleReplacedElement()
     m_positionOffsetBaseNode = m_node;
     m_positionStartOffset = 0;
     m_positionEndOffset = 1;
-
     m_textCharacters = 0;
-    m_textLength = 0;
 
+    if (m_emitsImageAltText && renderer->isImage() && renderer->isRenderImage()) {
+        m_text = toRenderImage(renderer)->altText();
+        if (!m_text.isEmpty()) {
+            m_textLength = m_text.length();
+            m_lastCharacter = m_text[m_textLength - 1];
+            return true;
+        }
+    }
+
+    m_textLength = 0;
     m_lastCharacter = 0;
 
     return true;
index 11992b3..b9e8310 100644 (file)
@@ -44,7 +44,8 @@ enum TextIteratorBehavior {
     TextIteratorIgnoresStyleVisibility = 1 << 3,
     TextIteratorEmitsObjectReplacementCharacters = 1 << 4,
     TextIteratorEmitsOriginalText = 1 << 5,
-    TextIteratorStopsOnFormControls = 1 << 6
+    TextIteratorStopsOnFormControls = 1 << 6,
+    TextIteratorEmitsImageAltText = 1 << 7,
 };
     
 // FIXME: Can't really answer this question correctly without knowing the white-space mode.
@@ -192,6 +193,8 @@ private:
     bool m_stopsOnFormControls;
     // Used when m_stopsOnFormControls is set to determine if the iterator should keep advancing.
     bool m_shouldStop;
+
+    bool m_emitsImageAltText;
 };
 
 // Iterates through the DOM range, returning all the text, and 0-length boundaries
index 7bfea06..fe4f40a 100644 (file)
@@ -262,13 +262,13 @@ void Editor::takeFindStringFromSelection()
     Vector<String> types;
     types.append(String(NSStringPboardType));
     platformStrategies()->pasteboardStrategy()->setTypes(types, NSFindPboard);
-    platformStrategies()->pasteboardStrategy()->setStringForType(m_frame->displayStringModifiedByEncoding(selectedText()), NSStringPboardType, NSFindPboard);
+    platformStrategies()->pasteboardStrategy()->setStringForType(m_frame->displayStringModifiedByEncoding(selectedTextForClipboard()), NSStringPboardType, NSFindPboard);
 }
 
 void Editor::writeSelectionToPasteboard(const String& pasteboardName, const Vector<String>& pasteboardTypes)
 {
     Pasteboard pasteboard(pasteboardName);
-    pasteboard.writeSelectionForTypes(pasteboardTypes, true, m_frame);
+    pasteboard.writeSelectionForTypes(pasteboardTypes, true, m_frame, DefaultSelectedTextType);
 }
     
 void Editor::readSelectionFromPasteboard(const String& pasteboardName)
@@ -282,7 +282,7 @@ void Editor::readSelectionFromPasteboard(const String& pasteboardName)
 
 String Editor::stringSelectionForPasteboard()
 {
-    return Pasteboard::getStringSelection(m_frame);
+    return Pasteboard::getStringSelection(m_frame, DefaultSelectedTextType);
 }
 
 PassRefPtr<SharedBuffer> Editor::dataSelectionForPasteboard(const String& pasteboardType)
index 0404594..d3619eb 100644 (file)
@@ -789,7 +789,7 @@ bool DragController::startDrag(Frame* src, const DragState& state, DragOperation
     if (state.m_dragType == DragSourceActionSelection) {
         if (!clipboard->hasData()) {
             if (enclosingTextFormControl(src->selection()->start()))
-                clipboard->writePlainText(src->editor()->selectedText());
+                clipboard->writePlainText(src->editor()->selectedTextForClipboard());
             else {
                 RefPtr<Range> selectionRange = src->selection()->toNormalizedRange();
                 ASSERT(selectionRange);
index 7784cae..89f1e1e 100644 (file)
@@ -203,3 +203,5 @@ defaultVideoPosterURL type=String
 
 smartInsertDeleteEnabled initial=defaultSmartInsertDeleteEnabled
 selectTrailingWhitespaceEnabled initial=defaultSelectTrailingWhitespaceEnabled
+
+selectionIncludesAltImageText initial=false
index 4022a61..08b6865 100644 (file)
@@ -63,7 +63,7 @@ extern const char* WebURLPboardType;
 extern const char* WebURLsWithTitlesPboardType;
 #endif
 
-    class ArchiveResource;
+class ArchiveResource;
 class Clipboard;
 class DocumentFragment;
 class Frame;
@@ -72,6 +72,8 @@ class KURL;
 class Node;
 class Range;
 class SharedBuffer;
+
+enum ShouldSerializeSelectedTextForClipboard { DefaultSelectedTextType, IncludeImageAltTextForClipboard };
     
 class Pasteboard {
     WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED;
@@ -83,14 +85,14 @@ public:
 
 #if PLATFORM(MAC)
     // This is required to support OS X services.
-    void writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame*);
+    void writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard);
     explicit Pasteboard(const String& pasteboardName);
-    static String getStringSelection(Frame*);
+    static String getStringSelection(Frame*, ShouldSerializeSelectedTextForClipboard);
     static PassRefPtr<SharedBuffer> getDataSelection(Frame*, const String& pasteboardType);
 #endif
     
     static Pasteboard* generalPasteboard();
-    void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*);
+    void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*, ShouldSerializeSelectedTextForClipboard = DefaultSelectedTextType);
     void writePlainText(const String&, SmartReplaceOption);
     void writeURL(const KURL&, const String&, Frame* = 0);
     void writeImage(Node*, const KURL&, const String& title);
index 608e24d..35d7d0d 100644 (file)
@@ -61,9 +61,9 @@ void Pasteboard::writeClipboard(Clipboard*)
     notImplemented();
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
-    WTF::String text = frame->editor()->selectedText();
+    WTF::String text = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
     WTF::String html = createMarkup(selectedRange, 0, AnnotateForInterchange);
     WTF::String url = frame->document()->url().string();
 
index d0905f2..6b981a0 100644 (file)
@@ -432,7 +432,7 @@ void ClipboardChromium::writeRange(Range* selectedRange, Frame* frame)
 
     m_dataObject->setHTMLAndBaseURL(createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs), frame->document()->url());
 
-    String str = frame->editor()->selectedText();
+    String str = frame->editor()->selectedTextForClipboard();
 #if OS(WINDOWS)
     replaceNewlinesWithWindowsStyleNewlines(str);
 #endif
index df1c6e5..07fa9a9 100644 (file)
@@ -85,11 +85,11 @@ void Pasteboard::setSelectionMode(bool selectionMode)
     m_selectionMode = selectionMode;
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     String html = createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
     KURL url = selectedRange->startContainer()->document()->url();
-    String plainText = frame->editor()->selectedText();
+    String plainText = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
 #if OS(WINDOWS)
     replaceNewlinesWithWindowsStyleNewlines(plainText);
 #endif
index 7a1ac45..d4430c6 100644 (file)
@@ -51,7 +51,7 @@ void Pasteboard::writePlainText(const String&, SmartReplaceOption)
     notImplemented();
 }
 
-void Pasteboard::writeSelection(Range*, bool, Frame*)
+void Pasteboard::writeSelection(Range*, bool, Frame*, ShouldSerializeSelectedTextForClipboard)
 {
     notImplemented();
 }
index f50460a..77a6505 100644 (file)
@@ -311,7 +311,7 @@ void ClipboardGtk::writeRange(Range* range, Frame* frame)
 {
     ASSERT(range);
 
-    m_dataObject->setText(frame->editor()->selectedText());
+    m_dataObject->setText(frame->editor()->selectedTextForClipboard());
     m_dataObject->setMarkup(createMarkup(range, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
 
     if (m_clipboard)
index cd62054..fb1443e 100644 (file)
@@ -56,7 +56,7 @@ Pasteboard::Pasteboard()
 {
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
     GtkClipboard* clipboard = helper->getCurrentClipboard(frame);
@@ -64,7 +64,7 @@ void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete,
     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     dataObject->clearAll();
 
-    dataObject->setText(frame->editor()->selectedText());
+    dataObject->setText(shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText());
     dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
     helper->writeClipboardContents(clipboard, canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
 }
index 36a4d8e..98da1b7 100644 (file)
@@ -377,7 +377,7 @@ void ClipboardMac::writeRange(Range* range, Frame* frame)
     ASSERT(range);
     ASSERT(frame);
     Pasteboard pasteboard(m_pasteboardName);
-    pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame);
+    pasteboard.writeSelection(range, frame->editor()->smartInsertDeleteEnabled() && frame->selection()->granularity() == WordGranularity, frame, IncludeImageAltTextForClipboard);
 }
 
 void ClipboardMac::writePlainText(const String& text)
index c20b7bb..e4952d7 100644 (file)
@@ -135,9 +135,9 @@ void Pasteboard::clear()
     platformStrategies()->pasteboardStrategy()->setTypes(Vector<String>(), m_pasteboardName);
 }
 
-String Pasteboard::getStringSelection(Frame* frame)
+String Pasteboard::getStringSelection(Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
-    String text = frame->editor()->selectedText();
+    String text = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
     text.replace(noBreakSpace, ' ');
     return text;
 }
@@ -175,7 +175,7 @@ PassRefPtr<SharedBuffer> Pasteboard::getDataSelection(Frame* frame, const String
     return 0;
 }
 
-void Pasteboard::writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     NSAttributedString* attributedString = nil;
     RetainPtr<WebHTMLConverter> converter(AdoptNS, [[WebHTMLConverter alloc] initWithDOMRange:kit(frame->editor()->selectedRange().get())]);
@@ -208,7 +208,7 @@ void Pasteboard::writeSelectionForTypes(const Vector<String>& pasteboardTypes, b
     
     // Put plain string on the pasteboard.
     if (types.contains(String(NSStringPboardType)))
-        platformStrategies()->pasteboardStrategy()->setStringForType(getStringSelection(frame), NSStringPboardType, m_pasteboardName);
+        platformStrategies()->pasteboardStrategy()->setStringForType(getStringSelection(frame, shouldSerializeSelectedTextForClipboard), NSStringPboardType, m_pasteboardName);
     
     if (types.contains(WebSmartPastePboardType))
         platformStrategies()->pasteboardStrategy()->setBufferForType(0, WebSmartPastePboardType, m_pasteboardName);
@@ -227,9 +227,9 @@ void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartRepl
         platformStrategies()->pasteboardStrategy()->setBufferForType(0, WebSmartPastePboardType, m_pasteboardName);
 }
     
-void Pasteboard::writeSelection(Range*, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range*, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
-    writeSelectionForTypes(Vector<String>(), canSmartCopyOrDelete, frame);
+    writeSelectionForTypes(Vector<String>(), canSmartCopyOrDelete, frame, shouldSerializeSelectedTextForClipboard);
 }
 
 static void writeURLForTypes(const Vector<String>& types, const String& pasteboardName, const KURL& url, const String& titleStr, Frame* frame)
index c5b8770..88cdcf6 100644 (file)
@@ -326,7 +326,7 @@ void ClipboardQt::writeRange(Range* range, Frame* frame)
 
     if (!m_writableData)
         m_writableData = new QMimeData;
-    QString text = frame->editor()->selectedText();
+    QString text = frame->editor()->selectedTextForClipboard();
     text.replace(QChar(0xa0), QLatin1Char(' '));
     m_writableData->setText(text);
     m_writableData->setHtml(createMarkup(range, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
index 08e97c7..550af7a 100644 (file)
@@ -59,10 +59,10 @@ Pasteboard* Pasteboard::generalPasteboard()
     return pasteboard;
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     QMimeData* md = new QMimeData;
-    QString text = frame->editor()->selectedText();
+    QString text = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
     text.replace(QChar(0xa0), QLatin1Char(' '));
     md->setText(text);
 
index 7ca3165..317b103 100644 (file)
@@ -747,7 +747,7 @@ void ClipboardWin::writeRange(Range* selectedRange, Frame* frame)
     if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
         ::GlobalFree(medium.hGlobal);
 
-    String str = frame->editor()->selectedText();
+    String str = frame->editor()->selectedTextForClipboard();
     replaceNewlinesWithWindowsStyleNewlines(str);
     replaceNBSPWithSpace(str);
     medium.hGlobal = createGlobalData(str);
index dde2e24..31ee75e 100644 (file)
@@ -113,7 +113,7 @@ void Pasteboard::clear()
     }
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     clear();
 
@@ -129,7 +129,7 @@ void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete,
     }
     
     // Put plain string on the pasteboard. CF_UNICODETEXT covers CF_TEXT as well
-    String str = frame->editor()->selectedText();
+    String str = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
     replaceNewlinesWithWindowsStyleNewlines(str);
     replaceNBSPWithSpace(str);
     if (::OpenClipboard(m_owner)) {
index 5ef3d2b..312ff15 100644 (file)
@@ -109,7 +109,7 @@ void Pasteboard::clear()
     }
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     clear();
 
@@ -124,7 +124,7 @@ void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete,
     }
 
     // Put plain string on the pasteboard. CF_UNICODETEXT covers CF_TEXT as well
-    String str = frame->selectedText();
+    String str = shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText();
     replaceNewlinesWithWindowsStyleNewlines(str);
     replaceNBSPWithSpace(str);
     if (::OpenClipboard(m_owner)) {
index d0cdc0a..43a347b 100644 (file)
@@ -50,13 +50,13 @@ Pasteboard* Pasteboard::generalPasteboard()
     return pasteboard;
 }
 
-void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
+void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame, ShouldSerializeSelectedTextForClipboard shouldSerializeSelectedTextForClipboard)
 {
     if (wxTheClipboard->Open()) {
 #if wxCHECK_VERSION(2, 9, 4)
         wxTheClipboard->SetData(new wxHTMLDataObject(createMarkup(selectedRange, 0, AnnotateForInterchange)));
 #endif
-        wxTheClipboard->SetData(new wxTextDataObject(frame->editor()->selectedText()));
+        wxTheClipboard->SetData(new wxTextDataObject(shouldSerializeSelectedTextForClipboard == IncludeImageAltTextForClipboard ? frame->editor()->selectedTextForClipboard() : frame->editor()->selectedText()));
         wxTheClipboard->Close();
     }
 }
index e1714f5..15c7906 100644 (file)
@@ -59,6 +59,8 @@ public:
 
     bool isGeneratedContent() const { return m_isGeneratedContent; }
 
+    String altText() const { return m_altText; }
+
 protected:
     virtual bool needsPreferredWidthsRecalculation() const;
     virtual RenderBox* embeddedContentBox() const;