Changeset 282740 in webkit


Ignore:
Timestamp:
Sep 19, 2021, 5:10:37 PM (4 years ago)
Author:
Wenson Hsieh
Message:

Teach WebKit::createShareableBitmap to snapshot video elements
https://bugs.webkit.org/show_bug.cgi?id=230468

Reviewed by Tim Horton.

Source/WebCore:

Now that createShareableBitmap may return images for video elements, we need to ensure that we explicitly
avoid allowing Live Text in video elements, since doing so will (1) break built-in platform media controls,
which also share the same shadow root, and (2) lead to confusing results when playing or seeking in videos,
since the recognized text falls out of sync with the video frame.

  • html/HTMLVideoElement.h:
  • page/EventHandler.cpp:

(WebCore::EventHandler::textRecognitionCandidateElement const):

For the above reasons, we refactor logic to check if the currently hovered node is a candidate for text
recognition, such that the video element check is consolidated all in one place.

(WebCore::EventHandler::updateMouseEventTargetNode):
(WebCore::EventHandler::textRecognitionHoverTimerFired):

  • page/EventHandler.h:
  • rendering/RenderVideo.h:

Source/WebKit:

createShareableBitmap currently only returns a non-null image bitmap for image renderers that have cached
images; notably, this omits video elements. For use in future patches, we should allow this helper function to
handle video elements by snapshotting the current frame of the video.

  • WebProcess/WebCoreSupport/ShareableBitmapUtilities.cpp:

(WebKit::createShareableBitmap):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r282738 r282740  
     12021-09-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Teach `WebKit::createShareableBitmap` to snapshot video elements
     4        https://bugs.webkit.org/show_bug.cgi?id=230468
     5
     6        Reviewed by Tim Horton.
     7
     8        Now that `createShareableBitmap` may return images for video elements, we need to ensure that we explicitly
     9        avoid allowing Live Text in video elements, since doing so will (1) break built-in platform media controls,
     10        which also share the same shadow root, and (2) lead to confusing results when playing or seeking in videos,
     11        since the recognized text falls out of sync with the video frame.
     12
     13        * html/HTMLVideoElement.h:
     14        * page/EventHandler.cpp:
     15        (WebCore::EventHandler::textRecognitionCandidateElement const):
     16
     17        For the above reasons, we refactor logic to check if the currently hovered node is a candidate for text
     18        recognition, such that the video element check is consolidated all in one place.
     19
     20        (WebCore::EventHandler::updateMouseEventTargetNode):
     21        (WebCore::EventHandler::textRecognitionHoverTimerFired):
     22        * page/EventHandler.h:
     23        * rendering/RenderVideo.h:
     24
    1252021-09-19  Alan Bujtas  <zalan@apple.com>
    226
  • trunk/Source/WebCore/html/HTMLVideoElement.h

    r278277 r282740  
    7878    void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
    7979
    80     RefPtr<NativeImage> nativeImageForCurrentTime();
     80    WEBCORE_EXPORT RefPtr<NativeImage> nativeImageForCurrentTime();
    8181
    8282    WEBCORE_EXPORT bool shouldDisplayPosterImage() const;
  • trunk/Source/WebCore/page/EventHandler.cpp

    r282480 r282740  
    6464#include "HTMLInputElement.h"
    6565#include "HTMLNames.h"
     66#include "HTMLVideoElement.h"
    6667#include "HitTestRequest.h"
    6768#include "HitTestResult.h"
     
    8485#include "Range.h"
    8586#include "RenderFrameSet.h"
     87#include "RenderImage.h"
    8688#include "RenderLayer.h"
    8789#include "RenderLayerScrollableArea.h"
     
    25132515}
    25142516
     2517RefPtr<Element> EventHandler::textRecognitionCandidateElement() const
     2518{
     2519    RefPtr shadowHost = m_elementUnderMouse ? m_elementUnderMouse->shadowHost() : nullptr;
     2520    if (!shadowHost)
     2521        return nullptr;
     2522
     2523    auto renderer = shadowHost->renderer();
     2524    if (!is<RenderImage>(renderer))
     2525        return nullptr;
     2526
     2527    if (is<HTMLVideoElement>(*shadowHost))
     2528        return nullptr;
     2529
     2530    return shadowHost;
     2531}
     2532
    25152533void EventHandler::updateMouseEventTargetNode(const AtomString& eventType, Node* targetNode, const PlatformMouseEvent& platformMouseEvent, FireMouseOverOut fireMouseOverOut)
    25162534{
     
    25322550#if ENABLE(IMAGE_ANALYSIS)
    25332551    if (m_frame.settings().preferInlineTextSelectionInImages()) {
    2534         if (!m_elementUnderMouse || !is<RenderImage>(m_elementUnderMouse->renderer()))
     2552        if (!textRecognitionCandidateElement())
    25352553            m_textRecognitionHoverTimer.stop();
    25362554        else if (!platformMouseEvent.movementDelta().isZero())
     
    34113429void EventHandler::textRecognitionHoverTimerFired()
    34123430{
    3413     if (!m_elementUnderMouse || !is<RenderImage>(m_elementUnderMouse->renderer()))
     3431    auto element = this->textRecognitionCandidateElement();
     3432    if (!element)
    34143433        return;
    34153434
    34163435    if (auto* page = m_frame.page())
    3417         page->chrome().client().requestTextRecognition(*m_elementUnderMouse);
     3436        page->chrome().client().requestTextRecognition(*element);
    34183437}
    34193438
  • trunk/Source/WebCore/page/EventHandler.h

    r281247 r282740  
    364364#endif
    365365
     366    RefPtr<Element> textRecognitionCandidateElement() const;
     367
    366368    bool eventActivatedView(const PlatformMouseEvent&) const;
    367369    bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity);
  • trunk/Source/WebCore/rendering/RenderVideo.h

    r269407 r282740  
    3939    virtual ~RenderVideo();
    4040
    41     HTMLVideoElement& videoElement() const;
     41    WEBCORE_EXPORT HTMLVideoElement& videoElement() const;
    4242
    4343    WEBCORE_EXPORT IntRect videoBox() const;
  • trunk/Source/WebKit/ChangeLog

    r282712 r282740  
     12021-09-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Teach `WebKit::createShareableBitmap` to snapshot video elements
     4        https://bugs.webkit.org/show_bug.cgi?id=230468
     5
     6        Reviewed by Tim Horton.
     7
     8        `createShareableBitmap` currently only returns a non-null image bitmap for image renderers that have cached
     9        images; notably, this omits video elements. For use in future patches, we should allow this helper function to
     10        handle video elements by snapshotting the current frame of the video.
     11
     12        * WebProcess/WebCoreSupport/ShareableBitmapUtilities.cpp:
     13        (WebKit::createShareableBitmap):
     14
    1152021-09-17  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/ShareableBitmapUtilities.cpp

    r280271 r282740  
    3737#include <WebCore/PlatformScreen.h>
    3838#include <WebCore/RenderImage.h>
     39#include <WebCore/RenderVideo.h>
    3940
    4041namespace WebKit {
     
    7172    }
    7273
     74    if (is<RenderVideo>(renderImage)) {
     75        auto& renderVideo = downcast<RenderVideo>(renderImage);
     76        Ref video = renderVideo.videoElement();
     77        auto image = video->nativeImageForCurrentTime();
     78        if (!image)
     79            return { };
     80
     81        auto imageSize = image->size();
     82        if (imageSize.isEmpty() || imageSize.width() <= 1 || imageSize.height() <= 1)
     83            return { };
     84
     85        auto bitmap = ShareableBitmap::createShareable(imageSize, { WTFMove(colorSpaceForBitmap) });
     86        if (!bitmap)
     87            return { };
     88
     89        auto context = bitmap->createGraphicsContext();
     90        if (!context)
     91            return { };
     92
     93        context->drawNativeImage(*image, imageSize, FloatRect { { }, imageSize }, FloatRect { { }, imageSize });
     94        return bitmap;
     95    }
     96
    7397    auto* cachedImage = renderImage.cachedImage();
    7498    if (!cachedImage || cachedImage->errorOccurred())
Note: See TracChangeset for help on using the changeset viewer.