Changeset 247679 in webkit


Ignore:
Timestamp:
Jul 21, 2019 8:35:38 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[iOS] [WebKit2] Add limited support for -isPosition:atBoundary:inDirection: in WKContentView
https://bugs.webkit.org/show_bug.cgi?id=199993
<rdar://problem/49523528>

Reviewed by Beth Dakin.

Source/WebKit:

Add support for -isPosition:atBoundary:inDirection:, only in the cases where the given position is the start or
and position and the given granularity is UITextGranularityParagraph.

Test: EditorStateTests.ParagraphBoundary

  • Shared/EditorState.cpp:

(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):

  • Shared/EditorState.h:

Add a couple of bits to indicate whether the selection start or end positions are at paragraph boundaries.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView isPosition:atBoundary:inDirection:]):

Implement this to return selectionStartIsAtParagraphBoundary or selectionEndIsAtParagraphBoundary.

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::platformEditorState const):

Tools:

Add a new API test to verify the behavior of -isPosition:atBoundary:inDirection:.

  • TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/cocoa/TestWKWebView.h:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247673 r247679  
     12019-07-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] [WebKit2] Add limited support for -isPosition:atBoundary:inDirection: in WKContentView
     4        https://bugs.webkit.org/show_bug.cgi?id=199993
     5        <rdar://problem/49523528>
     6
     7        Reviewed by Beth Dakin.
     8
     9        Add support for -isPosition:atBoundary:inDirection:, only in the cases where the given position is the start or
     10        and position and the given granularity is UITextGranularityParagraph.
     11
     12        Test: EditorStateTests.ParagraphBoundary
     13
     14        * Shared/EditorState.cpp:
     15        (WebKit::EditorState::PostLayoutData::encode const):
     16        (WebKit::EditorState::PostLayoutData::decode):
     17        * Shared/EditorState.h:
     18
     19        Add a couple of bits to indicate whether the selection start or end positions are at paragraph boundaries.
     20
     21        * UIProcess/ios/WKContentViewInteraction.mm:
     22        (-[WKContentView isPosition:atBoundary:inDirection:]):
     23
     24        Implement this to return selectionStartIsAtParagraphBoundary or selectionEndIsAtParagraphBoundary.
     25
     26        * WebProcess/WebPage/ios/WebPageIOS.mm:
     27        (WebKit::WebPage::platformEditorState const):
     28
    1292019-07-20  Chris Dumez  <cdumez@apple.com>
    230
  • trunk/Source/WebKit/Shared/EditorState.cpp

    r243102 r247679  
    135135    encoder << caretColor;
    136136    encoder << atStartOfSentence;
     137    encoder << selectionStartIsAtParagraphBoundary;
     138    encoder << selectionEndIsAtParagraphBoundary;
    137139#endif
    138140#if PLATFORM(MAC)
     
    197199        return false;
    198200    if (!decoder.decode(result.atStartOfSentence))
     201        return false;
     202    if (!decoder.decode(result.selectionStartIsAtParagraphBoundary))
     203        return false;
     204    if (!decoder.decode(result.selectionEndIsAtParagraphBoundary))
    199205        return false;
    200206#endif
  • trunk/Source/WebKit/Shared/EditorState.h

    r243102 r247679  
    113113        WebCore::Color caretColor;
    114114        bool atStartOfSentence { false };
     115        bool selectionStartIsAtParagraphBoundary { false };
     116        bool selectionEndIsAtParagraphBoundary { false };
    115117#endif
    116118#if PLATFORM(MAC)
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r247653 r247679  
    50705070- (BOOL)isPosition:(UITextPosition *)position atBoundary:(UITextGranularity)granularity inDirection:(UITextDirection)direction
    50715071{
     5072    if (granularity == UITextGranularityParagraph) {
     5073        if (direction == UITextStorageDirectionBackward && [position isEqual:self.selectedTextRange.start])
     5074            return _page->editorState().postLayoutData().selectionStartIsAtParagraphBoundary;
     5075
     5076        if (direction == UITextStorageDirectionForward && [position isEqual:self.selectedTextRange.end])
     5077            return _page->editorState().postLayoutData().selectionEndIsAtParagraphBoundary;
     5078    }
     5079
    50725080    return NO;
    50735081}
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r247667 r247679  
    274274        }
    275275        computeEditableRootHasContentAndPlainText(selection, postLayoutData);
     276        postLayoutData.selectionStartIsAtParagraphBoundary = atBoundaryOfGranularity(selection.visibleStart(), TextGranularity::ParagraphGranularity, SelectionDirection::DirectionBackward);
     277        postLayoutData.selectionEndIsAtParagraphBoundary = atBoundaryOfGranularity(selection.visibleEnd(), TextGranularity::ParagraphGranularity, SelectionDirection::DirectionForward);
    276278    }
    277279}
  • trunk/Tools/ChangeLog

    r247677 r247679  
     12019-07-21  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] [WebKit2] Add limited support for -isPosition:atBoundary:inDirection: in WKContentView
     4        https://bugs.webkit.org/show_bug.cgi?id=199993
     5        <rdar://problem/49523528>
     6
     7        Reviewed by Beth Dakin.
     8
     9        Add a new API test to verify the behavior of -isPosition:atBoundary:inDirection:.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
     12        (TestWebKitAPI::TEST):
     13        * TestWebKitAPI/cocoa/TestWKWebView.h:
     14
    1152019-07-21  Andres Gonzalez  <andresg_22@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm

    r244955 r247679  
    399399}
    400400
     401TEST(EditorStateTests, ParagraphBoundary)
     402{
     403    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     404    [webView synchronouslyLoadHTMLString:@"<body contenteditable><p>Hello world.</p></body>"];
     405    [webView stringByEvaluatingJavaScript:@"document.body.focus()"];
     406    [webView waitForNextPresentationUpdate];
     407
     408    auto textInput = [webView textInputContentView];
     409    auto editor = adoptNS([[EditingTestHarness alloc] initWithWebView:webView.get()]);
     410    [editor selectAll];
     411
     412    EXPECT_TRUE([textInput isPosition:textInput.selectedTextRange.start atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionBackward]);
     413    EXPECT_TRUE([textInput isPosition:textInput.selectedTextRange.end atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward]);
     414
     415    [editor moveForward];
     416    [editor moveBackward];
     417    [editor moveBackward];
     418
     419    EXPECT_FALSE([textInput isPosition:textInput.selectedTextRange.start atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionBackward]);
     420    EXPECT_FALSE([textInput isPosition:textInput.selectedTextRange.end atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward]);
     421}
     422
    401423#endif // PLATFORM(IOS_FAMILY)
    402424
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h

    r247567 r247679  
    8888
    8989@interface TestWKWebView (IOSOnly)
    90 @property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputInternal, UITextInputMultiDocument, UIWKInteractionViewProtocol> *textInputContentView;
     90@property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputInternal, UITextInputMultiDocument, UIWKInteractionViewProtocol, UITextInputTokenizer> *textInputContentView;
    9191@property (nonatomic, readonly) RetainPtr<NSArray> selectionRectsAfterPresentationUpdate;
    9292@property (nonatomic, readonly) CGRect caretViewRectInContentCoordinates;
Note: See TracChangeset for help on using the changeset viewer.