Title: [247679] trunk
Revision
247679
Author
[email protected]
Date
2019-07-21 20:35:38 -0700 (Sun, 21 Jul 2019)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247678 => 247679)


--- trunk/Source/WebKit/ChangeLog	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Source/WebKit/ChangeLog	2019-07-22 03:35:38 UTC (rev 247679)
@@ -1,3 +1,31 @@
+2019-07-21  Wenson Hsieh  <[email protected]>
+
+        [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.
+
+        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):
+
 2019-07-20  Chris Dumez  <[email protected]>
 
         Speed up HashTable decoding by reserving capacity and avoiding rehashing

Modified: trunk/Source/WebKit/Shared/EditorState.cpp (247678 => 247679)


--- trunk/Source/WebKit/Shared/EditorState.cpp	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Source/WebKit/Shared/EditorState.cpp	2019-07-22 03:35:38 UTC (rev 247679)
@@ -134,6 +134,8 @@
     encoder << editableRootIsTransparentOrFullyClipped;
     encoder << caretColor;
     encoder << atStartOfSentence;
+    encoder << selectionStartIsAtParagraphBoundary;
+    encoder << selectionEndIsAtParagraphBoundary;
 #endif
 #if PLATFORM(MAC)
     encoder << candidateRequestStartPosition;
@@ -197,6 +199,10 @@
         return false;
     if (!decoder.decode(result.atStartOfSentence))
         return false;
+    if (!decoder.decode(result.selectionStartIsAtParagraphBoundary))
+        return false;
+    if (!decoder.decode(result.selectionEndIsAtParagraphBoundary))
+        return false;
 #endif
 #if PLATFORM(MAC)
     if (!decoder.decode(result.candidateRequestStartPosition))

Modified: trunk/Source/WebKit/Shared/EditorState.h (247678 => 247679)


--- trunk/Source/WebKit/Shared/EditorState.h	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Source/WebKit/Shared/EditorState.h	2019-07-22 03:35:38 UTC (rev 247679)
@@ -112,6 +112,8 @@
         bool editableRootIsTransparentOrFullyClipped { false };
         WebCore::Color caretColor;
         bool atStartOfSentence { false };
+        bool selectionStartIsAtParagraphBoundary { false };
+        bool selectionEndIsAtParagraphBoundary { false };
 #endif
 #if PLATFORM(MAC)
         uint64_t candidateRequestStartPosition { 0 };

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (247678 => 247679)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-07-22 03:35:38 UTC (rev 247679)
@@ -5069,6 +5069,14 @@
 
 - (BOOL)isPosition:(UITextPosition *)position atBoundary:(UITextGranularity)granularity inDirection:(UITextDirection)direction
 {
+    if (granularity == UITextGranularityParagraph) {
+        if (direction == UITextStorageDirectionBackward && [position isEqual:self.selectedTextRange.start])
+            return _page->editorState().postLayoutData().selectionStartIsAtParagraphBoundary;
+
+        if (direction == UITextStorageDirectionForward && [position isEqual:self.selectedTextRange.end])
+            return _page->editorState().postLayoutData().selectionEndIsAtParagraphBoundary;
+    }
+
     return NO;
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (247678 => 247679)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-07-22 03:35:38 UTC (rev 247679)
@@ -273,6 +273,8 @@
                 postLayoutData.editableRootIsTransparentOrFullyClipped = isTransparentOrFullyClipped(*container);
         }
         computeEditableRootHasContentAndPlainText(selection, postLayoutData);
+        postLayoutData.selectionStartIsAtParagraphBoundary = atBoundaryOfGranularity(selection.visibleStart(), TextGranularity::ParagraphGranularity, SelectionDirection::DirectionBackward);
+        postLayoutData.selectionEndIsAtParagraphBoundary = atBoundaryOfGranularity(selection.visibleEnd(), TextGranularity::ParagraphGranularity, SelectionDirection::DirectionForward);
     }
 }
 

Modified: trunk/Tools/ChangeLog (247678 => 247679)


--- trunk/Tools/ChangeLog	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Tools/ChangeLog	2019-07-22 03:35:38 UTC (rev 247679)
@@ -1,3 +1,17 @@
+2019-07-21  Wenson Hsieh  <[email protected]>
+
+        [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.
+
+        Add a new API test to verify the behavior of -isPosition:atBoundary:inDirection:.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+
 2019-07-21  Andres Gonzalez  <[email protected]>
 
         Add accessibilityInsertText for text insertion in edit fields.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm (247678 => 247679)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm	2019-07-22 03:35:38 UTC (rev 247679)
@@ -398,6 +398,28 @@
     EXPECT_EQ(_WKSelectionAttributeNoSelection, [observer currentSelectionAttributes]);
 }
 
+TEST(EditorStateTests, ParagraphBoundary)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadHTMLString:@"<body contenteditable><p>Hello world.</p></body>"];
+    [webView stringByEvaluatingJavaScript:@"document.body.focus()"];
+    [webView waitForNextPresentationUpdate];
+
+    auto textInput = [webView textInputContentView];
+    auto editor = adoptNS([[EditingTestHarness alloc] initWithWebView:webView.get()]);
+    [editor selectAll];
+
+    EXPECT_TRUE([textInput isPosition:textInput.selectedTextRange.start atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionBackward]);
+    EXPECT_TRUE([textInput isPosition:textInput.selectedTextRange.end atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward]);
+
+    [editor moveForward];
+    [editor moveBackward];
+    [editor moveBackward];
+
+    EXPECT_FALSE([textInput isPosition:textInput.selectedTextRange.start atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionBackward]);
+    EXPECT_FALSE([textInput isPosition:textInput.selectedTextRange.end atBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward]);
+}
+
 #endif // PLATFORM(IOS_FAMILY)
 
 } // namespace TestWebKitAPI

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h (247678 => 247679)


--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2019-07-21 22:59:38 UTC (rev 247678)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h	2019-07-22 03:35:38 UTC (rev 247679)
@@ -87,7 +87,7 @@
 @end
 
 @interface TestWKWebView (IOSOnly)
-@property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputInternal, UITextInputMultiDocument, UIWKInteractionViewProtocol> *textInputContentView;
+@property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputInternal, UITextInputMultiDocument, UIWKInteractionViewProtocol, UITextInputTokenizer> *textInputContentView;
 @property (nonatomic, readonly) RetainPtr<NSArray> selectionRectsAfterPresentationUpdate;
 @property (nonatomic, readonly) CGRect caretViewRectInContentCoordinates;
 @property (nonatomic, readonly) NSArray<NSValue *> *selectionViewRectsInContentCoordinates;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to