Commit Graph

454 Commits

Author SHA1 Message Date
Sean Feng
97c334db09 Bug 1966135 - Allow CompareChildOffsetAndChildNode to do flattened tree comparison r=jjaschke,dom-core
If the element is slotted and the aKind == TreeKind::Flat, it should
use the index of AssignedNodes of the slot element to do the
comparison.

Differential Revision: https://phabricator.services.mozilla.com/D249427
2025-05-16 16:04:51 +00:00
Sean Feng
ebb4c0813e Bug 1966135 - Make CompareToRange{Start|End} explicit about the ordering r=jjaschke,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D249426
2025-05-16 16:04:47 +00:00
Sean Feng
bfe12c6363 Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D231590
2025-05-09 18:19:18 +00:00
Sean Feng
d3f6c9a968 Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231589
2025-05-09 18:19:04 +00:00
Sean Feng
59893c42dc Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-09 18:19:00 +00:00
Serban Stanca
5691c4beb2 Revert "Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core"
This reverts commit 8d55fdef16.
2025-05-08 20:00:31 +00:00
Serban Stanca
032142893c Revert "Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core"
This reverts commit 0221ba097e.
2025-05-08 20:00:27 +00:00
Serban Stanca
456ace9a5f Revert "Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug"
This reverts commit bce1570f96.
2025-05-08 20:00:13 +00:00
Sean Feng
bce1570f96 Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D231590
2025-05-08 13:40:18 +00:00
Sean Feng
0221ba097e Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231589
2025-05-08 13:40:04 +00:00
Sean Feng
8d55fdef16 Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-08 13:40:01 +00:00
Atila Butkovits
da71eedf0a Revert "Bug 1932150 - Fix build bustage" for causing build bustages.
This reverts commit 0681b181d6.

Revert "Bug 1932150 - Fix lint failure" for causing Build bustage.

This reverts commit 60cc0878d3.

Revert "Bug 1932150 - Add new test cases for selection in flat tree r=smaug"

This reverts commit 3dbe5fc183.

Revert "Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug"

This reverts commit 6f7a1e4886.

Revert "Bug 1932150 - ContentSubtreeIterator #3: Fix a bug in ContentSubtreeIterator where the end container is in the light DOM of a shadow host r=jjaschke"

This reverts commit 19ce2c5806.

Revert "Bug 1932150 - ContentSubtreeIterator #2: Allow ContentSubtreeIterator to iterate nodes in flattened tree r=jjaschke"

This reverts commit d9d192bc3a.

Revert "Bug 1932150 - ContentSubtreeIterator #1: Make the end container related logic in ContentSubtreeIterator more robust r=jjaschke,smaug,dom-core"

This reverts commit 2fbde5b84d.

Revert "Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core"

This reverts commit 116d26c37f.

Revert "Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core"

This reverts commit 2ba73e1639.

Revert "Bug 1932150 - Fix some inconsistency about indicating whether the selection is allowed to cross the shadow boundary r=jjaschke,dom-core"

This reverts commit 793c2453f1.
2025-05-07 18:30:42 +00:00
Sean Feng
6f7a1e4886 Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D231590
2025-05-07 15:08:52 +00:00
Sean Feng
116d26c37f Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231589
2025-05-07 15:08:38 +00:00
Sean Feng
2ba73e1639 Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-07 15:08:34 +00:00
Sean Feng
b46ba13f0c Bug 1949915 - Fix a bug where we unnecessarily trace nodes during unlinking r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D245796
2025-04-17 14:01:16 +00:00
Florian Quèze
9885783942 Bug 1956726 - remove leftover Telemetry.h includes in .cpp files, r=chutten,geckoview-reviewers,cookie-reviewers,win-reviewers,dom-storage-reviewers,gstoll,valentin,m_kato,janv.
Differential Revision: https://phabricator.services.mozilla.com/D244351
2025-04-08 13:03:02 +00:00
Stanca Serban
51ed5a8381 Bug 85686 - Fix for build bustages. CLOSED TREE 2025-03-17 18:04:39 +02:00
Sean Feng
e46b69d89c Bug 85686 - Mimic Chromium's getSelection().toString() behaviour r=masayuki,dom-core,webidl,smaug
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.

We should still address the spec issues, but this seems to be
an acceptable compromise.

Differential Revision: https://phabricator.services.mozilla.com/D239657
2025-03-17 13:36:16 +00:00
Masayuki Nakano
a5637890c7 Bug 1946001 - Fix some points which may cross independent selection boundary r=emilio,jjaschke
This patch fixes multiple points which may cross independent selection
boundaries which is element boundary of the native anonymous `<div>` for
editable content in text controls.  The reason why I don't split this patch is,
fixing one of them leads another assertion failure.  So, I couldn't pass all
tests with separated patches.

1. `nsFrameTraversal` should take `Element` instead of `nsIFrame` for the
limiter because e.g., inline editing host like `<span contenteditable>` may
have multiple frames if it's wrapped.  Therefore, we should make it take
an element as the ancestor limiter, and check it when getting parent frame
or after getting previous or next frame.
2. `nsIFrame::PeekBackwardAndForward` may cross the boundary because it does not
take the anonymous `<div>` element as ancestor limiter of the selection.  It's
currently used only for extending selection.  Therefore, I rename it to make
it clearer.
3. `SelectionMovementUtils::GetPrevNextBidiLevel` to take the ancestor limiter
for calling `nsIFrame::GetFrameFromDirection()`.
4. `nsINode` should have a method to return the `nsFrameSelection` instance
which manages the selection in the node.  This makes the check simpler, and
this is not expensive.  Then, for making it clearer, I rename
`TextControlElement::GetConstFrameSelection()` to
`GetIndependentFrameSelection()`.
5. `nsINode::GetSelectionRootContent()` should have an option to return
independent selection root when the node is its host for
`nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()`
6. `nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()` should not
retrieve independent selection root when the given frame is a text control
frame.
7. `RangeUtils` should get parent with checking the independent selection
boundaries.
8. `Selection::Extend` should assert if the destination is managed by its
frame selection to detect a bug.

Differential Revision: https://phabricator.services.mozilla.com/D241587
2025-03-17 12:49:57 +00:00
Alexandru Marc
2e0051d757 Backed out 2 changesets (bug 85686, bug 1954244) for causing mass failures a=backout
Backed out changeset 702bc8ef655a (bug 1954244)
Backed out changeset a3cd9e425585 (bug 85686)
2025-03-15 04:22:27 +02:00
Sean Feng
d9af41ffc2 Bug 85686 - Mimic Chromium's getSelection().toString() behaviour r=masayuki,dom-core,webidl,smaug
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.

We should still address the spec issues, but this seems to be
an acceptable compromise.

Differential Revision: https://phabricator.services.mozilla.com/D239657
2025-03-13 17:31:54 +00:00
Cristina Horotan
a755f2ab17 Backed out changeset c354639dff24 (bug 85686) for causing multiple dt failures. CLOSED TREE 2025-03-12 22:13:59 +02:00
Sean Feng
afba09df01 Bug 85686 - Mimic Chromium's getSelection().toString() behaviour r=masayuki,dom-core,webidl,smaug
Basically when getSelection().toString() is called, Chromium may
return an serialization on a different content than Firefox.
This patch tries to address this webcompat issue by mimicing
the same behaviour.

We should still address the spec issues, but this seems to be
an acceptable compromise.

Differential Revision: https://phabricator.services.mozilla.com/D239657
2025-03-12 15:50:43 +00:00
Andrea Marchesini
429a024494 Bug 1951364 - Update the webIDL definition of the Selection.modify method, r=webidl,emilio,smaug
Differential Revision: https://phabricator.services.mozilla.com/D240134
2025-03-04 07:36:59 +00:00
Butkovits Atila
6f85622c4f Backed out changeset 9820dd372dc5 (bug 1951364) for causing failures at browser_misused_characters_in_strings.js. CLOSED TREE 2025-03-03 21:01:34 +02:00
Andrea Marchesini
3acbf396f7 Bug 1951364 - Update the webIDL definition of the Selection.modify method, r=webidl,emilio,smaug
Differential Revision: https://phabricator.services.mozilla.com/D240134
2025-03-03 17:13:38 +00:00
Masayuki Nakano
da4abce2d9 Bug 1945714 - Rename RangeBoundaryBase::Container() to GetContainer() r=jjaschke,dom-core
Usually, we name methods as `GetFoo()` if they may return `nullptr`, on the
other hand, we name methods as `Foo()` if they won't return `nullptr`.

`RangeBoundaryBase::Container()` may return `nullptr`.  So, this name may cause
misleading of some developers.  Let's rename it as `GetContainer()`.

This does not change anything for avoiding merge conflict with the other
landings.

Differential Revision: https://phabricator.services.mozilla.com/D236796
2025-02-10 01:29:40 +00:00
Masayuki Nakano
01bac70fb9 Bug 1945711 - part 4: Rename the aParent/aOffset version of nsContentUtils::ComparePoints to ComparePointsWithIndices r=jjaschke,dom-core
To make it easier to find the callers, we should give different name instead
of overloading.

Differential Revision: https://phabricator.services.mozilla.com/D236794
2025-02-10 01:29:40 +00:00
Masayuki Nakano
e595f1e9aa Bug 1945711 - part 3: Make some callers of nsContentUtils::ComparePoints use the RangeBoundaryBase version r=jjaschke,dom-core
There are some callers of parent/offset version which computes offset before.
However, the offset may not be used.  Therefore, the callers should use
`RangeBoundaryBase` version.

Additionally, if only one of the pairs is computed from `RangeBoundaryBase`,
such callers should use the `RangeBoundaryBase` version too because the offset
computation may be skipped.  In this case, temporary `RangeBoundaryBase` should
be a `RawRangeBoundary` and whose `aRangeIsMutationObserver` should be set to
`RangeBoundaryIsMutationObserved::No` to avoid immediately to compute the child
node from `aOffset`.  I think that this should be default to
`RangeBoundaryIsMutationObserved::No` in the future, but for now, we should just
make the users explicitly set it to `RangeBoundaryIsMutationObserved::No` for
avoiding regressions.

Differential Revision: https://phabricator.services.mozilla.com/D236793
2025-02-10 01:29:39 +00:00
James Teh
1970e2b155 Bug 1909142 part 1: Add Selection and nsFrameSelection getters to enable the accessibility engine to query custom highlight information. r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D233805
2025-02-06 05:51:07 +00:00
Alexandru Marc
a2fd705a1c Backed out 3 changesets (bug 1909142) for causing build bustages @ Selection.h
Backed out changeset 86c70282c41a (bug 1909142)
Backed out changeset 91b09cf9d29b (bug 1909142)
Backed out changeset 4ca7e6d2bcab (bug 1909142)
2025-02-06 03:34:24 +02:00
James Teh
24f35ca025 Bug 1909142 part 1: Add Selection and nsFrameSelection getters to enable the accessibility engine to query custom highlight information. r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D233805
2025-02-05 22:59:15 +00:00
Jan-Niklas Jaeschke
6624852dc9 Bug 1943179 - Add [[nodiscard]] to ContentIterator methods that return nsresult. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D235361
2025-01-28 18:26:31 +00:00
Sandor Molnar
829c6cdf91 Backed out changeset afeecd52c4a7 (bug 1943179) for causing build bustages @ FilteredContentIterator.cpp CLOSED TREE 2025-01-28 18:24:33 +02:00
Jan-Niklas Jaeschke
d85b643e72 Bug 1943179 - Add [[nodiscard]] to ContentIterator methods that return nsresult. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D235361
2025-01-28 15:54:36 +00:00
Masayuki Nakano
2b503ca56d Bug 1943226 - Make nsFrameSelection treat limiters are elements r=jjaschke,dom-core
`nsFrameSelection::GetLimiter()` is not `nullptr` only when it's an instance for
an independent selection of a text control.  In the case, it's set to the editor
root anonymous `<div>` of the text control.  Despite the name, this is already
optimized only for this purpose in `nsFrameSelection::NodeIsInLimiters()`.
Thus, we don't have any problems to make this clearer for the other developers
with renaming some parameter names.

`nsFrameSelection::GetAncestorLimiter()` is also always an `Element`.  So,
we can change this to `Element` too.

Differential Revision: https://phabricator.services.mozilla.com/D235254
2025-01-24 02:53:07 +00:00
Masayuki Nakano
9fd27e7690 Bug 1937289 - Make AutoRangeArray::ExtendAnchorFocusRangeFor stop using nsFrameSelection r=m_kato,jjaschke,dom-core
`AutoRangeArray` is created for making some handlers of the editor classes free
from `Selection` and `nsFrameSelection` while handling the edit actions.
However, the method still depends on `nsFrameSelection` instance since its
callees are instance methods of `nsFrameSelection`.

However, `EditContext` requires completely free methods to compute target
ranges of `beforeinput`.  Therefore, we need to make it not depend on
`Selection` nor `nsFrameSelection`.

The common method, `nsFrameSelection::CreateRangeExtendedToSomewhere`, requires
`PresShell`, selection limiter which is set only when the selection is an
independent selection like in a selection for a text control, selection
ancestor limiter which is set only when an editing host has focus, caret
association hint to put caret to end of preceding line or start of following
line if selection range is collapsed at a line break and caret bidi level for
considering caret position around line break in bidi text.  They are now stored
by `nsFrameSelection` and modified when selection range is changed in some
cases.  Basically, the method is called without updating its ranges and if and
only if it's initialized with `Selection`.  So, simply caching the
`nsFrameSelection`'s values solves the issues in the most cases, but this
patch makes `AutoRangeArray` adjust the value only when its `Collapse` is
called because `Selection` automatically updates it and we can compute the
value without `Selection` nor `nsFrameSelection`.

After applying this patch, `AutoRangeArray` has two meanings, one is the
instance is a proxy for `Selection`.  The other is a container for a range to
call methods which take pointer or reference to it.  To make this differences
checked at build time, this patch creates a new subclass of it, and renamed to
`AutoClonedRangeArray` to make it clearer that what are stored in the array.

Oddly, `AutoRangeArray(nsRange&)` constructor has not been cloned.  Therefore,
I make it and its subclass version clone before storing into the array.  Then,
one caller needs to change which range should be tracked.

Differential Revision: https://phabricator.services.mozilla.com/D232174
2025-01-07 01:56:52 +00:00
Otto Länd
c5f207960d Bug 1933738: apply code formatting via Lando
# ignore-this-changeset
2024-11-29 07:34:40 +00:00
Jan-Niklas Jaeschke
32b0a740b7 Bug 1933738, part 2 - Change all calls to nsFrameSelection::GetSelection(eNormal) to nsFrameSelection::NormalSelection(). r=emilio
`nsFrameSelection::NormalSelection()` returns a `Selection&`, which eliminates the need for nullptr check at call sites.
This simplifies the code in some places and removes unnecessarily indented blocks.

Differential Revision: https://phabricator.services.mozilla.com/D230583
2024-11-29 07:31:58 +00:00
Jan-Niklas Jaeschke
c0e1ec05ea Bug 1927549, part 1: Introduce enum ExtendSelection in nsFrameSelection. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D227144
2024-10-29 09:25:07 +00:00
Emilio Cobos Álvarez
1123d2e75f Bug 1926031 - Make Selection::ScrollIntoView take ScrollFlags. r=jjaschke,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D226389
2024-10-22 09:58:02 +00:00
Jan-Niklas Jaeschke
148ccccc20 Bug 1920381 - Added missing sanity checks before inserting ranges into cache. r=sefeng
Differential Revision: https://phabricator.services.mozilla.com/D223700
2024-09-30 16:15:16 +00:00
Sean Feng
0a64494b46 Bug 1885462 - Add a new MOZ_DIAGNOSTIC_ASSERT_IF assert to Selection::SelectFrames r=masayuki
I wonder if this relates to shadow-crossing selection. I.e,
the default boundaries (nsRange.mStart, nsRange.mEnd) are collapsed,
but there's a CrossShadowBoundaryRange that makes this nsRange
still valid to many callers.

So adding this assertion to help diagnosing.

Differential Revision: https://phabricator.services.mozilla.com/D222864
2024-09-20 13:55:27 +00:00
Jan-Niklas Jaeschke
70014fe558 Bug 1867249, part 1: Implemented new cache to determine selected nodes. r=sefeng,dom-core
Determining if a node is selected is a super-hot code path,
which at times introduces jank both in Reflow and Painting.
This is due to each node comparing its position to the range's start and end point,
which even happens several times (`nsINode::IsSelected()` and `Selection::LookupSelection()`).
In worst cases, this can lead to reflow which takes several minutes.

This patch introduces a cache which contains all fully selected nodes,
and lives throughout one `PresShell::DoReflow()` call.
Collecting all selected nodes of a selection is very fast.
The selected nodes are then stored in a hash set.
During reflow the check if a node is selected first checks the cache
if the node is fully selected, and otherwise goes through the existing
code to check if the node is partially selected.

Differential Revision: https://phabricator.services.mozilla.com/D217794
2024-08-05 15:43:27 +00:00
James Teh
bd70ec7bf6 Bug 1905211 part 7: Notify accessibility about ranges that are added or removed from selections. r=smaug,morgan
nsISelectionListener isn't sufficient because it only notifies that the selection has changed.
A11y needs to know specifically which ranges were added or removed.
Previously, we handled this specifically for spelling errors in mozInlineSpellChecker.
That code has been removed and replaced with a more general approach.

Since we now have these notifications, rather than using nsISelectionListener just to fire events, we now use these notifications for that as well.
This avoids the need to add additional nsISelectionListeners, which would get messy particularly for custom highlights where there can be an arbitrary number of selections at any given time.

Differential Revision: https://phabricator.services.mozilla.com/D217068
2024-08-05 02:54:37 +00:00
Emilio Cobos Álvarez
bc37920bdb Bug 1908552 - Remove unused ChromeOnly Selection.scrollIntoView. r=jjaschke,masayuki
There are no callers from JS (looked at the selection region constant
usage in idl and those use nsISelectionController, not this).

If we were to provide this API in the future, it would probably use
ScrollIntoViewOptions or so instead (plus something extra perhaps).

I wanted to remove the weird WehreToScroll percentage impl, but actually
some C++ accessibility code still uses it.

Differential Revision: https://phabricator.services.mozilla.com/D216872
2024-07-26 11:29:56 +00:00
Iulian Moraru
ff7a722cf7 Backed out changeset b85a757c74ac (bug 1908552) for causing mochitest-plain failures on test_scroll_selection_into_view.html. CLOSED TREE 2024-07-24 13:00:24 +03:00
Emilio Cobos Álvarez
fedd97f1b3 Bug 1908552 - Remove unused ChromeOnly Selection.scrollIntoView. r=jjaschke,masayuki
There are no callers from JS (looked at the selection region constant
usage in idl and those use nsISelectionController, not this).

If we were to provide this API in the future, it would probably use
ScrollIntoViewOptions or so instead (plus something extra perhaps).

I wanted to remove the weird WehreToScroll percentage impl, but actually
some C++ accessibility code still uses it.

Differential Revision: https://phabricator.services.mozilla.com/D216872
2024-07-24 07:04:13 +00:00
Ting-Yu Lin
5cd68a11de Bug 1896516 Part 9 - Remove nsIScrollableFrame usages under dom/. r=layout-reviewers,emilio
Also, in EventStateManager, convert `ComputeScrollTarget()` and
`ComputeScrollTargetAndMayAdjustWheelEvent()` to return `ScrollContainerFrame*`
so that we can drop more unnecessarily `do_QueryFrame`.

Due to removing `nsIScrollableFrame` forward declaration in DOM headers, we have
to add `nsIScrollableFrame` forward declaration temporarily in
nsMenuPopupFrame.h to make this patch compile, but we'll remove it once we
remove `nsIScrollableFrame` under layout/.

Differential Revision: https://phabricator.services.mozilla.com/D211496
2024-05-30 06:32:21 +00:00