Chromium Code Reviews| 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 "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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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) | |
|
Elly Fong-Jones
2017/05/24 18:55:27
multi-line if bodies need {}
lgrey
2017/05/24 19:41:10
Done.
| |
| 1656 badgeIconCircleFrame.origin.x = NSWidth([profileCard frame]) - | |
| 1657 NSWidth(badgeIconCircleFrame) - | |
| 1658 NSMinX(badgeIconCircleFrame); | |
| 1653 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ | 1659 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ |
| 1654 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame | 1660 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame |
| 1655 withFillColor:GetDialogBackgroundColor()]); | 1661 withFillColor:GetDialogBackgroundColor()]); |
| 1656 // Add the badge icon. | 1662 // Add the badge icon. |
| 1657 constexpr int borderWidth = 1; | 1663 constexpr int borderWidth = 1; |
| 1658 const int badgeIconSize = badgeSize - borderWidth * 2; | 1664 const int badgeIconSize = badgeSize - borderWidth * 2; |
| 1659 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] | 1665 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] |
| 1660 initWithFrame:NSMakeRect(borderWidth, borderWidth, | 1666 initWithFrame:NSMakeRect(borderWidth, borderWidth, |
| 1661 badgeIconSize, badgeIconSize)]); | 1667 badgeIconSize, badgeIconSize)]); |
| 1662 const gfx::VectorIcon& badgeIcon = browser_->profile()->IsChild() | 1668 const gfx::VectorIcon& badgeIcon = browser_->profile()->IsChild() |
| 1663 ? kAccountChildCircleIcon | 1669 ? kAccountChildCircleIcon |
| 1664 : kSupervisorAccountCircleIcon; | 1670 : kSupervisorAccountCircleIcon; |
| 1665 [badgeIconView | 1671 [badgeIconView |
| 1666 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | 1672 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 1667 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; | 1673 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; |
| 1668 [badgeIconWithCircle addSubview:badgeIconView]; | 1674 [badgeIconWithCircle addSubview:badgeIconView]; |
| 1669 | 1675 |
| 1670 [profileCard addSubview:badgeIconWithCircle]; | 1676 [profileCard addSubview:badgeIconWithCircle]; |
| 1671 } | 1677 } |
| 1672 | 1678 if (!isRTL) |
| 1673 // Profile name, left-aligned to the right of profile icon. | 1679 xOffset += kMdImageSide + kHorizontalSpacing; |
| 1674 xOffset += kMdImageSide + kHorizontalSpacing; | |
| 1675 CGFloat fontSize = kTextFontSize + 1.0; | 1680 CGFloat fontSize = kTextFontSize + 1.0; |
| 1676 NSString* profileNameNSString = base::SysUTF16ToNSString(profileNameString); | 1681 NSString* profileNameNSString = base::SysUTF16ToNSString(profileNameString); |
| 1677 NSTextField* profileName = BuildLabel(profileNameNSString, NSZeroPoint, nil); | 1682 NSTextField* profileName = BuildLabel(profileNameNSString, NSZeroPoint, nil); |
| 1678 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 1683 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 1679 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; | 1684 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; |
| 1680 [profileName sizeToFit]; | 1685 [profileName sizeToFit]; |
| 1681 const int profileNameYOffset = | 1686 const int profileNameYOffset = |
| 1682 cardYOffset + | 1687 cardYOffset + |
| 1683 std::floor((kMdImageSide - NSHeight([profileName frame])) / 2); | 1688 std::floor((kMdImageSide - NSHeight([profileName frame])) / 2); |
| 1684 if (profileName.frame.size.width > availableTextWidth) { | 1689 if (profileName.frame.size.width > availableTextWidth) { |
| 1685 // Add the tooltip only if the profile name is truncated. This method to | 1690 // 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 | 1691 // test if text field is truncated is not ideal (spaces between characters |
| 1687 // may be reduced to avoid truncation). | 1692 // may be reduced to avoid truncation). |
| 1688 profileName.toolTip = profileNameNSString; | 1693 profileName.toolTip = profileNameNSString; |
| 1689 } | 1694 } |
| 1690 [profileName | 1695 [profileName |
| 1691 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth, | 1696 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth, |
| 1692 NSHeight([profileName frame]))]; | 1697 NSHeight([profileName frame]))]; |
| 1693 [profileCard addSubview:profileName]; | 1698 [profileCard addSubview:profileName]; |
| 1694 | 1699 |
| 1695 // Username, left-aligned to the right of profile icon and below the profile | 1700 // Username, aligned to the leading edge of the profile icon and |
| 1696 // name. | 1701 // below the profile name. |
| 1697 if (item.signed_in && !switches::IsEnableAccountConsistency()) { | 1702 if (item.signed_in && !switches::IsEnableAccountConsistency()) { |
| 1698 // Adjust the y-position of profile name to leave space for username. | 1703 // Adjust the y-position of profile name to leave space for username. |
| 1699 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; | 1704 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; |
| 1700 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; | 1705 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; |
| 1701 | 1706 |
| 1702 NSString* elidedEmail = | 1707 NSString* elidedEmail = |
| 1703 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth); | 1708 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth); |
| 1704 NSTextField* username = BuildLabel( | 1709 NSTextField* username = BuildLabel( |
| 1705 elidedEmail, NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); | 1710 elidedEmail, NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); |
| 1706 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; | 1711 CGFloat usernameOffset = |
| 1712 isRTL ? NSMaxX([profileName frame]) - NSWidth([username frame]) | |
| 1713 : xOffset; | |
| 1714 [username setFrameOrigin:NSMakePoint(usernameOffset, | |
| 1715 NSMaxY([profileName frame]))]; | |
| 1707 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); | 1716 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); |
| 1708 if (![elidedEmail isEqualToString:usernameNSString]) { | 1717 if (![elidedEmail isEqualToString:usernameNSString]) { |
| 1709 // Add the tooltip only if the user name is truncated. | 1718 // Add the tooltip only if the user name is truncated. |
| 1710 username.toolTip = usernameNSString; | 1719 username.toolTip = usernameNSString; |
| 1711 } | 1720 } |
| 1712 [profileCard addSubview:username]; | 1721 [profileCard addSubview:username]; |
| 1713 } | 1722 } |
| 1714 | 1723 |
| 1715 yOffset = NSMaxY([profileCard frame]); | 1724 yOffset = NSMaxY([profileCard frame]); |
| 1716 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | 1725 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | 1781 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( |
| 1773 l10n_util::GetStringFUTF16( | 1782 l10n_util::GetStringFUTF16( |
| 1774 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 1783 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 1775 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | 1784 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), |
| 1776 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); | 1785 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); |
| 1777 | 1786 |
| 1778 [signinButton setTitle:elidedButtonText]; | 1787 [signinButton setTitle:elidedButtonText]; |
| 1779 [signinButton sizeToFit]; | 1788 [signinButton sizeToFit]; |
| 1780 [signinButton setTarget:self]; | 1789 [signinButton setTarget:self]; |
| 1781 [signinButton setAction:@selector(showInlineSigninPage:)]; | 1790 [signinButton setAction:@selector(showInlineSigninPage:)]; |
| 1791 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | |
| 1792 NSRect buttonFrame = [signinButton frame]; | |
| 1793 buttonFrame.origin.x = NSWidth(rect) - NSWidth(buttonFrame); | |
| 1794 [signinButton setFrame:buttonFrame]; | |
| 1795 } | |
| 1782 [container addSubview:signinButton]; | 1796 [container addSubview:signinButton]; |
| 1783 | 1797 |
| 1784 // Sign-in promo text. | 1798 // Sign-in promo text. |
| 1785 NSTextField* promo = BuildLabel( | 1799 NSTextField* promo = BuildLabel( |
| 1786 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), | 1800 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), |
| 1787 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), | 1801 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), |
| 1788 nil); | 1802 nil); |
| 1789 if (kRightPadding >= 8) | 1803 if (kRightPadding >= 8 && |
| 1804 !cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | |
| 1790 rect.size.width += 8; // Re-stretch a little bit to fit promo text. | 1805 rect.size.width += 8; // Re-stretch a little bit to fit promo text. |
| 1806 } | |
| 1791 DCHECK(kRightPadding >= 8); | 1807 DCHECK(kRightPadding >= 8); |
| 1792 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; | 1808 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; |
| 1793 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; | 1809 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; |
| 1794 [container addSubview:promo]; | 1810 [container addSubview:promo]; |
| 1795 | 1811 |
| 1796 [container setFrameSize:NSMakeSize(rect.size.width, | 1812 [container setFrameSize:NSMakeSize(rect.size.width, |
| 1797 NSMaxY([promo frame]) + | 1813 NSMaxY([promo frame]) + |
| 1798 kRelatedControllVerticalSpacing)]; | 1814 kRelatedControllVerticalSpacing)]; |
| 1799 base::RecordAction( | 1815 base::RecordAction( |
| 1800 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 1816 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1840 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); | 1856 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
| 1841 | 1857 |
| 1842 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth, | 1858 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth, |
| 1843 kBlueButtonHeight + kSmallVerticalSpacing); | 1859 kBlueButtonHeight + kSmallVerticalSpacing); |
| 1844 const int imageTitleSpacing = kHorizontalSpacing; | 1860 const int imageTitleSpacing = kHorizontalSpacing; |
| 1845 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( | 1861 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( |
| 1846 [[BackgroundColorHoverButton alloc] | 1862 [[BackgroundColorHoverButton alloc] |
| 1847 initWithFrame:rect | 1863 initWithFrame:rect |
| 1848 imageTitleSpacing:imageTitleSpacing | 1864 imageTitleSpacing:imageTitleSpacing |
| 1849 backgroundColor:GetDialogBackgroundColor()]); | 1865 backgroundColor:GetDialogBackgroundColor()]); |
| 1850 [profileButton setRightMarginSpacing:kHorizontalSpacing]; | 1866 [profileButton setTrailingMarginSpacing:kHorizontalSpacing]; |
| 1851 | 1867 |
| 1852 NSString* title = base::SysUTF16ToNSString( | 1868 NSString* title = base::SysUTF16ToNSString( |
| 1853 profiles::GetProfileSwitcherTextForItem(item)); | 1869 profiles::GetProfileSwitcherTextForItem(item)); |
| 1854 [profileButton setTitle:title]; | 1870 [profileButton setTitle:title]; |
| 1855 | 1871 |
| 1856 CGFloat availableWidth; | 1872 CGFloat availableWidth; |
| 1857 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide, | 1873 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide, |
| 1858 profiles::SHAPE_CIRCLE)]; | 1874 profiles::SHAPE_CIRCLE)]; |
| 1859 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing - | 1875 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing - |
| 1860 2 * kHorizontalSpacing; | 1876 2 * kHorizontalSpacing; |
| 1861 | 1877 |
| 1862 [profileButton setImagePosition:NSImageLeft]; | 1878 [profileButton setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()]; |
| 1863 [profileButton setAlignment:NSLeftTextAlignment]; | 1879 [profileButton setAlignment:NSNaturalTextAlignment]; |
| 1864 [profileButton setBordered:NO]; | 1880 [profileButton setBordered:NO]; |
| 1865 [profileButton setTag:itemIndex]; | 1881 [profileButton setTag:itemIndex]; |
| 1866 [profileButton setTarget:self]; | 1882 [profileButton setTarget:self]; |
| 1867 [profileButton setAction:@selector(switchToProfile:)]; | 1883 [profileButton setAction:@selector(switchToProfile:)]; |
| 1868 | 1884 |
| 1869 return profileButton.autorelease(); | 1885 return profileButton.autorelease(); |
| 1870 } | 1886 } |
| 1871 | 1887 |
| 1872 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { | 1888 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { |
| 1873 const CGFloat kAccountButtonHeight = 34; | 1889 const CGFloat kAccountButtonHeight = 34; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1890 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | 1906 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( |
| 1891 l10n_util::GetStringFUTF16( | 1907 l10n_util::GetStringFUTF16( |
| 1892 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name), | 1908 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name), |
| 1893 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); | 1909 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); |
| 1894 | 1910 |
| 1895 NSButton* addAccountsButton = | 1911 NSButton* addAccountsButton = |
| 1896 [self linkButtonWithTitle:elidedButtonText | 1912 [self linkButtonWithTitle:elidedButtonText |
| 1897 frameOrigin:NSMakePoint( | 1913 frameOrigin:NSMakePoint( |
| 1898 kHorizontalSpacing, kSmallVerticalSpacing) | 1914 kHorizontalSpacing, kSmallVerticalSpacing) |
| 1899 action:@selector(addAccount:)]; | 1915 action:@selector(addAccount:)]; |
| 1916 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | |
| 1917 CGRect addAccountsButtonFrame = [addAccountsButton frame]; | |
| 1918 addAccountsButtonFrame.origin.x = NSMaxX(rect) - | |
| 1919 NSWidth(addAccountsButtonFrame) - | |
| 1920 NSMinX(addAccountsButtonFrame); | |
| 1921 [addAccountsButton setFrame:addAccountsButtonFrame]; | |
| 1922 } | |
| 1923 | |
| 1900 [container addSubview:addAccountsButton]; | 1924 [container addSubview:addAccountsButton]; |
| 1901 rect.origin.y += kAccountButtonHeight; | 1925 rect.origin.y += kAccountButtonHeight; |
| 1902 } | 1926 } |
| 1903 | 1927 |
| 1904 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( | 1928 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( |
| 1905 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; | 1929 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; |
| 1906 [container addSubview:accountEmails]; | 1930 [container addSubview:accountEmails]; |
| 1907 | 1931 |
| 1908 [container setFrameSize:NSMakeSize(rect.size.width, | 1932 [container setFrameSize:NSMakeSize(rect.size.width, |
| 1909 NSMaxY([accountEmails frame]))]; | 1933 NSMaxY([accountEmails frame]))]; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2243 | 2267 |
| 2244 - (NSButton*)hoverButtonWithRect:(NSRect)rect | 2268 - (NSButton*)hoverButtonWithRect:(NSRect)rect |
| 2245 text:(NSString*)text | 2269 text:(NSString*)text |
| 2246 image:(NSImage*)image | 2270 image:(NSImage*)image |
| 2247 action:(SEL)action { | 2271 action:(SEL)action { |
| 2248 BackgroundColorHoverButton* button = | 2272 BackgroundColorHoverButton* button = |
| 2249 [self hoverButtonWithRect:rect text:text action:action]; | 2273 [self hoverButtonWithRect:rect text:text action:action]; |
| 2250 [button setDefaultImage:image]; | 2274 [button setDefaultImage:image]; |
| 2251 [button setHoverImage:image]; | 2275 [button setHoverImage:image]; |
| 2252 [button setPressedImage:image]; | 2276 [button setPressedImage:image]; |
| 2253 [button setImagePosition:NSImageLeft]; | 2277 [button setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()]; |
| 2254 | 2278 |
| 2255 return button; | 2279 return button; |
| 2256 } | 2280 } |
| 2257 | 2281 |
| 2258 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect | 2282 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect |
| 2259 text:(NSString*)text | 2283 text:(NSString*)text |
| 2260 action:(SEL)action { | 2284 action:(SEL)action { |
| 2261 // The vector icons in hover buttons have small embeded paddings and are | 2285 // 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 | 2286 // 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 | 2287 // profile icons; hence the -2.0 here to left align the hover button texts |
| 2264 // with those of profile buttons. | 2288 // with those of profile buttons. |
| 2265 const int image_title_spacing = kHorizontalSpacing - 2.0; | 2289 const int image_title_spacing = kHorizontalSpacing - 2.0; |
| 2266 | 2290 |
| 2267 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2291 base::scoped_nsobject<BackgroundColorHoverButton> button( |
| 2268 [[BackgroundColorHoverButton alloc] | 2292 [[BackgroundColorHoverButton alloc] |
| 2269 initWithFrame:rect | 2293 initWithFrame:rect |
| 2270 imageTitleSpacing:image_title_spacing | 2294 imageTitleSpacing:image_title_spacing |
| 2271 backgroundColor:GetDialogBackgroundColor()]); | 2295 backgroundColor:GetDialogBackgroundColor()]); |
| 2272 | 2296 |
| 2273 [button setTitle:text]; | 2297 [button setTitle:text]; |
| 2274 [button setAlignment:NSLeftTextAlignment]; | 2298 [button setAlignment:NSNaturalTextAlignment]; |
| 2275 [button setBordered:NO]; | 2299 [button setBordered:NO]; |
| 2276 [button setTarget:self]; | 2300 [button setTarget:self]; |
| 2277 [button setAction:action]; | 2301 [button setAction:action]; |
| 2278 | 2302 |
| 2279 return button.autorelease(); | 2303 return button.autorelease(); |
| 2280 } | 2304 } |
| 2281 | 2305 |
| 2282 - (NSButton*)linkButtonWithTitle:(NSString*)title | 2306 - (NSButton*)linkButtonWithTitle:(NSString*)title |
| 2283 frameOrigin:(NSPoint)frameOrigin | 2307 frameOrigin:(NSPoint)frameOrigin |
| 2284 action:(SEL)action { | 2308 action:(SEL)action { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2318 if (warningImage) | 2342 if (warningImage) |
| 2319 availableTextWidth -= kHorizontalSpacing; | 2343 availableTextWidth -= kHorizontalSpacing; |
| 2320 | 2344 |
| 2321 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( | 2345 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( |
| 2322 profiles::kAvatarBubbleAccountsBackgroundColor); | 2346 profiles::kAvatarBubbleAccountsBackgroundColor); |
| 2323 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2347 base::scoped_nsobject<BackgroundColorHoverButton> button( |
| 2324 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 2348 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
| 2325 imageTitleSpacing:0 | 2349 imageTitleSpacing:0 |
| 2326 backgroundColor:backgroundColor]); | 2350 backgroundColor:backgroundColor]); |
| 2327 [button setTitle:ElideEmail(email, availableTextWidth)]; | 2351 [button setTitle:ElideEmail(email, availableTextWidth)]; |
| 2328 [button setAlignment:NSLeftTextAlignment]; | 2352 [button setAlignment:NSNaturalTextAlignment]; |
| 2329 [button setBordered:NO]; | 2353 [button setBordered:NO]; |
| 2330 if (reauthRequired) { | 2354 if (reauthRequired) { |
| 2331 [button setDefaultImage:warningImage]; | 2355 [button setDefaultImage:warningImage]; |
| 2332 [button setImagePosition:NSImageLeft]; | 2356 [button setImagePosition:cocoa_l10n_util::LeadingCellImagePosition()]; |
| 2333 [button setTarget:self]; | 2357 [button setTarget:self]; |
| 2334 [button setAction:@selector(showAccountReauthenticationView:)]; | 2358 [button setAction:@selector(showAccountReauthenticationView:)]; |
| 2335 [button setTag:tag]; | 2359 [button setTag:tag]; |
| 2336 } | 2360 } |
| 2337 | 2361 |
| 2338 // Delete button. | 2362 // Delete button. |
| 2339 if (!browser_->profile()->IsSupervised()) { | 2363 if (!browser_->profile()->IsSupervised()) { |
| 2340 NSRect buttonRect; | 2364 NSRect buttonRect; |
| 2341 NSDivideRect(rect, &buttonRect, &rect, | 2365 NSDivideRect(rect, &buttonRect, &rect, |
| 2342 deleteImageWidth + kHorizontalSpacing, NSMaxXEdge); | 2366 deleteImageWidth + kHorizontalSpacing, |
| 2367 cocoa_l10n_util::TrailingEdge()); | |
| 2343 buttonRect.origin.y = 0; | 2368 buttonRect.origin.y = 0; |
| 2344 | 2369 |
| 2345 base::scoped_nsobject<HoverImageButton> deleteButton( | 2370 base::scoped_nsobject<HoverImageButton> deleteButton( |
| 2346 [[HoverImageButton alloc] initWithFrame:buttonRect]); | 2371 [[HoverImageButton alloc] initWithFrame:buttonRect]); |
| 2347 [deleteButton setBordered:NO]; | 2372 [deleteButton setBordered:NO]; |
| 2348 [deleteButton setDefaultImage:deleteImage]; | 2373 [deleteButton setDefaultImage:deleteImage]; |
| 2349 [deleteButton setHoverImage:rb->GetNativeImageNamed( | 2374 [deleteButton setHoverImage:rb->GetNativeImageNamed( |
| 2350 IDR_CLOSE_1_H).ToNSImage()]; | 2375 IDR_CLOSE_1_H).ToNSImage()]; |
| 2351 [deleteButton setPressedImage:rb->GetNativeImageNamed( | 2376 [deleteButton setPressedImage:rb->GetNativeImageNamed( |
| 2352 IDR_CLOSE_1_P).ToNSImage()]; | 2377 IDR_CLOSE_1_P).ToNSImage()]; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2374 | 2399 |
| 2375 - (void)showWindow:(id)sender { | 2400 - (void)showWindow:(id)sender { |
| 2376 [super showWindow:sender]; | 2401 [super showWindow:sender]; |
| 2377 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2402 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2378 if (firstProfileView_ && [event type] == NSKeyDown) { | 2403 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2379 [[self window] makeFirstResponder:firstProfileView_]; | 2404 [[self window] makeFirstResponder:firstProfileView_]; |
| 2380 } | 2405 } |
| 2381 } | 2406 } |
| 2382 | 2407 |
| 2383 @end | 2408 @end |
| OLD | NEW |