Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2a2cb3b391a49d217d46149a72dda16107a8e33e
      
https://github.com/WebKit/WebKit/commit/2a2cb3b391a49d217d46149a72dda16107a8e33e
  Author: Timothy Hatcher <[email protected]>
  Date:   2026-07-20 (Mon, 20 Jul 2026)

  Changed paths:
    M Source/WebCore/page/text-extraction/TextExtraction.cpp
    M Source/WebCore/page/text-extraction/TextExtractionTypes.h
    M Source/WebKit/Shared/TextExtractionToStringConversion.cpp
    M Source/WebKit/Shared/TextExtractionToStringConversion.h
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView+TextExtraction.mm
    M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h
    M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm

  Log Message:
  -----------
  [Text Extraction] Add option to include tag names for blocks with inline 
children.
https://webkit.org/b/319821
rdar://problem/182720339

Reviewed by Wenson Hsieh.

The `.textTree` output collapses generic blocks such as headings and paragraphs 
into bare quoted text, which
reads well but discards the element type, leaving structure-aware clients no 
way to recover it.

Add an `includeTagName` option that prefixes each such block's line in 
`.textTree` output with its lowercased
tag name (e.g. `h1 'Title'`). Semantic containers already carry a descriptive 
label, so the option only tags
otherwise-generic blocks that render their own inline content (renderer has 
inline children); block-level
wrappers still collapse and empty blocks are still pruned. Off by default; 
affects only `.textTree`.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm

* Source/WebCore/page/text-extraction/TextExtraction.cpp:
(WebCore::TextExtraction::extractRecursive): When includeTagName is set, 
extract a generic block whose
renderer has inline children so its tag prefixes the text; block-level wrappers 
still collapse.
* Source/WebCore/page/text-extraction/TextExtractionTypes.h: Add the 
includeTagName request flag.
* Source/WebKit/Shared/TextExtractionToStringConversion.cpp:
(WebKit::TextExtractionAggregator::includeTagName const): True only for 
.textTree output with the flag set.
(WebKit::addPartsForItem): Emit the lowercased tag name as a generic 
container's line prefix when it has no label.
* Source/WebKit/Shared/TextExtractionToStringConversion.h: Add the 
IncludeTagName option flag.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: Serialize the 
new request flag.
* Source/WebKit/UIProcess/API/Cocoa/WKWebView+TextExtraction.mm:
(-[WKWebView 
_extractDebugTextWithConfigurationWithoutUpdatingFilterRules:assertionScope:completionHandler:]):
Map the configuration property onto the IncludeTagName option flag.
(-[WKWebView _requestTextExtractionInternal:completion:]): Thread the 
configuration property into the request.
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h: Declare the 
includeTagName property.
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm:
(-[_WKTextExtractionConfiguration init]): Default includeTagName to NO.
(-[_WKTextExtractionConfiguration configureForMinimalOutput]): Leave 
includeTagName off for minimal output.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm:
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNamePrefixesContentBlocks)): Added.
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNameTagsBlockWithOnlyInlineContent)): Added.
(TestWebKitAPI::TEST(TextExtractionTests, IncludeTagNameDisabledByDefault)): 
Added.
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNameCollapsesMixedInlineAndBlockContent)): Added.
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNameDropsEmptyAndWhitespaceBlocks)): Added.
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNameKeepsSemanticLabelForStructuralContainers)): Added.
(TestWebKitAPI::TEST(TextExtractionTests, 
IncludeTagNameFlattensInlineElementsIntoBlockText)): Added.

Canonical link: https://commits.webkit.org/317575@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to