Title: [125247] trunk
Revision
125247
Author
[email protected]
Date
2012-08-09 21:45:23 -0700 (Thu, 09 Aug 2012)

Log Message

Mouse-select then Cut, results in preceding character being lost
https://bugs.webkit.org/show_bug.cgi?id=60830

Patch by Sukolsak Sakshuwong <[email protected]> on 2012-08-09
Reviewed by Ryosuke Niwa.

Source/WebCore:

This bug happened only in text fields and text areas, not in other
content-editable elements. That's because when we cut or copied text
in a text control, we called Pasteboard::writePlainText instead of
Pasteboard::writeSelection. writePlainText did not record the smart replace
information. Make writePlainText record the smart replace information.

Test: editing/pasteboard/smart-paste-in-text-control.html

* editing/Editor.cpp:
(WebCore::Editor::cut):
(WebCore::Editor::copy):
* inspector/InjectedScriptHost.cpp:
(WebCore::InjectedScriptHost::copyText):
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::copyText):
* platform/Pasteboard.h:
* platform/blackberry/PasteboardBlackBerry.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/chromium/PasteboardChromium.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/efl/PasteboardEfl.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::writePlainText):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writePlainText):
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/wince/PasteboardWinCE.cpp:
(WebCore::Pasteboard::writePlainText):
* platform/wx/ClipboardWx.cpp:
(WebCore::ClipboardWx::writePlainText):
* platform/wx/PasteboardWx.cpp:
(WebCore::Pasteboard::writePlainText):

LayoutTests:

* editing/pasteboard/smart-paste-in-text-control-expected.txt: Added.
* editing/pasteboard/smart-paste-in-text-control.html: Added.
* platform/chromium/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (125246 => 125247)


--- trunk/LayoutTests/ChangeLog	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/LayoutTests/ChangeLog	2012-08-10 04:45:23 UTC (rev 125247)
@@ -1,3 +1,14 @@
+2012-08-09  Sukolsak Sakshuwong  <[email protected]>
+
+        Mouse-select then Cut, results in preceding character being lost
+        https://bugs.webkit.org/show_bug.cgi?id=60830
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/pasteboard/smart-paste-in-text-control-expected.txt: Added.
+        * editing/pasteboard/smart-paste-in-text-control.html: Added.
+        * platform/chromium/TestExpectations:
+
 2012-08-09  Joone Hur  <[email protected]>
 
         [EFL] Unreviewed gardening

Added: trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control-expected.txt (0 => 125247)


--- trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control-expected.txt	2012-08-10 04:45:23 UTC (rev 125247)
@@ -0,0 +1,3 @@
+This tests smart pasting in a text control. To manually test, double click the middle word in the text area below. Then cut and paste. It should result in the original text. The space before the middle word should not be lost.
+
+PASS: Smart cutting and pasting result in the original text.

Added: trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control.html (0 => 125247)


--- trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control.html	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/smart-paste-in-text-control.html	2012-08-10 04:45:23 UTC (rev 125247)
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html> 
+<head>
+<style>
+#textarea {
+    font-family: Ahem;
+    font-size: 16px;
+    color: rgba(0, 0, 0, 0.2);
+    -webkit-font-smoothing: none;
+}
+</style>
+</head>
+<body>
+This tests smart pasting in a text control.
+To manually test, double click the middle word in the text area below. Then cut and paste.
+It should result in the original text. The space before the middle word should not be lost.
+<div>
+<textarea id="textarea">Hello world test</textarea>
+</div>
+
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+if (window.eventSender) {
+    function doubleClick(x, y) {
+        eventSender.mouseMoveTo(x, y);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+        
+    var target = document.getElementById("textarea");
+    var x = target.offsetLeft + 120;
+    var y = target.offsetTop + 10;
+    doubleClick(x, y);
+
+    document.execCommand("Cut");
+    document.execCommand("Paste");
+
+    if (target.value == "Hello world test")
+        document.write("PASS: Smart cutting and pasting result in the original text.");
+    else
+        document.write("FAIL: Smart cutting and pasting do not result in the original text.");
+} else {
+    document.write("This test can't run automatically in web browser without eventSender.");
+}
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (125246 => 125247)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-08-10 04:45:23 UTC (rev 125247)
@@ -152,6 +152,9 @@
 // CSS image-orientation is not yet enabled.
 BUGWK89052 SKIP : fast/css/image-orientation = PASS
 
+// Chromium does not support smart pasting in text controls yet.
+BUGWK60830 SKIP : editing/pasteboard/smart-paste-in-text-control.html = PASS
+
 // Chromium needs larger media files to test buffering this way.
 BUGWK88172 SKIP : http/tests/media/video-buffered.html = PASS
 

Modified: trunk/Source/WebCore/ChangeLog (125246 => 125247)


--- trunk/Source/WebCore/ChangeLog	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/ChangeLog	2012-08-10 04:45:23 UTC (rev 125247)
@@ -1,3 +1,49 @@
+2012-08-09  Sukolsak Sakshuwong  <[email protected]>
+
+        Mouse-select then Cut, results in preceding character being lost
+        https://bugs.webkit.org/show_bug.cgi?id=60830
+
+        Reviewed by Ryosuke Niwa.
+
+        This bug happened only in text fields and text areas, not in other
+        content-editable elements. That's because when we cut or copied text
+        in a text control, we called Pasteboard::writePlainText instead of
+        Pasteboard::writeSelection. writePlainText did not record the smart replace
+        information. Make writePlainText record the smart replace information.
+
+        Test: editing/pasteboard/smart-paste-in-text-control.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::cut):
+        (WebCore::Editor::copy):
+        * inspector/InjectedScriptHost.cpp:
+        (WebCore::InjectedScriptHost::copyText):
+        * inspector/InspectorFrontendHost.cpp:
+        (WebCore::InspectorFrontendHost::copyText):
+        * platform/Pasteboard.h:
+        * platform/blackberry/PasteboardBlackBerry.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/chromium/PasteboardChromium.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/efl/PasteboardEfl.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/mac/ClipboardMac.mm:
+        (WebCore::ClipboardMac::writePlainText):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/qt/PasteboardQt.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/wince/PasteboardWinCE.cpp:
+        (WebCore::Pasteboard::writePlainText):
+        * platform/wx/ClipboardWx.cpp:
+        (WebCore::ClipboardWx::writePlainText):
+        * platform/wx/PasteboardWx.cpp:
+        (WebCore::Pasteboard::writePlainText):
+
 2012-08-09  Kentaro Hara  <[email protected]>
 
         Unreviewed. Updated run-binding-tests results.

Modified: trunk/Source/WebCore/editing/Editor.cpp (125246 => 125247)


--- trunk/Source/WebCore/editing/Editor.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/editing/Editor.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -985,9 +985,10 @@
     RefPtr<Range> selection = selectedRange();
     if (shouldDeleteRange(selection.get())) {
         updateMarkersForWordsAffectedByEditing(true);
-        if (enclosingTextFormControl(m_frame->selection()->start()))
-            Pasteboard::generalPasteboard()->writePlainText(selectedText());
-        else
+        if (enclosingTextFormControl(m_frame->selection()->start())) {
+            Pasteboard::generalPasteboard()->writePlainText(selectedText(),
+                canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
+        } else
             Pasteboard::generalPasteboard()->writeSelection(selection.get(), canSmartCopyOrDelete(), m_frame);
         didWriteSelectionToPasteboard();
         deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
@@ -1003,9 +1004,10 @@
         return;
     }
 
-    if (enclosingTextFormControl(m_frame->selection()->start()))
-        Pasteboard::generalPasteboard()->writePlainText(selectedText());
-    else {
+    if (enclosingTextFormControl(m_frame->selection()->start())) {
+        Pasteboard::generalPasteboard()->writePlainText(selectedText(),
+            canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
+    } else {
         Document* document = m_frame->document();
         if (HTMLImageElement* imageElement = imageElementFromImageDocument(document))
             Pasteboard::generalPasteboard()->writeImage(imageElement, document->url(), document->title());

Modified: trunk/Source/WebCore/inspector/InjectedScriptHost.cpp (125246 => 125247)


--- trunk/Source/WebCore/inspector/InjectedScriptHost.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/inspector/InjectedScriptHost.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -120,7 +120,7 @@
 
 void InjectedScriptHost::copyText(const String& text)
 {
-    Pasteboard::generalPasteboard()->writePlainText(text);
+    Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
 }
 
 ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)

Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp (125246 => 125247)


--- trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -222,7 +222,7 @@
 
 void InspectorFrontendHost::copyText(const String& text)
 {
-    Pasteboard::generalPasteboard()->writePlainText(text);
+    Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
 }
 
 void InspectorFrontendHost::openInNewTab(const String& url)

Modified: trunk/Source/WebCore/platform/Pasteboard.h (125246 => 125247)


--- trunk/Source/WebCore/platform/Pasteboard.h	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2012-08-10 04:45:23 UTC (rev 125247)
@@ -76,6 +76,11 @@
 class Pasteboard {
     WTF_MAKE_NONCOPYABLE(Pasteboard); WTF_MAKE_FAST_ALLOCATED;
 public:
+    enum SmartReplaceOption {
+        CanSmartReplace,
+        CannotSmartReplace
+    };
+
 #if PLATFORM(MAC)
     // This is required to support OS X services.
     void writeSelectionForTypes(const Vector<String>& pasteboardTypes, bool canSmartCopyOrDelete, Frame*);
@@ -86,7 +91,7 @@
     
     static Pasteboard* generalPasteboard();
     void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*);
-    void writePlainText(const String&);
+    void writePlainText(const String&, SmartReplaceOption);
     void writeURL(const KURL&, const String&, Frame* = 0);
     void writeImage(Node*, const KURL&, const String& title);
     void writeClipboard(Clipboard*);

Modified: trunk/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -76,7 +76,7 @@
     BlackBerry::Platform::Clipboard::writeURL(url.string().utf8().data());
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption)
 {
     BlackBerry::Platform::Clipboard::writePlainText(text.utf8().data());
 }

Modified: trunk/Source/WebCore/platform/chromium/PasteboardChromium.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/chromium/PasteboardChromium.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/chromium/PasteboardChromium.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -98,8 +98,9 @@
     WebKit::Platform::current()->clipboard()->writeHTML(html, url, plainText, canSmartCopyOrDelete);
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption)
 {
+    // FIXME: add support for smart replace
 #if OS(WINDOWS)
     String plainText(text);
     replaceNewlinesWithWindowsStyleNewlines(plainText);

Modified: trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -46,7 +46,7 @@
     notImplemented();
 }
 
-void Pasteboard::writePlainText(const String&)
+void Pasteboard::writePlainText(const String&, SmartReplaceOption)
 {
     notImplemented();
 }

Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -68,14 +68,15 @@
     helper->writeClipboardContents(clipboard, canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
 {
     GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     dataObject->clearAll();
 
     dataObject->setText(text);
-    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard);
+    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard,
+        (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
 }
 
 void Pasteboard::writeURL(const KURL& url, const String& label, Frame* frame)

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (125246 => 125247)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2012-08-10 04:45:23 UTC (rev 125247)
@@ -384,7 +384,7 @@
 void ClipboardMac::writePlainText(const String& text)
 {
     Pasteboard pasteboard(m_pasteboardName);
-    pasteboard.writePlainText(text);
+    pasteboard.writePlainText(text, Pasteboard::CannotSmartReplace);
 }
 
 void ClipboardMac::writeURL(const KURL& url, const String& title, Frame* frame)

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (125246 => 125247)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2012-08-10 04:45:23 UTC (rev 125247)
@@ -204,12 +204,17 @@
         platformStrategies()->pasteboardStrategy()->setBufferForType(0, WebSmartPastePboardType, m_pasteboardName);
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
 {
     Vector<String> types;
     types.append(NSStringPboardType);
+    if (smartReplaceOption == CanSmartReplace)
+        types.append(WebSmartPastePboardType);
+
     platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName);
     platformStrategies()->pasteboardStrategy()->setStringForType(text, NSStringPboardType, m_pasteboardName);
+    if (smartReplaceOption == CanSmartReplace)
+        platformStrategies()->pasteboardStrategy()->setBufferForType(0, WebSmartPastePboardType, m_pasteboardName);
 }
     
 void Pasteboard::writeSelection(Range*, bool canSmartCopyOrDelete, Frame* frame)

Modified: trunk/Source/WebCore/platform/qt/PasteboardQt.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/qt/PasteboardQt.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/qt/PasteboardQt.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -127,7 +127,7 @@
     return 0;
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
 {
 #ifndef QT_NO_CLIPBOARD
     QMimeData* md = new QMimeData;
@@ -135,6 +135,8 @@
     qtext.replace(QChar(0xa0), QLatin1Char(' '));
     md->setText(qtext);
     QGuiApplication::clipboard()->setMimeData(md, m_selectionMode ? QClipboard::Selection : QClipboard::Clipboard);
+    if (smartReplaceOption == CanSmartReplace)
+        md->setData(QLatin1String("application/vnd.qtwebkit.smartpaste"), QByteArray());
 #endif
 }
 

Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -149,7 +149,7 @@
     }
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
 {
     clear();
 
@@ -162,6 +162,14 @@
             ::GlobalFree(cbData);
         ::CloseClipboard();
     }
+
+    // enable smart-replacing later on by putting dummy data on the pasteboard
+    if (smartReplaceOption == CanSmartReplace) {
+        if (::OpenClipboard(m_owner)) {
+            ::SetClipboardData(WebSmartPasteFormat, 0);
+            ::CloseClipboard();
+        }
+    }
 }
 
 void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame)

Modified: trunk/Source/WebCore/platform/wince/PasteboardWinCE.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/wince/PasteboardWinCE.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/wince/PasteboardWinCE.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -144,7 +144,7 @@
     }
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
 {
     clear();
 
@@ -157,6 +157,14 @@
             ::GlobalFree(cbData);
         ::CloseClipboard();
     }
+
+    // enable smart-replacing later on by putting dummy data on the pasteboard
+    if (smartReplaceOption == CanSmartReplace) {
+        if (::OpenClipboard(m_owner)) {
+            ::SetClipboardData(WebSmartPasteFormat, 0);
+            ::CloseClipboard();
+        }
+    }
 }
 
 void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame)

Modified: trunk/Source/WebCore/platform/wx/ClipboardWx.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/wx/ClipboardWx.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/wx/ClipboardWx.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -142,7 +142,7 @@
 
 void ClipboardWx::writePlainText(const WTF::String& text)
 {
-    Pasteboard::generalPasteboard()->writePlainText(text);
+    Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
 }
 
 }

Modified: trunk/Source/WebCore/platform/wx/PasteboardWx.cpp (125246 => 125247)


--- trunk/Source/WebCore/platform/wx/PasteboardWx.cpp	2012-08-10 04:42:48 UTC (rev 125246)
+++ trunk/Source/WebCore/platform/wx/PasteboardWx.cpp	2012-08-10 04:45:23 UTC (rev 125247)
@@ -61,7 +61,7 @@
     }
 }
 
-void Pasteboard::writePlainText(const String& text)
+void Pasteboard::writePlainText(const String& text, SmartReplaceOption)
 {
     if (wxTheClipboard->Open()) {
         wxTheClipboard->SetData( new wxTextDataObject(text) );
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to