Commit Graph
71 Commits
Author SHA1 Message Date
Jan-Niklas Jaeschke c76424fb7b Bug 2043347 - Text Fragments: Follow spec when searching for end terms in case of range-based matching. r=dom-core-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D303151
2026-06-11 09:06:59 +00:00
Sylvestre Ledru 9eb1a31a98 Bug 2023419 - Remove Emacs/Vim modelines from dom/ r=emilio,media-playback-reviewers,webidl,padenot
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287843
2026-03-16 21:02:32 +00:00
Norisz Fay a86d829321 Revert "Bug 2012637 - part 9: Add a Firefox Source Docs documentation page for TreeKind and notable issues r=smaug,dom-core" as requested by dev
This reverts commit 88008cd8ca.

Revert "Bug 2012637 - part 8: Make `nsContentUtils::ComparePoints` handle `TreeKind::Flat` and `TreeKind::FlatForSelection` correctly r=smaug,dom-core"

This reverts commit 73e6f6587b.

Revert "Bug 2012637 - part 7: Make `RangeUtils::CompareNodeToRangeBoundaries()` use `nsContentUtils::ComparePoints` with valid point in the tree r=smaug"

This reverts commit 6985d5e80f.

Revert "Bug 2012637 - part 6: Make `nsRange::CutContents()` convert the range boundaries to the ones in the DOM before comparing r=smaug"

This reverts commit 73b585af3d.

Revert "Bug 2012637 - part 5: Delete the default template parameter of `nsContentUtils::ComparePoints` and relatives r=smaug,dom-core"

This reverts commit 1a7f24e5b5.

Revert "Bug 2012637 - part 4: Make `nsContentUtils` use `nsIContent` for taking a child node as a parameter r=smaug"

This reverts commit a6ea8d6824.

Revert "Bug 2012637 - part 3: Add template `nsINode` API which can switch to call API from `TreeKind` r=smaug,dom-core,webidl"

This reverts commit a4211e9df0.

Revert "Bug 2012637 - part 2: Add `TreeKind::FlatForSelection` and change the template parameter of `ChildIteratorBase` to `TreeKind` r=smaug,dom-core"

This reverts commit 0241749ee7.

Revert "Bug 2012637 - part 1: Make `ChildIterBase` template class to re-implement `FlattenedChildIterator` for DOM, Flat and FlatForSelection TreeKind r=smaug,dom-core,layout-reviewers,emilio"

This reverts commit 9e71cb77fb.
2026-03-13 02:52:45 +00:00
Leo Tenenbaum c4449b13c3 Bug 2022547 - Fix "Copy Link to Highlight" for long selection ending in punctuation. r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D287222
2026-03-12 15:02:21 +00:00
Masayuki Nakano 1a7f24e5b5 Bug 2012637 - part 5: Delete the default template parameter of nsContentUtils::ComparePoints and relatives r=smaug,dom-core
They accept any kind of points even if it does not match with the
template parameter's `TreeKind` because the caller wants to check the
relation in different kind of tree.  Therefore, any callers need to
consider the `TreeKind` more carefully and clarify the `TreeKind` makes
developers easier to find a bug.

Differential Revision: https://phabricator.services.mozilla.com/D281308
2026-03-12 03:01:54 +00:00
André Bargull 218bc52cd7 Bug 2020607 - Part 2: Replace mozilla::AnyOf with std::any_of. r=sergesanspaille
Differential Revision: https://phabricator.services.mozilla.com/D285695
2026-03-04 13:42:30 +00:00
Jan-Niklas Jaeschke c1168e11ed Bug 1989891 - Text Fragments: Ensure context terms don't start/end with whitespace when reaching maximum length. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D265814
2025-09-23 20:40:34 +00:00
Jan-Niklas Jaeschke 8d53e4e7bc Bug 1987845 - Text Fragments: Correctly deal with punctuation when identifying the first/last word of the target range. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D264576
2025-09-12 09:21:33 +00:00
iulian moraru 7f5e54f6c6 Revert "Bug 1987845 - Text Fragments: Correctly deal with punctuation when identifying the first/last word of the target range. r=smaug" for causing windows nightly as release build bustages on TextDirectiveCreator.cpp.
This reverts commit 9d7b87687b.
2025-09-11 21:19:38 +00:00
Jan Jaeschke 9d7b87687b Bug 1987845 - Text Fragments: Correctly deal with punctuation when identifying the first/last word of the target range. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D264576
2025-09-11 19:28:56 +00:00
Jan-Niklas Jaeschke 2c73b06392 Bug 1979588 - Text Fragments: Correctly deal with long words at end of range for range-based matching. r=dom-core,smaug
The range-based approach for creating a text directive uses the word breaker algorithm
to identify where to split between `start` and `end` term. If the range ends with a word
which is over 50% of the length content, the algorithm would return wordEnd=length,
which would result in the `end` term being empty, which is not allowed.

This patch fixes this case by choosing the word begin position in this case.

Differential Revision: https://phabricator.services.mozilla.com/D263867
2025-09-10 12:36:03 +00:00
Cosmin Sabou 4e8871487a Revert "Bug 1979588 - Text Fragments: Correctly deal with long words at end of range for range-based matching. r=dom-core,smaug" for causing crashes (bug 1987845) as part of the Nightly merge operations
This reverts commit 7db1bf44de.
2025-09-10 09:36:22 +00:00
Jan-Niklas Jaeschke 7db1bf44de Bug 1979588 - Text Fragments: Correctly deal with long words at end of range for range-based matching. r=dom-core,smaug
The range-based approach for creating a text directive uses the word breaker algorithm
to identify where to split between `start` and `end` term. If the range ends with a word
which is over 50% of the length content, the algorithm would return wordEnd=length,
which would result in the `end` term being empty, which is not allowed.

This patch fixes this case by choosing the word begin position in this case.

Differential Revision: https://phabricator.services.mozilla.com/D263867
2025-09-09 14:38:06 +00:00
Emilio Cobos Álvarez 791917d8af Bug 1976665 - Sort headers in dom/. r=dom-core,media-playback-reviewers,webrtc-reviewers,dom-storage-reviewers,padenot,janv,smaug,jesup,jib
Most changes are automated. Relevant bit is dom/.clang-format. I had to
manually disable clang-format in a few places where importing external
files and so on that aren't self-contained, and fix a couple includes /
forward declarations.

Differential Revision: https://phabricator.services.mozilla.com/D256800
2025-08-05 11:47:34 +00:00
Jan-Niklas Jaeschke 8bc85faf7d Bug 1979474 - Text Fragments: Normalize range boundaries when extending to word boundaries in the punctuation-only case. r=dom-core,mccr8
Bug 1976480 introduced a special code path if the target range only consists of punctuation.
However, this new code path did not "normalize" the boundary points, ie. moving them to
the actual text node. Therefore, the target range could contain empty blocks
(such as an empty <td>), which would then trigger range-based matching.

This patch adds normalizing to the target range in case of punctuation-only ranges.

Differential Revision: https://phabricator.services.mozilla.com/D259037
2025-07-30 18:33:08 +00:00
Jan-Niklas Jaeschke 3b4ef62a78 Bug 1978976 - Text Fragments: Bail out if start or end terms end up being empty. r=dom-core,mccr8
Differential Revision: https://phabricator.services.mozilla.com/D258575
2025-07-24 13:49:45 +00:00
Jan-Niklas Jaeschke 0d26658d5d Bug 1978642 - Text Fragments: Use brace initialization when returning a result with a different type. r=avandolder
Differential Revision: https://phabricator.services.mozilla.com/D258263
2025-07-23 08:13:04 +00:00
Jan-Niklas Jaeschke 57ee7d95ea Bug 1976480 - Text Fragments: Don't extend the selection if only punctuation is selected. r=dom-core,avandolder,mccr8
This patch adds a new check in the beginning of the algorithm which leaves the
input range unchanged if its content is only punctuation characters.
This edge case is handled by checking if all characters are punctuation and would return early, hence not going into the algorithm that extends the range to word boundaries
(which would become more complex trying to achieve the same).

Additionally, this patch contains a minor refactoring: Other edge cases in the input range
(empty range, whitespace-only ranges) are moved into the function that extends the
range to word boundaries.

Differential Revision: https://phabricator.services.mozilla.com/D258246
2025-07-22 18:37:23 +00:00
Jan-Niklas Jaeschke 45a81587b0 Bug 1976869 - Text Fragments: Fixed edge cases when computing common string lengths. r=mccr8,dom-core
In some edge cases (eg. boundary point already at end of block), the algorithm would
return the length of the reference string as common substring length (instead of 0).

This is fixed by moving the actual common length computation part out of the loop
(which in some conditions may not run).

Differential Revision: https://phabricator.services.mozilla.com/D258057
2025-07-22 08:56:18 +00:00
Jan-Niklas Jaeschke fc03d86d41 Bug 1978235 - Text Fragments: Ensure that start and end terms are always non-empty. r=mccr8,dom-core
The patch for Bug 1976473 changed  the behavior of the algorithm to collect word boundary distances
to merge punctuation characters with the preceding word. However, this led to unexpected behavior if a
context term only consisted of punctuation, where this function would unexpectedly return an empty array.

This patch makes sure that the returned list of word boundary distances is always non-empty
by appending the total length of the context term, which simplifies the next steps of the algorithm.

This change required some adaptations to an early-return condition where an empty word boundary distance list
indicated an edge case where the target range is too long for exact matching,
but doesn't contain a word boundary (for which we refuse to continue).
This check is now moved into a previous stage of the algorithm, where it should have been in the first place.

Differential Revision: https://phabricator.services.mozilla.com/D257943
2025-07-21 23:11:17 +00:00
Jan-Niklas Jaeschke 2fe49849de Bug 1971670 - Text Fragments: Correctly deal with whitespace-only ranges. r=dom-core,avandolder
Differential Revision: https://phabricator.services.mozilla.com/D257502
2025-07-16 15:52:01 +00:00
Jan-Niklas Jaeschke 492e12887f Bug 1948242, part 3 - Text Fragments: Reuse nsFind. r=dom-core,avandolder
Constructing an `nsFind` instance involves running non-trivial code.
In rare edge cases this can accumulate and shows up in profiles.

Differential Revision: https://phabricator.services.mozilla.com/D256176
2025-07-11 12:41:37 +00:00
Jan-Niklas Jaeschke 887768952f Bug 1948242, part 1 - Text Fragments: Switch from maximum number of words to maximum context string length. r=dom-core,smaug
The previous approach limited the amount of words which are considered
for creating context terms.
This affects only the latter part of the algorithm (identifying the best candidate).
However, in rare edge cases finding the common strings can already be time-consuming.
Therefore, the cutoff metric has been changed to a maximum context term length,
with an empirically set value of 1024 chars per context term.

Differential Revision: https://phabricator.services.mozilla.com/D256174
2025-07-11 12:41:32 +00:00
Jan-Niklas Jaeschke 824b81b7ea Bug 1948256 - Text Fragments: Add another Timeout check. r=dom-core,smaug
Differential Revision: https://phabricator.services.mozilla.com/D256171
2025-07-11 12:41:29 +00:00
Lando 22f4edb25b Bug 1971043, 1972004: apply code formatting via Lando
# ignore-this-changeset
2025-07-02 14:50:02 +00:00
Jan-Niklas Jaeschke d9a9264399 Bug 1971043 - Text Fragments: Correctly deal with expandable end terms for range-based matching. r=dom-core,keithamus,mccr8
Before this patch, the end term for
range-based matching could have been
created wrongly, resulting in potentially
wrong or longer-than-necessary
text directives. This was due to a bad
handling of start and end term word distances,
which used a wrong offset.

This patch removes the first / last word of
the start / end terms before computing the
common substring lengths with other matches,
therefore setting the offsets to 0 instead of
`length of the first/last word`. Additionally,
whitespaces are taken into account correctly.

Differential Revision: https://phabricator.services.mozilla.com/D252964
2025-07-02 14:49:35 +00:00
Lando 6c0e4fd7c0 Bug 1970339: apply code formatting via Lando
# ignore-this-changeset
2025-07-02 09:37:26 +00:00
Jan-Niklas Jaeschke 23c41ebb1a Bug 1970339, part 2 - Text Fragments: Make timeout for creating text fragments global for all ranges. r=vhilla,mccr8
Before this patch, the 5 second timeout was applied
to each range individually. In some edge cases,
the number of ranges could be large. And even if
creating a text directive for a single range was
very fast, the accumulated time for all ranges
could exceed the 5 second limit.

This patch changes the watchdog to run
globally instead of per range, therefore
cutting off the whole process of creating
a text directive after 5 seconds.

It is not feasible to create a test case for
the timeout watchdog, hence there are
no changed tests.

Differential Revision: https://phabricator.services.mozilla.com/D252946
2025-07-02 09:37:05 +00:00
Jan-Niklas Jaeschke eda97e012f Bug 1974513 - Text Fragments: Use strong pointers to Document in helper classes. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D255506
2025-07-01 08:48:42 +00:00
agoloman c5055a75c8 Revert "Bug 1974513 - Text Fragments: Use strong pointers to Document in helper classes. r=mccr8" for causing build bustages @TextDirectiveCreator.cpp.
This reverts commit 6dc38deef8.
2025-06-30 18:12:04 +00:00
Jan-Niklas Jaeschke 6dc38deef8 Bug 1974513 - Text Fragments: Use strong pointers to Document in helper classes. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D255506
2025-06-30 16:15:31 +00:00
Jan-Niklas Jaeschke 0ed8038c58 Bug 1968839 - Text Fragments: Abort creating a text directive if the target range has no word breaks and is longer than the exact-match threshold. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D252038
2025-06-02 09:40:19 +00:00
Jan-Niklas Jaeschke 7f8a9d57a3 Bug 1968643 - Text Fragments: Use the statement-expression based MOZ_TRY. r=vhilla,farre
This is a pure refactoring commit, no functional changes are expected.

As a drive-by, this patch also renames
`TextDirectiveCreator::ExtendRangeToBlockBoundaries()`
to reflect what it actually does (which is extending to
_word_ boundaries).

Differential Revision: https://phabricator.services.mozilla.com/D251285
2025-05-28 15:10:49 +00:00
Jan-Niklas Jaeschke 34e04faf89 Bug 1968627 - Use const auto& for structured bindings with a tuple. r=vhilla
I don't think this has any effect in real life,
but if clangd is happy, so am I.

Differential Revision: https://phabricator.services.mozilla.com/D251244
2025-05-27 08:15:17 +00:00
Jan-Niklas Jaeschke 642c7d191b Bug 1957557 - fix compilation issue with non-Nightly builds 2025-05-26 10:05:13 +00:00
Jan-Niklas Jaeschke 9a8964ad80 Bug 1957557, part 9 - Create Text Fragments: Find the shortest valid text directive. r=dom-core,farre
This patch introduces an algorithm which compares
all potential candidates against all available matches.

A candidate is defined as a combination of word-bounded
distances in the context terms.
A match is defined as the common substring lengths
of all relevant context terms.
A valid candidate must exceed the match in at least
one dimension.

For exact matching, the only relevant context terms
are prefix and suffix.
For range-based matching, two runs are required:
The start match uses prefix and start.
The end match uses end and suffix.

Differential Revision: https://phabricator.services.mozilla.com/D246196
2025-05-26 08:21:16 +00:00
Jan-Niklas Jaeschke 501aee2675 Bug 1957557, part 8 - Create Text Fragments: Find all matches for the target range in the partial document. r=dom-core,farre
Search the partial document to find all
other matches for the content of the target range.
Then, for these matches, compute and save the
common lengths of the context terms.

For range-based matching, this needs to be done
separately for the start term and the end term.

Differential Revision: https://phabricator.services.mozilla.com/D246195
2025-05-26 08:21:12 +00:00
Jan-Niklas Jaeschke 7ff13ed265 Bug 1957557, part 7 - Create Text Fragments: Compute word boundary distances for context terms. r=dom-core,farre
The distances are always in search direction:
For prefix and end terms, the positions are
relative to the end of the term and use the word
start boundary.
For start and suffix, they are relative to its
beginning and use the word end boundary.

Differential Revision: https://phabricator.services.mozilla.com/D246194
2025-05-26 08:21:08 +00:00
Jan-Niklas Jaeschke 116b393b5f Bug 1957557, part 6 - Create Text Fragments: Collect context terms for exact and range-based matching. r=dom-core,farre
This patch converts all required context around the target range
into normal and fold case string representations.
Prefix and suffix terms can reach until the next block boundary.

For exact matching, the whole target range content is used for
the Start term, the End term is empty.

If there are block boundaries in the target range,
the start term defined by the sub range until the first
block boundary is reached, and the end term is defined
by the sub range starting at the last block boundary.

If the range is longer than the threshold,
its content is split in the middle.

Differential Revision: https://phabricator.services.mozilla.com/D246193
2025-05-26 08:21:04 +00:00
Jan-Niklas Jaeschke b5a95103a8 Bug 1957557, part 5 - Create Text Fragments: Determine whether to use exact or range-based matching. r=dom-core,farre
Range-based matching has to be used if
 - there is a block boundary in the target range
 - the range content is too long.

This commit introduces sub classes for the
`TextDirectiveCreator` class, which are implemented
to correctly create exact and range-based matching
text directives in the following patches.

Differential Revision: https://phabricator.services.mozilla.com/D246192
2025-05-26 08:21:00 +00:00
Jan-Niklas Jaeschke 96d27ca716 Bug 1957557, part 2 - Create Text Fragments: Remove old implementation. r=dom-core,farre
Differential Revision: https://phabricator.services.mozilla.com/D246189
2025-05-26 08:20:49 +00:00
Roland Kossel f714f6fa67 Bug 1942117 - Part 2: gather metrics for text fragments, r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D237494
2025-03-23 12:31:26 +00:00
Jan-Niklas Jaeschke 45f9ee16cb Bug 1951362 - Text Fragments: Correctly consider prefixes for range-based matching. r=dom-core,farre
For range-based matching, the previous matches were determined incorrectly:
The `start` match must be matched until the end of the `start` of the target range,
and the `end` match must be matched until the end of the `end` of the target rage.

Before this change, the `start` of the target range was always considered as a
match to eliminate, therefore producing wrong results.

Differential Revision: https://phabricator.services.mozilla.com/D240131
2025-03-11 15:37:44 +00:00
Jan-Niklas Jaeschke 1d7f9dbb76 Bug 1950672 - Text Fragments: Improve timeout watchdog for creating text fragments. r=dom-core,farre
The inner loop can in some edge cases be expensive,
therefore the timeout should be checked there.

Differential Revision: https://phabricator.services.mozilla.com/D239763
2025-02-27 09:25:41 +00:00
Jan-Niklas Jaeschke 174e8375e2 Bug 1942080, part 5.2 - Text Fragments: Compare common substrings in parallel using rayon. r=emilio
Filtering non-matching candidates is the biggest
perf bottleneck in the algorithm to  create a
text fragment, especially if the user attempts to
create a text fragment for a very common string
on a very large page.

Since the expensive code only does string comparisons,
it can easily be moved to rust and run in parallel
using rayon.

Differential Revision: https://phabricator.services.mozilla.com/D235559
2025-02-22 19:46:44 +00:00
Jan-Niklas Jaeschke ba6d22044c Bug 1942080, part 5.1 - Text Fragments: Group string representations into a rust struct. r=farre,dom-core
This is a prerequisite commit, which moves the `nsString*` members of the
`TextDirectiveCandidate` C++ class into a bindgen-exposed Rust struct.

Differential Revision: https://phabricator.services.mozilla.com/D235558
2025-02-22 19:46:44 +00:00
Jan-Niklas Jaeschke 5a3143f2ec Bug 1942080, part 4 - Text Fragments: Use NodeIndexCache to further speed up nsContentUtils::ComparePoints(). r=farre,dom-core
`nsContentUtils::ComparePoints()` already has a cache which
keeps the last 100 indices in a stack-allocated array.

This patch makes use of this cache in the hot path.

Differential Revision: https://phabricator.services.mozilla.com/D235557
2025-02-22 19:46:44 +00:00
Jan-Niklas Jaeschke 5e62bf97e7 Bug 1942080, part 2 - Text Fragments: Reduce calls to nsRange::SetStart(). r=farre,dom-core
The algorithm to collect all occurrences of the
search string used to resize its search range after each match.
`nsRange::SetStart()` is an expensive call,
because it calls `nsContentUtils::ComparePoints()`.

However, `nsFind` uses the collapsed `nsRange`s
`aStartPoint` and `aEndPoint` to determine the search range.
Therefore, the code can be updated to accept range boundaries
instead, and to create the collapsed ranges locally.

Differential Revision: https://phabricator.services.mozilla.com/D235555
2025-02-22 19:46:43 +00:00
Jan-Niklas Jaeschke 123d82bf4d Bug 1942080, part 1 - Text Fragments: Implement string cache which reduces the amount of hash table lookups in TextDirectiveCreator. r=farre
Profiling has shown that for extreme cases
hash table lookups of the `RangeContentCache`
implementation could take a considerable amount of time.
Additionally, the design of returning a pair of strings
for a pair of ranges was awkward and rather unintuitive.

This patch reorganizes the cache.
The cache now contains the fold case representations as
`UniquePtr<nsString>` and returns constant raw pointers,
which are kept alive by the cache lifetime.
This allows to implement a much more intuitive
`GetOrInsert()` method, which accepts one `nsRange*`,
and returns one `const nsString*`.

Additionally, the `TextDirectiveCandidate` objects now
keep these raw pointers as members.
This way the hash table lookups are only required when
a new object is created that contains changed ranges.
Otherwise, the strings can be accessed directly.

These measures eliminate the hash table lookups
from the performance profiles entirely.

Differential Revision: https://phabricator.services.mozilla.com/D235382
2025-02-22 19:46:42 +00:00
Jan-Niklas Jaeschke 8b14fdb915 Bug 1942121, part 2 - Text Fragment: Use Watchdog to early-exit the create text fragment algorithm. r=dom-core,sefeng
This patch introduces the `TimeoutWatchdog` helper class
and checks at certain points in the algorithm
whether the timeout is hit, and aborts the
algorithm if necessary.

Differential Revision: https://phabricator.services.mozilla.com/D235539
2025-02-04 14:59:06 +00:00