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") {
"fullscreen_web_state_list_observer.mm",
"fullscreen_web_state_observer.h",
"fullscreen_web_state_observer.mm",
"voice_over_fullscreen_disabler.h",
"voice_over_fullscreen_disabler.mm",
"system_notification_fullscreen_disabler.h",
"system_notification_fullscreen_disabler.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
......
......@@ -17,7 +17,7 @@ class FullscreenControllerObserver;
class FullscreenMediator;
class FullscreenModel;
class FullscreenWebStateListObserver;
@class VoiceOverFullscreenDisabler;
@class SystemNotificationFullscreenDisabler;
class WebStateList;
// An object that observes scrolling events in the main content area and
......@@ -72,8 +72,8 @@ class FullscreenController : public KeyedService {
std::unique_ptr<FullscreenModel> model_;
// The bridge used to forward brodcasted UI to |model_|.
__strong ChromeBroadcastOberverBridge* bridge_ = nil;
// A helper object that disables fullscreen when VoiceOver is enabled.
__strong VoiceOverFullscreenDisabler* voice_over_disabler_ = nil;
// A helper object that disables fullscreen for system notifications.
__strong SystemNotificationFullscreenDisabler* disabler_ = nil;
// Object that manages sending signals to FullscreenControllerObservers.
std::unique_ptr<FullscreenMediator> mediator_;
// A WebStateListObserver that updates |model_| for WebStateList changes.
......
......@@ -10,7 +10,7 @@
#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_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)
#error "This file requires ARC support."
......@@ -21,8 +21,8 @@ FullscreenController::FullscreenController()
model_(base::MakeUnique<FullscreenModel>()),
bridge_(
[[ChromeBroadcastOberverBridge alloc] initWithObserver:model_.get()]),
voice_over_disabler_(
[[VoiceOverFullscreenDisabler alloc] initWithController:this]),
disabler_([[SystemNotificationFullscreenDisabler alloc]
initWithController:this]),
mediator_(base::MakeUnique<FullscreenMediator>(this, model_.get())) {
DCHECK(broadcaster_);
[broadcaster_ addObserver:bridge_
......@@ -70,7 +70,7 @@ void FullscreenController::DecrementDisabledCounter() {
void FullscreenController::Shutdown() {
mediator_->Disconnect();
[voice_over_disabler_ disconnect];
[disabler_ disconnect];
if (web_state_list_observer_)
web_state_list_observer_->Disconnect();
[broadcaster_ removeObserver:bridge_
......
......@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_FULLSCREEN_VOICE_OVER_FULLSCREEN_DISABLER_H_
#define 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_SYSTEM_NOTIFICATION_FULLSCREEN_DISABLER_H_
#import <UIKit/UIKit.h>
class FullscreenController;
// Helper class that handles disabling fullscreen while VoiceOver is enabled.
@interface VoiceOverFullscreenDisabler : NSObject
// Helper class that handles disabling fullscreen due to NSNotifications sent
// 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:
(nonnull FullscreenController*)controller NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)init NS_UNAVAILABLE;
......@@ -21,4 +25,4 @@ class FullscreenController;
@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 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/memory/ptr_util.h"
......@@ -13,23 +13,31 @@
#error "This file requires ARC support."
#endif
@interface VoiceOverFullscreenDisabler () {
@interface SystemNotificationFullscreenDisabler () {
// 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.
@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;
// Called when the keyboard is shown/hidden to reset |_keyboardDisabler|.
- (void)keyboardWillShow;
- (void)keyboardDidHide;
@end
@implementation VoiceOverFullscreenDisabler
@implementation SystemNotificationFullscreenDisabler
@synthesize controller = _controller;
- (instancetype)initWithController:(FullscreenController*)controller {
if (self = [super init]) {
_controller = controller;
DCHECK(_controller);
// Register for VoiceOVer status change notifications. The notification
// name has been updated in iOS 11.
if (@available(iOS 11, *)) {
[[NSNotificationCenter defaultCenter]
addObserver:self
......@@ -43,8 +51,22 @@
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
}
if (UIAccessibilityIsVoiceOverRunning())
_disabler = base::MakeUnique<ScopedFullscreenDisabler>(_controller);
// Create a disabler if VoiceOver is enabled.
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;
}
......@@ -64,9 +86,19 @@
#pragma mark Private
- (void)voiceOverStatusChanged {
_disabler = UIAccessibilityIsVoiceOverRunning()
? base::MakeUnique<ScopedFullscreenDisabler>(_controller)
: nullptr;
_voiceOverDisabler =
UIAccessibilityIsVoiceOverRunning()
? base::MakeUnique<ScopedFullscreenDisabler>(self.controller)
: nullptr;
}
- (void)keyboardWillShow {
_keyboardDisabler =
base::MakeUnique<ScopedFullscreenDisabler>(self.controller);
}
- (void)keyboardDidHide {
_keyboardDisabler = nullptr;
}
@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