Commit f2ff2775 authored by tony@chromium.org's avatar 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.

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: http://svn.webkit.org/repository/webkit/trunk@146835 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 146cfa02
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.
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>
<!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>
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
......@@ -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();
......@@ -2612,9 +2612,21 @@ 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
......
......@@ -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);
......
......@@ -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;
......
......@@ -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
......
......@@ -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)
......
......@@ -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);
......
......@@ -203,3 +203,5 @@ defaultVideoPosterURL type=String
smartInsertDeleteEnabled initial=defaultSmartInsertDeleteEnabled
selectTrailingWhitespaceEnabled initial=defaultSelectTrailingWhitespaceEnabled
selectionIncludesAltImageText initial=false
......@@ -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);
......
......@@ -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();
......
......@@ -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
......
......@@ -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
......
......@@ -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();
}
......
......@@ -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)
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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));
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)) {
......
......@@ -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)) {
......
......@@ -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();
}
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment