Skip to content

Commit

Permalink
Merge pull request #450 from ehren/tablet-uimodalpresentationformsheet
Browse files Browse the repository at this point in the history
WOCOperationMode should change UIUserInterfaceIdiom. Support UIModalPresentationFormSheet on tablets (non-fullscreen presentation)
  • Loading branch information
Ramu-msft committed May 2, 2016
2 parents 3392f5c + 4b2c9f9 commit 29cda07
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 101 deletions.
32 changes: 0 additions & 32 deletions Frameworks/StarboardXaml/ApplicationMain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@ void SetCACompositorClient(CACompositorClientInterface* client) {
_compositorClient = client;
}

struct ApplicationProperties {
float width;
float height;
float scale;
std::string name;
bool isTablet;
bool isLandscape;
};

ApplicationProperties g_applicationProperties;

std::string GetAppNameFromPList() {
NSString* appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
if (appName != nil) {
return [appName UTF8String];
}

return "Starboard";
}

int ApplicationMainStart(
int argc, char* argv[], const char* principalName, const char* delegateName, float windowWidth, float windowHeight) {
// Note: We must use nil rather than an empty string for these class names
Expand All @@ -68,11 +48,6 @@ int ApplicationMainStart(
WOCDisplayMode* displayMode = [UIApplication displayMode];
[displayMode _setWindowSize:CGSizeMake(windowWidth, windowHeight)];

float defaultWidth = GetCACompositor()->screenWidth();
float defaultHeight = GetCACompositor()->screenHeight();
float defaultScale = GetCACompositor()->screenScale();
bool defaultTablet = false;

[NSBundle setMainBundlePath:@"."];

NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
Expand Down Expand Up @@ -124,14 +99,7 @@ int ApplicationMainStart(
[UIApplication setStartupDisplayMode:displayMode];
}

g_applicationProperties.width = defaultWidth;
g_applicationProperties.height = defaultHeight;
g_applicationProperties.scale = defaultScale;
g_applicationProperties.name = GetAppNameFromPList();
g_applicationProperties.isTablet = defaultTablet;

[displayMode _updateDisplaySettings];
GetCACompositor()->setTablet(g_applicationProperties.isTablet);

UIApplicationMainInit(argc, argv, principalClassName, delegateClassName, defaultOrientation);
return UIApplicationMainLoop();
Expand Down
1 change: 1 addition & 0 deletions Frameworks/UIKit/UIApplication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,7 @@ - (void)_updateDisplaySettings {
break;
}

GetCACompositor()->setTablet(_operationMode == WOCOperationModeTablet);
GetCACompositor()->setScreenSize(newWidth, newHeight, newMagnification, newRotation);
GetCACompositor()->setDeviceSize(newWidth, newHeight);

Expand Down
125 changes: 63 additions & 62 deletions Frameworks/UIKit/UIViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,8 @@ - (CGRect)_orientationRect:(UIInterfaceOrientation)orientation {

appFrame = [[UIScreen mainScreen] applicationFrame];

if (priv->_presentationStyle == UIModalPresentationFormSheet) {
CGRect screenFrame;
screenFrame = [[UIScreen mainScreen] applicationFrame];

appFrame.size.width = 540;
appFrame.size.height = 575;

appFrame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - appFrame.size.width / 2.0f;
appFrame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - appFrame.size.height / 2.0f;
if ([self modalPresentationStyle] == UIModalPresentationFormSheet) {
appFrame = [self _modalPresentationFormSheetFrame];
}

CGRect rect;
Expand Down Expand Up @@ -386,6 +379,35 @@ - (CGRect)_orientationRect:(UIInterfaceOrientation)orientation {
return rect;
}

- (CGRect)_modalPresentationFormSheetFrame {
if (!GetCACompositor()->isTablet()) {
// fullscreen on non-tablets
return [[UIScreen mainScreen] applicationFrame];
}

CGRect frame;
if (!CGSizeEqualToSize([self preferredContentSize], CGSizeZero)) {
frame.size = [self preferredContentSize];
} else {
frame.size.width = 540;
frame.size.height = 620;
}

CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
frame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - frame.size.width / 2.0f;
frame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - frame.size.height / 2.0f;

return frame;
}

- (BOOL)_hidesParent {
if ([self modalPresentationStyle] == UIModalPresentationFormSheet && GetCACompositor()->isTablet()) {
return NO;
}

return YES;
}

- (void)_setResizeToScreen:(BOOL)resize {
priv->_resizeToScreen = TRUE;
}
Expand All @@ -402,20 +424,13 @@ - (void)setOrientationInternal:(UIInterfaceOrientation)orientation animated:(BOO

[[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:FALSE];

if (priv->_wantsFullScreenLayout) {
if ([self wantsFullScreenLayout]) {
appFrame = [[UIScreen mainScreen] bounds];
} else {
appFrame = [[UIScreen mainScreen] applicationFrame];
}
if (priv->_presentationStyle == UIModalPresentationFormSheet) {
CGRect screenFrame;
screenFrame = [[UIScreen mainScreen] applicationFrame];

appFrame.size.width = GetCACompositor()->screenWidth();
appFrame.size.height = GetCACompositor()->screenHeight();

appFrame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - appFrame.size.width / 2.0f;
appFrame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - appFrame.size.height / 2.0f;
if ([self modalPresentationStyle] == UIModalPresentationFormSheet) {
appFrame = [self _modalPresentationFormSheetFrame];
}

switch (orientation) {
Expand Down Expand Up @@ -786,15 +801,8 @@ - (void)loadView {
CGRect frame = { 0.0f, 0.0f, GetCACompositor()->screenWidth(), GetCACompositor()->screenHeight() };

frame = [[UIScreen mainScreen] applicationFrame]; /** This is correct **/
if (priv->_presentationStyle == UIModalPresentationFormSheet) {
CGRect screenFrame;
screenFrame = [[UIScreen mainScreen] applicationFrame];

frame.size.width = 540;
frame.size.height = 575;

frame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - frame.size.width / 2.0f;
frame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - frame.size.height / 2.0f;
if ([self modalPresentationStyle] == UIModalPresentationFormSheet) {
frame = [self _modalPresentationFormSheetFrame];
}

UIView* view = [[[UIEmptyController alloc] initWithFrame:frame] autorelease];
Expand All @@ -807,24 +815,17 @@ - (void)loadView {
}

- (void)_doResizeToScreen {
if ((priv->_resizeToScreen && priv->view && priv->_autoresize) || priv->_wantsFullScreenLayout) {
if ((priv->_resizeToScreen && priv->view && priv->_autoresize) || [self wantsFullScreenLayout]) {
CGRect frame = { 0.0f, 0.0f, GetCACompositor()->screenHeight(), GetCACompositor()->screenWidth() };

if (priv->_wantsFullScreenLayout) {
if ([self wantsFullScreenLayout]) {
frame = [[UIScreen mainScreen] bounds];
} else {
frame = [[UIScreen mainScreen] applicationFrame];
}

if (priv->_presentationStyle == UIModalPresentationFormSheet) {
CGRect screenFrame;
screenFrame = [[UIScreen mainScreen] applicationFrame];

frame.size.width = 540;
frame.size.height = 575;

frame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - frame.size.width / 2.0f;
frame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - frame.size.height / 2.0f;
if ([self modalPresentationStyle] == UIModalPresentationFormSheet) {
frame = [self _modalPresentationFormSheetFrame];
}
UIInterfaceOrientation curOrientation = (UIInterfaceOrientation)[[UIApplication sharedApplication] statusBarOrientation];

Expand Down Expand Up @@ -857,15 +858,8 @@ - (UIView*)view {
CGRect frame = { 0.0f, 0.0f, GetCACompositor()->screenHeight(), GetCACompositor()->screenWidth() };

frame = [[UIScreen mainScreen] applicationFrame];
if (priv->_presentationStyle == UIModalPresentationFormSheet) {
CGRect screenFrame;
screenFrame = [[UIScreen mainScreen] applicationFrame];

frame.size.width = 540;
frame.size.height = 575;

frame.origin.x = screenFrame.origin.x + screenFrame.size.width / 2.0f - frame.size.width / 2.0f;
frame.origin.y = screenFrame.origin.y + screenFrame.size.height / 2.0f - frame.size.height / 2.0f;
if ([self modalPresentationStyle] == UIModalPresentationFormSheet) {
frame = [self _modalPresentationFormSheetFrame];
}

UIView* view = [[[UIEmptyController alloc] initWithFrame:frame] autorelease];
Expand Down Expand Up @@ -1046,7 +1040,7 @@ - (void)presentViewController:(UIViewController*)controller animated:(BOOL)anima
if (curController->priv->_visibility != controllerNotVisible) {
shouldShow = true;
}
curController = curController->priv->_parentViewController;
curController = [curController parentViewController];
}
if (!shouldShow) {
TraceWarning(TAG, L"Controller is not visible!");
Expand All @@ -1069,7 +1063,9 @@ - (void)presentViewController:(UIViewController*)controller animated:(BOOL)anima
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
}

[self _notifyViewWillDisappear:animated];
if ([controller _hidesParent]) {
[self _notifyViewWillDisappear:animated];
}

priv->_modalViewController = controller;
priv->_presentedViewController = controller;
Expand Down Expand Up @@ -1129,8 +1125,8 @@ - (void)_dismissTransitionStopped:(id)anim finished:(BOOL)finished {
*/
- (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion {
if (priv->_modalViewController == nil) {
if (priv->_parentViewController) {
[priv->_parentViewController dismissViewControllerAnimated:animated completion:completion];
if ([self parentViewController] != nil) {
[[self parentViewController] dismissViewControllerAnimated:animated completion:completion];
return;
}
TraceWarning(TAG, L"dismissModalViewController invalid!");
Expand Down Expand Up @@ -1225,7 +1221,9 @@ - (void)_notifyDidAppearAnimated:(UIView*)view {
- (void)_transitionStopped:(id)context {
UIView* view = [self view];

[[priv->_parentViewController view] setHidden:TRUE];
if ([self _hidesParent]) {
[[[self parentViewController] view] setHidden:TRUE];
}
[self _notifyDidAppearAnimated:view];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
Expand All @@ -1235,18 +1233,18 @@ - (void)_addToTop:(NSNumber*)animatedValue {

priv->_isRootView = true;

if (priv->_parentViewController != nil) {
if ([self parentViewController] != nil) {
// TODO: This implementation satisfies the contract that the popoverPresentationController is not nil when presenting a
// UIViewController with modalPresentationType equal to UIModalPresentationPopover.
// The full implementation will need to utilize the UIPresentationController for UIViewController presentations
if (priv->_presentationStyle == UIModalPresentationPopover) {
if ([self modalPresentationStyle] == UIModalPresentationPopover) {
if (priv->_popoverPresentationController != nil) {
[priv->_popoverPresentationController release];
}

priv->_popoverPresentationController =
[[UIPopoverPresentationController alloc] initWithPresentedViewController:self
presentingViewController:priv->_parentViewController];
presentingViewController:[self parentViewController]];

if (priv->_presentationController != nil) {
[priv->_presentationController release];
Expand All @@ -1258,14 +1256,14 @@ - (void)_addToTop:(NSNumber*)animatedValue {
float endY = 0;

UIView* view = [self view];
UIWindow* parentWindow = [[priv->_parentViewController view] window];
UIWindow* parentWindow = [[[self parentViewController] view] window];

if (animated) {
g_presentingAnimated = TRUE;
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self _notifyViewWillAppear:TRUE];
} else {
[[priv->_parentViewController view] setHidden:TRUE];
} else if ([self _hidesParent]) {
[[[self parentViewController] view] setHidden:TRUE];
}

if (parentWindow != nil) {
Expand Down Expand Up @@ -1331,7 +1329,9 @@ - (void)_addToTop:(NSNumber*)animatedValue {
g_presentingAnimated = FALSE;
}

[priv->_parentViewController _notifyViewDidDisappear:animated];
if ([self _hidesParent]) {
[[self parentViewController] _notifyViewDidDisappear:animated];
}
} else {
TraceVerbose(TAG, L"Modal controller doesn't have a parent!");
}
Expand Down Expand Up @@ -1371,8 +1371,9 @@ - (BOOL)isModalInPopover {

static UIInterfaceOrientation findOrientation(UIViewController* self) {
UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[UIDevice currentDevice] orientation];
if (self->priv->_parentViewController != nil && [self->priv->_parentViewController _rotationLocked:orientation]) {
UIInterfaceOrientation parentOrientation = (UIInterfaceOrientation)[self->priv->_parentViewController interfaceOrientation];
UIViewController* parent = [self parentViewController];
if (parent != nil && [parent _rotationLocked:orientation]) {
UIInterfaceOrientation parentOrientation = (UIInterfaceOrientation)[parent interfaceOrientation];
if (parentOrientation != 0) {
orientation = parentOrientation;
}
Expand Down
Loading

0 comments on commit 29cda07

Please sign in to comment.