Bug 670508 Needs null check at starting table selection handling r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 14 Jul 2011 12:55:27 +0900
changeset 72796 0141c3f5b18cde4497c9fdafd37a00964e8b6bb5
parent 72795 01a3d2bd77a209b494a8cd3e7744ba17f00f5798
child 72798 f70f630c3e801b6582497a2dfdfb0b3282574dd0
push id20772
push usereakhgari@mozilla.com
push dateThu, 14 Jul 2011 16:20:50 +0000
treeherdermozilla-central@89b5fccb0514 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs670508
milestone8.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 670508 Needs null check at starting table selection handling r=roc
layout/generic/nsFrame.cpp
layout/generic/test/Makefile.in
layout/generic/test/test_bug670508.html
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2301,21 +2301,30 @@ nsFrame::HandlePress(nsPresContext* aPre
   PRInt32 target;
   rv = GetDataForTableSelection(fs, shell, me, getter_AddRefs(parentContent),
                                 &contentOffset, &target);
   if (NS_SUCCEEDED(rv) && parentContent)
   {
     // In table selection mode, a nearest scrollable frame should capture the
     // mouse events.
     if (captureMouse) {
+      // NOTE: we must have set a content to capture already.  The content is
+      // selection root of this frame.  Therefore, when there is no scrollable
+      // frame, we don't need to reset the capturing content.
+      NS_ASSERTION(nsIPresShell::GetCapturingContent() != nsnull,
+                   "Someone must have captured mouse event already");
       nsIScrollableFrame* scrollableFrame =
         FindNearestScrollableFrameForSelection(this);
-      nsIFrame* frame = do_QueryFrame(scrollableFrame);
-      nsIPresShell::SetCapturingContent(frame->GetContent(),
-                                        CAPTURE_IGNOREALLOWED);
+      if (scrollableFrame) {
+        nsIFrame* frame = do_QueryFrame(scrollableFrame);
+        nsIContent* contentToCaptureForTableSelection =
+          GetContentToCaptureForSelection(frame->GetContent());
+        nsIPresShell::SetCapturingContent(contentToCaptureForTableSelection,
+                                          CAPTURE_IGNOREALLOWED);
+      }
     }
     fs->SetMouseDownState(PR_TRUE);
     return fs->HandleTableSelection(parentContent, contentOffset, target, me);
   }
 
   fs->SetDelayedCaretData(0);
 
   // Check if any part of this frame is selected, and if the
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -133,15 +133,16 @@ include $(topsrcdir)/config/rules.mk
   test_bug469613.xul \
   test_bug469774.xul \
   test_backspace_delete.xul \
   test_bug514732-2.xul \
   file_bug514732_window.xul \
   test_selection_scrolling.html \
   window_selection_scrolling.html \
   test_bug670058.html \
+  test_bug670508.html \
   $(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
 libs:: $(_CHROME_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/layout/generic/test/test_bug670508.html
@@ -0,0 +1,37 @@
+<!DOCTYPE>
+<html>
+<head>
+<title>test for bug 670508</title>
+<script type="text/javascript"
+  src="chrome://mochikit/content/MochiKit/packed.js"></script>
+<script type="text/javascript"
+  src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script type="text/javascript"
+  src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+<link rel="stylesheet" type="text/css"
+  href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+</head>
+<body>
+<table>
+  <tr>
+    <td id="td" contenteditable="true">
+      here is an editable table cell
+    </td>
+  </tr>
+</table>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+SimpleTest.waitForExplicitFinish();
+
+function doTest() {
+  synthesizeMouse(document.getElementById('td'), 5, 5, { ctrlKey: true });
+  ok(true, "not crashed");
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForFocus(doTest, window);
+
+</script>
+</pre>
+</body>
+</html>