Commit 42504179 authored by noms@chromium.org's avatar noms@chromium.org

[Mac] Add accessibility features to the new avatar menu

BUG=401834

Review URL: https://codereview.chromium.org/471703002

Cr-Commit-Position: refs/heads/master@{#290055}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290055 0039d316-1c4b-4281-b951-d872f2087c98
parent d0483b19
......@@ -11269,12 +11269,33 @@ Chrome ran out of memory.
<message name="IDS_PROFILES_BUBBLE_ACCESSIBLE_DESCRIPTION" desc="The help text for the avatar bubble.">
Switch to a different user.
</message>
<message name="IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_NAME" desc="Title of the new avatar bubble menu for accessibility">
Switch Person
</message>
<message name="IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_DESCRIPTION" desc="The help text for the new avatar bubble.">
Switch to a different person.
</message>
<message name="IDS_PROFILES_CREATE_NEW_PROFILE_OPTION" desc="In Title Case. Create new profile menu item and button title.">
Add New User
</message>
<message name="IDS_NEW_PROFILES_CREATE_NEW_PROFILE_OPTION" desc="In Title Case. Create new profile menu item and button title when using the new Profiles UI.">
Add Person...
</message>
<message name="IDS_PROFILES_NEW_AVATAR_BUTTON_ACCESSIBLE_NAME" desc="Title of the avatar button for accessibility">
<ph name="PROFILE_NAME">$1<ex>User</ex></ph> button
</message>
<message name="IDS_PROFILES_NEW_AVATAR_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME" desc="Title of the avatar button for accessibility">
<ph name="PROFILE_NAME">$1<ex>User</ex></ph> button: sign in error
</message>
<message name="IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME" desc="Title of the avatar button for accessibility">
<ph name="PROFILE_NAME">$1<ex>User</ex></ph>: sign in error
</message>
<message name="IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME" desc="Title of the change photo button for accessibility">
Change Photo
</message>
<message name="IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME" desc="Title of the change photo button for accessibility">
Photo
</message>
</if>
<if expr="not use_titlecase">
<message name="IDS_PROFILES_SWITCH_PROFILE_LINK" desc="Link in the supervised user bubble view to switch to a different profile.">
......
......@@ -13,9 +13,11 @@
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#import "ui/base/cocoa/appkit_utils.h"
#import "ui/base/cocoa/hover_image_button.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/nine_image_painter_factory.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia_operations.h"
......@@ -51,7 +53,7 @@ NSImage* GetImageFromResourceID(int resourceId) {
base::scoped_nsobject<NSImage> authenticationErrorImage_;
}
- (void)setIsThemedWindow:(BOOL)isThemedWindow;
- (void)setHasError:(BOOL)hasError;
- (void)setHasError:(BOOL)hasError withTitle:(NSString*)title;
@end
......@@ -131,13 +133,19 @@ NSImage* GetImageFromResourceID(int resourceId) {
isThemedWindow_ = isThemedWindow;
}
- (void)setHasError:(BOOL)hasError {
- (void)setHasError:(BOOL)hasError withTitle:(NSString*)title {
if (hasError) {
authenticationErrorImage_.reset(
[ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToNSImage() retain]);
[self accessibilitySetOverrideValue:l10n_util::GetNSStringF(
IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME,
base::SysNSStringToUTF16(title))
forAttribute:NSAccessibilityTitleAttribute];
} else {
authenticationErrorImage_.reset();
[self accessibilitySetOverrideValue:title
forAttribute:NSAccessibilityTitleAttribute];
}
}
......@@ -172,8 +180,7 @@ NSImage* GetImageFromResourceID(int resourceId) {
[[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]);
SigninErrorController* errorController =
profiles::GetSigninErrorController(browser->profile());
if (errorController)
[cell setHasError:errorController->HasError()];
[button_ setCell:cell.get()];
[self setView:button_];
......@@ -189,6 +196,8 @@ NSImage* GetImageFromResourceID(int resourceId) {
[button_ setAction:@selector(buttonClicked:)];
[self updateAvatarButtonAndLayoutParent:NO];
if (errorController)
[cell setHasError:errorController->HasError() withTitle:[button_ title]];
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
......@@ -262,7 +271,7 @@ NSImage* GetImageFromResourceID(int resourceId) {
}
- (void)updateErrorStatus:(BOOL)hasError {
[[button_ cell] setHasError:hasError];
[[button_ cell] setHasError:hasError withTitle:[button_ title]];
[self updateAvatarButtonAndLayoutParent:YES];
}
......
......@@ -486,6 +486,32 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
// Hide the button until the image is hovered over.
[changePhotoButton_ setHidden:YES];
}
// Set the image cell's accessibility strings to be the same as the
// button's strings.
[[self cell] accessibilitySetOverrideValue:l10n_util::GetNSString(
editingAllowed ?
IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME :
IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME)
forAttribute:NSAccessibilityTitleAttribute];
[[self cell] accessibilitySetOverrideValue:
editingAllowed ? NSAccessibilityButtonRole : NSAccessibilityImageRole
forAttribute:NSAccessibilityRoleAttribute];
[[self cell] accessibilitySetOverrideValue:
NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil)
forAttribute:NSAccessibilityRoleDescriptionAttribute];
// The button and the cell should read the same thing.
[self accessibilitySetOverrideValue:l10n_util::GetNSString(
editingAllowed ?
IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME :
IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME)
forAttribute:NSAccessibilityTitleAttribute];
[self accessibilitySetOverrideValue:NSAccessibilityButtonRole
forAttribute:NSAccessibilityRoleAttribute];
[self accessibilitySetOverrideValue:
NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil)
forAttribute:NSAccessibilityRoleDescriptionAttribute];
}
return self;
}
......@@ -517,6 +543,28 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
[changePhotoButton_ setHidden:YES];
}
// Make sure the element is focusable for accessibility.
- (BOOL)canBecomeKeyView {
return YES;
}
- (BOOL)accessibilityIsIgnored {
return NO;
}
- (NSArray*)accessibilityActionNames {
NSArray* parentActions = [super accessibilityActionNames];
return [parentActions arrayByAddingObject:NSAccessibilityPressAction];
}
- (void)accessibilityPerformAction:(NSString*)action {
if ([action isEqualToString:NSAccessibilityPressAction]) {
avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex());
}
[super accessibilityPerformAction:action];
}
- (TransparentBackgroundButton*)changePhotoButtonWithRect:(NSRect)rect {
TransparentBackgroundButton* button =
[[TransparentBackgroundButton alloc] initWithFrame:rect];
......@@ -609,6 +657,12 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
[profileNameTextField_ setHidden:YES];
}
[[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole
forAttribute:NSAccessibilityRoleAttribute];
[[self cell] accessibilitySetOverrideValue:
NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil)
forAttribute:NSAccessibilityRoleDescriptionAttribute];
[self setBordered:NO];
[self setFont:[NSFont labelFontOfSize:kTitleFontSize]];
[self setAlignment:NSCenterTextAlignment];
......@@ -988,6 +1042,13 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
viewMode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT;
}
[window accessibilitySetOverrideValue:
l10n_util::GetNSString(IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_NAME)
forAttribute:NSAccessibilityTitleAttribute];
[window accessibilitySetOverrideValue:
l10n_util::GetNSString(IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_NAME)
forAttribute:NSAccessibilityHelpAttribute];
[[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge];
[[self bubble] setArrowLocation:info_bubble::kNoArrow];
[[self bubble] setBackgroundColor:GetDialogBackgroundColor()];
......@@ -1401,6 +1462,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
[link setTarget:self];
[link setAction:@selector(showAccountReauthenticationView:)];
[link setTag:kPrimaryProfileTag];
[[link cell]
accessibilitySetOverrideValue:l10n_util::GetNSStringF(
IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME,
item.sync_state)
forAttribute:NSAccessibilityTitleAttribute];
} else {
[link setEnabled:NO];
}
......
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