| Index: chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm
|
| diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm
|
| index c861fdcfef67bae896a6d64b3767dfd08247b0f2..a8c905fee584506c973e00e457388b4064c6ffa0 100644
|
| --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm
|
| +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm
|
| @@ -12,17 +12,27 @@
|
| #import "components/bookmarks/browser/bookmark_model.h"
|
| #include "content/public/browser/user_metrics.h"
|
| #include "ui/base/l10n/l10n_util_mac.h"
|
| +#include "ui/base/material_design/material_design_controller.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/resources/grit/ui_resources.h"
|
|
|
| using base::UserMetricsAction;
|
| using bookmarks::BookmarkNode;
|
|
|
| +namespace {
|
| +
|
| const int kHierarchyButtonXMargin = 4;
|
| +const int kIconTextSpacer = 4;
|
| +const int kTextRightPadding = 1;
|
| +const int kIconLeftPadding = 3;
|
| +
|
| +}; // namespace
|
|
|
| @interface BookmarkButtonCell(Private)
|
| - (void)configureBookmarkButtonCell;
|
| - (void)applyTextColor;
|
| +// Returns the dictionary of attributes to associate with the button title.
|
| +- (NSDictionary*)titleTextAttributes;
|
| @end
|
|
|
|
|
| @@ -121,11 +131,17 @@ const int kHierarchyButtonXMargin = 4;
|
| // Perform all normal init routines specific to the BookmarkButtonCell.
|
| - (void)configureBookmarkButtonCell {
|
| [self setButtonType:NSMomentaryPushInButton];
|
| - [self setBezelStyle:NSShadowlessSquareBezelStyle];
|
| [self setShowsBorderOnlyWhileMouseInside:YES];
|
| [self setControlSize:NSSmallControlSize];
|
| [self setAlignment:NSLeftTextAlignment];
|
| - [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
|
| + if (!ui::MaterialDesignController::IsModeMaterial()) {
|
| + [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
|
| + [self setBezelStyle:NSShadowlessSquareBezelStyle];
|
| + } else {
|
| + [self setFont:[NSFont systemFontOfSize:12]];
|
| + [self setBordered:NO];
|
| + [self setBezeled:NO];
|
| + }
|
| [self setWraps:NO];
|
| // NSLineBreakByTruncatingMiddle seems more common on OSX but let's
|
| // try to match Windows for a bit to see what happens.
|
| @@ -149,6 +165,13 @@ const int kHierarchyButtonXMargin = 4;
|
| }
|
|
|
| - (NSSize)cellSizeForBounds:(NSRect)aRect {
|
| + // There's no bezel or border in Material Design so return cellSize.
|
| + if (ui::MaterialDesignController::IsModeMaterial()) {
|
| + NSSize size = [self cellSize];
|
| + size.width = std::min(aRect.size.width, size.width);
|
| + size.height = std::min(aRect.size.height, size.height);
|
| + return size;
|
| + }
|
| NSSize size = [super cellSizeForBounds:aRect];
|
| // Cocoa seems to slightly underestimate how much space we need, so we
|
| // compensate here to avoid a clipped rendering.
|
| @@ -262,16 +285,70 @@ const int kHierarchyButtonXMargin = 4;
|
| }
|
| }
|
|
|
| +- (NSDictionary*)titleTextAttributes {
|
| + base::scoped_nsobject<NSMutableParagraphStyle> style(
|
| + [NSMutableParagraphStyle new]);
|
| + [style setAlignment:NSTextAlignmentNatural];
|
| + [style setLineBreakMode:NSLineBreakByTruncatingTail];
|
| + NSColor* textColor = nil;
|
| + if (![self isEnabled]) {
|
| + textColor = [textColor colorWithAlphaComponent:0.5];
|
| + } else {
|
| + textColor = textColor_ == nil ? [NSColor blackColor] : textColor_.get();
|
| + }
|
| + NSFont* theFont = [self font];
|
| + DCHECK(theFont);
|
| + return @{
|
| + NSFontAttributeName : theFont,
|
| + NSForegroundColorAttributeName : textColor,
|
| + NSParagraphStyleAttributeName : style.get(),
|
| + NSKernAttributeName : [NSNumber numberWithFloat:0.2]
|
| + };
|
| +}
|
| +
|
| // Add extra size for the arrow so it doesn't overlap the text.
|
| // Does not sanity check to be sure this is actually a folder node.
|
| - (NSSize)cellSize {
|
| - NSSize cellSize = [super cellSize];
|
| + NSSize cellSize = NSZeroSize;
|
| + if (!ui::MaterialDesignController::IsModeMaterial()) {
|
| + cellSize = [super cellSize];
|
| + } else {
|
| + // Return the space needed to display the image and text, with a little
|
| + // distance between them.
|
| + cellSize = [[self image] size];
|
| + cellSize.width += kIconLeftPadding;
|
| + NSString* title = [self title];
|
| + if ([title length] > 0) {
|
| + CGFloat textWidth =
|
| + [title sizeWithAttributes:[self titleTextAttributes]].width;
|
| + cellSize.width +=
|
| + kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding;
|
| + }
|
| + }
|
| +
|
| if (drawFolderArrow_) {
|
| cellSize.width += [arrowImage_ size].width + 2 * kHierarchyButtonXMargin;
|
| }
|
| return cellSize;
|
| }
|
|
|
| +- (NSRect)imageRectForBounds:(NSRect)theRect {
|
| + NSRect imageRect = [super imageRectForBounds:theRect];
|
| + // In Material Design, add a little space between the image and the button's
|
| + // left edge.
|
| + if (ui::MaterialDesignController::IsModeMaterial()) {
|
| + imageRect.origin.x += kIconLeftPadding;
|
| + }
|
| + return imageRect;
|
| +}
|
| +
|
| +- (CGFloat)textStartXOffset {
|
| + if (!ui::MaterialDesignController::IsModeMaterial()) {
|
| + return [super textStartXOffset];
|
| + }
|
| + return kIconLeftPadding + [[self image] size].width + kIconTextSpacer;
|
| +}
|
| +
|
| // Override cell drawing to add a submenu arrow like a real menu.
|
| - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
|
| // First draw "everything else".
|
|
|