| 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" |
| 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle
r.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle
r.h" |
| 12 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 13 #import "components/bookmarks/browser/bookmark_model.h" | 13 #import "components/bookmarks/browser/bookmark_model.h" |
| 14 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
| 15 #import "ui/base/cocoa/nsview_additions.h" | 15 #import "ui/base/cocoa/nsview_additions.h" |
| 16 #include "ui/base/l10n/l10n_util_mac.h" | 16 #include "ui/base/l10n/l10n_util_mac.h" |
| 17 #include "ui/base/material_design/material_design_controller.h" | 17 #include "ui/base/material_design/material_design_controller.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
| 20 | 20 |
| 21 using base::UserMetricsAction; | 21 using base::UserMetricsAction; |
| 22 using bookmarks::BookmarkNode; | 22 using bookmarks::BookmarkNode; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const int kHierarchyButtonXMargin = 4; | 26 const int kHierarchyButtonXMargin = 4; |
| 27 const int kIconTextSpacer = 4; | 27 const int kIconTextSpacer = 4; |
| 28 const int kTextRightPadding = 1; | 28 const int kTextRightPadding = 3; |
| 29 const int kIconLeftPadding = 1; | 29 const int kIconLeftPadding = 3; |
| 30 | 30 |
| 31 const int kDefaultFontSize = 12; | 31 const int kDefaultFontSize = 12; |
| 32 | 32 |
| 33 }; // namespace | 33 }; // namespace |
| 34 | 34 |
| 35 @interface BookmarkButtonCell(Private) | 35 @interface BookmarkButtonCell(Private) |
| 36 - (void)configureBookmarkButtonCell; | 36 - (void)configureBookmarkButtonCell; |
| 37 - (void)applyTextColor; | 37 - (void)applyTextColor; |
| 38 // Returns the title the button cell displays. Note that a button cell can | 38 // Returns the title the button cell displays. Note that a button cell can |
| 39 // have a title string assigned but it won't be visible if its image position | 39 // have a title string assigned but it won't be visible if its image position |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // Return the space needed to display the image and title, with a little | 323 // Return the space needed to display the image and title, with a little |
| 324 // distance between them. | 324 // distance between them. |
| 325 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width, | 325 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width, |
| 326 bookmarks::kBookmarkButtonHeight); | 326 bookmarks::kBookmarkButtonHeight); |
| 327 NSString* title = [self visibleTitle]; | 327 NSString* title = [self visibleTitle]; |
| 328 if ([title length] > 0) { | 328 if ([title length] > 0) { |
| 329 CGFloat textWidth = | 329 CGFloat textWidth = |
| 330 [title sizeWithAttributes:[self titleTextAttributes]].width; | 330 [title sizeWithAttributes:[self titleTextAttributes]].width; |
| 331 cellSize.width += | 331 cellSize.width += |
| 332 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding; | 332 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding; |
| 333 } else { | |
| 334 // Make buttons without visible titles 20pts wide (18 plus padding). | |
| 335 cellSize.width = 18; | |
| 336 } | 333 } |
| 337 } | 334 } |
| 338 | 335 |
| 339 if (drawFolderArrow_) { | 336 if (drawFolderArrow_) { |
| 340 cellSize.width += [arrowImage_ size].width + 2 * kHierarchyButtonXMargin; | 337 cellSize.width += [arrowImage_ size].width + 2 * kHierarchyButtonXMargin; |
| 341 } | 338 } |
| 342 return cellSize; | 339 return cellSize; |
| 343 } | 340 } |
| 344 | 341 |
| 345 - (NSRect)imageRectForBounds:(NSRect)theRect { | 342 - (NSRect)imageRectForBounds:(NSRect)theRect { |
| 346 NSRect imageRect = [super imageRectForBounds:theRect]; | 343 NSRect imageRect = [super imageRectForBounds:theRect]; |
| 347 // In Material Design, add a little space between the image and the button's | 344 // In Material Design, add a little space between the image and the button's |
| 348 // left edge, but only if there's a visible title. | 345 // left edge, but only if there's a visible title. |
| 349 if (ui::MaterialDesignController::IsModeMaterial()) { | 346 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 350 imageRect.origin.y -= 1; | 347 imageRect.origin.y -= 1; |
| 351 imageRect.origin.x += kIconLeftPadding; | 348 if ([[self visibleTitle] length]) { |
| 349 imageRect.origin.x += kIconLeftPadding; |
| 350 } |
| 352 } | 351 } |
| 353 return imageRect; | 352 return imageRect; |
| 354 } | 353 } |
| 355 | 354 |
| 356 - (CGFloat)textStartXOffset { | 355 - (CGFloat)textStartXOffset { |
| 357 if (!ui::MaterialDesignController::IsModeMaterial()) { | 356 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 358 return [super textStartXOffset]; | 357 return [super textStartXOffset]; |
| 359 } | 358 } |
| 360 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; | 359 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; |
| 361 } | 360 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 const CGFloat kLineWidth = [controlView cr_lineWidth]; | 400 const CGFloat kLineWidth = [controlView cr_lineWidth]; |
| 402 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && | 401 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && |
| 403 ![self isFolderButtonCell] && kLineWidth < 1) { | 402 ![self isFolderButtonCell] && kLineWidth < 1) { |
| 404 return -kLineWidth; | 403 return -kLineWidth; |
| 405 } | 404 } |
| 406 return 0.0; | 405 return 0.0; |
| 407 } | 406 } |
| 408 | 407 |
| 409 | 408 |
| 410 @end | 409 @end |
| OLD | NEW |