summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/download_item_button.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/download_item_button.mm')
-rw-r--r--chrome/browser/cocoa/download_item_button.mm29
1 files changed, 29 insertions, 0 deletions
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