Bug 45021

Summary: [GTK] enhanced context menu for media elements
Product: WebKit Reporter: Philippe Normand <pnormand>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ademar, eric.carlson, eric, webkit.review.bot, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on: 39102, 45904    
Bug Blocks: 37624    
Attachments:
Description Flags
proposed patch (test missing)
none
proposed patch (test missing)
none
proposed patch
none
updated patch
none
updated patch
none
updated patch
eric.carlson: review-
Patch
none
updated patch
none
updated patch probably more utf-16 friendly eric.carlson: review+

Description Philippe Normand 2010-09-01 00:44:03 PDT
It'd be nice to have entries for:

- copy media url to clipboard
- download media
- open in new window (?)
- controls display control
- switch to fullscreen
- loop playback control
Comment 1 Philippe Normand 2010-09-09 03:49:35 PDT
Created attachment 67017 [details]
proposed patch (test missing)
Comment 2 Philippe Normand 2010-09-09 06:40:32 PDT
The test doesn't seem very easy to write, I can send a contextClick() event on the media element but then, how do i know at which position to move the mouse to click on a specific item? :(
Comment 3 Philippe Normand 2010-09-09 08:12:51 PDT
Created attachment 67035 [details]
proposed patch (test missing)
Comment 4 WebKit Review Bot 2010-09-09 08:13:51 PDT
Attachment 67035 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebCore/platform/gtk/ContextMenuItemGtk.cpp:108:  Use 0 instead of NULL.  [readability/null] [5]
WebCore/rendering/HitTestResult.cpp:297:  An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]
Total errors found: 2 in 16 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Philippe Normand 2010-09-09 08:17:34 PDT
(In reply to comment #4)
> Attachment 67035 [details] did not pass style-queue:
> 
> Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
> WebCore/platform/gtk/ContextMenuItemGtk.cpp:108:  Use 0 instead of NULL.  [readability/null] [5]
> WebCore/rendering/HitTestResult.cpp:297:  An else statement can be removed when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]
> Total errors found: 2 in 16 files
> 
> 
> If any of these errors are false positives, please file a bug against check-webkit-style.

This version sports play/pause mute/unmute too
Comment 6 Philippe Normand 2010-09-15 00:27:05 PDT
Created attachment 67650 [details]
proposed patch
Comment 7 Philippe Normand 2010-09-15 00:34:29 PDT
This patch is on top of the one in bug 39102 which hasn't landed yet. That's while the style-bot fails to check it.
Comment 8 Eric Carlson 2010-09-15 05:46:52 PDT
Comment on attachment 67650 [details]
proposed patch

> +            function start()
> +            {
> +                findMediaElement();
> +                waitForEvent('play', canplaythrough);
> +                run("video.src = '" + findMediaFile("video", "content/test") + "'");
> +            }
"canplaythrough" is an odd name for a test that triggers on the 'play' event ;-)

> +            if (result.mediaSupportsFullscreen())
> +                appendItem(EnterVideoFullscreen);
> +
I wonder if it would make more sense to always append the fullcreen menu 
item for a <video> element and enable/disable it based on supportsFullscreen().
It will be somewhat confusing to some that the menu item isn't always enabled,
but it will also be consusing that the menu item is sometimes there and sometimes
not for the same element.

I am not positive which is the correct behavior for this menu item...


> +        case ContextMenuItemTagMediaMute:
> +            if (m_hitTestResult.mediaMuted())
> +                item.setTitle(contextMenuItemTagMediaUnMute());
> +            else
> +                item.setTitle(contextMenuItemTagMediaMute());
You should disable the mute menu item and not toggle the title if the element does
not have an audio track:

    case ContextMenuItemTagMediaMute:
        shouldEnable = m_hitTestResult.mediaHasAudio();
        if (!shouldEnable || !m_hitTestResult.mediaMuted())
            item.setTitle(contextMenuItemTagMediaMute());
        else
            item.setTitle(contextMenuItemTagMediaUnMute());
        break;

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        return m_innerNonSharedNode->document()->completeURL(deprecatedParseURL(mediaElt->currentSrc()));
I think something like "if (HTMLMediaElement* mediaElt = mediaElement())" would be
more in keeping with the current C++ style for this type of test.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        mediaElt->setControls(!mediaElt->controls());
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        mediaElt->setLoop(!mediaElt->loop());
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        return mediaElt->controls();
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        return mediaElt->loop();
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        return !mediaElt->paused();
Ditto.


> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        mediaElt->togglePlayState();
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        return mediaElt->muted();
Ditto.

> +    HTMLMediaElement* mediaElt(mediaElement());
> +    if (mediaElt)
> +        mediaElt->setMuted(!mediaElt->muted());
Ditto.

It would be nice to have a menu item for saving the movie file. HTMLMediaElement has a
supportsSave() method that should be used to enable/disable (or add/remove) the menu item
because not all movies will be savable. Please file a bug for this if you don't want to
add it to this patch.

Nice stuff, it will be great to finally have this feature!

r=me with these suggestions.
Comment 9 Philippe Normand 2010-09-15 06:26:19 PDT
Thanks for the review Eric!

I applied the changes requested in my branch.

About the fullscreen/save menus I think it depends on the UI design guidelines of the platform.

For instance the GNOME HIG recommends to show the items but make them inactive: http://library.gnome.org/devel/hig-book/stable/menus-design.html.en#menu-item-type-command

I think this is what I'll do... On mac it would probably be different, I don't know.

I will open a separate bug report for supportsSave, this patch is already quite big.

Also I'll wait the bug 39102 gets reviewed to land this patch ;)
Comment 10 Philippe Normand 2010-09-16 09:22:32 PDT
Committed r67628: <http://trac.webkit.org/changeset/67628>
Comment 11 WebKit Review Bot 2010-09-16 10:17:39 PDT
http://trac.webkit.org/changeset/67628 might have broken Qt Linux Release minimal, Qt Linux ARMv5 Release, Qt Linux ARMv7 Release, Qt Windows 32-bit Release, Qt Windows 32-bit Debug, Chromium Win Release, Chromium Mac Release, and Chromium Linux Release
The following changes are on the blame list:
http://trac.webkit.org/changeset/67626
http://trac.webkit.org/changeset/67627
http://trac.webkit.org/changeset/67628
http://trac.webkit.org/changeset/67629
http://trac.webkit.org/changeset/67630
http://trac.webkit.org/changeset/67631
Comment 12 Philippe Normand 2010-09-16 10:43:58 PDT
the new ContextMenu::contextMenu* methods are not implemented in the mac, qt, chromium ports. Will send a fixed patch, sorry for the major breakage :/
Comment 13 Philippe Normand 2010-09-17 00:40:47 PDT
Created attachment 67889 [details]
updated patch
Comment 14 Philippe Normand 2010-09-17 02:03:24 PDT
Created attachment 67892 [details]
updated patch
Comment 15 WebKit Review Bot 2010-09-17 02:15:32 PDT
Attachment 67892 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebCore/platform/gtk/ContextMenuItemGtk.cpp:108:  Use 0 instead of NULL.  [readability/null] [5]
Total errors found: 1 in 36 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 16 Philippe Normand 2010-09-17 02:17:34 PDT
Created attachment 67893 [details]
updated patch
Comment 17 Eric Carlson 2010-09-17 08:16:29 PDT
Comment on attachment 67893 [details]
updated patch

This doesn't work on OS X and Windows because the localizable strings are missing. I will add them and update the patch.
Comment 18 Philippe Normand 2010-09-17 08:26:16 PDT
Comment on attachment 67893 [details]
updated patch

>  WebKit/mac/WebCoreSupport/WebPlatformStrategies.h  |    9 ++
>  WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm |   45 +++++++
>  .../win/WebCoreSupport/WebPlatformStrategies.cpp   |   45 +++++++
>  .../WebCoreSupport/WebPlatformStrategies.cpp       |   45 +++++++
>  .../WebCoreSupport/WebPlatformStrategies.h         |    9 ++

So what are those? Did I miss something?
Comment 19 Eric Carlson 2010-09-17 10:25:03 PDT
(In reply to comment #18)
> (From update of attachment 67893 [details])
> >  WebKit/mac/WebCoreSupport/WebPlatformStrategies.h  |    9 ++
> >  WebKit/mac/WebCoreSupport/WebPlatformStrategies.mm |   45 +++++++
> >  .../win/WebCoreSupport/WebPlatformStrategies.cpp   |   45 +++++++
> >  .../WebCoreSupport/WebPlatformStrategies.cpp       |   45 +++++++
> >  .../WebCoreSupport/WebPlatformStrategies.h         |    9 ++
> 
> So what are those? Did I miss something?

You didn't add the actual strings to Localizable.strings or WebLocalizableStrings.cpp
Comment 20 Eric Carlson 2010-09-17 10:34:26 PDT
(In reply to comment #19)

> You didn't add the actual strings to Localizable.strings or WebLocalizableStrings.cpp

No need to update WebLocalizableStrings.cpp as it doesn't exist any more ;-)
Comment 21 Eric Carlson 2010-09-17 10:44:58 PDT
Created attachment 67917 [details]
Patch

This adds the missing Mac strings and changes the behavior of the "Mute" menu item from changing the text to adding and removing a check mark.

I think the patch should use "Audio" or "Video" instead of "Media" (depending on the element type and movie contents) in "Open Media in New Window" and "Copy Media Address".
Comment 22 Ademar Reis 2010-09-20 07:51:38 PDT
Just a heads up:

WebCore/platform/qt/Localizations.cpp is no more after r67787 <http://trac.webkit.org/changeset/67787>, so you'll have to update your patch again to update the respective platform strategies file instead.
Comment 23 Philippe Normand 2010-09-20 09:33:27 PDT
Created attachment 68097 [details]
updated patch
Comment 24 Philippe Normand 2010-09-20 10:08:32 PDT
Created attachment 68100 [details]
updated patch probably more utf-16 friendly
Comment 25 Eric Carlson 2010-09-20 11:07:34 PDT
Comment on attachment 68100 [details]
updated patch probably more utf-16 friendly

Thanks!
Comment 26 Philippe Normand 2010-09-20 23:55:45 PDT
Committed r67928: <http://trac.webkit.org/changeset/67928>
Comment 27 Simon Fraser (smfr) 2014-02-25 21:31:57 PST
Comment on attachment 68097 [details]
updated patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68097&action=review

> WebCore/rendering/HitTestResult.h:97
> +    void toggleMediaControlsDisplay() const;
> +    void toggleMediaLoopPlayback() const;
> +    void enterFullscreenForVideo() const;
> +    bool mediaControlsEnabled() const;
> +    bool mediaLoopEnabled() const;
> +    bool mediaPlaying() const;
> +    bool mediaSupportsFullscreen() const;
> +    void toggleMediaPlayState() const;
> +    bool mediaHasAudio() const;
> +    bool mediaIsVideo() const;
> +    bool mediaMuted() const;
> +    void toggleMediaMuteState() const;

This stuff doesn't belong on rendering/HitTestResult.