Title: [247702] trunk
Revision
247702
Author
[email protected]
Date
2019-07-22 15:14:48 -0700 (Mon, 22 Jul 2019)

Log Message

[iOS] [WK1] UIWebView always jumps to the top left corner when scrolling to reveal the selection
https://bugs.webkit.org/show_bug.cgi?id=200013
<rdar://problem/52526901>

Reviewed by Simon Fraser.

Source/WebCore:

After <https://trac.webkit.org/r244141>, we no longer attempt to scroll to reveal the text selection in
UIWebView after changing the selection, due to how we use the legacy document view rect in legacy WebKit when
computing the visual viewport. This causes the viewRect in RenderLayer::scrollRectToVisible to be the same size
as the content size, which then causes us to always scroll to the origin when revealing the selection.

To make selection revealing work again in legacy WebKit, conditionally restore the old behavior of using the
unobscured content rect as the view rect, only in the case where scrolling is delegated and the platform widget
is present.

Test: WebKitLegacy.ScrollToRevealSelection

* page/FrameView.cpp:
(WebCore::FrameView::viewRectExpandedByContentInsets const):
(WebCore::FrameView::visualViewportRectExpandedByContentInsets const): Deleted.

Additionally rename visualViewportRectExpandedByContentInsets to viewRectExpandedByContentInsets, to reflect the
fact that this may either be the visual viewport rect or unobscured content rect.

* page/FrameView.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):

Tools:

Add a new API test to verify that inserting text in UIWebView causes the document to scroll.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitLegacy/ios/ScrollToRevealSelection.mm: Added.
(-[LegacyLoadingDelegate webViewDidFinishLoad:]):
(-[LegacyLoadingDelegate waitForDidFinishLoad]):
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (247701 => 247702)


--- trunk/Source/WebCore/ChangeLog	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Source/WebCore/ChangeLog	2019-07-22 22:14:48 UTC (rev 247702)
@@ -1,3 +1,33 @@
+2019-07-22  Wenson Hsieh  <[email protected]>
+
+        [iOS] [WK1] UIWebView always jumps to the top left corner when scrolling to reveal the selection
+        https://bugs.webkit.org/show_bug.cgi?id=200013
+        <rdar://problem/52526901>
+
+        Reviewed by Simon Fraser.
+
+        After <https://trac.webkit.org/r244141>, we no longer attempt to scroll to reveal the text selection in
+        UIWebView after changing the selection, due to how we use the legacy document view rect in legacy WebKit when
+        computing the visual viewport. This causes the viewRect in RenderLayer::scrollRectToVisible to be the same size
+        as the content size, which then causes us to always scroll to the origin when revealing the selection.
+
+        To make selection revealing work again in legacy WebKit, conditionally restore the old behavior of using the
+        unobscured content rect as the view rect, only in the case where scrolling is delegated and the platform widget
+        is present.
+
+        Test: WebKitLegacy.ScrollToRevealSelection
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::viewRectExpandedByContentInsets const):
+        (WebCore::FrameView::visualViewportRectExpandedByContentInsets const): Deleted.
+
+        Additionally rename visualViewportRectExpandedByContentInsets to viewRectExpandedByContentInsets, to reflect the
+        fact that this may either be the visual viewport rect or unobscured content rect.
+
+        * page/FrameView.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollRectToVisible):
+
 2019-07-22  Brent Fulgham  <[email protected]>
 
         Correct web audio-related crash in seed reports

Modified: trunk/Source/WebCore/page/FrameView.cpp (247701 => 247702)


--- trunk/Source/WebCore/page/FrameView.cpp	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Source/WebCore/page/FrameView.cpp	2019-07-22 22:14:48 UTC (rev 247702)
@@ -1943,12 +1943,18 @@
     });
 }
 
-IntRect FrameView::visualViewportRectExpandedByContentInsets() const
+IntRect FrameView::viewRectExpandedByContentInsets() const
 {
-    FloatRect unobscuredContentRect = this->visualViewportRect();
+    FloatRect viewRect;
+    if (delegatesScrolling() && platformWidget())
+        viewRect = unobscuredContentRect();
+    else
+        viewRect = visualViewportRect();
+
     if (auto* page = frame().page())
-        unobscuredContentRect.expand(page->contentInsets());
-    return IntRect(unobscuredContentRect);
+        viewRect.expand(page->contentInsets());
+
+    return IntRect(viewRect);
 }
 
 bool FrameView::fixedElementsLayoutRelativeToFrame() const

Modified: trunk/Source/WebCore/page/FrameView.h (247701 => 247702)


--- trunk/Source/WebCore/page/FrameView.h	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Source/WebCore/page/FrameView.h	2019-07-22 22:14:48 UTC (rev 247702)
@@ -327,7 +327,7 @@
     WEBCORE_EXPORT static LayoutRect rectForViewportConstrainedObjects(const LayoutRect& visibleContentRect, const LayoutSize& totalContentsSize, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame, ScrollBehaviorForFixedElements);
 #endif
 
-    IntRect visualViewportRectExpandedByContentInsets() const;
+    IntRect viewRectExpandedByContentInsets() const;
     
     bool fixedElementsLayoutRelativeToFrame() const;
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (247701 => 247702)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-07-22 22:14:48 UTC (rev 247702)
@@ -2689,7 +2689,7 @@
 #else
             // FIXME: ContentInsets should be taken care of in UI process side. webkit.org/b/199682
             // To do that, getRectToExpose needs to return the additional scrolling to do beyond content rect.
-            LayoutRect viewRect = frameView.visualViewportRectExpandedByContentInsets();
+            LayoutRect viewRect = frameView.viewRectExpandedByContentInsets();
 
             // FIXME: webkit.org/b/199683 FrameView::visibleContentRect is wrong when content insets are present
             maxScrollPosition = frameView.scrollPositionFromOffset(ScrollPosition(frameView.totalContentsSize() - flooredIntSize(viewRect.size())));

Modified: trunk/Tools/ChangeLog (247701 => 247702)


--- trunk/Tools/ChangeLog	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Tools/ChangeLog	2019-07-22 22:14:48 UTC (rev 247702)
@@ -1,3 +1,19 @@
+2019-07-22  Wenson Hsieh  <[email protected]>
+
+        [iOS] [WK1] UIWebView always jumps to the top left corner when scrolling to reveal the selection
+        https://bugs.webkit.org/show_bug.cgi?id=200013
+        <rdar://problem/52526901>
+
+        Reviewed by Simon Fraser.
+
+        Add a new API test to verify that inserting text in UIWebView causes the document to scroll.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitLegacy/ios/ScrollToRevealSelection.mm: Added.
+        (-[LegacyLoadingDelegate webViewDidFinishLoad:]):
+        (-[LegacyLoadingDelegate waitForDidFinishLoad]):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2019-07-22  Jer Noble  <[email protected]>
 
         REGRESSION(rUnknown): YouTube playback pauses when switching to a new tab

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (247701 => 247702)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-07-22 22:14:48 UTC (rev 247702)
@@ -928,6 +928,7 @@
 		F41AB9AA1EF4696B0083FA08 /* textarea-to-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F41AB9951EF4692C0083FA08 /* textarea-to-input.html */; };
 		F42D634422A1729F00D2FB3A /* AutocorrectionTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */; };
 		F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
+		F434CA1A22E65BCA005DDB26 /* ScrollToRevealSelection.mm in Sources */ = {isa = PBXBuildFile; fileRef = F434CA1922E65BCA005DDB26 /* ScrollToRevealSelection.mm */; };
 		F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */; };
 		F43E3BC120DADBC500A4E7ED /* fixed-nav-bar.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */; };
 		F442851D2140DF2900CCDA22 /* NSFontPanelTesting.mm in Sources */ = {isa = PBXBuildFile; fileRef = F442851C2140DF2900CCDA22 /* NSFontPanelTesting.mm */; };
@@ -2365,6 +2366,7 @@
 		F41AB99E1EF4692C0083FA08 /* div-and-large-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "div-and-large-image.html"; sourceTree = "<group>"; };
 		F42D634322A1729F00D2FB3A /* AutocorrectionTestsIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutocorrectionTestsIOS.mm; sourceTree = "<group>"; };
 		F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKitCocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
+		F434CA1922E65BCA005DDB26 /* ScrollToRevealSelection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = ScrollToRevealSelection.mm; path = ScrollToRevealSelection.mm; sourceTree = "<group>"; };
 		F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKScrollViewTests.mm; sourceTree = "<group>"; };
 		F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "fixed-nav-bar.html"; sourceTree = "<group>"; };
 		F442851B2140DF2900CCDA22 /* NSFontPanelTesting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFontPanelTesting.h; sourceTree = "<group>"; };
@@ -2566,8 +2568,8 @@
 				BC131AA8117131FC00B69727 /* TestsController.cpp */,
 				BCB9E7C711234E3A00A137E0 /* TestsController.h */,
 				7C83E0361D0A5F7000FEBCF3 /* Utilities.h */,
+				7CBD5A2222DE42A6004A9E32 /* WTFStringUtilities.cpp */,
 				44A622C114A0E2B60048515B /* WTFStringUtilities.h */,
-				7CBD5A2222DE42A6004A9E32 /* WTFStringUtilities.cpp */,
 			);
 			name = Source;
 			sourceTree = "<group>";
@@ -3907,6 +3909,7 @@
 				CDC8E4851BC5B19400594FEC /* AudioSessionCategoryIOS.mm */,
 				E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */,
 				CDC0932A21C872C10030C4B0 /* ScrollingDoesNotPauseMedia.mm */,
+				F434CA1922E65BCA005DDB26 /* ScrollToRevealSelection.mm */,
 				0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */,
 			);
 			path = ios;
@@ -4137,7 +4140,6 @@
 			files = (
 				7C83DE991D0A590C00FEBCF3 /* AtomString.cpp in Sources */,
 				1ADAD1501D77A9F600212586 /* BlockPtr.mm in Sources */,
-				7CBD5A2322DE42A6004A9E32 /* WTFStringUtilities.cpp in Sources */,
 				7C83DE9C1D0A590C00FEBCF3 /* BloomFilter.cpp in Sources */,
 				7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
 				0F30CB5C1FCE1796004B5323 /* ConcurrentPtrHashSet.cpp in Sources */,
@@ -4214,6 +4216,7 @@
 				37C7CC2D1EA4146B007BD956 /* WeakLinking.cpp in Sources */,
 				57C3FA661F7C248F009D4B80 /* WeakPtr.cpp in Sources */,
 				7C83DF631D0A590C00FEBCF3 /* WTFString.cpp in Sources */,
+				7CBD5A2322DE42A6004A9E32 /* WTFStringUtilities.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4293,7 +4296,6 @@
 				5C3B1D2622A74F6700BCF4D0 /* ContextMenus.mm in Sources */,
 				5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */,
 				51D1249B1E785425002B2820 /* CookieManager.cpp in Sources */,
-				7C74C8FA22DFBA9600DA2DAB /* WTFStringUtilities.cpp in Sources */,
 				5C19A5241FD0F60100EEA323 /* CookiePrivateBrowsing.mm in Sources */,
 				9B1F6F781F90558400B55744 /* CopyHTML.mm in Sources */,
 				9999108B1F393C96008AD455 /* Copying.mm in Sources */,
@@ -4553,6 +4555,7 @@
 				CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */,
 				CDC0932B21C872C10030C4B0 /* ScrollingDoesNotPauseMedia.mm in Sources */,
 				7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */,
+				F434CA1A22E65BCA005DDB26 /* ScrollToRevealSelection.mm in Sources */,
 				F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */,
 				0FF1134E22D68679009A81DA /* ScrollViewScrollabilityTests.mm in Sources */,
 				CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */,
@@ -4712,6 +4715,7 @@
 				93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */,
 				CD7F89DC22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm in Sources */,
 				9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */,
+				7C74C8FA22DFBA9600DA2DAB /* WTFStringUtilities.cpp in Sources */,
 				9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/ScrollToRevealSelection.mm (0 => 247702)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/ScrollToRevealSelection.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/ios/ScrollToRevealSelection.mm	2019-07-22 22:14:48 UTC (rev 247702)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+IGNORE_WARNINGS_BEGIN("deprecated-implementations")
+
+#import "PlatformUtilities.h"
+#import "UIKitSPI.h"
+#import <wtf/RetainPtr.h>
+
+@interface LegacyLoadingDelegate : NSObject <UIWebViewDelegate>
+- (void)waitForDidFinishLoad;
+@end
+
+@implementation LegacyLoadingDelegate {
+    BOOL _loadComplete;
+}
+
+- (void)webViewDidFinishLoad:(UIWebView *)webView
+{
+    _loadComplete = YES;
+}
+
+- (void)waitForDidFinishLoad
+{
+    EXPECT_FALSE(_loadComplete);
+    TestWebKitAPI::Util::run(&_loadComplete);
+}
+
+@end
+
+TEST(WebKitLegacy, ScrollToRevealSelection)
+{
+    auto window = adoptNS([[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [window setHidden:NO];
+    auto webView = adoptNS([[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [window addSubview:webView.get()];
+    auto delegate = adoptNS([[LegacyLoadingDelegate alloc] init]);
+    [webView setDelegate:delegate.get()];
+    [webView loadHTMLString:@"<meta name='viewport' content='width=device-width, initial-scale=1'><body style='font-size: 100px;' contenteditable>" baseURL:nil];
+    [delegate waitForDidFinishLoad];
+    [webView stringByEvaluatingJavaScriptFromString:@"document.body.focus()"];
+    for (int i = 0; i < 10; ++i)
+        [[webView _browserView] insertText:@"\n"];
+
+    EXPECT_GT([[webView scrollView] contentOffset].y, 0);
+}
+
+IGNORE_WARNINGS_END
+
+#endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (247701 => 247702)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-07-22 22:02:58 UTC (rev 247701)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2019-07-22 22:14:48 UTC (rev 247702)
@@ -42,6 +42,11 @@
 #import <UIKit/UIWKTextInteractionAssistant.h>
 #import <UIKit/UIWebFormAccessory.h>
 
+IGNORE_WARNINGS_BEGIN("deprecated-implementations")
+#import <UIKit/UIWebBrowserView.h>
+#import <UIKit/UIWebView_Private.h>
+IGNORE_WARNINGS_END
+
 #if PLATFORM(IOS)
 @protocol UIDragSession;
 @class UIDragInteraction;
@@ -155,6 +160,17 @@
 - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
 @end
 
+IGNORE_WARNINGS_BEGIN("deprecated-implementations")
+
+@interface UIWebBrowserView : UIView <UIKeyInput>
+@end
+
+@interface UIWebView (Private)
+- (UIWebBrowserView *)_browserView;
+@end
+
+IGNORE_WARNINGS_END
+
 #endif
 
 #if __has_include(<UIKit/UITextAutofillSuggestion.h>)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to