Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm

Issue 2200303004: [Mac][Material Design] Adjust bookmark spacing and folder menu drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests, changes for icon-only items. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 25
26 // Padding on the right side of the arrow icon. 26 // Padding on the right side of the arrow icon.
27 const int kHierarchyButtonRightPadding = 4; 27 const int kHierarchyButtonRightPadding = 4;
28 28
29 // Padding on the left side of the arrow icon. 29 // Padding on the left side of the arrow icon.
30 int HierarchyButtonLeftPadding() { 30 int HierarchyButtonLeftPadding() {
31 return ui::MaterialDesignController::IsModeMaterial() ? 11 : 2; 31 return ui::MaterialDesignController::IsModeMaterial() ? 11 : 2;
32 } 32 }
33 33
34 const int kIconTextSpacer = 4; 34 const int kIconTextSpacer = 4;
35 const int kTextRightPadding = 1; 35 const int kTextRightPadding = 4;
36 const int kIconLeftPadding = 1; 36 const int kIconLeftPadding = 4;
37 37
38 const int kDefaultFontSize = 12; 38 const int kDefaultFontSize = 12;
39 39
40 }; // namespace 40 }; // namespace
41 41
42 @interface OffTheSideButtonCell : BookmarkButtonCell 42 @interface OffTheSideButtonCell : BookmarkButtonCell
43 @end 43 @end
44 @implementation OffTheSideButtonCell 44 @implementation OffTheSideButtonCell
45 45
46 - (BOOL)isOffTheSideButtonCell { 46 - (BOOL)isOffTheSideButtonCell {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width, 348 cellSize = NSMakeSize(kIconLeftPadding + [[self image] size].width,
349 bookmarks::kBookmarkButtonHeight); 349 bookmarks::kBookmarkButtonHeight);
350 NSString* title = [self visibleTitle]; 350 NSString* title = [self visibleTitle];
351 if ([title length] > 0) { 351 if ([title length] > 0) {
352 CGFloat textWidth = 352 CGFloat textWidth =
353 [title sizeWithAttributes:[self titleTextAttributes]].width; 353 [title sizeWithAttributes:[self titleTextAttributes]].width;
354 cellSize.width += 354 cellSize.width +=
355 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding; 355 kIconTextSpacer + std::ceil(textWidth) + kTextRightPadding;
356 } else { 356 } else {
357 // Make buttons without visible titles 20pts wide (18 plus padding). 357 // Make buttons without visible titles 20pts wide (18 plus padding).
358 cellSize.width = 18; 358 cellSize.width += kIconLeftPadding;
359 } 359 }
360 } 360 }
361 361
362 if (drawFolderArrow_) { 362 if (drawFolderArrow_) {
363 cellSize.width += [arrowImage_ size].width + 363 cellSize.width += [arrowImage_ size].width +
364 HierarchyButtonLeftPadding() + 364 HierarchyButtonLeftPadding() +
365 kHierarchyButtonRightPadding; 365 kHierarchyButtonRightPadding;
366 } 366 }
367 return cellSize; 367 return cellSize;
368 } 368 }
369 369
370 - (NSRect)imageRectForBounds:(NSRect)theRect { 370 - (NSRect)imageRectForBounds:(NSRect)theRect {
371 NSRect imageRect = [super imageRectForBounds:theRect]; 371 NSRect imageRect = [super imageRectForBounds:theRect];
372 // In Material Design, add a little space between the image and the button's 372 // In Material Design, add a little space between the image and the button's
373 // left edge, but only if there's a visible title. 373 // left edge, but only if there's a visible title.
374 if (ui::MaterialDesignController::IsModeMaterial()) { 374 if (ui::MaterialDesignController::IsModeMaterial()) {
375 imageRect.origin.y -= 1; 375 imageRect.origin.y -= 1;
376 if ([[self visibleTitle] length] > 0) { 376 imageRect.origin.x = kIconLeftPadding;
377 imageRect.origin.x += kIconLeftPadding;
378 }
379 } 377 }
380 return imageRect; 378 return imageRect;
381 } 379 }
382 380
383 - (CGFloat)textStartXOffset { 381 - (CGFloat)textStartXOffset {
384 if (!ui::MaterialDesignController::IsModeMaterial()) { 382 if (!ui::MaterialDesignController::IsModeMaterial()) {
385 return [super textStartXOffset]; 383 return [super textStartXOffset];
386 } 384 }
387 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer; 385 return kIconLeftPadding + [[self image] size].width + kIconTextSpacer;
388 } 386 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (!ui::MaterialDesignController::IsModeMaterial()) { 434 if (!ui::MaterialDesignController::IsModeMaterial()) {
437 return 0; 435 return 0;
438 } 436 }
439 return -1; 437 return -1;
440 } 438 }
441 439
442 - (CGFloat)hoverBackgroundVerticalOffsetInControlView:(NSView*)controlView { 440 - (CGFloat)hoverBackgroundVerticalOffsetInControlView:(NSView*)controlView {
443 // In Material Design on Retina, and not in a folder menu, nudge the hover 441 // In Material Design on Retina, and not in a folder menu, nudge the hover
444 // background by 1px. 442 // background by 1px.
445 const CGFloat kLineWidth = [controlView cr_lineWidth]; 443 const CGFloat kLineWidth = [controlView cr_lineWidth];
446 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && 444 if ([self isMaterialDesignButtonType] && ![self isFolderButtonCell] &&
447 ![self isFolderButtonCell] && kLineWidth < 1) { 445 kLineWidth < 1) {
448 return -kLineWidth; 446 return -kLineWidth;
449 } 447 }
450 return 0.0; 448 return 0.0;
451 } 449 }
452 450
453 451
454 @end 452 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm ('k') | chrome/browser/ui/cocoa/gradient_button_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698