Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 2901973002: [Mac] Mirror profile switcher UI in RTL (Closed)
Patch Set: CL comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/l10n_util.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
6 6
7 #import <Carbon/Carbon.h> // kVK_Return. 7 #import <Carbon/Carbon.h> // kVK_Return.
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 // Builds a label with the given |title| anchored at |frame_origin|. Sets the 150 // Builds a label with the given |title| anchored at |frame_origin|. Sets the
151 // text color to |text_color| if not null. 151 // text color to |text_color| if not null.
152 NSTextField* BuildLabel(NSString* title, 152 NSTextField* BuildLabel(NSString* title,
153 NSPoint frame_origin, 153 NSPoint frame_origin,
154 NSColor* text_color) { 154 NSColor* text_color) {
155 base::scoped_nsobject<NSTextField> label( 155 base::scoped_nsobject<NSTextField> label(
156 [[NSTextField alloc] initWithFrame:NSZeroRect]); 156 [[NSTextField alloc] initWithFrame:NSZeroRect]);
157 [label setStringValue:title]; 157 [label setStringValue:title];
158 [label setEditable:NO]; 158 [label setEditable:NO];
159 [label setAlignment:NSLeftTextAlignment]; 159 [label setAlignment:NSNaturalTextAlignment];
160 [label setBezeled:NO]; 160 [label setBezeled:NO];
161 [label setFont:[NSFont labelFontOfSize:kTextFontSize]]; 161 [label setFont:[NSFont labelFontOfSize:kTextFontSize]];
162 [label setDrawsBackground:NO]; 162 [label setDrawsBackground:NO];
163 [label setFrameOrigin:frame_origin]; 163 [label setFrameOrigin:frame_origin];
164 [label sizeToFit]; 164 [label sizeToFit];
165 165
166 if (text_color) 166 if (text_color)
167 [[label cell] setTextColor:text_color]; 167 [[label cell] setTextColor:text_color];
168 168
169 return label.autorelease(); 169 return label.autorelease();
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // The observer can be removed both when closing the browser, and by just 412 // The observer can be removed both when closing the browser, and by just
413 // closing the avatar bubble. However, in the case of closing the browser, 413 // closing the avatar bubble. However, in the case of closing the browser,
414 // the avatar bubble will also be closed afterwards, resulting in a second 414 // the avatar bubble will also be closed afterwards, resulting in a second
415 // attempt to remove the observer. This ensures the observer is only 415 // attempt to remove the observer. This ensures the observer is only
416 // removed once. 416 // removed once.
417 bool token_observer_registered_; 417 bool token_observer_registered_;
418 418
419 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); 419 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge);
420 }; 420 };
421 421
422 // Custom button cell that adds a left padding before the button image, and 422 // Custom button cell that adds a leading padding before the button image, and
423 // a custom spacing between the button image and title. 423 // a custom spacing between the button image and title.
424 @interface CustomPaddingImageButtonCell : NSButtonCell { 424 @interface CustomPaddingImageButtonCell : NSButtonCell {
425 @private 425 @private
426 // Padding added to the left margin of the button. 426 // Padding added to the leading margin of the button.
427 int leftMarginSpacing_; 427 int leadingMarginSpacing_;
428 // Spacing between the cell image and title. 428 // Spacing between the cell image and title.
429 int imageTitleSpacing_; 429 int imageTitleSpacing_;
430 // Padding added to the right margin of the button. 430 // Padding added to the traling margin of the button.
431 int rightMarginSpacing_; 431 int trailingMarginSpacing_;
432 } 432 }
433 433
434 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing 434 - (id)initWithLeadingMarginSpacing:(int)leadingMarginSpacing
435 imageTitleSpacing:(int)imageTitleSpacing; 435 imageTitleSpacing:(int)imageTitleSpacing;
436 436
437 - (void)setRightMarginSpacing:(int)rightMarginSpacing; 437 - (void)setTrailingMarginSpacing:(int)trailingMarginSpacing;
438 @end 438 @end
439 439
440 @implementation CustomPaddingImageButtonCell 440 @implementation CustomPaddingImageButtonCell
441 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing 441 - (id)initWithLeadingMarginSpacing:(int)leadingMarginSpacing
442 imageTitleSpacing:(int)imageTitleSpacing { 442 imageTitleSpacing:(int)imageTitleSpacing {
443 if ((self = [super init])) { 443 if ((self = [super init])) {
444 leftMarginSpacing_ = leftMarginSpacing; 444 leadingMarginSpacing_ = leadingMarginSpacing;
445 imageTitleSpacing_ = imageTitleSpacing; 445 imageTitleSpacing_ = imageTitleSpacing;
446 } 446 }
447 return self; 447 return self;
448 } 448 }
449 449
450 - (void)setRightMarginSpacing:(int)rightMarginSpacing { 450 - (void)setTrailingMarginSpacing:(int)trailingMarginSpacing {
451 rightMarginSpacing_ = rightMarginSpacing; 451 trailingMarginSpacing_ = trailingMarginSpacing;
452 } 452 }
453 453
454 - (NSRect)drawTitle:(NSAttributedString*)title 454 - (NSRect)drawTitle:(NSAttributedString*)title
455 withFrame:(NSRect)frame 455 withFrame:(NSRect)frame
456 inView:(NSView*)controlView { 456 inView:(NSView*)controlView {
457 NSRect marginRect; 457 NSRect marginRect;
458 NSDivideRect(frame, &marginRect, &frame, leftMarginSpacing_, NSMinXEdge); 458 NSDivideRect(frame, &marginRect, &frame, leadingMarginSpacing_,
459 459 cocoa_l10n_util::LeadingEdge());
460 // The title frame origin isn't aware of the left margin spacing added 460 // The title frame origin isn't aware of the leading margin spacing added
461 // in -drawImage, so it must be added when drawing the title as well. 461 // in -drawImage, so it must be added when drawing the title as well.
462 if ([self imagePosition] == NSImageLeft) 462 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_,
463 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge); 463 cocoa_l10n_util::LeadingEdge());
464 464 NSDivideRect(frame, &marginRect, &frame, trailingMarginSpacing_,
465 NSDivideRect(frame, &marginRect, &frame, rightMarginSpacing_, NSMaxXEdge); 465 cocoa_l10n_util::TrailingEdge());
466 466
467 return [super drawTitle:title withFrame:frame inView:controlView]; 467 return [super drawTitle:title withFrame:frame inView:controlView];
468 } 468 }
469 469
470 - (void)drawImage:(NSImage*)image 470 - (void)drawImage:(NSImage*)image
471 withFrame:(NSRect)frame 471 withFrame:(NSRect)frame
472 inView:(NSView*)controlView { 472 inView:(NSView*)controlView {
473 if ([self imagePosition] == NSImageLeft) 473 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout())
474 frame.origin.x = leftMarginSpacing_; 474 frame.origin.x -= leadingMarginSpacing_;
475 else
476 frame.origin.x = leadingMarginSpacing_;
475 [super drawImage:image withFrame:frame inView:controlView]; 477 [super drawImage:image withFrame:frame inView:controlView];
476 } 478 }
477 479
478 - (NSSize)cellSize { 480 - (NSSize)cellSize {
479 NSSize buttonSize = [super cellSize]; 481 NSSize buttonSize = [super cellSize];
480 buttonSize.width += leftMarginSpacing_; 482 buttonSize.width += leadingMarginSpacing_;
481 if ([self imagePosition] == NSImageLeft) 483 buttonSize.width += imageTitleSpacing_;
482 buttonSize.width += imageTitleSpacing_;
483 return buttonSize; 484 return buttonSize;
484 } 485 }
485 486
486 - (NSFocusRingType)focusRingType { 487 - (NSFocusRingType)focusRingType {
487 // This is taken care of by the custom drawing code. 488 // This is taken care of by the custom drawing code.
488 return NSFocusRingTypeNone; 489 return NSFocusRingTypeNone;
489 } 490 }
490 491
491 - (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView { 492 - (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView {
492 [super drawInteriorWithFrame:frame inView:controlView]; 493 [super drawInteriorWithFrame:frame inView:controlView];
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 556 }
556 @end 557 @end
557 558
558 // A custom button that allows for setting a background color when hovered over. 559 // A custom button that allows for setting a background color when hovered over.
559 @interface BackgroundColorHoverButton : HoverImageButton { 560 @interface BackgroundColorHoverButton : HoverImageButton {
560 @private 561 @private
561 base::scoped_nsobject<NSColor> backgroundColor_; 562 base::scoped_nsobject<NSColor> backgroundColor_;
562 base::scoped_nsobject<NSColor> hoverColor_; 563 base::scoped_nsobject<NSColor> hoverColor_;
563 } 564 }
564 565
565 - (void)setRightMarginSpacing:(int)rightMarginSpacing; 566 - (void)setTrailingMarginSpacing:(int)trailingMarginSpacing;
566 @end 567 @end
567 568
568 @implementation BackgroundColorHoverButton 569 @implementation BackgroundColorHoverButton
569 570
570 - (id)initWithFrame:(NSRect)frameRect 571 - (id)initWithFrame:(NSRect)frameRect
571 imageTitleSpacing:(int)imageTitleSpacing 572 imageTitleSpacing:(int)imageTitleSpacing
572 backgroundColor:(NSColor*)backgroundColor { 573 backgroundColor:(NSColor*)backgroundColor {
573 if ((self = [super initWithFrame:frameRect])) { 574 if ((self = [super initWithFrame:frameRect])) {
574 backgroundColor_.reset([backgroundColor retain]); 575 backgroundColor_.reset([backgroundColor retain]);
575 hoverColor_.reset([skia::SkColorToSRGBNSColor(profiles::kHoverColor) 576 hoverColor_.reset([skia::SkColorToSRGBNSColor(profiles::kHoverColor)
576 retain]); 577 retain]);
577 578
578 [self setBordered:NO]; 579 [self setBordered:NO];
579 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; 580 [self setFont:[NSFont labelFontOfSize:kTextFontSize]];
580 [self setButtonType:NSMomentaryChangeButton]; 581 [self setButtonType:NSMomentaryChangeButton];
581 582
582 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( 583 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
583 [[CustomPaddingImageButtonCell alloc] 584 [[CustomPaddingImageButtonCell alloc]
584 initWithLeftMarginSpacing:kHorizontalSpacing 585 initWithLeadingMarginSpacing:kHorizontalSpacing
585 imageTitleSpacing:imageTitleSpacing]); 586 imageTitleSpacing:imageTitleSpacing]);
586 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; 587 [cell setLineBreakMode:NSLineBreakByTruncatingTail];
587 [cell setHighlightsBy:NSNoCellMask]; 588 [cell setHighlightsBy:NSNoCellMask];
588 [self setCell:cell.get()]; 589 [self setCell:cell.get()];
589 } 590 }
590 return self; 591 return self;
591 } 592 }
592 593
593 - (void)setRightMarginSpacing:(int)rightMarginSpacing { 594 - (void)setTrailingMarginSpacing:(int)trailingMarginSpacing {
594 [[self cell] setRightMarginSpacing:rightMarginSpacing]; 595 [[self cell] setTrailingMarginSpacing:trailingMarginSpacing];
595 } 596 }
596 597
597 - (void)drawRect:(NSRect)dirtyRect { 598 - (void)drawRect:(NSRect)dirtyRect {
598 if ([self isEnabled]) { 599 if ([self isEnabled]) {
599 bool isHighlighted = ([self hoverState] != kHoverStateNone); 600 bool isHighlighted = ([self hoverState] != kHoverStateNone);
600 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; 601 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_;
601 [[self cell] setBackgroundColor:backgroundColor]; 602 [[self cell] setBackgroundColor:backgroundColor];
602 } 603 }
603 [super drawRect:dirtyRect]; 604 [super drawRect:dirtyRect];
604 } 605 }
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 1580
1580 [container 1581 [container
1581 setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset + kVerticalSpacing)]; 1582 setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset + kVerticalSpacing)];
1582 return container.autorelease(); 1583 return container.autorelease();
1583 } 1584 }
1584 1585
1585 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { 1586 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item {
1586 base::scoped_nsobject<NSView> container( 1587 base::scoped_nsobject<NSView> container(
1587 [[NSView alloc] initWithFrame:NSZeroRect]); 1588 [[NSView alloc] initWithFrame:NSZeroRect]);
1588 1589
1590 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
1589 CGFloat xOffset = kHorizontalSpacing; 1591 CGFloat xOffset = kHorizontalSpacing;
1590 CGFloat yOffset = 0.0; 1592 CGFloat yOffset = 0.0;
1591 CGFloat cardYOffset = kRelatedControllVerticalSpacing; 1593 CGFloat cardYOffset = kRelatedControllVerticalSpacing;
1592 CGFloat availableTextWidth = 1594 CGFloat availableTextWidth =
1593 kFixedMenuWidth - 3.0 * kHorizontalSpacing - kMdImageSide; 1595 kFixedMenuWidth - 3.0 * kHorizontalSpacing - kMdImageSide;
1594 CGFloat maxAvailableTextWidth = kFixedMenuWidth - kHorizontalSpacing; 1596 CGFloat maxAvailableTextWidth = kFixedMenuWidth - kHorizontalSpacing;
1595 1597
1596 // Profile options. This can be a link to the accounts view, or a "Sign in" 1598 // Profile options. This can be a link to the accounts view, or a "Sign in"
1597 // button for local profiles. 1599 // button for local profiles.
1598 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( 1600 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1645
1644 // Profile badge for supervised account. 1646 // Profile badge for supervised account.
1645 if (browser_->profile()->IsSupervised()) { 1647 if (browser_->profile()->IsSupervised()) {
1646 // Draw a circle as the background of the badge icon. 1648 // Draw a circle as the background of the badge icon.
1647 constexpr int badgeSize = 24; 1649 constexpr int badgeSize = 24;
1648 constexpr int badgeSpacing = 4; 1650 constexpr int badgeSpacing = 4;
1649 NSRect badgeIconCircleFrame = 1651 NSRect badgeIconCircleFrame =
1650 NSMakeRect(xOffset + kMdImageSide - badgeSize + badgeSpacing, 1652 NSMakeRect(xOffset + kMdImageSide - badgeSize + badgeSpacing,
1651 cardYOffset + kMdImageSide - badgeSize + badgeSpacing, 1653 cardYOffset + kMdImageSide - badgeSize + badgeSpacing,
1652 badgeSize, badgeSize); 1654 badgeSize, badgeSize);
1655 if (isRTL) {
1656 badgeIconCircleFrame.origin.x = NSWidth([profileCard frame]) -
1657 NSWidth(badgeIconCircleFrame) -
1658 NSMinX(badgeIconCircleFrame);
1659 }
1653 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ 1660 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([
1654 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame 1661 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame
1655 withFillColor:GetDialogBackgroundColor()]); 1662 withFillColor:GetDialogBackgroundColor()]);
1656 // Add the badge icon. 1663 // Add the badge icon.
1657 constexpr int borderWidth = 1; 1664 constexpr int borderWidth = 1;
1658 const int badgeIconSize = badgeSize - borderWidth * 2; 1665 const int badgeIconSize = badgeSize - borderWidth * 2;
1659 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] 1666 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc]
1660 initWithFrame:NSMakeRect(borderWidth, borderWidth, 1667 initWithFrame:NSMakeRect(borderWidth, borderWidth,
1661 badgeIconSize, badgeIconSize)]); 1668 badgeIconSize, badgeIconSize)]);
1662 const gfx::VectorIcon& badgeIcon = browser_->profile()->IsChild() 1669 const gfx::VectorIcon& badgeIcon = browser_->profile()->IsChild()
1663 ? kAccountChildCircleIcon 1670 ? kAccountChildCircleIcon
1664 : kSupervisorAccountCircleIcon; 1671 : kSupervisorAccountCircleIcon;
1665 [badgeIconView 1672 [badgeIconView
1666 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( 1673 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon(
1667 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; 1674 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))];
1668 [badgeIconWithCircle addSubview:badgeIconView]; 1675 [badgeIconWithCircle addSubview:badgeIconView];
1669 1676
1670 [profileCard addSubview:badgeIconWithCircle]; 1677 [profileCard addSubview:badgeIconWithCircle];
1671 } 1678 }
1672 1679 if (!isRTL)
1673 // Profile name, left-aligned to the right of profile icon. 1680 xOffset += kMdImageSide + kHorizontalSpacing;
1674 xOffset += kMdImageSide + kHorizontalSpacing;
1675 CGFloat fontSize = kTextFontSize + 1.0; 1681 CGFloat fontSize = kTextFontSize + 1.0;
1676 NSString* profileNameNSString = base::SysUTF16ToNSString(profileNameString); 1682 NSString* profileNameNSString = base::SysUTF16ToNSString(profileNameString);
1677 NSTextField* profileName = BuildLabel(profileNameNSString, NSZeroPoint, nil); 1683 NSTextField* profileName = BuildLabel(profileNameNSString, NSZeroPoint, nil);
1678 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 1684 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1679 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; 1685 [profileName setFont:[NSFont labelFontOfSize:fontSize]];
1680 [profileName sizeToFit]; 1686 [profileName sizeToFit];
1681 const int profileNameYOffset = 1687 const int profileNameYOffset =
1682 cardYOffset + 1688 cardYOffset +
1683 std::floor((kMdImageSide - NSHeight([profileName frame])) / 2); 1689 std::floor((kMdImageSide - NSHeight([profileName frame])) / 2);
1684 if (profileName.frame.size.width > availableTextWidth) { 1690 if (profileName.frame.size.width > availableTextWidth) {
1685 // Add the tooltip only if the profile name is truncated. This method to 1691 // Add the tooltip only if the profile name is truncated. This method to
1686 // test if text field is truncated is not ideal (spaces between characters 1692 // test if text field is truncated is not ideal (spaces between characters
1687 // may be reduced to avoid truncation). 1693 // may be reduced to avoid truncation).
1688 profileName.toolTip = profileNameNSString; 1694 profileName.toolTip = profileNameNSString;
1689 } 1695 }
1690 [profileName 1696 [profileName
1691 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth, 1697 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth,
1692 NSHeight([profileName frame]))]; 1698 NSHeight([profileName frame]))];
1693 [profileCard addSubview:profileName]; 1699 [profileCard addSubview:profileName];
1694 1700
1695 // Username, left-aligned to the right of profile icon and below the profile 1701 // Username, aligned to the leading edge of the profile icon and
1696 // name. 1702 // below the profile name.
1697 if (item.signed_in && !switches::IsEnableAccountConsistency()) { 1703 if (item.signed_in && !switches::IsEnableAccountConsistency()) {
1698 // Adjust the y-position of profile name to leave space for username. 1704 // Adjust the y-position of profile name to leave space for username.
1699 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; 1705 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height;
1700 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; 1706 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)];
1701 1707
1702 NSString* elidedEmail = 1708 NSString* elidedEmail =
1703 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth); 1709 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth);
1704 NSTextField* username = BuildLabel( 1710 NSTextField* username = BuildLabel(
1705 elidedEmail, NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); 1711 elidedEmail, NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
1706 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; 1712 CGFloat usernameOffset =
1713 isRTL ? NSMaxX([profileName frame]) - NSWidth([username frame])
1714 : xOffset;
1715 [username setFrameOrigin:NSMakePoint(usernameOffset,
1716 NSMaxY([profileName frame]))];
1707 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); 1717 NSString* usernameNSString = base::SysUTF16ToNSString(item.username);
1708 if (![elidedEmail isEqualToString:usernameNSString]) { 1718 if (![elidedEmail isEqualToString:usernameNSString]) {
1709 // Add the tooltip only if the user name is truncated. 1719 // Add the tooltip only if the user name is truncated.
1710 username.toolTip = usernameNSString; 1720 username.toolTip = usernameNSString;
1711 } 1721 }
1712 [profileCard addSubview:username]; 1722 [profileCard addSubview:username];
1713 } 1723 }
1714 1724
1715 yOffset = NSMaxY([profileCard frame]); 1725 yOffset = NSMaxY([profileCard frame]);
1716 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1726 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( 1782 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText(
1773 l10n_util::GetStringFUTF16( 1783 l10n_util::GetStringFUTF16(
1774 IDS_SYNC_START_SYNC_BUTTON_LABEL, 1784 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1775 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), 1785 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)),
1776 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); 1786 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL));
1777 1787
1778 [signinButton setTitle:elidedButtonText]; 1788 [signinButton setTitle:elidedButtonText];
1779 [signinButton sizeToFit]; 1789 [signinButton sizeToFit];
1780 [signinButton setTarget:self]; 1790 [signinButton setTarget:self];
1781 [signinButton setAction:@selector(showInlineSigninPage:)]; 1791 [signinButton setAction:@selector(showInlineSigninPage:)];
1792 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
1793 NSRect buttonFrame = [signinButton frame];
1794 buttonFrame.origin.x = NSWidth(rect) - NSWidth(buttonFrame);
1795 [signinButton setFrame:buttonFrame];
1796 }
1782 [container addSubview:signinButton]; 1797 [container addSubview:signinButton];
1783 1798
1784 // Sign-in promo text. 1799 // Sign-in promo text.
1785 NSTextField* promo = BuildLabel( 1800 NSTextField* promo = BuildLabel(
1786 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), 1801 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO),
1787 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), 1802 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing),
1788 nil); 1803 nil);
1789 if (kRightPadding >= 8) 1804 if (kRightPadding >= 8 &&
1805 !cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
1790 rect.size.width += 8; // Re-stretch a little bit to fit promo text. 1806 rect.size.width += 8; // Re-stretch a little bit to fit promo text.
1807 }
1791 DCHECK(kRightPadding >= 8); 1808 DCHECK(kRightPadding >= 8);
1792 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; 1809 [promo setFrameSize:NSMakeSize(rect.size.width, 0)];
1793 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; 1810 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo];
1794 [container addSubview:promo]; 1811 [container addSubview:promo];
1795 1812
1796 [container setFrameSize:NSMakeSize(rect.size.width, 1813 [container setFrameSize:NSMakeSize(rect.size.width,
1797 NSMaxY([promo frame]) + 1814 NSMaxY([promo frame]) +
1798 kRelatedControllVerticalSpacing)]; 1815 kRelatedControllVerticalSpacing)];
1799 base::RecordAction( 1816 base::RecordAction(
1800 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 1817 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); 1857 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex);
1841 1858
1842 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth, 1859 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth,
1843 kBlueButtonHeight + kSmallVerticalSpacing); 1860 kBlueButtonHeight + kSmallVerticalSpacing);
1844 const int imageTitleSpacing = kHorizontalSpacing; 1861 const int imageTitleSpacing = kHorizontalSpacing;
1845 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( 1862 base::scoped_nsobject<BackgroundColorHoverButton> profileButton(
1846 [[BackgroundColorHoverButton alloc] 1863 [[BackgroundColorHoverButton alloc]
1847 initWithFrame:rect 1864 initWithFrame:rect
1848 imageTitleSpacing:imageTitleSpacing 1865 imageTitleSpacing:imageTitleSpacing
1849 backgroundColor:GetDialogBackgroundColor()]); 1866 backgroundColor:GetDialogBackgroundColor()]);
1850 [profileButton setRightMarginSpacing:kHorizontalSpacing]; 1867 [profileButton setTrailingMarginSpacing:kHorizontalSpacing];
1851 1868
1852 NSString* title = base::SysUTF16ToNSString( 1869 NSString* title = base::SysUTF16ToNSString(
1853 profiles::GetProfileSwitcherTextForItem(item)); 1870 profiles::GetProfileSwitcherTextForItem(item));
1854 [profileButton setTitle:title]; 1871 [profileButton setTitle:title];
1855 1872
1856 CGFloat availableWidth; 1873 CGFloat availableWidth;
1857 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide, 1874 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide,
1858 profiles::SHAPE_CIRCLE)]; 1875 profiles::SHAPE_CIRCLE)];
1859 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing - 1876 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing -
1860 2 * kHorizontalSpacing; 1877 2 * kHorizontalSpacing;
1861 1878
1862 [profileButton setImagePosition:NSImageLeft]; 1879 [profileButton setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()];
1863 [profileButton setAlignment:NSLeftTextAlignment]; 1880 [profileButton setAlignment:NSNaturalTextAlignment];
1864 [profileButton setBordered:NO]; 1881 [profileButton setBordered:NO];
1865 [profileButton setTag:itemIndex]; 1882 [profileButton setTag:itemIndex];
1866 [profileButton setTarget:self]; 1883 [profileButton setTarget:self];
1867 [profileButton setAction:@selector(switchToProfile:)]; 1884 [profileButton setAction:@selector(switchToProfile:)];
1868 1885
1869 return profileButton.autorelease(); 1886 return profileButton.autorelease();
1870 } 1887 }
1871 1888
1872 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { 1889 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect {
1873 const CGFloat kAccountButtonHeight = 34; 1890 const CGFloat kAccountButtonHeight = 34;
(...skipping 16 matching lines...) Expand all
1890 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( 1907 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText(
1891 l10n_util::GetStringFUTF16( 1908 l10n_util::GetStringFUTF16(
1892 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name), 1909 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name),
1893 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); 1910 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL));
1894 1911
1895 NSButton* addAccountsButton = 1912 NSButton* addAccountsButton =
1896 [self linkButtonWithTitle:elidedButtonText 1913 [self linkButtonWithTitle:elidedButtonText
1897 frameOrigin:NSMakePoint( 1914 frameOrigin:NSMakePoint(
1898 kHorizontalSpacing, kSmallVerticalSpacing) 1915 kHorizontalSpacing, kSmallVerticalSpacing)
1899 action:@selector(addAccount:)]; 1916 action:@selector(addAccount:)];
1917 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
1918 CGRect addAccountsButtonFrame = [addAccountsButton frame];
1919 addAccountsButtonFrame.origin.x = NSMaxX(rect) -
1920 NSWidth(addAccountsButtonFrame) -
1921 NSMinX(addAccountsButtonFrame);
1922 [addAccountsButton setFrame:addAccountsButtonFrame];
1923 }
1924
1900 [container addSubview:addAccountsButton]; 1925 [container addSubview:addAccountsButton];
1901 rect.origin.y += kAccountButtonHeight; 1926 rect.origin.y += kAccountButtonHeight;
1902 } 1927 }
1903 1928
1904 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( 1929 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect(
1905 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; 1930 0, rect.origin.y, rect.size.width, kAccountButtonHeight)];
1906 [container addSubview:accountEmails]; 1931 [container addSubview:accountEmails];
1907 1932
1908 [container setFrameSize:NSMakeSize(rect.size.width, 1933 [container setFrameSize:NSMakeSize(rect.size.width,
1909 NSMaxY([accountEmails frame]))]; 1934 NSMaxY([accountEmails frame]))];
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 2268
2244 - (NSButton*)hoverButtonWithRect:(NSRect)rect 2269 - (NSButton*)hoverButtonWithRect:(NSRect)rect
2245 text:(NSString*)text 2270 text:(NSString*)text
2246 image:(NSImage*)image 2271 image:(NSImage*)image
2247 action:(SEL)action { 2272 action:(SEL)action {
2248 BackgroundColorHoverButton* button = 2273 BackgroundColorHoverButton* button =
2249 [self hoverButtonWithRect:rect text:text action:action]; 2274 [self hoverButtonWithRect:rect text:text action:action];
2250 [button setDefaultImage:image]; 2275 [button setDefaultImage:image];
2251 [button setHoverImage:image]; 2276 [button setHoverImage:image];
2252 [button setPressedImage:image]; 2277 [button setPressedImage:image];
2253 [button setImagePosition:NSImageLeft]; 2278 [button setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()];
2254 2279
2255 return button; 2280 return button;
2256 } 2281 }
2257 2282
2258 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect 2283 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect
2259 text:(NSString*)text 2284 text:(NSString*)text
2260 action:(SEL)action { 2285 action:(SEL)action {
2261 // The vector icons in hover buttons have small embeded paddings and are 2286 // The vector icons in hover buttons have small embeded paddings and are
2262 // therefore given an extra 2px in size to have a consistent look as the 2287 // therefore given an extra 2px in size to have a consistent look as the
2263 // profile icons; hence the -2.0 here to left align the hover button texts 2288 // profile icons; hence the -2.0 here to left align the hover button texts
2264 // with those of profile buttons. 2289 // with those of profile buttons.
2265 const int image_title_spacing = kHorizontalSpacing - 2.0; 2290 const int image_title_spacing = kHorizontalSpacing - 2.0;
2266 2291
2267 base::scoped_nsobject<BackgroundColorHoverButton> button( 2292 base::scoped_nsobject<BackgroundColorHoverButton> button(
2268 [[BackgroundColorHoverButton alloc] 2293 [[BackgroundColorHoverButton alloc]
2269 initWithFrame:rect 2294 initWithFrame:rect
2270 imageTitleSpacing:image_title_spacing 2295 imageTitleSpacing:image_title_spacing
2271 backgroundColor:GetDialogBackgroundColor()]); 2296 backgroundColor:GetDialogBackgroundColor()]);
2272 2297
2273 [button setTitle:text]; 2298 [button setTitle:text];
2274 [button setAlignment:NSLeftTextAlignment]; 2299 [button setAlignment:NSNaturalTextAlignment];
2275 [button setBordered:NO]; 2300 [button setBordered:NO];
2276 [button setTarget:self]; 2301 [button setTarget:self];
2277 [button setAction:action]; 2302 [button setAction:action];
2278 2303
2279 return button.autorelease(); 2304 return button.autorelease();
2280 } 2305 }
2281 2306
2282 - (NSButton*)linkButtonWithTitle:(NSString*)title 2307 - (NSButton*)linkButtonWithTitle:(NSString*)title
2283 frameOrigin:(NSPoint)frameOrigin 2308 frameOrigin:(NSPoint)frameOrigin
2284 action:(SEL)action { 2309 action:(SEL)action {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 if (warningImage) 2343 if (warningImage)
2319 availableTextWidth -= kHorizontalSpacing; 2344 availableTextWidth -= kHorizontalSpacing;
2320 2345
2321 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( 2346 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor(
2322 profiles::kAvatarBubbleAccountsBackgroundColor); 2347 profiles::kAvatarBubbleAccountsBackgroundColor);
2323 base::scoped_nsobject<BackgroundColorHoverButton> button( 2348 base::scoped_nsobject<BackgroundColorHoverButton> button(
2324 [[BackgroundColorHoverButton alloc] initWithFrame:rect 2349 [[BackgroundColorHoverButton alloc] initWithFrame:rect
2325 imageTitleSpacing:0 2350 imageTitleSpacing:0
2326 backgroundColor:backgroundColor]); 2351 backgroundColor:backgroundColor]);
2327 [button setTitle:ElideEmail(email, availableTextWidth)]; 2352 [button setTitle:ElideEmail(email, availableTextWidth)];
2328 [button setAlignment:NSLeftTextAlignment]; 2353 [button setAlignment:NSNaturalTextAlignment];
2329 [button setBordered:NO]; 2354 [button setBordered:NO];
2330 if (reauthRequired) { 2355 if (reauthRequired) {
2331 [button setDefaultImage:warningImage]; 2356 [button setDefaultImage:warningImage];
2332 [button setImagePosition:NSImageLeft]; 2357 [button setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()];
2333 [button setTarget:self]; 2358 [button setTarget:self];
2334 [button setAction:@selector(showAccountReauthenticationView:)]; 2359 [button setAction:@selector(showAccountReauthenticationView:)];
2335 [button setTag:tag]; 2360 [button setTag:tag];
2336 } 2361 }
2337 2362
2338 // Delete button. 2363 // Delete button.
2339 if (!browser_->profile()->IsSupervised()) { 2364 if (!browser_->profile()->IsSupervised()) {
2340 NSRect buttonRect; 2365 NSRect buttonRect;
2341 NSDivideRect(rect, &buttonRect, &rect, 2366 NSDivideRect(rect, &buttonRect, &rect,
2342 deleteImageWidth + kHorizontalSpacing, NSMaxXEdge); 2367 deleteImageWidth + kHorizontalSpacing,
2368 cocoa_l10n_util::TrailingEdge());
2343 buttonRect.origin.y = 0; 2369 buttonRect.origin.y = 0;
2344 2370
2345 base::scoped_nsobject<HoverImageButton> deleteButton( 2371 base::scoped_nsobject<HoverImageButton> deleteButton(
2346 [[HoverImageButton alloc] initWithFrame:buttonRect]); 2372 [[HoverImageButton alloc] initWithFrame:buttonRect]);
2347 [deleteButton setBordered:NO]; 2373 [deleteButton setBordered:NO];
2348 [deleteButton setDefaultImage:deleteImage]; 2374 [deleteButton setDefaultImage:deleteImage];
2349 [deleteButton setHoverImage:rb->GetNativeImageNamed( 2375 [deleteButton setHoverImage:rb->GetNativeImageNamed(
2350 IDR_CLOSE_1_H).ToNSImage()]; 2376 IDR_CLOSE_1_H).ToNSImage()];
2351 [deleteButton setPressedImage:rb->GetNativeImageNamed( 2377 [deleteButton setPressedImage:rb->GetNativeImageNamed(
2352 IDR_CLOSE_1_P).ToNSImage()]; 2378 IDR_CLOSE_1_P).ToNSImage()];
(...skipping 21 matching lines...) Expand all
2374 2400
2375 - (void)showWindow:(id)sender { 2401 - (void)showWindow:(id)sender {
2376 [super showWindow:sender]; 2402 [super showWindow:sender];
2377 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; 2403 NSEvent *event = [[NSApplication sharedApplication] currentEvent];
2378 if (firstProfileView_ && [event type] == NSKeyDown) { 2404 if (firstProfileView_ && [event type] == NSKeyDown) {
2379 [[self window] makeFirstResponder:firstProfileView_]; 2405 [[self window] makeFirstResponder:firstProfileView_];
2380 } 2406 }
2381 } 2407 }
2382 2408
2383 @end 2409 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/l10n_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698