Changeset 245804 in webkit
- Timestamp:
- May 27, 2019, 6:36:11 PM (7 years ago)
- Location:
- branches/safari-608.1.24.20-branch
- Files:
-
- 8 edited
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/WebPage.h (modified) (1 diff)
-
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (4 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm (modified) (15 diffs)
-
Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h (modified) (1 diff)
-
Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-608.1.24.20-branch/Source/WebKit/ChangeLog
r245782 r245804 1 2019-05-27 Babak Shafiei <bshafiei@apple.com> 2 3 Cherry-pick r245803. rdar://problem/51145977 4 5 [iOS] Dropping in an editable element should result in a ranged selection 6 https://bugs.webkit.org/show_bug.cgi?id=198267 7 <rdar://problem/51145977> 8 9 Reviewed by Tim Horton. 10 11 Source/WebKit: 12 13 When drag and drop was first implemented for iOS in iOS 11, selection behavior when dropping into editable 14 elements matched that of macOS, by leaving the inserted content selected after performing the drop. However, in 15 other parts of the platform (e.g. Notes), both the keyboard and selection views are not shown after a drop. 16 17 Instead of matching macOS behavior, WebKit on iOS should match the rest of the platform. This is a little 18 tricky, since we use the selection range after a drop to create a TextIndicator snapshot when creating a drag 19 preview. To resolve this, we refactor some of the logic introduced in r245778 to remember the DOM range to 20 snapshot before collapsing the range to the end of the inserted content. 21 22 Tested by adjusting some existing API tests. 23 24 * UIProcess/ios/WKContentViewInteraction.mm: 25 (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]): 26 27 Remove some logic that currently presents the keyboard while the user is performing a drop that focuses an 28 editable element. 29 30 * WebProcess/WebPage/WebPage.h: 31 32 Add a member variable to keep track of which range should be snapshotted when generating a drop preview. 33 34 * WebProcess/WebPage/ios/WebPageIOS.mm: 35 (WebKit::WebPage::didConcludeDrop): 36 (WebKit::WebPage::didConcludeEditDrag): 37 38 Collapse the selection range to the end after an edit drag (i.e., a drop in an editable area that inserted 39 content). 40 41 (WebKit::WebPage::computeAndSendEditDragSnapshot): 42 43 Tools: 44 45 Adjust some existing API tests that currently check for selection rects after a drop. Instead of checking for 46 visible selection rects, simply check for the start caret rect, as determined by WKContentView's 47 -selectionRange. 48 49 * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm: 50 (TestWebKitAPI::TEST): 51 (makeCGRectValue): Deleted. 52 (checkSelectionRectsWithLogging): Deleted. 53 * TestWebKitAPI/cocoa/DragAndDropSimulator.h: 54 55 Replace finalSelectionRects with finalSelectionStartRect. 56 57 * TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm: 58 (-[DragAndDropSimulator _resetSimulatedState]): 59 (-[DragAndDropSimulator runFrom:to:additionalItemRequestLocations:]): 60 (-[DragAndDropSimulator finalSelectionRects]): Deleted. 61 62 63 git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245803 268f45cc-cd09-0410-ab3c-d52691b4dbfc 64 65 2019-05-27 Wenson Hsieh <wenson_hsieh@apple.com> 66 67 [iOS] Dropping in an editable element should result in a ranged selection 68 https://bugs.webkit.org/show_bug.cgi?id=198267 69 <rdar://problem/51145977> 70 71 Reviewed by Tim Horton. 72 73 When drag and drop was first implemented for iOS in iOS 11, selection behavior when dropping into editable 74 elements matched that of macOS, by leaving the inserted content selected after performing the drop. However, in 75 other parts of the platform (e.g. Notes), both the keyboard and selection views are not shown after a drop. 76 77 Instead of matching macOS behavior, WebKit on iOS should match the rest of the platform. This is a little 78 tricky, since we use the selection range after a drop to create a TextIndicator snapshot when creating a drag 79 preview. To resolve this, we refactor some of the logic introduced in r245778 to remember the DOM range to 80 snapshot before collapsing the range to the end of the inserted content. 81 82 Tested by adjusting some existing API tests. 83 84 * UIProcess/ios/WKContentViewInteraction.mm: 85 (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]): 86 87 Remove some logic that currently presents the keyboard while the user is performing a drop that focuses an 88 editable element. 89 90 * WebProcess/WebPage/WebPage.h: 91 92 Add a member variable to keep track of which range should be snapshotted when generating a drop preview. 93 94 * WebProcess/WebPage/ios/WebPageIOS.mm: 95 (WebKit::WebPage::didConcludeDrop): 96 (WebKit::WebPage::didConcludeEditDrag): 97 98 Collapse the selection range to the end after an edit drag (i.e., a drop in an editable area that inserted 99 content). 100 101 (WebKit::WebPage::computeAndSendEditDragSnapshot): 102 1 103 2019-05-26 Babak Shafiei <bshafiei@apple.com> 2 104 -
branches/safari-608.1.24.20-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r245781 r245804 5052 5052 return YES; 5053 5053 5054 #if ENABLE(DRAG_SUPPORT)5055 if (_dragDropInteractionState.isPerformingDrop())5056 return YES;5057 #endif5058 5059 5054 if (self.isFirstResponder || _becomingFirstResponder) { 5060 5055 // When the software keyboard is being used to enter an url, only the focus activity state is changing. -
branches/safari-608.1.24.20-branch/Source/WebKit/WebProcess/WebPage/WebPage.h
r245781 r245804 1767 1767 #if ENABLE(DRAG_SUPPORT) && PLATFORM(IOS_FAMILY) 1768 1768 HashSet<RefPtr<WebCore::HTMLImageElement>> m_pendingImageElementsForDropSnapshot; 1769 RefPtr<WebCore::Range> m_rangeForDropSnapshot; 1769 1770 #endif 1770 1771 -
branches/safari-608.1.24.20-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r245781 r245804 825 825 void WebPage::didConcludeDrop() 826 826 { 827 m_rangeForDropSnapshot = nullptr; 827 828 m_pendingImageElementsForDropSnapshot.clear(); 828 829 } … … 837 838 838 839 bool waitingForAnyImageToLoad = false; 839 auto & frame = m_page->focusController().focusedOrMainFrame();840 if (auto range = frame.selection().selection().toNormalizedRange()) {841 for (TextIterator iterator( range.get()); !iterator.atEnd(); iterator.advance()) {840 auto frame = makeRef(m_page->focusController().focusedOrMainFrame()); 841 if (auto selectionRange = frame->selection().selection().toNormalizedRange()) { 842 for (TextIterator iterator(selectionRange.get()); !iterator.atEnd(); iterator.advance()) { 842 843 auto* node = iterator.node(); 843 844 if (!is<HTMLImageElement>(node)) … … 851 852 } 852 853 } 854 auto collapsedRange = Range::create(selectionRange->ownerDocument(), selectionRange->endPosition(), selectionRange->endPosition()); 855 frame->selection().setSelectedRange(collapsedRange.ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 856 857 m_rangeForDropSnapshot = WTFMove(selectionRange); 853 858 } 854 859 … … 872 877 Optional<TextIndicatorData> textIndicatorData; 873 878 static auto defaultTextIndicatorOptionsForEditDrag = TextIndicatorOptionIncludeSnapshotOfAllVisibleContentWithoutSelection | TextIndicatorOptionExpandClipBeyondVisibleRect | TextIndicatorOptionPaintAllContent | TextIndicatorOptionIncludeMarginIfRangeMatchesSelection | TextIndicatorOptionPaintBackgrounds | TextIndicatorOptionComputeEstimatedBackgroundColor| TextIndicatorOptionUseSelectionRectForSizing | TextIndicatorOptionIncludeSnapshotWithSelectionHighlight; 874 auto& frame = m_page->focusController().focusedOrMainFrame(); 875 if (auto range = frame.selection().selection().toNormalizedRange()) { 879 if (auto range = std::exchange(m_rangeForDropSnapshot, nullptr)) { 876 880 if (auto textIndicator = TextIndicator::createWithRange(*range, defaultTextIndicatorOptionsForEditDrag, TextIndicatorPresentationTransition::None, { })) 877 881 textIndicatorData = textIndicator->data(); -
branches/safari-608.1.24.20-branch/Tools/ChangeLog
r245782 r245804 1 2019-05-27 Babak Shafiei <bshafiei@apple.com> 2 3 Cherry-pick r245803. rdar://problem/51145977 4 5 [iOS] Dropping in an editable element should result in a ranged selection 6 https://bugs.webkit.org/show_bug.cgi?id=198267 7 <rdar://problem/51145977> 8 9 Reviewed by Tim Horton. 10 11 Source/WebKit: 12 13 When drag and drop was first implemented for iOS in iOS 11, selection behavior when dropping into editable 14 elements matched that of macOS, by leaving the inserted content selected after performing the drop. However, in 15 other parts of the platform (e.g. Notes), both the keyboard and selection views are not shown after a drop. 16 17 Instead of matching macOS behavior, WebKit on iOS should match the rest of the platform. This is a little 18 tricky, since we use the selection range after a drop to create a TextIndicator snapshot when creating a drag 19 preview. To resolve this, we refactor some of the logic introduced in r245778 to remember the DOM range to 20 snapshot before collapsing the range to the end of the inserted content. 21 22 Tested by adjusting some existing API tests. 23 24 * UIProcess/ios/WKContentViewInteraction.mm: 25 (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]): 26 27 Remove some logic that currently presents the keyboard while the user is performing a drop that focuses an 28 editable element. 29 30 * WebProcess/WebPage/WebPage.h: 31 32 Add a member variable to keep track of which range should be snapshotted when generating a drop preview. 33 34 * WebProcess/WebPage/ios/WebPageIOS.mm: 35 (WebKit::WebPage::didConcludeDrop): 36 (WebKit::WebPage::didConcludeEditDrag): 37 38 Collapse the selection range to the end after an edit drag (i.e., a drop in an editable area that inserted 39 content). 40 41 (WebKit::WebPage::computeAndSendEditDragSnapshot): 42 43 Tools: 44 45 Adjust some existing API tests that currently check for selection rects after a drop. Instead of checking for 46 visible selection rects, simply check for the start caret rect, as determined by WKContentView's 47 -selectionRange. 48 49 * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm: 50 (TestWebKitAPI::TEST): 51 (makeCGRectValue): Deleted. 52 (checkSelectionRectsWithLogging): Deleted. 53 * TestWebKitAPI/cocoa/DragAndDropSimulator.h: 54 55 Replace finalSelectionRects with finalSelectionStartRect. 56 57 * TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm: 58 (-[DragAndDropSimulator _resetSimulatedState]): 59 (-[DragAndDropSimulator runFrom:to:additionalItemRequestLocations:]): 60 (-[DragAndDropSimulator finalSelectionRects]): Deleted. 61 62 63 git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245803 268f45cc-cd09-0410-ab3c-d52691b4dbfc 64 65 2019-05-27 Wenson Hsieh <wenson_hsieh@apple.com> 66 67 [iOS] Dropping in an editable element should result in a ranged selection 68 https://bugs.webkit.org/show_bug.cgi?id=198267 69 <rdar://problem/51145977> 70 71 Reviewed by Tim Horton. 72 73 Adjust some existing API tests that currently check for selection rects after a drop. Instead of checking for 74 visible selection rects, simply check for the start caret rect, as determined by WKContentView's 75 -selectionRange. 76 77 * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm: 78 (TestWebKitAPI::TEST): 79 (makeCGRectValue): Deleted. 80 (checkSelectionRectsWithLogging): Deleted. 81 * TestWebKitAPI/cocoa/DragAndDropSimulator.h: 82 83 Replace finalSelectionRects with finalSelectionStartRect. 84 85 * TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm: 86 (-[DragAndDropSimulator _resetSimulatedState]): 87 (-[DragAndDropSimulator runFrom:to:additionalItemRequestLocations:]): 88 (-[DragAndDropSimulator finalSelectionRects]): Deleted. 89 1 90 2019-05-26 Babak Shafiei <bshafiei@apple.com> 2 91 -
branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm
r245781 r245804 118 118 } 119 119 120 static NSValue *makeCGRectValue(CGFloat x, CGFloat y, CGFloat width, CGFloat height)121 {122 return [NSValue valueWithCGRect:CGRectMake(x, y, width, height)];123 }124 125 120 static void checkCGRectIsEqualToCGRectWithLogging(CGRect expected, CGRect observed) 126 121 { … … 129 124 if (!isEqual) 130 125 NSLog(@"Expected: %@ but observed: %@", NSStringFromCGRect(expected), NSStringFromCGRect(observed)); 131 }132 133 static void checkSelectionRectsWithLogging(NSArray *expected, NSArray *observed)134 {135 if (![expected isEqualToArray:observed])136 NSLog(@"Expected selection rects: %@ but observed: %@", expected, observed);137 EXPECT_TRUE([expected isEqualToArray:observed]);138 126 } 139 127 … … 276 264 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 277 265 EXPECT_TRUE([observedEventNames containsObject:@"drop"]); 278 check SelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [simulator finalSelectionRects]);266 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(214, 201, 2, 174), [simulator finalSelectionStartRect]); 279 267 checkFirstTypeIsPresentAndSecondTypeIsMissing(simulator.get(), kUTTypePNG, kUTTypeFileURL); 280 268 checkEstimatedSize(simulator.get(), { 215, 174 }); … … 321 309 322 310 EXPECT_WK_STREQ("https://www.apple.com/", [webView editorValue].UTF8String); 323 check SelectionRectsWithLogging(@[ makeCGRectValue(101, 241, 2057, 232) ], [simulator finalSelectionRects]);311 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(2156, 241, 2, 232), [simulator finalSelectionStartRect]); 324 312 checkSuggestedNameAndEstimatedSize(simulator.get(), @"icon.png", { 215, 174 }); 325 313 checkTypeIdentifierIsRegisteredAtIndex(simulator.get(), (__bridge NSString *)kUTTypePNG, 0); … … 391 379 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 392 380 EXPECT_TRUE([observedEventNames containsObject:@"drop"]); 393 check SelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 961, 227) ], [simulator finalSelectionRects]);381 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(960, 201, 2, 227), [simulator finalSelectionStartRect]); 394 382 checkRichTextTypePrecedesPlainTextType(simulator.get()); 395 383 EXPECT_TRUE([simulator lastKnownDropProposal].precise); … … 415 403 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 416 404 EXPECT_TRUE([observedEventNames containsObject:@"drop"]); 417 check SelectionRectsWithLogging(@[ makeCGRectValue(101, 203, 990, 232) ], [simulator finalSelectionRects]);405 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(1089, 203, 2, 232), [simulator finalSelectionStartRect]); 418 406 checkRichTextTypePrecedesPlainTextType(simulator.get()); 419 407 EXPECT_TRUE([simulator lastKnownDropProposal].precise); … … 472 460 EXPECT_FALSE(secondParagraphOffset == NSNotFound); 473 461 EXPECT_GT(firstParagraphOffset, secondParagraphOffset); 474 check SelectionRectsWithLogging(@[ makeCGRectValue(190, 100, 130, 20), makeCGRectValue(0, 120, 320, 100), makeCGRectValue(0, 220, 252, 20) ], [simulator finalSelectionRects]);462 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(251, 220, 2, 20), [simulator finalSelectionStartRect]); 475 463 EXPECT_TRUE([simulator lastKnownDropProposal].precise); 476 464 } … … 498 486 EXPECT_EQ([webView stringByEvaluatingJavaScript:@"source.value"].length, 0UL); 499 487 EXPECT_WK_STREQ("Hello world", [webView editorValue].UTF8String); 500 check SelectionRectsWithLogging(@[ makeCGRectValue(101, 241, 990, 232) ], [simulator finalSelectionRects]);488 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(1089, 241, 2, 232), [simulator finalSelectionStartRect]); 501 489 } 502 490 … … 569 557 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 570 558 EXPECT_TRUE([observedEventNames containsObject:@"drop"]); 571 check SelectionRectsWithLogging(@[ makeCGRectValue(101, 273, 2057, 232) ], [simulator finalSelectionRects]);559 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(2156, 273, 2, 232), [simulator finalSelectionStartRect]); 572 560 checkTypeIdentifierIsRegisteredAtIndex(simulator.get(), (__bridge NSString *)kUTTypeURL, 0); 573 561 } … … 587 575 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 588 576 EXPECT_TRUE([observedEventNames containsObject:@"drop"]); 589 check SelectionRectsWithLogging(@[ makeCGRectValue(101, 241, 2057, 232) ], [simulator finalSelectionRects]);577 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(2156, 241, 2, 232), [simulator finalSelectionStartRect]); 590 578 checkTypeIdentifierIsRegisteredAtIndex(simulator.get(), (__bridge NSString *)kUTTypeURL, 0); 591 579 } … … 605 593 EXPECT_FALSE([observedEventNames containsObject:@"dragenter"]); 606 594 EXPECT_FALSE([observedEventNames containsObject:@"dragover"]); 607 check SelectionRectsWithLogging(@[ ], [simulator finalSelectionRects]);595 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(0, 0, 0, 0), [simulator finalSelectionStartRect]); 608 596 } 609 597 … … 621 609 EXPECT_TRUE([observedEventNames containsObject:@"dragenter"]); 622 610 EXPECT_TRUE([observedEventNames containsObject:@"dragover"]); 623 check SelectionRectsWithLogging(@[ ], [simulator finalSelectionRects]);611 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(0, 0, 0, 0), [simulator finalSelectionStartRect]); 624 612 } 625 613 … … 639 627 EXPECT_TRUE([observedEventNames containsObject:@"dragleave"]); 640 628 EXPECT_FALSE([observedEventNames containsObject:@"drop"]); 641 check SelectionRectsWithLogging(@[ ], [simulator finalSelectionRects]);629 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(0, 0, 0, 0), [simulator finalSelectionStartRect]); 642 630 } 643 631 … … 1026 1014 [simulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)]; 1027 1015 EXPECT_WK_STREQ(textPayload.UTF8String, [webView stringByEvaluatingJavaScript:@"editor.textContent"].UTF8String); 1028 check SelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 1936, 227) ], [simulator finalSelectionRects]);1016 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(1935, 201, 2, 227), [simulator finalSelectionStartRect]); 1029 1017 } 1030 1018 … … 1046 1034 [simulator runFrom:CGPointMake(300, 400) to:CGPointMake(100, 300)]; 1047 1035 EXPECT_TRUE([webView editorContainsImageElement]); 1048 check SelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [simulator finalSelectionRects]);1036 checkCGRectIsEqualToCGRectWithLogging(CGRectMake(214, 201, 2, 223), [simulator finalSelectionStartRect]); 1049 1037 } 1050 1038 -
branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/cocoa/DragAndDropSimulator.h
r245781 r245804 109 109 @property (nonatomic, readonly) NSArray *sourceItemProviders; 110 110 @property (nonatomic, readonly) NSArray *observedEventNames; 111 @property (nonatomic, readonly) NSArray *finalSelectionRects;111 @property (nonatomic, readonly) CGRect finalSelectionStartRect; 112 112 @property (nonatomic, readonly) CGRect lastKnownDragCaretRect; 113 113 @property (nonatomic, readonly) NSArray<UITargetedDragPreview *> *liftPreviews; -
branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/ios/DragAndDropSimulatorIOS.mm
r245781 r245804 304 304 RetainPtr<NSArray> _externalItemProviders; 305 305 RetainPtr<NSArray> _sourceItemProviders; 306 RetainPtr<NSArray> _finalSelectionRects;306 CGRect _finalSelectionStartRect; 307 307 CGPoint _startLocation; 308 308 CGPoint _endLocation; … … 382 382 _insertedAttachments = adoptNS([[NSMutableArray alloc] init]); 383 383 _removedAttachments = adoptNS([[NSMutableArray alloc] init]); 384 _finalSelection Rects = @[ ];384 _finalSelectionStartRect = CGRectNull; 385 385 _dragSession = nil; 386 386 _dropSession = nil; … … 464 464 Util::run(&_isDoneWaitingForDelayedDropPreviews); 465 465 [_webView clearMessageHandlers:dragAndDropEventNames()]; 466 _finalSelectionRects = [_webView selectionRectsAfterPresentationUpdate]; 466 [_webView waitForNextPresentationUpdate]; 467 468 auto contentView = [_webView textInputContentView]; 469 _finalSelectionStartRect = [contentView caretRectForPosition:contentView.selectedTextRange.start]; 467 470 468 471 [defaultCenter removeObserver:self]; 469 }470 471 - (NSArray *)finalSelectionRects472 {473 return _finalSelectionRects.get();474 472 } 475 473
Note:
See TracChangeset
for help on using the changeset viewer.