Commit fe64d4d8 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Remove some keyWindow uses (ios 12 deprecation, mw)

Removed orientation [uikit_]ui_util fncts that relied on
[[UIApplication] sharedApp].keyWindow.

Change-Id: I2936c5c1afd2c682fa967db896ba3b5161144be1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424085
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809763}
parent c50ddcd8
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include "ios/chrome/browser/json_parser/in_process_json_parser.h" #include "ios/chrome/browser/json_parser/in_process_json_parser.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h" #include "ios/chrome/browser/signin/identity_manager_factory.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/common/channel_info.h" #include "ios/chrome/common/channel_info.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
......
...@@ -134,7 +134,7 @@ const CGFloat kFeedCardIPhoneWidth = 375; ...@@ -134,7 +134,7 @@ const CGFloat kFeedCardIPhoneWidth = 375;
// TODO(b/167703449): Once the card width and padding is exposed we should // TODO(b/167703449): Once the card width and padding is exposed we should
// stop hardcoding this for some iPhones (the ones with a portrait width of // stop hardcoding this for some iPhones (the ones with a portrait width of
// kFeedCardIPhoneWidth) and use those values instead. // kFeedCardIPhoneWidth) and use those values instead.
BOOL shouldFixWidth = IsPortrait() BOOL shouldFixWidth = IsPortrait(self.window)
? (CurrentScreenWidth() == kFeedCardIPhoneWidth) ? (CurrentScreenWidth() == kFeedCardIPhoneWidth)
: (CurrentScreenHeight() == kFeedCardIPhoneWidth); : (CurrentScreenHeight() == kFeedCardIPhoneWidth);
if (shouldFixWidth) { if (shouldFixWidth) {
......
...@@ -448,7 +448,7 @@ NSString* const kMessageTextViewBulletRTLFormat = @"\u202E%@\u202C"; ...@@ -448,7 +448,7 @@ NSString* const kMessageTextViewBulletRTLFormat = @"\u202E%@\u202C";
- (void)layoutActionButton { - (void)layoutActionButton {
CGRect containerBounds = self.containerBounds; CGRect containerBounds = self.containerBounds;
BOOL isIPadIdiom = IsIPadIdiom(); BOOL isIPadIdiom = IsIPadIdiom();
BOOL isPortrait = IsPortrait(); BOOL isPortrait = IsPortrait(self.window);
BOOL shouldAddActionButtonToContainer = isIPadIdiom || !isPortrait; BOOL shouldAddActionButtonToContainer = isIPadIdiom || !isPortrait;
LayoutRect actionButtonLayout = LayoutRectZero; LayoutRect actionButtonLayout = LayoutRectZero;
actionButtonLayout.size = actionButtonLayout.size =
...@@ -491,7 +491,7 @@ NSString* const kMessageTextViewBulletRTLFormat = @"\u202E%@\u202C"; ...@@ -491,7 +491,7 @@ NSString* const kMessageTextViewBulletRTLFormat = @"\u202E%@\u202C";
// Center the containerView on iPads. // Center the containerView on iPads.
containerOriginY = containerOriginY =
(CGRectGetHeight(self.bounds) - containerSize.height) / 2.0f; (CGRectGetHeight(self.bounds) - containerSize.height) / 2.0f;
} else if (IsPortrait()) { } else if (IsPortrait(self.window)) {
// Align containerView to a quarter of the view height on portrait iPhones. // Align containerView to a quarter of the view height on portrait iPhones.
containerOriginY = containerOriginY =
(CGRectGetHeight(self.bounds) - containerSize.height) / 4.0f; (CGRectGetHeight(self.bounds) - containerSize.height) / 4.0f;
......
...@@ -149,7 +149,7 @@ const NSTimeInterval kUploadTotalTime = 5; ...@@ -149,7 +149,7 @@ const NSTimeInterval kUploadTotalTime = 5;
// bounds will still be landscape at this point. Swap the height and width // bounds will still be landscape at this point. Swap the height and width
// here so that the dimensions will be correct once the app rotates to // here so that the dimensions will be correct once the app rotates to
// portrait. // portrait.
if (IsLandscape()) { if (IsLandscape(self.view.window)) {
mainBounds.size = CGSizeMake(mainBounds.size.height, mainBounds.size.width); mainBounds.size = CGSizeMake(mainBounds.size.height, mainBounds.size.width);
} }
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:mainBounds]; UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:mainBounds];
......
...@@ -20,13 +20,6 @@ enum InterfaceIdiom { IPHONE_IDIOM, IPAD_IDIOM, INTERFACE_IDIOM_COUNT }; ...@@ -20,13 +20,6 @@ enum InterfaceIdiom { IPHONE_IDIOM, IPAD_IDIOM, INTERFACE_IDIOM_COUNT };
// Array of widths for device idioms in portrait orientation. // Array of widths for device idioms in portrait orientation.
extern const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT]; extern const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT];
// Returns true if the device is in portrait orientation or if interface
// orientation is unknown.
bool IsPortrait();
// Returns true if the device is in landscape orientation.
bool IsLandscape();
// Returns the height of the screen in the current orientation. // Returns the height of the screen in the current orientation.
CGFloat CurrentScreenHeight(); CGFloat CurrentScreenHeight();
......
...@@ -29,16 +29,6 @@ const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT] = { ...@@ -29,16 +29,6 @@ const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT] = {
768 // IPAD_IDIOM 768 // IPAD_IDIOM
}; };
bool IsPortrait() {
UIInterfaceOrientation orient = GetInterfaceOrientation();
return UIInterfaceOrientationIsPortrait(orient) ||
orient == UIInterfaceOrientationUnknown;
}
bool IsLandscape() {
return UIInterfaceOrientationIsLandscape(GetInterfaceOrientation());
}
CGFloat CurrentScreenHeight() { CGFloat CurrentScreenHeight() {
return [UIScreen mainScreen].bounds.size.height; return [UIScreen mainScreen].bounds.size.height;
} }
......
...@@ -179,8 +179,8 @@ UIView* GetFirstResponderSubview(UIView* view); ...@@ -179,8 +179,8 @@ UIView* GetFirstResponderSubview(UIView* view);
// Returns a cropped image using |cropRect| on |image|. // Returns a cropped image using |cropRect| on |image|.
UIImage* CropImage(UIImage* image, const CGRect& cropRect); UIImage* CropImage(UIImage* image, const CGRect& cropRect);
// Returns the interface orientation of the app. // Returns the interface orientation of the given window in the app.
UIInterfaceOrientation GetInterfaceOrientation(); UIInterfaceOrientation GetInterfaceOrientation(UIWindow* window);
// Returns the height of the keyboard in the current orientation. // Returns the height of the keyboard in the current orientation.
CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue); CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue);
...@@ -199,6 +199,13 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -199,6 +199,13 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
UIColor* secondColor, UIColor* secondColor,
CGFloat fraction); CGFloat fraction);
// Returns true if the window is in portrait orientation or if orientation is
// unknown.
bool IsPortrait(UIWindow* window);
// Returns true if the window is in landscape orientation.
bool IsLandscape(UIWindow* window);
// Whether the |environment| has a compact horizontal size class. // Whether the |environment| has a compact horizontal size class.
bool IsCompactWidth(id<UITraitEnvironment> environment); bool IsCompactWidth(id<UITraitEnvironment> environment);
......
...@@ -513,8 +513,12 @@ UIImage* CropImage(UIImage* image, const CGRect& cropRect) { ...@@ -513,8 +513,12 @@ UIImage* CropImage(UIImage* image, const CGRect& cropRect) {
return result; return result;
} }
UIInterfaceOrientation GetInterfaceOrientation() { UIInterfaceOrientation GetInterfaceOrientation(UIWindow* window) {
#if !defined(__IPHONE_13_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
return [[UIApplication sharedApplication] statusBarOrientation]; return [[UIApplication sharedApplication] statusBarOrientation];
#else
return window.windowScene.interfaceOrientation;
#endif
} }
CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue) { CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue) {
...@@ -571,6 +575,16 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -571,6 +575,16 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
alpha:Lerp(a1, a2, fraction)]; alpha:Lerp(a1, a2, fraction)];
} }
bool IsPortrait(UIWindow* window) {
UIInterfaceOrientation orient = GetInterfaceOrientation(window);
return UIInterfaceOrientationIsPortrait(orient) ||
orient == UIInterfaceOrientationUnknown;
}
bool IsLandscape(UIWindow* window) {
return UIInterfaceOrientationIsLandscape(GetInterfaceOrientation(window));
}
bool IsCompactWidth(id<UITraitEnvironment> environment) { bool IsCompactWidth(id<UITraitEnvironment> environment) {
return IsCompactWidth(environment.traitCollection); return IsCompactWidth(environment.traitCollection);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment