Changeset 258821 in webkit
- Timestamp:
- Mar 22, 2020 12:29:40 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r258814 r258821 1 2020-03-22 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Adopt -[UIWindowScene interfaceOrientation] when determining device orientation 4 https://bugs.webkit.org/show_bug.cgi?id=209372 5 <rdar://problem/60491857> 6 7 Reviewed by Darin Adler. 8 9 Currently, for WebKit clients that have adopted the UIScene lifecycle (and also do not set an interface 10 orientation override, like MobileSafari does), device orientation APIs will always report that the device is in 11 portrait mode, regardless of the actual device orientation. This is because our current mechanism for tracking 12 device orientation asks the shared UIApplication for its -statusBarOrientation. This is hard-coded to always 13 return UIInterfaceOrientationPortrait for apps that adopt the UIScene lifecycle, and will additionally trigger a 14 simulated crash, explaining that it is invalid for any scene-based app to call -statusBarOrientation. 15 16 To fix this, we adjust the `deviceOrientation` helper in WKWebViewIOS.mm to work for scene-based apps. See below 17 for more details. 18 19 * Platform/spi/ios/UIKitSPI.h: 20 * UIProcess/API/ios/WKWebViewIOS.h: 21 * UIProcess/API/ios/WKWebViewIOS.mm: 22 (-[WKWebView _setupScrollAndContentViews]): 23 24 Change call sites of `deviceOrientation()` to be `[self _deviceOrientation]` instead. 25 26 (-[WKWebView _deviceOrientation]): 27 28 Replace `deviceOrientation()` with a `_deviceOrientation` helper method on `WKWebView`. For non-scene-based 29 apps, this new helper method does not change any behavior, and continues to go through UIApplication. However, 30 for scene-based apps, we instead ask the web view's window's `UIWindowScene` for its interface orientation. 31 32 Importantly, this means that if a WKWebView is not parented, it doesn't have a valid device orientation (i.e. 33 the orientation is UIInterfaceOrientationUnknown). As such, a newly created WKWebView that is unparented will 34 start out with no orientation; it's only upon moving the view into a window that it is able to determine the 35 device orientation. To ensure this, we add logic to -didMoveToWindow to recompute device orientation and 36 dispatch an update if needed. 37 38 To avoid sending unnecessary updates, if a WKWebView is unparented, we wait until it's parented again to send 39 the new device orientation. 40 41 (-[WKWebView didMoveToWindow]): 42 (-[WKWebView _windowDidRotate:]): 43 (deviceOrientation): Deleted. 44 45 See -[WKWebView _deviceOrientation] above. 46 1 47 2020-03-21 David Kilzer <ddkilzer@apple.com> 2 48 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r258767 r258821 195 195 - (void)_handleHIDEvent:(IOHIDEventRef)event; 196 196 - (void)handleKeyUIEvent:(UIEvent *)event; 197 - (BOOL)_appAdoptsUISceneLifecycle; 197 198 @end 198 199 -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.h
r254315 r258821 136 136 @property (nonatomic, readonly) UIEdgeInsets _computedUnobscuredSafeAreaInset; 137 137 @property (nonatomic, readonly, getter=_isRetainingActiveFocusedState) BOOL _retainingActiveFocusedState; 138 @property (nonatomic, readonly) int32_t _deviceOrientation; 138 139 139 140 - (BOOL)_effectiveAppearanceIsDark; … … 142 143 @end 143 144 144 int32_t deviceOrientation();145 146 145 #endif // PLATFORM(IOS_FAMILY) -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
r258148 r258821 89 89 } 90 90 91 int32_t deviceOrientation()92 {93 ALLOW_DEPRECATED_DECLARATIONS_BEGIN94 return deviceOrientationForUIInterfaceOrientation([[UIApplication sharedApplication] statusBarOrientation]);95 ALLOW_DEPRECATED_DECLARATIONS_END96 }97 98 91 @interface UIView (UIViewInternal) 99 92 - (UIViewController *)_viewControllerForAncestor; … … 158 151 [self addSubview:_scrollView.get()]; 159 152 160 [self _dispatchSetDeviceOrientation: deviceOrientation()];153 [self _dispatchSetDeviceOrientation:[self _deviceOrientation]]; 161 154 162 155 [_contentView layer].anchorPoint = CGPointZero; … … 229 222 // -_decrementFocusPreservationCount after resetting the count to 0. 230 223 return _focusPreservationCount || _activeFocusedStateRetainCount; 224 } 225 226 - (int32_t)_deviceOrientation 227 { 228 auto orientation = UIInterfaceOrientationUnknown; 229 auto application = UIApplication.sharedApplication; 230 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 231 if (!application._appAdoptsUISceneLifecycle) 232 orientation = application.statusBarOrientation; 233 ALLOW_DEPRECATED_DECLARATIONS_END 234 else if (auto windowScene = self.window.windowScene) 235 orientation = windowScene.interfaceOrientation; 236 return deviceOrientationForUIInterfaceOrientation(orientation); 231 237 } 232 238 … … 1396 1402 - (void)didMoveToWindow 1397 1403 { 1404 if (!_overridesInterfaceOrientation) 1405 [self _dispatchSetDeviceOrientation:[self _deviceOrientation]]; 1398 1406 _page->activityStateDidChange(WebCore::ActivityState::allFlags()); 1399 1407 _page->webViewDidMoveToWindow(); … … 2242 2250 { 2243 2251 if (!_overridesInterfaceOrientation) 2244 [self _dispatchSetDeviceOrientation: deviceOrientation()];2252 [self _dispatchSetDeviceOrientation:[self _deviceOrientation]]; 2245 2253 } 2246 2254
Note: See TracChangeset
for help on using the changeset viewer.