Skip to content
Permalink
Browse files
WebContextMenuProxy doesn't have to be ref-counted
https://bugs.webkit.org/show_bug.cgi?id=150415

Reviewed by Tim Horton.

Change WebContextMenuProxy to not inherit from RefCounted. Instead of using RefPtr, use std::unique_ptr.
Get rid of cancelTracking and hideContextMenu and dismiss the menu whenever the menu proxy is destroyed.
Also, rename showContextMenu to show.

* UIProcess/PageClient.h:
* UIProcess/WebContextMenuProxy.h:
(WebKit::WebContextMenuProxy::cancelTracking): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::internalShowContextMenu):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::create): Deleted.
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::show):
(WebKit::WebContextMenuProxyMac::showContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::hideContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::cancelTracking): Deleted.

Canonical link: https://commits.webkit.org/168567@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191402 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Oct 21, 2015
1 parent 121a490 commit 589bb2a187e9b13ce785123af2f84f4891183e2e
Showing 11 changed files with 49 additions and 43 deletions.
@@ -1,3 +1,36 @@
2015-10-21 Anders Carlsson <andersca@apple.com>

WebContextMenuProxy doesn't have to be ref-counted
https://bugs.webkit.org/show_bug.cgi?id=150415

Reviewed by Tim Horton.

Change WebContextMenuProxy to not inherit from RefCounted. Instead of using RefPtr, use std::unique_ptr.
Get rid of cancelTracking and hideContextMenu and dismiss the menu whenever the menu proxy is destroyed.
Also, rename showContextMenu to show.

* UIProcess/PageClient.h:
* UIProcess/WebContextMenuProxy.h:
(WebKit::WebContextMenuProxy::cancelTracking): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::internalShowContextMenu):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::createContextMenuProxy):
* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::create): Deleted.
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::show):
(WebKit::WebContextMenuProxyMac::showContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::hideContextMenu): Deleted.
(WebKit::WebContextMenuProxyMac::cancelTracking): Deleted.

2015-10-21 Anders Carlsson <andersca@apple.com>

Stop using a popup menu button cell(!) for context menus
@@ -224,7 +224,7 @@ class PageClient {

virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) = 0;
#if ENABLE(CONTEXT_MENUS)
virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0;
virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) = 0;
#endif

#if ENABLE(INPUT_TYPE_COLOR)
@@ -36,13 +36,11 @@ namespace WebKit {

class WebContextMenuItem;

class WebContextMenuProxy : public RefCounted<WebContextMenuProxy> {
class WebContextMenuProxy {
public:
virtual ~WebContextMenuProxy();

virtual void showContextMenu() = 0;
virtual void hideContextMenu() = 0;
virtual void cancelTracking() { }
virtual void show() = 0;

protected:
WebContextMenuProxy(const ContextMenuContextData&, const UserData&);
@@ -817,8 +817,7 @@ void WebPageProxy::close()
m_activePopupMenu->cancelTracking();

#if ENABLE(CONTEXT_MENUS)
if (m_activeContextMenu)
m_activeContextMenu->cancelTracking();
m_activeContextMenu = nullptr;
#endif

m_backForwardList->pageClosed();
@@ -4197,19 +4196,14 @@ void WebPageProxy::internalShowContextMenu(const ContextMenuContextData& context
{
m_activeContextMenuContextData = contextMenuContextData;

if (!m_contextMenuClient->hideContextMenu(*this) && m_activeContextMenu) {
m_activeContextMenu->hideContextMenu();
m_activeContextMenu = nullptr;
}

m_activeContextMenu = m_pageClient.createContextMenuProxy(*this, contextMenuContextData, userData);
if (!m_activeContextMenu)
return;

// Since showContextMenu() can spin a nested run loop we need to turn off the responsiveness timer.
m_process->responsivenessTimer()->stop();

m_activeContextMenu->showContextMenu();
m_activeContextMenu->show();
}

void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
@@ -1546,7 +1546,7 @@ class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>

RefPtr<WebPopupMenuProxy> m_activePopupMenu;
#if ENABLE(CONTEXT_MENUS)
RefPtr<WebContextMenuProxy> m_activeContextMenu;
std::unique_ptr<WebContextMenuProxy> m_activeContextMenu;
ContextMenuContextData m_activeContextMenuContextData;
#endif
RefPtr<API::HitTestResult> m_lastMouseMoveHitTestResult;
@@ -97,7 +97,7 @@ class PageClientImpl : public PageClient
#endif
virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
#if ENABLE(CONTEXT_MENUS)
virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
#endif
virtual void setTextIndicator(Ref<WebCore::TextIndicator>, WebCore::TextIndicatorWindowLifetime) override;
virtual void clearTextIndicator(WebCore::TextIndicatorWindowDismissalAnimation) override;
@@ -444,7 +444,7 @@ - (void)redoEditing:(id)sender
}

#if ENABLE(CONTEXT_MENUS)
RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const UserData&)
std::unique_ptr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy&, const UserData&)
{
return nullptr;
}
@@ -127,7 +127,7 @@ class PageClientImpl final : public PageClient

virtual RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
#if ENABLE(CONTEXT_MENUS)
virtual RefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
virtual std::unique_ptr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, const ContextMenuContextData&, const UserData&) override;
#endif

#if ENABLE(INPUT_TYPE_COLOR)
@@ -500,9 +500,9 @@ - (void)redoEditing:(id)sender
}

#if ENABLE(CONTEXT_MENUS)
RefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
std::unique_ptr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
{
return WebContextMenuProxyMac::create(m_wkView, page, context, userData);
return std::make_unique<WebContextMenuProxyMac>(m_wkView, page, context, userData);
}
#endif

@@ -44,17 +44,9 @@ class WebPageProxy;

class WebContextMenuProxyMac : public WebContextMenuProxy {
public:
static Ref<WebContextMenuProxyMac> create(WKView* webView, WebPageProxy& page, const ContextMenuContextData& context, const UserData& userData)
{
return adoptRef(*new WebContextMenuProxyMac(webView, page, context, userData));
}
WebContextMenuProxyMac(WKView*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
~WebContextMenuProxyMac();

virtual void showContextMenu() override;

virtual void hideContextMenu() override;
virtual void cancelTracking() override;

void contextMenuItemSelected(const WebContextMenuItemData&);

#if ENABLE(SERVICE_CONTROLS)
@@ -65,7 +57,7 @@ class WebContextMenuProxyMac : public WebContextMenuProxy {
NSWindow *window() const;

private:
WebContextMenuProxyMac(WKView*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
virtual void show() override;

void populate(const Vector<RefPtr<WebContextMenuItem>>&);

@@ -160,6 +160,7 @@ - (void)forwardContextMenuAction:(id)sender

WebContextMenuProxyMac::~WebContextMenuProxyMac()
{
[m_menu cancelTracking];
}

void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItemData& item)
@@ -374,7 +375,7 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me
populateNSMenu(m_menu.get(), nsMenuItemVector(items));
}

void WebContextMenuProxyMac::showContextMenu()
void WebContextMenuProxyMac::show()
{
// Unless this is an image control, give the PageContextMenuClient one last swipe at changing the menu.
bool askClientToChangeMenu = true;
@@ -422,21 +423,9 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me
[[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setMenuProxy:this];
#endif

Ref<WebContextMenuProxyMac> protect(*this);
Ref<WebPageProxy> protect(m_page);

[m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];

hideContextMenu();
}

void WebContextMenuProxyMac::hideContextMenu()
{
[m_menu cancelTracking];
}

void WebContextMenuProxyMac::cancelTracking()
{
[m_menu cancelTracking];
}

NSWindow *WebContextMenuProxyMac::window() const

0 comments on commit 589bb2a

Please sign in to comment.