diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /dom/base/Highlight.cpp | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/Highlight.cpp')
-rw-r--r-- | dom/base/Highlight.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/dom/base/Highlight.cpp b/dom/base/Highlight.cpp index cd0efccce5..0bac8193d7 100644 --- a/dom/base/Highlight.cpp +++ b/dom/base/Highlight.cpp @@ -101,24 +101,36 @@ already_AddRefed<Selection> Highlight::CreateHighlightSelection( } void Highlight::Add(AbstractRange& aRange, ErrorResult& aRv) { + // Manually check if the range `aKey` is already present in this highlight, + // because `SetlikeHelpers::Add()` doesn't indicate this. + // To keep the setlike and the mirrored array in sync, the range must not + // be added to `mRanges` if it was already present. + // `SetlikeHelpers::Has()` is much faster in checking this than + // `nsTArray<>::Contains()`. + if (Highlight_Binding::SetlikeHelpers::Has(this, aRange, aRv) || + aRv.Failed()) { + return; + } Highlight_Binding::SetlikeHelpers::Add(this, aRange, aRv); if (aRv.Failed()) { return; } - if (!mRanges.Contains(&aRange)) { - mRanges.AppendElement(&aRange); - AutoFrameSelectionBatcher selectionBatcher(__FUNCTION__, - mHighlightRegistries.Count()); - for (const RefPtr<HighlightRegistry>& registry : - mHighlightRegistries.Keys()) { - auto frameSelection = registry->GetFrameSelection(); - selectionBatcher.AddFrameSelection(frameSelection); - // since this is run in a context guarded by a selection batcher, - // no strong reference is needed to keep `registry` alive. - MOZ_KnownLive(registry)->MaybeAddRangeToHighlightSelection(aRange, *this); - if (aRv.Failed()) { - return; - } + + MOZ_ASSERT(!mRanges.Contains(&aRange), + "setlike and DOM mirror are not in sync"); + + mRanges.AppendElement(&aRange); + AutoFrameSelectionBatcher selectionBatcher(__FUNCTION__, + mHighlightRegistries.Count()); + for (const RefPtr<HighlightRegistry>& registry : + mHighlightRegistries.Keys()) { + auto frameSelection = registry->GetFrameSelection(); + selectionBatcher.AddFrameSelection(frameSelection); + // since this is run in a context guarded by a selection batcher, + // no strong reference is needed to keep `registry` alive. + MOZ_KnownLive(registry)->MaybeAddRangeToHighlightSelection(aRange, *this); + if (aRv.Failed()) { + return; } } } |