Changeset 200778 in webkit


Ignore:
Timestamp:
May 12, 2016, 10:53:38 AM (10 years ago)
Author:
eric.carlson@apple.com
Message:

Adjust "main content" video heuristic
https://bugs.webkit.org/show_bug.cgi?id=157532
Source/WebCore:

<rdar://problem/25840861>

Reviewed by Darin Adler.

Test: media/video-main-content-autoplay.html, plus existing tests updated.

  • html/MediaElementSession.cpp:

(WebCore::MediaElementSession::canControlControlsManager): Use isElementLargeEnoughForMainContent.
(WebCore::isMainContent): Ditto.
(WebCore::isElementLargeEnoughForMainContent): Check video area and aspect ratio.
(WebCore::MediaElementSession::mainContentCheckTimerFired): Call result.setToNonUserAgentShadowAncestor

so it doesn't hit test the video controls in the shadow DOM.

LayoutTests:

Reviewed by Darin Adler.

  • media/video-main-content-allow.html:
  • media/video-main-content-autoplay-expected.txt: Added.
  • media/video-main-content-autoplay.html: Added.
  • media/video-main-content-deny-too-small.html:
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r200769 r200778  
     12016-05-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Adjust "main content" video heuristic
     4        https://bugs.webkit.org/show_bug.cgi?id=157532
     5
     6        Reviewed by Darin Adler.
     7
     8        * media/video-main-content-allow.html:
     9        * media/video-main-content-autoplay-expected.txt: Added.
     10        * media/video-main-content-autoplay.html: Added.
     11        * media/video-main-content-deny-too-small.html:
     12
    1132016-05-12  Antoine Quint  <graouts@apple.com>
    214
  • trunk/LayoutTests/media/video-main-content-allow.html

    r197953 r200778  
    2323    <style>
    2424    video {
    25         width: 600px;
    26         height: 400px;
     25        width: 270px;
     26        height: 480px;
    2727    }
    2828    </style>
  • trunk/LayoutTests/media/video-main-content-deny-too-small.html

    r197953 r200778  
    88    function go() {
    99        video = document.createElement('video');
     10        video.controls = ""
    1011        run('internals.setMediaElementRestrictions(video, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent")');
    1112        document.body.appendChild(video);
     
    2829    <style>
    2930    video {
    30         width: 200px;
    31         height: 100px;
     31        width: 400px;
     32        height: 299px;
    3233    }
    3334    </style>
  • trunk/Source/WebCore/ChangeLog

    r200776 r200778  
     12016-05-12  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Adjust "main content" video heuristic
     4        https://bugs.webkit.org/show_bug.cgi?id=157532
     5        <rdar://problem/25840861>
     6
     7        Reviewed by Darin Adler.
     8
     9        Test: media/video-main-content-autoplay.html, plus existing tests updated.
     10
     11        * html/MediaElementSession.cpp:
     12        (WebCore::MediaElementSession::canControlControlsManager): Use isElementLargeEnoughForMainContent.
     13        (WebCore::isMainContent): Ditto.
     14        (WebCore::isElementLargeEnoughForMainContent): Check video area and aspect ratio.
     15        (WebCore::MediaElementSession::mainContentCheckTimerFired): Call result.setToNonUserAgentShadowAncestor
     16          so it doesn't hit test the video controls in the shadow DOM.
     17
    1182016-05-12  Fujii Hironori  <Hironori.Fujii@sony.com>
    219
  • trunk/Source/WebCore/html/MediaElementSession.cpp

    r200688 r200778  
    5555namespace WebCore {
    5656
    57 static const int elementMainContentMinimumWidth = 400;
    58 static const int elementMainContentMinimumHeight = 300;
    5957static const double elementMainContentCheckInterval = .250;
    6058
    6159static bool isMainContent(const HTMLMediaElement&);
     60static bool isElementLargeEnoughForMainContent(const HTMLMediaElement&);
    6261
    6362#if !LOG_DISABLED
     
    225224        return false;
    226225
    227     if (element.hasVideo() && renderer->clientWidth() >= elementMainContentMinimumWidth && renderer->clientHeight() >= elementMainContentMinimumHeight)
    228             return true;
     226    if (isElementLargeEnoughForMainContent(element))
     227        return true;
    229228
    230229    if (ScriptController::processingUserGestureForMedia())
     
    507506        return false;
    508507
    509     if (renderer->clientWidth() < elementMainContentMinimumWidth
    510         || renderer->clientHeight() < elementMainContentMinimumHeight)
     508    if (!isElementLargeEnoughForMainContent(element))
    511509        return false;
    512510
     
    540538    // Elements which are obscured by other elements cannot be main content.
    541539    mainRenderView.hitTest(request, result);
     540    result.setToNonUserAgentShadowAncestor();
    542541    Element* hitElement = result.innerElement();
    543542    if (hitElement != &element)
     
    547546}
    548547
     548static bool isElementLargeEnoughForMainContent(const HTMLMediaElement& element)
     549{
     550    static const double elementMainContentAreaMinimum = 400 * 300;
     551    static const double maximumAspectRatio = 1.8; // Slightly larger than 16:9.
     552    static const double minimumAspectRatio = .5; // Slightly smaller than 16:9.
     553
     554    // Elements which have not yet been laid out, or which are not yet in the DOM, cannot be main content.
     555    RenderBox* renderer = downcast<RenderBox>(element.renderer());
     556    if (!renderer)
     557        return false;
     558
     559    double width = renderer->clientWidth();
     560    double height = renderer->clientHeight();
     561    double area = width * height;
     562    double aspectRatio = width / height;
     563    return area >= elementMainContentAreaMinimum && aspectRatio >= minimumAspectRatio && aspectRatio <= maximumAspectRatio;
     564}
     565
    549566void MediaElementSession::mainContentCheckTimerFired()
    550567{
Note: See TracChangeset for help on using the changeset viewer.