OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 [self addTrackingArea:trackingArea_.get()]; | 479 [self addTrackingArea:trackingArea_.get()]; |
480 | 480 |
481 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide); | 481 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide); |
482 if (editingAllowed) { | 482 if (editingAllowed) { |
483 changePhotoButton_.reset([self changePhotoButtonWithRect:bounds]); | 483 changePhotoButton_.reset([self changePhotoButtonWithRect:bounds]); |
484 [self addSubview:changePhotoButton_]; | 484 [self addSubview:changePhotoButton_]; |
485 | 485 |
486 // Hide the button until the image is hovered over. | 486 // Hide the button until the image is hovered over. |
487 [changePhotoButton_ setHidden:YES]; | 487 [changePhotoButton_ setHidden:YES]; |
488 } | 488 } |
489 | |
490 // Set the image cell's accessibility strings to be the same as the | |
491 // button's strings. | |
492 [[self cell] accessibilitySetOverrideValue:l10n_util::GetNSString( | |
493 editingAllowed ? | |
494 IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME : | |
495 IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME) | |
496 forAttribute:NSAccessibilityTitleAttribute]; | |
497 [[self cell] accessibilitySetOverrideValue: | |
498 editingAllowed ? NSAccessibilityButtonRole : NSAccessibilityImageRole | |
499 forAttribute:NSAccessibilityRoleAttribute]; | |
500 [[self cell] accessibilitySetOverrideValue: | |
501 NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil) | |
502 forAttribute:NSAccessibilityRoleDescriptionAttribute]; | |
503 | |
504 // The button and the cell should read the same thing. | |
505 [self accessibilitySetOverrideValue:l10n_util::GetNSString( | |
506 editingAllowed ? | |
507 IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME : | |
508 IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME) | |
509 forAttribute:NSAccessibilityTitleAttribute]; | |
510 [self accessibilitySetOverrideValue:NSAccessibilityButtonRole | |
511 forAttribute:NSAccessibilityRoleAttribute]; | |
512 [self accessibilitySetOverrideValue: | |
513 NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil) | |
514 forAttribute:NSAccessibilityRoleDescriptionAttribute]; | |
489 } | 515 } |
490 return self; | 516 return self; |
491 } | 517 } |
492 | 518 |
493 - (void)drawRect:(NSRect)dirtyRect { | 519 - (void)drawRect:(NSRect)dirtyRect { |
494 NSRect bounds = [self bounds]; | 520 NSRect bounds = [self bounds]; |
495 | 521 |
496 // Display the profile picture as a circle. | 522 // Display the profile picture as a circle. |
497 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:bounds]; | 523 NSBezierPath* path = [NSBezierPath bezierPathWithOvalInRect:bounds]; |
498 [path addClip]; | 524 [path addClip]; |
(...skipping 11 matching lines...) Expand all Loading... | |
510 } | 536 } |
511 | 537 |
512 - (void)mouseEntered:(NSEvent*)event { | 538 - (void)mouseEntered:(NSEvent*)event { |
513 [changePhotoButton_ setHidden:NO]; | 539 [changePhotoButton_ setHidden:NO]; |
514 } | 540 } |
515 | 541 |
516 - (void)mouseExited:(NSEvent*)event { | 542 - (void)mouseExited:(NSEvent*)event { |
517 [changePhotoButton_ setHidden:YES]; | 543 [changePhotoButton_ setHidden:YES]; |
518 } | 544 } |
519 | 545 |
546 // Make sure the element is focusable for accessibility. | |
547 - (BOOL)canBecomeKeyView { | |
548 return YES; | |
549 } | |
550 | |
551 - (BOOL)accessibilityIsIgnored { | |
552 return NO; | |
553 } | |
554 | |
555 - (NSArray*)accessibilityActionNames { | |
556 NSArray* parentActions = [super accessibilityActionNames]; | |
557 return [parentActions arrayByAddingObject:NSAccessibilityPressAction]; | |
558 } | |
559 | |
560 - (void)accessibilityPerformAction:(NSString*)action { | |
561 if ([action isEqualToString:NSAccessibilityPressAction]) { | |
562 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); | |
563 } | |
564 | |
565 [super accessibilityPerformAction:action]; | |
566 } | |
567 | |
520 - (TransparentBackgroundButton*)changePhotoButtonWithRect:(NSRect)rect { | 568 - (TransparentBackgroundButton*)changePhotoButtonWithRect:(NSRect)rect { |
521 TransparentBackgroundButton* button = | 569 TransparentBackgroundButton* button = |
522 [[TransparentBackgroundButton alloc] initWithFrame:rect]; | 570 [[TransparentBackgroundButton alloc] initWithFrame:rect]; |
523 [button setImage:ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 571 [button setImage:ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
524 IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; | 572 IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; |
525 [button setImagePosition:NSImageOnly]; | 573 [button setImagePosition:NSImageOnly]; |
526 [button setTarget:self]; | 574 [button setTarget:self]; |
527 [button setAction:@selector(editPhoto:)]; | 575 [button setAction:@selector(editPhoto:)]; |
528 return button; | 576 return button; |
529 } | 577 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 [[profileNameTextField_ cell] setLineBreakMode: | 650 [[profileNameTextField_ cell] setLineBreakMode: |
603 NSLineBreakByTruncatingTail]; | 651 NSLineBreakByTruncatingTail]; |
604 [self addSubview:profileNameTextField_]; | 652 [self addSubview:profileNameTextField_]; |
605 [profileNameTextField_ setTarget:self]; | 653 [profileNameTextField_ setTarget:self]; |
606 [profileNameTextField_ setAction:@selector(saveProfileName:)]; | 654 [profileNameTextField_ setAction:@selector(saveProfileName:)]; |
607 | 655 |
608 // Hide the textfield until the user clicks on the button. | 656 // Hide the textfield until the user clicks on the button. |
609 [profileNameTextField_ setHidden:YES]; | 657 [profileNameTextField_ setHidden:YES]; |
610 } | 658 } |
611 | 659 |
660 [[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole | |
661 forAttribute:NSAccessibilityRoleAttribute]; | |
662 [[self cell] accessibilitySetOverrideValue: | |
663 NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil) | |
664 forAttribute:NSAccessibilityRoleDescriptionAttribute]; | |
665 | |
612 [self setBordered:NO]; | 666 [self setBordered:NO]; |
613 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 667 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
614 [self setAlignment:NSCenterTextAlignment]; | 668 [self setAlignment:NSCenterTextAlignment]; |
615 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 669 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
616 [self setTitle:profileName]; | 670 [self setTitle:profileName]; |
617 } | 671 } |
618 return self; | 672 return self; |
619 } | 673 } |
620 | 674 |
621 - (void)saveProfileName:(id)sender { | 675 - (void)saveProfileName:(id)sender { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 // If view mode is PROFILE_CHOOSER but there is an auth error, force | 1041 // If view mode is PROFILE_CHOOSER but there is an auth error, force |
988 // ACCOUNT_MANAGEMENT mode. | 1042 // ACCOUNT_MANAGEMENT mode. |
989 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | 1043 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && |
990 HasAuthError(browser_->profile()) && | 1044 HasAuthError(browser_->profile()) && |
991 switches::IsEnableAccountConsistency() && | 1045 switches::IsEnableAccountConsistency() && |
992 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()). | 1046 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()). |
993 signed_in) { | 1047 signed_in) { |
994 viewMode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; | 1048 viewMode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; |
995 } | 1049 } |
996 | 1050 |
1051 [window accessibilitySetOverrideValue: | |
1052 l10n_util::GetNSString(IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_NAME) | |
1053 forAttribute:NSAccessibilityTitleAttribute]; | |
1054 [window accessibilitySetOverrideValue: | |
1055 l10n_util::GetNSString(IDS_PROFILES_NEW_AVATAR_MENU_ACCESSIBLE_NAME) | |
1056 forAttribute:NSAccessibilityHelpAttribute]; | |
1057 | |
997 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; | 1058 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; |
998 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; | 1059 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; |
999 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()]; | 1060 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()]; |
1000 [self initMenuContentsWithView:viewMode_]; | 1061 [self initMenuContentsWithView:viewMode_]; |
1001 } | 1062 } |
1002 | 1063 |
1003 return self; | 1064 return self; |
1004 } | 1065 } |
1005 | 1066 |
1006 - (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay { | 1067 - (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 frameOrigin:rect.origin | 1463 frameOrigin:rect.origin |
1403 action:nil]; | 1464 action:nil]; |
1404 if (HasAuthError(browser_->profile())) { | 1465 if (HasAuthError(browser_->profile())) { |
1405 [link setImage:ui::ResourceBundle::GetSharedInstance(). | 1466 [link setImage:ui::ResourceBundle::GetSharedInstance(). |
1406 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR). | 1467 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR). |
1407 ToNSImage()]; | 1468 ToNSImage()]; |
1408 [link setImagePosition:NSImageRight]; | 1469 [link setImagePosition:NSImageRight]; |
1409 [link setTarget:self]; | 1470 [link setTarget:self]; |
1410 [link setAction:@selector(showAccountReauthenticationView:)]; | 1471 [link setAction:@selector(showAccountReauthenticationView:)]; |
1411 [link setTag:kPrimaryProfileTag]; | 1472 [link setTag:kPrimaryProfileTag]; |
1473 [[link cell] | |
1474 accessibilitySetOverrideValue:l10n_util::GetNSStringF( | |
1475 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, | |
1476 item.sync_state) | |
1477 forAttribute:NSAccessibilityTitleAttribute]; | |
1412 } else { | 1478 } else { |
1413 [link setEnabled:NO]; | 1479 [link setEnabled:NO]; |
1414 } | 1480 } |
1415 } | 1481 } |
1416 // -linkButtonWithTitle sizeToFit's the link, so re-stretch it so that it | 1482 // -linkButtonWithTitle sizeToFit's the link, so re-stretch it so that it |
1417 // can be centered correctly in the view. | 1483 // can be centered correctly in the view. |
1418 [link setAlignment:NSCenterTextAlignment]; | 1484 [link setAlignment:NSCenterTextAlignment]; |
1419 [link setFrame:rect]; | 1485 [link setFrame:rect]; |
1420 [container addSubview:link]; | 1486 [container addSubview:link]; |
1421 [container setFrameSize:rect.size]; | 1487 [container setFrameSize:rect.size]; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1525 action:@selector(lockProfile:)]; | 1591 action:@selector(lockProfile:)]; |
1526 [container addSubview:lockButton]; | 1592 [container addSubview:lockButton]; |
1527 viewRect.origin.y = NSMaxY([lockButton frame]); | 1593 viewRect.origin.y = NSMaxY([lockButton frame]); |
1528 | 1594 |
1529 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | 1595 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; |
1530 [container addSubview:separator]; | 1596 [container addSubview:separator]; |
1531 viewRect.origin.y = NSMaxY([separator frame]); | 1597 viewRect.origin.y = NSMaxY([separator frame]); |
1532 } | 1598 } |
1533 | 1599 |
1534 if ([self shouldShowGoIncognito]) { | 1600 if ([self shouldShowGoIncognito]) { |
1601 // TODO(noms): Use the correct incognito icon when it's available. | |
groby-ooo-7-16
2014/08/15 19:52:07
nit: Pleaze to be filing a bug?
noms (inactive)
2014/08/15 20:00:00
Gah, sorry, bad rebase. Right icon is already in u
| |
1535 NSButton* goIncognitoButton = | 1602 NSButton* goIncognitoButton = |
1536 [self hoverButtonWithRect:viewRect | 1603 [self hoverButtonWithRect:viewRect |
1537 text:l10n_util::GetNSString( | 1604 text:l10n_util::GetNSString( |
1538 IDS_PROFILES_GO_INCOGNITO_BUTTON) | 1605 IDS_PROFILES_GO_INCOGNITO_BUTTON) |
1539 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO | 1606 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO |
1540 action:@selector(goIncognito:)]; | 1607 action:@selector(goIncognito:)]; |
1541 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); | 1608 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); |
1542 [container addSubview:goIncognitoButton]; | 1609 [container addSubview:goIncognitoButton]; |
1543 | 1610 |
1544 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | 1611 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1972 } | 2039 } |
1973 | 2040 |
1974 - (bool)shouldShowGoIncognito { | 2041 - (bool)shouldShowGoIncognito { |
1975 bool incognitoAvailable = | 2042 bool incognitoAvailable = |
1976 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2043 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
1977 IncognitoModePrefs::DISABLED; | 2044 IncognitoModePrefs::DISABLED; |
1978 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2045 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
1979 } | 2046 } |
1980 | 2047 |
1981 @end | 2048 @end |
OLD | NEW |