Title: [285425] trunk/Source/WebCore
- Revision
- 285425
- Author
- [email protected]
- Date
- 2021-11-08 12:55:25 -0800 (Mon, 08 Nov 2021)
Log Message
[Live Text] Add a helper method to remove recognized text from an image element
https://bugs.webkit.org/show_bug.cgi?id=232788
Reviewed by Aditya Keerthi.
Add a couple of helper functions for resetting cached text recognition results, and for removing recognized text
from the shadow root of an image element. These will be used to support enhancements to Live Text in a future
patch. No change in behavior.
* html/HTMLElement.cpp:
(WebCore::HTMLElement::removeImageOverlaySoonIfNeeded):
* html/HTMLElement.h:
* page/Page.cpp:
(WebCore::Page::resetTextRecognitionResult):
* page/Page.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (285424 => 285425)
--- trunk/Source/WebCore/ChangeLog 2021-11-08 20:54:08 UTC (rev 285424)
+++ trunk/Source/WebCore/ChangeLog 2021-11-08 20:55:25 UTC (rev 285425)
@@ -1,3 +1,21 @@
+2021-11-08 Wenson Hsieh <[email protected]>
+
+ [Live Text] Add a helper method to remove recognized text from an image element
+ https://bugs.webkit.org/show_bug.cgi?id=232788
+
+ Reviewed by Aditya Keerthi.
+
+ Add a couple of helper functions for resetting cached text recognition results, and for removing recognized text
+ from the shadow root of an image element. These will be used to support enhancements to Live Text in a future
+ patch. No change in behavior.
+
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::removeImageOverlaySoonIfNeeded):
+ * html/HTMLElement.h:
+ * page/Page.cpp:
+ (WebCore::Page::resetTextRecognitionResult):
+ * page/Page.h:
+
2021-11-08 Antoine Quint <[email protected]>
Discrete animation of content property does not work
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (285424 => 285425)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2021-11-08 20:54:08 UTC (rev 285424)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2021-11-08 20:55:25 UTC (rev 285425)
@@ -1324,8 +1324,40 @@
return false;
}
+void HTMLElement::removeImageOverlaySoonIfNeeded()
+{
+ if (!hasImageOverlay())
+ return;
+
+ document().eventLoop().queueTask(TaskSource::InternalAsyncTask, [weakThis = WeakPtr { *this }] {
+ RefPtr protectedThis = weakThis.get();
+ if (!protectedThis)
+ return;
+
+ RefPtr shadowRoot = protectedThis->userAgentShadowRoot();
+ if (!shadowRoot)
+ return;
+
+ RefPtr<HTMLDivElement> containerToRemove;
+ for (auto& child : childrenOfType<HTMLDivElement>(*shadowRoot)) {
+ if (child.getIdAttribute() == imageOverlayElementIdentifier()) {
+ containerToRemove = &child;
+ break;
+ }
+ }
+
+ if (containerToRemove)
+ containerToRemove->remove();
+
#if ENABLE(IMAGE_ANALYSIS)
+ if (auto page = protectedThis->document().page())
+ page->resetTextRecognitionResult(*protectedThis);
+#endif
+ });
+}
+#if ENABLE(IMAGE_ANALYSIS)
+
IntRect HTMLElement::containerRectForTextRecognition()
{
auto* renderer = this->renderer();
Modified: trunk/Source/WebCore/html/HTMLElement.h (285424 => 285425)
--- trunk/Source/WebCore/html/HTMLElement.h 2021-11-08 20:54:08 UTC (rev 285424)
+++ trunk/Source/WebCore/html/HTMLElement.h 2021-11-08 20:55:25 UTC (rev 285425)
@@ -138,6 +138,7 @@
WEBCORE_EXPORT static bool isInsideImageOverlay(const Node&);
WEBCORE_EXPORT static bool isImageOverlayText(const Node&);
WEBCORE_EXPORT static bool isImageOverlayText(const Node*);
+ void removeImageOverlaySoonIfNeeded();
#if ENABLE(IMAGE_ANALYSIS)
IntRect containerRectForTextRecognition();
Modified: trunk/Source/WebCore/page/Page.cpp (285424 => 285425)
--- trunk/Source/WebCore/page/Page.cpp 2021-11-08 20:54:08 UTC (rev 285424)
+++ trunk/Source/WebCore/page/Page.cpp 2021-11-08 20:55:25 UTC (rev 285425)
@@ -3715,6 +3715,11 @@
m_textRecognitionResults.clear();
}
+void Page::resetTextRecognitionResult(const HTMLElement& element)
+{
+ m_textRecognitionResults.remove(element);
+}
+
#endif // ENABLE(IMAGE_ANALYSIS)
#if ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/page/Page.h (285424 => 285425)
--- trunk/Source/WebCore/page/Page.h 2021-11-08 20:54:08 UTC (rev 285424)
+++ trunk/Source/WebCore/page/Page.h 2021-11-08 20:55:25 UTC (rev 285425)
@@ -890,6 +890,7 @@
#if ENABLE(IMAGE_ANALYSIS)
WEBCORE_EXPORT bool hasCachedTextRecognitionResult(const HTMLElement&) const;
void cacheTextRecognitionResult(const HTMLElement&, const IntRect& containerRect, const TextRecognitionResult&);
+ void resetTextRecognitionResult(const HTMLElement&);
#endif
WEBCORE_EXPORT PermissionController& permissionController();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes