Chromium Code Reviews| 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 |