Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Menu shows Exit Full Screen instead of Exit Viewer #29798

Conversation

danae404
Copy link
Contributor

@danae404 danae404 commented Jun 14, 2024

de1667d

Context Menu shows Exit Full Screen instead of Exit Viewer
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

61d3bc9

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2 βœ… πŸ§ͺ wincairo-tests
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-cairo
βœ… πŸ§ͺ api-ios ❌ πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
⏳ πŸ›  vision βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
⏳ πŸ›  vision-sim βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ api-gtk
⏳ πŸ§ͺ vision-wk2
βœ… πŸ›  πŸ§ͺ unsafe-merge βœ… πŸ›  tv
βœ… πŸ›  tv-sim
βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@danae404 danae404 requested a review from cdumez as a code owner June 14, 2024 00:48
@danae404 danae404 self-assigned this Jun 14, 2024
@danae404 danae404 added the Media Bugs related to the HTML 5 Media elements. label Jun 14, 2024
@danae404 danae404 force-pushed the eng/Context-Menu-shows-Exit-Full-Screen-instead-of-Exit-Viewer branch from 9b94885 to aba38a6 Compare June 14, 2024 01:10
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 55;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok?

@@ -175,6 +175,9 @@
/* Allow button title in speech recognition prompt */
"Allow (speechrecognition)" = "Allow";

/* Allow */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these ok to add?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being added, just moved. The script sorts alphabetically.

Though we should preserve the existing comment for this string, which was Display USDZ file.

Comment on lines 558 to 559
auto* mediaElement(this->mediaElement());
auto* videoElement = dynamicDowncast<HTMLVideoElement>(*mediaElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be RefPtr's maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of examples in this file of raw pointers being used (for example, HitTestResult::toggleEnhancedFullscreenForVideo()). I am not sure if this is for a particular reason, or if it would still be best practice to use RefPtr's. @pxlcoder do you have thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new code should use RefPtrs. We are slowly working towards adopting smart pointers everywhere (which is why others in this file have not yet been updated).

Comment on lines 564 to 567
if (videoElement->webkitPresentationMode() == HTMLVideoElement::VideoPresentationMode::InWindow)
videoElement->webkitSetPresentationMode(HTMLVideoElement::VideoPresentationMode::Inline);
else
videoElement->webkitSetPresentationMode(HTMLVideoElement::VideoPresentationMode::InWindow);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (videoElement->webkitPresentationMode() == HTMLVideoElement::VideoPresentationMode::InWindow)
videoElement->webkitSetPresentationMode(HTMLVideoElement::VideoPresentationMode::Inline);
else
videoElement->webkitSetPresentationMode(HTMLVideoElement::VideoPresentationMode::InWindow);
auto newMode = videoElement->webkitPresentationMode() == HTMLVideoElement::VideoPresentationMode::InWindow ? HTMLVideoElement::VideoPresentationMode::Inline : HTMLVideoElement::VideoPresentationMode::InWindow;
videoElement->webkitSetPresentationMode(newMode);

@@ -175,6 +175,9 @@
/* Allow button title in speech recognition prompt */
"Allow (speechrecognition)" = "Allow";

/* Allow */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being added, just moved. The script sorts alphabetically.

Though we should preserve the existing comment for this string, which was Display USDZ file.

@@ -1096,6 +1102,9 @@
/* Title for Open in External Application Link action button */
"Open in β€œ%@”" = "Open in β€œ%@”";

/* Open this 3D model? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably preserve the original comment, which was Open 3D object in a new window?.

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

/* Cancel */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about preserving the original comment. Cancel USDZ file.

@danae404 danae404 force-pushed the eng/Context-Menu-shows-Exit-Full-Screen-instead-of-Exit-Viewer branch from aba38a6 to 590540c Compare June 14, 2024 21:04
{
#if PLATFORM(MAC) && ENABLE(VIDEO) && ENABLE(VIDEO_PRESENTATION_MODE)
RefPtr mediaElement(this->mediaElement());
RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(*mediaElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unsafe is mediaElement is ever null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dynamicDowncast returns a nullptr if mediaElement is null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to do:

RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(mediaElement);

I.e., without the * dereference.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 14, 2024
@danae404 danae404 removed the merging-blocked Applied to prevent a change from being merged label Jun 17, 2024
@danae404 danae404 force-pushed the eng/Context-Menu-shows-Exit-Full-Screen-instead-of-Exit-Viewer branch from 590540c to 5ab3302 Compare June 17, 2024 16:41
@danae404 danae404 requested a review from rr-codes June 17, 2024 16:51
{
#if PLATFORM(MAC) && ENABLE(VIDEO) && ENABLE(VIDEO_PRESENTATION_MODE)
RefPtr mediaElement(this->mediaElement());
RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(*mediaElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to do:

RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(mediaElement);

I.e., without the * dereference.

@danae404 danae404 force-pushed the eng/Context-Menu-shows-Exit-Full-Screen-instead-of-Exit-Viewer branch from 5ab3302 to 61d3bc9 Compare June 18, 2024 00:08
@danae404 danae404 requested a review from jernoble June 18, 2024 00:09
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 18, 2024
Comment on lines +558 to +559
RefPtr mediaElement(this->mediaElement());
RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(mediaElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits: Early returns are always ok, so this could bail after the first RefPtr. Also, this could be written either as a simple assignment, or with the modern, curly-brace initializer:

RefPtr mediaElement { this->mediaElement() };
if (!mediaElement)
    return;

RefPtr videoElement = dynamicDowncast<HTMLVideoElement>(mediaElement);

But this would null-check mediaElement twice, so you could add back in the dereference to mediaElement inside dynamicDowncast(). Just a suggestion though.

@danae404 danae404 added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Jun 18, 2024
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
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Context-Menu-shows-Exit-Full-Screen-instead-of-Exit-Viewer branch from 61d3bc9 to de1667d Compare June 18, 2024 17:59
@webkit-commit-queue
Copy link
Collaborator

Committed 280128@main (de1667d): https://commits.webkit.org/280128@main

Reviewed commits have been landed. Closing PR #29798 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit de1667d into WebKit:main Jun 18, 2024
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
7 participants