<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[280374] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/280374">280374</a></dd>
<dt>Author</dt> <dd>drousso@apple.com</dd>
<dt>Date</dt> <dd>2021-07-27 20:56:44 -0700 (Tue, 27 Jul 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Modern Media Controls] [macOS] Overflow button still shows as `on` even after contextmenu is dismissed
https://bugs.webkit.org/show_bug.cgi?id=228310
<rdar://problem/81124786>

Reviewed by Wenson Hsieh.

Source/WebCore:

Test: media/modern-media-controls/overflow-support/button-state.html

* page/ContextMenuController.h:
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::didDismissContextMenu): Added.
* page/ContextMenuProvider.h:
(WebCore::ContextMenuProvider::didDismissContextMenu): Added.
Add plumbing from WebKit to the `ContextMenuProvider` for when the contextmenu is dismissed.

* Modules/mediacontrols/MediaControlsHost.cpp:
(WebCore::MediaControlsContextMenuProvider::didDismissContextMenu): Added.
When the contextmenu is dismissed, invoke the callback provided to `MediaControlsHost::showMediaControlsContextMenu`
as that's the signal to the `MediaController` that the contextmenu interaction is over,
which adjusts the `on` state of the `Button`.

Source/WebKit:

Pipe along the `-[NSMenuDelegate menuDidClose:]` signal to the WebProcess so the `WebCore::ContextMenuProvider`
can handle it if needed.

* UIProcess/WebContextMenuProxy.cpp:
(WebKit::WebContextMenuProxy::useContextMenuItems):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WKMenuDelegate menuWillOpen:]):
(-[WKMenuDelegate menuDidClose:]):

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showContextMenu):
(WebKit::WebPageProxy::didShowContextMenu):
(WebKit::WebPageProxy::didDismissContextMenu): Added.

* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::show):

* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::startWaitingForContextMenuToShow): Added.
(WebKit::WebPage::contextMenuShowing): Deleted.
(WebKit::WebPage::contextMenuHidden): Deleted.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didShowContextMenu): Added.
(WebKit::WebPage::didDismissContextMenu): Added.
(WebKit::WebPage::mouseEvent):
Drive-by: Rename `m_contextMenuShowing` to `m_waitingForContextMenuToShow` for clarity.

Tools:

* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView dismissActiveMenu]):
(-[TestRunnerWKWebView immediatelyDismissContextMenuIfNeeded]):
(-[TestRunnerWKWebView _dismissAllContextMenuInteractions]): Added.

LayoutTests:

* media/modern-media-controls/overflow-support/button-state.html: Added.
* media/modern-media-controls/overflow-support/button-state-expected.txt: Added.

* media/modern-media-controls/overflow-support/playback-speed.html:
* media/modern-media-controls/tracks-support/click-track-in-contextmenu.html:
Adjust how these tests wait for and dismiss the contextmenu.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolsoverflowsupportplaybackspeedhtml">trunk/LayoutTests/media/modern-media-controls/overflow-support/playback-speed.html</a></li>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolstrackssupportclicktrackincontextmenuhtml">trunk/LayoutTests/media/modern-media-controls/tracks-support/click-track-in-contextmenu.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp">trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuControllercpp">trunk/Source/WebCore/page/ContextMenuController.cpp</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuControllerh">trunk/Source/WebCore/page/ContextMenuController.h</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuProviderh">trunk/Source/WebCore/page/ContextMenuProvider.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebContextMenuProxycpp">trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebContextMenucpp">trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagecpp">trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagemessagesin">trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsWebKitTestRunnercocoaTestRunnerWKWebViewmm">trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolsoverflowsupportbuttonstateexpectedtxt">trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediamodernmediacontrolsoverflowsupportbuttonstatehtml">trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/LayoutTests/ChangeLog 2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2021-07-27  Devin Rousso  <drousso@apple.com>
+
+        [Modern Media Controls] [macOS] Overflow button still shows as `on` even after contextmenu is dismissed
+        https://bugs.webkit.org/show_bug.cgi?id=228310
+        <rdar://problem/81124786>
+
+        Reviewed by Wenson Hsieh.
+
+        * media/modern-media-controls/overflow-support/button-state.html: Added.
+        * media/modern-media-controls/overflow-support/button-state-expected.txt: Added.
+
+        * media/modern-media-controls/overflow-support/playback-speed.html:
+        * media/modern-media-controls/tracks-support/click-track-in-contextmenu.html:
+        Adjust how these tests wait for and dismiss the contextmenu.
+
</ins><span class="cx"> 2021-07-27  Amir Mark Jr  <amir_mark@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [LayoutTests] Delete unused LayoutTests/inspector resources
</span></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolsoverflowsupportbuttonstateexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state-expected.txt (0 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state-expected.txt                         (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state-expected.txt    2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+Testing that the overflow button is properly marked as `on` only when the context menu is showing.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS shadowRoot.querySelector('button.overflow') became different from null
+PASS shadowRoot.querySelector('button.overflow').getBoundingClientRect().width became different from 0
+Tapping overflow button...
+PASS shadowRoot.querySelector('button.overflow').classList.contains('on') became true
+Dismissing contextmenu...
+PASS shadowRoot.querySelector('button.overflow').classList.contains('on') became false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolsoverflowsupportbuttonstatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state.html (0 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state.html                         (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/overflow-support/button-state.html    2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<meta name="viewport" content="width=device-width">
+<script src="../resources/media-controls-utils.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+<script src="../../../resources/js-test-pre.js"></script>
+<body>
+<video src="../../content/test.mp4" style="position: absolute; left: 0; top: 0; width: 600px;" controls autoplay></video>
+<script type="text/javascript">
+
+window.jsTestIsAsync = true;
+
+description("Testing that the overflow button is properly marked as `on` only when the context menu is showing.");
+
+const media = document.querySelector("video");
+const shadowRoot = window.internals.shadowRoot(media);
+
+media.addEventListener("play", async function() {
+    media.pause();
+
+    await shouldBecomeDifferent("shadowRoot.querySelector('button.overflow')", "null");
+
+    await shouldBecomeDifferent("shadowRoot.querySelector('button.overflow').getBoundingClientRect().width", "0");
+
+    debug("Tapping overflow button...");
+    await pressOnElement(shadowRoot.querySelector("button.overflow"));
+    await UIHelper.waitForContextMenuToShow();
+    await shouldBecomeEqual("shadowRoot.querySelector('button.overflow').classList.contains('on')", "true");
+
+    debug("Dismissing contextmenu...");
+    await new Promise((resolve, reject) => {
+        testRunner.runUIScript(`
+            uiController.dismissMenu();
+            uiController.uiScriptComplete();
+        `, resolve);
+    });
+    await UIHelper.waitForContextMenuToHide();
+    await shouldBecomeEqual("shadowRoot.querySelector('button.overflow').classList.contains('on')", "false");
+
+    media.remove();
+    finishJSTest();
+});
+
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
</ins></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolsoverflowsupportplaybackspeedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/media/modern-media-controls/overflow-support/playback-speed.html (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/overflow-support/playback-speed.html       2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/LayoutTests/media/modern-media-controls/overflow-support/playback-speed.html  2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -30,6 +30,13 @@
</span><span class="cx">             checkedItems = contextmenu[0].children.filter((item) => item.checked);
</span><span class="cx">             shouldBe("checkedItems.length", "1");
</span><span class="cx">             shouldBeEqualToString("checkedItems[0].title", `1${multiplicationSign}`);
</span><ins>+
+            await new Promise((resolve, reject) => {
+                testRunner.runUIScript(`
+                    uiController.dismissMenu();
+                    uiController.uiScriptComplete();
+                `, resolve);
+            });
</ins><span class="cx">             await UIHelper.waitForContextMenuToHide();
</span><span class="cx"> 
</span><span class="cx">             debug("Changing playback speed via JavaScript...");
</span></span></pre></div>
<a id="trunkLayoutTestsmediamodernmediacontrolstrackssupportclicktrackincontextmenuhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/media/modern-media-controls/tracks-support/click-track-in-contextmenu.html (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/modern-media-controls/tracks-support/click-track-in-contextmenu.html     2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/LayoutTests/media/modern-media-controls/tracks-support/click-track-in-contextmenu.html        2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx"> async function clickOnFrenchAudioTrack()
</span><span class="cx"> {
</span><span class="cx">     debug("Selecting 'French' track...");
</span><del>-    await getTracksContextMenu();
</del><ins>+    await UIHelper.waitForContextMenuToShow();
</ins><span class="cx">     await UIHelper.chooseMenuAction("French Sound");
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -50,7 +50,7 @@
</span><span class="cx"> async function clickOnSpanishAudioTrack()
</span><span class="cx"> {
</span><span class="cx">     debug("Selecting 'Spanish' track...");
</span><del>-    await getTracksContextMenu();
</del><ins>+    await UIHelper.waitForContextMenuToShow();
</ins><span class="cx">     await UIHelper.chooseMenuAction("Spanish Sound");
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebCore/ChangeLog      2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2021-07-27  Devin Rousso  <drousso@apple.com>
+
+        [Modern Media Controls] [macOS] Overflow button still shows as `on` even after contextmenu is dismissed
+        https://bugs.webkit.org/show_bug.cgi?id=228310
+        <rdar://problem/81124786>
+
+        Reviewed by Wenson Hsieh.
+
+        Test: media/modern-media-controls/overflow-support/button-state.html
+
+        * page/ContextMenuController.h:
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::didDismissContextMenu): Added.
+        * page/ContextMenuProvider.h:
+        (WebCore::ContextMenuProvider::didDismissContextMenu): Added.
+        Add plumbing from WebKit to the `ContextMenuProvider` for when the contextmenu is dismissed.
+
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        (WebCore::MediaControlsContextMenuProvider::didDismissContextMenu): Added.
+        When the contextmenu is dismissed, invoke the callback provided to `MediaControlsHost::showMediaControlsContextMenu`
+        as that's the signal to the `MediaController` that the contextmenu interaction is over,
+        which adjusts the `on` state of the `Button`.
+
</ins><span class="cx"> 2021-07-27  Ryosuke Niwa  <rniwa@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         [macOS] Stop away unpaired surrogate pair in findNextWordFromIndex:forward:
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediacontrolsMediaControlsHostcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp 2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp    2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -388,6 +388,12 @@
</span><span class="cx">             menu->appendItem(item);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void didDismissContextMenu() override
+    {
+        if (m_callback)
+            m_callback(ContextMenuItemTagNoAction);
+    }
+
</ins><span class="cx">     void contextMenuItemSelected(ContextMenuAction action, const String&) override
</span><span class="cx">     {
</span><span class="cx">         m_callback(action - ContextMenuItemBaseCustomTag);
</span><span class="lines">@@ -455,14 +461,8 @@
</span><span class="cx"> bool MediaControlsHost::showMediaControlsContextMenu(HTMLElement& target, String&& optionsJSONString, Ref<VoidCallback>&& callback)
</span><span class="cx"> {
</span><span class="cx"> #if USE(UICONTEXTMENU) || (ENABLE(CONTEXT_MENUS) && USE(ACCESSIBILITY_CONTEXT_MENUS))
</span><del>-    if (m_showMediaControlsContextMenuCallback) {
-#if USE(UICONTEXTMENU)
</del><ins>+    if (m_showMediaControlsContextMenuCallback)
</ins><span class="cx">         return false;
</span><del>-#elif (ENABLE(CONTEXT_MENUS) && USE(ACCESSIBILITY_CONTEXT_MENUS))
-        // FIXME: `contextMenuCleared` is invoked between show and item selected so we may have a pending callback.
-        std::exchange(m_showMediaControlsContextMenuCallback, nullptr)->handleEvent();
-#endif
-    }
</del><span class="cx"> 
</span><span class="cx">     m_showMediaControlsContextMenuCallback = WTFMove(callback);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuController.cpp      2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp 2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -172,6 +172,12 @@
</span><span class="cx">     event.setDefaultHandled();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ContextMenuController::didDismissContextMenu()
+{
+    if (m_menuProvider)
+        m_menuProvider->didDismissContextMenu();
+}
+
</ins><span class="cx"> static void openNewWindow(const URL& urlToLoad, Frame& frame, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy)
</span><span class="cx"> {
</span><span class="cx">     Page* oldPage = frame.page();
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuController.h (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuController.h        2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebCore/page/ContextMenuController.h   2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx">     void showContextMenu(Event&, ContextMenuProvider&);
</span><span class="cx"> 
</span><span class="cx">     void populate();
</span><ins>+    WEBCORE_EXPORT void didDismissContextMenu();
</ins><span class="cx">     WEBCORE_EXPORT void contextMenuItemSelected(ContextMenuAction, const String& title);
</span><span class="cx">     void addInspectElementItem();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuProviderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuProvider.h (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuProvider.h  2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebCore/page/ContextMenuProvider.h     2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">     virtual ~ContextMenuProvider() { };
</span><span class="cx"> 
</span><span class="cx">     virtual void populateContextMenu(ContextMenu*) = 0;
</span><ins>+    virtual void didDismissContextMenu() { }
</ins><span class="cx">     virtual void contextMenuItemSelected(ContextMenuAction, const String& title) = 0;
</span><span class="cx">     virtual void contextMenuCleared() = 0;
</span><span class="cx">     virtual ContextMenuContext::Type contextMenuContextType() { return ContextMenuContext::Type::ContextMenu; };
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/ChangeLog       2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2021-07-27  Devin Rousso  <drousso@apple.com>
+
+        [Modern Media Controls] [macOS] Overflow button still shows as `on` even after contextmenu is dismissed
+        https://bugs.webkit.org/show_bug.cgi?id=228310
+        <rdar://problem/81124786>
+
+        Reviewed by Wenson Hsieh.
+
+        Pipe along the `-[NSMenuDelegate menuDidClose:]` signal to the WebProcess so the `WebCore::ContextMenuProvider`
+        can handle it if needed.
+
+        * UIProcess/WebContextMenuProxy.cpp:
+        (WebKit::WebContextMenuProxy::useContextMenuItems):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (-[WKMenuDelegate menuWillOpen:]):
+        (-[WKMenuDelegate menuDidClose:]):
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showContextMenu):
+        (WebKit::WebPageProxy::didShowContextMenu):
+        (WebKit::WebPageProxy::didDismissContextMenu): Added.
+
+        * WebProcess/WebPage/WebContextMenu.cpp:
+        (WebKit::WebContextMenu::show):
+
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::startWaitingForContextMenuToShow): Added.
+        (WebKit::WebPage::contextMenuShowing): Deleted.
+        (WebKit::WebPage::contextMenuHidden): Deleted.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::didShowContextMenu): Added.
+        (WebKit::WebPage::didDismissContextMenu): Added.
+        (WebKit::WebPage::mouseEvent):
+        Drive-by: Rename `m_contextMenuShowing` to `m_waitingForContextMenuToShow` for clarity.
+
</ins><span class="cx"> 2021-07-27  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [GPU Process] Code cleanup after r280356
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebContextMenuProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp    2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp       2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx">     showContextMenuWithItems(WTFMove(items));
</span><span class="cx"> 
</span><span class="cx">     // No matter the result of showContextMenuWithItems, always notify the WebProcess that the menu is hidden so it starts handling mouse events again.
</span><del>-    page->send(Messages::WebPage::ContextMenuHidden());
</del><ins>+    page->send(Messages::WebPage::DidShowContextMenu());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -6828,7 +6828,7 @@
</span><span class="cx">     // can hang the page / WebDriver test. Pretend to show and immediately dismiss the context menu.
</span><span class="cx">     if (auto* automationSession = process().processPool().automationSession()) {
</span><span class="cx">         if (m_controlledByAutomation && automationSession->isSimulatingUserInteraction()) {
</span><del>-            send(Messages::WebPage::ContextMenuHidden());
</del><ins>+            send(Messages::WebPage::DidShowContextMenu());
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -6844,6 +6844,21 @@
</span><span class="cx">     m_activeContextMenu->show();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::didShowContextMenu()
+{
+    // Don't send `Messages::WebPage::DidShowContextMenu` as that should've already been eagerly
+    // sent when requesting the context menu to show, regardless of the result of that request.
+
+    pageClient().didShowContextMenu();
+}
+
+void WebPageProxy::didDismissContextMenu()
+{
+    send(Messages::WebPage::DidDismissContextMenu());
+
+    pageClient().didDismissContextMenu();
+}
+
</ins><span class="cx"> void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
</span><span class="cx"> {
</span><span class="cx">     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1314,6 +1314,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx">     // Called by the WebContextMenuProxy.
</span><ins>+    void didShowContextMenu();
+    void didDismissContextMenu();
</ins><span class="cx">     void contextMenuItemSelected(const WebContextMenuItemData&);
</span><span class="cx">     void handleContextMenuKeyEvent();
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm      2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -171,12 +171,12 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)menuWillOpen:(NSMenu *)menu
</span><span class="cx"> {
</span><del>-    _menuProxy->page()->pageClient().didShowContextMenu();
</del><ins>+    _menuProxy->page()->didShowContextMenu();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)menuDidClose:(NSMenu *)menu
</span><span class="cx"> {
</span><del>-    _menuProxy->page()->pageClient().didDismissContextMenu();
</del><ins>+    _menuProxy->page()->didDismissContextMenu();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebContextMenucpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp        2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebContextMenu.cpp   2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -68,7 +68,7 @@
</span><span class="cx">     ContextMenuContextData contextMenuContextData(menuLocation, menuItems, controller.context());
</span><span class="cx"> 
</span><span class="cx">     // Mark the WebPage has having a shown context menu then notify the UIProcess.
</span><del>-    m_page->contextMenuShowing();
</del><ins>+    m_page->startWaitingForContextMenuToShow();
</ins><span class="cx">     m_page->flushPendingEditorStateUpdate();
</span><span class="cx">     m_page->send(Messages::WebPageProxy::ShowContextMenu(contextMenuContextData, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp       2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp  2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -2857,6 +2857,20 @@
</span><span class="cx">     const WebEvent* m_previousCurrentEvent;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+
+void WebPage::didShowContextMenu()
+{
+    m_waitingForContextMenuToShow = false;
+}
+
+void WebPage::didDismissContextMenu()
+{
+    corePage()->contextMenuController().didDismissContextMenu();
+}
+
+#endif // ENABLE(CONTEXT_MENUS)
+
</ins><span class="cx"> #if ENABLE(CONTEXT_MENU_EVENT)
</span><span class="cx"> static bool isContextClick(const PlatformMouseEvent& event)
</span><span class="cx"> {
</span><span class="lines">@@ -2962,7 +2976,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx">     // Don't try to handle any pending mouse events if a context menu is showing.
</span><del>-    if (m_isShowingContextMenu)
</del><ins>+    if (m_waitingForContextMenuToShow)
</ins><span class="cx">         shouldHandleEvent = false;
</span><span class="cx"> #endif
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1050,7 +1050,7 @@
</span><span class="cx">     void simulateMouseMotion(WebCore::IntPoint, WallTime);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><del>-    void contextMenuShowing() { m_isShowingContextMenu = true; }
</del><ins>+    void startWaitingForContextMenuToShow() { m_waitingForContextMenuToShow = true; }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     bool wheelEvent(const WebWheelEvent&, OptionSet<WebCore::WheelEventProcessingSteps>);
</span><span class="lines">@@ -1620,7 +1620,8 @@
</span><span class="cx">     void touchWithIdentifierWasRemoved(WebCore::PointerID);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><del>-    void contextMenuHidden() { m_isShowingContextMenu = false; }
</del><ins>+    void didShowContextMenu();
+    void didDismissContextMenu();
</ins><span class="cx"> #endif
</span><span class="cx"> #if ENABLE(CONTEXT_MENU_EVENT)
</span><span class="cx">     void contextMenuForKeyEvent();
</span><span class="lines">@@ -2172,7 +2173,7 @@
</span><span class="cx">     OptionSet<WebCore::ActivityState::Flag> m_lastActivityStateChanges;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><del>-    bool m_isShowingContextMenu { false };
</del><ins>+    bool m_waitingForContextMenuToShow { false };
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     RefPtr<WebCore::Element> m_focusedElement;
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in       2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in  2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -164,11 +164,6 @@
</span><span class="cx">     DidEndDateTimePicker();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if ENABLE(CONTEXT_MENUS)
-    ContextMenuHidden()
-    ContextMenuForKeyEvent()
-#endif
-
</del><span class="cx">     ScrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
</span><span class="cx">     CenterSelectionInVisibleArea()
</span><span class="cx"> 
</span><span class="lines">@@ -345,7 +340,10 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx">     # Context menu.
</span><ins>+    DidShowContextMenu()
+    DidDismissContextMenu()
</ins><span class="cx">     DidSelectItemFromActiveContextMenu(WebKit::WebContextMenuItemData menuItem)
</span><ins>+    ContextMenuForKeyEvent()
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     # Open panel.
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Tools/ChangeLog       2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-07-27  Devin Rousso  <drousso@apple.com>
+
+        [Modern Media Controls] [macOS] Overflow button still shows as `on` even after contextmenu is dismissed
+        https://bugs.webkit.org/show_bug.cgi?id=228310
+        <rdar://problem/81124786>
+
+        Reviewed by Wenson Hsieh.
+
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
+        (-[TestRunnerWKWebView dismissActiveMenu]):
+        (-[TestRunnerWKWebView immediatelyDismissContextMenuIfNeeded]):
+        (-[TestRunnerWKWebView _dismissAllContextMenuInteractions]): Added.
+
</ins><span class="cx"> 2021-07-27  Diego Pino Garcia  <dpino@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [GTK][WPE] Fix wrong path to GLIB dependencies introduced in r280354.
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnercocoaTestRunnerWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm (280373 => 280374)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm        2021-07-28 03:02:11 UTC (rev 280373)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm   2021-07-28 03:56:44 UTC (rev 280374)
</span><span class="lines">@@ -185,6 +185,7 @@
</span><span class="cx"> - (void)dismissActiveMenu
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><ins>+    [self _dismissAllContextMenuInteractions];
</ins><span class="cx">     [self resignFirstResponder];
</span><span class="cx"> #else
</span><span class="cx">     auto menu = retainPtr(self._activeMenu);
</span><span class="lines">@@ -253,6 +254,11 @@
</span><span class="cx"> 
</span><span class="cx">     self.showingContextMenu = NO;
</span><span class="cx"> 
</span><ins>+    [self _dismissAllContextMenuInteractions];
+}
+
+- (void)_dismissAllContextMenuInteractions
+{
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     for (id <UIInteraction> interaction in self.contentView.interactions) {
</span><span class="cx">         if ([interaction isKindOfClass:UIContextMenuInteraction.class])
</span></span></pre>
</div>
</div>

</body>
</html>