Commit d74ebdc7 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Disable fullscreen while the keyboard is visible.

In addition to adding keyboard notification observation, this
CL also moves VoiceOver fullscreen disabling into a shared
object.

Bug: 793129
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ia8f8501ff7f5e97ec9d794e6c3d33687e90f4d9f
Reviewed-on: https://chromium-review.googlesource.com/816356
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524518}
parent a657d1a6
...@@ -53,8 +53,8 @@ source_set("new_fullscreen_internal") { ...@@ -53,8 +53,8 @@ source_set("new_fullscreen_internal") {
"fullscreen_web_state_list_observer.mm", "fullscreen_web_state_list_observer.mm",
"fullscreen_web_state_observer.h", "fullscreen_web_state_observer.h",
"fullscreen_web_state_observer.mm", "fullscreen_web_state_observer.mm",
"voice_over_fullscreen_disabler.h", "system_notification_fullscreen_disabler.h",
"voice_over_fullscreen_disabler.mm", "system_notification_fullscreen_disabler.mm",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
...@@ -17,7 +17,7 @@ class FullscreenControllerObserver; ...@@ -17,7 +17,7 @@ class FullscreenControllerObserver;
class FullscreenMediator; class FullscreenMediator;
class FullscreenModel; class FullscreenModel;
class FullscreenWebStateListObserver; class FullscreenWebStateListObserver;
@class VoiceOverFullscreenDisabler; @class SystemNotificationFullscreenDisabler;
class WebStateList; class WebStateList;
// An object that observes scrolling events in the main content area and // An object that observes scrolling events in the main content area and
...@@ -72,8 +72,8 @@ class FullscreenController : public KeyedService { ...@@ -72,8 +72,8 @@ class FullscreenController : public KeyedService {
std::unique_ptr<FullscreenModel> model_; std::unique_ptr<FullscreenModel> model_;
// The bridge used to forward brodcasted UI to |model_|. // The bridge used to forward brodcasted UI to |model_|.
__strong ChromeBroadcastOberverBridge* bridge_ = nil; __strong ChromeBroadcastOberverBridge* bridge_ = nil;
// A helper object that disables fullscreen when VoiceOver is enabled. // A helper object that disables fullscreen for system notifications.
__strong VoiceOverFullscreenDisabler* voice_over_disabler_ = nil; __strong SystemNotificationFullscreenDisabler* disabler_ = nil;
// Object that manages sending signals to FullscreenControllerObservers. // Object that manages sending signals to FullscreenControllerObservers.
std::unique_ptr<FullscreenMediator> mediator_; std::unique_ptr<FullscreenMediator> mediator_;
// A WebStateListObserver that updates |model_| for WebStateList changes. // A WebStateListObserver that updates |model_| for WebStateList changes.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_mediator.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_mediator.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_state_list_observer.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_web_state_list_observer.h"
#import "ios/chrome/browser/ui/fullscreen/voice_over_fullscreen_disabler.h" #import "ios/chrome/browser/ui/fullscreen/system_notification_fullscreen_disabler.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -21,8 +21,8 @@ FullscreenController::FullscreenController() ...@@ -21,8 +21,8 @@ FullscreenController::FullscreenController()
model_(base::MakeUnique<FullscreenModel>()), model_(base::MakeUnique<FullscreenModel>()),
bridge_( bridge_(
[[ChromeBroadcastOberverBridge alloc] initWithObserver:model_.get()]), [[ChromeBroadcastOberverBridge alloc] initWithObserver:model_.get()]),
voice_over_disabler_( disabler_([[SystemNotificationFullscreenDisabler alloc]
[[VoiceOverFullscreenDisabler alloc] initWithController:this]), initWithController:this]),
mediator_(base::MakeUnique<FullscreenMediator>(this, model_.get())) { mediator_(base::MakeUnique<FullscreenMediator>(this, model_.get())) {
DCHECK(broadcaster_); DCHECK(broadcaster_);
[broadcaster_ addObserver:bridge_ [broadcaster_ addObserver:bridge_
...@@ -70,7 +70,7 @@ void FullscreenController::DecrementDisabledCounter() { ...@@ -70,7 +70,7 @@ void FullscreenController::DecrementDisabledCounter() {
void FullscreenController::Shutdown() { void FullscreenController::Shutdown() {
mediator_->Disconnect(); mediator_->Disconnect();
[voice_over_disabler_ disconnect]; [disabler_ disconnect];
if (web_state_list_observer_) if (web_state_list_observer_)
web_state_list_observer_->Disconnect(); web_state_list_observer_->Disconnect();
[broadcaster_ removeObserver:bridge_ [broadcaster_ removeObserver:bridge_
......
...@@ -2,16 +2,20 @@ ...@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_FULLSCREEN_VOICE_OVER_FULLSCREEN_DISABLER_H_ #ifndef IOS_CHROME_BROWSER_UI_FULLSCREEN_SYSTEM_NOTIFICATION_FULLSCREEN_DISABLER_H_
#define IOS_CHROME_BROWSER_UI_FULLSCREEN_VOICE_OVER_FULLSCREEN_DISABLER_H_ #define IOS_CHROME_BROWSER_UI_FULLSCREEN_SYSTEM_NOTIFICATION_FULLSCREEN_DISABLER_H_
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
class FullscreenController; class FullscreenController;
// Helper class that handles disabling fullscreen while VoiceOver is enabled. // Helper class that handles disabling fullscreen due to NSNotifications sent
@interface VoiceOverFullscreenDisabler : NSObject // by system frameworks. This class disables fullscreen:
// - when VoiceOver is enabled,
// - when the software keyboard is visible.
@interface SystemNotificationFullscreenDisabler : NSObject
// Designated initializer that disables |controller| for system notifications.
- (nullable instancetype)initWithController: - (nullable instancetype)initWithController:
(nonnull FullscreenController*)controller NS_DESIGNATED_INITIALIZER; (nonnull FullscreenController*)controller NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)init NS_UNAVAILABLE; - (nullable instancetype)init NS_UNAVAILABLE;
...@@ -21,4 +25,4 @@ class FullscreenController; ...@@ -21,4 +25,4 @@ class FullscreenController;
@end @end
#endif // IOS_CHROME_BROWSER_UI_FULLSCREEN_VOICE_OVER_FULLSCREEN_DISABLER_H_ #endif // IOS_CHROME_BROWSER_UI_FULLSCREEN_SYSTEM_NOTIFICATION_FULLSCREEN_DISABLER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/fullscreen/voice_over_fullscreen_disabler.h" #import "ios/chrome/browser/ui/fullscreen/system_notification_fullscreen_disabler.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -13,23 +13,31 @@ ...@@ -13,23 +13,31 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface VoiceOverFullscreenDisabler () { @interface SystemNotificationFullscreenDisabler () {
// The disabler created when VoiceOver is enabled. // The disabler created when VoiceOver is enabled.
std::unique_ptr<ScopedFullscreenDisabler> _disabler; std::unique_ptr<ScopedFullscreenDisabler> _voiceOverDisabler;
// The disabler created when the keyboard is visible.
std::unique_ptr<ScopedFullscreenDisabler> _keyboardDisabler;
} }
// The FullscreenController being enabled/disabled for VoiceOver. // The FullscreenController being enabled/disabled for VoiceOver.
@property(nonatomic, readonly, nonnull) FullscreenController* controller; @property(nonatomic, readonly, nonnull) FullscreenController* controller;
// Creates or destroys |_disabler| depending on whether VoiceOver is enabled. // Creates or destroys |_voiceOverDisabler| depending on whether VoiceOver is
// enabled.
- (void)voiceOverStatusChanged; - (void)voiceOverStatusChanged;
// Called when the keyboard is shown/hidden to reset |_keyboardDisabler|.
- (void)keyboardWillShow;
- (void)keyboardDidHide;
@end @end
@implementation VoiceOverFullscreenDisabler @implementation SystemNotificationFullscreenDisabler
@synthesize controller = _controller; @synthesize controller = _controller;
- (instancetype)initWithController:(FullscreenController*)controller { - (instancetype)initWithController:(FullscreenController*)controller {
if (self = [super init]) { if (self = [super init]) {
_controller = controller; _controller = controller;
DCHECK(_controller); DCHECK(_controller);
// Register for VoiceOVer status change notifications. The notification
// name has been updated in iOS 11.
if (@available(iOS 11, *)) { if (@available(iOS 11, *)) {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver:self addObserver:self
...@@ -43,8 +51,22 @@ ...@@ -43,8 +51,22 @@
name:UIAccessibilityVoiceOverStatusChanged name:UIAccessibilityVoiceOverStatusChanged
object:nil]; object:nil];
} }
if (UIAccessibilityIsVoiceOverRunning()) // Create a disabler if VoiceOver is enabled.
_disabler = base::MakeUnique<ScopedFullscreenDisabler>(_controller); if (UIAccessibilityIsVoiceOverRunning()) {
_voiceOverDisabler =
base::MakeUnique<ScopedFullscreenDisabler>(_controller);
}
// Regsiter for keyboard visibility notifications.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardDidHide)
name:UIKeyboardDidHideNotification
object:nil];
} }
return self; return self;
} }
...@@ -64,9 +86,19 @@ ...@@ -64,9 +86,19 @@
#pragma mark Private #pragma mark Private
- (void)voiceOverStatusChanged { - (void)voiceOverStatusChanged {
_disabler = UIAccessibilityIsVoiceOverRunning() _voiceOverDisabler =
? base::MakeUnique<ScopedFullscreenDisabler>(_controller) UIAccessibilityIsVoiceOverRunning()
: nullptr; ? base::MakeUnique<ScopedFullscreenDisabler>(self.controller)
: nullptr;
}
- (void)keyboardWillShow {
_keyboardDisabler =
base::MakeUnique<ScopedFullscreenDisabler>(self.controller);
}
- (void)keyboardDidHide {
_keyboardDisabler = nullptr;
} }
@end @end
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