Make action menus much more reliable
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Nov 2014 19:06:15 +0000 (19:06 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Nov 2014 19:06:15 +0000 (19:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138654
<rdar://problem/18909111>

Reviewed by Anders Carlsson.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController prepareForMenu:withEvent:]):
Remove MenuUpdateStage; nothing actually uses this value, we just pass it around.

(-[WKActionMenuController didPerformActionMenuHitTest:userData:]):
Update the menu as soon as we have a reply from the Web process.

(-[WKActionMenuController menuNeedsUpdate:]):
If our sync-wait for the Web process' reply times out, we should still update
the menu to remove the placeholder separator item.

(-[WKActionMenuController _updateActionMenuItems]):
(-[WKActionMenuController _updateActionMenuItemsForStage:]): Deleted.
If we have our final answer for this menu (_state == Ready), and the final answer
has no items in the menu, cancel tracking on the menu.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176027 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm

index 8f5071718ac7b061a8b02a0b7cd99e4024946d11..765d82622a66112d7ef769346914fdf6131c2fd7 100644 (file)
@@ -1,3 +1,27 @@
+2014-11-12  Tim Horton  <timothy_horton@apple.com>
+
+        Make action menus much more reliable
+        https://bugs.webkit.org/show_bug.cgi?id=138654
+        <rdar://problem/18909111>
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController prepareForMenu:withEvent:]):
+        Remove MenuUpdateStage; nothing actually uses this value, we just pass it around.
+
+        (-[WKActionMenuController didPerformActionMenuHitTest:userData:]):
+        Update the menu as soon as we have a reply from the Web process.
+
+        (-[WKActionMenuController menuNeedsUpdate:]):
+        If our sync-wait for the Web process' reply times out, we should still update
+        the menu to remove the placeholder separator item.
+
+        (-[WKActionMenuController _updateActionMenuItems]):
+        (-[WKActionMenuController _updateActionMenuItemsForStage:]): Deleted.
+        If we have our final answer for this menu (_state == Ready), and the final answer
+        has no items in the menu, cancel tracking on the menu.
+
 2014-11-12  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Move RedirectedXCompositeWindow from platform to WebKit2 layer
index 28f77e4f1c876d2d998b808c625eb9239341183e..f32e2b8afc7bb815c0ecde42ed5763113b2e0687 100644 (file)
 #import <WebCore/SoftLinking.h>
 #import <WebCore/URL.h>
 
-enum class MenuUpdateStage {
-    PrepareForMenu,
-    MenuNeedsUpdate
-};
-
 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(Quartz, ImageKit)
 SOFT_LINK_CLASS(ImageKit, IKSlideshow)
 
@@ -63,7 +58,7 @@ using namespace WebCore;
 using namespace WebKit;
 
 @interface WKActionMenuController () <NSSharingServiceDelegate, NSSharingServicePickerDelegate, NSPopoverDelegate>
-- (void)_updateActionMenuItemsForStage:(MenuUpdateStage)stage;
+- (void)_updateActionMenuItems;
 - (BOOL)_canAddMediaToPhotos;
 - (void)_showTextIndicator;
 - (void)_hideTextIndicator;
@@ -181,7 +176,7 @@ using namespace WebKit;
     _page->performActionMenuHitTestAtLocation([_wkView convertPoint:event.locationInWindow fromView:nil]);
 
     _state = ActionMenuState::Pending;
-    [self _updateActionMenuItemsForStage:MenuUpdateStage::PrepareForMenu];
+    [self _updateActionMenuItems];
 
     _shouldKeepPreviewPopoverOpen = NO;
 }
@@ -240,6 +235,8 @@ using namespace WebKit;
     _state = ActionMenuState::Ready;
     _hitTestResult = hitTestResult;
     _userData = userData;
+
+    [self _updateActionMenuItems];
 }
 
 - (void)dismissActionMenuPopovers
@@ -685,7 +682,8 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
             connection->waitForAndDispatchImmediately<Messages::WebPageProxy::DidPerformActionMenuHitTest>(_page->pageID(), std::chrono::milliseconds(500));
     }
 
-    [self _updateActionMenuItemsForStage:MenuUpdateStage::MenuNeedsUpdate];
+    if (_state != ActionMenuState::Ready)
+        [self _updateActionMenuItems];
 }
 
 - (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item
@@ -909,7 +907,7 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     return _state != ActionMenuState::Ready ? @[ [NSMenuItem separatorItem] ] : @[ ];
 }
 
-- (void)_updateActionMenuItemsForStage:(MenuUpdateStage)stage
+- (void)_updateActionMenuItems
 {
     [_wkView.actionMenu removeAllItems];
 
@@ -923,6 +921,9 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
 
     for (NSMenuItem *item in menuItems)
         [_wkView.actionMenu addItem:item];
+
+    if (_state == ActionMenuState::Ready && !_wkView.actionMenu.numberOfItems)
+        [_wkView.actionMenu cancelTracking];
 }
 
 #if WK_API_ENABLED