Bug 1758564 - Allow rendering children of <img>'s shadow root. r=dholbert

This doesn't change behavior just yet, but seems worth doing separately.

With this patch, we can render content overlaid on top of an image
frame, by attaching a shadow root to it. The idea is to use this for
text recognition (OCR) of text inside images.

I chose to implement this using the DynamicLeaf stuff that I removed in
bug 1746310 (because nsMenuPopupFrame was its only user).

That seems simpler than either a new frame class, or more special cases
in the frame constructor, etc. But let me know if you disagree.

There are further changes that we want to do. For example, trying to
select the overlaid text with the mouse right now will start dragging
the image. For that, we might need to tweak our selection / mouse
dragging code. But those seem all changes that can go on top of this.

Differential Revision: https://phabricator.services.mozilla.com/D140638
This commit is contained in:
Emilio Cobos Álvarez
2022-03-10 05:11:38 +00:00
parent cc44a214ef
commit 79e1d54c07
7 changed files with 67 additions and 6 deletions

View File

@@ -1681,6 +1681,14 @@ void nsCSSFrameConstructor::CreateGeneratedContentFromListStyleType(
aAddChild(child);
}
// Frames for these may not be leaves in the proper sense, but we still don't
// want to expose generated content on them. For the purposes of the page they
// should be leaves.
static bool HasUAWidget(const Element& aOriginatingElement) {
const ShadowRoot* sr = aOriginatingElement.GetShadowRoot();
return sr && sr->IsUAWidget();
}
/*
* aParentFrame - the frame that should be the parent of the generated
* content. This is the frame for the corresponding content node,
@@ -1705,10 +1713,7 @@ void nsCSSFrameConstructor::CreateGeneratedContentItem(
aPseudoElement == PseudoStyleType::marker,
"unexpected aPseudoElement");
if (aParentFrame && (aParentFrame->IsHTMLVideoFrame() ||
aParentFrame->IsDateTimeControlFrame())) {
// Video frames and date time control frames may not be leafs when backed by
// an UA widget, but we still don't want to expose generated content.
if (HasUAWidget(aOriginatingElement)) {
return;
}