Commit graph

331 commits

Author SHA1 Message Date
Jan-Niklas Jaeschke
10cdb4892f Bug 1894666 - Custom Highlight API: Call NotifySelectionListener() for the correct selection type. r=masayuki,dom-core
Before this patch, the `AutoFrameSelectionBatcher` helper class would always call `NotifySelectionListeners()` for `SelectionType::eNormal`, even if the selection may have originated from Custom Highlight.

This patch moves the information that a change has occurred during batching from `nsFrameSelection` into the `Selection` instance, thus keeping the information per instance instead of globally.
When batching ends, `Selection::NotifySelectionListeners()` is called for all `Selection` instances depending on the flag.

Additionally, `Selection::NotifySelectionListeners()` is updated so that some Listeners (AutoCopyListener, SelectionChangeEvent, AccessibleCaret) are only notified for `SelectionType::eNormal`.

Differential Revision: https://phabricator.services.mozilla.com/D210130
2024-05-15 12:35:39 +00:00
Emilio Cobos Álvarez
f6f9f50178 Bug 1896051 - Notify selection listeners from TakeFocus even if batching. r=masayuki
Otherwise we don't note the selection change, and listeners like the
caret might remain in the wrong position.

NotifySelectionListeners deals itself with batching:

  https://searchfox.org/mozilla-central/rev/8e885f04a0a4ff6d64ea59741c10d9b8e45d9ff8/dom/base/Selection.cpp#3752-3754

This is ancient code from the netscape era:

  0e36c2f407
  24e9fbcab6

So my hope is that tests pass with this, otherwise there are lower risk
fixes that we could make like just calling
SetChangesDuringBatchingFlag(), but that seems sketchy at best.

So let's try to do the right thing...

Differential Revision: https://phabricator.services.mozilla.com/D210050
2024-05-14 07:46:41 +00:00
Jan-Niklas Jaeschke
81f5e14057 Bug 1867939, part 4: Implemented the ::target-text CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.

Differential Revision: https://phabricator.services.mozilla.com/D195687
2024-04-04 14:39:32 +00:00
Stanca Serban
c9bea63c35 Backed out 6 changesets (bug 1867939) for causing wpt failures in target-text-010.html. CLOSED TREE
Backed out changeset 44101c258e52 (bug 1867939)
Backed out changeset c53267e1b460 (bug 1867939)
Backed out changeset 0748839408e5 (bug 1867939)
Backed out changeset 38631fbd2f2f (bug 1867939)
Backed out changeset d77b9257c842 (bug 1867939)
Backed out changeset 0d269b891421 (bug 1867939)
2024-04-04 00:50:50 +03:00
Jan-Niklas Jaeschke
e58875610d Bug 1867939, part 4: Implemented the ::target-text CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.

Differential Revision: https://phabricator.services.mozilla.com/D195687
2024-04-03 15:23:02 +00:00
Sandor Molnar
8340afd1fb Backed out 6 changesets (bug 1867939) for causing a top crash in nightly Bug 1889393 CLOSED TREE
Backed out changeset 2110f57e928c (bug 1867939)
Backed out changeset 51890598ecb4 (bug 1867939)
Backed out changeset 839bc1b11a2c (bug 1867939)
Backed out changeset bb88c4d09e82 (bug 1867939)
Backed out changeset 27c76e65cf58 (bug 1867939)
Backed out changeset c3e3c81f9ceb (bug 1867939)
2024-04-03 17:31:56 +03:00
Jan-Niklas Jaeschke
2ec51d7c56 Bug 1867939, part 4: Implemented the ::target-text CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.

Differential Revision: https://phabricator.services.mozilla.com/D195687
2024-04-02 13:44:25 +00:00
Cristian Tuns
a1bb69acae Backed out 6 changesets (bug 1867939) for causing build bustages in Document.h CLOSED TREE
Backed out changeset 0853f9a7a06c (bug 1867939)
Backed out changeset 2279e6577c13 (bug 1867939)
Backed out changeset 1b3af4b6a27b (bug 1867939)
Backed out changeset 2fbe643ca483 (bug 1867939)
Backed out changeset 575873406614 (bug 1867939)
Backed out changeset 82f99c0210b0 (bug 1867939)
2024-04-02 09:15:46 -04:00
Jan-Niklas Jaeschke
b764eaf1f8 Bug 1867939, part 4: Implemented the ::target-text CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe
This patch implements the `::target-text` pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.

Differential Revision: https://phabricator.services.mozilla.com/D195687
2024-04-02 11:43:21 +00:00
Sean Feng
2026f2e0ce Bug 1867058 - Part 8: Update Selection to support across shadow dom selection r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D195310
2024-03-25 13:40:59 +00:00
Sean Feng
76908bb481 Bug 1867058 - Part 1: Implement Selection.direction r=jjaschke,dom-core
This patch implements the .direction attribute

Spec: https://www.w3.org/TR/selection-api/#dom-selection-direction

Differential Revision: https://phabricator.services.mozilla.com/D195301
2024-03-25 13:40:56 +00:00
pstanciu
715a8e1d09 Backed out 12 changesets (bug 1867058) for causing bustages on AbstractRange.cpp
Backed out changeset 6254c9c51033 (bug 1867058)
Backed out changeset 2ad556d56736 (bug 1867058)
Backed out changeset a8bc41291ab3 (bug 1867058)
Backed out changeset c30869c03a70 (bug 1867058)
Backed out changeset 39c5816dff6b (bug 1867058)
Backed out changeset 42e226158dc9 (bug 1867058)
Backed out changeset 67bb7158a09f (bug 1867058)
Backed out changeset 7b5a689dc7fd (bug 1867058)
Backed out changeset 3cf108eb13a6 (bug 1867058)
Backed out changeset 8efda4cce80c (bug 1867058)
Backed out changeset 0837e15babab (bug 1867058)
Backed out changeset 8ce7972ea4df (bug 1867058)
2024-03-23 02:24:26 +02:00
Sean Feng
05056421c1 Bug 1867058 - Part 8: Update Selection to support across shadow dom selection r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D195310
2024-03-22 17:05:51 +00:00
Sean Feng
dd9904e006 Bug 1867058 - Part 1: Implement Selection.direction r=jjaschke,dom-core
This patch implements the .direction attribute

Spec: https://www.w3.org/TR/selection-api/#dom-selection-direction

Differential Revision: https://phabricator.services.mozilla.com/D195301
2024-03-22 17:05:48 +00:00
Gregory Pappas
3ea20569e6 Bug 1881845 - Remove nsContentCID.h r=smaug,media-playback-reviewers,karlt
All of these components have been converted to static registration, making this
file unneeded.

Differential Revision: https://phabricator.services.mozilla.com/D202633
2024-03-04 23:41:05 +00:00
Gregory Pappas
153106ad94 Bug 1881188 - Remove nsLayoutCID.h r=emilio
All of this stuff has been converted to static registration, making this file
unneeded.

Differential Revision: https://phabricator.services.mozilla.com/D202291
2024-02-21 13:04:30 +00:00
Masayuki Nakano
cd53d5600e Bug 1816581 - part 6: Move the static methods used for moving caret or considering caret geometry into new utility class r=emilio
The methods are in `nsCaret`, `nsFrameSelection` and `dom::Selection`.  That
makes harder to read, and they are called each other, so, they are reused for
different purpose.  Therefore, it must be better to move them into a new class.
Then, the name differences may become more unclear.  If you think so, feel free
to request renaming some methods of them.

Differential Revision: https://phabricator.services.mozilla.com/D197288
2023-12-27 04:42:12 +00:00
Masayuki Nakano
20faadc9da Bug 1816581 - part 5: Make nsFrameSelection::PeekOffsetForCaretMove implement without members r=emilio
A caller of it should be independent from `nsFrameSelection` instance.
Therefore, I'd like to separate it to static method part and instance method
part.

Differential Revision: https://phabricator.services.mozilla.com/D197287
2023-12-27 04:42:11 +00:00
Masayuki Nakano
bc8a395afe Bug 1816581 - part 4: Make Selection::GetPrimaryFrameForFocusNode stop updating the caret association hint of nsFrameSelection r=emilio
Its name sounds a getter, but it updates the caret association hint of
`nsFrameSelection`, but at least, one of its callers,
`nsFrameSelection::PeekOffsetForCaretMove` shouldn't update it because it
just scans the previous or next position for caret.

Then, `Selection::GetPrimaryFrameForFocusNode` can be implemented with a
new static method which is useful for `PeekOffsetForCaretMove` when it becomes
a static method.

Differential Revision: https://phabricator.services.mozilla.com/D197286
2023-12-27 04:42:11 +00:00
Masayuki Nakano
ac6767faae Bug 1816581 - part 2: Make nsCaret::GetCaretFrameForNodeOffset static r=emilio
Oddly, it updates `nsFrameSelection` instance and some root callers may depend
on that. Therefore, this patch keep updating `nsFrameSelection` in the callers.

Differential Revision: https://phabricator.services.mozilla.com/D197284
2023-12-27 04:42:10 +00:00
Masayuki Nakano
fe9fef936b Bug 1816581 - part 1: Make CaretAssociationHint an enum class r=emilio
For forward-decl-able.

Differential Revision: https://phabricator.services.mozilla.com/D197283
2023-12-27 04:42:09 +00:00
Masayuki Nakano
a558378375 Bug 779684 - part 3: Make nsFrameIterator non-refcountable r=emilio
Nobody shares an instance of `nsFrameIterator`.  Therefore, we can make it
non-refcountable.  Additionally, `nsVisualIterator` is not required because
it overrides only 4 methods which are really simple.  So, once we merge it
into `nsFrameIterator`, we can allocate it in the stack.

Differential Revision: https://phabricator.services.mozilla.com/D197144
2023-12-24 06:01:19 +00:00
Masayuki Nakano
76826c766a Bug 779684 - part 2: Get rid of nsFrameTraversal and nsIFrameTraversal r=emilio
The class is used only for creating `nsFrameIterator`, but it's unnecessary
so that we can get rid of it and its interface.

Differential Revision: https://phabricator.services.mozilla.com/D197143
2023-12-24 06:01:19 +00:00
Masayuki Nakano
32c9d4f8e7 Bug 779684 - part 1: Get rid of nsIFrameEnumerator interface r=emilio
It's inherited only by `nsFrameIterator`, and `nsFrameIterator` can be declared
in a header file. So, the interface is not required and removing it can avoid
virtual calls.

Differential Revision: https://phabricator.services.mozilla.com/D197142
2023-12-24 06:01:19 +00:00
Stanca Serban
e07cea7e9d Backed out 3 changesets (bug 779684) for causing nsFrameIterator related mochitests failures.
Backed out changeset 8b92fb4e3f41 (bug 779684)
Backed out changeset f357b2287591 (bug 779684)
Backed out changeset 738fe6bbf913 (bug 779684)
2023-12-23 10:32:48 +02:00
Masayuki Nakano
5518ab835e Bug 779684 - part 3: Make nsFrameIterator non-refcountable r=emilio
Nobody shares an instance of `nsFrameIterator`.  Therefore, we can make it
non-refcountable.  Additionally, `nsVisualIterator` is not required because
it overrides only 4 methods which are really simple.  So, once we merge it
into `nsFrameIterator`, we can allocate it in the stack.

Differential Revision: https://phabricator.services.mozilla.com/D197144
2023-12-23 05:39:39 +00:00
Masayuki Nakano
c889543d50 Bug 779684 - part 2: Get rid of nsFrameTraversal and nsIFrameTraversal r=emilio
The class is used only for creating `nsFrameIterator`, but it's unnecessary
so that we can get rid of it and its interface.

Differential Revision: https://phabricator.services.mozilla.com/D197143
2023-12-23 05:39:38 +00:00
Masayuki Nakano
d04f4666eb Bug 779684 - part 1: Get rid of nsIFrameEnumerator interface r=emilio
It's inherited only by `nsFrameIterator`, and `nsFrameIterator` can be declared
in a header file. So, the interface is not required and removing it can avoid
virtual calls.

Differential Revision: https://phabricator.services.mozilla.com/D197142
2023-12-23 05:39:38 +00:00
Masayuki Nakano
02ee2a0c6f Bug 1820290 - Rename PeekOffsetOption::ScrollViewStop for consistency r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D193622
2023-11-21 08:05:19 +00:00
Masayuki Nakano
3e86e21ebe Bug 1855345 - Make AutoCopyListener ignore any selection changes caused by Selection API r=karlt,smaug
Even though there is a reasonable usabe like bug 1567160, we should
ensure that `AutoCopyListener` never update clipboard when the selection
change is caused by a Selection API call.

Differential Revision: https://phabricator.services.mozilla.com/D191585
2023-10-26 04:05:02 +00:00
Sylvestre Ledru
d0f6c7fc66 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-15 15:29:02 +00:00
Cristina Horotan
6a90f5eded Backed out 2 changesets (bug 1856795) for causing build bustage at BasicEvents.h CLOSED TREE
Backed out changeset 1d98b028923a (bug 1856795)
Backed out changeset eae2ac93e17c (bug 1856795)
2023-10-14 21:42:14 +03:00
Sylvestre Ledru
cc8a0ee742 Bug 1856795 - Remove redundant member init r=emilio
Done with:
./mach static-analysis check --checks="-*, readability-redundant-member-init" --fix .

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-member-init.html

Differential Revision: https://phabricator.services.mozilla.com/D190002
2023-10-14 17:34:26 +00:00
Jan-Niklas Jaeschke
12f5099c54 Bug 1838262, part 3: Removed ServoStyleSet::ProbeHighlightPseudoElementStyle(). r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D184709
2023-07-31 13:47:55 +00:00
Jan-Niklas Jaeschke
a4a9d51c57 Bug 1811823, part 1: Added HighlightSelectionData struct. r=emilio
The idea of this struct is to allow live data of a highlight selection to be passed into layout.
Layout needs highlight properties such as priority or type to resolve combinations of highlights correctly.

Differential Revision: https://phabricator.services.mozilla.com/D181142
2023-06-23 15:22:43 +00:00
Jan-Niklas Jaeschke
1817114384 Bug 1836013: Order highlight selections by insertion order. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D174480
2023-05-31 10:07:51 +00:00
Kagami Sascha Rosylight
89172dc9c2 Bug 1831065 - Part 2: Remove unused ErrorResult parameters in highlight and selection r=webidl,smaug
Differential Revision: https://phabricator.services.mozilla.com/D177008
2023-05-03 13:24:53 +00:00
Masayuki Nakano
5b59e4aeae Bug 1384606 - part 4: Make nsIFrame::GetFrameFromDirection allow to return content in different native anonymous subtree if the caller wants r=emilio
The a11y module wants to traverse frames in native anonymous subtrees.
Therefore, this patch adds new option for allowing it, makes
`nsIFrame::GetFrameFromDirection` check it before comparing native anonymous
subtree root nodes, and makes `HyperTextAccessible::FindOffset` use the
option.

Differential Revision: https://phabricator.services.mozilla.com/D172759
2023-03-18 04:18:53 +00:00
Masayuki Nakano
01d2fe15e1 Bug 1384606 - part 3: Make nsPeekOffsetStruct and its handlers treat bool options with an EnumSet r=emilio
The constructor of `nsPeekOffsetStruct` and `nsIFrame::GetFrameFromDirection`
take too many `bool` arguments.  Therefore, adding new `bool` arguments does
not make sense.  Now, we have a useful `mozilla:EnumSet` class to treat them
with an `enum class`. Therefore, let's change `nsPeekOffsetStruct` with it.

Differential Revision: https://phabricator.services.mozilla.com/D172758
2023-03-18 04:18:53 +00:00
Iulian Moraru
6f60d5fa4d Backed out 4 changesets (bug 1384606) for causing mochitest browser a11y failures on browser_text_basics.js. CLOSED TREE
Backed out changeset 6f7176c0d6a3 (bug 1384606)
Backed out changeset 19c51e735059 (bug 1384606)
Backed out changeset eb8a5705b2d3 (bug 1384606)
Backed out changeset 39b202962261 (bug 1384606)
2023-03-17 10:40:53 +02:00
Masayuki Nakano
25e942f2a0 Bug 1384606 - part 4: Make nsIFrame::GetFrameFromDirection allow to return content in different native anonymous subtree if the caller wants r=emilio
The a11y module wants to traverse frames in native anonymous subtrees.
Therefore, this patch adds new option for allowing it, makes
`nsIFrame::GetFrameFromDirection` check it before comparing native anonymous
subtree root nodes, and makes `HyperTextAccessible::FindOffset` use the
option.

Differential Revision: https://phabricator.services.mozilla.com/D172759
2023-03-17 06:26:03 +00:00
Masayuki Nakano
9cf5036656 Bug 1384606 - part 3: Make nsPeekOffsetStruct and its handlers treat bool options with an EnumSet r=emilio
The constructor of `nsPeekOffsetStruct` and `nsIFrame::GetFrameFromDirection`
take too many `bool` arguments.  Therefore, adding new `bool` arguments does
not make sense.  Now, we have a useful `mozilla:EnumSet` class to treat them
with an `enum class`. Therefore, let's change `nsPeekOffsetStruct` with it.

Differential Revision: https://phabricator.services.mozilla.com/D172758
2023-03-17 06:26:03 +00:00
Noemi Erli
585fe519f1 Backed out 4 changesets (bug 1384606) for causing build bustage in nsFrameSelection.h CLOSED TREE
Backed out changeset 917f487fdf0f (bug 1384606)
Backed out changeset 0782f42b2a99 (bug 1384606)
Backed out changeset 22099c5efaf6 (bug 1384606)
Backed out changeset f3a38b1eac88 (bug 1384606)
2023-03-17 06:54:59 +02:00
Masayuki Nakano
c2b9c4058b Bug 1384606 - part 4: Make nsIFrame::GetFrameFromDirection allow to return content in different native anonymous subtree if the caller wants r=emilio
The a11y module wants to traverse frames in native anonymous subtrees.
Therefore, this patch adds new option for allowing it, makes
`nsIFrame::GetFrameFromDirection` check it before comparing native anonymous
subtree root nodes, and makes `HyperTextAccessible::FindOffset` use the
option.

Depends on D172758

Differential Revision: https://phabricator.services.mozilla.com/D172759
2023-03-17 04:22:05 +00:00
Masayuki Nakano
1387f2e7bc Bug 1384606 - part 3: Make nsPeekOffsetStruct and its handlers treat bool options with an EnumSet r=emilio
The constructor of `nsPeekOffsetStruct` and `nsIFrame::GetFrameFromDirection`
take too many `bool` arguments.  Therefore, adding new `bool` arguments does
not make sense.  Now, we have a useful `mozilla:EnumSet` class to treat them
with an `enum class`. Therefore, let's change `nsPeekOffsetStruct` with it.

Differential Revision: https://phabricator.services.mozilla.com/D172758
2023-03-17 04:22:05 +00:00
Masayuki Nakano
50bfccb021 Bug 1820445 - Clean up Selection::SelectFrames r=jjaschke
It's little bit messy, we can make it cleaner with using
`nsIContent::FromNode` and it do null-checks safer.

Differential Revision: https://phabricator.services.mozilla.com/D171668
2023-03-06 22:34:58 +00:00
Jan-Niklas Jaeschke
ebf3cd6240 Bug 1808565, part 1: Adapt Selection to support StaticRanges. r=webidl,saschanaz,masayuki,smaug
This change is necessary to support the [CSS Highlight API](https://drafts.csswg.org/css-highlight-api-1/),
which uses `Selection` internally.

To replace `nsRange` with `AbstractRange`, some sections needed to be
adapted since `nsRange`-specific features were used.
Therefore, some methods (such as `GetRangeAt()`) may only be called if
the `Selection` is *not* of type `SelectionType::eHighlight`,
as it (per spec) returns an `nsRange`.
These methods will now `MOZ_ASSERT` if called for a highlight selection.
Additional methods are implemented which return `AbstractRange`
instead and are safe to be called for every selection type.

This commit also improves support of highlight features:
- Invalidation of highlight ranges: adding/removing Ranges in-place instead of
  removing and re-adding the Selection object associated with the highlight.
- Ranges are only associated with the Selection that shares the same Document
- Fixed minor IDL issue

Differential Revision: https://phabricator.services.mozilla.com/D170582
2023-03-03 14:59:47 +00:00
Jan-Niklas Jaeschke
2243494a74 Bug 1810403: Allow nsRanges to be in multiple Selections. r=masayuki
The Custom Highlight API allows a use case where a `Range` of a `Highlight`
is also used as `Selection`. Due to the decision to use the `Selection` mechanism
to display `Highlight`s, a `Range` can be part of several `Selection`s.
Since the `Range` has a pointer to its associated `Selection`
to notify about changes, this must be adapted to allow several `Selections`.

As a tradeoff of performance and memory usage, the `Selection`s are stored
as `mozilla::LinkedList`. A helper class `mozilla::SelectionListWrapper`
was implemented to allow `Selection`s to be in multiple of these lists
and without having to be derived from `LinkedListElement<T>`.

To simplify usage of the list, the use case  "does this range belong to Selection x?"
is wrapped into the convenience method`IsInSelection(Selection&)`;
The method previously named like this was renamed to `IsInAnySelection()`
to be named more precisely.

Registering and unregistering of the closest common inclusive ancestor
of the `Range` is done when the first `Selection` is registered and
the last `Selection` is unregistered.

Differential Revision: https://phabricator.services.mozilla.com/D169597
2023-02-21 12:25:28 +00:00
Jan-Niklas Jaeschke
fa75d3a60f Bug 1803355: Basic implementation of Custom Highlight API. r=edgar,emilio
Added WebIDL interfaces as per spec, added some necessary changes to support maplike and setlike structures to be accessed from C++.

Added `::highlight(foo)` pseudo element to CSS engine.

Implemented Highlight as new kind of `Selection` using `HighlightType::eHighlight`. This implies Selections being added/removed during runtime (one `Selection` object per highlight identifier), therefore a dynamic container for highlight `Selection` objects was added to `nsFrameSelection`. Also, the painting code queries the highlight style for highlight Selections.

Implementation is currently hidden behind a pref `dom.customHighlightAPI.enabled`.

Differential Revision: https://phabricator.services.mozilla.com/D164203
2023-01-27 11:42:18 +00:00
Sandor Molnar
4c4d29b581 Backed out changeset d7f27aa40260 (bug 1803355) for causing win build bustage. 2023-01-24 18:07:50 +02:00