| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bookmarks/bookmark_button_cell.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 9 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 const int kIconTextSpacer = 4; | 34 const int kIconTextSpacer = 4; |
| 35 const int kTextRightPadding = 1; | 35 const int kTextRightPadding = 1; |
| 36 const int kIconLeftPadding = 1; | 36 const int kIconLeftPadding = 1; |
| 37 | 37 |
| 38 const int kDefaultFontSize = 12; | 38 const int kDefaultFontSize = 12; |
| 39 | 39 |
| 40 }; // namespace | 40 }; // namespace |
| 41 | 41 |
| 42 @interface OffTheSideButtonCell : BookmarkButtonCell |
| 43 @end |
| 44 @implementation OffTheSideButtonCell |
| 45 |
| 46 - (BOOL)isOffTheSideButtonCell { |
| 47 return YES; |
| 48 } |
| 49 |
| 50 @end |
| 51 |
| 42 @interface BookmarkButtonCell(Private) | 52 @interface BookmarkButtonCell(Private) |
| 53 // Returns YES if the cell is the offTheSide button cell. |
| 54 - (BOOL)isOffTheSideButtonCell; |
| 43 - (void)configureBookmarkButtonCell; | 55 - (void)configureBookmarkButtonCell; |
| 44 - (void)applyTextColor; | 56 - (void)applyTextColor; |
| 45 // Returns the title the button cell displays. Note that a button cell can | 57 // Returns the title the button cell displays. Note that a button cell can |
| 46 // have a title string assigned but it won't be visible if its image position | 58 // have a title string assigned but it won't be visible if its image position |
| 47 // is NSImageOnly. | 59 // is NSImageOnly. |
| 48 - (NSString*)visibleTitle; | 60 - (NSString*)visibleTitle; |
| 49 // Returns the dictionary of attributes to associate with the button title. | 61 // Returns the dictionary of attributes to associate with the button title. |
| 50 - (NSDictionary*)titleTextAttributes; | 62 - (NSDictionary*)titleTextAttributes; |
| 51 @end | 63 @end |
| 52 | 64 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Used by the off-the-side menu, the only case where a | 148 // Used by the off-the-side menu, the only case where a |
| 137 // BookmarkButtonCell is loaded from a nib. | 149 // BookmarkButtonCell is loaded from a nib. |
| 138 - (void)awakeFromNib { | 150 - (void)awakeFromNib { |
| 139 [self configureBookmarkButtonCell]; | 151 [self configureBookmarkButtonCell]; |
| 140 } | 152 } |
| 141 | 153 |
| 142 - (BOOL)isFolderButtonCell { | 154 - (BOOL)isFolderButtonCell { |
| 143 return NO; | 155 return NO; |
| 144 } | 156 } |
| 145 | 157 |
| 158 - (BOOL)isOffTheSideButtonCell { |
| 159 return NO; |
| 160 } |
| 161 |
| 146 // Perform all normal init routines specific to the BookmarkButtonCell. | 162 // Perform all normal init routines specific to the BookmarkButtonCell. |
| 147 - (void)configureBookmarkButtonCell { | 163 - (void)configureBookmarkButtonCell { |
| 148 [self setButtonType:NSMomentaryPushInButton]; | 164 [self setButtonType:NSMomentaryPushInButton]; |
| 149 [self setShowsBorderOnlyWhileMouseInside:YES]; | 165 [self setShowsBorderOnlyWhileMouseInside:YES]; |
| 150 [self setControlSize:NSSmallControlSize]; | 166 [self setControlSize:NSSmallControlSize]; |
| 151 [self setAlignment:NSLeftTextAlignment]; | 167 [self setAlignment:NSLeftTextAlignment]; |
| 152 if (!ui::MaterialDesignController::IsModeMaterial()) { | 168 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 153 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 169 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 154 [self setBezelStyle:NSShadowlessSquareBezelStyle]; | 170 [self setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 155 } else { | 171 } else { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 382 |
| 367 - (CGFloat)textStartXOffset { | 383 - (CGFloat)textStartXOffset { |
| 368 if (!ui::MaterialDesignController::IsModeMaterial()) { | 384 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 369 return [super textStartXOffset]; | 385 return [super textStartXOffset]; |
| 370 } | 386 } |
| 371 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; | 387 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; |
| 372 } | 388 } |
| 373 | 389 |
| 374 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame | 390 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame |
| 375 inView:(NSView*)controlView { | 391 inView:(NSView*)controlView { |
| 376 // In Material Design we have to move the focus ring over by 2 pts to get it | 392 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 377 // to line up with the image. | 393 // In Material Design we have to move the focus ring over by 2 pts to get it |
| 378 if (ui::MaterialDesignController::IsModeMaterial() && | 394 // to line up with the image. |
| 379 [self visibleTitle].length > 0) { | 395 if ([self visibleTitle].length > 0) { |
| 380 cellFrame.origin.x += 2; | 396 cellFrame.origin.x += 2; |
| 397 } |
| 398 |
| 399 // We also have to nudge the chevron button's focus ring up 2pts. |
| 400 if ([self isOffTheSideButtonCell]) { |
| 401 cellFrame.origin.y -= 2; |
| 402 } |
| 381 } | 403 } |
| 382 [super drawFocusRingMaskWithFrame:cellFrame inView:controlView]; | 404 [super drawFocusRingMaskWithFrame:cellFrame inView:controlView]; |
| 383 } | 405 } |
| 384 | 406 |
| 385 // Override cell drawing to add a submenu arrow like a real menu. | 407 // Override cell drawing to add a submenu arrow like a real menu. |
| 386 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 408 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 387 // First draw "everything else". | 409 // First draw "everything else". |
| 388 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 410 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 389 | 411 |
| 390 // If asked to do so, and if a folder, draw the arrow. | 412 // If asked to do so, and if a folder, draw the arrow. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 const CGFloat kLineWidth = [controlView cr_lineWidth]; | 445 const CGFloat kLineWidth = [controlView cr_lineWidth]; |
| 424 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && | 446 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && |
| 425 ![self isFolderButtonCell] && kLineWidth < 1) { | 447 ![self isFolderButtonCell] && kLineWidth < 1) { |
| 426 return -kLineWidth; | 448 return -kLineWidth; |
| 427 } | 449 } |
| 428 return 0.0; | 450 return 0.0; |
| 429 } | 451 } |
| 430 | 452 |
| 431 | 453 |
| 432 @end | 454 @end |
| OLD | NEW |