Changeset 256520 in webkit
- Timestamp:
- Feb 13, 2020 10:10:41 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r256512 r256520 1 2020-02-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] -updateSelectionWithExtentPoint:completionHandler: should work without requiring floating cursor 4 https://bugs.webkit.org/show_bug.cgi?id=207680 5 <rdar://problem/59340940> 6 7 Reviewed by Tim Horton. 8 9 Currently, WebPage::updateSelectionWithExtentPoint consults the value of m_selectionAnchor to determine whether 10 it should attempt to modify the current selection using the hit-tested visible position. m_selectionAnchor is 11 only set under WebPage::beginSelectionInDirection, which is only invoked when the user begins a floating cursor 12 gesture. When attempting to perform an out-of-band selection update (i.e. without calling 13 beginSelectionInDirection beforehand), we will end up consulting an arbitrary value for m_selectionAnchor 14 (::Start by default; otherwise, the last value set by beginSelectionInDirection if it was previously called). 15 This means that the selection can often only be extended in one direction (typically forwards) when an API 16 client attempts to use -updateSelectionWithExtentPoint:completionHandler: to extend the current selection. 17 18 To fix this, make it so that we only respect the selection anchor (m_selectionAnchor) in the case where the user 19 is currently using the floating cursor; otherwise, allow the SPI to expand the selection, such that it contains 20 the visible position for the given location. 21 22 Test: UIWKInteractionViewProtocol.UpdateSelectionWithExtentPoint 23 24 * Platform/spi/ios/UIKitSPI.h: 25 * Scripts/webkit/messages.py: 26 * Shared/ios/GestureTypes.h: 27 28 Add a new flag to tell the web process whether it should limit selection extent updates to the current selection 29 anchor. Also, remove an existing enum type, SelectionHandlePosition, that is unused (since we no longer support 30 block text selection). 31 32 * UIProcess/WebPageProxy.h: 33 * UIProcess/ios/WKContentViewInteraction.mm: 34 (-[UITextInteractionAssistant _wk_hasFloatingCursor]): 35 36 Add a helper method to determine (using the text interaction assistant) whether there's an active floating 37 cursor gesture. In the case where floating cursor is active, the text interaction assistant will be in an active 38 gesture but its UITextInteraction will not, since the gesture recognizer belongs to the keyboard or input view 39 rather than the first responder (in this case, WKContentView). 40 41 (-[WKContentView updateSelectionWithExtentPoint:completionHandler:]): 42 43 Only respect the selection anchor if we're in floating cursor mode; otherwise, allow selection updates with an 44 extent point to extend the current selection to include the new position. 45 46 * UIProcess/ios/WebPageProxyIOS.mm: 47 (WebKit::WebPageProxy::updateSelectionWithExtentPoint): 48 * WebProcess/WebPage/WebPage.h: 49 * WebProcess/WebPage/WebPage.messages.in: 50 51 Plumb the RespectsSelectionAnchor flag over to the web process. 52 53 * WebProcess/WebPage/ios/WebPageIOS.mm: 54 (WebKit::WebPage::updateSelectionWithExtentPoint): 55 1 56 2020-02-13 Said Abou-Hallawa <said@apple.com> 2 57 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r255907 r256520 454 454 - (void)setGestureRecognizers; 455 455 - (void)willStartScrollingOverflow; 456 - (void)willStartScrollingOrZooming; 457 - (void)didEndScrollingOrZooming; 456 458 @end 457 459 … … 1111 1113 #define UIWKDocumentRequestMarkedTextRects (1 << 5) 1112 1114 1113 @interface UITextInteractionAssistant (Staging_55645619) 1114 - (void)didEndScrollingOrZooming; 1115 - (void)willStartScrollingOrZooming; 1115 @interface UITextInteractionAssistant (IPI) 1116 @property (nonatomic, readonly) BOOL inGesture; 1117 @property (nonatomic, readonly) UITextInteraction *interactions; 1118 @end 1119 1120 @interface UITextInteraction (IPI) 1121 @property (nonatomic, readonly) BOOL inGesture; 1116 1122 @end 1117 1123 -
trunk/Source/WebKit/Scripts/webkit/messages.py
r256353 r256520 615 615 'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'], 616 616 'WebKit::PageState': ['"SessionState.h"'], 617 'WebKit::RespectSelectionAnchor': ['"GestureTypes.h"'], 617 618 'WebKit::WebGestureEvent': ['"WebEvent.h"'], 618 619 'WebKit::WebKeyboardEvent': ['"WebEvent.h"'], -
trunk/Source/WebKit/Shared/ios/GestureTypes.h
r246116 r256520 76 76 }; 77 77 78 enum class SelectionHandlePosition { 79 Top, 80 Right, 81 Bottom, 82 Left 78 enum class RespectSelectionAnchor : bool { 79 No, 80 Yes 83 81 }; 84 82 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r256236 r256520 119 119 120 120 #if PLATFORM(IOS_FAMILY) 121 #include "GestureTypes.h" 121 122 #include "WebAutocorrectionContext.h" 122 123 #endif … … 741 742 void moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity, WebCore::SelectionDirection, WTF::Function<void(CallbackBase::Error)>&&); 742 743 void beginSelectionInDirection(WebCore::SelectionDirection, WTF::Function<void (uint64_t, CallbackBase::Error)>&&); 743 void updateSelectionWithExtentPoint(const WebCore::IntPoint, bool isInteractingWithFocusedElement, WTF::Function<void(uint64_t, CallbackBase::Error)>&&);744 void updateSelectionWithExtentPoint(const WebCore::IntPoint, bool isInteractingWithFocusedElement, RespectSelectionAnchor, WTF::Function<void(uint64_t, CallbackBase::Error)>&&); 744 745 void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint, WebCore::TextGranularity, bool isInteractingWithFocusedElement, WTF::Function<void(uint64_t, CallbackBase::Error)>&&); 745 746 void requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&&); -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r256485 r256520 314 314 @end 315 315 316 @interface UITextInteractionAssistant (WebKit) 317 @property (nonatomic, readonly) BOOL _wk_hasFloatingCursor; 318 @end 319 316 320 @interface UIView (UIViewInternalHack) 317 321 + (BOOL)_addCompletion:(void(^)(BOOL))completion; … … 322 326 @interface WKFocusedElementInfo : NSObject <_WKFocusedElementInfo> 323 327 - (instancetype)initWithFocusedElementInformation:(const WebKit::FocusedElementInformation&)information isUserInitiated:(BOOL)isUserInitiated userObject:(NSObject <NSSecureCoding> *)userObject; 328 @end 329 330 @implementation UITextInteractionAssistant (WebKit) 331 332 - (BOOL)_wk_hasFloatingCursor 333 { 334 return self.inGesture && !self.interactions.inGesture; 335 } 336 324 337 @end 325 338 … … 4071 4084 UIWKSelectionWithDirectionCompletionHandler selectionHandler = [completionHandler copy]; 4072 4085 4073 _page->updateSelectionWithExtentPoint(WebCore::IntPoint(point), [self _isInteractingWithFocusedElement], [selectionHandler](bool endIsMoving, WebKit::CallbackBase::Error error) { 4086 auto respectSelectionAnchor = self.interactionAssistant._wk_hasFloatingCursor ? WebKit::RespectSelectionAnchor::Yes : WebKit::RespectSelectionAnchor::No; 4087 _page->updateSelectionWithExtentPoint(WebCore::IntPoint(point), self._isInteractingWithFocusedElement, respectSelectionAnchor, [selectionHandler](bool endIsMoving, WebKit::CallbackBase::Error error) { 4074 4088 selectionHandler(endIsMoving); 4075 4089 [selectionHandler release]; -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r256234 r256520 543 543 } 544 544 545 void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point, bool isInteractingWithFocusedElement, WTF::Function<void(uint64_t, CallbackBase::Error)>&& callbackFunction)545 void WebPageProxy::updateSelectionWithExtentPoint(const WebCore::IntPoint point, bool isInteractingWithFocusedElement, RespectSelectionAnchor respectSelectionAnchor, WTF::Function<void(uint64_t, CallbackBase::Error)>&& callbackFunction) 546 546 { 547 547 if (!hasRunningProcess()) { … … 551 551 552 552 auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::updateSelectionWithExtentPoint"_s)); 553 m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithFocusedElement, callbackID), m_webPageID);553 m_process->send(Messages::WebPage::UpdateSelectionWithExtentPoint(point, isInteractingWithFocusedElement, respectSelectionAnchor, callbackID), m_webPageID); 554 554 555 555 } -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r256236 r256520 675 675 void selectPositionAtPoint(const WebCore::IntPoint&, bool isInteractingWithFocusedElement, CallbackID); 676 676 void beginSelectionInDirection(uint32_t direction, CallbackID); 677 void updateSelectionWithExtentPoint(const WebCore::IntPoint&, bool isInteractingWithFocusedElement, CallbackID);677 void updateSelectionWithExtentPoint(const WebCore::IntPoint&, bool isInteractingWithFocusedElement, RespectSelectionAnchor, CallbackID); 678 678 void updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithFocusedElement, CallbackID); 679 679 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r256236 r256520 75 75 SelectPositionAtPoint(WebCore::IntPoint point, bool isInteractingWithFocusedElement, WebKit::CallbackID callbackID) 76 76 BeginSelectionInDirection(uint32_t direction, WebKit::CallbackID callbackID) 77 UpdateSelectionWithExtentPoint(WebCore::IntPoint point, bool isInteractingWithFocusedElement, WebKit::CallbackID callbackID)77 UpdateSelectionWithExtentPoint(WebCore::IntPoint point, bool isInteractingWithFocusedElement, enum:bool WebKit::RespectSelectionAnchor respectSelectionAnchor, WebKit::CallbackID callbackID) 78 78 UpdateSelectionWithExtentPointAndBoundary(WebCore::IntPoint point, uint32_t granularity, bool isInteractingWithFocusedElement, WebKit::CallbackID callbackID) 79 79 RequestDictationContext(WebKit::CallbackID callbackID) -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r256401 r256520 35 35 #import "EditingRange.h" 36 36 #import "EditorState.h" 37 #import "GestureTypes.h"38 37 #import "InteractionInformationAtPosition.h" 39 38 #import "Logging.h" … … 2136 2135 } 2137 2136 2138 void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, bool isInteractingWithFocusedElement, CallbackID callbackID)2137 void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, bool isInteractingWithFocusedElement, RespectSelectionAnchor respectSelectionAnchor, CallbackID callbackID) 2139 2138 { 2140 2139 auto& frame = m_page->focusController().focusedOrMainFrame(); … … 2150 2149 VisiblePosition selectionEnd; 2151 2150 2152 if (m_selectionAnchor == Start) { 2153 selectionStart = frame.selection().selection().visibleStart(); 2154 selectionEnd = position; 2155 2156 if (position <= selectionStart) { 2157 selectionStart = selectionStart.previous(); 2151 if (respectSelectionAnchor == RespectSelectionAnchor::Yes) { 2152 if (m_selectionAnchor == Start) { 2153 selectionStart = frame.selection().selection().visibleStart(); 2154 selectionEnd = position; 2155 if (position <= selectionStart) { 2156 selectionStart = selectionStart.previous(); 2157 selectionEnd = frame.selection().selection().visibleEnd(); 2158 m_selectionAnchor = End; 2159 } 2160 } else { 2161 selectionStart = position; 2158 2162 selectionEnd = frame.selection().selection().visibleEnd(); 2159 m_selectionAnchor = End; 2163 if (position >= selectionEnd) { 2164 selectionStart = frame.selection().selection().visibleStart(); 2165 selectionEnd = selectionEnd.next(); 2166 m_selectionAnchor = Start; 2167 } 2160 2168 } 2161 2169 } else { 2162 selectionStart = position; 2163 selectionEnd = frame.selection().selection().visibleEnd(); 2164 2165 if (position >= selectionEnd) { 2166 selectionStart = frame.selection().selection().visibleStart(); 2167 selectionEnd = selectionEnd.next(); 2168 m_selectionAnchor = Start; 2170 auto currentStart = frame.selection().selection().visibleStart(); 2171 auto currentEnd = frame.selection().selection().visibleEnd(); 2172 if (position <= currentStart) { 2173 selectionStart = position; 2174 selectionEnd = currentEnd; 2175 } else if (position >= currentEnd) { 2176 selectionStart = currentStart; 2177 selectionEnd = position; 2169 2178 } 2170 2179 } -
trunk/Tools/ChangeLog
r256512 r256520 1 2020-02-13 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] -updateSelectionWithExtentPoint:completionHandler: should work without requiring floating cursor 4 https://bugs.webkit.org/show_bug.cgi?id=207680 5 <rdar://problem/59340940> 6 7 Reviewed by Tim Horton. 8 9 Add a new API test to verify that calling -updateSelectionWithExtentPoint:completionHandler: with a point behind 10 the current selection works. 11 12 * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm: 13 (-[TestWKWebView updateSelectionWithExtentPoint:]): 14 * TestWebKitAPI/ios/UIKitSPI.h: 15 1 16 2020-02-13 Said Abou-Hallawa <said@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm
r256000 r256520 35 35 @interface TestWKWebView (UIWKInteractionViewTesting) 36 36 - (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point; 37 - (void)updateSelectionWithExtentPoint:(CGPoint)point; 37 38 - (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity; 38 39 @end … … 44 45 __block bool done = false; 45 46 [self.textInputContentView selectTextWithGranularity:granularity atPoint:point completionHandler:^{ 47 done = true; 48 }]; 49 TestWebKitAPI::Util::run(&done); 50 } 51 52 - (void)updateSelectionWithExtentPoint:(CGPoint)point 53 { 54 __block bool done = false; 55 [self.textInputContentView updateSelectionWithExtentPoint:point completionHandler:^(BOOL) { 46 56 done = true; 47 57 }]; … … 69 79 } 70 80 81 TEST(UIWKInteractionViewProtocol, UpdateSelectionWithExtentPoint) 82 { 83 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]); 84 [webView synchronouslyLoadHTMLString:@"<body contenteditable style='font-size: 20px;'>Hello world</body>"]; 85 86 [webView evaluateJavaScript:@"getSelection().setPosition(document.body, 1)" completionHandler:nil]; 87 [webView updateSelectionWithExtentPoint:CGPointMake(5, 20)]; 88 EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"getSelection().toString()"]); 89 90 [webView evaluateJavaScript:@"getSelection().setPosition(document.body, 0)" completionHandler:nil]; 91 [webView updateSelectionWithExtentPoint:CGPointMake(300, 20)]; 92 EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"getSelection().toString()"]); 93 } 94 71 95 #endif -
trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h
r256297 r256520 176 176 - (void)selectWordBackward; 177 177 - (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point completionHandler:(void (^)(void))completionHandler; 178 - (void)updateSelectionWithExtentPoint:(CGPoint)point completionHandler:(void (^)(BOOL selectionEndIsMoving))completionHandler; 178 179 - (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity completionHandler:(void (^)(BOOL selectionEndIsMoving))completionHandler; 179 180 @property (nonatomic, readonly) NSString *selectedText;
Note: See TracChangeset
for help on using the changeset viewer.