Commit graph

388 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
e7f43ecf6f Bug 1860328 - Track nsCaret position at the DOM level. r=sefeng,masayuki
This should avoid a bunch of paint invalidation issues with our caret
code (and seems simpler anyways).

Differential Revision: https://phabricator.services.mozilla.com/D204434
2024-03-18 09:12:57 +00:00
Jan-Niklas Jaeschke
aaf5f671f0 Bug 1881695: Implemented a new Cache to store the index of a node in a parent. r=smaug
This new cache implementation keeps the last N node/index combos in a stack-allocated array, which will be queried before calling nsINode::ComputeIndexOf().

Differential Revision: https://phabricator.services.mozilla.com/D203900
2024-03-11 19:02:11 +00:00
Natalia Csoregi
c2e4efaac4 Backed out changeset 37af5c6d011a (bug 1881695) for causing Bug 1884602 and Bug 1884601. CLOSED TREE 2024-03-11 10:47:07 +02:00
Jan-Niklas Jaeschke
aa9f0ab239 Bug 1881695: Implemented a new Cache to store the index of a node in a parent. r=smaug
This new cache implementation keeps the last N node/index combos in a stack-allocated array, which will be queried before calling nsINode::ComputeIndexOf().

Differential Revision: https://phabricator.services.mozilla.com/D203900
2024-03-09 11:13:55 +00:00
Cristina Horotan
b7aa7557e1 Backed out changeset e72815765675 (bug 1881695) for causing Hazard failure at nsContentUtils.h 2024-03-07 23:47:13 +02:00
Jan-Niklas Jaeschke
41b0de8fcd Bug 1881695: Implemented a new Cache to store the index of a node in a parent. r=smaug
This new cache implementation keeps the last N node/index combos in a stack-allocated array, which will be queried before calling nsINode::ComputeIndexOf().

Differential Revision: https://phabricator.services.mozilla.com/D203900
2024-03-07 16:57:16 +00:00
Narcis Beleuzu
314ea3bd7d Backed out changeset cc11e54ef4b1 (bug 1881695) for bustages on nsContentUtils.h 2024-03-07 18:01:44 +02:00
Jan-Niklas Jaeschke
861a450bea Bug 1881695: Implemented a new Cache to store the index of a node in a parent. r=smaug
This new cache implementation keeps the last N node/index combos in a stack-allocated array, which will be queried before calling nsINode::ComputeIndexOf().

Differential Revision: https://phabricator.services.mozilla.com/D203900
2024-03-07 15:14:06 +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
Masayuki Nakano
657bc8f9d5 Bug 1878191 - Fix 2 iterating loops of selection ranges r=smaug,Jamie
These loops may run script.

In  `HyperTextAccessible`, it calls
`RemoveRangeAndUnselectFramesAndNotifyListeners`. So, chrome script which is not
directly related to this module may run in each call.  I think that using
`RemoveAllRanges` is better for here.  Before bug 1735446, this loop tried
to keep first range, but accidentally, I changed this loop delete all ranges.
However, `SetSelectionBoundsAt` will add a range if it's required and there is
no bug reports.  Therefore, I think keep the new behavior is better.

In `nsRange::DeleteFromDocument`, the loop may run mutation events too.
Therefore, it needs to store all ranges first.  Then, the preceding patch
changes the behavior here if a selection range is moved to different root.
Previously, it was deleted, but now, they are not touched.

Depends on D200606

Differential Revision: https://phabricator.services.mozilla.com/D200607
2024-02-07 04:34:38 +00:00
Peter Van der Beken
e6a1561035 Bug 1878631 - Remove some unused selection code. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D200620
2024-02-06 09:31:43 +00:00
Jan-Niklas Jaeschke
0157568420 Bug 1878504: Don't trigger range reordering when a range is added. r=smaug
Ranges stored in Selection::StyledRanges are expected to be sorted by their start point.
In Bug 1872535 a range reordering was introduced which makes sure that static ranges are at the right spot after a DOM mutation has happened.
Reordering is necessary in two conditions:
- The document generation has changed (=There are changes to the DOM tree)
- A selection has changed (which would call NotfySelectionListeners())
However, when a range is added, it is not necessary to reorder, since the AddRange...() method inserts the new range at the correct spot (and reorders beforehand if necessary).

Differential Revision: https://phabricator.services.mozilla.com/D200592
2024-02-05 08:28:00 +00:00
Jan-Niklas Jaeschke
f9f5a3ed69 Bug 1872535: Deal with invalid StaticRanges and DOM mutations in Selection. r=smaug
Ranges inside of a `Selection` are expected to be sorted by their start point by the painting algorithms. Also, `StaticRange`s, which previously were not part of `Selection`, need to be considered for painting based on their `IsValid()` status.

This is now added by introducing a second array for invalid static ranges and an additional re-ordering method which needs to be called before paint that moves ranges in between.
 A potential change in range endpoints can be determined by observing the `Document`s generation and by adding a flag that's set to true in `Selection::NotifySelectionObservers()`.

Differential Revision: https://phabricator.services.mozilla.com/D198943
2024-01-23 13:27:41 +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
ac0ec484c7 Bug 1816581 - part 3: Make Selection::GetPrimaryOrCaretFrameForNodeOffset static r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D197285
2023-12-27 04:42:10 +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
87da8e59cd Bug 1612076 - Make AdjustCaretFrameForLineEnd stop scanning text node if first node is editable but reached non-editable one r=emilio
When pressing `ArrowLeft` key at:
```
<p>abc</p><p><span contenteditable=false>def</span>{}<br></p>
```
, caret is moved into the non-editable text because
`nsCaret::GetCaretFrameForNodeOffset` looks for a preceding text node from
the `BRFrame`. This is required if the preceding text node ends with a
collapsible white-space but followed by a `<br>` because the text frame
should not contain the white-space rect and `BRFrame` frame should be next
to it, i.e., the white-space looks like a overflown content.

So, for rendering a caret, the method needs to return non-editable text frame
even in the case, but for considering new caret position in the DOM tree, it
should not return non-editable text frame.

Therefore, this patch adds a param to `nsCaret::GetCaretFrameForNodeOffset()`
which forcibly return editable content frame or not and makes
`Selection::GetPrimaryOrCaretFrameForNodeOffset` call it with the new option
because its callers are the handler of caret navigation.

Differential Revision: https://phabricator.services.mozilla.com/D196259
2023-12-19 01:58:07 +00:00
Emilio Cobos Álvarez
25c0d10932 Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.

I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).

Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 08:51:12 +00:00
Jan Varga
c458754592 Bug 1855134 - Move existing MOZ_TRY macros to a dedicated header file; r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D189226
2023-09-28 20:46:07 +00:00
Olli Pettay
b632508d71 Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-26 12:36:20 +00:00
Cosmin Sabou
baf8a5cf23 Backed out 6 changesets (bug 1843477) for causing hazards failures. CLOSED TREE
Backed out changeset 64b093aa12a9 (bug 1843477)
Backed out changeset bdcd84c938d1 (bug 1843477)
Backed out changeset 05c882dd0d9a (bug 1843477)
Backed out changeset 1de814e5820d (bug 1843477)
Backed out changeset 6a0e19a60a5d (bug 1843477)
Backed out changeset 48942aff586f (bug 1843477)
2023-09-26 05:32:28 +03:00
Olli Pettay
ce2ffc54c9 Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-25 21:09:00 +00:00
Cosmin Sabou
2b53f8d322 Backed out 3 changesets (bug 1843477) for causing hazards failures on TelemetryFixture.cpp. CLOSED TREE
Backed out changeset 4dd5d8ac600c (bug 1843477)
Backed out changeset e7bc0b63286a (bug 1843477)
Backed out changeset 4f45f40beaf7 (bug 1843477)
2023-09-08 20:21:46 +03:00
Olli Pettay
d7c56b8b4f Bug 1843477, remove main thread only CC macros, r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D187146
2023-09-08 14:51:48 +00:00
Daniel Holbert
86e0c0cc41 Bug 1802466 part 2: Change GetSelectionEndPointGeometry to handle vertical-writing-mode text nodes. r=emilio
This function had some code that we hadn't yet updated to support vertical
writing modes.  This patch makes it more generic so that it can properly handle
vertical-writing-mode text nodes (so that we can e.g. properly keep the caret
scrolled into view, in a vertical-writing-mode textfield).

I'm just focusing on vertical vs. horizontal generification for now.  I'm not
entirely sure if it makes sense to make it even-more-generic-still to support
reversed-inline-direction writing modes as well. I wasn't able to trigger any
issues with those in some brief testing, so I think this patch is sufficient
as-is, but I left a TODO(dholbert) code-comment to call out that ambiguity
that's still present in the code.

Differential Revision: https://phabricator.services.mozilla.com/D187160
2023-09-07 08:22:27 +00:00
Daniel Holbert
677d053e78 Bug 1802466 part 1: Refactor computation of outparam rect in GetSelectionEndPointGeometry. r=emilio
This patch doesn't change behavior. It's just laying the groundwork for the
next patch which adds vertical-writing-mode support.

(This patch adds some documentation in terms of logical axes, though, which
will become accurate as of the next patch in this series.)

Differential Revision: https://phabricator.services.mozilla.com/D187161
2023-09-07 08:22:26 +00:00
Narcis Beleuzu
8af2b78975 Backed out 3 changesets (bug 1802466) for mochitest failure on test_composition_text_querycontent.xhtml . CLOSED TREE
Backed out changeset 1af6a9b30e2c (bug 1802466)
Backed out changeset 9461b0e136d3 (bug 1802466)
Backed out changeset 59c6e8943e53 (bug 1802466)
2023-09-06 21:24:32 +03:00
Daniel Holbert
7bf2dfa2d0 Bug 1802466 part 2: Change GetSelectionEndPointGeometry to handle vertical-writing-mode text nodes. r=emilio
This function had some code that we hadn't yet updated to support vertical
writing modes.  This patch makes it more generic so that it can properly handle
vertical-writing-mode text nodes (so that we can e.g. properly keep the caret
scrolled into view, in a vertical-writing-mode textfield).

I'm just focusing on vertical vs. horizontal generification for now.  I'm not
entirely sure if it makes sense to make it even-more-generic-still to support
reversed-inline-direction writing modes as well. I wasn't able to trigger any
issues with those in some brief testing, so I think this patch is sufficient
as-is, but I left a TODO(dholbert) code-comment to call out that ambiguity
that's still present in the code.

Differential Revision: https://phabricator.services.mozilla.com/D187160
2023-09-06 17:16:46 +00:00
Daniel Holbert
26fbaa39db Bug 1802466 part 1: Refactor computation of outparam rect in GetSelectionEndPointGeometry. r=emilio
This patch doesn't change behavior. It's just laying the groundwork for the
next patch which adds vertical-writing-mode support.

(This patch adds some documentation in terms of logical axes, though, which
will become accurate as of the next patch in this series.)

Differential Revision: https://phabricator.services.mozilla.com/D187161
2023-09-06 17:16:46 +00:00
Masayuki Nakano
1caee5555f Bug 1840700 - Make Selection::AddRangeAndSelectFramesAndNotifyListenersInternal() update interline position even if it does nothing r=jjaschke
It always set to "start of next line" when new range was added.  However,
after bug 1815802, it does nothing when adding range is one of its ranges.
Therefore, if interline position is set to "end of line" by our internal
code, like editor, `getSelection().addRange(getSelection().getRangeAt(0))`
keeps the last interline position.

Differential Revision: https://phabricator.services.mozilla.com/D182300
2023-06-28 07:59:13 +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
bfe0baa6d6 Bug 1828469, part 2: Moved some logic from nsRange to AbstractRange to support StaticRanges in custom highlights. r=masayuki
With this change, Selections are also registered into StaticRanges,
ultimately making them visible to `nsINode::IsSelected()`,
which is necessary to paint them.

Differential Revision: https://phabricator.services.mozilla.com/D175784
2023-05-31 08:23:45 +00:00
Noemi Erli
61ed1c4c8c Backed out 3 changesets (bug 1828469) for causing assertion in RangeBoundary.h
Backed out changeset ab92a12ba6ea (bug 1828469)
Backed out changeset 217801294c41 (bug 1828469)
Backed out changeset c78c717e4ec9 (bug 1828469)
2023-05-23 12:10:12 +03:00
Jan-Niklas Jaeschke
0bf8a22c8f Bug 1828469, part 2: Moved some logic from nsRange to AbstractRange to support StaticRanges in custom highlights. r=masayuki
With this change, Selections are also registered into StaticRanges,
ultimately making them visible to `nsINode::IsSelected()`,
which is necessary to paint them.

Differential Revision: https://phabricator.services.mozilla.com/D175784
2023-05-23 06:53:32 +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
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
Masayuki Nakano
9f3a55f73d Bug 1818128 - Add logging code for Selection API calls r=smaug
It's hard to check Selection API calls from both JS and internals when we debug
web apps which has complicated `contenteditable` editor.  Therefore, I'd like to
add an ability to log Selection API calls.

This patch needs to stop some methods inlined.  Therefore, this could affect to
the performance in release builds, though.  If so, I need to work on some
optimization later.

For minimizing the impact for performance, this patch also makes them to check
the logging level before calling logging methods.  It's currently redundant
for `LogLevel::Info` case.  However, this avoids any performance impact from
changes of `MOZ_LOG` implementation and in the blocks.

Differential Revision: https://phabricator.services.mozilla.com/D170585
2023-03-05 22:38:05 +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
Masayuki Nakano
06b3ec5836 Bug 1815802 - Make Selection::AddRangeJS do nothing if adding range instance belongs to the Selection r=jjaschke
`Selection` stores given ranges directly if and only if it's possible.
Therefore, adding a range which is already in the array of `Selection` ranges
needs to do nothing.

Differential Revision: https://phabricator.services.mozilla.com/D169301
2023-02-10 07:46:23 +00:00
Masayuki Nakano
f1091f8e6c Bug 1815621 - Make Selection::NotifySelectionListeners check concrete class listeners too when it wants to return early r=smaug
In bug 1486370, bug 1487591 and bug 1487659, we made `Selection` handle some
selection listeners with pointers to concrete classes for the performance (for
saving virtual call cost, allocation cost of the selection listener array and
copy cost of the array before notifying).  However, at that time, I forgot to
change the condition of early return.   Therefore, current `Selection` does not
notify concrete class listeners of selection changes if there is no active
`nsISelectionListener` instances for the `Selection` instance.

Differential Revision: https://phabricator.services.mozilla.com/D169191
2023-02-09 00:32: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
Jan-Niklas Jaeschke
1b3bff372b 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-24 11:46:28 +00:00
Sandor Molnar
a610ef723a Backed out changeset 54771a1963b6 (bug 1803355) for causing win build bustage. CLOSED TREE 2023-01-24 12:17:49 +02:00
Jan-Niklas Jaeschke
99eb703228 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-24 07:36:13 +00:00
Noemi Erli
aec839cbc8 Backed out changeset 759d4948ed8b (bug 1803355) for causing build bustages CLOSED TREE 2023-01-22 05:03:04 +02:00