Allow for toggling fullscreen on <video> elements

https://bugs.webkit.org/show_bug.cgi?id=117220

Patch by Ruth Fong <ruth_fong@apple.com> on 2013-06-12
Reviewed by Dean Jackson.

Source/WebCore:

This patch adds the ability for fullscreen
context menu item on <video> elements to switch between "Enter Fullscreen"
and "Exit Fullscreen" and behave appropriately.

No new tests. media/context-menu-action.html,
which has been disabled by bug 116651, is used to test context menus.

* English.lproj/Localizable.strings: Add "Exit Fullscreen" string.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::toggleFullscreenState): Added to appropriately enter/exit fullscreen.
* html/HTMLMediaElement.h:
* page/ContextMenuController.cpp:
* platform/ContextMenuItem.h:
* platform/LocalizedStrings.cpp:
* platform/LocalizedStrings.h:
Updated to rename variables more appropriately to reflect the toggle-ability of video fullscreen.
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::mediaIsInFullscreen): Added to check if an element
was a media element in fullscreen.
(WebCore::HitTestResult::toggleMediaFullscreenState): Added to hook into
HTMLMediaElement::toggleFullscreenState.
* rendering/HitTestResult.h:

Source/WebKit2:

* Shared/API/c/WKContextMenuItemTypes.h:
* Shared/API/c/WKSharedAPICast.h:
Added variables to support the toggle-ability of the fullscreen
video context menu item.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@151512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 24c0bd0a
2013-06-12 Ruth Fong <ruth_fong@apple.com>
Allow for toggling fullscreen on <video> elements
https://bugs.webkit.org/show_bug.cgi?id=117220
Reviewed by Dean Jackson.
This patch adds the ability for fullscreen
context menu item on <video> elements to switch between "Enter Fullscreen"
and "Exit Fullscreen" and behave appropriately.
No new tests. media/context-menu-action.html,
which has been disabled by bug 116651, is used to test context menus.
* English.lproj/Localizable.strings: Add "Exit Fullscreen" string.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::toggleFullscreenState): Added to appropriately enter/exit fullscreen.
* html/HTMLMediaElement.h:
* page/ContextMenuController.cpp:
* platform/ContextMenuItem.h:
* platform/LocalizedStrings.cpp:
* platform/LocalizedStrings.h:
Updated to rename variables more appropriately to reflect the toggle-ability of video fullscreen.
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::mediaIsInFullscreen): Added to check if an element
was a media element in fullscreen.
(WebCore::HitTestResult::toggleMediaFullscreenState): Added to hook into
HTMLMediaElement::toggleFullscreenState.
* rendering/HitTestResult.h:
2013-06-12 Sergio Villar Senin <svillar@igalia.com>
Skipping {}, () and [] blocks while error recovering in CSS
......
B/* accessibility help text for media controller time value >= 1 day */
......
......@@ -4362,6 +4362,16 @@ bool HTMLMediaElement::isFullscreen() const
return false;
}
void HTMLMediaElement::toggleFullscreenState()
{
LOG(Media, "HTMLMediaElement::toggleFullscreenState - isFullscreen() is %s", boolString(isFullscreen()));
if (isFullscreen())
exitFullscreen();
else
enterFullscreen();
}
void HTMLMediaElement::enterFullscreen()
{
LOG(Media, "HTMLMediaElement::enterFullscreen");
......
......@@ -337,6 +337,7 @@ public:
bool hasSingleSecurityOrigin() const { return !m_player || m_player->hasSingleSecurityOrigin(); }
bool isFullscreen() const;
void toggleFullscreenState();
void enterFullscreen();
void exitFullscreen();
......
......@@ -263,6 +263,9 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
case ContextMenuItemTagToggleMediaLoop:
m_hitTestResult.toggleMediaLoopPlayback();
break;
case ContextMenuItemTagToggleVideoFullscreen:
m_hitTestResult.toggleMediaFullscreenState();
break;
case ContextMenuItemTagEnterVideoFullscreen:
m_hitTestResult.enterFullscreenForVideo();
break;
......@@ -732,6 +735,12 @@ static bool selectionContainsPossibleWord(Frame* frame)
#endif
#endif
#if PLATFORM(MAC)
#define SUPPORTS_TOGGLE_VIDEO_FULLSCREEN 1
#else
#define SUPPORTS_TOGGLE_VIDEO_FULLSCREEN 0
#endif
void ContextMenuController::populate()
{
ContextMenuItem OpenLinkItem(ActionType, ContextMenuItemTagOpenLink, contextMenuItemTagOpenLink());
......@@ -762,7 +771,9 @@ void ContextMenuController::populate()
contextMenuItemTagToggleMediaControls());
ContextMenuItem ToggleMediaLoop(CheckableActionType, ContextMenuItemTagToggleMediaLoop,
contextMenuItemTagToggleMediaLoop());
ContextMenuItem EnterVideoFullscreen(ActionType, ContextMenuItemTagEnterVideoFullscreen,
ContextMenuItem EnterVideoFullscreen(ActionType, ContextMenuItemTagEnterVideoFullscreen,
contextMenuItemTagEnterVideoFullscreen());
ContextMenuItem ToggleVideoFullscreen(ActionType, ContextMenuItemTagToggleVideoFullscreen,
contextMenuItemTagEnterVideoFullscreen());
#if PLATFORM(MAC)
ContextMenuItem SearchSpotlightItem(ActionType, ContextMenuItemTagSearchInSpotlight,
......@@ -845,8 +856,11 @@ void ContextMenuController::populate()
appendItem(MediaMute, m_contextMenu.get());
appendItem(ToggleMediaControls, m_contextMenu.get());
appendItem(ToggleMediaLoop, m_contextMenu.get());
#if SUPPORTS_TOGGLE_VIDEO_FULLSCREEN
appendItem(ToggleVideoFullscreen, m_contextMenu.get());
#else
appendItem(EnterVideoFullscreen, m_contextMenu.get());
#endif
appendItem(*separatorItem(), m_contextMenu.get());
appendItem(CopyMediaLinkItem, m_contextMenu.get());
appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
......@@ -1342,6 +1356,11 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
case ContextMenuItemTagToggleMediaLoop:
shouldCheck = m_hitTestResult.mediaLoopEnabled();
break;
case ContextMenuItemTagToggleVideoFullscreen:
#if SUPPORTS_TOGGLE_VIDEO_FULLSCREEN
item.setTitle(m_hitTestResult.mediaIsInFullscreen() ? contextMenuItemTagExitVideoFullscreen() : contextMenuItemTagEnterVideoFullscreen());
break;
#endif
case ContextMenuItemTagEnterVideoFullscreen:
shouldEnable = m_hitTestResult.mediaSupportsFullscreen();
break;
......
......@@ -161,6 +161,7 @@ namespace WebCore {
ContextMenuItemTagMediaMute,
ContextMenuItemTagDictationAlternative,
ContextMenuItemTagOpenLinkInThisWindow,
ContextMenuItemTagToggleVideoFullscreen,
ContextMenuItemBaseCustomTag = 5000,
ContextMenuItemCustomTagNoAction = 5998,
ContextMenuItemLastCustomTag = 5999,
......
......@@ -494,6 +494,11 @@ String contextMenuItemTagEnterVideoFullscreen()
return WEB_UI_STRING("Enter Fullscreen", "Video Enter Fullscreen context menu item");
}
String contextMenuItemTagExitVideoFullscreen()
{
return WEB_UI_STRING("Exit Fullscreen", "Video Exit Fullscreen context menu item");
}
String contextMenuItemTagMediaPlay()
{
return WEB_UI_STRING("Play", "Media Play context menu item");
......
......@@ -137,6 +137,7 @@ namespace WebCore {
String contextMenuItemTagToggleMediaControls();
String contextMenuItemTagToggleMediaLoop();
String contextMenuItemTagEnterVideoFullscreen();
String contextMenuItemTagExitVideoFullscreen();
String contextMenuItemTagMediaPlay();
String contextMenuItemTagMediaPause();
String contextMenuItemTagMediaMute();
......
......@@ -399,6 +399,27 @@ void HitTestResult::toggleMediaLoopPlayback() const
#endif
}
bool HitTestResult::mediaIsInFullscreen() const
{
#if ENABLE(VIDEO)
if (HTMLMediaElement* mediaElement = this->mediaElement())
return mediaElement->isVideo() && mediaElement->isFullscreen();
#endif
return false;
}
void HitTestResult::toggleMediaFullscreenState() const
{
#if ENABLE(VIDEO)
if (HTMLMediaElement* mediaElement = this->mediaElement()) {
if (mediaElement->isVideo() && mediaElement->supportsFullscreen()) {
UserGestureIndicator indicator(DefinitelyProcessingNewUserGesture);
mediaElement->toggleFullscreenState();
}
}
#endif
}
void HitTestResult::enterFullscreenForVideo() const
{
#if ENABLE(VIDEO)
......
......@@ -112,6 +112,8 @@ public:
bool isContentEditable() const;
void toggleMediaControlsDisplay() const;
void toggleMediaLoopPlayback() const;
bool mediaIsInFullscreen() const;
void toggleMediaFullscreenState() const;
void enterFullscreenForVideo() const;
bool mediaControlsEnabled() const;
bool mediaLoopEnabled() const;
......
2013-06-12 Ruth Fong <ruth_fong@apple.com>
Allow for toggling fullscreen on <video> elements
https://bugs.webkit.org/show_bug.cgi?id=117220
Reviewed by Dean Jackson.
* Shared/API/c/WKContextMenuItemTypes.h:
* Shared/API/c/WKSharedAPICast.h:
Added variables to support the toggle-ability of the fullscreen
video context menu item.
2013-06-12 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Invalidate the ProcessLauncher when the process is terminated before it has finished launching
......
......@@ -117,6 +117,7 @@ enum {
kWKContextMenuItemTagCopyImageUrlToClipboard,
kWKContextMenuItemTagSelectAll,
kWKContextMenuItemTagOpenLinkInThisWindow,
kWKContextMenuItemTagToggleVideoFullscreen,
kWKContextMenuItemBaseApplicationTag = 10000
};
typedef uint32_t WKContextMenuItemTag;
......
......@@ -468,6 +468,8 @@ inline WKContextMenuItemTag toAPI(WebCore::ContextMenuAction action)
return kWKContextMenuItemTagToggleMediaControls;
case WebCore::ContextMenuItemTagToggleMediaLoop:
return kWKContextMenuItemTagToggleMediaLoop;
case WebCore::ContextMenuItemTagToggleVideoFullscreen:
return kWKContextMenuItemTagToggleVideoFullscreen;
case WebCore::ContextMenuItemTagEnterVideoFullscreen:
return kWKContextMenuItemTagEnterVideoFullscreen;
case WebCore::ContextMenuItemTagMediaPlayPause:
......@@ -658,6 +660,8 @@ inline WebCore::ContextMenuAction toImpl(WKContextMenuItemTag tag)
return WebCore::ContextMenuItemTagToggleMediaControls;
case kWKContextMenuItemTagToggleMediaLoop:
return WebCore::ContextMenuItemTagToggleMediaLoop;
case kWKContextMenuItemTagToggleVideoFullscreen:
return WebCore::ContextMenuItemTagToggleVideoFullscreen;
case kWKContextMenuItemTagEnterVideoFullscreen:
return WebCore::ContextMenuItemTagEnterVideoFullscreen;
case kWKContextMenuItemTagMediaPlayPause:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment