- Revision
- 249998
- Author
- [email protected]
- Date
- 2019-09-17 15:29:44 -0700 (Tue, 17 Sep 2019)
Log Message
Cherry-pick r249813. rdar://problem/55427490
[Cocoa] Text indicator for an image link on the front page of apple.com looks wrong
https://bugs.webkit.org/show_bug.cgi?id=201724
<rdar://problem/54622894>
Reviewed by Tim Horton.
Source/WebCore:
When computing the bounds of the range (<a>, 0) to (<a>, 1) for a text indicator snapshot where <a> is a link
with a single non-breaking whitespace character, we currently use the text rect of the single space. This leads
to a confusing text indicator, as the resulting snapshot is a tiny blank square in the top left corner of the
link. This problem manifests when starting a drag or showing the system context menu on iOS, or force clicking
or three-finger tapping to show a preview on macOS.
To address this scenario, tweak the heuristic in the case where the text indicator option
TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges is specified, such that we consider a range
containing only text with whitespaces to be "complex"; additionally, instead of falling back to the range's
bounding rect (which in this case is still tiny), fall back to the common ancestor container's bounding rect,
which encompasses not only the text inside the range but also the element containing the range (in this case,
the anchor element).
Test: fast/text-indicator/text-indicator-empty-link.html
* page/TextIndicator.cpp:
(WebCore::containsOnlyWhiteSpaceText):
Add a helper to determine whether a Range is comprised only of rendered text that only contains whitespace
characters.
(WebCore::initializeIndicator):
See ChangeLog entry above for more detail.
LayoutTests:
Add a new layout test to exercise this scenario.
* fast/text-indicator/text-indicator-empty-link-expected.txt: Added.
* fast/text-indicator/text-indicator-empty-link.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Added Paths
Diff
Modified: branches/safari-608-branch/LayoutTests/ChangeLog (249997 => 249998)
--- branches/safari-608-branch/LayoutTests/ChangeLog 2019-09-17 22:29:41 UTC (rev 249997)
+++ branches/safari-608-branch/LayoutTests/ChangeLog 2019-09-17 22:29:44 UTC (rev 249998)
@@ -1,5 +1,65 @@
2019-09-17 Kocsen Chung <[email protected]>
+ Cherry-pick r249813. rdar://problem/55427490
+
+ [Cocoa] Text indicator for an image link on the front page of apple.com looks wrong
+ https://bugs.webkit.org/show_bug.cgi?id=201724
+ <rdar://problem/54622894>
+
+ Reviewed by Tim Horton.
+
+ Source/WebCore:
+
+ When computing the bounds of the range (<a>, 0) to (<a>, 1) for a text indicator snapshot where <a> is a link
+ with a single non-breaking whitespace character, we currently use the text rect of the single space. This leads
+ to a confusing text indicator, as the resulting snapshot is a tiny blank square in the top left corner of the
+ link. This problem manifests when starting a drag or showing the system context menu on iOS, or force clicking
+ or three-finger tapping to show a preview on macOS.
+
+ To address this scenario, tweak the heuristic in the case where the text indicator option
+ TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges is specified, such that we consider a range
+ containing only text with whitespaces to be "complex"; additionally, instead of falling back to the range's
+ bounding rect (which in this case is still tiny), fall back to the common ancestor container's bounding rect,
+ which encompasses not only the text inside the range but also the element containing the range (in this case,
+ the anchor element).
+
+ Test: fast/text-indicator/text-indicator-empty-link.html
+
+ * page/TextIndicator.cpp:
+ (WebCore::containsOnlyWhiteSpaceText):
+
+ Add a helper to determine whether a Range is comprised only of rendered text that only contains whitespace
+ characters.
+
+ (WebCore::initializeIndicator):
+
+ See ChangeLog entry above for more detail.
+
+ LayoutTests:
+
+ Add a new layout test to exercise this scenario.
+
+ * fast/text-indicator/text-indicator-empty-link-expected.txt: Added.
+ * fast/text-indicator/text-indicator-empty-link.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-12 Wenson Hsieh <[email protected]>
+
+ [Cocoa] Text indicator for an image link on the front page of apple.com looks wrong
+ https://bugs.webkit.org/show_bug.cgi?id=201724
+ <rdar://problem/54622894>
+
+ Reviewed by Tim Horton.
+
+ Add a new layout test to exercise this scenario.
+
+ * fast/text-indicator/text-indicator-empty-link-expected.txt: Added.
+ * fast/text-indicator/text-indicator-empty-link.html: Added.
+
+2019-09-17 Kocsen Chung <[email protected]>
+
Cherry-pick r249734. rdar://problem/55291693
Attempt to make this test not flakey.
Added: branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link-expected.txt (0 => 249998)
--- branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link-expected.txt (rev 0)
+++ branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link-expected.txt 2019-09-17 22:29:44 UTC (rev 249998)
@@ -0,0 +1,11 @@
+PASS 0 is >= boundingRect.x
+PASS 0 is >= boundingRect.y
+PASS boundingRect.width is >= innerWidth
+PASS boundingRect.height is >= innerHeight
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+To test manually, force click on macOS or begin a drag on iPadOS here. The preview highlight rect or targeted drag preview (respectively) should encompass the entire window, instead of just a tiny piece of empty text in the upper left hand corner.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Added: branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link.html (0 => 249998)
--- branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link.html (rev 0)
+++ branches/safari-608-branch/LayoutTests/fast/text-indicator/text-indicator-empty-link.html 2019-09-17 22:29:44 UTC (rev 249998)
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<head>
+<script src=""
+<style>
+ html, body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ }
+
+ .fullscreen {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ }
+
+ div.fullscreen {
+ background-color: lightgray;
+ text-align: center;
+ z-index: -100;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
+
+ img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+
+ a {
+ text-decoration: none;
+ }
+</style>
+</head>
+<body>
+ <a class="fullscreen" href=""
+ <div class="fullscreen" id="description"></div>
+</body>
+<script>
+ description("To test manually, force click on macOS or begin a drag on iPadOS here. The preview highlight rect or targeted drag preview (respectively) should encompass the entire window, instead of just a tiny piece of empty text in the upper left hand corner.");
+
+ function runTest() {
+ if (!window.internals)
+ return;
+
+ const range = document.createRange();
+ range.selectNodeContents(document.querySelector("a.fullscreen"));
+
+ const indicator = internals.textIndicatorForRange(range, { useBoundingRectAndPaintAllContentForComplexRanges : true });
+ boundingRect = indicator.textBoundingRectInRootViewCoordinates;
+
+ shouldBeGreaterThanOrEqual("0", "boundingRect.x");
+ shouldBeGreaterThanOrEqual("0", "boundingRect.y");
+ shouldBeGreaterThanOrEqual("boundingRect.width", "innerWidth");
+ shouldBeGreaterThanOrEqual("boundingRect.height", "innerHeight");
+ }
+
+ runTest();
+</script>
+</html>
Modified: branches/safari-608-branch/Source/WebCore/ChangeLog (249997 => 249998)
--- branches/safari-608-branch/Source/WebCore/ChangeLog 2019-09-17 22:29:41 UTC (rev 249997)
+++ branches/safari-608-branch/Source/WebCore/ChangeLog 2019-09-17 22:29:44 UTC (rev 249998)
@@ -1,5 +1,85 @@
2019-09-17 Kocsen Chung <[email protected]>
+ Cherry-pick r249813. rdar://problem/55427490
+
+ [Cocoa] Text indicator for an image link on the front page of apple.com looks wrong
+ https://bugs.webkit.org/show_bug.cgi?id=201724
+ <rdar://problem/54622894>
+
+ Reviewed by Tim Horton.
+
+ Source/WebCore:
+
+ When computing the bounds of the range (<a>, 0) to (<a>, 1) for a text indicator snapshot where <a> is a link
+ with a single non-breaking whitespace character, we currently use the text rect of the single space. This leads
+ to a confusing text indicator, as the resulting snapshot is a tiny blank square in the top left corner of the
+ link. This problem manifests when starting a drag or showing the system context menu on iOS, or force clicking
+ or three-finger tapping to show a preview on macOS.
+
+ To address this scenario, tweak the heuristic in the case where the text indicator option
+ TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges is specified, such that we consider a range
+ containing only text with whitespaces to be "complex"; additionally, instead of falling back to the range's
+ bounding rect (which in this case is still tiny), fall back to the common ancestor container's bounding rect,
+ which encompasses not only the text inside the range but also the element containing the range (in this case,
+ the anchor element).
+
+ Test: fast/text-indicator/text-indicator-empty-link.html
+
+ * page/TextIndicator.cpp:
+ (WebCore::containsOnlyWhiteSpaceText):
+
+ Add a helper to determine whether a Range is comprised only of rendered text that only contains whitespace
+ characters.
+
+ (WebCore::initializeIndicator):
+
+ See ChangeLog entry above for more detail.
+
+ LayoutTests:
+
+ Add a new layout test to exercise this scenario.
+
+ * fast/text-indicator/text-indicator-empty-link-expected.txt: Added.
+ * fast/text-indicator/text-indicator-empty-link.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-09-12 Wenson Hsieh <[email protected]>
+
+ [Cocoa] Text indicator for an image link on the front page of apple.com looks wrong
+ https://bugs.webkit.org/show_bug.cgi?id=201724
+ <rdar://problem/54622894>
+
+ Reviewed by Tim Horton.
+
+ When computing the bounds of the range (<a>, 0) to (<a>, 1) for a text indicator snapshot where <a> is a link
+ with a single non-breaking whitespace character, we currently use the text rect of the single space. This leads
+ to a confusing text indicator, as the resulting snapshot is a tiny blank square in the top left corner of the
+ link. This problem manifests when starting a drag or showing the system context menu on iOS, or force clicking
+ or three-finger tapping to show a preview on macOS.
+
+ To address this scenario, tweak the heuristic in the case where the text indicator option
+ TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges is specified, such that we consider a range
+ containing only text with whitespaces to be "complex"; additionally, instead of falling back to the range's
+ bounding rect (which in this case is still tiny), fall back to the common ancestor container's bounding rect,
+ which encompasses not only the text inside the range but also the element containing the range (in this case,
+ the anchor element).
+
+ Test: fast/text-indicator/text-indicator-empty-link.html
+
+ * page/TextIndicator.cpp:
+ (WebCore::containsOnlyWhiteSpaceText):
+
+ Add a helper to determine whether a Range is comprised only of rendered text that only contains whitespace
+ characters.
+
+ (WebCore::initializeIndicator):
+
+ See ChangeLog entry above for more detail.
+
+2019-09-17 Kocsen Chung <[email protected]>
+
Cherry-pick r249770. rdar://problem/55427487
REGRESSION (245006): can't scroll in "read more" view in Eventbrite app
Modified: branches/safari-608-branch/Source/WebCore/page/TextIndicator.cpp (249997 => 249998)
--- branches/safari-608-branch/Source/WebCore/page/TextIndicator.cpp 2019-09-17 22:29:41 UTC (rev 249997)
+++ branches/safari-608-branch/Source/WebCore/page/TextIndicator.cpp 2019-09-17 22:29:44 UTC (rev 249998)
@@ -291,6 +291,16 @@
return !hasOnlyLegibleTextColors || textColors.isEmpty();
}
+static bool containsOnlyWhiteSpaceText(const Range& range)
+{
+ auto* stop = range.pastLastNode();
+ for (auto* node = range.firstNode(); node && node != stop; node = NodeTraversal::next(*node)) {
+ if (!is<RenderText>(node->renderer()))
+ return false;
+ }
+ return plainTextReplacingNoBreakSpace(&range).stripWhiteSpace().isEmpty();
+}
+
static bool initializeIndicator(TextIndicatorData& data, Frame& frame, const Range& range, FloatSize margin, bool indicatesCurrentSelection)
{
if (auto* document = frame.document())
@@ -312,7 +322,14 @@
FrameSelection::TextRectangleHeight textRectHeight = (data.options & TextIndicatorOptionTightlyFitContent) ? FrameSelection::TextRectangleHeight::TextHeight : FrameSelection::TextRectangleHeight::SelectionHeight;
- if ((data.options & TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges) && (hasNonInlineOrReplacedElements(range) || treatRangeAsComplexDueToIllegibleTextColors))
+ bool useBoundingRectAndPaintAllContentForComplexRanges = data.options & TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges;
+ if (useBoundingRectAndPaintAllContentForComplexRanges && containsOnlyWhiteSpaceText(range)) {
+ auto commonAncestorContainer = makeRefPtr(range.commonAncestorContainer());
+ if (auto* containerRenderer = commonAncestorContainer->renderer()) {
+ data.options |= TextIndicatorOptionPaintAllContent;
+ textRects.append(containerRenderer->absoluteBoundingBoxRect());
+ }
+ } else if (useBoundingRectAndPaintAllContentForComplexRanges && (treatRangeAsComplexDueToIllegibleTextColors || hasNonInlineOrReplacedElements(range)))
data.options |= TextIndicatorOptionPaintAllContent;
#if PLATFORM(IOS_FAMILY)
else if (data.options & TextIndicatorOptionUseSelectionRectForSizing)