diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/cocoa/download_item_button.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_button.mm | 29 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_controller.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_controller.mm | 27 |
5 files changed, 47 insertions, 23 deletions
diff --git a/chrome/browser/cocoa/download_item_button.h b/chrome/browser/cocoa/download_item_button.h index 5ce1a01..b421e3b 100644 --- a/chrome/browser/cocoa/download_item_button.h +++ b/chrome/browser/cocoa/download_item_button.h @@ -7,13 +7,18 @@ #include "base/file_path.h" #import "chrome/browser/cocoa/draggable_button.h" -// A button that is a drag source for a file. +@class DownloadItemController; + +// A button that is a drag source for a file and that displays a context menu +// instead of firing an action when clicked in a certain area. @interface DownloadItemButton : DraggableButton { @private FilePath downloadPath_; + DownloadItemController* controller_; // weak } @property(assign, nonatomic) FilePath download; +@property(assign, nonatomic) DownloadItemController* controller; // Overridden from DraggableButton. - (void)beginDrag:(NSEvent*)event; diff --git a/chrome/browser/cocoa/download_item_button.mm b/chrome/browser/cocoa/download_item_button.mm index 41a62c8..dd46c53 100644 --- a/chrome/browser/cocoa/download_item_button.mm +++ b/chrome/browser/cocoa/download_item_button.mm @@ -4,11 +4,15 @@ #import "chrome/browser/cocoa/download_item_button.h" +#include "base/logging.h" #include "base/sys_string_conversions.h" +#import "chrome/browser/cocoa/download_item_cell.h" +#import "chrome/browser/cocoa/download_item_controller.h" @implementation DownloadItemButton @synthesize download = downloadPath_; +@synthesize controller = controller_; // Overridden from DraggableButton. - (void)beginDrag:(NSEvent*)event { @@ -18,4 +22,29 @@ } } +// Override to show a context menu on mouse down if clicked over the context +// menu area. +- (void)mouseDown:(NSEvent*)event { + DCHECK(controller_); + // Override so that we can pop up a context menu on mouse down. + NSCell* cell = [self cell]; + DCHECK([cell respondsToSelector:@selector(isMouseOverButtonPart)]); + if ([reinterpret_cast<DownloadItemCell*>(cell) isMouseOverButtonPart]) { + [super mouseDown:event]; + } else { + // Hold a reference to our controller in case the download completes and we + // represent a file that's auto-removed (e.g. a theme). + scoped_nsobject<DownloadItemController> ref([controller_ retain]); + [cell setHighlighted:YES]; + [[self menu] setDelegate:self]; + [NSMenu popUpContextMenu:[self menu] + withEvent:[NSApp currentEvent] + forView:self]; + } +} + +- (void)menuDidClose:(NSMenu*)menu { + [[self cell] setHighlighted:NO]; +} + @end diff --git a/chrome/browser/cocoa/download_item_cell.h b/chrome/browser/cocoa/download_item_cell.h index 248225c..8cfca82 100644 --- a/chrome/browser/cocoa/download_item_cell.h +++ b/chrome/browser/cocoa/download_item_cell.h @@ -52,9 +52,8 @@ enum DownloadItemMousePosition { @property (copy) NSString* secondaryTitle; @property (retain) NSFont* secondaryFont; -// Valid to call in response to a click of the cell's button. Returns if the -// button part of the cell was clicked. -- (BOOL)isButtonPartPressed; +// Returns if the mouse is over the button part of the cell. +- (BOOL)isMouseOverButtonPart; @end diff --git a/chrome/browser/cocoa/download_item_controller.h b/chrome/browser/cocoa/download_item_controller.h index a4c7f66..7d7b769 100644 --- a/chrome/browser/cocoa/download_item_controller.h +++ b/chrome/browser/cocoa/download_item_controller.h @@ -27,8 +27,6 @@ class DownloadShelfContextMenuMac; IBOutlet NSMenu* activeDownloadMenu_; IBOutlet NSMenu* completeDownloadMenu_; - NSMenu* currentMenu_; // points to one of the two menus above - // This is shown instead of progressView_ for dangerous downloads. IBOutlet NSView* dangerousDownloadView_; IBOutlet NSTextField* dangerousDownloadLabel_; diff --git a/chrome/browser/cocoa/download_item_controller.mm b/chrome/browser/cocoa/download_item_controller.mm index b2ff7ff..a00313c 100644 --- a/chrome/browser/cocoa/download_item_controller.mm +++ b/chrome/browser/cocoa/download_item_controller.mm @@ -100,11 +100,14 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + [progressView_ setController:nil]; [[self view] removeFromSuperview]; [super dealloc]; } - (void)awakeFromNib { + [progressView_ setController:self]; + [self setStateFromDownload:bridge_->download_model()]; GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = @@ -164,13 +167,12 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { // Set correct popup menu. Also, set draggable download on completion. if (downloadModel->download()->state() == DownloadItem::COMPLETE) { - currentMenu_ = completeDownloadMenu_; + [progressView_ setMenu:completeDownloadMenu_]; [progressView_ setDownload:downloadModel->download()->full_path()]; } else { - currentMenu_ = activeDownloadMenu_; + [progressView_ setMenu:activeDownloadMenu_]; } - [progressView_ setMenu:currentMenu_]; // for context menu [cell_ setStateFromDownload:downloadModel]; } @@ -195,20 +197,11 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { } - (IBAction)handleButtonClick:(id)sender { - if ([cell_ isButtonPartPressed]) { - DownloadItem* download = bridge_->download_model()->download(); - if (download->state() == DownloadItem::IN_PROGRESS) - download->set_open_when_complete(!download->open_when_complete()); - else if (download->state() == DownloadItem::COMPLETE) - download_util::OpenDownload(download); - } else { - // Hold a reference to ourselves in case the download completes and we - // represent a file that's auto-removed (e.g. a theme). - scoped_nsobject<DownloadItemController> ref([self retain]); - [NSMenu popUpContextMenu:currentMenu_ - withEvent:[NSApp currentEvent] - forView:progressView_]; - } + DownloadItem* download = bridge_->download_model()->download(); + if (download->state() == DownloadItem::IN_PROGRESS) + download->set_open_when_complete(!download->open_when_complete()); + else if (download->state() == DownloadItem::COMPLETE) + download_util::OpenDownload(download); } - (NSSize)preferredSize { |