Skip to content

Commit 46c5871

Browse files
pxlcodermnutt
authored andcommitted
[visionOS] Hide ornaments when entering fullscreen
https://bugs.webkit.org/show_bug.cgi?id=258786 rdar://111453364 Reviewed by Tim Horton. Ornaments are smaller pieces of UI associated with a particular window scene. When performing the fullscreen transition, these pieces of UI should be hidden alongside the presenting window. * Source/WebKit/Platform/spi/visionos/MRUIKitSPI.h: * Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm: (-[WKFullScreenParentWindowState initWithWindow:]): Store the original depth of ornaments to restore their depth after exiting fullscreen. (-[WKFullScreenParentWindowState ornamentDepths]): (-[WKFullScreenWindowController _performSpatialFullScreenTransition:completionHandler:]): Animate the ornaments as if they were a part of the presenting window, matching the fade and depth animations. Canonical link: https://commits.webkit.org/265733@main
1 parent 4dd9ed5 commit 46c5871

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

Source/WebKit/Platform/spi/visionos/MRUIKitSPI.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,19 @@ typedef void (^MRUIWindowSceneResizeRequestCompletion)(CGSize grantedSize, NSErr
8686

8787
#endif // USE(APPLE_INTERNAL_SDK)
8888

89+
// FIXME: <rdar://111655142> Import ornaments SPI using framework headers.
90+
91+
@interface MRUIPlatterOrnament : NSObject
92+
@property (nonatomic, assign, getter=_depthDisplacement, setter=_setDepthDisplacement:) CGFloat depthDisplacement;
93+
@end
94+
95+
@interface MRUIPlatterOrnamentManager : NSObject
96+
@property (nonatomic, readonly) NSArray<MRUIPlatterOrnament *> *ornaments;
97+
@end
98+
99+
@interface UIWindowScene (MRUIPlatterOrnaments)
100+
@property (nonatomic, readonly) MRUIPlatterOrnamentManager *_mrui_platterOrnamentManager;
101+
@property (nonatomic, readwrite) BOOL prefersOrnamentsHidden_forLMKOnly;
102+
@end
103+
89104
#endif // PLATFORM(VISION)

Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,11 @@ void store(WKWebView* webView)
193193
static constexpr CGFloat kFullScreenWindowCornerRadius = 12;
194194
static constexpr CGFloat kDarknessAnimationDuration = 0.6;
195195
static constexpr CGFloat kOutgoingWindowFadeDuration = 0.4;
196-
static constexpr CGFloat kOutgoingWindowTranslationDuration = 0.6;
197196
static constexpr CGFloat kOutgoingWindowZOffset = -150;
198197
static constexpr CGFloat kIncomingWindowFadeDuration = 0.6;
199198
static constexpr CGFloat kIncomingWindowFadeDelay = 0.2;
200-
static constexpr CGFloat kIncomingWindowTranslationDuration = 0.6;
201199
static constexpr CGFloat kIncomingWindowZOffset = -170;
200+
static constexpr CGFloat kWindowTranslationDuration = 0.6;
202201
static constexpr NSString *kPrefersFullScreenDimmingKey = @"WebKitPrefersFullScreenDimming";
203202
#endif
204203

@@ -476,12 +475,17 @@ @interface WKFullScreenParentWindowState : NSObject
476475
@property (nonatomic, readonly) RSSSceneChromeOptions sceneChromeOptions;
477476
@property (nonatomic, readonly) MRUISceneResizingBehavior sceneResizingBehavior;
478477
@property (nonatomic, readonly) MRUIDarknessPreference preferredDarkness;
478+
@property (nonatomic, readonly) BOOL prefersOrnamentsHidden;
479+
480+
@property (nonatomic, readonly) NSMapTable<MRUIPlatterOrnament *, NSNumber *> *ornamentDepths;
479481

480482
- (id)initWithWindow:(UIWindow *)window;
481483

482484
@end
483485

484-
@implementation WKFullScreenParentWindowState
486+
@implementation WKFullScreenParentWindowState {
487+
RetainPtr<NSMapTable<MRUIPlatterOrnament *, NSNumber *>> _ornamentDepths;
488+
}
485489

486490
- (id)initWithWindow:(UIWindow *)window
487491
{
@@ -490,14 +494,28 @@ - (id)initWithWindow:(UIWindow *)window
490494

491495
_transform3D = window.transform3D;
492496
_windowClass = object_getClass(window);
493-
_sceneMinimumSize = window.windowScene.sizeRestrictions.minimumSize;
494-
_sceneChromeOptions = window.windowScene.mrui_placement.preferredChromeOptions;
495-
_sceneResizingBehavior = window.windowScene.mrui_placement.preferredResizingBehavior;
496497
_preferredDarkness = UIApplication.sharedApplication.mrui_activeStage.preferredDarkness;
497498

499+
UIWindowScene *windowScene = window.windowScene;
500+
_sceneMinimumSize = windowScene.sizeRestrictions.minimumSize;
501+
_sceneChromeOptions = windowScene.mrui_placement.preferredChromeOptions;
502+
_sceneResizingBehavior = windowScene.mrui_placement.preferredResizingBehavior;
503+
_prefersOrnamentsHidden = windowScene.prefersOrnamentsHidden_forLMKOnly;
504+
505+
_ornamentDepths = [NSMapTable weakToStrongObjectsMapTable];
506+
507+
MRUIPlatterOrnamentManager *ornamentManager = windowScene._mrui_platterOrnamentManager;
508+
for (MRUIPlatterOrnament *ornament in ornamentManager.ornaments)
509+
[_ornamentDepths setObject:@(ornament._depthDisplacement) forKey:ornament];
510+
498511
return self;
499512
}
500513

514+
- (NSMapTable<MRUIPlatterOrnament *, NSNumber *> *)ornamentDepths
515+
{
516+
return _ornamentDepths.get();
517+
}
518+
501519
@end
502520

503521
@interface WKFullscreenWindowSceneDelegate : NSObject <MRUIWindowSceneDelegate>
@@ -1557,16 +1575,31 @@ - (void)_performSpatialFullScreenTransition:(BOOL)enter completionHandler:(Compl
15571575

15581576
[UIView animateWithDuration:kOutgoingWindowFadeDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
15591577
outWindow.alpha = 0;
1578+
if (enter)
1579+
outWindow.windowScene.prefersOrnamentsHidden_forLMKOnly = YES;
15601580
} completion:nil];
15611581

1562-
[UIView animateWithDuration:kOutgoingWindowTranslationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
1582+
[UIView animateWithDuration:kWindowTranslationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
15631583
outWindow.transform3D = CATransform3DTranslate(outWindow.transform3D, 0, 0, kOutgoingWindowZOffset);
15641584
} completion:nil];
15651585

1566-
[UIView animateWithDuration:kIncomingWindowTranslationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
1586+
[UIView animateWithDuration:kWindowTranslationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
15671587
inWindow.transform3D = originalState.transform3D;
15681588
} completion:nil];
15691589

1590+
for (MRUIPlatterOrnament *ornament in originalState.ornamentDepths) {
1591+
CGFloat originalDepth = [[originalState.ornamentDepths objectForKey:ornament] floatValue];
1592+
CGFloat finalDepth = originalDepth;
1593+
if (enter)
1594+
finalDepth += kOutgoingWindowZOffset;
1595+
else
1596+
[ornament _setDepthDisplacement:originalDepth + kIncomingWindowZOffset];
1597+
1598+
[UIView animateWithDuration:kWindowTranslationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
1599+
[ornament _setDepthDisplacement:finalDepth];
1600+
} completion:nil];
1601+
}
1602+
15701603
auto completion = makeBlockPtr([controller = retainPtr(controller), inWindow = retainPtr(inWindow), originalState = retainPtr(originalState), enter, completionHandler = WTFMove(completionHandler)] (BOOL finished) mutable {
15711604
WebKit::resizeScene([inWindow windowScene], [inWindow bounds].size, [controller, inWindow, originalState, enter, completionHandler = WTFMove(completionHandler)]() mutable {
15721605
Class inWindowClass = enter ? [UIWindow class] : [originalState windowClass];
@@ -1594,6 +1627,8 @@ - (void)_performSpatialFullScreenTransition:(BOOL)enter completionHandler:(Compl
15941627

15951628
[UIView animateWithDuration:kIncomingWindowFadeDuration delay:kIncomingWindowFadeDelay options:UIViewAnimationOptionCurveEaseInOut animations:^{
15961629
inWindow.alpha = 1;
1630+
if (!enter)
1631+
inWindow.windowScene.prefersOrnamentsHidden_forLMKOnly = originalState.prefersOrnamentsHidden;
15971632
} completion:completion.get()];
15981633
}
15991634

0 commit comments

Comments
 (0)