Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stop using a popup menu button cell(!) for context menus
https://bugs.webkit.org/show_bug.cgi?id=150413

Reviewed by Tim Horton.

Just use a regular NSMenu. Also, have the service menu code path store the service menu
in the same member variable.

* UIProcess/mac/WebContextMenuProxyMac.h:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::setupServicesMenu):
(WebKit::WebContextMenuProxyMac::clearServicesMenu):
(WebKit::WebContextMenuProxyMac::populate):
(WebKit::WebContextMenuProxyMac::showContextMenu):
(WebKit::WebContextMenuProxyMac::hideContextMenu):
(WebKit::WebContextMenuProxyMac::cancelTracking):
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac): Deleted.

Canonical link: https://commits.webkit.org/168566@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Oct 21, 2015
1 parent 0795ef4 commit 121a490
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
20 changes: 20 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,23 @@
2015-10-21 Anders Carlsson <andersca@apple.com>

Stop using a popup menu button cell(!) for context menus
https://bugs.webkit.org/show_bug.cgi?id=150413

Reviewed by Tim Horton.

Just use a regular NSMenu. Also, have the service menu code path store the service menu
in the same member variable.

* UIProcess/mac/WebContextMenuProxyMac.h:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::setupServicesMenu):
(WebKit::WebContextMenuProxyMac::clearServicesMenu):
(WebKit::WebContextMenuProxyMac::populate):
(WebKit::WebContextMenuProxyMac::showContextMenu):
(WebKit::WebContextMenuProxyMac::hideContextMenu):
(WebKit::WebContextMenuProxyMac::cancelTracking):
(WebKit::WebContextMenuProxyMac::~WebContextMenuProxyMac): Deleted.

2015-10-21 Chris Dumez <cdumez@apple.com>

Add assertions to NetworkCache::Entry constructor to make sure a key's type is "resource"
Expand Down
6 changes: 2 additions & 4 deletions Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h
Expand Up @@ -74,10 +74,8 @@ class WebContextMenuProxyMac : public WebContextMenuProxy {
WebCore::ContextMenuItem shareMenuItem();
#endif

RetainPtr<NSPopUpButtonCell> m_popup;
#if ENABLE(SERVICE_CONTROLS)
RetainPtr<NSMenu> m_servicesMenu;
#endif
RetainPtr<NSMenu> m_menu;

WKView* m_webView;
WebPageProxy& m_page;
};
Expand Down
74 changes: 15 additions & 59 deletions Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm
Expand Up @@ -160,7 +160,6 @@ - (void)forwardContextMenuAction:(id)sender

WebContextMenuProxyMac::~WebContextMenuProxyMac()
{
[m_popup setControlView:nil];
}

void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItemData& item)
Expand Down Expand Up @@ -284,10 +283,10 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me
[[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setFiltersEditingServices:!includeEditorServices];
[[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setHandlesEditingReplacement:includeEditorServices];

m_servicesMenu = adoptNS([[picker menu] copy]);
m_menu = adoptNS([[picker menu] copy]);

if (!hasControlledImage)
[m_servicesMenu setShowsStateColumn:YES];
[m_menu setShowsStateColumn:YES];

// Explicitly add a menu item for each telephone number that is in the selection.
const Vector<String>& selectedTelephoneNumbers = context.selectedTelephoneNumbers();
Expand All @@ -300,28 +299,28 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me
}

if (!telephoneNumberMenuItems.isEmpty()) {
if (m_servicesMenu)
[m_servicesMenu insertItem:[NSMenuItem separatorItem] atIndex:0];
if (m_menu)
[m_menu insertItem:[NSMenuItem separatorItem] atIndex:0];
else
m_servicesMenu = adoptNS([[NSMenu alloc] init]);
m_menu = adoptNS([[NSMenu alloc] init]);
int itemPosition = 0;
NSMenuItem *groupEntry = [[NSMenuItem alloc] initWithTitle:menuItemTitleForTelephoneNumberGroup() action:nil keyEquivalent:@""];
[groupEntry setEnabled:NO];
[m_servicesMenu insertItem:groupEntry atIndex:itemPosition++];
[m_menu insertItem:groupEntry atIndex:itemPosition++];
for (auto& menuItem : telephoneNumberMenuItems)
[m_servicesMenu insertItem:menuItem.get() atIndex:itemPosition++];
[m_menu insertItem:menuItem.get() atIndex:itemPosition++];
}

// If there is no services menu, then the existing services on the system have changed, so refresh that list of services.
// If <rdar://problem/17954709> is resolved then we can more accurately keep the list up to date without this call.
if (!m_servicesMenu)
if (!m_menu)
ServicesController::singleton().refreshExistingServices();
}

void WebContextMenuProxyMac::clearServicesMenu()
{
[[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:nullptr];
m_servicesMenu = nullptr;
m_menu = nullptr;
}

ContextMenuItem WebContextMenuProxyMac::shareMenuItem()
Expand Down Expand Up @@ -369,17 +368,10 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me
}
#endif

if (m_popup)
[m_popup removeAllItems];
else {
m_popup = adoptNS([[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]);
[m_popup setUsesItemFromMenu:NO];
[m_popup setAutoenablesItems:NO];
[m_popup setAltersStateOfSelectedItem:NO];
}
m_menu = [[NSMenu alloc] initWithTitle:@""];
[m_menu setAutoenablesItems:NO];

NSMenu* menu = [m_popup menu];
populateNSMenu(menu, nsMenuItemVector(items));
populateNSMenu(m_menu.get(), nsMenuItemVector(items));
}

void WebContextMenuProxyMac::showContextMenu()
Expand Down Expand Up @@ -425,62 +417,26 @@ static void populateNSMenu(NSMenu* menu, const Vector<RetainPtr<NSMenuItem>>& me

[[WKMenuTarget sharedMenuTarget] setMenuProxy:this];

NSPoint menuLocation = m_context.menuLocation();
NSRect menuRect = NSMakeRect(menuLocation.x, menuLocation.y, 0, 0);

#if ENABLE(SERVICE_CONTROLS)
if (m_context.isServicesMenu())
[[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setMenuProxy:this];

if (!m_servicesMenu)
[m_popup attachPopUpWithFrame:menuRect inView:m_webView];

NSMenu *menu = m_servicesMenu ? m_servicesMenu.get() : [m_popup menu];

// Telephone number and service menus must use the [NSMenu popUpMenuPositioningItem:atLocation:inView:] API.
// FIXME: That API is better than WKPopupContextMenu. In the future all menus should use either it
// or the [NSMenu popUpContextMenu:withEvent:forView:] API, depending on the menu type.
// Then we could get rid of NSPopUpButtonCell, custom metrics, and WKPopupContextMenu.
if (m_context.isServicesMenu()) {
[menu popUpMenuPositioningItem:nil atLocation:menuLocation inView:m_webView];
hideContextMenu();
return;
}

#else
[m_popup attachPopUpWithFrame:menuRect inView:m_webView];

NSMenu *menu = [m_popup menu];
#endif

// These values were borrowed from AppKit to match their placement of the menu.
NSRect titleFrame = [m_popup titleRectForBounds:menuRect];
if (titleFrame.size.width <= 0 || titleFrame.size.height <= 0)
titleFrame = menuRect;
float vertOffset = roundf((NSMaxY(menuRect) - NSMaxY(titleFrame)) + NSHeight(titleFrame));
NSPoint location = NSMakePoint(NSMinX(menuRect), NSMaxY(menuRect) - vertOffset);

location = [m_webView convertPoint:location toView:nil];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
location = [m_webView.window convertBaseToScreen:location];
#pragma clang diagnostic pop

Ref<WebContextMenuProxyMac> protect(*this);

WKPopupContextMenu(menu, location);
[m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];

hideContextMenu();
}

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

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

NSWindow *WebContextMenuProxyMac::window() const
Expand Down

0 comments on commit 121a490

Please sign in to comment.