Closed Bug 1867939 Opened 1 year ago Closed 8 months ago

Implement first version of Text Fragments

Categories

(Core :: DOM: Navigation, task)

task

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 --- fixed

People

(Reporter: jjaschke, Assigned: jjaschke)

References

(Blocks 3 open bugs)

Details

Attachments

(6 files, 1 obsolete file)

This bug tracks the initial implementation for Text Fragments to not mess up the meta bug 1753933.

This patch also adds the empty shell of the FragmentDirective class to the Document.

This patch provides functions to extract the fragment directive from a url / a hash
into an array of TextDirectives
as well as to create a fragment directive string from given text directives.

The algorithms are implemented as a rust crate.
Interface functions and data structures which are accessible from C++
are provided in lib.rs.
The actual implementation (using pure rust types)
lives in fragment_directive_impl.rs, tests live in test.rs.

The implementation currently only supports text directives.
Other future directive types are not considered and will be ignored.

The main function, parse_fragment_directive() takes a url / a url hash
as parameter and returns (as out parameter) a struct which contains the stripped input url,
the fragment directive string, and an array of parsed text directive objects.

Additionally, there are functions that create a full fragment directive string
from a list of text directives as well as a function that creates
a single text directive string from a text directive.

The TextDirective class, which is shared with C++, contains four
string elements for the prefix, start, end and suffix elements.
These strings are percent-decoded and do not contain identifiers
(like the - that indicates it being a prefix or suffix).
All elements besides start can be empty.

The implemented algorithms are used in the following patches.

Depends on D195684

Main part of this patch is an implementation of the algorithm defined
in the spec 0.
The algorithm takes an array of TextDirective (which is the result of
the fragment directive parser implemented in part 2 of this bug)
and converts it into an array of nsRanges.

The algorithm is not optimized for performance yet.
Instead it follows the spec very closely.
Therefore, it may for now only be seen as a baseline to a faster nsFind based approach.
The algorithm differs from the spec, using a standard nsString::Find()
instead of the mentioned collator-based search, i.e.
performing a case-sensitive and locale-independent search.

Depends on D195685

This patch implements the ::target-text pseudo element.
Similarly to the Custom Highlight API, this is done implementing
a new Selection type.

Depends on D195686

This patch integrates the algorithm to find a text fragment range
into the document loading mechanism.
Unlike described in the spec, the fragment directive is not stripped
from the URL in the Session History Entry, instead it is stripped when
setting the URI into the Document using Document::SetURI(),
as well as when accessing the URL through Location.

The PresShell class is extended by a new method which sets the
ranges created from the text directives into the FrameSelection as
TargetText selection and scrolls it into view.

Security restrictions like force load at top and cross-origin iframes
are not yet considered in this patch.

Depends on D195687

This test sets the pref dom.text_fragments.enabled to true for
web-platform tests in

  • /scroll-to-text-fragment
  • / css/css-pseudo (which contains various tests for ::target-text

Depends on D195688

This patch introduces a new webidl api called document.fragmentDirective.createTextFragment(),
which allows web apps to create a text directive string from a given range.
Optionally, the api accepts a boolean parameter to force the text directive to use start and end
(i.e. the result looks like this: text=prefix-,start,end,-suffix),
otherwise it will only use start (i.e. text=prefix-,start,-suffix).

This API is not spec'd yet [0] and is subject to change.
Currently it mainly serves the purpose of testing the underlying algorithm
that can create a text directive from a range, which is the main part of this patch.

This algorithm uses the find-range-from-text-directive algorithm implemented in part 3
of this bug to iteratively expand the text directive (expanding prefix and suffix,
and if forceRangeBased is true also start and end) until the created text directive
is the first search result.
This algorithm may not be very efficient because
a) the find-range-from-text-directive algorithm is not performance-optimized yet and
b) it is called in a loop, each time doing a full search of the document.

This patch also contains a few mozilla-specific web-platform tests that test
the new algorithm.

[0] https://github.com/WICG/scroll-to-text-fragment/issues/160

Depends on D195690

Blocks: 1868732
Depends on: 1860915
Attachment #9367322 - Attachment is obsolete: true
See Also: → 1876324
See Also: → 1876524
See Also: → 1881429
Pushed by jjaschke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/82f99c0210b0 part 1: Add FragmentDirective webidl and pref. r=dom-core,webidl,emilio,hsivonen https://hg.mozilla.org/integration/autoland/rev/575873406614 part 2: Implement Fragment Directive parser. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/2fbe643ca483 part 3: Implement an algorithm to find text directives in a document. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/1b3af4b6a27b part 4: Implemented the `::target-text` CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe https://hg.mozilla.org/integration/autoland/rev/2279e6577c13 part 5: Integrate find-text-directive algorithm into Document load. r=peterv,farre,dom-core https://hg.mozilla.org/integration/autoland/rev/0853f9a7a06c part 6: Enabled tests for Text Fragments which pass now. r=dom-core,hsivonen

Backed out for causing build bustages in Document.h

  • Backout link
  • Push with failures
  • Failure Log
  • Failure line: /builds/worker/workspace/obj-build/dist/include/mozilla/dom/Document.h:4100:40: error: declaration of 'mozilla::dom::FragmentDirective* mozilla::dom::Document::FragmentDirective()' [-fpermissive]
Flags: needinfo?(jjaschke)

Should be fixed.

Flags: needinfo?(jjaschke)
Pushed by jjaschke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c3e3c81f9ceb part 1: Add FragmentDirective webidl and pref. r=dom-core,webidl,emilio,hsivonen https://hg.mozilla.org/integration/autoland/rev/27c76e65cf58 part 2: Implement Fragment Directive parser. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/bb88c4d09e82 part 3: Implement an algorithm to find text directives in a document. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/839bc1b11a2c part 4: Implemented the `::target-text` CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe https://hg.mozilla.org/integration/autoland/rev/51890598ecb4 part 5: Integrate find-text-directive algorithm into Document load. r=peterv,farre,dom-core https://hg.mozilla.org/integration/autoland/rev/2110f57e928c part 6: Enabled tests for Text Fragments which pass now. r=dom-core,hsivonen
Regressions: 1889349
No longer regressions: 1889349
Regressions: 1889349
Regressions: 1889389
Regressions: 1889393
Regressions: 1889395

Backed out 6 changesets (Bug 1867939) for causing a top crash in nightly Bug 1889393

Backout link central: https://hg.mozilla.org/mozilla-central/rev/cfb42711da4589f5ede0032644a6d577d66aa468

Status: RESOLVED → REOPENED
Flags: needinfo?(jjaschke)
Resolution: FIXED → ---
Target Milestone: 126 Branch → ---
Pushed by jjaschke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0d269b891421 part 1: Add FragmentDirective webidl and pref. r=dom-core,webidl,emilio,hsivonen https://hg.mozilla.org/integration/autoland/rev/d77b9257c842 part 2: Implement Fragment Directive parser. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/38631fbd2f2f part 3: Implement an algorithm to find text directives in a document. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/0748839408e5 part 4: Implemented the `::target-text` CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe https://hg.mozilla.org/integration/autoland/rev/c53267e1b460 part 5: Integrate find-text-directive algorithm into Document load. r=peterv,farre,dom-core https://hg.mozilla.org/integration/autoland/rev/44101c258e52 part 6: Enabled tests for Text Fragments which pass now. r=dom-core,hsivonen

Backed out for causing wpt failures in target-text-010.html.

Pushed by jjaschke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/72fd96c52665 part 1: Add FragmentDirective webidl and pref. r=dom-core,webidl,emilio,hsivonen https://hg.mozilla.org/integration/autoland/rev/73ecb30d1c88 part 2: Implement Fragment Directive parser. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/6a93f2b9da54 part 3: Implement an algorithm to find text directives in a document. r=hsivonen,dom-core https://hg.mozilla.org/integration/autoland/rev/de9babe5fda2 part 4: Implemented the `::target-text` CSS Pseudo Element. r=emilio,devtools-reviewers,nchevobbe https://hg.mozilla.org/integration/autoland/rev/5ad5bd073009 part 5: Integrate find-text-directive algorithm into Document load. r=peterv,farre,dom-core https://hg.mozilla.org/integration/autoland/rev/11e85bb40828 part 6: Enabled tests for Text Fragments which pass now. r=dom-core,hsivonen
Blocks: 1860915
No longer depends on: 1860915
Flags: needinfo?(jjaschke)
See Also: → 1890733
Depends on: 1908683
No longer depends on: 1908683
Component: DOM: Core & HTML → DOM: Navigation
Blocks: 1777208
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: