Bug 238555 - HTMLElement.innerText should return the content of a clipped box
Summary: HTMLElement.innerText should return the content of a clipped box
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2022-03-30 08:58 PDT by zalan
Modified: 2023-08-01 05:33 PDT (History)
8 users (show)

See Also:


Attachments
test case (281 bytes, text/html)
2022-03-30 08:58 PDT, zalan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.