]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Implement menu parameter
authorCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 11:05:22 +0000 (19:05 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 11:05:22 +0000 (19:05 +0800)
atom/browser/api/atom_api_tray.cc
atom/browser/ui/tray_icon_cocoa.mm

index 1e1c7c304d8287a55302ac139f8b4781574327a6..3b1a3a6321bbe6682ba1f4d3889a23b6b017b3f1 100644 (file)
@@ -137,11 +137,11 @@ void Tray::DisplayBalloon(mate::Arguments* args,
 }
 
 void Tray::PopUpContextMenu(mate::Arguments* args) {
-  Menu* menu = nullptr;
+  mate::Handle<Menu> menu;
   args->GetNext(&menu);
   gfx::Point pos;
   args->GetNext(&pos);
-  tray_icon_->PopUpContextMenu(pos, menu ? menu->model() : nullptr);
+  tray_icon_->PopUpContextMenu(pos, menu.IsEmpty() ? nullptr : menu->model());
 }
 
 void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
index 5005234ab13129567d2a64ca50175e97888b4476..997ac6fd3134e48385141faabec0f9eb57aaa7d4 100644 (file)
@@ -23,6 +23,7 @@ const CGFloat kVerticalTitleMargin = 2;
   atom::TrayIconCocoa* trayIcon_; // weak
   AtomMenuController* menuController_; // weak
   BOOL isHighlightEnable_;
+  BOOL forceHighlight_;
   BOOL inMouseEventSequence_;
   base::scoped_nsobject<NSImage> image_;
   base::scoped_nsobject<NSImage> alternateImage_;
@@ -39,6 +40,8 @@ const CGFloat kVerticalTitleMargin = 2;
   image_.reset([image copy]);
   trayIcon_ = icon;
   isHighlightEnable_ = YES;
+  forceHighlight_ = NO;
+  inMouseEventSequence_ = NO;
 
   if ((self = [super initWithFrame: CGRectZero])) {
     // Setup the image view.
@@ -238,7 +241,19 @@ const CGFloat kVerticalTitleMargin = 2;
   [self setNeedsDisplay:YES];
 }
 
-- (void)popUpContextMenu {
+- (void)popUpContextMenu:(ui::SimpleMenuModel*)menu_model {
+  // Show a custom menu.
+  if (menu_model) {
+    base::scoped_nsobject<AtomMenuController> menuController(
+        [[AtomMenuController alloc] initWithModel:menu_model]);
+    forceHighlight_ = YES;  // Should highlight when showing menu.
+    [self setNeedsDisplay:YES];
+    [statusItem_ popUpStatusItemMenu:[menuController menu]];
+    forceHighlight_ = NO;
+    [self setNeedsDisplay:YES];
+    return;
+  }
+
   if (menuController_ && ![menuController_ isMenuOpen]) {
     // Redraw the dray icon to show highlight if it is enabled.
     [self setNeedsDisplay:YES];
@@ -288,6 +303,8 @@ const CGFloat kVerticalTitleMargin = 2;
 }
 
 - (BOOL)shouldHighlight {
+  if (isHighlightEnable_ && forceHighlight_)
+    return true;
   BOOL isMenuOpen = menuController_ && [menuController_ isMenuOpen];
   return isHighlightEnable_ && (inMouseEventSequence_ || isMenuOpen);
 }
@@ -340,7 +357,7 @@ void TrayIconCocoa::SetHighlightMode(bool highlight) {
 
 void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
                                      ui::SimpleMenuModel* menu_model) {
-  [status_item_view_ popUpContextMenu];
+  [status_item_view_ popUpContextMenu:menu_model];
 }
 
 void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {