| 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 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/resources/grit/ui_resources.h" | 18 #include "ui/resources/grit/ui_resources.h" |
| 19 | 19 |
| 20 using base::UserMetricsAction; | 20 using base::UserMetricsAction; |
| 21 using bookmarks::BookmarkNode; | 21 using bookmarks::BookmarkNode; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const int kHierarchyButtonXMargin = 4; | 25 const int kHierarchyButtonXMargin = 4; |
| 26 const int kIconTextSpacer = 4; | 26 const int kIconTextSpacer = 4; |
| 27 const int kTextRightPadding = 1; | 27 const int kTextRightPadding = 3; |
| 28 const int kIconLeftPadding = 3; | 28 const int kIconLeftPadding = 3; |
| 29 | 29 |
| 30 const int kDefaultFontSize = 12; | 30 const int kDefaultFontSize = 12; |
| 31 | 31 |
| 32 }; // namespace | 32 }; // namespace |
| 33 | 33 |
| 34 @interface BookmarkButtonCell(Private) | 34 @interface BookmarkButtonCell(Private) |
| 35 - (void)configureBookmarkButtonCell; | 35 - (void)configureBookmarkButtonCell; |
| 36 - (void)applyTextColor; | 36 - (void)applyTextColor; |
| 37 // Returns the title the button cell displays. Note that a button cell can | 37 // Returns the title the button cell displays. Note that a button cell can |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Add extra size for the arrow so it doesn't overlap the text. | 315 // Add extra size for the arrow so it doesn't overlap the text. |
| 316 // Does not sanity check to be sure this is actually a folder node. | 316 // Does not sanity check to be sure this is actually a folder node. |
| 317 - (NSSize)cellSize { | 317 - (NSSize)cellSize { |
| 318 NSSize cellSize = NSZeroSize; | 318 NSSize cellSize = NSZeroSize; |
| 319 if (!ui::MaterialDesignController::IsModeMaterial()) { | 319 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 320 cellSize = [super cellSize]; | 320 cellSize = [super cellSize]; |
| 321 } else { | 321 } else { |
| 322 // Return the space needed to display the image and title, with a little | 322 // Return the space needed to display the image and title, with a little |
| 323 // distance between them. | 323 // distance between them. |
| 324 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width, | 324 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width, |
| 325 bookmarks::kMaterialBookmarkButtonHeight); | 325 bookmarks::kBookmarkButtonHeight); |
| 326 NSString* title = [self visibleTitle]; | 326 NSString* title = [self visibleTitle]; |
| 327 if ([title length] > 0) { | 327 if ([title length] > 0) { |
| 328 CGFloat textWidth = | 328 CGFloat textWidth = |
| 329 [title sizeWithAttributes:[self titleTextAttributes]].width; | 329 [title sizeWithAttributes:[self titleTextAttributes]].width; |
| 330 cellSize.width += | 330 cellSize.width += |
| 331 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding; | 331 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 if (drawFolderArrow_) { | 335 if (drawFolderArrow_) { |
| 336 cellSize.width += [arrowImage_ size].width + 2 * kHierarchyButtonXMargin; | 336 cellSize.width += [arrowImage_ size].width + 2 * kHierarchyButtonXMargin; |
| 337 } | 337 } |
| 338 return cellSize; | 338 return cellSize; |
| 339 } | 339 } |
| 340 | 340 |
| 341 - (NSRect)imageRectForBounds:(NSRect)theRect { | 341 - (NSRect)imageRectForBounds:(NSRect)theRect { |
| 342 NSRect imageRect = [super imageRectForBounds:theRect]; | 342 NSRect imageRect = [super imageRectForBounds:theRect]; |
| 343 // In Material Design, add a little space between the image and the button's | 343 // In Material Design, add a little space between the image and the button's |
| 344 // left edge, but only if there's a visible title. | 344 // left edge, but only if there's a visible title. |
| 345 if ([[self visibleTitle] length] && | 345 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 346 ui::MaterialDesignController::IsModeMaterial()) { | 346 imageRect.origin.y -= 1; |
| 347 imageRect.origin.x += kIconLeftPadding; | 347 if ([[self visibleTitle] length]) { |
| 348 imageRect.origin.x += kIconLeftPadding; |
| 349 } |
| 348 } | 350 } |
| 349 return imageRect; | 351 return imageRect; |
| 350 } | 352 } |
| 351 | 353 |
| 352 - (CGFloat)textStartXOffset { | 354 - (CGFloat)textStartXOffset { |
| 353 if (!ui::MaterialDesignController::IsModeMaterial()) { | 355 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 354 return [super textStartXOffset]; | 356 return [super textStartXOffset]; |
| 355 } | 357 } |
| 356 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; | 358 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; |
| 357 } | 359 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 378 [arrowImage_ drawInRect:drawRect | 380 [arrowImage_ drawInRect:drawRect |
| 379 fromRect:imageRect | 381 fromRect:imageRect |
| 380 operation:NSCompositeSourceOver | 382 operation:NSCompositeSourceOver |
| 381 fraction:[self isEnabled] ? 1.0 : 0.5 | 383 fraction:[self isEnabled] ? 1.0 : 0.5 |
| 382 respectFlipped:YES | 384 respectFlipped:YES |
| 383 hints:nil]; | 385 hints:nil]; |
| 384 } | 386 } |
| 385 } | 387 } |
| 386 | 388 |
| 387 - (int)verticalTextOffset { | 389 - (int)verticalTextOffset { |
| 388 return 0; | 390 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 391 return 0; |
| 392 } |
| 393 return -1; |
| 389 } | 394 } |
| 390 | 395 |
| 391 @end | 396 @end |
| OLD | NEW |