Bug 1317322 - Activate `paste` in menus when within <textarea> controls, r=ehsan
☠☠ backed out by 486075111a45 ☠ ☠
authorMichael Layzell <michael@thelayzells.com>
Tue, 03 Jan 2017 13:06:58 -0500
changeset 329687 79d6e9229fda9ed2076cdb1b675b2662759ee0be
parent 329686 26ed78caca3d0ffa819c31f066cfc5d03dde7a95
child 329688 cbce75114440f0a37d65ce3fb4725e288fc24c08
push id85781
push usermichael@thelayzells.com
push dateTue, 17 Jan 2017 20:06:47 +0000
treeherdermozilla-inbound@79d6e9229fda [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1317322
milestone53.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 1317322 - Activate `paste` in menus when within <textarea> controls, r=ehsan MozReview-Commit-ID: 7YD8qtsC3u6
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/TextEditorDataTransfer.cpp
editor/libeditor/tests/chrome.ini
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_pasteImgTextarea.html
editor/libeditor/tests/test_pasteImgTextarea.xul
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -1533,16 +1533,23 @@ static const char* textHtmlEditorFlavors
 
 NS_IMETHODIMP
 HTMLEditor::CanPaste(int32_t aSelectionType,
                      bool* aCanPaste)
 {
   NS_ENSURE_ARG_POINTER(aCanPaste);
   *aCanPaste = false;
 
+  // Always enable the paste command when inside of a HTML or XHTML document.
+  nsCOMPtr<nsIDocument> doc = GetDocument();
+  if (doc && doc->IsHTMLOrXHTML()) {
+    *aCanPaste = true;
+    return NS_OK;
+  }
+
   // can't paste if readonly
   if (!IsModifiable()) {
     return NS_OK;
   }
 
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -377,16 +377,23 @@ TextEditor::PasteTransferable(nsITransfe
 
 NS_IMETHODIMP
 TextEditor::CanPaste(int32_t aSelectionType,
                      bool* aCanPaste)
 {
   NS_ENSURE_ARG_POINTER(aCanPaste);
   *aCanPaste = false;
 
+  // Always enable the paste command when inside of a HTML or XHTML document.
+  nsCOMPtr<nsIDocument> doc = GetDocument();
+  if (doc && doc->IsHTMLOrXHTML()) {
+    *aCanPaste = true;
+    return NS_OK;
+  }
+
   // can't paste if readonly
   if (!IsModifiable()) {
     return NS_OK;
   }
 
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/tests/chrome.ini
+++ b/editor/libeditor/tests/chrome.ini
@@ -6,8 +6,9 @@ support-files = green.png
 [test_bug599983.xul]
 [test_bug607584.xul]
 [test_bug616590.xul]
 [test_bug780908.xul]
 [test_contenteditable_text_input_handling.html]
 [test_htmleditor_keyevent_handling.html]
 [test_texteditor_keyevent_handling.html]
 skip-if = (debug && os=='win') || (os == 'linux') # Bug 1116205, leaks on windows debug, fails delete key on linux
+[test_pasteImgTextarea.xul]
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -234,8 +234,9 @@ skip-if = os == 'android'
 [test_root_element_replacement.html]
 [test_select_all_without_body.html]
 [test_spellcheck_pref.html]
 skip-if = toolkit == 'android'
 [test_backspace_vs.html]
 [test_css_chrome_load_access.html]
 skip-if = toolkit == 'android' # chrome urls not available due to packaging
 [test_selection_move_commands.html]
+[test_pasteImgTextarea.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_pasteImgTextarea.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="/tests/SimpleTest/SpawnTask.js"></script>
+<img id="i" src="green.png">
+<textarea id="t"></textarea>
+
+<script>
+let loaded = new Promise(resolve => addLoadEvent(resolve));
+    add_task(function*() {
+        yield loaded;
+        SpecialPowers.setCommandNode(window, document.getElementById("i"));
+        SpecialPowers.doCommand(window, "cmd_copyImageContents");
+        let input = document.getElementById("t");
+        input.focus();
+        var controller =
+          SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste");
+        is(controller.isCommandEnabled("cmd_paste"), true,
+           "paste should be enabled in html textareas when an image is on the clipboard");
+    });
+</script>
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_pasteImgTextarea.xul
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
+<window xmlns:html="http://www.w3.org/1999/xhtml"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+
+  <body xmlns="http://www.w3.org/1999/xhtml">
+    <html:img id="i" src="green.png" />
+    <html:textarea id="t"></html:textarea>
+  </body>
+  <script type="text/javascript"><![CDATA[
+    let loaded = new Promise(resolve => addLoadEvent(resolve));
+    add_task(function*() {
+        yield loaded;
+        SpecialPowers.setCommandNode(window, document.getElementById("i"));
+        SpecialPowers.doCommand(window, "cmd_copyImageContents");
+        let input = document.getElementById("t");
+        input.focus();
+        var controller =
+          SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste");
+        is(controller.isCommandEnabled("cmd_paste"), false,
+           "paste should not be enabled in xul textareas when an image is on the clipboard");
+    });
+  ]]></script>
+</window>