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

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_folder_controller.mm

Issue 842005: Bookmark bar menu/folder button text is left-aligned, not centered.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cocoa/bookmark_bar_folder_controller.h" 5 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h"
6 #include "base/mac_util.h" 6 #include "base/mac_util.h"
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #import "chrome/browser/browser_theme_provider.h" 9 #import "chrome/browser/browser_theme_provider.h"
10 #import "chrome/browser/cocoa/bookmark_bar_constants.h" // namespace bookmarks 10 #import "chrome/browser/cocoa/bookmark_bar_constants.h" // namespace bookmarks
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // single implementation. 83 // single implementation.
84 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)child { 84 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)child {
85 return [parentController_ cellForBookmarkNode:child]; 85 return [parentController_ cellForBookmarkNode:child];
86 } 86 }
87 87
88 // Create a bookmark button for the given node using frame. 88 // Create a bookmark button for the given node using frame.
89 // 89 //
90 // If |node| is NULL this is an "(empty)" button. 90 // If |node| is NULL this is an "(empty)" button.
91 // Does NOT add this button to our button list. 91 // Does NOT add this button to our button list.
92 // Returns an autoreleased button. 92 // Returns an autoreleased button.
93 // Adjusts the input frame width as appropriate.
93 // 94 //
94 // TODO(jrg): combine with addNodesToButtonList: code from 95 // TODO(jrg): combine with addNodesToButtonList: code from
95 // bookmark_bar_controller.mm, and generalize that to use both x and y 96 // bookmark_bar_controller.mm, and generalize that to use both x and y
96 // offsets. 97 // offsets.
97 // http://crbug.com/35966 98 // http://crbug.com/35966
98 - (BookmarkButton*)makeButtonForNode:(const BookmarkNode*)node 99 - (BookmarkButton*)makeButtonForNode:(const BookmarkNode*)node
99 frame:(NSRect)frame { 100 frame:(NSRect)frame {
101 NSCell* cell = [self cellForBookmarkNode:node];
102 DCHECK(cell);
103
104 // The "+2" is needed because, sometimes, Cocoa is off by a tad when
105 // returning the value it thinks it needs.
106 CGFloat desired = [cell cellSize].width + 2;
107 frame.size.width = std::min(
108 std::max(bookmarks::kBookmarkMenuButtonMinimumWidth, desired),
109 bookmarks::kBookmarkMenuButtonMaximumWidth);
110
100 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame] 111 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame]
101 autorelease]; 112 autorelease];
102 DCHECK(button); 113 DCHECK(button);
103 NSCell* cell = [self cellForBookmarkNode:node]; 114
104 [button setCell:cell]; 115 [button setCell:cell];
105 [button setDelegate:self]; 116 [button setDelegate:self];
106 if (node) { 117 if (node) {
107 if (node->is_folder()) { 118 if (node->is_folder()) {
108 [button setTarget:self]; 119 [button setTarget:self];
109 [button setAction:@selector(openBookmarkFolderFromButton:)]; 120 [button setAction:@selector(openBookmarkFolderFromButton:)];
110 } else { 121 } else {
111 // Make the button do something. 122 // Make the button do something.
112 [button setTarget:self]; 123 [button setTarget:self];
113 [button setAction:@selector(openBookmark:)]; 124 [button setAction:@selector(openBookmark:)];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Determine window size and position. 186 // Determine window size and position.
176 // Create buttons for all our nodes. 187 // Create buttons for all our nodes.
177 // TODO(jrg): break up into more and smaller routines for easier unit testing. 188 // TODO(jrg): break up into more and smaller routines for easier unit testing.
178 - (void)configureWindow { 189 - (void)configureWindow {
179 NSPoint newWindowTopLeft = [self windowTopLeft]; 190 NSPoint newWindowTopLeft = [self windowTopLeft];
180 const BookmarkNode* node = [parentButton_ bookmarkNode]; 191 const BookmarkNode* node = [parentButton_ bookmarkNode];
181 DCHECK(node); 192 DCHECK(node);
182 int buttons = node->GetChildCount(); 193 int buttons = node->GetChildCount();
183 if (buttons == 0) 194 if (buttons == 0)
184 buttons = 1; // the "empty" button 195 buttons = 1; // the "empty" button
196
185 int height = buttons * bookmarks::kBookmarkButtonHeight; 197 int height = buttons * bookmarks::kBookmarkButtonHeight;
186 // TODO(jrg): use full width for buttons, like menus? 198
187 // http://crbug.com/36487 199 // Note: this will be replaced once we make buttons; for now, use a
188 int width = (bookmarks::kDefaultBookmarkWidth + 200 // reasonable value. Button creation needs a valid (x,y,h) in a
189 2 * bookmarks::kBookmarkVerticalPadding); 201 // frame to position them properly.
190 [[self window] setFrame:NSMakeRect(newWindowTopLeft.x, 202 int windowWidth = (bookmarks::kBookmarkMenuButtonMinimumWidth +
191 newWindowTopLeft.y - height, 203 2 * bookmarks::kBookmarkVerticalPadding);
192 width, 204
193 height) 205 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x,
194 display:YES]; 206 newWindowTopLeft.y - height,
207 windowWidth,
208 height);
209 [[self window] setFrame:windowFrame display:YES];
195 210
196 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm 211 // TODO(jrg): combine with frame code in bookmark_bar_controller.mm
197 // http://crbug.com/35966 212 // http://crbug.com/35966
198 NSRect frame = NSMakeRect(bookmarks::kBookmarkHorizontalPadding, 213 NSRect buttonsOuterFrame = NSMakeRect(
199 height - (bookmarks::kBookmarkBarHeight - 214 bookmarks::kBookmarkHorizontalPadding,
200 bookmarks::kBookmarkHorizontalPadding), 215 height - (bookmarks::kBookmarkBarHeight -
201 bookmarks::kDefaultBookmarkWidth, 216 bookmarks::kBookmarkHorizontalPadding),
202 (bookmarks::kBookmarkBarHeight - 217 bookmarks::kDefaultBookmarkWidth,
203 2 * bookmarks::kBookmarkVerticalPadding)); 218 (bookmarks::kBookmarkBarHeight -
219 2 * bookmarks::kBookmarkVerticalPadding));
204 220
205 // TODO(jrg): combine with addNodesToButtonList: code from 221 // TODO(jrg): combine with addNodesToButtonList: code from
206 // bookmark_bar_controller.mm (but use y offset) 222 // bookmark_bar_controller.mm (but use y offset)
207 // http://crbug.com/35966 223 // http://crbug.com/35966
208 if (!node->GetChildCount()) { 224 if (!node->GetChildCount()) {
209 // If no children we are the empty button. 225 // If no children we are the empty button.
210 BookmarkButton* button = [self makeButtonForNode:nil 226 BookmarkButton* button = [self makeButtonForNode:nil
211 frame:frame]; 227 frame:buttonsOuterFrame];
212 [buttons_ addObject:button]; 228 [buttons_ addObject:button];
213 [mainView_ addSubview:button]; 229 [mainView_ addSubview:button];
214 } else { 230 } else {
215 for (int i = 0; i < node->GetChildCount(); i++) { 231 for (int i = 0; i < node->GetChildCount(); i++) {
216 const BookmarkNode* child = node->GetChild(i); 232 const BookmarkNode* child = node->GetChild(i);
217 BookmarkButton* button = [self makeButtonForNode:child 233 BookmarkButton* button = [self makeButtonForNode:child
218 frame:frame]; 234 frame:buttonsOuterFrame];
219 [buttons_ addObject:button]; 235 [buttons_ addObject:button];
220 [mainView_ addSubview:button]; 236 [mainView_ addSubview:button];
221 frame.origin.y -= bookmarks::kBookmarkBarHeight; 237 buttonsOuterFrame.origin.y -= bookmarks::kBookmarkBarHeight;
222 } 238 }
223 } 239 }
240 [self updateTheme:[self themeProvider]];
224 241
225 [self updateTheme:[self themeProvider]]; 242 // Now that we have all our buttons we can determine the real size
243 // of our window.
244 CGFloat width = 0.0;
245 for (BookmarkButton* button in buttons_.get()) {
246 width = std::max(width, NSWidth([button bounds]));
247 }
248 width = std::min(width, bookmarks::kBookmarkMenuButtonMaximumWidth);
249
250 // Things look and feel more menu-like if all the buttons are the
251 // full width of the window, especially if there are submenus.
252 for (BookmarkButton* button in buttons_.get()) {
253 NSRect buttonFrame = [button frame];
254 buttonFrame.size.width = width;
255 [button setFrame:buttonFrame];
256 }
257
258 // Finally, set our window size.
259 width += (2 * bookmarks::kBookmarkVerticalPadding);
260 windowFrame.size.width = width;
261 [[self window] setFrame:windowFrame display:YES];
262
226 [[parentController_ parentWindow] addChildWindow:[self window] 263 [[parentController_ parentWindow] addChildWindow:[self window]
227 ordered:NSWindowAbove]; 264 ordered:NSWindowAbove];
228 } 265 }
229 266
230 - (ThemeProvider*)themeProvider { 267 - (ThemeProvider*)themeProvider {
231 return [parentController_ themeProvider]; 268 return [parentController_ themeProvider];
232 } 269 }
233 270
234 - (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child { 271 - (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child {
235 // Do nothing. 272 // Do nothing.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 initWithParentButton:sender 639 initWithParentButton:sender
603 parentController:self]; 640 parentController:self];
604 [folderController_ showWindow:self]; 641 [folderController_ showWindow:self];
605 } 642 }
606 643
607 - (NSArray*)buttons { 644 - (NSArray*)buttons {
608 return buttons_.get(); 645 return buttons_.get();
609 } 646 }
610 647
611 @end // BookmarkBarFolderController 648 @end // BookmarkBarFolderController
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.h ('k') | chrome/browser/cocoa/bookmark_bar_folder_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698