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

[iOS] Move banner a11y updates to util functions.

This will allow this functionality to be shared between overlay-based
and legacy infobar presentation.

Bug: 1030357
Change-Id: I3f3182cf41880ba03b5f4257936230238c72f8e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975016
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726440}
parent cae75965
......@@ -5,6 +5,8 @@
source_set("banners") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"infobar_banner_accessibility_util.h",
"infobar_banner_accessibility_util.mm",
"infobar_banner_consumer.h",
"infobar_banner_delegate.h",
"infobar_banner_view_controller.h",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_INFOBARS_BANNERS_INFOBAR_BANNER_ACCESSIBILITY_UTIL_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_BANNERS_INFOBAR_BANNER_ACCESSIBILITY_UTIL_H_
#import <UIKit/UIKit.h>
// Updates the accessibility of the presenting view controller so that VoiceOver
// users have the ability to select other elements while the banner is
// presented. This should be called after the banner's presentation is
// finished. |presenting_view_controller| and |banner_view| must not be nil.
void UpdateBannerAccessibilityForPresentation(
UIViewController* presenting_view_controller,
UIView* banner_view);
// Removes the banner view from |presenting_view_controller|'s accessibility
// elements. This should be called after the banner's dismissal is finished.
// |presenting_view_controller| must not be nil.
void UpdateBannerAccessibilityForDismissal(
UIViewController* presenting_view_controller);
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_BANNERS_INFOBAR_BANNER_ACCESSIBILITY_UTIL_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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/infobars/banners/infobar_banner_accessibility_util.h"
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
void UpdateBannerAccessibilityForPresentation(
UIViewController* presenting_view_controller,
UIView* banner_view) {
DCHECK(presenting_view_controller);
DCHECK(banner_view);
// Set the banner's superview accessibilityViewIsModal property to NO. This
// will allow the selection of the banner sibling views (e.g. the
// presentingViewController views).
banner_view.superview.accessibilityViewIsModal = NO;
// Make sure the banner is an accessibility element of
// |presenting_view_controller|.
presenting_view_controller.accessibilityElements =
@[ banner_view, presenting_view_controller.view ];
// Finally, focus the banner.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
banner_view);
}
void UpdateBannerAccessibilityForDismissal(
UIViewController* presenting_view_controller) {
DCHECK(presenting_view_controller);
// Remove the Banner as an accessibility element.
presenting_view_controller.accessibilityElements =
@[ presenting_view_controller.view ];
}
......@@ -7,6 +7,7 @@
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/fullscreen/animated_scoped_fullscreen_disabler.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_accessibility_util.h"
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_presentation_state.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinator_implementation.h"
#import "ios/chrome/browser/ui/infobars/infobar_badge_ui_delegate.h"
......@@ -476,23 +477,10 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
(UIViewController*)presentingViewController
presenting:(BOOL)presenting {
if (presenting) {
// Set the banner's superview accessibilityViewIsModal property to NO. This
// will allow the selection of the banner sibling views e.g. the
// presentingViewController views.
self.bannerViewController.view.superview.accessibilityViewIsModal = NO;
// Make sure the banner is an accessibility element of the
// PresentingViewController.
presentingViewController.accessibilityElements =
@[ self.bannerViewController.view, presentingViewController.view ];
// Finally, focus the banner.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
self.bannerViewController.view);
UpdateBannerAccessibilityForPresentation(presentingViewController,
self.bannerViewController.view);
} else {
// Remove the Banner as an A11y element.
presentingViewController.accessibilityElements =
@[ presentingViewController.view ];
UpdateBannerAccessibilityForDismissal(presentingViewController);
}
}
......
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