Diff
Modified: trunk/Source/WebKit2/ChangeLog (212973 => 212974)
--- trunk/Source/WebKit2/ChangeLog 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/ChangeLog 2017-02-25 00:05:45 UTC (rev 212974)
@@ -1,5 +1,36 @@
2017-02-20 Wenson Hsieh <wenson_hs...@apple.com>
+ Refactor data interaction to use new WKDataInteraction SPI
+ https://bugs.webkit.org/show_bug.cgi?id=168602
+ Work towards <rdar://problem/30313681>
+
+ Reviewed by Tim Horton.
+
+ Adjust testing SPI to match new data interaction interfaces.
+
+ * Platform/spi/ios/UIKitSPI.h:
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView _simulateDataInteractionEntered:]):
+ (-[WKWebView _simulateDataInteractionUpdated:]):
+ (-[WKWebView _simulateDataInteractionPerformOperation:]):
+ (-[WKWebView _simulateDataInteractionEnded:]):
+ (-[WKWebView _simulateDataInteractionSessionDidEnd:]):
+ (-[WKWebView _simulateWillBeginDataInteractionWithSession:]):
+ (-[WKWebView _simulatedItemsForSession:]):
+ (-[WKWebView _simulatePrepareForDataInteractionSession:completion:]):
+ (-[WKWebView _simulateDataInteractionSessionDidEnd:withOperation:]): Deleted.
+ (-[WKWebView _simulateFailedDataInteractionWithIndex:]): Deleted.
+ (-[WKWebView _simulateWillBeginDataInteractionWithIndex:withSession:]): Deleted.
+ (-[WKWebView _simulatedItemsForDataInteractionWithIndex:]): Deleted.
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/ios/WKContentViewInteraction.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView _positionInformationDidChange:]):
+ * UIProcess/ios/WKScrollView.h:
+ * UIProcess/ios/WKScrollView.mm:
+
+2017-02-20 Wenson Hsieh <wenson_hs...@apple.com>
+
Remove the data interaction gesture recognizer
https://bugs.webkit.org/show_bug.cgi?id=168600
<rdar://problem/30313681>
Modified: trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h (212973 => 212974)
--- trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h 2017-02-25 00:05:45 UTC (rev 212974)
@@ -54,6 +54,7 @@
#import <UIKit/UIStringDrawing_Private.h>
#import <UIKit/UITableViewCell_Private.h>
#import <UIKit/UITapGestureRecognizer_Private.h>
+#import <UIKit/UITextEffectsWindow.h>
#import <UIKit/UITextInput_Private.h>
#import <UIKit/UITextInteractionAssistant_Private.h>
#import <UIKit/UIViewControllerTransitioning_Private.h>
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (212973 => 212974)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-02-25 00:05:45 UTC (rev 212974)
@@ -5235,35 +5235,60 @@
- (void)_simulateDataInteractionEntered:(id)info
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionEntered:info];
+#endif
}
- (void)_simulateDataInteractionUpdated:(id)info
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionUpdated:info];
+#endif
}
- (void)_simulateDataInteractionPerformOperation:(id)info
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionPerformOperation:info];
+#endif
}
- (void)_simulateDataInteractionEnded:(id)info
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionEnded:info];
+#endif
}
-- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation
+- (void)_simulateDataInteractionSessionDidEnd:(id)session
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateDataInteractionSessionDidEnd:session];
+#endif
}
-- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex
+- (void)_simulateWillBeginDataInteractionWithSession:(id)session
{
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulateWillBeginDataInteractionWithSession:session];
+#endif
}
-- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session
+- (NSArray *)_simulatedItemsForSession:(id)session
{
+#if ENABLE(DATA_INTERACTION)
+ return [_contentView _simulatedItemsForSession:session];
+#else
+ return @[ ];
+#endif
}
-- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex
+- (void)_simulatePrepareForDataInteractionSession:(id)session completion:(dispatch_block_t)completion
{
- return @[ ];
+#if ENABLE(DATA_INTERACTION)
+ [_contentView _simulatePrepareForDataInteractionSession:session completion:completion];
+#endif
}
@end
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (212973 => 212974)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-02-25 00:05:45 UTC (rev 212974)
@@ -310,10 +310,10 @@
- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionSessionDidEnd:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateWillBeginDataInteractionWithSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (NSArray *)_simulatedItemsForSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulatePrepareForDataInteractionSession:(id)session completion:(dispatch_block_t)completion WK_API_AVAILABLE(ios(WK_IOS_TBA));
#endif // TARGET_OS_IPHONE
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (212973 => 212974)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h 2017-02-25 00:05:45 UTC (rev 212974)
@@ -188,6 +188,8 @@
#if ENABLE(DATA_INTERACTION)
WebKit::WKDataInteractionState _dataInteractionState;
BOOL _isPerformingDataInteractionOperation;
+ RetainPtr<WKDataInteraction> _dataInteraction;
+ CGPoint _deferredActionSheetRequestLocation;
#endif
}
@@ -195,7 +197,7 @@
@interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate, WKActionSheetAssistantDelegate
#if ENABLE(DATA_INTERACTION)
- , WKViewDataInteractionSourceDelegate, WKDataInteractionSessionDelegate, WKViewDataInteractionDestinationDelegate, WKDataInteractionItemVisualTarget
+ , WKDataInteractionItemVisualTarget, WKDataInteractionDelegate, WKViewDataInteractionDestinationDelegate
#endif
>
@@ -269,14 +271,14 @@
- (void)_didPerformDataInteractionControllerOperation;
- (void)_didHandleStartDataInteractionRequest:(BOOL)started;
- (void)_startDataInteractionWithImage:(RetainPtr<CGImageRef>)image withIndicatorData:(std::optional<WebCore::TextIndicatorData>)indicatorData atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action;
-- (void)_simulateDataInteractionEntered:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateDataInteractionUpdated:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateDataInteractionPerformOperation:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateDataInteractionEnded:(id)info WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateDataInteractionSessionDidEnd:(id)session withOperation:(NSUInteger)operation WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateFailedDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (void)_simulateWillBeginDataInteractionWithIndex:(NSInteger)sourceIndex withSession:(id)session WK_API_AVAILABLE(ios(WK_IOS_TBA));
-- (NSArray *)_simulatedItemsForDataInteractionWithIndex:(NSInteger)sourceIndex WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (void)_simulateDataInteractionEntered:(id)info;
+- (void)_simulateDataInteractionUpdated:(id)info;
+- (void)_simulateDataInteractionPerformOperation:(id)info;
+- (void)_simulateDataInteractionEnded:(id)info;
+- (void)_simulateDataInteractionSessionDidEnd:(id)session;
+- (void)_simulateWillBeginDataInteractionWithSession:(id)session;
+- (NSArray *)_simulatedItemsForSession:(id)session;
+- (void)_simulatePrepareForDataInteractionSession:(id)session completion:(dispatch_block_t)completion;
#endif
@end
Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (212973 => 212974)
--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm 2017-02-25 00:05:45 UTC (rev 212974)
@@ -1720,10 +1720,6 @@
_hasValidPositionInformation = YES;
if (_actionSheetAssistant)
[_actionSheetAssistant updateSheetPosition];
-
-#if ENABLE(DATA_INTERACTION)
- [self _updateDataInteractionPreviewSnapshotIfPossible];
-#endif
}
- (void)_willStartScrollingOrZooming
Modified: trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm (212973 => 212974)
--- trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Source/WebKit2/UIProcess/ios/WKScrollView.mm 2017-02-25 00:05:45 UTC (rev 212974)
@@ -129,6 +129,10 @@
return self;
}
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKScrollViewAdditions.mm>)
+#import <WebKitAdditions/WKScrollViewAdditions.mm>
+#endif
+
- (void)setInternalDelegate:(WKWebView <UIScrollViewDelegate> *)internalDelegate
{
if (internalDelegate == _internalDelegate)
Modified: trunk/Tools/ChangeLog (212973 => 212974)
--- trunk/Tools/ChangeLog 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Tools/ChangeLog 2017-02-25 00:05:45 UTC (rev 212974)
@@ -1,5 +1,27 @@
2017-02-20 Wenson Hsieh <wenson_hs...@apple.com>
+ Refactor data interaction to use new WKDataInteraction SPI
+ https://bugs.webkit.org/show_bug.cgi?id=168602
+ Work towards <rdar://problem/30313681>
+
+ Reviewed by Tim Horton.
+
+ Update DataInteractionSimulator to simulate data interaction using updated SPI. See changes in WebKit2 for more details.
+
+ * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/ios/DataInteractionSimulator.h:
+ * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+ (-[DataInteractionSimulator _resetSimulatedState]):
+ (-[DataInteractionSimulator runFrom:to:]):
+ (-[DataInteractionSimulator _advanceProgress]):
+ (-[DataInteractionSimulator _currentLocation]):
+ (-[DataInteractionSimulator _finishDataInteraction]): Deleted.
+ (-[DataInteractionSimulator webViewDidSendDataInteractionStartRequest:]): Deleted.
+ (-[DataInteractionSimulator webView:didReceiveDataInteractionStartResponse:]): Deleted.
+
+2017-02-20 Wenson Hsieh <wenson_hs...@apple.com>
+
Remove the data interaction gesture recognizer
https://bugs.webkit.org/show_bug.cgi?id=168600
<rdar://problem/30313681>
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm (212973 => 212974)
--- trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm 2017-02-25 00:05:45 UTC (rev 212974)
@@ -25,7 +25,7 @@
#include "config.h"
-#if 0
+#if ENABLE(DATA_INTERACTION)
#import "DataInteractionSimulator.h"
#import "PlatformUtilities.h"
@@ -81,7 +81,6 @@
NSURL *imageURL = [NSURL fileURLWithPath:[webView editorValue]];
EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -102,7 +101,6 @@
EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -121,7 +119,6 @@
EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.textContent"].length, 0UL);
EXPECT_WK_STREQ("Hello world", [webView editorValue].UTF8String);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -139,7 +136,6 @@
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -157,7 +153,6 @@
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -175,7 +170,6 @@
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
EXPECT_FALSE([webView editorContainsImageElement]);
- EXPECT_FALSE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_FALSE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -192,7 +186,6 @@
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
EXPECT_FALSE([webView editorContainsImageElement]);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -209,7 +202,6 @@
[dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 450)];
EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
- EXPECT_TRUE([dataInteractionSimulator didTryToBeginDataInteraction]);
NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
@@ -219,22 +211,6 @@
EXPECT_TRUE([[dataInteractionSimulator finalSelectionRects] isEqualToArray:@[ ]]);
}
-TEST(DataInteractionTests, HandlesDataInteractionFailureGracefully)
-{
- RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
- [webView synchronouslyLoadTestPageNamed:@"link-and-input"];
-
- RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
- [dataInteractionSimulator setForceRequestToFail:YES];
- [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
- EXPECT_WK_STREQ("", [webView editorValue].UTF8String);
-
- // Before r212266, starting a subsequent gesture would have caused a debug assertion in the web process.
- [dataInteractionSimulator setForceRequestToFail:NO];
- [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
- EXPECT_WK_STREQ("https://www.daringfireball.net/", [webView editorValue].UTF8String);
-}
-
TEST(DataInteractionTests, ExternalSourceUTF8PlainTextOnly)
{
RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h (212973 => 212974)
--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.h 2017-02-25 00:05:45 UTC (rev 212974)
@@ -32,6 +32,7 @@
#import <wtf/BlockPtr.h>
@class MockDataInteractionInfo;
+@class MockDataInteractionSession;
extern NSString * const DataInteractionEnterEventName;
extern NSString * const DataInteractionOverEventName;
@@ -40,7 +41,8 @@
extern NSString * const DataInteractionStartEventName;
typedef NS_ENUM(NSInteger, DataInteractionPhase) {
- DataInteractionUnrecognized = 1,
+ DataInteractionCancelled = 0,
+ DataInteractionBeginning = 1,
DataInteractionBegan = 2,
DataInteractionEntered = 3,
DataInteractionPerforming = 4
@@ -48,6 +50,7 @@
@interface DataInteractionSimulator : NSObject<_WKTestingDelegate> {
RetainPtr<TestWKWebView> _webView;
+ RetainPtr<MockDataInteractionSession> _dataInteractionSession;
RetainPtr<MockDataInteractionInfo> _dataInteractionInfo;
RetainPtr<NSMutableArray> _observedEventNames;
RetainPtr<UIItemProvider> _externalItemProvider;
@@ -55,7 +58,7 @@
CGPoint _startLocation;
CGPoint _endLocation;
- double _gestureProgress;
+ double _currentProgress;
bool _isDoneWithCurrentRun;
DataInteractionPhase _phase;
}
@@ -63,9 +66,7 @@
- (instancetype)initWithWebView:(TestWKWebView *)webView;
- (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation;
-@property (nonatomic) BOOL forceRequestToFail;
@property (nonatomic, strong) UIItemProvider *externalItemProvider;
-@property (nonatomic, readonly) BOOL didTryToBeginDataInteraction;
@property (nonatomic, readonly) NSArray *observedEventNames;
@property (nonatomic, readonly) NSArray *finalSelectionRects;
Modified: trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm (212973 => 212974)
--- trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm 2017-02-25 00:05:39 UTC (rev 212973)
+++ trunk/Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm 2017-02-25 00:05:45 UTC (rev 212974)
@@ -73,12 +73,13 @@
- (void)_resetSimulatedState
{
- _gestureProgress = 0;
- _phase = DataInteractionUnrecognized;
+ _phase = DataInteractionBeginning;
+ _currentProgress = 0;
_isDoneWithCurrentRun = false;
- _didTryToBeginDataInteraction = NO;
_observedEventNames = adoptNS([[NSMutableArray alloc] init]);
_finalSelectionRects = @[ ];
+ _dataInteractionSession = nil;
+ _dataInteractionInfo = nil;
}
- (NSArray *)observedEventNames
@@ -102,12 +103,19 @@
_endLocation = endLocation;
if (self.externalItemProvider) {
+ _dataInteractionInfo = adoptNS([[MockDataInteractionInfo alloc] initWithProvider:self.externalItemProvider location:_startLocation window:[_webView window]]);
_phase = DataInteractionBegan;
- _dataInteractionInfo = adoptNS([[MockDataInteractionInfo alloc] initWithProvider:self.externalItemProvider location:startLocation window:[_webView window]]);
+ [self _advanceProgress];
+ } else {
+ _dataInteractionSession = adoptNS([[MockDataInteractionSession alloc] initWithWindow:[_webView window]]);
+ [_dataInteractionSession setMockLocationInWindow:_startLocation];
+ [_webView _simulatePrepareForDataInteractionSession:_dataInteractionSession.get() completion:^() {
+ DataInteractionSimulator *weakSelf = strongSelf.get();
+ weakSelf->_phase = DataInteractionBeginning;
+ [weakSelf _advanceProgress];
+ }];
}
- [self _scheduleAdvanceProgress];
-
Util::run(&_isDoneWithCurrentRun);
[_webView clearMessageHandlers:dataInteractionEventNames()];
_finalSelectionRects = [_webView selectionRectsAfterPresentationUpdate];
@@ -120,42 +128,54 @@
- (void)_advanceProgress
{
- _gestureProgress = std::min(1.0, std::max(0.0, progressIncrementStep + _gestureProgress));
- [_dataInteractionInfo setMockLocationInWindow:self._currentLocation];
- if (_gestureProgress >= 1) {
- [self _finishDataInteraction];
+ _currentProgress += progressIncrementStep;
+ CGPoint locationInWindow = self._currentLocation;
+ [_dataInteractionSession setMockLocationInWindow:locationInWindow];
+ [_dataInteractionInfo setMockLocationInWindow:locationInWindow];
+
+ if (_currentProgress >= 1) {
+ [_webView _simulateDataInteractionPerformOperation:_dataInteractionInfo.get()];
+ [_webView _simulateDataInteractionEnded:_dataInteractionInfo.get()];
+ if (_dataInteractionSession)
+ [_webView _simulateDataInteractionSessionDidEnd:_dataInteractionSession.get()];
+
+ _phase = DataInteractionPerforming;
+ _currentProgress = 1;
return;
}
switch (_phase) {
- case DataInteractionUnrecognized:
- [self _scheduleAdvanceProgress];
+ case DataInteractionBeginning: {
+ NSMutableArray<UIItemProvider *> *itemProviders = [NSMutableArray array];
+ NSArray<WKDataInteractionItem *> *items = [_webView _simulatedItemsForSession:_dataInteractionSession.get()];
+ if (!items.count) {
+ _phase = DataInteractionCancelled;
+ _currentProgress = 1;
+ _isDoneWithCurrentRun = true;
+ return;
+ }
+
+ for (WKDataInteractionItem *item in items)
+ [itemProviders addObject:item.itemProvider];
+
+ _dataInteractionInfo = adoptNS([[MockDataInteractionInfo alloc] initWithProvider:itemProviders.firstObject location:self._currentLocation window:[_webView window]]);
+ [_dataInteractionSession setItems:items];
+ [_webView _simulateWillBeginDataInteractionWithSession:_dataInteractionSession.get()];
+ _phase = DataInteractionBegan;
break;
+ }
case DataInteractionBegan:
[_webView _simulateDataInteractionEntered:_dataInteractionInfo.get()];
_phase = DataInteractionEntered;
- [self _scheduleAdvanceProgress];
break;
case DataInteractionEntered:
[_webView _simulateDataInteractionUpdated:_dataInteractionInfo.get()];
- [self _scheduleAdvanceProgress];
break;
default:
break;
}
-}
-- (void)_finishDataInteraction
-{
- if (_phase == DataInteractionUnrecognized) {
- _isDoneWithCurrentRun = true;
- return;
- }
-
- _phase = DataInteractionPerforming;
- [_webView _simulateDataInteractionPerformOperation:_dataInteractionInfo.get()];
- [_webView _simulateDataInteractionEnded:_dataInteractionInfo.get()];
- [_webView _simulateDataInteractionSessionDidEnd:nil withOperation:0];
+ [self _scheduleAdvanceProgress];
}
- (CGPoint)_currentLocation
@@ -162,7 +182,7 @@
{
CGFloat distanceX = _endLocation.x - _startLocation.x;
CGFloat distanceY = _endLocation.y - _startLocation.y;
- return CGPointMake(_startLocation.x + _gestureProgress * distanceX, _startLocation.y + _gestureProgress * distanceY);
+ return CGPointMake(_startLocation.x + _currentProgress * distanceX, _startLocation.y + _currentProgress * distanceY);
}
- (void)_scheduleAdvanceProgress
@@ -188,20 +208,6 @@
_isDoneWithCurrentRun = true;
}
-- (void)webViewDidSendDataInteractionStartRequest:(WKWebView *)webView
-{
- // This addresses a race condition in the testing harness wherein the web process might take longer than usual to process the
- // request to start data interaction, and in the meantime, DataInteractionSimulator would end up completing the rest of the test
- // before a response from the web process is received. We instead defer test progress until after the web process has indicated
- // whether or not data interaction should commence.
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_advanceProgress) object:nil];
-}
-
-- (void)webView:(WKWebView *)webView didReceiveDataInteractionStartResponse:(BOOL)started
-{
- [self _scheduleAdvanceProgress];
-}
-
@end
#endif // ENABLE(DATA_INTERACTION)