Introduce a layout milestone to track when the document contains a large number of...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2018 21:05:45 +0000 (21:05 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2018 21:05:45 +0000 (21:05 +0000)
commit1099308b675194e5dcb91f7fcb62e3f0ba6f3edc
tree41b1b19734853ce97da0dd88e32dab669380204a
parent11ff0038234ff9d8aceff8dcbfa83c31d6a551f7
Introduce a layout milestone to track when the document contains a large number of rendered characters
https://bugs.webkit.org/show_bug.cgi?id=187412
<rdar://problem/41744338>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Implements a new layout milestone: `DidRenderSignificantAmountOfText`. This is similar to the existing
`DidFirstVisuallyNonEmptyLayout` milestone, but with a few important additional constraints:

• The minimum threshold of rendered characters is much larger (3000 instead of 200).
• The mean length of a text node must be large (at least 50).

This is a (computationally) lightweight heuristic intended to estimate the likelihood that a page is capable of
being presented in Reader mode. In many article-like pages, the average length of a text node is significantly
longer than other types of pages; thus, on pages where the average length of a text node is very large *and*
there is a large quantity of text, we can use this as a cue to opportunistically detect and enter Safari reader
mode on watchOS.

Test: RenderingProgressTests.DidRenderSignificantAmountOfText

* page/FrameView.cpp:
(WebCore::FrameView::reset):

Clear out new state members that keep track of whether the significant rendered text milestone has been met.

(WebCore::elementOverflowRectIsLargerThanThreshold):

Factor out logic to grab the overflow height of an element into a separate helper function.

(WebCore::FrameView::qualifiesAsVisuallyNonEmpty const):
(WebCore::FrameView::updateSignificantRenderedTextMilestoneIfNeeded):

Determines whether to fire this new milestone after the next layout pass is finished. The logic here is similar
to the logic in qualifiesAsVisuallyNonEmpty, requiring that there are not still pending stylesheets in the head
and that the document height is at least a minimum threshold. However, unlike the first visually non-empty
layout, this milestone is never guaranteed to fire.

(WebCore::FrameView::fireLayoutRelatedMilestonesIfNeeded):
* page/FrameView.h:
(WebCore::FrameView::incrementVisuallyNonEmptyCharacterCount):
* page/LayoutMilestones.h:

Source/WebKit:

Add plumbing for the new significant rendered text layout milestone in the modern WebKit client layer. See
WebCore/ChangeLog for more details.

* Shared/API/Cocoa/_WKRenderingProgressEvents.h:
* Shared/API/Cocoa/_WKRenderingProgressEventsInternal.h:
(renderingProgressEvents):
* Shared/API/c/WKPageLoadTypes.h:
* Shared/API/c/WKSharedAPICast.h:
(WebKit::toWKLayoutMilestones):
(WebKit::toLayoutMilestones):
* UIProcess/API/Cocoa/WKWebView.mm:
(layoutMilestones):

Tools:

Add a new API test to check that we observe the new rendering milestone in an article-like document.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/significant-text-milestone.html: Added.
* TestWebKitAPI/Tests/ios/RenderingProgressTests.mm:
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233623 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/page/LayoutMilestones.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/API/Cocoa/_WKRenderingProgressEvents.h
Source/WebKit/Shared/API/Cocoa/_WKRenderingProgressEventsInternal.h
Source/WebKit/Shared/API/c/WKPageLoadTypes.h
Source/WebKit/Shared/API/c/WKSharedAPICast.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/significant-text-milestone.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/ios/RenderingProgressTests.mm