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

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

Issue 7465090: [Mac] Replace the custom bookmark menus with native NSMenus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
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/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #import "chrome/browser/bookmarks/bookmark_model.h" 9 #import "chrome/browser/bookmarks/bookmark_model.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_menu.h" 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu.h"
12 #import "chrome/browser/ui/cocoa/image_utils.h" 12 #import "chrome/browser/ui/cocoa/image_utils.h"
13 #include "content/browser/user_metrics.h" 13 #include "content/browser/user_metrics.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util_mac.h" 15 #include "ui/base/l10n/l10n_util_mac.h"
16 #include "ui/gfx/mac/nsimage_cache.h"
17 16
18 17
19 @interface BookmarkButtonCell(Private) 18 @interface BookmarkButtonCell(Private)
20 - (void)configureBookmarkButtonCell; 19 - (void)configureBookmarkButtonCell;
21 - (void)applyTextColor; 20 - (void)applyTextColor;
22 @end 21 @end
23 22
24 23
25 @implementation BookmarkButtonCell 24 @implementation BookmarkButtonCell
26 25
27 @synthesize startingChildIndex = startingChildIndex_; 26 @synthesize startingChildIndex = startingChildIndex_;
28 @synthesize drawFolderArrow = drawFolderArrow_;
29 27
30 + (id)buttonCellForNode:(const BookmarkNode*)node 28 + (id)buttonCellForNode:(const BookmarkNode*)node
31 contextMenu:(NSMenu*)contextMenu 29 contextMenu:(NSMenu*)contextMenu
32 cellText:(NSString*)cellText 30 cellText:(NSString*)cellText
33 cellImage:(NSImage*)cellImage { 31 cellImage:(NSImage*)cellImage {
34 id buttonCell = 32 id buttonCell =
35 [[[BookmarkButtonCell alloc] initForNode:node 33 [[[BookmarkButtonCell alloc] initForNode:node
36 contextMenu:contextMenu 34 contextMenu:contextMenu
37 cellText:cellText 35 cellText:cellText
38 cellImage:cellImage] 36 cellImage:cellImage]
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 [super mouseEntered:event]; 199 [super mouseEntered:event];
202 [[self controlView] mouseEntered:event]; 200 [[self controlView] mouseEntered:event];
203 } 201 }
204 202
205 // See comment above mouseEntered:, above. 203 // See comment above mouseEntered:, above.
206 - (void)mouseExited:(NSEvent*)event { 204 - (void)mouseExited:(NSEvent*)event {
207 [[self controlView] mouseExited:event]; 205 [[self controlView] mouseExited:event];
208 [super mouseExited:event]; 206 [super mouseExited:event];
209 } 207 }
210 208
211 - (void)setDrawFolderArrow:(BOOL)draw {
212 drawFolderArrow_ = draw;
213 if (draw && !arrowImage_) {
214 arrowImage_.reset(
215 [gfx::GetCachedImageWithName(@"menu_hierarchy_arrow.pdf") retain]);
216 }
217 }
218
219 // Add extra size for the arrow so it doesn't overlap the text.
220 // Does not sanity check to be sure this is actually a folder node.
221 - (NSSize)cellSize {
222 NSSize cellSize = [super cellSize];
223 if (drawFolderArrow_) {
224 cellSize.width += [arrowImage_ size].width; // plus margin?
225 }
226 return cellSize;
227 }
228
229 // Override cell drawing to add a submenu arrow like a real menu.
230 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
231 // First draw "everything else".
232 [super drawInteriorWithFrame:cellFrame inView:controlView];
233
234 // If asked to do so, and if a folder, draw the arrow.
235 if (!drawFolderArrow_)
236 return;
237 BookmarkButton* button = static_cast<BookmarkButton*>([self controlView]);
238 DCHECK([button respondsToSelector:@selector(isFolder)]);
239 if ([button isFolder]) {
240 NSRect imageRect = NSZeroRect;
241 imageRect.size = [arrowImage_ size];
242 const CGFloat kArrowOffset = 1.0; // Required for proper centering.
243 CGFloat dX = NSWidth(cellFrame) - NSWidth(imageRect);
244 CGFloat dY = (NSHeight(cellFrame) / 2.0) - (NSHeight(imageRect) / 2.0) +
245 kArrowOffset;
246 NSRect drawRect = NSOffsetRect(imageRect, dX, dY);
247 [arrowImage_ drawInRect:drawRect
248 fromRect:imageRect
249 operation:NSCompositeSourceOver
250 fraction:[self isEnabled] ? 1.0 : 0.5
251 neverFlipped:YES];
252 }
253 }
254
255 @end 209 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698