Skip to content

Commit

Permalink
Make caretRangeFromPoint return empty range for content-visibility: h…
Browse files Browse the repository at this point in the history
…idden

https://bugs.webkit.org/show_bug.cgi?id=249473

Reviewed by Darin Adler.

Make caretRangeFromPoint return empty range for content-visibility: hidden since
the element's contents are empty.

* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-080-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-080.html:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::caretPositionFromPoint):

Canonical link: https://commits.webkit.org/258142@main
  • Loading branch information
rwlbuis authored and darinadler committed Dec 20, 2022
1 parent b09f48f commit 0ccd3d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
@@ -1,4 +1,4 @@
Content Visibility: caret position with html hidden * { all: initial; content-visibility: hidden; } test(() => { const range = document.caretRangeFromPoint(); assert_not_equals(range, null, "range exists"); assert_equals(range.startContainer, html, "startContainer is html"); assert_equals(range.startOffset, 0, "startOffset is zero"); assert_equals(range.endContainer, html, "endContainer is html"); assert_equals(range.endOffset, 0, "endOffset is zero"); }, "Caret range from point");
FAIL Caret range from point assert_equals: startContainer is html expected Element node <html id="html"><head><meta charset="utf8">
<title>Conten... but got Text node "Content Visibility: caret position with html hidden"


PASS Caret range from point

Expand Up @@ -19,7 +19,8 @@
</style>

<script>
test(() => {
test((t) => {
t.add_cleanup(() => { document.getElementsByTagName('style')[0].remove(); });
const range = document.caretRangeFromPoint();
assert_not_equals(range, null, "range exists");
assert_equals(range.startContainer, html, "startContainer is html");
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/dom/Document.cpp
Expand Up @@ -1627,6 +1627,10 @@ std::optional<BoundaryPoint> Document::caretPositionFromPoint(const LayoutPoint&
auto* renderer = node->renderer();
if (!renderer)
return std::nullopt;

if (renderer->shouldSkipContent())
return { { *node, 0 } };

auto rangeCompliantPosition = renderer->positionForPoint(localPoint).parentAnchoredEquivalent();
if (rangeCompliantPosition.isNull())
return std::nullopt;
Expand Down

0 comments on commit 0ccd3d9

Please sign in to comment.