Use RetainPtr and rename +autocorrectionRectsWithRects:lastRect: to +autocorrectionRe...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Apr 2019 23:49:09 +0000 (23:49 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Apr 2019 23:49:09 +0000 (23:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197122

Reviewed by Wenson Hsieh.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]): Renamed; formerly named +autocorrectionRectsWithRects:lastRect:.
While I am here use else-branch to initialize firstRect and lastRect just to make the code closer to the optimal
assembly. Also use Vector::{isEmpty, first, last}() instead of using the index operator overload and size() for
emptiness checks. The code is more readable at the cost being ever so slightly slower (due to the overflow checks
in first() and last()), but this code is likely not hot enough for it to matter.
(-[WKContentView applyAutocorrection:toString:withCompletionHandler:]): Update for renaming.
(+[WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:lastCGRect:]): Ditto.
(+[WKAutocorrectionRects autocorrectionRectsWithRects:lastRect:]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244474 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

index 1f5b487..5901241 100644 (file)
@@ -1,5 +1,22 @@
 2019-04-19  Daniel Bates  <dabates@apple.com>
 
+        Use RetainPtr and rename +autocorrectionRectsWithRects:lastRect: to +autocorrectionRectsWithFirstCGRect:lastCGRect:
+        https://bugs.webkit.org/show_bug.cgi?id=197122
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView requestAutocorrectionRectsForString:withCompletionHandler:]): Renamed; formerly named +autocorrectionRectsWithRects:lastRect:.
+        While I am here use else-branch to initialize firstRect and lastRect just to make the code closer to the optimal
+        assembly. Also use Vector::{isEmpty, first, last}() instead of using the index operator overload and size() for
+        emptiness checks. The code is more readable at the cost being ever so slightly slower (due to the overflow checks
+        in first() and last()), but this code is likely not hot enough for it to matter.
+        (-[WKContentView applyAutocorrection:toString:withCompletionHandler:]): Update for renaming.
+        (+[WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:lastCGRect:]): Ditto.
+        (+[WKAutocorrectionRects autocorrectionRectsWithRects:lastRect:]): Deleted.
+
+2019-04-19  Daniel Bates  <dabates@apple.com>
+
         -[WKAutocorrectionContext emptyAutocorrectionContext:] generates invalid empty context
         https://bugs.webkit.org/show_bug.cgi?id=197119
 
index 33e6e97..d59b072 100644 (file)
@@ -285,7 +285,7 @@ constexpr double fasterTapSignificantZoomThreshold = 0.8;
 @end
 
 @interface WKAutocorrectionRects : UIWKAutocorrectionRects
-+ (WKAutocorrectionRects *)autocorrectionRectsWithRects:(CGRect)firstRect lastRect:(CGRect)lastRect;
++ (WKAutocorrectionRects *)autocorrectionRectsWithFirstCGRect:(CGRect)firstRect lastCGRect:(CGRect)lastRect;
 @end
 
 @interface WKAutocorrectionContext : UIWKAutocorrectionContext
@@ -3467,20 +3467,23 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
     }
 
     _page->requestAutocorrectionData(input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& rects, auto& fontName, double fontSize, uint64_t traits, auto) {
-        CGRect firstRect = CGRectZero;
-        CGRect lastRect = CGRectZero;
-        if (rects.size()) {
-            firstRect = rects[0];
-            lastRect = rects[rects.size() - 1];
+        CGRect firstRect;
+        CGRect lastRect;
+        if (rects.isEmpty()) {
+            firstRect = CGRectZero;
+            lastRect = CGRectZero;
+        } else {
+            firstRect = rects.first();
+            lastRect = rects.last();
         }
-        
+
         view->_autocorrectionData.fontName = fontName;
         view->_autocorrectionData.fontSize = fontSize;
         view->_autocorrectionData.fontTraits = traits;
         view->_autocorrectionData.textFirstRect = firstRect;
         view->_autocorrectionData.textLastRect = lastRect;
 
-        completion(rects.size() ? [WKAutocorrectionRects autocorrectionRectsWithRects:firstRect lastRect:lastRect] : nil);
+        completion(!rects.isEmpty() ? [WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:firstRect lastCGRect:lastRect] : nil);
     });
 }
 
@@ -3671,13 +3674,13 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
 
     if (useSyncRequest) {
         if (completionHandler)
-            completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithRects:_autocorrectionData.textFirstRect lastRect:_autocorrectionData.textLastRect] : nil);
+            completionHandler(_page->applyAutocorrection(correction, input) ? [WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:_autocorrectionData.textFirstRect lastCGRect:_autocorrectionData.textLastRect] : nil);
         return;
     }
 
     _page->applyAutocorrection(correction, input, [view = retainPtr(self), completion = makeBlockPtr(completionHandler)](auto& string, auto error) {
         if (completion)
-            completion(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithRects:view->_autocorrectionData.textFirstRect lastRect:view->_autocorrectionData.textLastRect] : nil);
+            completion(!string.isNull() ? [WKAutocorrectionRects autocorrectionRectsWithFirstCGRect:view->_autocorrectionData.textFirstRect lastCGRect:view->_autocorrectionData.textLastRect] : nil);
     });
 }
 
@@ -7672,12 +7675,12 @@ ALLOW_DEPRECATED_DECLARATIONS_END
 
 @implementation WKAutocorrectionRects
 
-+ (WKAutocorrectionRects *)autocorrectionRectsWithRects:(CGRect)firstRect lastRect:(CGRect)lastRect
++ (WKAutocorrectionRects *)autocorrectionRectsWithFirstCGRect:(CGRect)firstRect lastCGRect:(CGRect)lastRect
 {
-    WKAutocorrectionRects *rects =[[WKAutocorrectionRects alloc] init];
-    rects.firstRect = firstRect;
-    rects.lastRect = lastRect;
-    return [rects autorelease];
+    auto rects = adoptNS([[WKAutocorrectionRects alloc] init]);
+    [rects setFirstRect:firstRect];
+    [rects setLastRect:lastRect];
+    return rects.autorelease();
 }
 
 @end