Bug 624127, clear mousedown selection state in frame where mouse was pressed down,r=smaug,a=jst
authorNeil Deakin <enndeakin@gmail.com>
Thu, 03 Feb 2011 12:08:30 -0500
changeset 61847 f1f0bf6fedbbe884eecc2699799c357628286f7f
parent 61846 ba7090bbf9fe42387f589659f75686517e9f4838
child 61848 d62ae33c94d7ce71f2bb126a4eaf0a5b7a1dae66
push idunknown
push userunknown
push dateunknown
reviewerssmaug, jst
bugs624127
milestone2.0b12pre
Bug 624127, clear mousedown selection state in frame where mouse was pressed down,r=smaug,a=jst
content/events/test/Makefile.in
content/events/test/test_bug624127.html
layout/generic/nsFrame.cpp
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -92,16 +92,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug547996-2.xhtml \
 		test_bug556493.html \
 		test_bug574663.html \
 		test_bug586961.xul \
 		test_clickevent_on_input.html \
 		test_bug593959.html \
 		test_bug591815.html \
 		test_bug605242.html \
+		test_bug624127.html \
 		$(NULL)
 
 #bug 585630
 ifneq (mobile,$(MOZ_BUILD_APP))
 _TEST_FILES += \
 		test_dragstart.html \
 		$(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/content/events/test/test_bug624127.html
@@ -0,0 +1,36 @@
+<html>
+<head>
+  <title>Test for Bug 624127</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  synthesizeMouse($("text"), 2, 2, { type: "mousedown" });
+  synthesizeMouse(frames[0].document.body, 2, 2, { type: "mouseup" }, frames[0]);
+  synthesizeMouse($("text2"), 50, 8, { type: "mousemove" });
+
+  is(window.getSelection().toString(), "", "no selection made");
+  SimpleTest.finish();
+}
+
+</script>
+</pre>
+
+<p id="text">Normal text</p>
+<iframe src="data:text/plain,text in iframe"></iframe>
+<p id="text2">Normal text</p>
+
+</body>
+</html>
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2539,16 +2539,18 @@ HandleFrameSelection(nsFrameSelection*  
 }
 
 NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext,
                                      nsGUIEvent*    aEvent,
                                      nsEventStatus* aEventStatus)
 {
   nsIFrame* activeFrame = GetActiveSelectionFrame(aPresContext, this);
 
+  nsCOMPtr<nsIContent> captureContent = nsIPresShell::GetCapturingContent();
+
   // We can unconditionally stop capturing because
   // we should never be capturing when the mouse button is up
   nsIPresShell::SetCapturingContent(nsnull, 0);
 
   PRBool selectionOff =
     (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF);
 
   nsRefPtr<nsFrameSelection> frameselection;
@@ -2580,21 +2582,36 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsP
                                  &targetForTableSel);
       }
     }
   }
 
   // We might be capturing in some other document and the event just happened to
   // trickle down here. Make sure that document's frame selection is notified.
   // Note, this may cause the current nsFrame object to be deleted, bug 336592.
+  nsRefPtr<nsFrameSelection> frameSelection;
   if (activeFrame != this &&
       static_cast<nsFrame*>(activeFrame)->DisplaySelection(activeFrame->PresContext())
         != nsISelectionController::SELECTION_OFF) {
-    nsRefPtr<nsFrameSelection> frameSelection =
-      activeFrame->GetFrameSelection();
+      frameSelection = activeFrame->GetFrameSelection();
+  }
+
+  // Also check the selection of the capturing content which might be in a
+  // different document.
+  if (!frameSelection && captureContent) {
+    nsIDocument* doc = captureContent->GetCurrentDoc();
+    if (doc) {
+      nsIPresShell* capturingShell = doc->GetShell();
+      if (capturingShell && capturingShell != PresContext()->GetPresShell()) {
+        frameSelection = capturingShell->FrameSelection();
+      }
+    }
+  }
+
+  if (frameSelection) {
     frameSelection->SetMouseDownState(PR_FALSE);
     frameSelection->StopAutoScrollTimer();
   }
 
   // Do not call any methods of the current object after this point!!!
   // The object is perhaps dead!
 
   return selectionOff