Closed Bug 719503 Opened 12 years ago Closed 12 years ago

selection.deleteFromDocument() throws for collapsed selection

Categories

(Core :: DOM: Selection, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla13

People

(Reporter: ayg, Assigned: ayg)

Details

Attachments

(1 file, 1 obsolete file)

Test-case:

data:text/html,<!doctype html>
<body>
<script>
try {
getSelection().collapse(document.head, 0);
getSelection().deleteFromDocument();
} catch(e) {
document.body.textContent = e;
throw e;
}
document.body.textContent = "success";
</script>

In IE9, Chrome 17 dev, and Opera Next 12.00 alpha, this outputs "success".  In Firefox 12.0a1 (2012-01-17), it outputs

"""
[Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsISelection.deleteFromDocument]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: data:text/html,<!doctype%20html><body><script>try%20{getSelection().collapse(document.head,%200);getSelection().deleteFromDocument();}%20catch(e)%20{document.body.textContent%20=%20e;throw%20e;}document.body.textContent%20=%20"success";</script> :: <TOP_LEVEL> :: line 1" data: no]
"""

This causes test failures in <http://dvcs.w3.org/hg/editing/raw-file/tip/selecttest/deleteFromDocument.html>.  The specification requires the non-Gecko behavior, which is IMO less surprising:

"""
The deleteFromDocument() method must do nothing if the context object's range is null, and otherwise must invoke the deleteContents() method on the context object's range.
"""
http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#dom-selection-deletefromdocument

deleteContents() on a collapsed selection is therefore a no-op.
Attached patch Patch v1 (obsolete) — Splinter Review
Since I didn't have enough time left today to start on transitions/animations testing, and none of the transforms stuff left on my plate looks particularly easy, I figured I'd write a quick Selection patch to round out my day.  Turns out the behavior was actually odder than I thought: it only throws in some cases, and in other cases it does something that looks quite surprising.
Assignee: nobody → ayg
Status: NEW → ASSIGNED
Attachment #597167 - Flags: review?
Attachment #597167 - Flags: review? → review?(bzbarsky)
Whiteboard: [autoland]
Whiteboard: [autoland] → [autoland-in-queue]
Autoland Patchset:
	Patches: 597167
	Branch: mozilla-central => try
	Destination: http://hg.mozilla.org/try/pushloghtml?changeset=4f40044ba6c3
Try run started, revision 4f40044ba6c3. To cancel or monitor the job, see: https://tbpl.mozilla.org/?tree=Try&rev=4f40044ba6c3
Try run for 4f40044ba6c3 is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=4f40044ba6c3
Results (out of 211 total builds):
    exception: 1
    success: 179
    warnings: 16
    failure: 15
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/autolanduser@mozilla.com-4f40044ba6c3
Whiteboard: [autoland-in-queue]
Comment on attachment 597167 [details] [diff] [review]
Patch v1

Goig to punt this to Ehsan, but it looks like that code was trying to deal with deleting the previous char as needed... is that not necessary?
Attachment #597167 - Flags: review?(bzbarsky) → review?(ehsan)
It's not what any other browser does.  If the idea was to make it work like execCommand("delete"), it looks far too crude to be useful.  To get an effect anything like hitting the backspace key, you need way way more code than that.
OK.  I assume you did look at the blame for this code and there was nothing useful there, right?
It seemed to go back to the original hg commit.  I didn't look in CVS.  I just did that and it seems to go back to CVS commit 3.1 (?):

"""
3.1 <cmanske@netscape.com> 2000-03-21 15:57
Cleaning up selection: changed 'RangeList' to 'Selection', thus changing implementation class of nsIDOMSelection and nsIFrameSelection to nsSelection. File nsRangeList.cpp replaced with new nsSelection.cpp
"""
http://bonsai.mozilla.org/cvsview2.cgi?diff_mode=context&whitespace_mode=show&root=/cvsroot&subdir=mozilla/layout/generic&command=DIFF_FRAMESET&file=nsSelection.cpp&rev2=3.1&rev1=1.6

That's as far back as I was able to find.
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla%2Flayout%2Fbase%2Fsrc%2FAttic%2FnsRangeList.cpp&rev=&cvsroot=%2Fcvsroot is a starting point for going further back.

That gets us to:

  1.31 <akkana@netscape.com> 1999-01-29 17:02
  Add IsCollapsed; add collapsed case to DeleteFromDocument

Not helpful, indeed.  I don't think it's worth getting in touch with Akkana to find out what she meant here...  OK.
Comment on attachment 597167 [details] [diff] [review]
Patch v1

Review of attachment 597167 [details] [diff] [review]:
-----------------------------------------------------------------

::: layout/generic/test/test_bug719503.html
@@ +11,5 @@
> +<pre id="test">
> +<script>
> +getSelection().collapse(document.head, 0);
> +getSelection().deleteFromDocument();
> +ok(true, "Passed, no exception");

This is not the right way of testing this.  This way, if something throws, ok() will never get executed and the test will pass silently.  Please add a try/catch block around those two calls, and ok(false) in the catch block.  (Note that you still need to keep the current ok(true) so that the test would print _something_ when successful, to keep the test framework from complaining about a test finished with no checks run.)

r=me with that.
Attachment #597167 - Flags: review?(ehsan) → review+
Attached patch Patch v2Splinter Review
Attachment #597167 - Attachment is obsolete: true
Attachment #599608 - Flags: review+
Patch updated as requested.
Keywords: checkin-needed
http://hg.mozilla.org/integration/mozilla-inbound/rev/0e50adaab9d7
Flags: in-testsuite+
Keywords: checkin-needed
OS: Linux → All
Hardware: x86 → All
Target Milestone: --- → mozilla13
https://hg.mozilla.org/mozilla-central/rev/0e50adaab9d7
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: