You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[css-highlight-api] Make highlightsFromPoint return HighlightHitResults
This CL changes the return type for CSS.highlights.highlightsFromPoint()
to return a sequence<HighlightHitResult>. Internally this corresponds to
returning a HeapVector<Member<HighlightHitResult>>.
This implements what was resolved in a CSSWG meeting, see more details
in this issue: w3c/csswg-drafts#12031
Other changes:
- Introduce the HighlightHitResult type.
- Fix unit tests and WPTs.
- Add some new unit tests and WPTs to address the ranges being returned
now as well.
Bug: 365046212, 416254971
Change-Id: Ic2cf061ff921e4a1d7ad7f47609fb6f644374724
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6598200
Commit-Queue: Fernando Fiori <ffiori@microsoft.com>
Reviewed-by: Dan Clark <daniec@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1467678}
<metaname="assert" content="HighlightRegistry.highlightsFromPoint returns the Highlights and their corresponding Ranges and StaticRanges present at the coordinates provided as argument in the right order in multi-line text.">
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the text contents');
37
+
38
+
// Get x and y coordinates between characters '0' and '1' on the first line (not highlighted).
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the highlighted ranges');
43
+
44
+
// Get x and y coordinates between characters '2' and '3' on the first line.
assert_equals(highlight_hit_results.length,1,'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');
48
+
assert_equals(highlight_hit_results[0].highlight,highlight,'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');
49
+
assert_array_equals(highlight_hit_results[0].ranges,[big_range],'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');
50
+
51
+
// Get x and y coordinates between characters '6' and '7' on the first line.
assert_equals(highlight_hit_results.length,1,'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');
55
+
assert_equals(highlight_hit_results[0].highlight,highlight,'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');
56
+
assert_array_equals(highlight_hit_results[0].ranges,ranges,'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided in the right order');
57
+
58
+
// Get x and y coordinates to the right of the last character of the first line.
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are to the right of the text contents');
62
+
63
+
// Get x and y coordinates between characters '0' and '1' on the second line.
assert_equals(highlight_hit_results.length,1,'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');
68
+
assert_equals(highlight_hit_results[0].highlight,highlight,'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');
69
+
assert_array_equals(highlight_hit_results[0].ranges,[big_range],'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');
70
+
71
+
// Get x and y coordinates between characters '8' and '9' on the second line (not highlighted).
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the highlighted ranges');
75
+
76
+
// Get x and y coordinates to the right of the last character of the second line.
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are to the right of the text contents');
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are below the text contents');
86
+
}
87
+
88
+
test(()=>{
89
+
// Set a Highlight with two nested ranges in this way:
},'CSS.highlights.highlightsFromPoint() returns HighlightHitResults with the Highlights and their corresponding Ranges and StaticRanges present at the given point in the right order on multi-line text.');
assert_equals(highlights.length,0,'CSS.highlights.highlightsFromPoint() returns no Highlights when the coordinates provided are outside of the text contents');
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided are outside of the text contents');
assert_equals(highlights.length,0,'CSS.highlights.highlightsFromPoint() returns no Highlights when the coordinates provided point at no Highlights');
59
+
assert_equals(highlight_hit_results.length,0,'CSS.highlights.highlightsFromPoint() returns an empty array when the coordinates provided point at no Highlights');
assert_equals(highlights.length,1,'CSS.highlights.highlightsFromPoint() returns exactly one Highlight when the coordinates provided point at one Highlight');
65
-
assert_equals(highlights[0],highlight1,'CSS.highlights.highlightsFromPoint() returns the Highlight present at the coordinates provided');
assert_equals(highlight_hit_results.length,1,'CSS.highlights.highlightsFromPoint() returns exactly one HighlightHitResult when the coordinates provided point at one Highlight');
65
+
assert_equals(highlight_hit_results[0].highlight,highlight1,'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the Highlight present at the coordinates provided');
66
+
assert_array_equals(highlight_hit_results[0].ranges,[range1],'CSS.highlights.highlightsFromPoint() returns a HighlightHitResult with the ranges of the Highlight present at the coordinates provided');
66
67
67
68
// Get x and y coordinates between '6' and '7'.
68
69
// Same priority for the Highlights, break tie by order of registration.
assert_equals(highlights.length,2,'CSS.highlights.highlightsFromPoint() returns exactly two Highlights when the coordinates provided point at two overlapping Highlights');
72
-
assert_equals(highlights[0],highlight2,'CSS.highlights.highlightsFromPoint() returns first the Highlight registered last when both Highlights present at the point provided have the same priority');
73
-
assert_equals(highlights[1],highlight1,'CSS.highlights.highlightsFromPoint() returns last the Highlight registered first when both Highlights present at the point provided have the same priority');
assert_equals(highlight_hit_results.length,2,'CSS.highlights.highlightsFromPoint() returns exactly two HighlightHitResults when the coordinates provided point at two overlapping Highlights');
73
+
assert_equals(highlight_hit_results[0].highlight,highlight2,'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the Highlight registered last when both Highlights present at the point provided have the same priority');
74
+
assert_equals(highlight_hit_results[1].highlight,highlight1,'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the Highlight registered first when both Highlights present at the point provided have the same priority');
75
+
assert_array_equals(highlight_hit_results[0].ranges,[range2],'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the ranges of the Highlight present on top at the coordinates provided');
76
+
assert_array_equals(highlight_hit_results[1].ranges,[range1],'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the ranges of the Highlight present at the bottom at the coordinates provided');
74
77
75
78
// Now highlight1 should be first because it's got higher priority.
assert_equals(highlights.length,2,'CSS.highlights.highlightsFromPoint() returns exactly two Highlights when the coordinates provided point at two overlapping Highlights');
80
-
assert_equals(highlights[0],highlight1,'CSS.highlights.highlightsFromPoint() returns first the Highlight with higher priority when there are two Highlights present at the point provided');
81
-
assert_equals(highlights[1],highlight2,'CSS.highlights.highlightsFromPoint() returns last the Highlight with lower priority when there are two Highlights present at the point provided');
82
-
},'CSS.highlights.highlightsFromPoint() returns Highlights present at the given point in the right order.');
assert_equals(highlight_hit_results.length,2,'CSS.highlights.highlightsFromPoint() returns exactly two HighlightHitResults when the coordinates provided point at two overlapping Highlights');
83
+
assert_equals(highlight_hit_results[0].highlight,highlight1,'CSS.highlights.highlightsFromPoint() returns first a HighlightHitResult with the Highlight with higher priority when there are two Highlights present at the point provided');
84
+
assert_equals(highlight_hit_results[1].highlight,highlight2,'CSS.highlights.highlightsFromPoint() returns last a HighlightHitResult with the Highlight with lower priority when there are two Highlights present at the point provided');
85
+
},'CSS.highlights.highlightsFromPoint() returns the Highlights with their corresponding ranges present at the given point in the right order.');
0 commit comments