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)
commit55ae5e013d178a63e0a36237419a1657976281d0
tree84dfd9922b921e30797e99e8404962d51db878e7
parentc6afb9cbde4adb7284d7c454a08b190d4db133be
Image alt text not included in plain-text version when copying
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