Closed Bug 1623413 Opened 5 years ago Closed 4 years ago

Selection.collapse fails with NS_ERROR_FAILURE if called for two different editable blocks

Categories

(Core :: DOM: Selection, defect, P3)

76 Branch
defect

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox76 --- wontfix
firefox82 --- fixed

People

(Reporter: saschanaz, Assigned: saschanaz)

References

Details

Attachments

(4 files)

Attached file selection-failure.html

Loading the attached file throws with NS_ERROR_FAILURE.

Interesting, this indeed only happens when there are two divs. For the error to occur, it suffices if the first div is contenteditable. Works on Chrome.

Priority: -- → P3

!frameSelection->IsValidSelectionPoint(aPoint.Container()) check fails inside Selection::Collapse().

Internally, the first collapse() call gets null from GetAncestorLimit() while the second call gets the parent div (the grandparent of the text node bar) and then fails aNode->IsInclusiveDescendantOf(limiter) check.

Not sure what an ancestor limit is here, could you give me a thought?

Flags: needinfo?(mbrodesser)

(In reply to Kagami :saschanaz from comment #2)

!frameSelection->IsValidSelectionPoint(aPoint.Container()) check fails inside Selection::Collapse().

Internally, the first collapse() call gets null from GetAncestorLimit() while the second call gets the parent div (the grandparent of the text node bar) and then fails aNode->IsInclusiveDescendantOf(limiter) check.

Not sure what an ancestor limit is here, could you give me a thought?

The idea seems to be, that the ancestor-limiter limits a Selection to the ancestor-limiter's descendants (https://searchfox.org/mozilla-central/rev/6cd54550a27e2f6ca0755a25328f769e41e524f4/layout/generic/nsFrameSelection.h#892-893). However, the comment in the code has to be taken with a grain of salt, because it's potentially outdated.

Flags: needinfo?(mbrodesser)

Weird that this bug doesn't happen when refreshing the page with the focus on the browser chrome. GetAncestorLimit() returns null for both <div> and passes IsValidSelectionPoint().

The comment of IsValidSelectionPoint says:

In the case of NO limiter all points are valid since you are in a topmost iframe. (browser or composer)

But in this case a <div> gets no limiter. Is this expected?

Flags: needinfo?(mbrodesser)
Flags: needinfo?(masayuki)

Well, navigation (e.g., ArrowDown key press) should be limited in the ancestor limit, but it might be better Selection API calls to ignore it especially when the caller is content script. If Selection allows any callers to ignore it, I guess that editor would be broken. For example, editor would collapse selection to outside of active editing host and that causes focus move.

(In reply to Kagami :saschanaz from comment #4)

Weird that this bug doesn't happen when refreshing the page with the focus on the browser chrome. GetAncestorLimit() returns null for both <div> and passes IsValidSelectionPoint().

The comment of IsValidSelectionPoint says:

In the case of NO limiter all points are valid since you are in a topmost iframe. (browser or composer)

But in this case a <div> gets no limiter. Is this expected?

Well, not expected, but I guess that the reason is focus event is not fired on non-focused DOM window:
https://searchfox.org/mozilla-central/rev/202a285024f174c2d2bf2152d9cba90a03723eab/dom/base/nsFocusManager.cpp#1454-1455,1459-1460,1464-1470,1517-1519

Flags: needinfo?(masayuki)
Flags: needinfo?(mbrodesser)

Because this bug's Severity has not been changed from the default since it was filed, and it's Priority is P3 (Backlog,) indicating it has been triaged, the bug's Severity is being updated to S3 (normal.)

Severity: normal → S3

This keeps happening whenever I write test cases...

Assignee: nobody → krosylight
Attachment #9172830 - Attachment description: Bug 1623413 - Skip selection point check when called from JS r=masayuki → Bug 1623413 - Part 1: Skip selection point check when called from JS r=masayuki
Pushed by krosylight@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0eef32d6a454 Part 1: Skip selection point check when called from JS r=masayuki https://hg.mozilla.org/integration/autoland/rev/75ed1b8a5c67 Part 2: Rename Collapse() to CollapseInLimiter() r=masayuki https://hg.mozilla.org/integration/autoland/rev/d3d67293f115 Part 3: Skip limiter check in CollapseToStart/End r=masayuki
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/25370 for changes under testing/web-platform/tests
Pushed by krosylight@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/6f419d6b635a Part 1: Skip selection point check when called from JS r=masayuki https://hg.mozilla.org/integration/autoland/rev/5d57d36010c1 Part 2: Rename Collapse() to CollapseInLimiter() r=masayuki https://hg.mozilla.org/integration/autoland/rev/aa032cbc9455 Part 3: Skip limiter check in CollapseToStart/End r=masayuki
Upstream PR merged by moz-wptsync-bot
Flags: needinfo?(krosylight)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: