Skip to content

Commit

Permalink
Context Menu shows Exit Full Screen instead of Exit Viewer
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=275460
rdar://126300924

Reviewed by Jer Noble.

This patch adds a context menu item to video elements
that enters and exits Viewer mode. This patch also
removes the toggle fullscreen context menu item when
the video is in Viewer mode.

* Source/WebCore/en.lproj/Localizable.strings:
* Source/WebCore/page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
(WebCore::ContextMenuController::populate):
(WebCore::ContextMenuController::checkOrEnableIfNeeded const):
* Source/WebCore/platform/ContextMenuItem.cpp:
(WebCore::isValidContextMenuAction):
* Source/WebCore/platform/ContextMenuItem.h:
* Source/WebCore/platform/LocalizedStrings.h:
* Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm:
(WebCore::contextMenuItemTagEnterVideoViewer):
(WebCore::contextMenuItemTagExitVideoViewer):
* Source/WebCore/rendering/HitTestResult.cpp:
(WebCore::HitTestResult::mediaIsInVideoViewer const):
(WebCore::HitTestResult::toggleVideoViewer const):
* Source/WebCore/rendering/HitTestResult.h:
* Source/WebKit/Shared/API/c/WKContextMenuItemTypes.h:
* Source/WebKit/Shared/API/c/WKSharedAPICast.h:
(WebKit::toAPI):
(WebKit::toImpl):
* Source/WebKit/UIProcess/API/Cocoa/WKMenuItemIdentifiers.mm:
* Source/WebKit/UIProcess/API/Cocoa/WKMenuItemIdentifiersPrivate.h:
* Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::menuItemIdentifier):
* Source/WebKitLegacy/mac/WebView/WebHTMLView.mm:
(toAction):
(toTag):
* Source/WebKitLegacy/mac/WebView/WebUIDelegatePrivate.h:

Canonical link: https://commits.webkit.org/280128@main
  • Loading branch information
danae404 committed Jun 18, 2024
1 parent 5b73f8e commit de1667d
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 10 deletions.
24 changes: 15 additions & 9 deletions Source/WebCore/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
/* Allow button title in speech recognition prompt */
"Allow (speechrecognition)" = "Allow";

/* Display USDZ file */
"Allow (usdz QuickLook Preview)" = "Allow (usdz QuickLook Preview)";

/* Allow button title in user media prompt */
"Allow (usermedia)" = "Allow";

Expand Down Expand Up @@ -286,12 +289,12 @@
/* Button title in Device Orientation Permission API prompt */
"Cancel (device motion and orientation access)" = "Cancel";

/* Cancel USDZ file */
"Cancel (usdz QuickLook Preview)" = "Cancel (usdz QuickLook Preview)";

/* Title for Cancel button label in button bar */
"Cancel button label in button bar" = "Cancel";

/* Cancel USDZ file */
"Cancel (usdz QuickLook Preview)" = "Cancel";

/* Capitalize context menu item */
"Capitalize" = "Capitalize";

Expand Down Expand Up @@ -439,9 +442,6 @@
/* Undo action name */
"Dictation (Undo action name)" = "Dictation";

/* Display USDZ file */
"Allow (usdz QuickLook Preview)" = "Allow";

/* Message for requesting cross-site cookie and website data access. */
"Do you want to allow “%@” and “%@” to use cookies and website data while browsing “%@”?" = "Do you want to allow “%@” and “%@” to use cookies and website data while browsing “%@”?";

Expand Down Expand Up @@ -550,6 +550,9 @@
/* menu item */
"Enter Picture in Picture" = "Enter Picture in Picture";

/* Enter Video Viewer context menu item */
"Enter Viewer" = "Enter Viewer";

/* Validation message for input form controls of type 'url' that have an invalid value */
"Enter a URL" = "Enter a URL";

Expand Down Expand Up @@ -583,6 +586,9 @@
/* menu item */
"Exit Picture in Picture" = "Exit Picture in Picture";

/* Exit Video Viewer context menu item */
"Exit Viewer" = "Exit Viewer";

/* Codec Strings */
"Extended Profile (AVC Codec Profile)" = "Extended Profile";

Expand Down Expand Up @@ -1096,6 +1102,9 @@
/* Title for Open in External Application Link action button */
"Open in “%@”" = "Open in “%@”";

/* Open 3D object in a new window? */
"Open this 3D model?" = "Open this 3D model?";

/* context menu item for PDF */
"Open with %@" = "Open with %@";

Expand Down Expand Up @@ -1318,9 +1327,6 @@
/* Title for Show Text action button */
"Show Text" = "Show Text";

/* Open 3D object in a new window? */
"Open this 3D model?" = "Open this 3D model?";

/* Title of the context menu item to show when PDFPlugin was used instead of a blocked plugin */
"Show in blocked plug-in" = "Show in blocked plug-in";

Expand Down
13 changes: 12 additions & 1 deletion Source/WebCore/page/ContextMenuController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuAction action, co
case ContextMenuItemTagToggleVideoEnhancedFullscreen:
m_context.hitTestResult().toggleEnhancedFullscreenForVideo();
break;
case ContextMenuItemTagToggleVideoViewer:
m_context.hitTestResult().toggleVideoViewer();
break;
case ContextMenuItemTagOpenFrameInNewWindow: {
RefPtr loader = frame->loader().documentLoader();
if (!loader->unreachableURL().isEmpty())
Expand Down Expand Up @@ -947,6 +950,7 @@ void ContextMenuController::populate()
contextMenuItemTagEnterVideoFullscreen());
#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
ContextMenuItem ToggleVideoEnhancedFullscreen(ContextMenuItemType::Action, ContextMenuItemTagToggleVideoEnhancedFullscreen, contextMenuItemTagEnterVideoEnhancedFullscreen());
ContextMenuItem ToggleVideoViewer(ContextMenuItemType::Action, ContextMenuItemTagToggleVideoViewer, contextMenuItemTagEnterVideoViewer());
#endif

#if ENABLE(PDFJS)
Expand Down Expand Up @@ -1138,12 +1142,14 @@ void ContextMenuController::populate()
appendItem(ToggleMediaControls, m_contextMenu.get());
appendItem(ToggleMediaLoop, m_contextMenu.get());
#if SUPPORTS_TOGGLE_VIDEO_FULLSCREEN
appendItem(ToggleVideoFullscreen, m_contextMenu.get());
if (!m_context.hitTestResult().mediaIsInVideoViewer())
appendItem(ToggleVideoFullscreen, m_contextMenu.get());
#else
appendItem(EnterVideoFullscreen, m_contextMenu.get());
#endif
#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
appendItem(ToggleVideoEnhancedFullscreen, m_contextMenu.get());
appendItem(ToggleVideoViewer, m_contextMenu.get());
#endif
if (m_context.hitTestResult().isDownloadableMedia() && loader->client().canHandleRequest(ResourceRequest(mediaURL))) {
appendItem(*separatorItem(), m_contextMenu.get());
Expand Down Expand Up @@ -1741,6 +1747,11 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
#endif
shouldEnable = m_context.hitTestResult().mediaSupportsEnhancedFullscreen();
break;
case ContextMenuItemTagToggleVideoViewer:
#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
item.setTitle(m_context.hitTestResult().mediaIsInVideoViewer() ? contextMenuItemTagExitVideoViewer() : contextMenuItemTagEnterVideoViewer());
#endif
break;
case ContextMenuItemTagOpenFrameInNewWindow:
case ContextMenuItemTagSpellingGuess:
case ContextMenuItemTagOther:
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/ContextMenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static bool isValidContextMenuAction(WebCore::ContextMenuAction action)
case ContextMenuAction::ContextMenuItemTagDictationAlternative:
case ContextMenuAction::ContextMenuItemTagToggleVideoFullscreen:
case ContextMenuAction::ContextMenuItemTagShareMenu:
case ContextMenuAction::ContextMenuItemTagToggleVideoViewer:
case ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen:
case ContextMenuAction::ContextMenuItemTagLookUpImage:
case ContextMenuAction::ContextMenuItemTagTranslate:
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/ContextMenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ enum ContextMenuAction {
ContextMenuItemTagToggleVideoFullscreen,
ContextMenuItemTagShareMenu,
ContextMenuItemTagToggleVideoEnhancedFullscreen,
ContextMenuItemTagToggleVideoViewer,
ContextMenuItemTagAddHighlightToCurrentQuickNote,
ContextMenuItemTagAddHighlightToNewQuickNote,
ContextMenuItemTagLookUpImage,
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/LocalizedStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ namespace WebCore {
#if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
String contextMenuItemTagEnterVideoEnhancedFullscreen();
String contextMenuItemTagExitVideoEnhancedFullscreen();
String contextMenuItemTagEnterVideoViewer();
String contextMenuItemTagExitVideoViewer();
#endif
String contextMenuItemTagMediaPlay();
String contextMenuItemTagMediaPause();
Expand Down
10 changes: 10 additions & 0 deletions Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ String contextMenuItemTagExitVideoEnhancedFullscreen()
{
return WEB_UI_STRING("Exit Picture in Picture", "menu item");
}

String contextMenuItemTagEnterVideoViewer()
{
return WEB_UI_STRING("Enter Viewer", "Enter Video Viewer context menu item");
}

String contextMenuItemTagExitVideoViewer()
{
return WEB_UI_STRING("Exit Viewer", "Exit Video Viewer context menu item");
}
#endif
#endif // ENABLE(CONTEXT_MENUS)

Expand Down
25 changes: 25 additions & 0 deletions Source/WebCore/rendering/HitTestResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,31 @@ void HitTestResult::enterFullscreenForVideo() const
#endif
}

bool HitTestResult::mediaIsInVideoViewer() const
{
#if PLATFORM(MAC) && ENABLE(VIDEO) && ENABLE(VIDEO_PRESENTATION_MODE)
HTMLMediaElement* mediaElt(mediaElement());
return is<HTMLVideoElement>(mediaElt) && mediaElt->fullscreenMode() == HTMLMediaElementEnums::VideoFullscreenModeInWindow;
#else
return false;
#endif
}

void HitTestResult::toggleVideoViewer() const
{
#if PLATFORM(MAC) && ENABLE(VIDEO) && ENABLE(VIDEO_PRESENTATION_MODE)
RefPtr mediaElement(this->mediaElement());
RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(mediaElement);
if (!videoElement || !mediaElement->supportsFullscreen(HTMLMediaElementEnums::VideoFullscreenModeInWindow))
return;

UserGestureIndicator indicator(IsProcessingUserGesture::Yes, &mediaElement->document());
auto newMode = videoElement->webkitPresentationMode() == HTMLVideoElement::VideoPresentationMode::InWindow ? HTMLVideoElement::VideoPresentationMode::Inline : HTMLVideoElement::VideoPresentationMode::InWindow;

videoElement->webkitSetPresentationMode(newMode);
#endif
}

bool HitTestResult::mediaControlsEnabled() const
{
#if ENABLE(VIDEO)
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/HitTestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class HitTestResult {
void toggleMediaLoopPlayback() const;
void toggleShowMediaStats() const;
WEBCORE_EXPORT bool mediaIsInFullscreen() const;
bool mediaIsInVideoViewer() const;
void toggleVideoViewer() const;
void toggleMediaFullscreenState() const;
void enterFullscreenForVideo() const;
bool mediaControlsEnabled() const;
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/API/c/WKContextMenuItemTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ enum {
kWKContextMenuItemTagToggleVideoFullscreen,
kWKContextMenuItemTagShareMenu,
kWKContextMenuItemTagToggleVideoEnhancedFullscreen,
kWKContextMenuItemTagToggleVideoViewer,
kWKContextMenuItemTagAddHighlightToCurrentQuickNote,
kWKContextMenuItemTagAddHighlightToNewQuickNote,
kWKContextMenuItemTagRevealImage,
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit/Shared/API/c/WKSharedAPICast.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ inline WKContextMenuItemTag toAPI(WebCore::ContextMenuAction action)
return kWKContextMenuItemTagToggleVideoEnhancedFullscreen;
case WebCore::ContextMenuItemTagMediaPlayPause:
return kWKContextMenuItemTagMediaPlayPause;
case WebCore::ContextMenuItemTagToggleVideoViewer:
return kWKContextMenuItemTagToggleVideoViewer;
case WebCore::ContextMenuItemTagMediaMute:
return kWKContextMenuItemTagMediaMute;
case WebCore::ContextMenuItemTagAddHighlightToCurrentQuickNote:
Expand Down Expand Up @@ -753,6 +755,8 @@ inline WebCore::ContextMenuAction toImpl(WKContextMenuItemTag tag)
return WebCore::ContextMenuItemTagToggleVideoEnhancedFullscreen;
case kWKContextMenuItemTagMediaPlayPause:
return WebCore::ContextMenuItemTagMediaPlayPause;
case kWKContextMenuItemTagToggleVideoViewer:
return WebCore::ContextMenuItemTagToggleVideoViewer;
case kWKContextMenuItemTagMediaMute:
return WebCore::ContextMenuItemTagMediaMute;
case kWKContextMenuItemTagAddHighlightToCurrentQuickNote:
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKMenuItemIdentifiers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
NSString * const _WKMenuItemIdentifierShowHideMediaStats = @"WKMenuItemIdentifierShowHideMediaStats";
NSString * const _WKMenuItemIdentifierToggleEnhancedFullScreen = @"WKMenuItemIdentifierToggleEnhancedFullScreen";
NSString * const _WKMenuItemIdentifierToggleFullScreen = @"WKMenuItemIdentifierToggleFullScreen";
NSString * const _WKMenuItemIdentifierToggleVideoViewer = @"WKMenuItemIdentifierToggleVideoViewer";

NSString * const _WKMenuItemIdentifierShareMenu = @"WKMenuItemIdentifierShareMenu";
NSString * const _WKMenuItemIdentifierSpeechMenu = @"WKMenuItemIdentifierSpeechMenu";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ WK_EXTERN NSString * const _WKMenuItemIdentifierSearchWeb WK_API_AVAILABLE(macos
WK_EXTERN NSString * const _WKMenuItemIdentifierShowHideMediaControls WK_API_AVAILABLE(macos(10.12), ios(10.0));
WK_EXTERN NSString * const _WKMenuItemIdentifierShowHideMediaStats WK_API_AVAILABLE(macos(13.3), ios(16.4));
WK_EXTERN NSString * const _WKMenuItemIdentifierToggleEnhancedFullScreen WK_API_AVAILABLE(macos(10.14), ios(12.0));
WK_EXTERN NSString * const _WKMenuItemIdentifierToggleVideoViewer WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
WK_EXTERN NSString * const _WKMenuItemIdentifierToggleFullScreen WK_API_AVAILABLE(macos(10.12), ios(10.0));

WK_EXTERN NSString * const _WKMenuItemIdentifierShareMenu WK_API_AVAILABLE(macos(10.12), ios(10.0));
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ static void getStandardShareMenuItem(NSArray *items, void (^completionHandler)(N
case ContextMenuItemTagToggleVideoFullscreen:
return _WKMenuItemIdentifierToggleFullScreen;

case ContextMenuItemTagToggleVideoViewer:
return _WKMenuItemIdentifierToggleVideoViewer;

case ContextMenuItemTagTranslate:
return _WKMenuItemIdentifierTranslate;

Expand Down
4 changes: 4 additions & 0 deletions Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ - (void)forwardContextMenuAction:(id)sender;
return ContextMenuItemTagEnterVideoFullscreen;
case WebMenuItemTagToggleVideoEnhancedFullscreen:
return ContextMenuItemTagToggleVideoEnhancedFullscreen;
case WebMenuItemTagToggleVideoViewer:
return ContextMenuItemTagToggleVideoViewer;
case WebMenuItemTagMediaPlayPause:
return ContextMenuItemTagMediaPlayPause;
case WebMenuItemTagMediaMute:
Expand Down Expand Up @@ -593,6 +595,8 @@ - (void)forwardContextMenuAction:(id)sender;
return WebMenuItemTagShareMenu;
case ContextMenuItemTagToggleVideoEnhancedFullscreen:
return WebMenuItemTagToggleVideoEnhancedFullscreen;
case ContextMenuItemTagToggleVideoViewer:
return WebMenuItemTagToggleVideoViewer;
case ContextMenuItemTagTranslate:
return WebMenuItemTagTranslate;
case ContextMenuItemTagSwapCharacters:
Expand Down
1 change: 1 addition & 0 deletions Source/WebKitLegacy/mac/WebView/WebUIDelegatePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum {
WebMenuItemTagToggleVideoFullscreen,
WebMenuItemTagShareMenu,
WebMenuItemTagToggleVideoEnhancedFullscreen,
WebMenuItemTagToggleVideoViewer,
WebMenuItemTagAddHighlightToCurrentQuickNote,
WebMenuItemTagAddHighlightToNewQuickNote,
WebMenuItemTagRevealImage,
Expand Down

0 comments on commit de1667d

Please sign in to comment.