Changeset 260759 in webkit
- Timestamp:
- Apr 27, 2020 9:08:21 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r260755 r260759 1 2020-04-27 Daniel Bates <dabates@apple.com> 2 3 Caret may be placed in the wrong spot for text input context that is a form control 4 https://bugs.webkit.org/show_bug.cgi?id=210939 5 <rdar://problem/61943089> 6 7 Reviewed by Darin Adler. 8 9 Add a helper function that returns the closest editable position inside an element 10 for a given point (if any). 11 12 * editing/Editing.cpp: 13 (WebCore::closestEditablePositionInElementForAbsolutePoint): Added. 14 * editing/Editing.h: 15 1 16 2020-04-27 Alicia Boya García <aboya@igalia.com> 2 17 -
trunk/Source/WebCore/editing/Editing.cpp
r260753 r260759 51 51 #include "RenderElement.h" 52 52 #include "RenderTableCell.h" 53 #include "RenderTextControlSingleLine.h" 53 54 #include "ShadowRoot.h" 54 55 #include "Text.h" 56 #include "TextControlInnerElements.h" 55 57 #include "TextIterator.h" 56 58 #include "VisibleUnits.h" … … 560 562 ASSERT(!node.parentNode()->isShadowRoot()); 561 563 return positionInParentAfterNode(&node); 564 } 565 566 VisiblePosition closestEditablePositionInElementForAbsolutePoint(const Element& element, const IntPoint& point) 567 { 568 if (!element.isConnected() || !element.document().frame()) 569 return { }; 570 571 Ref<const Element> protectedElement { element }; 572 auto frame = makeRef(*element.document().frame()); 573 574 element.document().updateLayoutIgnorePendingStylesheets(); 575 576 RenderObject* renderer = element.renderer(); 577 // Look at the inner element of a form control, not the control itself, as it is the editable part. 578 if (is<HTMLTextFormControlElement>(element)) { 579 auto& formControlElement = downcast<HTMLTextFormControlElement>(element); 580 if (!formControlElement.isInnerTextElementEditable()) 581 return { }; 582 if (auto innerTextElement = formControlElement.innerTextElement()) 583 renderer = innerTextElement->renderer(); 584 } 585 if (!renderer) 586 return { }; 587 auto absoluteBoundingBox = renderer->absoluteBoundingBoxRect(); 588 auto constrainedPoint = point.constrainedBetween(absoluteBoundingBox.minXMinYCorner(), absoluteBoundingBox.maxXMaxYCorner()); 589 auto visiblePosition = frame->visiblePositionForPoint(constrainedPoint); 590 return isEditablePosition(visiblePosition.deepEquivalent()) ? visiblePosition : VisiblePosition { }; 562 591 } 563 592 -
trunk/Source/WebCore/editing/Editing.h
r260753 r260759 157 157 VisiblePosition visiblePositionForIndexUsingCharacterIterator(Node&, int index); // FIXME: Why do we need this version? 158 158 159 WEBCORE_EXPORT VisiblePosition closestEditablePositionInElementForAbsolutePoint(const Element&, const IntPoint&); 160 159 161 // ------------------------------------------------------------------------- 160 162 // HTMLElement -
trunk/Source/WebKit/ChangeLog
r260757 r260759 1 2020-04-27 Daniel Bates <dabates@apple.com> 2 3 Caret may be placed in the wrong spot for text input context that is a form control 4 https://bugs.webkit.org/show_bug.cgi?id=210939 5 <rdar://problem/61943089> 6 7 Reviewed by Darin Adler. 8 9 Find the closest editable position in the element for the point using the 10 newly introduced closestEditablePositionInElementForAbsolutePoint(). 11 12 * WebProcess/WebPage/ios/WebPageIOS.mm: 13 (WebKit::WebPage::focusTextInputContextAndPlaceCaret): 14 1 15 2020-04-27 Darin Adler <darin@apple.com> 2 16 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r260739 r260759 100 100 #import <WebCore/HTMLSummaryElement.h> 101 101 #import <WebCore/HTMLTextAreaElement.h> 102 #import <WebCore/HTMLTextFormControlElement.h>103 102 #import <WebCore/HistoryItem.h> 104 103 #import <WebCore/HitTestResult.h> … … 4351 4350 } 4352 4351 4352 // FIXME: Do not focus an element if it moved or the caret point is outside its bounds 4353 // because we only want to do so if the caret can be placed. 4353 4354 UserGestureIndicator gestureIndicator { ProcessingUserGesture, &target->document() }; 4354 4355 SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true }; … … 4360 4361 return; 4361 4362 } 4362 // The function visiblePositionInFocusedNodeForPoint constrains the point to be inside 4363 // the bounds of the target element. 4364 auto position = visiblePositionInFocusedNodeForPoint(targetFrame, point, true /* isInteractingWithFocusedElement */); 4363 4364 ASSERT(targetFrame->view()); 4365 auto position = closestEditablePositionInElementForAbsolutePoint(*target, targetFrame->view()->rootViewToContents(point)); 4366 if (position.isNull()) { 4367 completionHandler(false); 4368 return; 4369 } 4365 4370 targetFrame->selection().setSelectedRange(Range::create(*targetFrame->document(), position, position).ptr(), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 4366 4371 completionHandler(true); -
trunk/Tools/ChangeLog
r260758 r260759 1 2020-04-27 Daniel Bates <dabates@apple.com> 2 3 Caret may be placed in the wrong spot for text input context that is a form control 4 https://bugs.webkit.org/show_bug.cgi?id=210939 5 <rdar://problem/61943089> 6 7 Reviewed by Darin Adler. 8 9 Add a test. 10 11 * TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm: 12 (TestWebKitAPI::TEST): 13 1 14 2020-04-27 Alexey Proskuryakov <ap@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/RequestTextInputContext.mm
r260756 r260759 465 465 } 466 466 467 TEST(RequestTextInputContext, FocusFieldWithPaddingAndPlaceCaretAtEnd) 468 { 469 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 470 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 471 472 constexpr char exampleText[] = "hello world"; 473 constexpr size_t exampleTextLength = sizeof(exampleText) - 1; 474 [webView synchronouslyLoadHTMLString:applyStyle([NSString stringWithFormat:@"<input type='text' value='%s' style='width: 100px; height: 50px; padding: 20px'>", exampleText])]; 475 NSArray<_WKTextInputContext *> *contexts = [webView synchronouslyRequestTextInputContextsInRect:[webView bounds]]; 476 EXPECT_EQ(1UL, contexts.count); 477 RetainPtr<_WKTextInputContext> inputElement = contexts[0]; 478 479 CGRect boundingRect = [inputElement boundingRect]; 480 CGPoint endPosition = CGPointMake(boundingRect.origin.x + boundingRect.size.width, boundingRect.origin.y); 481 EXPECT_EQ((UIResponder<UITextInput> *)[webView textInputContentView], [webView synchronouslyFocusTextInputContext:inputElement.get() placeCaretAt:endPosition]); 482 EXPECT_WK_STREQ("INPUT", [webView stringByEvaluatingJavaScript:@"document.activeElement.tagName"]); 483 EXPECT_EQ(static_cast<int>(exampleTextLength), [[webView objectByEvaluatingJavaScript:@"document.activeElement.selectionStart"] intValue]); 484 EXPECT_EQ(static_cast<int>(exampleTextLength), [[webView objectByEvaluatingJavaScript:@"document.activeElement.selectionEnd"] intValue]); 485 } 486 467 487 TEST(RequestTextInputContext, FocusFieldAndPlaceCaretOutsideField) 468 488 {
Note: See TracChangeset
for help on using the changeset viewer.