Bug 674770 - contenteditable breaks middle-click to open links when middlemouse.paste=true; r=roc
☠☠ backed out by e204fcdf5049 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 28 Jul 2011 17:42:38 -0400
changeset 75497 46dc0fb0b1cb4b5b90bbb655f4e0d6d820e0aae6
parent 75496 e8cb0687737a90e89871b38707153e8f98042a6d
child 75498 e79dbde50f8e5b61a6b2586ce02b6de19136cdb5
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersroc
bugs674770
milestone9.0a1
Bug 674770 - contenteditable breaks middle-click to open links when middlemouse.paste=true; r=roc
editor/libeditor/base/nsEditorEventListener.cpp
editor/libeditor/html/tests/Makefile.in
editor/libeditor/html/tests/file_bug674770.html
editor/libeditor/html/tests/test_bug674770.html
editor/libeditor/text/tests/test_bug597331.html
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -384,16 +384,26 @@ nsEditorEventListener::MouseClick(nsIDOM
     // We're done if 'preventdefault' is true (see for example bug 70698).
     return rv;
   }
 
   // If we got a mouse down inside the editing area, we should force the 
   // IME to commit before we change the cursor position
   mEditor->ForceCompositionEnd();
 
+  nsCOMPtr<nsIDOMEventTarget> target;
+  aMouseEvent->GetTarget(getter_AddRefs(target));
+  nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
+  NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
+
+  if (!mEditor->IsModifiableNode(node)) {
+    // We shouldn't handle the event for non-editable content.
+    return NS_OK;
+  }
+
   PRUint16 button = (PRUint16)-1;
   mouseEvent->GetButton(&button);
   // middle-mouse click (paste);
   if (button == 1)
   {
     if (Preferences::GetBool("middlemouse.paste", PR_FALSE))
     {
       // Set the selection to the point under the mouse cursor:
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -79,16 +79,18 @@ include $(topsrcdir)/config/rules.mk
 		test_bug607584.html \
 		test_bug611182.html \
 		test_bug612447.html \
 		test_bug620906.html \
 		test_bug622371.html \
 		test_bug629845.html \
 		test_bug640321.html \
 		test_bug668599.html \
+		test_bug674770.html \
+		file_bug674770.html \
 		test_bug674861.html \
 		test_bug676401.html \
 		test_CF_HTML_clipboard.html \
 		test_contenteditable_focus.html \
 		test_htmleditor_keyevent_handling.html \
 		test_select_all_without_body.html \
 		file_select_all_without_body.html \
 		test_root_element_replacement.html \
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/file_bug674770.html
@@ -0,0 +1,5 @@
+<!DOCTYPE>
+<script>
+  localStorage["clicked"] = "true";
+  close();
+</script>
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug674770.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=674770
+-->
+<head>
+  <title>Test for Bug 674770</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674770">Mozilla Bug 674770</a>
+<p id="display"></p>
+<div id="content">
+<a href="file_bug674770.html" id="link1">test</a>
+<div contenteditable>
+<a href="file_bug674770.html" id="link2">test</a>
+</div>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 674770 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+  SpecialPowers.setBoolPref("middlemouse.paste", true);
+  localStorage.removeItem("clicked");
+  window.linkWasClicked = false;
+
+  var link = document.querySelector("#link1");
+  addEventListener("storage", function(e) {
+    is(e.key, "clicked", "Correct event");
+    is(e.newValue, "true", "Correct value");
+    window.linkWasClicked = true;
+  }, false);
+  synthesizeMouseAtCenter(link, {button: 1});
+
+  hitEventLoop(function() {
+    ok(window.linkWasClicked, "The click operation worked successfully");
+    window.linkWasClicked = false;
+
+    link = document.querySelector("#link2");
+    localStorage.removeItem("clicked");
+    synthesizeMouseAtCenter(link, {button: 1});
+
+    hitEventLoop(function() {
+      ok(!window.linkWasClicked, "The click operation shouldn't work in the contenteditable area");
+
+      localStorage.removeItem("clicked");
+      SpecialPowers.clearUserPref("middlemouse.paste");
+      focus(); // reset focus
+      SimpleTest.finish();
+    }, 100);
+  }, 100);
+});
+
+function hitEventLoop(func, times) {
+  if (times > 0) {
+    setTimeout(hitEventLoop, 0, func, times - 1);
+  } else {
+    setTimeout(func, 0);
+  }
+}
+
+</script>
+</pre>
+</body>
+</html>
--- a/editor/libeditor/text/tests/test_bug597331.html
+++ b/editor/libeditor/text/tests/test_bug597331.html
@@ -19,17 +19,17 @@ line2
 line3
 </textarea>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 597331 **/
 SimpleTest.waitForExplicitFinish();
-addLoadEvent(function() {
+SimpleTest.waitForFocus(function() {
   var t = document.querySelector("textarea");
   t.focus();
   t.selectionStart = 4;
   t.selectionEnd = 4;
   SimpleTest.executeSoon(function() {
     var before = snapshotWindow(window, true);
     t.selectionStart = 5;
     t.selectionEnd = 5;