]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement 'right-clicked' tray event on OS X.
authorHaojian Wu <hokein.wu@gmail.com>
Wed, 15 Jul 2015 11:23:12 +0000 (19:23 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Wed, 15 Jul 2015 11:32:00 +0000 (19:32 +0800)
atom/browser/api/atom_api_tray.cc
atom/browser/api/atom_api_tray.h
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.mm
atom/browser/ui/tray_icon_observer.h

index 649967a2b1ebfc35c75451bd936341c9fa293fef..7c1bfdfac95a0d885ec01467e3f377de87e46184 100644 (file)
@@ -60,6 +60,10 @@ void Tray::OnBalloonClosed() {
   Emit("balloon-closed");
 }
 
+void Tray::OnRightClicked(const gfx::Rect& bounds) {
+  Emit("right-clicked", bounds);
+}
+
 bool Tray::IsDestroyed() const {
   return !tray_icon_;
 }
index 1a4a498d16b9f87491ba96c8a951812e1e471a13..366a847ac602c20fe33273d407930a82e096d14a 100644 (file)
@@ -46,6 +46,7 @@ class Tray : public mate::EventEmitter,
   void OnBalloonShow() override;
   void OnBalloonClicked() override;
   void OnBalloonClosed() override;
+  void OnRightClicked(const gfx::Rect&) override;
 
   // mate::Wrappable:
   bool IsDestroyed() const override;
index a3878f718a6236ef82e0788dd77fdd8d459596c6..4f801faf862ead2ecbfe4b55d20e6b88a534802f 100644 (file)
@@ -46,4 +46,8 @@ void TrayIcon::NotifyBalloonClosed() {
   FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClosed());
 }
 
+void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds) {
+  FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnRightClicked(bounds));
+}
+
 }  // namespace atom
index 7dc67da1bac4f14158824aa8c002120005994b7f..4e097e0ac84aa1cfb9e8a4b7f5634d66bec653c3 100644 (file)
@@ -56,6 +56,7 @@ class TrayIcon {
   void NotifyBalloonShow();
   void NotifyBalloonClicked();
   void NotifyBalloonClosed();
+  void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect());
 
  protected:
   TrayIcon();
index 11efbe0aee900e60c0822409ac5ecb6ef752f849..2d0acdd6aaf40215ade97a9fec84ec064c1ea10c 100644 (file)
@@ -75,7 +75,7 @@ const CGFloat kMargin = 3;
                                    title_width + kStatusItemLength,
                                    [[statusItem_ statusBar] thickness]);
     [title_ drawInRect:title_rect
-          withAttributes:[self titleAttributes]];
+        withAttributes:[self titleAttributes]];
     [statusItem_ setLength:title_width + kStatusItemLength];
   }
 }
@@ -129,11 +129,7 @@ const CGFloat kMargin = 3;
       [statusItem_ popUpStatusItemMenu:[menu_controller_ menu]];
     }
 
-    NSRect frame = event.window.frame;
-    gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
-    NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
-    bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
-    trayIcon_->NotifyClicked(bounds);
+    trayIcon_->NotifyClicked([self getBoundsFromEvent:event]);
   }
 
   if (event.clickCount == 2 && !menu_controller_) {
@@ -142,11 +138,22 @@ const CGFloat kMargin = 3;
   [self setNeedsDisplay:YES];
 }
 
+- (void)rightMouseUp:(NSEvent*)event {
+  trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
+}
+
 -(BOOL) shouldHighlight {
   BOOL is_menu_open = [menu_controller_ isMenuOpen];
   return isHighlightEnable_ && (inMouseEventSequence_ || is_menu_open);
 }
 
+-(gfx::Rect) getBoundsFromEvent:(NSEvent*)event {
+  NSRect frame = event.window.frame;
+  gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
+  NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
+  bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
+  return bounds;
+}
 @end
 
 namespace atom {
index 3a34888b5318f4df08052aaeba7f5cf607496785..061115efdc64227277d032bdbf85bf0e4a3c0957 100644 (file)
@@ -18,6 +18,7 @@ class TrayIconObserver {
   virtual void OnBalloonShow() {}
   virtual void OnBalloonClicked() {}
   virtual void OnBalloonClosed() {}
+  virtual void OnRightClicked(const gfx::Rect&) {}
 
  protected:
   virtual ~TrayIconObserver() {}