Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Text text selection in image goes offscreen in Mail #13865

Merged
merged 1 commit into from May 17, 2023

Conversation

rr-codes
Copy link
Contributor

@rr-codes rr-codes commented May 14, 2023

9477772

Live Text text selection in image goes offscreen in Mail
https://bugs.webkit.org/show_bug.cgi?id=256772
rdar://108597859

Reviewed by Wenson Hsieh.

In `ImageOverlay::updateWithTextRecognitionResult`, the `sizeBeforeTransform` is empty in the case
of selecting text in an image in Mail. This is because the renderer returned by `textContainer->renderBoxModelObject()`
is `nullptr`, so `sizeBeforeTransform` is never set.

This renderer is null because it is never created, because `shouldCreateRenderer` returns `false`,
ultimately because `RenderImage::hasShadowContent` returns `false`. This method returns `false`
because `m_hasImageOverlay` is `false`.

In the constructor of `RenderImage`, `m_hasImageOverlay` is initialized to the result of
`ImageOverlay::hasOverlay`. _This_ method returns `false` because the shadow root has no element
who's id is that of `imageOverlayElementIdentifier`.

`updateSubtree` in `ImageOverlay` is what is responsible for setting the id of the root shadow
element to `imageOverlayElementIdentifier`.

In the case of Safari, `updateSubtree` is called first, and then the constructor of `RenderImage`
is called, which ensures that the renderer is ultimately created. However, in Mail, the `RenderImage`
constructor is called first, and so at that time there's no `imageOverlayElementIdentifier` element,
which leads to the renderer never being created.

This PR fixes this by ensuring that `RenderImage::hasShadowContent` returns `true` if the element
has a shadow root in `updateSubtree`, by setting `RenderImage::setHasImageOverlay`.

* LayoutTests/fast/images/text-recognition/image-overlay-with-attachment-element-expected.txt: Added.
* LayoutTests/fast/images/text-recognition/image-overlay-with-attachment-element.html: Added.
* Source/WebCore/dom/ImageOverlay.cpp:
(WebCore::ImageOverlay::updateSubtree):

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

14221b0

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@rr-codes rr-codes self-assigned this May 14, 2023
@rr-codes rr-codes added the HTML Editing For bugs in HTML editing support (including designMode and contentEditable). label May 14, 2023
@rr-codes rr-codes requested a review from whsieh May 14, 2023 22:31
@@ -280,6 +280,9 @@ static Elements updateSubtree(HTMLElement& element, const TextRecognitionResult&
#endif // ENABLE(MODERN_MEDIA_CONTROLS)

if (RefPtr shadowRoot = element.shadowRoot()) {
if (auto* renderer = dynamicDowncast<RenderImage>(element.renderer()))
renderer->setHasImageOverlay();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm basically just co-opting "hasImageOverlay" to mean "has shadow content", since that's what it effectively means, and I figured this was preferable to introducing a new method / member variable to RenderImage

@whsieh
Copy link
Member

whsieh commented May 14, 2023

Is it possible to write a test for this?

@rr-codes
Copy link
Contributor Author

Is it possible to write a test for this?

I tried to, but I wasn't sure how to artificially get it into the same state as Mail such that the RenderImage constructor is called before updateSubtree.

@rr-codes
Copy link
Contributor Author

rr-codes commented May 14, 2023

Is it possible to write a test for this?

I tried to, but I wasn't sure how to artificially get it into the same state as Mail such that the RenderImage constructor is called before updateSubtree.

oh maybe I can replicate it if I use < attachment>

@whsieh
Copy link
Member

whsieh commented May 14, 2023

oh maybe I can replicate it if I use < attachment>

Yeah, makes sense β€” HTMLAttachmentElement.getAttachmentIdentifier() is specific to Mail/Notes, and would cause the image element to gain a shadow root before Live Text code is triggered, which might in turn explain why Live Text code ends up getting confused in Mail and not Safari.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 16, 2023
@rr-codes rr-codes removed the merging-blocked Applied to prevent a change from being merged label May 16, 2023
@rr-codes rr-codes added the merge-queue Applied to send a pull request to merge-queue label May 17, 2023
https://bugs.webkit.org/show_bug.cgi?id=256772
rdar://108597859

Reviewed by Wenson Hsieh.

In `ImageOverlay::updateWithTextRecognitionResult`, the `sizeBeforeTransform` is empty in the case
of selecting text in an image in Mail. This is because the renderer returned by `textContainer->renderBoxModelObject()`
is `nullptr`, so `sizeBeforeTransform` is never set.

This renderer is null because it is never created, because `shouldCreateRenderer` returns `false`,
ultimately because `RenderImage::hasShadowContent` returns `false`. This method returns `false`
because `m_hasImageOverlay` is `false`.

In the constructor of `RenderImage`, `m_hasImageOverlay` is initialized to the result of
`ImageOverlay::hasOverlay`. _This_ method returns `false` because the shadow root has no element
who's id is that of `imageOverlayElementIdentifier`.

`updateSubtree` in `ImageOverlay` is what is responsible for setting the id of the root shadow
element to `imageOverlayElementIdentifier`.

In the case of Safari, `updateSubtree` is called first, and then the constructor of `RenderImage`
is called, which ensures that the renderer is ultimately created. However, in Mail, the `RenderImage`
constructor is called first, and so at that time there's no `imageOverlayElementIdentifier` element,
which leads to the renderer never being created.

This PR fixes this by ensuring that `RenderImage::hasShadowContent` returns `true` if the element
has a shadow root in `updateSubtree`, by setting `RenderImage::setHasImageOverlay`.

* LayoutTests/fast/images/text-recognition/image-overlay-with-attachment-element-expected.txt: Added.
* LayoutTests/fast/images/text-recognition/image-overlay-with-attachment-element.html: Added.
* Source/WebCore/dom/ImageOverlay.cpp:
(WebCore::ImageOverlay::updateSubtree):

Canonical link: https://commits.webkit.org/264156@main
@webkit-commit-queue
Copy link
Collaborator

Committed 264156@main (9477772): https://commits.webkit.org/264156@main

Reviewed commits have been landed. Closing PR #13865 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 9477772 into WebKit:main May 17, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTML Editing For bugs in HTML editing support (including designMode and contentEditable).
Projects
None yet
5 participants