WebKit Bugzilla
Attachment 369094 Details for
Bug 197601
: [iOS] Add SPI to disable zooming when focusing an element
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-197601-20190505145434.patch (text/plain), 9.31 KB, created by
Wenson Hsieh
on 2019-05-05 14:54:35 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2019-05-05 14:54:35 PDT
Size:
9.31 KB
patch
obsolete
>Subversion Revision: 244950 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 270fa0792317a5e33012e9c8f67ad76b2beaa59e..0a93b3b7f06dd9d56a86796afbe827688d914772 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,18 @@ >+2019-05-05 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Add SPI to disable zooming when focusing an element >+ https://bugs.webkit.org/show_bug.cgi?id=197601 >+ <rdar://problem/50482558> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adds an input delegate hook to allow clients to prevent zooming when focusing an element. If unimplemented, the >+ default behavior is to zoom in on the focused element. >+ >+ * UIProcess/API/Cocoa/_WKInputDelegate.h: >+ * UIProcess/ios/WKContentViewInteraction.mm: >+ (-[WKContentView _zoomToRevealFocusedElement]): >+ > 2019-05-03 Wenson Hsieh <wenson_hsieh@apple.com> > > REGRESSION (r244897): Caret may appear wider than normal after zooming to focus an editable element >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h b/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h >index 1665279d366ebb20fdcb56d2861126f4a317d14b..c6beb69d99d5e7fb01736cf113d3dc3a7cf019a0 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h >@@ -56,6 +56,7 @@ typedef NS_ENUM(NSInteger, _WKFocusStartsInputSessionPolicy) { > - (BOOL)_webView:(WKWebView *)webView focusRequiresStrongPasswordAssistance:(id <_WKFocusedElementInfo>)info WK_API_AVAILABLE(ios(12.0)); > > - (BOOL)_webView:(WKWebView *)webView shouldRevealFocusOverlayForInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0)); >+- (BOOL)_webView:(WKWebView *)webView shouldZoomToRevealFocusedElementForInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(WK_IOS_TBA)); > - (CGFloat)_webView:(WKWebView *)webView focusedElementContextViewHeightForFittingSize:(CGSize)fittingSize inputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0)); > - (UIView *)_webView:(WKWebView *)webView focusedElementContextViewForInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0)); > #endif >diff --git a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >index 12e8f3da0113f288e7df4e77836dd11c0dba9278..33ba90ec4356cb37d063b8e311780cfaaad175d3 100644 >--- a/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >+++ b/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm >@@ -1664,6 +1664,10 @@ - (void)_zoomToRevealFocusedElement > if (_suppressSelectionAssistantReasons.contains(WebKit::EditableRootIsTransparentOrFullyClipped) || _suppressSelectionAssistantReasons.contains(WebKit::FocusedElementIsTooSmall)) > return; > >+ id <_WKInputDelegate> delegate = _webView._inputDelegate; >+ if ([delegate respondsToSelector:@selector(_webView:shouldZoomToRevealFocusedElementForInputSession:)] && ![delegate _webView:_webView shouldZoomToRevealFocusedElementForInputSession:_formInputSession.get()]) >+ return; >+ > // In case user scaling is force enabled, do not use that scaling when zooming in with an input field. > // Zooming above the page's default scale factor should only happen when the user performs it. > [self _zoomToFocusRect:_focusedElementInformation.elementRect >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 6e7f334be51dc7daa02149745ad5c6173690aafe..3b6b2c3394c02022052eb13abcf1082c862c70c3 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,20 @@ >+2019-05-05 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Add SPI to disable zooming when focusing an element >+ https://bugs.webkit.org/show_bug.cgi?id=197601 >+ <rdar://problem/50482558> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a test to exercise the new SPI. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/_WKInputDelegate.mm: >+ * TestWebKitAPI/Tests/ios/TestInputDelegate.h: >+ * TestWebKitAPI/Tests/ios/TestInputDelegate.mm: >+ (-[TestInputDelegate setShouldZoomToRevealFocusedElementHandler:]): >+ (-[TestInputDelegate shouldZoomToRevealFocusedElementHandler]): >+ (-[TestInputDelegate _webView:shouldZoomToRevealFocusedElementForInputSession:]): >+ > 2019-05-03 Wenson Hsieh <wenson_hsieh@apple.com> > > REGRESSION (r244897): Caret may appear wider than normal after zooming to focus an editable element >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInputDelegate.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInputDelegate.mm >index b6165cddba6d6b64712484b7e4d1734c2328f7f5..fe598d3681911e1fc69e7cb02fe9909082835912 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInputDelegate.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKInputDelegate.mm >@@ -27,6 +27,7 @@ > > #import "PlatformUtilities.h" > #import "Test.h" >+#import "TestInputDelegate.h" > #import "TestWKWebView.h" > #import <WebKit/WKWebViewPrivate.h> > #import <WebKit/_WKFocusedElementInfo.h> >@@ -142,6 +143,29 @@ TEST(WebKit, FocusedElementInfo) > EXPECT_WK_STREQ("garply", [currentElement label]); > } > >-#endif // PLATFORM(IOS_FAMILY) >+TEST(WebKit, PreventZoomingToFocusedElement) >+{ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); >+ auto delegate = adoptNS([[TestInputDelegate alloc] init]); >+ [delegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id<_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy { >+ return _WKFocusStartsInputSessionPolicyAllow; >+ }]; >+ [delegate setShouldZoomToRevealFocusedElementHandler:^BOOL(WKWebView *, id<_WKFormInputSession>) { >+ return NO; >+ }]; >+ [webView _setInputDelegate:delegate.get()]; >+ [webView synchronouslyLoadHTMLString:@"<textarea></textarea>"]; >+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.querySelector('textarea').focus()"]; >+ [webView waitForNextPresentationUpdate]; >+ EXPECT_LT([webView scrollView].zoomScale, 1); > >+ [delegate setShouldZoomToRevealFocusedElementHandler:^BOOL(WKWebView *, id<_WKFormInputSession>) { >+ return YES; >+ }]; >+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.querySelector('textarea').blur()"]; >+ [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.querySelector('textarea').focus()"]; >+ [webView waitForNextPresentationUpdate]; >+ EXPECT_GT([webView scrollView].zoomScale, 1); >+} > >+#endif // PLATFORM(IOS_FAMILY) >diff --git a/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h b/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h >index fadb4469590d2c405b893284e8ae1e0539962726..cbaacd355f4ca21fed9990aae26ac46a00030066 100644 >--- a/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h >+++ b/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h >@@ -36,6 +36,7 @@ > @interface TestInputDelegate : NSObject <_WKInputDelegate> > @property (nonatomic, copy) _WKFocusStartsInputSessionPolicy (^focusStartsInputSessionPolicyHandler)(WKWebView *, id <_WKFocusedElementInfo>); > @property (nonatomic, copy) void (^willStartInputSessionHandler)(WKWebView *, id <_WKFormInputSession>); >+@property (nonatomic, copy) BOOL (^shouldZoomToRevealFocusedElementHandler)(WKWebView *, id <_WKFormInputSession>); > @end > > #endif >diff --git a/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm b/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm >index 124d82c67d202271c2ea0cfe6320267cad72aee2..704b2542b1e1e5b788eb67f9a18bee1ad18eb6f1 100644 >--- a/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm >+++ b/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm >@@ -33,6 +33,7 @@ > @implementation TestInputDelegate { > BlockPtr<_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>)> _focusStartsInputSessionPolicyHandler; > BlockPtr<void(WKWebView *, id <_WKFormInputSession>)> _willStartInputSessionHandler; >+ BlockPtr<BOOL(WKWebView *, id <_WKFormInputSession>)> _shouldZoomToRevealFocusedElementHandler; > } > > - (void)setFocusStartsInputSessionPolicyHandler:(_WKFocusStartsInputSessionPolicy (^)(WKWebView *, id <_WKFocusedElementInfo>))handler >@@ -55,6 +56,16 @@ - (void (^)(WKWebView *, id<_WKFormInputSession>))willStartInputSessionHandler > return _willStartInputSessionHandler.get(); > } > >+- (void)setShouldZoomToRevealFocusedElementHandler:(BOOL (^)(WKWebView *, id<_WKFormInputSession>))shouldZoomToRevealFocusedElementHandler >+{ >+ _shouldZoomToRevealFocusedElementHandler = shouldZoomToRevealFocusedElementHandler; >+} >+ >+- (BOOL (^)(WKWebView *, id<_WKFormInputSession>))shouldZoomToRevealFocusedElementHandler >+{ >+ return _shouldZoomToRevealFocusedElementHandler.get(); >+} >+ > - (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info > { > return self.focusStartsInputSessionPolicyHandler ? self.focusStartsInputSessionPolicyHandler(webView, info) : _WKFocusStartsInputSessionPolicyAuto; >@@ -66,6 +77,13 @@ - (void)_webView:(WKWebView *)webView willStartInputSession:(id<_WKFormInputSess > _willStartInputSessionHandler(webView, inputSession); > } > >+- (BOOL)_webView:(WKWebView *)webView shouldZoomToRevealFocusedElementForInputSession:(id <_WKFormInputSession>)inputSession >+{ >+ if (_shouldZoomToRevealFocusedElementHandler) >+ return _shouldZoomToRevealFocusedElementHandler(webView, inputSession); >+ return YES; >+} >+ > @end > > #endif // PLATFORM(IOS_FAMILY)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197601
:
369094