Commit 99dff50a authored by David Jean's avatar David Jean Committed by Chromium LUCI CQ

[ios] Fix orientation issues for ios 12 deprecation

Also includes two #ifdef-out of deprecated code unrelated
to orientation.

Bug: 1131852
Change-Id: Ia229a421d0b9f9e9d655791d43b0cb59c0b0e75c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612898
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841433}
parent 9ec63731
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
#import "ios/chrome/browser/ui/main/scene_delegate.h" #import "ios/chrome/browser/ui/main/scene_delegate.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h" #import "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/browser/ui/util/multi_window_support.h" #include "ios/chrome/browser/ui/util/multi_window_support.h"
#include "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/ui/webui/chrome_web_ui_ios_controller_factory.h" #import "ios/chrome/browser/ui/webui/chrome_web_ui_ios_controller_factory.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h" #import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
...@@ -733,9 +734,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -733,9 +734,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
} }
- (void)orientationDidChange:(NSNotification*)notification { - (void)orientationDidChange:(NSNotification*)notification {
crash_keys::SetCurrentOrientation( crash_keys::SetCurrentOrientation(GetInterfaceOrientation(),
[[UIApplication sharedApplication] statusBarOrientation], [[UIDevice currentDevice] orientation]);
[[UIDevice currentDevice] orientation]);
} }
- (void)registerForOrientationChangeNotifications { - (void)registerForOrientationChangeNotifications {
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#import "ios/chrome/browser/ui/authentication/unified_consent/unified_consent_coordinator.h" #import "ios/chrome/browser/ui/authentication/unified_consent/unified_consent_coordinator.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h" #import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/unified_consent/unified_consent_service_factory.h" #import "ios/chrome/browser/unified_consent/unified_consent_service_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -432,8 +433,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f; ...@@ -432,8 +433,7 @@ const CGFloat kFadeOutAnimationDuration = 0.16f;
// Avoid presenting the promo if the current device orientation is not // Avoid presenting the promo if the current device orientation is not
// supported. The promo will be presented at a later moment, when the // supported. The promo will be presented at a later moment, when the
// device orientation is supported. // device orientation is supported.
UIInterfaceOrientation orientation = UIInterfaceOrientation orientation = GetInterfaceOrientation();
[UIApplication sharedApplication].statusBarOrientation;
NSUInteger supportedOrientationsMask = NSUInteger supportedOrientationsMask =
[self.viewController supportedInterfaceOrientations]; [self.viewController supportedInterfaceOrientations];
if (!((1 << orientation) & supportedOrientationsMask)) { if (!((1 << orientation) & supportedOrientationsMask)) {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/util/rtl_geometry.h" #import "ios/chrome/browser/ui/util/rtl_geometry.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h" #import "ios/chrome/common/ui/colors/semantic_color_names.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -363,8 +364,7 @@ void CardUnmaskPromptViewBridge::DeleteSelf() { ...@@ -363,8 +364,7 @@ void CardUnmaskPromptViewBridge::DeleteSelf() {
// Focus the first visible input, unless the orientation is landscape. In // Focus the first visible input, unless the orientation is landscape. In
// landscape, the keyboard covers up the storage checkbox shown below this // landscape, the keyboard covers up the storage checkbox shown below this
// view and the user might never see it. // view and the user might never see it.
if (UIInterfaceOrientationIsPortrait( if (UIInterfaceOrientationIsPortrait(GetInterfaceOrientation())) {
[UIApplication sharedApplication].statusBarOrientation)) {
// Also check whether any of the inputs are already the first responder and // Also check whether any of the inputs are already the first responder and
// are non-empty, in which case the focus should be left there. // are non-empty, in which case the focus should be left there.
if ((!CVC.monthInput.isFirstResponder || CVC.monthInput.text.length == 0) && if ((!CVC.monthInput.isFirstResponder || CVC.monthInput.text.length == 0) &&
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/common/ios_app_bundle_id_prefix_buildflags.h" #include "ios/chrome/common/ios_app_bundle_id_prefix_buildflags.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -329,8 +330,7 @@ ...@@ -329,8 +330,7 @@
} }
- (AVCaptureVideoOrientation)videoOrientationForCurrentInterfaceOrientation { - (AVCaptureVideoOrientation)videoOrientationForCurrentInterfaceOrientation {
UIInterfaceOrientation orientation = UIInterfaceOrientation orientation = GetInterfaceOrientation();
[[UIApplication sharedApplication] statusBarOrientation];
switch (orientation) { switch (orientation) {
case UIInterfaceOrientationUnknown: case UIInterfaceOrientationUnknown:
return AVCaptureVideoOrientationPortrait; return AVCaptureVideoOrientationPortrait;
......
...@@ -118,11 +118,13 @@ ...@@ -118,11 +118,13 @@
- (void)keyboardWillHide:(NSNotification*)notification { - (void)keyboardWillHide:(NSNotification*)notification {
self.keyboardOnScreen = NO; self.keyboardOnScreen = NO;
#if !defined(__IPHONE_13_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (self.keyboardOnScreen) { if (self.keyboardOnScreen) {
[self.consumer keyboardDidStayOnScreen]; [self.consumer keyboardDidStayOnScreen];
} }
}); });
#endif
} }
#pragma mark - Private #pragma mark - Private
......
...@@ -69,6 +69,7 @@ source_set("agents") { ...@@ -69,6 +69,7 @@ source_set("agents") {
"//ios/chrome/browser/main:public", "//ios/chrome/browser/main:public",
"//ios/chrome/browser/sessions:restoration_agent", "//ios/chrome/browser/sessions:restoration_agent",
"//ios/chrome/browser/sessions:restoration_observer", "//ios/chrome/browser/sessions:restoration_observer",
"//ios/chrome/browser/ui/util",
"//ios/web/public", "//ios/web/public",
] ]
frameworks = [ "Foundation.framework" ] frameworks = [ "Foundation.framework" ]
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/crash_report/crash_loop_detection_util.h" #include "ios/chrome/browser/crash_report/crash_loop_detection_util.h"
#import "ios/chrome/browser/sessions/session_restoration_browser_agent.h" #import "ios/chrome/browser/sessions/session_restoration_browser_agent.h"
#include "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/browser/web_state_list/session_metrics.h" #include "ios/chrome/browser/web_state_list/session_metrics.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
...@@ -157,7 +158,7 @@ void WebStateListMetricsBrowserAgent::DidFinishNavigation( ...@@ -157,7 +158,7 @@ void WebStateListMetricsBrowserAgent::DidFinishNavigation(
void WebStateListMetricsBrowserAgent::PageLoaded( void WebStateListMetricsBrowserAgent::PageLoaded(
web::WebState* web_state, web::WebState* web_state,
web::PageLoadCompletionStatus load_completion_status) { web::PageLoadCompletionStatus load_completion_status) {
switch ([[UIApplication sharedApplication] statusBarOrientation]) { switch (GetInterfaceOrientation()) {
case UIInterfaceOrientationPortrait: case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown: case UIInterfaceOrientationPortraitUpsideDown:
UMA_HISTOGRAM_BOOLEAN("Tab.PageLoadInPortrait", YES); UMA_HISTOGRAM_BOOLEAN("Tab.PageLoadInPortrait", YES);
......
...@@ -11,4 +11,8 @@ ...@@ -11,4 +11,8 @@
// Use only if the context of which window doesn't matter. // Use only if the context of which window doesn't matter.
UIWindow* GetAnyKeyWindow(); UIWindow* GetAnyKeyWindow();
// Returns interface orientation for the current window, returned by
// GetAnyKeyWindow().
UIInterfaceOrientation GetInterfaceOrientation();
#endif // IOS_WEB_COMMON_UIKIT_UI_UTIL_H_ #endif // IOS_WEB_COMMON_UIKIT_UI_UTIL_H_
...@@ -22,3 +22,11 @@ UIWindow* GetAnyKeyWindow() { ...@@ -22,3 +22,11 @@ UIWindow* GetAnyKeyWindow() {
return nil; return nil;
#endif #endif
} }
UIInterfaceOrientation GetInterfaceOrientation() {
#if !defined(__IPHONE_13_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
return [[UIApplication sharedApplication] statusBarOrientation];
#else
return GetAnyKeyWindow().windowScene.interfaceOrientation;
#endif
}
...@@ -168,6 +168,9 @@ ...@@ -168,6 +168,9 @@
}]; }];
} }
#if !defined(__IPHONE_13_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0
// TODO(crbug.com/1131852): Preview depracted is iOS13+
- (BOOL)webView:(WKWebView*)webView - (BOOL)webView:(WKWebView*)webView
shouldPreviewElement:(WKPreviewElementInfo*)elementInfo { shouldPreviewElement:(WKPreviewElementInfo*)elementInfo {
return self.webStateImpl->ShouldPreviewLink( return self.webStateImpl->ShouldPreviewLink(
...@@ -211,6 +214,8 @@ ...@@ -211,6 +214,8 @@
completionHandler); completionHandler);
} }
#endif // End of >iOS13 deprecated block.
- (void)webView:(WKWebView*)webView - (void)webView:(WKWebView*)webView
contextMenuDidEndForElement:(WKContextMenuElementInfo*)elementInfo contextMenuDidEndForElement:(WKContextMenuElementInfo*)elementInfo
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
......
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