Hide the 'Add to Photos' item if it isn't available
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Oct 2014 20:24:13 +0000 (20:24 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Oct 2014 20:24:13 +0000 (20:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138182
<rdar://problem/18814999>

Reviewed by Beth Dakin.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _defaultMenuItemsForImage]):
(-[WKActionMenuController _canAddImageToPhotos]):
(-[WKActionMenuController _addImageToPhotos:]):
Factor _canAddImageToPhotos out of _addImageToPhotos:, and use it in
_defaultMenuItemsForImage to avoid including the menu item in the first place.

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

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

index 74c609c9b56a0ba43097dae47f5f4285f0db5b0d..d9e362f31ae118e4ec7b509a847685be9361eff3 100644 (file)
@@ -1,3 +1,18 @@
+2014-10-29  Tim Horton  <timothy_horton@apple.com>
+
+        Hide the 'Add to Photos' item if it isn't available
+        https://bugs.webkit.org/show_bug.cgi?id=138182
+        <rdar://problem/18814999>
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _defaultMenuItemsForImage]):
+        (-[WKActionMenuController _canAddImageToPhotos]):
+        (-[WKActionMenuController _addImageToPhotos:]):
+        Factor _canAddImageToPhotos out of _addImageToPhotos:, and use it in
+        _defaultMenuItemsForImage to avoid including the menu item in the first place.
+
 2014-10-29  Tim Horton  <timothy_horton@apple.com>
 
         Rename WebPageProxy::activeActionMenuHitTestResult to lastMouseMoveHitTestResult
index c5b7c032f26ea36f97c5767ecc79e1edc5aec61d..0f35aab17952b2120d6bd8b1c18a705239b54030 100644 (file)
@@ -64,6 +64,7 @@ using namespace WebKit;
 
 @interface WKActionMenuController () <NSSharingServiceDelegate, NSSharingServicePickerDelegate>
 - (void)_updateActionMenuItems;
+- (BOOL)_canAddImageToPhotos;
 @end
 
 @interface WKView (WKDeprecatedSPI)
@@ -173,7 +174,11 @@ using namespace WebKit;
 - (NSArray *)_defaultMenuItemsForImage
 {
     RetainPtr<NSMenuItem> copyImageItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyImage];
-    RetainPtr<NSMenuItem> addToPhotosItem = [self _createActionMenuItemForTag:kWKContextActionItemTagAddImageToPhotos];
+    RetainPtr<NSMenuItem> addToPhotosItem;
+    if ([self _canAddImageToPhotos])
+        addToPhotosItem = [self _createActionMenuItemForTag:kWKContextActionItemTagAddImageToPhotos];
+    else
+        addToPhotosItem = [NSMenuItem separatorItem];
     RetainPtr<NSMenuItem> saveToDownloadsItem = [self _createActionMenuItemForTag:kWKContextActionItemTagSaveImageToDownloads];
     RetainPtr<NSMenuItem> shareItem = [self _createActionMenuItemForTag:kWKContextActionItemTagShareImage];
 
@@ -251,10 +256,14 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
     return path;
 }
 
+- (BOOL)_canAddImageToPhotos
+{
+    return [getIKSlideshowClass() canExportToApplication:@"com.apple.Photos"];
+}
+
 - (void)_addImageToPhotos:(id)sender
 {
-    // FIXME: We shouldn't even add the menu item if this is the case, for now.
-    if (![getIKSlideshowClass() canExportToApplication:@"com.apple.Photos"])
+    if (![self _canAddImageToPhotos])
         return;
 
     RefPtr<ShareableBitmap> bitmap = _hitTestResult.image;