From 7a1951a2d5a549f49714aa243c5f51fa9b86f7a8 Mon Sep 17 00:00:00 2001 From: "jrg@chromium.org" Date: Tue, 14 Jul 2009 00:58:17 +0000 Subject: More bookmark bar changes. * Applied memory cleanliness fix in unit test; follow-up from http://codereview.chromium.org/149308. * Move bookmark bar into it's own nib; minor code refactor to accomodate. * The toolbar STAR button somehow lost it's action; added it back in. * Implemented delete bookmark notification callback so we behave (remove button from the screen) when a bookmark is deleted. * Added context menus for the bookmark bar and bookmark buttons. * Hooked up a handful of these menu items. E.g. - open in new tab, window, incog window - delete bookmark (finally) - bookmark manager (which then hits a NOTIMPLEMENTED()) - always show bookmark bar * Truncate bookmark button text on end, not on middle. Experimental to look more like Windows. It looks cleaner but is less Mac-like. * Add "draws border when mouse goes over" for bookmark buttons. Need to do it by hand since we have a custom button drawing method. BUG=crbug.com/8381 TEST=Here's a list: - Make sure the bookmark buttons don't have a border unless the mouse is over them - Toolbar "STAR" should now add bookmarks when clicked - Test context menus on bookmark buttons, and the bar itself - Confirm a few of the behaviors as listed in the 'what I hooked up'; e.g. Right click on bookmark --> delete menu item should delete button Review URL: http://codereview.chromium.org/155358 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20591 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/gradient_button_cell.mm | 58 ++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'chrome/browser/cocoa/gradient_button_cell.mm') diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index 1ad72d4..87c87ba 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -8,11 +8,62 @@ @implementation GradientButtonCell +- (id)initTextCell:(NSString*)string { + if ((self = [super initTextCell:string])) { + shouldTheme_ = YES; + } + return self; +} + +- (void)setShouldTheme:(BOOL)shouldTheme { + shouldTheme_ = shouldTheme; +} + - (NSBackgroundStyle)interiorBackgroundStyle { return [self isHighlighted] ? NSBackgroundStyleLowered : NSBackgroundStyleRaised; } +- (void)mouseEntered:(NSEvent *)theEvent { + isMouseInside_ = YES; + [[self controlView] setNeedsDisplay:YES]; +} + +- (void)mouseExited:(NSEvent *)theEvent { + isMouseInside_ = NO; + [[self controlView] setNeedsDisplay:YES]; +} + +- (BOOL)isMouseInside { + return trackingArea_ && isMouseInside_; +} + +// Since we have our own drawWithFrame:, we need to also have our own +// logic for determining when the mouse is inside for honoring this +// request. +- (void)setShowsBorderOnlyWhileMouseInside:(BOOL)showOnly { + [super setShowsBorderOnlyWhileMouseInside:showOnly]; + if (showOnly) { + if (trackingArea_.get()) { + [self setShowsBorderOnlyWhileMouseInside:NO]; + } + trackingArea_.reset([[NSTrackingArea alloc] + initWithRect:[[self controlView] + bounds] + options:(NSTrackingMouseEnteredAndExited | + NSTrackingActiveInActiveApp) + owner:self + userInfo:nil]); + [[self controlView] addTrackingArea:trackingArea_]; + } else { + if (trackingArea_) { + [[self controlView] removeTrackingArea:trackingArea_]; + trackingArea_.reset(nil); + isMouseInside_ = NO; + } + } +} + - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { // Constants from Cole. Will kConstant them once the feedback loop // is complete. @@ -50,7 +101,9 @@ // Stroke the borders and appropriate fill gradient. If we're borderless, // the only time we want to draw the inner gradient is if we're highlighted. - if ([self isBordered] || pressed) { + if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || + pressed || + [self isMouseInside]) { [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; [outerPath stroke]; @@ -129,8 +182,7 @@ - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { GTMTheme* theme = [controlView gtm_theme]; - BOOL shouldTheme = YES; - if (shouldTheme) { + if (shouldTheme_) { BOOL isTemplate = [[self image] isTemplate]; [NSGraphicsContext saveGraphicsState]; -- cgit v1.1