Closed Bug 1808565 Opened 2 years ago Closed 2 years ago

Add support for StaticRange in Selection

Categories

(Core :: DOM: Selection, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
112 Branch
Tracking Status
firefox112 --- fixed

People

(Reporter: jjaschke, Assigned: jjaschke)

References

(Blocks 1 open bug, )

Details

Attachments

(2 files)

The Custom Highlight API dictates that highlights can be created from AbstractRanges, i.e. both static and dynamic ranges. Internally, highlights are implemented as a Selection. Selections currently only support dynamic ranges (nsRange), not StaticRanges. Therefore, support for StaticRanges in Selection must be added to support the Highlight API.

This change is necessary to support the CSS Highlight API,
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
Assignee: nobody → jjaschke
Status: NEW → ASSIGNED
Attachment #9319151 - Attachment description: Bug 1808565: Adapt `Selection` to support `StaticRange`s. r=masayuki → Bug 1808565, part 1: Adapt `Selection` to support `StaticRange`s. r=masayuki
Pushed by jjaschke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d0efd5366ad0 part 1: Adapt `Selection` to support `StaticRange`s. r=webidl,saschanaz,masayuki,smaug https://hg.mozilla.org/integration/autoland/rev/328335bf81de part 2: Use `SelectionBatcher` when updating Highlights. r=masayuki
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 112 Branch
Regressions: 1820286
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: