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

Unified Diff: chrome/browser/ui/cocoa/download/download_item_button.mm

Issue 1125423002: Dismiss context menu when download bar is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refine unit test. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/download/download_item_button.mm
diff --git a/chrome/browser/ui/cocoa/download/download_item_button.mm b/chrome/browser/ui/cocoa/download/download_item_button.mm
index 141976df7e2fe28b127630acc84160c28e60b21d..b2b6ae9cb369f6abcff4e13df8719469c5628ad3 100644
--- a/chrome/browser/ui/cocoa/download/download_item_button.mm
+++ b/chrome/browser/ui/cocoa/download/download_item_button.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,6 +25,18 @@
}
}
+- (void)showContextMenu {
+ base::scoped_nsobject<DownloadShelfContextMenuController> menuController(
+ [[DownloadShelfContextMenuController alloc]
+ initWithItemController:controller_
+ withDelegate:self]);
+ contextMenu_.reset([[menuController menu] retain]);
+ [NSMenu popUpContextMenu:contextMenu_.get()
+ withEvent:[NSApp currentEvent]
+ forView:self];
+ contextMenu_.reset();
+}
+
// Override to show a context menu on mouse down if clicked over the context
// menu area.
- (void)mouseDown:(NSEvent*)event {
@@ -35,15 +47,8 @@
if ([reinterpret_cast<DownloadItemCell*>(cell) isMouseOverButtonPart]) {
[self.draggableButton mouseDownImpl:event];
} else {
- base::scoped_nsobject<DownloadShelfContextMenuController> menuController(
- [[DownloadShelfContextMenuController alloc]
- initWithItemController:controller_
- withDelegate:self]);
-
[cell setHighlighted:YES];
- [NSMenu popUpContextMenu:[menuController menu]
- withEvent:[NSApp currentEvent]
- forView:self];
+ [self showContextMenu];
}
}
@@ -84,4 +89,16 @@
[self setNeedsDisplay:YES];
}
+- (BOOL)showingContextMenu
+{
+ return contextMenu_.get() != nil;
+}
+
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
+ // If the DownloadItemButton's context menu is still visible, dismiss it.
+ if (!newWindow) {
+ [contextMenu_.get() cancelTrackingWithoutAnimation];
+ }
+}
+
@end
« no previous file with comments | « chrome/browser/ui/cocoa/download/download_item_button.h ('k') | chrome/browser/ui/cocoa/download/download_item_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698