[Input Events] Set "affected" ranges to the result of `getTargetRanges()` at dispatching `beforeinput` event
Categories
(Core :: DOM: Events, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox83 | --- | fixed |
People
(Reporter: masayuki, Assigned: masayuki)
References
Details
(Keywords: dev-doc-complete)
Attachments
(22 files)
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review |
InputEvent.getTargetRanges()
is an important feature of beforeinput
event because without this API, web apps cannot know where will be deleted or replaced if they won't cancel the beforeinput
event. Currently, we just set selection ranges, but when deleting content, we need to set actual ranges which will be deleted.
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 1•4 years ago
|
||
I think that we can land the patches separately because the API has not been shipped in any channels and multiple landings make regression window smaller.
Assignee | ||
Comment 2•4 years ago
|
||
In strictly speaking, we should use same computed target ranges for any edit
actions which causes removing non-collapsed selection. However, for now,
this patch makes only DeleteSelectionAsAction()
because it's not so important
differences for shipping beforeinput
in Nightly channel.
Assignee | ||
Comment 3•4 years ago
|
||
This patch implements computation of target ranges for this part:
https://searchfox.org/mozilla-central/rev/73a14f1b367948faa571ed2fe5d7eb29460787c1/editor/libeditor/HTMLEditSubActionHandler.cpp#3099-3141
This patch adds some utility methods for computing the ranges. Currently,
it's not yet standardized, but the other browser engines look for leaf content
of another block when blocks are joined (or a block is deleted like this case).
Therefore, we follow the behavior basically, but different from the other
browsers, we should include invisible white-spaces into the range when they
are included. That avoids the invisible white-spaces become visible when
web apps do something instead of us. Note that utility methods have the code,
but this patch does not use it because in this case, we just delete a empty
block ancestor, not join it with previous/next block.
Depends on D88376
Assignee | ||
Comment 4•4 years ago
|
||
This change is corresponding to the part:
https://searchfox.org/mozilla-central/rev/73a14f1b367948faa571ed2fe5d7eb29460787c1/editor/libeditor/HTMLEditSubActionHandler.cpp#3143-3155
When caret is not adjacent the deleting character in bidi text, we may do
nothing except putting caret to the character. So, ComputeRangesToDelete()
shouldn't update the caret position since the caret position will be check
by its Run()
later if beforeinput
event is not canceled. For avoiding
the code duplication, this patch reimplements
EditorBase::SetCaretBidiLevelForDeletion()
as a stack only class and
split the check and updating part from correcting the data.
Note that by the default pref, the new tests failed since it won't be
canceled, and the method still don't compute for deleting a character.
Depends on D88377
Assignee | ||
Comment 5•4 years ago
|
||
This patch adding computation code corresponding to:
https://searchfox.org/mozilla-central/rev/27932d4e6ebd2f4b8519865dad864c72176e4e3b/editor/libeditor/HTMLEditSubActionHandler.cpp#3157-3185
For beforeinput
event listeners, AutoSetTemporaryAncestorLimiter
is not
enough since when beforeinput
event listeners modifies Selection
, the
ancestor limit is not set when it has a job. Perhaps, we should make editor
stop using focus/blur event listener and makes nsFocusManager
notifies
editor of them synchronously before dispatching the events. But it's not
scope of this bug at least.
Depends on D88378
Comment 9•4 years ago
|
||
Backed out changeset bacd9a2d26c1 (Bug 1658702) for causing hazard bustages in HTMLEditSubActionHandler.cpp
Backout link: https://hg.mozilla.org/integration/autoland/rev/c0c0237502da2d05609acc2be5e9e3ee95437f57
Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=314452788&repo=autoland&lineNumber=18320
Comment 10•4 years ago
|
||
bugherder |
Assignee | ||
Updated•4 years ago
|
Assignee | ||
Comment 12•4 years ago
|
||
This patch implements the preparation part of deleting collapsed range.
https://searchfox.org/mozilla-central/rev/ce21a13035623c1d349980057d09000e70669802/editor/libeditor/HTMLEditSubActionHandler.cpp#3188-3206
Depends on D88379
Assignee | ||
Comment 13•4 years ago
|
||
For implementing this case, we need more helper methods. Let's do this after
implementing other cases.
https://searchfox.org/mozilla-central/rev/ce21a13035623c1d349980057d09000e70669802/editor/libeditor/HTMLEditSubActionHandler.cpp#3207-3276
Depends on D88939
Assignee | ||
Comment 14•4 years ago
|
||
Just for computing the deletion range, we can use new path for the Blink-compat
white-space normalizer.
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/ce21a13035623c1d349980057d09000e70669802/editor/libeditor/HTMLEditSubActionHandler.cpp#3278-3284
- https://searchfox.org/mozilla-central/rev/ce21a13035623c1d349980057d09000e70669802/editor/libeditor/HTMLEditSubActionHandler.cpp#3298-3344
- https://searchfox.org/mozilla-central/rev/ce21a13035623c1d349980057d09000e70669802/editor/libeditor/HTMLEditSubActionHandler.cpp#3422-3455
Depends on D88940
Comment 15•4 years ago
|
||
Comment 16•4 years ago
|
||
Comment 18•4 years ago
|
||
Comment 19•4 years ago
|
||
bugherder |
Assignee | ||
Comment 20•4 years ago
|
||
This patch corresponds to the following part:
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/HTMLEditSubActionHandler.cpp#3346-3360
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/HTMLEditSubActionHandler.cpp#3750-3761
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/WSRunObject.cpp#1075-1113
Let's return a range selecting the deleting atomic content (i.e., between
EditorDOMPoint(&content)
and EditorDOMPoint::After(content)
).
For doing it, we need to shrink the computed range after
AutoRangeArray::ExtendAnchorFocusRangeFor()
because layout code puts
range boundaries to start or end of text node in this case.
Then, surprisingly, our deletion code have not used
HandleDeleteCollapsedSelectionAtAtomicContent()
in most cases because
AutoRangeArray::ExtendAnchorFocusRangeFor()
makes the collapsed range
to non-collapsed. For making the deletion faster and simpler, this patch
shrinks the result of AutoRangeArray::ExtendAnchorFocusRangeFor()
if
it has only one range and selects only one atomic content node.
Depends on D88941
Assignee | ||
Comment 21•4 years ago
|
||
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/HTMLEditSubActionHandler.cpp#3362-3375
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/HTMLEditSubActionHandler.cpp#3679-3695
- https://searchfox.org/mozilla-central/rev/0c682c4f01442c3de0fa6cd286e9cadc8276b45f/editor/libeditor/HTMLEditSubActionHandler.cpp#3728-3742
Note that the complicated cases (surrounded by invisible <br>
element and/or
surrounded by invisible white-spaces) are handled as deleting non-collapsed
range so that this improves only the simple cases.
And also this adds a pref to disable the Gecko specific complicated <hr>
element handling.
Depends on D88968
Comment 23•4 years ago
|
||
bugherder |
Comment 24•4 years ago
|
||
Assignee | ||
Comment 25•4 years ago
|
||
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#3525-3543
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#2710-2719
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#4140-4165
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/HTMLEditSubActionHandler.cpp#5650-5716
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#97-213
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#218-386
- https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/editor/libeditor/WSRunObject.cpp#391-480
In WSRunObject.cpp
, joining 2 blocks code is split to 3 methods, they are
for:
- left block element is an ancestor of right block element
- right block element is an ancestor of left block element
- left block element and right block element are siblings
The reason why they are split to is, they need to move descendants of child
block element or right block element with different logic. However, this
difference is not a big problem when we compute target ranges because only
the difference is where we need to check whether there are invisible white-
spaces. Therefore, this patch creates only a utility method in WSRunScanner
and makes AutoInclusiveAncestorBlockElementsJoiner::ComputeRangesToDelete()
much simpler than AutoInclusiveAncestorBlockElementsJoiner::Run()
.
And also this patch fixes a long standing bug that is HTMLEditor
tries to
join <body>
element and <head>
element when you type Backspace
at
beginning of the <body>
element when <html>
element has contenteditable
.
Without this fix, the getTargetRange
result becomes buggy in this case.
Depends on D88969
Comment 26•4 years ago
|
||
bugherder |
Comment 27•4 years ago
|
||
Comment 28•4 years ago
|
||
bugherder |
Comment 29•4 years ago
|
||
Comment 31•4 years ago
|
||
bugherder |
Comment 33•4 years ago
|
||
Comment 34•4 years ago
|
||
bugherder |
Updated•4 years ago
|
Assignee | ||
Comment 35•4 years ago
|
||
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#3679-3697
- https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#2733-2751
- https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4286-4302
- https://searchfox.org/mozilla-central/rev/b2716c233e9b4398fc5923cbe150e7f83c7c6c5b/editor/libeditor/HTMLEditSubActionHandler.cpp#4309-4355
HandleDeleteCollapsedSelectionAtCurrentBlockBoundary()
delete leaf content
of the child block when the block is not joined with current block. For
doing it, it creates another AutoDeleteRangesHandler
with collapsing selection
in the child block. Then, it may refer selection for handling bidi text.
Therefore, the computation code which is added by this patch may modify
selection temporarily for the child AutoDeleteRangeHandler
. However, the
selection change shouldn't cause running any scrip (even if chrome script)
because it's required only for this hack. Therefore, this patch blocks all
notifications and selection change events with AutoHideSelectionChanges
.
Therefore, this patch marks
AutoBlockElementsJoiner::ComputeRangesToDeleteAtOtherBlockBoundary()
as
MOZ_CAN_RUN_SCRIPT_BOUNDARY
for using HTMLEditor::CollapseSelectionTo()
.
Depends on D89278
Assignee | ||
Comment 36•4 years ago
|
||
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#3531-3537
- https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#4443-4561
- https://searchfox.org/mozilla-central/rev/8a0745cd346f0cfb89ae71690babbf7bff706113/editor/libeditor/HTMLEditSubActionHandler.cpp#2778-2822
Note that the new failure of input-events-get-target-ranges-forwarddelete.html
is mismatch between target range (including the trailing white-space) and
actually deleted range (not including the trailing white-space). Let's
accept this new failure for now since not so important problem and same test
with backspace has same bug.
Depends on D89869
Comment 37•4 years ago
|
||
Assignee | ||
Comment 39•4 years ago
|
||
Depends on D90065
Assignee | ||
Comment 40•4 years ago
|
||
HTMLEditor
falls back to EditorBase::DeleteRangesWithTransaction()
in
some cases, especially when handling non-collapsed ranges. Therefore, we
need to implement it for the following patches.
The code corresponds to:
- https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3848-3862
- https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3355,3371,3374,3376,3386-3387,3392
- https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/EditorBase.cpp#3421,3431-3432,3435-3436,3444,3453-3455,3464-3465,3473-3474,3477-3478,3486,3495-3497,3506-3507,3515-3520,3526-3528,3535-3538,3543-3544,3546-3549,3558-3562,3570-3572,3579-3580
- https://searchfox.org/mozilla-central/rev/62c443a7c801ba9672de34c2867ec1665a4bbe67/editor/libeditor/DeleteTextTransaction.cpp#34,49-51,59,69-71
Basically, we don't need to touch the ranges, but if aDirectionAndAmount
is
nsIEditor::eNext
or nsIEditor::ePrevious
, each collapsed range is extened
for:
- previous character (treating only surrogate pair)
- next character (treating only surrogate pair)
- selecting another content node
This logic is much rougher than what AutoDeleteRangesHandler
and its nested
classes do. So, HTMLEditor
should stop using it in the future, but we need
to keep using it for now.
Depends on D90210
Assignee | ||
Comment 41•4 years ago
|
||
This patch corresponds to:
Depends on D90211
Assignee | ||
Comment 42•4 years ago
|
||
They need to just call
AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction()
because
their corresponding methods calls EditorBase::DeleteRangesWithTransaction()
and do additional different jobs after that, but the they don't affect the
ranges.
- https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4602,4627-4628,4639-4642
- https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4650,4669-4670,4676-4678,4685-4686
Depends on D90212
Assignee | ||
Comment 43•4 years ago
|
||
This patch corresponds to:
- https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4812-4825,4839-4850
- https://searchfox.org/mozilla-central/rev/0c97a6410ff018c22e65a0cbe4e5f2ca4581b22e/editor/libeditor/HTMLEditSubActionHandler.cpp#4699-4706,4709,4734-4747
Like mentioned in the first link, the logic is completely broken so that this
just follows the broken logic to return actual "affected ranges".
Depends on D90213
Comment 44•4 years ago
|
||
bugherder |
Comment 46•4 years ago
|
||
Comment 47•4 years ago
|
||
bugherder |
Comment 48•4 years ago
|
||
Comment 49•4 years ago
|
||
bugherder |
Comment 50•4 years ago
|
||
Assignee | ||
Comment 52•4 years ago
|
||
This patch corresponds to:
However, it seems that this is a dead path in most cases because most tests
added by this patch are handled as non-collapsed range deletion. The
collapsed range is extended by AutoRangeArray::ExtendAnchorFocusRangeFor()
.
Depends on D90214
Assignee | ||
Comment 53•4 years ago
|
||
When joining 2 block elements, the left block element may ends with invisible
<br>
element or the right block element may follows an invisible <br>
element if it's a descendant of the left block element. In those cases, the
invisible <br>
element must be start of the target range of the joining
block elements since it'll be deleted.
Depends on D90540
Assignee | ||
Comment 54•4 years ago
|
||
Currently, target ranges do not extend the ranges even when deleting empty
parent elements of the range. Therefore, the frag indicating whether empty
parents removed or not is not necessary for the methods.
Depends on D90541
Comment 55•4 years ago
|
||
Comment 56•4 years ago
|
||
Assignee | ||
Comment 57•4 years ago
|
||
A lot of edit actions calls DeleteSelectionAsSubAction()
if selection is
not collapsed. In such case, getTargetRanges()
should return same result
as when the selection range is simply deleted.
This patch creates 2 methods to consider whether EditAction
causes
running DeleteSelectionAsSubAction()
with collapsed selection or
non-collapsed selection.
And makes DeleteSelectionAsAction()
stop initializing the target ranges
itself. Instead, makes AutoEditActionDataSetter
do it immediately before
dispatching beforeinput
event unless it's been already initialized manually.
- https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#492
- https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditor.cpp#731
- https://searchfox.org/mozilla-central/rev/30e70f2fe80c97bfbfcd975e68538cefd7f58b2a/editor/libeditor/TextEditorDataTransfer.cpp#503
The correctness of the new utility methods are tested with new MOZ_ASSERT
in DeleteSelectionAsSubAction()
.
Additionally, this reorganizes input-events-get-target-ranges-*.html
.
- Moving common code into
input-events-get-target-ranges.js
- Moving non-collapsed selection cases into
input-events-get-target-ranges-non-collapsed-selection.html
- Adding "typing a" case into the new test for testing this patch's behavior
Depends on D90542
Assignee | ||
Comment 58•4 years ago
|
||
If deleting/replacing range selects a text node, it may shrink the range
to start and end of the text node. So, the result may not be wider than
the original range.
This behavior is compatible with Blink.
Depends on D90639
Comment 59•4 years ago
|
||
bugherder |
Comment 61•4 years ago
|
||
Comment 62•4 years ago
|
||
Comment 64•4 years ago
|
||
Comment 65•4 years ago
|
||
bugherder |
Assignee | ||
Updated•4 years ago
|
Comment 67•4 years ago
|
||
Comment 69•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/77da8a3e42c0
https://hg.mozilla.org/mozilla-central/rev/384654269ee3
Updated•4 years ago
|
Comment 71•4 years ago
|
||
These changes have been documented; see https://github.com/mdn/sprints/issues/3799#issuecomment-717309934 for the full details.
Let us know if you need anything else. Thanks!
Description
•