Changeset 150371 in webkit


Ignore:
Timestamp:
May 20, 2013 9:47:07 AM (11 years ago)
Author:
Antoine Quint
Message:

[Mac] captions menu should behave more like a menu
https://bugs.webkit.org/show_bug.cgi?id=116436

Reviewed by Eric Carlson.

Let the captions menu behave more like a native Mac menu by hiding it when
clicking anywhere on the page and preventing the page from scrolling when
attempting to scroll the captions menu when it cannot scroll in the requested
direction.

Test: media/video-controls-captions-trackmenu-hide-on-click-outside.html

  • dom/EventListener.h:

Add the new MediaControlsAppleEventListenerType.

  • html/shadow/MediaControlsApple.cpp:

(WebCore::MediaControlsApple::defaultEventHandler):
(WebCore::MediaControlsApple::hide):
(WebCore::MediaControlsApple::makeTransparent):
(WebCore::MediaControlsApple::changedClosedCaptionsVisibility):
(WebCore::MediaControlsApple::reportedError):
(WebCore::MediaControlsApple::toggleClosedCaptionTrackList):
Use the hideClosedCaptionTrackList() and showClosedCaptionTrackList()
methods to hide and show the captions menu instead of calling hide()
and show() directly on m_closedCaptionsContainer.

(WebCore::MediaControlsApple::showClosedCaptionTrackList):
Show the m_closedCaptionsContainer and register a "mousewheel" event
listener on it as well as a "click" event listener on the entire document.

(WebCore::MediaControlsApple::hideClosedCaptionTrackList):
Hide the m_closedCaptionsContainer and remove the "mousewheel" event
listener on it as well as the "click" event listener on the entire document.

(WebCore::MediaControlsApple::shouldClosedCaptionsContainerPreventPageScrolling):
New private utility to determine whether the m_closedCaptionsContainer can scroll
in the provided scroll direction.

(WebCore::MediaControlsApple::eventListener):
Obtain the event listener used for "mousewheel" and "click" event handlers.

(WebCore::MediaControlsAppleEventListener::handleEvent):
Event handler for the "mousewheel" and "click" events. If we get a "click" event, we
toggle the captions menu visibility and if we get a "mousewheel" event, we call into
shouldClosedCaptionsContainerPreventPageScrolling() to see if we can scroll in the
current scroll direction, and if not prevent the event from resulting in a scroll by
calling preventDefault().

(WebCore::MediaControlsAppleEventListener::operator==):
Required for the successful subclassing of EventListener.

  • html/shadow/MediaControlsApple.h:

(MediaControlsAppleEventListener):
(WebCore::MediaControlsAppleEventListener::create):
(WebCore::MediaControlsAppleEventListener::cast):
(WebCore::MediaControlsAppleEventListener::MediaControlsAppleEventListener):
New subclass of EventListener required to provide a custom event listener for the
"mousewheel" and "click" events registered in showClosedCaptionTrackList() and
hideClosedCaptionTrackList().

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r150370 r150371  
     12013-05-20  Antoine Quint  <graouts@apple.com>
     2
     3        [Mac] captions menu should behave more like a menu
     4        https://bugs.webkit.org/show_bug.cgi?id=116436
     5
     6        Reviewed by Eric Carlson.
     7
     8        New test that checks that the caption menu hides when clicking outside
     9        of the bounds of the media element.
     10
     11        * media/video-controls-captions-trackmenu-hide-on-click-outside-expected.txt: Added.
     12        * media/video-controls-captions-trackmenu-hide-on-click-outside.html: Added.
     13        * platform/efl/TestExpectations:
     14        * platform/gtk/TestExpectations:
     15        * platform/qt/TestExpectations:
     16        * platform/win/TestExpectations:
     17
    1182013-05-18  Rashmi Shyamasundar  <rashmi.s2@samsung.com>
    219
  • trunk/LayoutTests/platform/efl/TestExpectations

    r150368 r150371  
    16191619webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
    16201620webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click.html [ Skip ]
     1621webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click-outside.html [ Skip ]
    16211622webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
    16221623
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r150275 r150371  
    745745webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
    746746webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click.html [ Skip ]
     747webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click-outside.html [ Skip ]
    747748webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
    748749
  • trunk/LayoutTests/platform/qt/TestExpectations

    r150250 r150371  
    25982598webkit.org/b/101670 media/video-controls-captions-trackmenu-localized.html [ Skip ]
    25992599webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click.html [ Skip ]
     2600webkit.org/b/101670 media/video-controls-captions-trackmenu-hide-on-click-outside.html [ Skip ]
    26002601webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
    26012602
  • trunk/LayoutTests/platform/win/TestExpectations

    r150090 r150371  
    25602560media/video-controls-captions-trackmenu.html
    25612561media/video-controls-captions-trackmenu-hide-on-click.html
     2562media/video-controls-captions-trackmenu-hide-on-click-outside.html
    25622563media/video-controls-visible-exiting-fullscreen.html
    25632564
  • trunk/Source/WebCore/ChangeLog

    r150370 r150371  
     12013-05-20  Antoine Quint  <graouts@apple.com>
     2
     3        [Mac] captions menu should behave more like a menu
     4        https://bugs.webkit.org/show_bug.cgi?id=116436
     5
     6        Reviewed by Eric Carlson.
     7
     8        Let the captions menu behave more like a native Mac menu by hiding it when
     9        clicking anywhere on the page and preventing the page from scrolling when
     10        attempting to scroll the captions menu when it cannot scroll in the requested
     11        direction.
     12
     13        Test: media/video-controls-captions-trackmenu-hide-on-click-outside.html
     14
     15        * dom/EventListener.h:
     16        Add the new MediaControlsAppleEventListenerType.
     17
     18        * html/shadow/MediaControlsApple.cpp:
     19        (WebCore::MediaControlsApple::defaultEventHandler):
     20        (WebCore::MediaControlsApple::hide):
     21        (WebCore::MediaControlsApple::makeTransparent):
     22        (WebCore::MediaControlsApple::changedClosedCaptionsVisibility):
     23        (WebCore::MediaControlsApple::reportedError):
     24        (WebCore::MediaControlsApple::toggleClosedCaptionTrackList):
     25        Use the hideClosedCaptionTrackList() and showClosedCaptionTrackList()
     26        methods to hide and show the captions menu instead of calling hide()
     27        and show() directly on m_closedCaptionsContainer.
     28
     29        (WebCore::MediaControlsApple::showClosedCaptionTrackList):
     30        Show the m_closedCaptionsContainer and register a "mousewheel" event
     31        listener on it as well as a "click" event listener on the entire document.
     32
     33        (WebCore::MediaControlsApple::hideClosedCaptionTrackList):
     34        Hide the m_closedCaptionsContainer and remove the "mousewheel" event
     35        listener on it as well as the "click" event listener on the entire document.
     36
     37        (WebCore::MediaControlsApple::shouldClosedCaptionsContainerPreventPageScrolling):
     38        New private utility to determine whether the m_closedCaptionsContainer can scroll
     39        in the provided scroll direction.
     40
     41        (WebCore::MediaControlsApple::eventListener):
     42        Obtain the event listener used for "mousewheel" and "click" event handlers.
     43
     44        (WebCore::MediaControlsAppleEventListener::handleEvent):
     45        Event handler for the "mousewheel" and "click" events. If we get a "click" event, we
     46        toggle the captions menu visibility and if we get a "mousewheel" event, we call into
     47        shouldClosedCaptionsContainerPreventPageScrolling() to see if we can scroll in the
     48        current scroll direction, and if not prevent the event from resulting in a scroll by
     49        calling preventDefault().
     50
     51        (WebCore::MediaControlsAppleEventListener::operator==):
     52        Required for the successful subclassing of EventListener.
     53
     54        * html/shadow/MediaControlsApple.h:
     55        (MediaControlsAppleEventListener):
     56        (WebCore::MediaControlsAppleEventListener::create):
     57        (WebCore::MediaControlsAppleEventListener::cast):
     58        (WebCore::MediaControlsAppleEventListener::MediaControlsAppleEventListener):
     59        New subclass of EventListener required to provide a custom event listener for the
     60        "mousewheel" and "click" events registered in showClosedCaptionTrackList() and
     61        hideClosedCaptionTrackList().
     62
    1632013-05-18  Rashmi Shyamasundar  <rashmi.s2@samsung.com>
    264
  • trunk/Source/WebCore/dom/EventListener.h

    r147795 r150371  
    4444            GObjectEventListenerType,
    4545            NativeEventListenerType,
    46             SVGTRefTargetEventListenerType
     46            SVGTRefTargetEventListenerType,
     47            MediaControlsAppleEventListenerType
    4748        };
    4849
  • trunk/Source/WebCore/html/shadow/MediaControlsApple.cpp

    r149942 r150371  
    3939#include "RenderTheme.h"
    4040#include "Text.h"
     41#include "WheelEvent.h"
    4142
    4243#if ENABLE(VIDEO_TRACK)
     
    279280    if (event->type() == eventNames().clickEvent) {
    280281        if (m_closedCaptionsContainer && m_closedCaptionsContainer->isShowing()) {
    281             m_closedCaptionsContainer->hide();
     282            hideClosedCaptionTrackList();
    282283            event->setDefaultHandled();
    283284        }
     
    292293    m_volumeSliderContainer->hide();
    293294    if (m_closedCaptionsContainer)
    294         m_closedCaptionsContainer->hide();
     295        hideClosedCaptionTrackList();
    295296}
    296297
     
    300301    m_volumeSliderContainer->hide();
    301302    if (m_closedCaptionsContainer)
    302         m_closedCaptionsContainer->hide();
     303        hideClosedCaptionTrackList();
    303304}
    304305
     
    307308    MediaControls::changedClosedCaptionsVisibility();
    308309    if (m_closedCaptionsContainer && m_closedCaptionsContainer->isShowing())
    309         m_closedCaptionsContainer->hide();
     310        hideClosedCaptionTrackList();
    310311
    311312}
     
    415416        m_toggleClosedCaptionsButton->hide();
    416417    if (m_closedCaptionsContainer)
    417         m_closedCaptionsContainer->hide();
     418        hideClosedCaptionTrackList();
    418419}
    419420
     
    499500    if (m_closedCaptionsContainer) {
    500501        if (m_closedCaptionsContainer->isShowing())
    501             m_closedCaptionsContainer->hide();
     502            hideClosedCaptionTrackList();
    502503        else {
    503504            if (m_closedCaptionsTrackList)
    504505                m_closedCaptionsTrackList->updateDisplay();
    505             m_closedCaptionsContainer->show();
     506            showClosedCaptionTrackList();
    506507        }
    507508    }
     509}
     510
     511void MediaControlsApple::showClosedCaptionTrackList()
     512{
     513    if (!m_closedCaptionsContainer || m_closedCaptionsContainer->isShowing())
     514        return;
     515
     516    m_closedCaptionsContainer->show();
     517
     518    RefPtr<EventListener> listener = eventListener();
     519    m_closedCaptionsContainer->addEventListener(eventNames().mousewheelEvent, listener, true);
     520    document()->addEventListener(eventNames().clickEvent, listener, true);
     521}
     522
     523void MediaControlsApple::hideClosedCaptionTrackList()
     524{
     525    if (!m_closedCaptionsContainer || !m_closedCaptionsContainer->isShowing())
     526        return;
     527
     528    m_closedCaptionsContainer->hide();
     529
     530    EventListener* listener = eventListener().get();
     531    m_closedCaptionsContainer->removeEventListener(eventNames().mousewheelEvent, listener, true);
     532    document()->removeEventListener(eventNames().clickEvent, listener, true);
     533}
     534
     535bool MediaControlsApple::shouldClosedCaptionsContainerPreventPageScrolling(int wheelDeltaY)
     536{
     537    int scrollTop = m_closedCaptionsContainer->scrollTop();
     538    // Scrolling down.
     539    if (wheelDeltaY < 0 && (scrollTop + m_closedCaptionsContainer->offsetHeight()) >= m_closedCaptionsContainer->scrollHeight())
     540        return true;
     541    // Scrolling up.
     542    if (wheelDeltaY > 0 && scrollTop <= 0)
     543        return true;
     544    return false;
    508545}
    509546
     
    518555}
    519556
     557PassRefPtr<MediaControlsAppleEventListener> MediaControlsApple::eventListener()
     558{
     559    if (!m_eventListener)
     560        m_eventListener = MediaControlsAppleEventListener::create(this);
     561    return m_eventListener;
     562}
     563
     564// --------
     565
     566void MediaControlsAppleEventListener::handleEvent(ScriptExecutionContext*, Event* event)
     567{
     568    if (event->type() == eventNames().clickEvent && !m_mediaControls->contains(event->target()->toNode()))
     569        m_mediaControls->toggleClosedCaptionTrackList();
     570
     571    if (event->type() == eventNames().mousewheelEvent && event->hasInterface(eventNames().interfaceForWheelEvent)) {
     572        WheelEvent* wheelEvent = static_cast<WheelEvent*>(event);
     573        if (m_mediaControls->shouldClosedCaptionsContainerPreventPageScrolling(wheelEvent->wheelDeltaY()))
     574            event->preventDefault();
     575    }
     576}
     577
     578bool MediaControlsAppleEventListener::operator==(const EventListener& listener)
     579{
     580    if (const MediaControlsAppleEventListener* mediaControlsAppleEventListener = MediaControlsAppleEventListener::cast(&listener))
     581        return m_mediaControls == mediaControlsAppleEventListener->m_mediaControls;
     582    return false;
     583}
     584
    520585}
    521586
  • trunk/Source/WebCore/html/shadow/MediaControlsApple.h

    r142774 r150371  
    3434namespace WebCore {
    3535
     36class MediaControlsApple;
     37
     38class MediaControlsAppleEventListener : public EventListener {
     39public:
     40    static PassRefPtr<MediaControlsAppleEventListener> create(MediaControlsApple* mediaControls) { return adoptRef(new MediaControlsAppleEventListener(mediaControls)); }
     41    static const MediaControlsAppleEventListener* cast(const EventListener* listener)
     42    {
     43        return listener->type() == MediaControlsAppleEventListenerType
     44            ? static_cast<const MediaControlsAppleEventListener*>(listener)
     45            : 0;
     46    }
     47
     48    virtual bool operator==(const EventListener& other);
     49
     50private:
     51    MediaControlsAppleEventListener(MediaControlsApple* mediaControls)
     52        : EventListener(MediaControlsAppleEventListenerType)
     53        , m_mediaControls(mediaControls)
     54    {
     55    }
     56
     57    virtual void handleEvent(ScriptExecutionContext*, Event*);
     58
     59    MediaControlsApple* m_mediaControls;
     60};
     61
    3662class MediaControlsApple : public MediaControls {
    3763public:
     
    6389    virtual void closedCaptionTracksChanged() OVERRIDE;
    6490
     91    bool shouldClosedCaptionsContainerPreventPageScrolling(int wheelDeltaY);
     92
    6593private:
    6694    MediaControlsApple(Document*);
    6795
    6896    virtual void defaultEventHandler(Event*) OVERRIDE;
     97    PassRefPtr<MediaControlsAppleEventListener> eventListener();
     98
     99    void showClosedCaptionTrackList();
     100    void hideClosedCaptionTrackList();
    69101
    70102    MediaControlRewindButtonElement* m_rewindButton;
     
    82114    MediaControlFullscreenVolumeSliderElement* m_fullScreenVolumeSlider;
    83115    MediaControlFullscreenVolumeMaxButtonElement* m_fullScreenMaxVolumeButton;
     116    RefPtr<MediaControlsAppleEventListener> m_eventListener;
    84117};
    85118
Note: See TracChangeset for help on using the changeset viewer.