]> khamidou — GitHub mirrors - electron.git/commitdiff
Add "click" event for TrayIcon.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 2 Jun 2014 03:08:29 +0000 (11:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 2 Jun 2014 03:08:29 +0000 (11:08 +0800)
atom.gyp
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_observer.h [new file with mode: 0644]

index a00a487fb4fe97e2075b05bdc2ec2c904cef2984..d0503227386a50cd2523573dbf62ddd4517d00be 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'atom/browser/ui/tray_icon_gtk.cc',
       'atom/browser/ui/tray_icon_cocoa.h',
       'atom/browser/ui/tray_icon_cocoa.mm',
+      'atom/browser/ui/tray_icon_observer.h',
       'atom/browser/ui/tray_icon_win.cc',
       'atom/browser/ui/tray_icon_win.h',
       'atom/browser/ui/win/menu_2.cc',
index 51fb2d954570aad53103a159daa0aea4f3df6ab0..1fc6aa936af0033c5675653fe93a899802ef49b8 100644 (file)
@@ -31,6 +31,10 @@ mate::Wrappable* Tray::New(const gfx::ImageSkia& image) {
   return new Tray(image);
 }
 
+void Tray::OnClicked() {
+  Emit("clicked");
+}
+
 void Tray::SetImage(const gfx::ImageSkia& image) {
   tray_icon_->SetImage(image);
 }
index 8040f0f99750261f94c91c4b934fbccd4d39d2e1..5dce0cbe9546dfb467636cc879c9388cc508e7bc 100644 (file)
@@ -8,6 +8,7 @@
 #include <string>
 
 #include "atom/browser/api/event_emitter.h"
+#include "atom/browser/ui/tray_icon_observer.h"
 #include "base/memory/scoped_ptr.h"
 
 namespace gfx {
@@ -22,7 +23,8 @@ namespace api {
 
 class Menu;
 
-class Tray : public mate::EventEmitter {
+class Tray : public mate::EventEmitter,
+             public TrayIconObserver {
  public:
   static mate::Wrappable* New(const gfx::ImageSkia& image);
 
@@ -33,6 +35,9 @@ class Tray : public mate::EventEmitter {
   explicit Tray(const gfx::ImageSkia& image);
   virtual ~Tray();
 
+  // TrayIcon implementations:
+  virtual void OnClicked() OVERRIDE;
+
   void SetImage(const gfx::ImageSkia& image);
   void SetPressedImage(const gfx::ImageSkia& image);
   void SetToolTip(const std::string& tool_tip);
index c67c9bbcf562d1fc54aa7e113a85afa69c49ac7d..fdbdf7a5395cca8195ec91860f18f80e9efbde7d 100644 (file)
@@ -12,4 +12,8 @@ TrayIcon::TrayIcon() {
 TrayIcon::~TrayIcon() {
 }
 
+void TrayIcon::NotifyClicked() {
+  FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked());
+}
+
 }  // namespace atom
index 67f3150d40e29f7d1aff8d98a2ead0c2e9fddf8d..80de248810bb7502a6a141db64318fead5cc658d 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <string>
 
+#include "atom/browser/ui/tray_icon_observer.h"
+#include "base/observer_list.h"
 #include "ui/base/models/simple_menu_model.h"
 
 namespace atom {
@@ -32,10 +34,16 @@ class TrayIcon {
   // Set the context menu for this icon.
   virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
 
+  void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
+  void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
+  void NotifyClicked();
+
  protected:
   TrayIcon();
 
  private:
+  ObserverList<TrayIconObserver> observers_;
+
   DISALLOW_COPY_AND_ASSIGN(TrayIcon);
 };
 
diff --git a/atom/browser/ui/tray_icon_observer.h b/atom/browser/ui/tray_icon_observer.h
new file mode 100644 (file)
index 0000000..621530f
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
+#define ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_
+
+namespace atom {
+
+class TrayIconObserver {
+ public:
+  virtual void OnClicked() {};
+
+ protected:
+  virtual ~TrayIconObserver() {};
+};
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_UI_TRAY_ICON_OBSERVER_H_