mac: Simple implementation of tray icon.
This commit is contained in:
parent
80fb79daac
commit
6f5184f001
8 changed files with 46 additions and 8 deletions
|
@ -6,14 +6,10 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
TrayIcon::TrayIcon() : model_(NULL) {
|
||||
TrayIcon::TrayIcon() {
|
||||
}
|
||||
|
||||
TrayIcon::~TrayIcon() {
|
||||
}
|
||||
|
||||
void TrayIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
model_ = menu_model;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -28,15 +28,13 @@ class TrayIcon {
|
|||
virtual void SetToolTip(const std::string& tool_tip) = 0;
|
||||
|
||||
// Set the context menu for this icon.
|
||||
void SetContextMenu(ui::SimpleMenuModel* menu_model);
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
|
||||
|
||||
protected:
|
||||
TrayIcon();
|
||||
virtual ~TrayIcon();
|
||||
|
||||
private:
|
||||
ui::SimpleMenuModel* model_; // Weak reference.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TrayIcon);
|
||||
};
|
||||
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
#ifndef ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
||||
#define ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/ui/tray_icon.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
@class AtomMenuController;
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -16,11 +21,17 @@ class TrayIconCocoa : public TrayIcon {
|
|||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||
|
||||
private:
|
||||
TrayIconCocoa();
|
||||
virtual ~TrayIconCocoa();
|
||||
|
||||
base::scoped_nsobject<NSStatusItem> item_;
|
||||
|
||||
// Status menu shown when right-clicking the system icon.
|
||||
base::scoped_nsobject<AtomMenuController> menu_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TrayIconCocoa);
|
||||
};
|
||||
|
||||
|
|
|
@ -4,21 +4,46 @@
|
|||
|
||||
#include "atom/browser/ui/tray_icon_cocoa.h"
|
||||
|
||||
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "skia/ext/skia_utils_mac.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
TrayIconCocoa::TrayIconCocoa() {
|
||||
item_.reset([[[NSStatusBar systemStatusBar]
|
||||
statusItemWithLength:NSVariableStatusItemLength] retain]);
|
||||
[item_ setEnabled:YES];
|
||||
[item_ setHighlightMode:YES];
|
||||
}
|
||||
|
||||
TrayIconCocoa::~TrayIconCocoa() {
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) {
|
||||
if (!image.isNull()) {
|
||||
NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap());
|
||||
if (ns_image)
|
||||
[item_ setImage:ns_image];
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetPressedImage(const gfx::ImageSkia& image) {
|
||||
if (!image.isNull()) {
|
||||
NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap());
|
||||
if (ns_image)
|
||||
[item_ setAlternateImage:ns_image];
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
|
||||
[item_ setToolTip:base::SysUTF8ToNSString(tool_tip)];
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
TrayIcon::SetContextMenu(menu_model);
|
||||
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model]);
|
||||
[item_ setMenu:[menu_ menu]];
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -21,4 +21,7 @@ void TrayIconGtk::SetPressedImage(const gfx::ImageSkia& image) {
|
|||
void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
|
||||
}
|
||||
|
||||
void TrayIconGtk::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -16,6 +16,7 @@ class TrayIconGtk : public TrayIcon {
|
|||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||
|
||||
private:
|
||||
TrayIconGtk();
|
||||
|
|
|
@ -21,4 +21,7 @@ void TrayIconWin::SetPressedImage(const gfx::ImageSkia& image) {
|
|||
void TrayIconWin::SetToolTip(const std::string& tool_tip) {
|
||||
}
|
||||
|
||||
void TrayIconWin::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -16,6 +16,7 @@ class TrayIconWin : public TrayIcon {
|
|||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||
|
||||
private:
|
||||
TrayIconWin();
|
||||
|
|
Loading…
Reference in a new issue