Bug 719503 - selection.deleteFromDocument() throws for collapsed selection; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Wed, 22 Feb 2012 10:38:25 -0500
changeset 87513 0e50adaab9d7da719eb46b1b075443b646a29dfe
parent 87512 7eb9acce263ab76343743fc56301611ca72b3a2b
child 87514 c5d42c74c357b0626e1ac22a1c4cc7b4e1029c01
push id6381
push userdgottwald@mozilla.com
push dateThu, 23 Feb 2012 13:26:16 +0000
treeherdermozilla-inbound@e65188cac8b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs719503
milestone13.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 719503 - selection.deleteFromDocument() throws for collapsed selection; r=ehsan
layout/generic/nsSelection.cpp
layout/generic/test/Makefile.in
layout/generic/test/test_bug719503.html
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -3291,38 +3291,26 @@ nsFrameSelection::SetAncestorLimiter(nsI
 
 
 
 nsresult
 nsFrameSelection::DeleteFromDocument()
 {
   nsresult res;
 
-  // If we're already collapsed, then set ourselves to include the
-  // last item BEFORE the current range, rather than the range itself,
-  // before we do the delete.
+  // If we're already collapsed, then we do nothing (bug 719503).
   bool isCollapsed;
   PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
   if (!mDomSelections[index])
     return NS_ERROR_NULL_POINTER;
 
   mDomSelections[index]->GetIsCollapsed( &isCollapsed);
   if (isCollapsed)
   {
-    // If the offset is positive, then it's easy:
-    if (mDomSelections[index]->GetFocusOffset() > 0)
-    {
-      mDomSelections[index]->Extend(mDomSelections[index]->GetFocusNode(), mDomSelections[index]->GetFocusOffset() - 1);
-    }
-    else
-    {
-      // Otherwise it's harder, have to find the previous node
-      printf("Sorry, don't know how to delete across frame boundaries yet\n");
-      return NS_ERROR_NOT_IMPLEMENTED;
-    }
+    return NS_OK;
   }
 
   // Get an iterator
   nsSelectionIterator iter(mDomSelections[index]);
   res = iter.First();
   if (NS_FAILED(res))
     return res;
 
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -122,16 +122,17 @@ include $(topsrcdir)/config/rules.mk
   test_bug589621.html \
   test_bug589623.html \
   test_bug633762.html \
   bug633762_iframe.html \
   $(srcdir)/../../reftests/backgrounds/blue-32x32.png \
   $(srcdir)/../../reftests/backgrounds/fuchsia-32x32.png \
   test_selection_splitText-normalize.html \
   test_bug524925.html \
+  test_bug719503.html \
   $(NULL)
 
 _CHROME_FILES = \
   test_bug632379.xul \
   test_bug508115.xul \
   test_bug469613.xul \
   test_bug469774.xul \
   test_backspace_delete.xul \
new file mode 100644
--- /dev/null
+++ b/layout/generic/test/test_bug719503.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=719503
+-->
+<title>Test for Bug 719503</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719503">Mozilla Bug 719503</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script>
+try {
+  getSelection().collapse(document.head, 0);
+  getSelection().deleteFromDocument();
+} catch(e) {
+  ok(false, "Exception thrown");
+}
+ok(true, "Passed, no exception");
+</script>