summaryrefslogtreecommitdiffstats
path: root/dom/base/Highlight.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /dom/base/Highlight.cpp
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.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.cpp40
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;
}
}
}