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" | |
| 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 21 matching lines...) Expand all Loading... | |
| 41 | 43 |
| 42 @interface BookmarkButtonCell(Private) | 44 @interface BookmarkButtonCell(Private) |
| 43 - (void)configureBookmarkButtonCell; | 45 - (void)configureBookmarkButtonCell; |
| 44 - (void)applyTextColor; | 46 - (void)applyTextColor; |
| 45 // Returns the title the button cell displays. Note that a button cell can | 47 // 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 | 48 // have a title string assigned but it won't be visible if its image position |
| 47 // is NSImageOnly. | 49 // is NSImageOnly. |
| 48 - (NSString*)visibleTitle; | 50 - (NSString*)visibleTitle; |
| 49 // Returns the dictionary of attributes to associate with the button title. | 51 // Returns the dictionary of attributes to associate with the button title. |
| 50 - (NSDictionary*)titleTextAttributes; | 52 - (NSDictionary*)titleTextAttributes; |
| 53 // Returns the BookmarkBarController for the BookmarkButtonCell's controlView. | |
| 54 - (BookmarkBarController*) | |
| 55 bookmarkBarViewControllerFromControlView:(NSView*)controlView; | |
| 51 @end | 56 @end |
| 52 | 57 |
| 53 | 58 |
| 54 @implementation BookmarkButtonCell | 59 @implementation BookmarkButtonCell |
| 55 | 60 |
| 56 @synthesize startingChildIndex = startingChildIndex_; | 61 @synthesize startingChildIndex = startingChildIndex_; |
| 57 @synthesize drawFolderArrow = drawFolderArrow_; | 62 @synthesize drawFolderArrow = drawFolderArrow_; |
| 58 | 63 |
| 59 + (id)buttonCellForNode:(const BookmarkNode*)node | 64 + (id)buttonCellForNode:(const BookmarkNode*)node |
| 60 text:(NSString*)text | 65 text:(NSString*)text |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 return imageRect; | 369 return imageRect; |
| 365 } | 370 } |
| 366 | 371 |
| 367 - (CGFloat)textStartXOffset { | 372 - (CGFloat)textStartXOffset { |
| 368 if (!ui::MaterialDesignController::IsModeMaterial()) { | 373 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 369 return [super textStartXOffset]; | 374 return [super textStartXOffset]; |
| 370 } | 375 } |
| 371 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; | 376 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; |
| 372 } | 377 } |
| 373 | 378 |
| 379 - (BookmarkBarController*) | |
| 380 bookmarkBarViewControllerFromControlView:(NSView*)controlView { | |
|
tapted
2016/06/16 05:53:19
having the button cell know much about its parents
shrike
2016/06/16 15:19:09
Great! My original preference was to change the ce
| |
| 381 NSView* nextView = [controlView superview]; | |
| 382 while (nextView) { | |
| 383 if ([nextView isKindOfClass:[BookmarkBarView class]]) { | |
| 384 BookmarkBarView* bookmarkBarView = (BookmarkBarView*)nextView; | |
| 385 return [bookmarkBarView controller]; | |
| 386 } | |
| 387 nextView = [nextView superview]; | |
| 388 } | |
| 389 return nil; | |
| 390 } | |
| 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 BookmarkBarController* bookmarkBarController = | |
| 403 [self bookmarkBarViewControllerFromControlView:controlView]; | |
| 404 if ([bookmarkBarController offTheSideButton] == controlView) { | |
| 405 cellFrame.origin.y -= 2; | |
| 406 } | |
| 381 } | 407 } |
| 382 [super drawFocusRingMaskWithFrame:cellFrame inView:controlView]; | 408 [super drawFocusRingMaskWithFrame:cellFrame inView:controlView]; |
| 383 } | 409 } |
| 384 | 410 |
| 385 // Override cell drawing to add a submenu arrow like a real menu. | 411 // Override cell drawing to add a submenu arrow like a real menu. |
| 386 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 412 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 387 // First draw "everything else". | 413 // First draw "everything else". |
| 388 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 414 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 389 | 415 |
| 390 // If asked to do so, and if a folder, draw the arrow. | 416 // 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]; | 449 const CGFloat kLineWidth = [controlView cr_lineWidth]; |
| 424 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && | 450 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && |
| 425 ![self isFolderButtonCell] && kLineWidth < 1) { | 451 ![self isFolderButtonCell] && kLineWidth < 1) { |
| 426 return -kLineWidth; | 452 return -kLineWidth; |
| 427 } | 453 } |
| 428 return 0.0; | 454 return 0.0; |
| 429 } | 455 } |
| 430 | 456 |
| 431 | 457 |
| 432 @end | 458 @end |
| OLD | NEW |