Skip to content

Commit

Permalink
Makes zoom buttons in Chrome main menu accessible to Jaws and NVDA
Browse files Browse the repository at this point in the history
Screen readers now announce the correct role for the zoom in and zoom out buttons and also announce the zoom level if changed.
Announcing that these controls are buttons sends a signal to screen reader users that the menu will not close when these controls are activated.
The drawback is that the word "Alert" is prepended to the announcement of the new zoom level.

R=aleventhal@chromium.org, pbos@chromium.org

Bug: 779304
Change-Id: Ie078d63c318a70fa64db268ac748dc2700995f55
Tested: Use zoom in and zoom out while Jaws and NVDA are running
Reviewed-on: https://chromium-review.googlesource.com/957902
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: Nektarios Paisios <nektar@chromium.org>
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542636}
  • Loading branch information
Nektarios Paisios authored and Commit Bot committed Mar 12, 2018
1 parent b956afc commit 1bcb2e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
17 changes: 15 additions & 2 deletions chrome/browser/ui/views/toolbar/app_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
Expand Down Expand Up @@ -317,6 +318,12 @@ class AppMenuView : public views::View,
menu_->RemoveObserver(this);
}

// Overridden from views::View.
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
views::View::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kMenu;
}

// Overridden from views::View.
void SchedulePaintInRect(const gfx::Rect& r) override {
// Normally when the mouse enters/exits a button the buttons invokes
Expand Down Expand Up @@ -504,6 +511,10 @@ class AppMenu::ZoomView : public AppMenuView {
zoom_label_->SetBackground(std::make_unique<InMenuButtonBackground>(
InMenuButtonBackground::NO_BORDER));

// An accessibility role of kAlert will ensure that any updates to the zoom
// level can be picked up by screen readers.
zoom_label_->GetViewAccessibility().OverrideRole(ax::mojom::Role::kAlert);

AddChildView(zoom_label_);
zoom_label_max_width_valid_ = false;

Expand All @@ -513,7 +524,7 @@ class AppMenu::ZoomView : public AppMenuView {

fullscreen_button_ = new FullscreenButton(this);
// all buttons on menu should must be a custom button in order for
// the keyboard navigation work.
// the keyboard navigation to work.
DCHECK(Button::AsButton(fullscreen_button_));
gfx::ImageSkia* full_screen_image =
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
Expand Down Expand Up @@ -639,7 +650,9 @@ class AppMenu::ZoomView : public AppMenuView {
contents->GetMinimumZoomPercent());
}
zoom_label_->SetText(base::FormatPercent(zoom));
zoom_label_->NotifyAccessibilityEvent(ax::mojom::Event::kTextChanged, true);
// An alert notification will ensure that the zoom label is always announced
// even if is not focusable.
zoom_label_->NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
zoom_label_max_width_valid_ = false;
}

Expand Down
14 changes: 11 additions & 3 deletions ui/accessibility/platform/ax_platform_node_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,17 @@ void AXPlatformNodeWin::NotifyAccessibilityEvent(ax::mojom::Event event_type) {

// Menu items fire selection events but Windows screen readers work reliably
// with focus events. Remap here.
if (event_type == ax::mojom::Event::kSelection &&
GetData().role == ax::mojom::Role::kMenuItem)
event_type = ax::mojom::Event::kFocus;
if (event_type == ax::mojom::Event::kSelection) {
// A menu item could have something other than a role of
// |ROLE_SYSTEM_MENUITEM|. Zoom modification controls for example have a
// role of button.
auto* parent =
static_cast<AXPlatformNodeWin*>(FromNativeViewAccessible(GetParent()));
if (MSAARole() == ROLE_SYSTEM_MENUITEM ||
(parent && parent->MSAARole() == ROLE_SYSTEM_MENUPOPUP)) {
event_type = ax::mojom::Event::kFocus;
}
}

int native_event = MSAAEvent(event_type);
if (native_event < EVENT_MIN)
Expand Down

0 comments on commit 1bcb2e3

Please sign in to comment.