Changeset 278747 in webkit
- Timestamp:
- Jun 10, 2021 6:22:52 PM (13 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/images/text-recognition/image-overlay-size-change-expected.txt (added)
-
LayoutTests/fast/images/text-recognition/image-overlay-size-change.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/HTMLElement.cpp (modified) (2 diffs)
-
Source/WebCore/html/HTMLElement.h (modified) (1 diff)
-
Source/WebCore/page/Page.cpp (modified) (4 diffs)
-
Source/WebCore/page/Page.h (modified) (6 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.cpp (modified) (5 diffs)
-
Source/WebKit/WebProcess/WebPage/WebPage.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r278743 r278747 1 2021-06-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Live Text] Add a mechanism to regenerate text in an image element when it changes dimensions 4 https://bugs.webkit.org/show_bug.cgi?id=226858 5 rdar://77522786 6 7 Reviewed by Devin Rousso. 8 9 * fast/images/text-recognition/image-overlay-size-change-expected.txt: Added. 10 * fast/images/text-recognition/image-overlay-size-change.html: Added. 11 1 12 2021-06-10 Arcady Goldmints-Orlov <agoldmints@igalia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r278746 r278747 1 2021-06-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Live Text] Add a mechanism to regenerate text in an image element when it changes dimensions 4 https://bugs.webkit.org/show_bug.cgi?id=226858 5 rdar://77522786 6 7 Reviewed by Devin Rousso. 8 9 Push `m_elementsWithTextRecognitionResults` from WebPage down to Page, and additionally keep track of a 10 TextRecognitionResult per element, as well as the size of the element at the time when we last injected text 11 recognition results. Use this information to tell elements to update their OCR text containers if their 12 dimenions have changed since the last update, after finishing a rendering update. 13 14 Test: fast/images/text-recognition/image-overlay-size-change.html 15 16 * html/HTMLElement.cpp: 17 (WebCore::HTMLElement::updateWithTextRecognitionResult): 18 19 Refactor this to take a `const TextRecognitionResult&` instead of a `TextRecognitionResult&&`, since this method 20 doesn't actually take ownership of the TextRecognitionResult. This allows us to avoid explicitly copying a 21 TextRecognitionResult when calling this method from `Page::updateElementsWithTextRecognitionResults`. Also, add 22 a CacheTextRecognitionResults enum flag as an argument, to avoid entering `Page::cacheTextRecognitionResult` 23 every time we update a resized element in `Page::updateElementsWithTextRecognitionResults`; since we know that 24 the dimensions are the only thing that changed, we simply update the cached dimensions. 25 26 Call into `Page::cacheTextRecognitionResult` to store per-element TextRecognitionResults when we 27 finish injecting the OCR text and data detectors into the image element. 28 29 * html/HTMLElement.h: 30 * page/Page.cpp: 31 (WebCore::Page::didCommitLoad): 32 33 Clear out both `m_textRecognitionResultsByElement` and `m_elementsWithTextRecognitionResults`. 34 35 (WebCore::Page::doAfterUpdateRendering): 36 37 At the end of each rendering update, go through `m_elementsWithTextRecognitionResults` and check if any of the 38 elements' dimensions have changed; if so, tell those elements to re-update their OCR text quads and data 39 detectors in the UA shadow tree. 40 41 (WebCore::Page::resetTextRecognitionResults): 42 (WebCore::Page::updateElementsWithTextRecognitionResults): 43 (WebCore::Page::hasCachedTextRecognitionResult const): 44 (WebCore::Page::cacheTextRecognitionResult): 45 46 Add the element to `m_elementsWithTextRecognitionResults` and `m_textRecognitionResultsByElement`, appending a 47 new entry to `m_textRecognitionResultsByElement` only if necessary. 48 49 * page/Page.h: 50 1 51 2021-06-10 Chris Dumez <cdumez@apple.com> 2 52 -
trunk/Source/WebCore/html/HTMLElement.cpp
r278689 r278747 1332 1332 #if ENABLE(IMAGE_ANALYSIS) 1333 1333 1334 void HTMLElement::updateWithTextRecognitionResult( TextRecognitionResult&& result)1334 void HTMLElement::updateWithTextRecognitionResult(const TextRecognitionResult& result, CacheTextRecognitionResults cacheTextRecognitionResults) 1335 1335 { 1336 1336 RefPtr<HTMLDivElement> previousContainer; … … 1510 1510 if (auto frame = makeRefPtr(document().frame())) 1511 1511 frame->eventHandler().scheduleCursorUpdate(); 1512 1513 if (cacheTextRecognitionResults == CacheTextRecognitionResults::Yes) { 1514 if (auto* page = document().page()) 1515 page->cacheTextRecognitionResult(*this, containerSize, result); 1516 } 1512 1517 } 1513 1518 -
trunk/Source/WebCore/html/HTMLElement.h
r278575 r278747 140 140 141 141 #if ENABLE(IMAGE_ANALYSIS) 142 WEBCORE_EXPORT void updateWithTextRecognitionResult(TextRecognitionResult&&); 142 enum class CacheTextRecognitionResults : bool { No, Yes }; 143 WEBCORE_EXPORT void updateWithTextRecognitionResult(const TextRecognitionResult&, CacheTextRecognitionResults = CacheTextRecognitionResults::Yes); 143 144 #endif 144 145 -
trunk/Source/WebCore/page/Page.cpp
r278498 r278747 137 137 #include "SubframeLoader.h" 138 138 #include "TextIterator.h" 139 #include "TextRecognitionResult.h" 139 140 #include "TextResourceDecoder.h" 140 141 #include "UserContentProvider.h" … … 1275 1276 resetSeenPlugins(); 1276 1277 resetSeenMediaEngines(); 1278 1279 #if ENABLE(IMAGE_ANALYSIS) 1280 resetTextRecognitionResults(); 1281 #endif 1277 1282 } 1278 1283 … … 1660 1665 document.updateTextTrackRepresentationImageIfNeeded(); 1661 1666 }); 1667 #endif 1668 1669 #if ENABLE(IMAGE_ANALYSIS) 1670 updateElementsWithTextRecognitionResults(); 1662 1671 #endif 1663 1672 … … 3604 3613 } 3605 3614 3615 #if ENABLE(IMAGE_ANALYSIS) 3616 3617 void Page::updateElementsWithTextRecognitionResults() 3618 { 3619 if (m_textRecognitionResultsByElement.isEmpty()) 3620 return; 3621 3622 m_textRecognitionResultsByElement.removeAllMatching([](auto& elementAndResult) { 3623 return !elementAndResult.first; 3624 }); 3625 3626 for (auto& [element, resultAndSize] : m_textRecognitionResultsByElement) { 3627 if (!element || !element->isConnected()) 3628 continue; 3629 3630 auto protectedElement = makeRef(*element); 3631 auto& [result, offsetSize] = resultAndSize; 3632 IntSize newOffsetSize { protectedElement->offsetWidth(), protectedElement->offsetHeight() }; 3633 if (offsetSize == newOffsetSize) 3634 continue; 3635 3636 offsetSize = newOffsetSize; 3637 protectedElement->updateWithTextRecognitionResult(result, HTMLElement::CacheTextRecognitionResults::No); 3638 } 3639 } 3640 3641 bool Page::hasCachedTextRecognitionResult(const HTMLElement& element) const 3642 { 3643 return m_elementsWithTextRecognitionResults.contains(element); 3644 } 3645 3646 void Page::cacheTextRecognitionResult(const HTMLElement& element, const IntSize& offsetSize, const TextRecognitionResult& result) 3647 { 3648 m_elementsWithTextRecognitionResults.add(element); 3649 3650 auto index = m_textRecognitionResultsByElement.findMatching([&](auto& elementAndResult) { 3651 return elementAndResult.first == &element; 3652 }); 3653 3654 if (index == notFound) 3655 m_textRecognitionResultsByElement.append({ makeWeakPtr(element), { result, offsetSize } }); 3656 else 3657 m_textRecognitionResultsByElement[index].second = { result, offsetSize }; 3658 3659 m_textRecognitionResultsByElement.removeAllMatching([](auto& elementAndResult) { 3660 return !elementAndResult.first; 3661 }); 3662 } 3663 3664 void Page::resetTextRecognitionResults() 3665 { 3666 m_textRecognitionResultsByElement.clear(); 3667 m_elementsWithTextRecognitionResults.clear(); 3668 } 3669 3670 #endif // ENABLE(IMAGE_ANALYSIS) 3671 3606 3672 } // namespace WebCore -
trunk/Source/WebCore/page/Page.h
r278482 r278747 108 108 class FormData; 109 109 class Frame; 110 class HTMLElement; 110 111 class HTMLMediaElement; 111 112 class HistoryItem; … … 113 114 class InspectorClient; 114 115 class InspectorController; 116 class IntSize; 115 117 class LibWebRTCProvider; 116 118 class LowPowerModeNotifier; … … 159 161 160 162 struct SimpleRange; 163 struct TextRecognitionResult; 161 164 162 165 using PlatformDisplayID = uint32_t; … … 861 864 void setLoadSchedulingMode(LoadSchedulingMode); 862 865 866 #if ENABLE(IMAGE_ANALYSIS) 867 WEBCORE_EXPORT bool hasCachedTextRecognitionResult(const HTMLElement&) const; 868 void cacheTextRecognitionResult(const HTMLElement&, const IntSize& offsetSize, const TextRecognitionResult&); 869 #endif 870 863 871 private: 864 872 struct Navigation { … … 905 913 906 914 WheelEventTestMonitor& ensureWheelEventTestMonitor(); 915 916 #if ENABLE(IMAGE_ANALYSIS) 917 void resetTextRecognitionResults(); 918 void updateElementsWithTextRecognitionResults(); 919 #endif 907 920 908 921 const std::unique_ptr<Chrome> m_chrome; … … 1176 1189 const bool m_httpsUpgradeEnabled { true }; 1177 1190 mutable MediaSessionGroupIdentifier m_mediaSessionGroupIdentifier; 1191 1192 #if ENABLE(IMAGE_ANALYSIS) 1193 // FIXME: These should be refactored to use a weak hash map of HTMLElement to std::pair<TextRecognitionResult, IntSize>. 1194 Vector<std::pair<WeakPtr<HTMLElement>, std::pair<TextRecognitionResult, IntSize>>> m_textRecognitionResultsByElement; 1195 WeakHashSet<HTMLElement> m_elementsWithTextRecognitionResults; 1196 #endif 1178 1197 }; 1179 1198 -
trunk/Source/WebKit/ChangeLog
r278745 r278747 1 2021-06-10 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Live Text] Add a mechanism to regenerate text in an image element when it changes dimensions 4 https://bugs.webkit.org/show_bug.cgi?id=226858 5 rdar://77522786 6 7 Reviewed by Devin Rousso. 8 9 Push `m_elementsWithTextRecognitionResults` from `WebKit::WebPage` down to `WebCore::Page`. See WebCore 10 ChangeLog for more details. 11 12 * WebProcess/WebPage/WebPage.cpp: 13 (WebKit::WebPage::didCommitLoad): 14 (WebKit::WebPage::requestTextRecognition): 15 (WebKit::WebPage::updateWithTextRecognitionResult): 16 * WebProcess/WebPage/WebPage.h: 17 1 18 2021-06-10 Per Arne Vollan <pvollan@apple.com> 2 19 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r278737 r278747 6291 6291 } 6292 6292 m_elementsPendingTextRecognition.clear(); 6293 m_elementsWithTextRecognitionResults.clear();6294 6293 #endif 6295 6294 … … 7397 7396 } 7398 7397 7399 if (m_elementsWithTextRecognitionResults.contains(element)) { 7398 auto htmlElement = makeRef(downcast<HTMLElement>(element)); 7399 if (corePage()->hasCachedTextRecognitionResult(htmlElement.get())) { 7400 7400 if (completion) { 7401 ASSERT(is<HTMLElement>(element));7402 7401 RefPtr<Element> imageOverlayHost; 7403 if ( is<HTMLElement>(element) && downcast<HTMLElement>(element).hasImageOverlay())7402 if (htmlElement->hasImageOverlay()) 7404 7403 imageOverlayHost = makeRefPtr(element); 7405 7404 completion(WTFMove(imageOverlayHost)); … … 7467 7466 7468 7467 auto& htmlElement = downcast<HTMLElement>(*protectedElement); 7469 htmlElement.updateWithTextRecognitionResult(WTFMove(result)); 7470 protectedPage->m_elementsWithTextRecognitionResults.add(htmlElement); 7468 htmlElement.updateWithTextRecognitionResult(result); 7471 7469 7472 7470 auto matchIndex = protectedPage->m_elementsPendingTextRecognition.findMatching([&] (auto& elementAndCompletionHandlers) { … … 7485 7483 } 7486 7484 7487 void WebPage::updateWithTextRecognitionResult( TextRecognitionResult&& result, const ElementContext& context, const FloatPoint& location, CompletionHandler<void(TextRecognitionUpdateResult)>&& completionHandler)7485 void WebPage::updateWithTextRecognitionResult(const TextRecognitionResult& result, const ElementContext& context, const FloatPoint& location, CompletionHandler<void(TextRecognitionUpdateResult)>&& completionHandler) 7488 7486 { 7489 7487 auto elementToUpdate = elementForContext(context); … … 7493 7491 } 7494 7492 7495 downcast<HTMLElement>(*elementToUpdate).updateWithTextRecognitionResult( WTFMove(result));7493 downcast<HTMLElement>(*elementToUpdate).updateWithTextRecognitionResult(result); 7496 7494 auto hitTestResult = corePage()->mainFrame().eventHandler().hitTestResultAtPoint(roundedIntPoint(location), { 7497 7495 HitTestRequest::Type::ReadOnly, -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r278712 r278747 245 245 struct RunJavaScriptParameters; 246 246 struct TextCheckingResult; 247 struct TextRecognitionResult; 247 248 struct ViewportArguments; 248 249 … … 1405 1406 #if ENABLE(IMAGE_ANALYSIS) 1406 1407 void requestTextRecognition(WebCore::Element&, CompletionHandler<void(RefPtr<WebCore::Element>&&)>&&); 1407 void updateWithTextRecognitionResult( WebCore::TextRecognitionResult&&, const WebCore::ElementContext&, const WebCore::FloatPoint& location, CompletionHandler<void(TextRecognitionUpdateResult)>&&);1408 void updateWithTextRecognitionResult(const WebCore::TextRecognitionResult&, const WebCore::ElementContext&, const WebCore::FloatPoint& location, CompletionHandler<void(TextRecognitionUpdateResult)>&&); 1408 1409 #endif 1409 1410 … … 2349 2350 #if ENABLE(IMAGE_ANALYSIS) 2350 2351 Vector<std::pair<WeakPtr<WebCore::HTMLElement>, Vector<CompletionHandler<void(RefPtr<WebCore::Element>&&)>>>> m_elementsPendingTextRecognition; 2351 WeakHashSet<WebCore::HTMLElement> m_elementsWithTextRecognitionResults;2352 2352 #endif 2353 2353
Note: See TracChangeset
for help on using the changeset viewer.