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