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

Unified Diff: ui/base/cocoa/menu_controller.mm

Issue 2863883002: Tracing for NSMenu timelines
Patch Set: big CL with more trace points Created 3 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
« no previous file with comments | « ui/base/cocoa/menu_controller.h ('k') | ui/base/cocoa/menu_controller_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/cocoa/menu_controller.mm
diff --git a/ui/base/cocoa/menu_controller.mm b/ui/base/cocoa/menu_controller.mm
index 0c42fe7ba34504e04d011ebb24215a1f75ea9e2d..7ae478a92880aea9eb5948dfc590865bc769fc37 100644
--- a/ui/base/cocoa/menu_controller.mm
+++ b/ui/base/cocoa/menu_controller.mm
@@ -25,6 +25,9 @@ NSString* const kMenuControllerMenuDidCloseNotification =
atIndex:(int)index;
@end
+@interface ResponsiveNSMenuItem : NSMenuItem
+@end
+
@implementation MenuController
@synthesize model = model_;
@@ -60,6 +63,8 @@ NSString* const kMenuControllerMenuDidCloseNotification =
[self cancel];
model_ = NULL;
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
[super dealloc];
}
@@ -112,10 +117,10 @@ NSString* const kMenuControllerMenuDidCloseNotification =
label16 = [MenuController elideMenuTitle:label16 toWidth:maxWidth];
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);
- base::scoped_nsobject<NSMenuItem> item(
- [[NSMenuItem alloc] initWithTitle:label
- action:@selector(itemSelected:)
- keyEquivalent:@""]);
+ base::scoped_nsobject<NSMenuItem> item([[ResponsiveNSMenuItem alloc]
+ initWithTitle:label
+ action:@selector(itemSelected:)
+ keyEquivalent:@""]);
// If the menu item has an icon, set it.
gfx::Image icon;
@@ -200,9 +205,19 @@ NSString* const kMenuControllerMenuDidCloseNotification =
return NO;
}
-// Called when the user chooses a particular menu item. |sender| is the menu
-// item chosen.
+- (void)itemWillBeSelected:(id)sender {
+ suppressNextItemSelected_ = [self processItemSelectedEarly:sender];
+}
+
+- (BOOL)processItemSelectedEarly:(id)sender {
+ return NO;
+}
+
- (void)itemSelected:(id)sender {
+ DLOG(INFO) << "got action";
+ if (suppressNextItemSelected_)
+ return;
+
NSInteger modelIndex = [sender tag];
ui::MenuModel* model =
static_cast<ui::MenuModel*>(
@@ -237,13 +252,20 @@ NSString* const kMenuControllerMenuDidCloseNotification =
- (void)menuWillOpen:(NSMenu*)menu {
isMenuOpen_ = YES;
+ suppressNextItemSelected_ = NO;
model_->MenuWillShow();
[[NSNotificationCenter defaultCenter]
postNotificationName:kMenuControllerMenuWillOpenNotification
object:self];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(willSendAction:)
+ name:NSMenuWillSendActionNotification
+ object:nil];
}
- (void)menuDidClose:(NSMenu*)menu {
+ DLOG(INFO) << "did close";
if (isMenuOpen_) {
model_->MenuWillClose();
isMenuOpen_ = NO;
@@ -253,4 +275,24 @@ NSString* const kMenuControllerMenuDidCloseNotification =
object:self];
}
+- (void)willSendAction:(NSNotification*)note {
+ DLOG(INFO) << "will send action";
+}
+
+@end
+
+@interface NSMenuItem (Private)
+// Private method which is invoked very soon after the event that activates a
+// menu item is received. AppKit then spends 300ms or so flashing the menu item,
+// and fading out the menu, blocking the UI thread the entire time.
+- (void)_sendItemSelectedNote;
+@end
+
+@implementation ResponsiveNSMenuItem
+- (void)_sendItemSelectedNote {
+ DLOG(INFO) << "early";
+ if ([[self target] respondsToSelector:@selector(itemWillBeSelected:)])
+ [[self target] itemWillBeSelected:self];
+ [super _sendItemSelectedNote];
+}
@end
« no previous file with comments | « ui/base/cocoa/menu_controller.h ('k') | ui/base/cocoa/menu_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698