Skip to content
Permalink
Browse files
Implement full search for text directives for Scroll to Text Fragment…
… spec.

https://bugs.webkit.org/show_bug.cgi?id=243511
rdar://89301977

Reviewed by Ryosuke Niwa.

Add full search algorithm as specified in the spec here:
https://wicg.github.io/scroll-to-text-fragment/
To properly search for text fragments from the directives that we have
parsed out of the URL.

Currently these have been tested against some examples, but in the
near future we will import that WPT tests and ensure that all of those pass
as well as address the last few edge case FIXMEs left in this implementation.

Source/WebCore/dom/FragmentDirectiveParser.cpp:
Fix an error in parsing the fragment directive that wasn't caught until I
finished coding the search algorithm.

* Source/WebCore/dom/BoundaryPoint.h:
(WebCore::operator!=):
* Source/WebCore/dom/FragmentDirectiveParser.cpp:
(WebCore::FragmentDirectiveParser::parseFragmentDirective):
* Source/WebCore/dom/FragmentDirectiveRangeFinder.cpp:
(WebCore::FragmentDirectiveRangeFinder::isSearchInvisible):
(WebCore::FragmentDirectiveRangeFinder::isNonSearchableSubtree):
(WebCore::FragmentDirectiveRangeFinder::nearestBlockAncestor):
(WebCore::FragmentDirectiveRangeFinder::getBoundaryPointAtIndex):
(WebCore::FragmentDirectiveRangeFinder::indexIsWordBoundary):
(WebCore::FragmentDirectiveRangeFinder::isVisibleTextNode):
(WebCore::FragmentDirectiveRangeFinder::findRangeFromNodeList):
(WebCore::FragmentDirectiveRangeFinder::rangeOfStringInRange):
(WebCore::FragmentDirectiveRangeFinder::advanceRangeStartToNextNonWhitespace):
(WebCore::FragmentDirectiveRangeFinder::rangesForFragments):
(WebCore::FragmentDirectiveRangeFinder::rangeForFragment):
(WebCore::FragmentDirectiveRangeFinder::collapseIfRootsDiffer): Deleted.
(WebCore::FragmentDirectiveRangeFinder::rangeOfString): Deleted.
* Source/WebCore/dom/FragmentDirectiveRangeFinder.h:
* Source/WebCore/rendering/style/RenderStyle.h:
(WebCore::RenderStyle::isDisplayBlockLevel const):

Canonical link: https://commits.webkit.org/253383@main
  • Loading branch information
megangardner authored and ryanhaddad committed Aug 12, 2022
1 parent e1eec3e commit 721922be3ab62d8bdbde2ed93b6cb60d4cede316
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 17 deletions.
@@ -68,6 +68,11 @@ inline bool operator==(const BoundaryPoint& a, const BoundaryPoint& b)
return a.container.ptr() == b.container.ptr() && a.offset == b.offset;
}

inline bool operator!=(const BoundaryPoint& a, const BoundaryPoint& b)
{
return !(a == b);
}

inline BoundaryPoint makeBoundaryPointBeforeNodeContents(Node& node)
{
return { node, 0 };
@@ -63,6 +63,7 @@ FragmentDirectiveParser::FragmentDirectiveParser(const URL& url)
m_isValid = true;
}

// https://wicg.github.io/scroll-to-text-fragment/#parse-a-text-directive
void FragmentDirectiveParser::parseFragmentDirective(StringView fragmentDirective)
{
LOG_WITH_STREAM(TextFragment, stream << " parseFragmentDirective: ");
@@ -101,7 +102,7 @@ void FragmentDirectiveParser::parseFragmentDirective(StringView fragmentDirectiv

if (tokens.first().endsWith('-') && tokens.first().length() > 1) {
auto takenFirstToken = tokens.takeFirst();
if (auto prefix = WTF::URLParser::formURLDecode(StringView(takenFirstToken).left(takenFirstToken.length() - 2)))
if (auto prefix = WTF::URLParser::formURLDecode(StringView(takenFirstToken).left(takenFirstToken.length() - 1)))
parsedTextDirective.prefix = WTFMove(*prefix);
else
LOG_WITH_STREAM(TextFragment, stream << " could not decode prefix ");

0 comments on commit 721922b

Please sign in to comment.