summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 03:12:49 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 03:12:49 +0000
commit58dd56d1be3b5b4dcba851aebd59b8d3645685e8 (patch)
tree10421ea2adf2f44fd33cc5a4eaa15a722156e238 /chrome/browser/cocoa/bookmark_bar_folder_controller.mm
parent3cb29296dd9eb603f033a527e33f5e40eea90c9d (diff)
downloadchromium_src-58dd56d1be3b5b4dcba851aebd59b8d3645685e8.zip
chromium_src-58dd56d1be3b5b4dcba851aebd59b8d3645685e8.tar.gz
chromium_src-58dd56d1be3b5b4dcba851aebd59b8d3645685e8.tar.bz2
Bookmark bar menu/folder button text is left-aligned, not centered.
Bookmark bar menu/folder maximum window width is now 1000, not 150. High cosmetic impact. BUG=36487, 17608 TEST=\ 1) Add bookmarks on the bar with small (e.g. 'x') and big titles. Make sure all looks OK (e.g. small ones are small.) 2) Add bookmarks in a folder. Make sure text is left aligned on the menus. 3) Add bookmarks in a folder with long names (e.g. 100 characters). Make sure folder/menus are now much wider. 4) Add bookmarks in a folder with mega long names (e.g. 4000 characters). Make sure menus have a maximum size of ~1000 pixes (no need to be exact but 'no limit' is fail). 5) In a folder, add a subfolder named 'x' and a bookmark with a REAL long name. Make sure the "button" (menu item) is the full width of the menu. Review URL: http://codereview.chromium.org/842005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41387 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_folder_controller.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_folder_controller.mm77
1 files changed, 57 insertions, 20 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
index 2dca753..88a5f21 100644
--- a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm
@@ -90,6 +90,7 @@
// If |node| is NULL this is an "(empty)" button.
// Does NOT add this button to our button list.
// Returns an autoreleased button.
+// Adjusts the input frame width as appropriate.
//
// TODO(jrg): combine with addNodesToButtonList: code from
// bookmark_bar_controller.mm, and generalize that to use both x and y
@@ -97,10 +98,20 @@
// http://crbug.com/35966
- (BookmarkButton*)makeButtonForNode:(const BookmarkNode*)node
frame:(NSRect)frame {
+ NSCell* cell = [self cellForBookmarkNode:node];
+ DCHECK(cell);
+
+ // The "+2" is needed because, sometimes, Cocoa is off by a tad when
+ // returning the value it thinks it needs.
+ CGFloat desired = [cell cellSize].width + 2;
+ frame.size.width = std::min(
+ std::max(bookmarks::kBookmarkMenuButtonMinimumWidth, desired),
+ bookmarks::kBookmarkMenuButtonMaximumWidth);
+
BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame]
autorelease];
DCHECK(button);
- NSCell* cell = [self cellForBookmarkNode:node];
+
[button setCell:cell];
[button setDelegate:self];
if (node) {
@@ -182,25 +193,30 @@
int buttons = node->GetChildCount();
if (buttons == 0)
buttons = 1; // the "empty" button
+
int height = buttons * bookmarks::kBookmarkButtonHeight;
- // TODO(jrg): use full width for buttons, like menus?
- // http://crbug.com/36487
- int width = (bookmarks::kDefaultBookmarkWidth +
- 2 * bookmarks::kBookmarkVerticalPadding);
- [[self window] setFrame:NSMakeRect(newWindowTopLeft.x,
- newWindowTopLeft.y - height,
- width,
- height)
- display:YES];
+
+ // Note: this will be replaced once we make buttons; for now, use a
+ // reasonable value. Button creation needs a valid (x,y,h) in a
+ // frame to position them properly.
+ int windowWidth = (bookmarks::kBookmarkMenuButtonMinimumWidth +
+ 2 * bookmarks::kBookmarkVerticalPadding);
+
+ NSRect windowFrame = NSMakeRect(newWindowTopLeft.x,
+ newWindowTopLeft.y - height,
+ windowWidth,
+ height);
+ [[self window] setFrame:windowFrame display:YES];
// TODO(jrg): combine with frame code in bookmark_bar_controller.mm
// http://crbug.com/35966
- NSRect frame = NSMakeRect(bookmarks::kBookmarkHorizontalPadding,
- height - (bookmarks::kBookmarkBarHeight -
- bookmarks::kBookmarkHorizontalPadding),
- bookmarks::kDefaultBookmarkWidth,
- (bookmarks::kBookmarkBarHeight -
- 2 * bookmarks::kBookmarkVerticalPadding));
+ NSRect buttonsOuterFrame = NSMakeRect(
+ bookmarks::kBookmarkHorizontalPadding,
+ height - (bookmarks::kBookmarkBarHeight -
+ bookmarks::kBookmarkHorizontalPadding),
+ bookmarks::kDefaultBookmarkWidth,
+ (bookmarks::kBookmarkBarHeight -
+ 2 * bookmarks::kBookmarkVerticalPadding));
// TODO(jrg): combine with addNodesToButtonList: code from
// bookmark_bar_controller.mm (but use y offset)
@@ -208,21 +224,42 @@
if (!node->GetChildCount()) {
// If no children we are the empty button.
BookmarkButton* button = [self makeButtonForNode:nil
- frame:frame];
+ frame:buttonsOuterFrame];
[buttons_ addObject:button];
[mainView_ addSubview:button];
} else {
for (int i = 0; i < node->GetChildCount(); i++) {
const BookmarkNode* child = node->GetChild(i);
BookmarkButton* button = [self makeButtonForNode:child
- frame:frame];
+ frame:buttonsOuterFrame];
[buttons_ addObject:button];
[mainView_ addSubview:button];
- frame.origin.y -= bookmarks::kBookmarkBarHeight;
+ buttonsOuterFrame.origin.y -= bookmarks::kBookmarkBarHeight;
}
}
-
[self updateTheme:[self themeProvider]];
+
+ // Now that we have all our buttons we can determine the real size
+ // of our window.
+ CGFloat width = 0.0;
+ for (BookmarkButton* button in buttons_.get()) {
+ width = std::max(width, NSWidth([button bounds]));
+ }
+ width = std::min(width, bookmarks::kBookmarkMenuButtonMaximumWidth);
+
+ // Things look and feel more menu-like if all the buttons are the
+ // full width of the window, especially if there are submenus.
+ for (BookmarkButton* button in buttons_.get()) {
+ NSRect buttonFrame = [button frame];
+ buttonFrame.size.width = width;
+ [button setFrame:buttonFrame];
+ }
+
+ // Finally, set our window size.
+ width += (2 * bookmarks::kBookmarkVerticalPadding);
+ windowFrame.size.width = width;
+ [[self window] setFrame:windowFrame display:YES];
+
[[parentController_ parentWindow] addChildWindow:[self window]
ordered:NSWindowAbove];
}