diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 00:55:49 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 00:55:49 +0000 |
commit | 73448fc4d5e742a7e2afe4325abbb3f4a44b0aef (patch) | |
tree | f7e0828bd05feca241ba05f2423444c3f4d81d6d | |
parent | 6c2e45b826315fb4a3d452d589e245cdf2297991 (diff) | |
download | chromium_src-73448fc4d5e742a7e2afe4325abbb3f4a44b0aef.zip chromium_src-73448fc4d5e742a7e2afe4325abbb3f4a44b0aef.tar.gz chromium_src-73448fc4d5e742a7e2afe4325abbb3f4a44b0aef.tar.bz2 |
Icon-only (titleless) bookmarks are squeezed closer.
BUG=42516
TEST=change some bookmark titles to "" and watch them get Kate Mossified.
Review URL: http://codereview.chromium.org/2045002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46644 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/bookmark_button_cell.mm | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_button_cell_unittest.mm | 32 |
2 files changed, 45 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/bookmark_button_cell.mm b/chrome/browser/cocoa/bookmark_button_cell.mm index 85cfaf4..d2a30b9 100644 --- a/chrome/browser/cocoa/bookmark_button_cell.mm +++ b/chrome/browser/cocoa/bookmark_button_cell.mm @@ -75,7 +75,6 @@ [self setButtonType:NSMomentaryPushInButton]; [self setBezelStyle:NSShadowlessSquareBezelStyle]; [self setShowsBorderOnlyWhileMouseInside:YES]; - [self setControlSize:NSSmallControlSize]; [self setAlignment:NSLeftTextAlignment]; [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; [self setWraps:NO]; @@ -98,7 +97,11 @@ - (NSSize)cellSizeForBounds:(NSRect)aRect { NSSize size = [super cellSizeForBounds:aRect]; - size.width += 2; + // See comments in setBookmarkCellText:image: about squeezing + // buttons with no title. + if ([[self title] length]) { + size.width += 2; + } size.height += 4; return size; } @@ -109,7 +112,14 @@ withString:@" "]; title = [title stringByReplacingOccurrencesOfString:@"\r" withString:@" "]; - [self setImagePosition:NSImageLeft]; + // If no title squeeze things tight with a NSMiniControlSize. + // Else make them small and place the image on the left. + if ([title length]) { + [self setImagePosition:NSImageLeft]; + [self setControlSize:NSSmallControlSize]; + } else { + [self setControlSize:NSMiniControlSize]; + } if (image) [self setImage:image]; if (title) diff --git a/chrome/browser/cocoa/bookmark_button_cell_unittest.mm b/chrome/browser/cocoa/bookmark_button_cell_unittest.mm index 0762863..a665a48 100644 --- a/chrome/browser/cocoa/bookmark_button_cell_unittest.mm +++ b/chrome/browser/cocoa/bookmark_button_cell_unittest.mm @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/resource_bundle.h" #include "base/scoped_nsobject.h" #import "chrome/browser/cocoa/bookmark_button_cell.h" #import "chrome/browser/cocoa/bookmark_menu.h" #include "chrome/browser/cocoa/browser_test_helper.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "grit/app_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -52,6 +54,36 @@ TEST_F(BookmarkButtonCellTest, SizeForBounds) { EXPECT_TRUE(size.width < 200 && size.height < 200); } +// Make sure icon-only buttons are squeezed tightly. +TEST_F(BookmarkButtonCellTest, IconOnlySqueeze) { + NSRect frame = NSMakeRect(0, 0, 50, 30); + scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]); + scoped_nsobject<BookmarkButtonCell> cell( + [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); + [view setCell:cell.get()]; + [[test_window() contentView] addSubview:view]; + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + scoped_nsobject<NSImage> image([rb.GetNSImageNamed(IDR_DEFAULT_FAVICON) + retain]); + EXPECT_TRUE(image.get()); + + NSRect r = NSMakeRect(0, 0, 100, 100); + [cell setBookmarkCellText:@" " image:image]; + CGFloat two_space_width = [cell.get() cellSizeForBounds:r].width; + [cell setBookmarkCellText:@" " image:image]; + CGFloat one_space_width = [cell.get() cellSizeForBounds:r].width; + [cell setBookmarkCellText:@"" image:image]; + CGFloat zero_space_width = [cell.get() cellSizeForBounds:r].width; + + // Make sure the switch to "no title" is more significant than we + // would otherwise see by decreasing the length of the title. + CGFloat delta1 = two_space_width - one_space_width; + CGFloat delta2 = one_space_width - zero_space_width; + EXPECT_GT(delta2, delta1); + +} + // Make sure the default from the base class is overridden. TEST_F(BookmarkButtonCellTest, MouseEnterStuff) { scoped_nsobject<BookmarkButtonCell> cell( |