Bug 238555

Summary: HTMLElement.innerText should return the content of a clipped box
Product: WebKit Reporter: zalan <zalan>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, bfulgham, cdumez, darin, rniwa, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: BrowserCompat, InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
test case none

Description zalan 2022-03-30 08:58:18 PDT
Created attachment 456128 [details]
test case

I think we fail at interpreting "being rendered" properly.

https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute says that innerText returns a DOMString representing the rendered text content of an element if it is being rendered.
while "An element is being rendered if it has any associated CSS layout boxes, SVG layout boxes, or some equivalent in other styling languages" (https://html.spec.whatwg.org/multipage/rendering.html#being-rendered)
So I would think clipped content is still considered "being rendered" as we compute geometry/create box for such content.
Comment 1 zalan 2022-03-30 09:24:03 PDT
innerText calls TextIterator::handleTextNode() which early returns when the content is clipped:
"if (m_fullyClippedStack.top() && !m_behaviors.contains(TextIteratorBehavior::IgnoresStyleVisibility))"
Comment 2 Ryosuke Niwa 2022-04-05 10:42:43 PDT
Hm... skipping clipped content stuff comes from this change:
https://github.com/WebKit/WebKit/commit/55e9335cacf138ba817ca25d71e3d8ae66d1ced6

I guess this is really for find so we could add a new TextIterator behavior to not ignore clipped contents and use it in innerText and other places where appropriate.
Comment 3 Ryosuke Niwa 2022-04-05 10:43:39 PDT
Alternatively, we could re-implement innerText as the spec says. There is no reason it has to use innerText if there is a clear spec text which specifies the behavior since TextIterator is used for all sorts of other features like copy & paste, etc... and has a lot of quirky behaviors.
Comment 4 Radar WebKit Bug Importer 2022-04-06 08:59:15 PDT
<rdar://problem/91356685>
Comment 5 Darin Adler 2022-04-07 12:52:31 PDT
TextIteratorBehavior::IgnoresStyleVisibility lets us do this without moving off of TextIterator.

A whole new implementation of innerText is also OK.