Changeset 233436 in webkit


Ignore:
Timestamp:
Jul 2, 2018 2:52:18 PM (6 years ago)
Author:
Megan Gardner
Message:

Enable copy paste on iOS apps for Mac
https://bugs.webkit.org/show_bug.cgi?id=187194
<rdar://problem/41451148>

Reviewed by Darin Adler.

Difficult to test this platform.

UIKit doesn't support itemProviders for iOS apps for Mac, so we need to revert to the
older way of setting a dictionary of objects and keys for items. Not everything is
availble in this form, and we haven't cleaned up our itemProvider code yet, so we
need to case some things out for now. Hopefully in the future, this will be implmented
and can just work as expected, but for now, this is the best workaround.

  • platform/ios/PlatformPasteboardIOS.mm:

(WebCore::registerItemToPasteboard):
(WebCore::PlatformPasteboard::write):
(WebCore::PlatformPasteboard::readURL):

  • platform/ios/WebItemProviderPasteboard.h:
  • platform/ios/WebItemProviderPasteboard.mm:

(-[WebItemProviderRegistrationInfoList itemProvider]):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r233435 r233436  
     12018-07-02  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Enable copy paste on iOS apps for Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=187194
     5        <rdar://problem/41451148>
     6
     7        Reviewed by Darin Adler.
     8
     9        Difficult to test this platform.
     10
     11        UIKit doesn't support itemProviders for iOS apps for Mac, so we need to revert to the
     12        older way of setting a dictionary of objects and keys for items. Not everything is
     13        availble in this form, and we haven't cleaned up our itemProvider code yet, so we
     14        need to case some things out for now. Hopefully in the future, this will be implmented
     15        and can just work as expected, but for now, this is the best workaround.
     16
     17        * platform/ios/PlatformPasteboardIOS.mm:
     18        (WebCore::registerItemToPasteboard):
     19        (WebCore::PlatformPasteboard::write):
     20        (WebCore::PlatformPasteboard::readURL):
     21        * platform/ios/WebItemProviderPasteboard.h:
     22        * platform/ios/WebItemProviderPasteboard.mm:
     23        (-[WebItemProviderRegistrationInfoList itemProvider]):
     24
    1252018-07-02  Eric Carlson  <eric.carlson@apple.com>
    226
  • trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r233339 r233436  
    4646#import <wtf/text/StringHash.h>
    4747
    48 #define PASTEBOARD_SUPPORTS_ITEM_PROVIDERS (PLATFORM(IOS) && !(PLATFORM(WATCHOS) || PLATFORM(APPLETV) || ENABLE(MINIMAL_SIMULATOR)))
     48#define PASTEBOARD_SUPPORTS_ITEM_PROVIDERS (PLATFORM(IOS) && !(PLATFORM(WATCHOS) || PLATFORM(APPLETV)))
     49#define NSURL_SUPPORTS_TITLE (!ENABLE(MINIMAL_SIMULATOR))
    4950
    5051SOFT_LINK_FRAMEWORK(UIKit)
     
    289290static void registerItemToPasteboard(WebItemProviderRegistrationInfoList *representationsToRegister, id <AbstractPasteboard> pasteboard)
    290291{
     292#if ENABLE(MINIMAL_SIMULATOR)
     293    auto itemDictionary = adoptNS([[NSMutableDictionary alloc] init]);
     294    [representationsToRegister enumerateItems:[itemDictionary] (id <WebItemProviderRegistrar> item, NSUInteger) {
     295        if ([item respondsToSelector:@selector(typeIdentifierForClient)] && [item respondsToSelector:@selector(dataForClient)])
     296            [itemDictionary setObject:item.dataForClient forKey:item.typeIdentifierForClient];
     297    }];
     298    [pasteboard setItems:@[ itemDictionary.get() ]];
     299#else
    291300    if (UIItemProvider *itemProvider = representationsToRegister.itemProvider)
    292301        [pasteboard setItemProviders:@[ itemProvider ]];
     
    296305    if ([pasteboard respondsToSelector:@selector(stageRegistrationList:)])
    297306        [pasteboard stageRegistrationList:representationsToRegister];
     307#endif
     308   
    298309}
    299310
     
    387398    auto& pasteboardURL = pasteboardImage.url;
    388399    if (NSURL *nsURL = pasteboardURL.url) {
     400#if NSURL_SUPPORTS_TITLE
    389401        nsURL._title = pasteboardURL.title.isEmpty() ? userVisibleString(pasteboardURL.url) : (NSString *)pasteboardURL.title;
     402#endif
    390403        [representationsToRegister addRepresentingObject:nsURL];
    391404    }
     
    417430
    418431    if (NSURL *nsURL = url.url) {
     432#if NSURL_SUPPORTS_TITLE
    419433        if (!url.title.isEmpty())
    420434            nsURL._title = url.title;
     435#endif
    421436        [representationsToRegister addRepresentingObject:nsURL];
    422437        [representationsToRegister addRepresentingObject:(NSString *)url.url.string()];
     
    659674        return { };
    660675
    661 #if PASTEBOARD_SUPPORTS_ITEM_PROVIDERS
     676#if PASTEBOARD_SUPPORTS_ITEM_PROVIDERS && NSURL_SUPPORTS_TITLE
    662677    title = [url _title];
    663678#else
  • trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h

    r226779 r233436  
    2727
    2828#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
     29
     30// UIItemProviders are not implemented for iOS apps for Mac, because they were depricated last year.
     31// We need to switch over to NSItemProviders everywhere. This should just be a temporary fix.
     32#if defined(TARGET_OS_IOSMAC) && TARGET_OS_IOSMAC
     33
     34#define UIItemProvider NSItemProvider
     35#define UIItemProviderReading NSItemProviderReading
     36#define UIItemProviderWriting NSItemProviderWriting
     37#define UIItemProviderRepresentationOptionsVisibilityAll NSItemProviderRepresentationVisibilityAll
     38
     39#endif
    2940
    3041@class UIItemProvider;
  • trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm

    r232512 r233436  
    2727#import "WebItemProviderPasteboard.h"
    2828
    29 #if ENABLE(DATA_INTERACTION)
     29#if ENABLE(DATA_INTERACTION) || ENABLE(MINIMAL_SIMULATOR)
    3030
    3131#import <Foundation/NSItemProvider.h>
     
    257257}
    258258
     259#if !ENABLE(MINIMAL_SIMULATOR)
    259260static UIPreferredPresentationStyle uiPreferredPresentationStyle(WebPreferredPresentationStyle style)
    260261{
     
    271272    }
    272273}
     274#endif
    273275
    274276- (UIItemProvider *)itemProvider
     
    280282    for (id <WebItemProviderRegistrar> representation in _representations.get())
    281283        [representation registerItemProvider:itemProvider.get()];
     284    [itemProvider setSuggestedName:self.suggestedName];
     285    // UIItemProviders are not implemented for iOS apps for Mac, because they were depricated last year.
     286    // We need to switch over to NSItemProviders everywhere. This should just be a temporary fix.
     287#if !ENABLE(MINIMAL_SIMULATOR)
    282288    [itemProvider setPreferredPresentationSize:self.preferredPresentationSize];
    283     [itemProvider setSuggestedName:self.suggestedName];
    284289    [itemProvider setPreferredPresentationStyle:uiPreferredPresentationStyle(self.preferredPresentationStyle)];
    285290    [itemProvider setTeamData:self.teamData];
     291#endif
    286292    return itemProvider.autorelease();
    287293}
     
    833839@end
    834840
    835 #endif // ENABLE(DATA_INTERACTION)
     841#endif // ENABLE(DATA_INTERACTION) || ENABLE(MINIMAL_SIMULATOR)
Note: See TracChangeset for help on using the changeset viewer.