Bug 741734 - Fire the paste event when pasting without formatting; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 03 Apr 2012 13:41:04 -0400
changeset 94243 a154bf84abdb11780e118491c5c3e1aff5a2867f
parent 94242 ca51e71184bb7e76c9837138f944220af14f2bad
child 94244 1ef36ed1ae2773a4852bdbaf1cdef1cf7b3fc57c
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs741734
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 741734 - Fire the paste event when pasting without formatting; r=roc
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/tests/test_bug410986.html
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -1619,16 +1619,19 @@ NS_IMETHODIMP nsHTMLEditor::PasteTransfe
                                 nsnull, 0, true);
 }
 
 // 
 // HTML PasteNoFormatting. Ignore any HTML styles and formating in paste source
 //
 NS_IMETHODIMP nsHTMLEditor::PasteNoFormatting(PRInt32 aSelectionType)
 {
+  if (!FireClipboardEvent(NS_PASTE))
+    return NS_OK;
+
   ForceCompositionEnd();
 
   // Get Clipboard Service
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the nsITransferable interface for getting the data from the clipboard.
--- a/editor/libeditor/html/tests/test_bug410986.html
+++ b/editor/libeditor/html/tests/test_bug410986.html
@@ -16,46 +16,53 @@ https://bugzilla.mozilla.org/show_bug.cg
   <div id="contents"><span style="color: green;">green text</span></div>
   <div id="editor" contenteditable="true"></div>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 410986 **/
 
+var gPasteEvents = 0;
+document.getElementById("editor").addEventListener("paste", function() {
+  ++gPasteEvents;
+}, false);
+
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(function() {
   getSelection().selectAllChildren(document.getElementById("contents"));
   SimpleTest.waitForClipboard("green text",
     function() {
       synthesizeKey("C", {accelKey: true});
     },
     function() {
       var ed = document.getElementById("editor");
       ed.focus();
       if (navigator.platform.indexOf("Mac") >= 0) {
         synthesizeKey("V", {accelKey: true, shiftKey: true, altKey: true});
       } else {
         synthesizeKey("V", {accelKey: true, shiftKey: true});
       }
       is(ed.innerHTML, "green text", "Content should be pasted in plaintext format");
+      is(gPasteEvents, 1, "One paste event must be fired");
 
       ed.innerHTML = "";
       ed.blur();
       getSelection().selectAllChildren(document.getElementById("contents"));
       SimpleTest.waitForClipboard("green text",
         function() {
           synthesizeKey("C", {accelKey: true});
         },
         function() {
           var ed = document.getElementById("editor");
           ed.focus();
           synthesizeKey("V", {accelKey: true});
           isnot(ed.innerHTML.indexOf("<span style=\"color: green;\">green text</span>"), -1,
                 "Content should be pasted in HTML format");
+          is(gPasteEvents, 2, "Two paste events must be fired");
 
           SimpleTest.finish();
         },
         function() {
           ok(false, "Failed to copy the second item to the clipboard");
           SimpleTest.finish();
         }
       );