Title: [257852] trunk/Source/WebKit
Revision
257852
Author
[email protected]
Date
2020-03-04 10:05:43 -0800 (Wed, 04 Mar 2020)

Log Message

Implement WKTextSelectionRect in terms of WebCore::SelectionRect and WKTextRange in terms of WKTextSelectionRect
https://bugs.webkit.org/show_bug.cgi?id=208563

Reviewed by Alex Christensen.

It is a layering violation that WebKit2 includes a header from WebKit. Implement
WKTextSelectionRect in terms of WebCore::SelectionRect as a step towards fixing this.
Also avoid the WebCore::SelectionRect -> WebSelectionRect -> WKTextSelectionRect
dance that WKTextRange does so that -[WKTextRange selectionRectsForRange] returns
an array of WKTextSelectionRects by writing WKTextRange in terms of NSArray<WKTextSelectionRect *>*.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _uiTextSelectionRects]):
(-[WKContentView selectedTextRange]):
(-[WKContentView selectionRectsForRange:]):
* UIProcess/ios/WKTextSelectionRect.h:
* UIProcess/ios/WKTextSelectionRect.mm:
(-[WKTextSelectionRect initWithSelectionRect:]):
(-[WKTextSelectionRect rect]):
(-[WKTextSelectionRect writingDirection]):
(-[WKTextSelectionRect containsStart]):
(-[WKTextSelectionRect containsEnd]):
(-[WKTextSelectionRect isVertical]):
(-[WKTextSelectionRect initWithWebRect:]): Deleted.
(-[WKTextSelectionRect dealloc]): Deleted.
(+[WKTextSelectionRect textSelectionRectsWithWebRects:]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (257851 => 257852)


--- trunk/Source/WebKit/ChangeLog	2020-03-04 18:04:05 UTC (rev 257851)
+++ trunk/Source/WebKit/ChangeLog	2020-03-04 18:05:43 UTC (rev 257852)
@@ -1,5 +1,34 @@
 2020-03-04  Daniel Bates  <[email protected]>
 
+        Implement WKTextSelectionRect in terms of WebCore::SelectionRect and WKTextRange in terms of WKTextSelectionRect
+        https://bugs.webkit.org/show_bug.cgi?id=208563
+
+        Reviewed by Alex Christensen.
+
+        It is a layering violation that WebKit2 includes a header from WebKit. Implement
+        WKTextSelectionRect in terms of WebCore::SelectionRect as a step towards fixing this.
+        Also avoid the WebCore::SelectionRect -> WebSelectionRect -> WKTextSelectionRect
+        dance that WKTextRange does so that -[WKTextRange selectionRectsForRange] returns
+        an array of WKTextSelectionRects by writing WKTextRange in terms of NSArray<WKTextSelectionRect *>*.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _uiTextSelectionRects]):
+        (-[WKContentView selectedTextRange]):
+        (-[WKContentView selectionRectsForRange:]):
+        * UIProcess/ios/WKTextSelectionRect.h:
+        * UIProcess/ios/WKTextSelectionRect.mm:
+        (-[WKTextSelectionRect initWithSelectionRect:]):
+        (-[WKTextSelectionRect rect]):
+        (-[WKTextSelectionRect writingDirection]):
+        (-[WKTextSelectionRect containsStart]):
+        (-[WKTextSelectionRect containsEnd]):
+        (-[WKTextSelectionRect isVertical]):
+        (-[WKTextSelectionRect initWithWebRect:]): Deleted.
+        (-[WKTextSelectionRect dealloc]): Deleted.
+        (+[WKTextSelectionRect textSelectionRectsWithWebRects:]): Deleted.
+
+2020-03-04  Daniel Bates  <[email protected]>
+
         Move WKTextSelectionRect into its own file
         https://bugs.webkit.org/show_bug.cgi?id=208561
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (257851 => 257852)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-03-04 18:04:05 UTC (rev 257851)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-03-04 18:05:43 UTC (rev 257852)
@@ -266,7 +266,7 @@
     BOOL _isNone;
     BOOL _isRange;
     BOOL _isEditable;
-    NSArray *_selectionRects;
+    NSArray<WKTextSelectionRect *>*_selectionRects;
     NSUInteger _selectedTextLength;
 }
 @property (nonatomic) CGRect startRect;
@@ -275,7 +275,7 @@
 @property (nonatomic) BOOL isRange;
 @property (nonatomic) BOOL isEditable;
 @property (nonatomic) NSUInteger selectedTextLength;
-@property (copy, nonatomic) NSArray *selectionRects;
+@property (copy, nonatomic) NSArray<WKTextSelectionRect *> *selectionRects;
 
 + (WKTextRange *)textRangeWithState:(BOOL)isNone isRange:(BOOL)isRange isEditable:(BOOL)isEditable startRect:(CGRect)startRect endRect:(CGRect)endRect selectionRects:(NSArray *)selectionRects selectedTextLength:(NSUInteger)selectedTextLength;
 
@@ -2294,7 +2294,7 @@
 
     if (_textInteractionAssistant) {
         for (WKTextSelectionRect *selectionRect in [_textInteractionAssistant valueForKeyPath:@"selectionView.selection.selectionRects"])
-            [textSelectionRects addObject:[NSValue valueWithCGRect:selectionRect.webRect.rect]];
+            [textSelectionRects addObject:[NSValue valueWithCGRect:selectionRect.rect]];
     }
 
     return textSelectionRects;
@@ -4460,6 +4460,16 @@
 {
 }
 
+static NSArray<WKTextSelectionRect *> *wkTextSelectionRects(const Vector<WebCore::SelectionRect>& coreRects)
+{
+    auto rects = adoptNS([[NSMutableArray alloc] initWithCapacity:coreRects.size()]);
+    for (auto& coreRect : coreRects) {
+        auto wkTextSelectionRect = adoptNS([[WKTextSelectionRect alloc] initWithSelectionRect:coreRect]);
+        [rects addObject:wkTextSelectionRect.get()];
+    }
+    return rects.autorelease();
+}
+
 - (UITextRange *)selectedTextRange
 {
     if (_page->editorState().selectionIsNone || _page->editorState().isMissingPostLayoutData)
@@ -4497,7 +4507,7 @@
                                 isEditable:_page->editorState().isContentEditable
                                  startRect:startRect
                                    endRect:endRect
-                            selectionRects:[self webSelectionRects]
+                            selectionRects:wkTextSelectionRects(_page->editorState().postLayoutData().selectionRects)
                         selectedTextLength:postLayoutEditorStateData.selectedTextLength];
 }
 
@@ -4508,7 +4518,7 @@
 
 - (NSArray *)selectionRectsForRange:(UITextRange *)range
 {
-    return [WKTextSelectionRect textSelectionRectsWithWebRects:((WKTextRange *)range).selectionRects];
+    return [(WKTextRange *)range selectionRects];
 }
 
 - (void)setSelectedTextRange:(UITextRange *)range

Modified: trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.h (257851 => 257852)


--- trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.h	2020-03-04 18:04:05 UTC (rev 257851)
+++ trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.h	2020-03-04 18:05:43 UTC (rev 257852)
@@ -29,14 +29,14 @@
 
 #import <UIKit/UIKit.h>
 
-@class WebSelectionRect;
+namespace WebCore {
+class SelectionRect;
+}
 
 @interface WKTextSelectionRect : UITextSelectionRect
 
-@property (nonatomic, retain) WebSelectionRect *webRect;
+- (instancetype)initWithSelectionRect:(const WebCore::SelectionRect&)selectionRect;
 
-+ (NSArray *)textSelectionRectsWithWebRects:(NSArray *)webRects;
-
 @end
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.mm (257851 => 257852)


--- trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.mm	2020-03-04 18:04:05 UTC (rev 257851)
+++ trunk/Source/WebKit/UIProcess/ios/WKTextSelectionRect.mm	2020-03-04 18:05:43 UTC (rev 257852)
@@ -28,47 +28,29 @@
 
 #if PLATFORM(IOS_FAMILY)
 
-// FIXME: Layering violation; WebKit2 should not include WebKit headers.
-#import <WebKit/WebSelectionRect.h>
+#import <WebCore/SelectionRect.h>
 
-@implementation WKTextSelectionRect
+@implementation WKTextSelectionRect {
+    WebCore::SelectionRect _selectionRect;
+}
 
-- (id)initWithWebRect:(WebSelectionRect *)wRect
+- (instancetype)initWithSelectionRect:(const WebCore::SelectionRect&)selectionRect
 {
-    self = [super init];
-    if (self)
-        self.webRect = wRect;
-
+    if (!(self = [super init]))
+        return nil;
+    _selectionRect = selectionRect;
     return self;
 }
 
-- (void)dealloc
-{
-    self.webRect = nil;
-    [super dealloc];
-}
-
-// FIXME: We are using this implementation for now that uses WebSelectionRect, but
-// we want to provide our own based on WebCore::SelectionRect.
-+ (NSArray *)textSelectionRectsWithWebRects:(NSArray *)webRects
-{
-    NSMutableArray *array = [NSMutableArray arrayWithCapacity:webRects.count];
-    for (WebSelectionRect *webRect in webRects) {
-        RetainPtr<WKTextSelectionRect> rect = adoptNS([[WKTextSelectionRect alloc] initWithWebRect:webRect]);
-        [array addObject:rect.get()];
-    }
-    return array;
-}
-
 - (CGRect)rect
 {
-    return _webRect.rect;
+    return _selectionRect.rect();
 }
 
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
 - (UITextWritingDirection)writingDirection
 {
-    return (UITextWritingDirection)_webRect.writingDirection;
+    return _selectionRect.direction() == WebCore::TextDirection::LTR ? UITextWritingDirectionLeftToRight : UITextWritingDirectionRightToLeft;
 }
 ALLOW_DEPRECATED_DECLARATIONS_END
 
@@ -79,17 +61,17 @@
 
 - (BOOL)containsStart
 {
-    return _webRect.containsStart;
+    return _selectionRect.containsStart();
 }
 
 - (BOOL)containsEnd
 {
-    return _webRect.containsEnd;
+    return _selectionRect.containsEnd();
 }
 
 - (BOOL)isVertical
 {
-    return !_webRect.isHorizontal;
+    return !_selectionRect.isHorizontal();
 }
 
 @end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to