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

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: Remove unneeded scoped ptrs. 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..fb4fe47bf00b15b545015b1965de1419eb0ea020 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,17 @@
}
}
+- (void)showContextMenu {
+ base::scoped_nsobject<DownloadShelfContextMenuController> menuController(
+ [[DownloadShelfContextMenuController alloc]
+ initWithItemController:controller_
+ withDelegate:self]);
+ showingContextMenu_ = YES;
+ [NSMenu popUpContextMenu:[menuController menu]
+ withEvent:[NSApp currentEvent]
+ forView:self];
+}
+
// Override to show a context menu on mouse down if clicked over the context
// menu area.
- (void)mouseDown:(NSEvent*)event {
@@ -35,15 +46,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];
}
}
@@ -55,6 +59,7 @@
}
- (void)menuDidClose:(NSMenu*)menu {
+ showingContextMenu_ = NO;
[[self cell] setHighlighted:NO];
}
@@ -84,4 +89,32 @@
[self setNeedsDisplay:YES];
}
+- (BOOL)showingContextMenu
+{
+ return showingContextMenu_;
+}
+
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
asanka 2015/05/08 17:12:47 Shall we trigger the menu close logic on the downl
shrike 2015/05/08 17:52:04 By "described above" do you mean your previous com
asanka 2015/05/12 01:27:33 Sorry, I was referring to https://codereview.chrom
+ // If the DownloadItemButton's context menu is still visible, synthesize an
+ // Escape key event to hide it (there is no API to explicitly dismiss a
+ // pop up menu).
asanka 2015/05/08 17:12:47 What about NSMenu cancelTracking: ?
shrike 2015/05/08 17:52:04 Indeed, but the problem is that popUpContextMenu:
asanka 2015/05/12 01:27:33 Can we keep a reference to the DownloadShelfContex
+ if (showingContextMenu_ && !newWindow) {
+ unichar escapeString[] = { 27, 0 };
+ NSString* escapeCharacterString =
+ [NSString stringWithCharacters:escapeString length:1];
+ NSEvent* escapeKeyEvent =
+ [NSEvent keyEventWithType:NSKeyDown
+ location:NSZeroPoint
+ modifierFlags:0
+ timestamp:[[NSDate date] timeIntervalSinceNow]
+ windowNumber:[[self window] windowNumber]
+ context:NULL
+ characters:escapeCharacterString
+ charactersIgnoringModifiers:escapeCharacterString
+ isARepeat:NO
+ keyCode:53];
+ [[NSApplication sharedApplication] postEvent:escapeKeyEvent atStart:YES];
+ }
+}
+
@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