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 {
|
namespace atom {
|
||||||
|
|
||||||
TrayIcon::TrayIcon() : model_(NULL) {
|
TrayIcon::TrayIcon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TrayIcon::~TrayIcon() {
|
TrayIcon::~TrayIcon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
|
||||||
model_ = menu_model;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -28,15 +28,13 @@ class TrayIcon {
|
||||||
virtual void SetToolTip(const std::string& tool_tip) = 0;
|
virtual void SetToolTip(const std::string& tool_tip) = 0;
|
||||||
|
|
||||||
// Set the context menu for this icon.
|
// Set the context menu for this icon.
|
||||||
void SetContextMenu(ui::SimpleMenuModel* menu_model);
|
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TrayIcon();
|
TrayIcon();
|
||||||
virtual ~TrayIcon();
|
virtual ~TrayIcon();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ui::SimpleMenuModel* model_; // Weak reference.
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(TrayIcon);
|
DISALLOW_COPY_AND_ASSIGN(TrayIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,14 @@
|
||||||
#ifndef ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
#ifndef ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
||||||
#define ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
#define ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/browser/ui/tray_icon.h"
|
#include "atom/browser/ui/tray_icon.h"
|
||||||
|
#include "base/mac/scoped_nsobject.h"
|
||||||
|
|
||||||
|
@class AtomMenuController;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -16,11 +21,17 @@ class TrayIconCocoa : public TrayIcon {
|
||||||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||||
|
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayIconCocoa();
|
TrayIconCocoa();
|
||||||
virtual ~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);
|
DISALLOW_COPY_AND_ASSIGN(TrayIconCocoa);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,46 @@
|
||||||
|
|
||||||
#include "atom/browser/ui/tray_icon_cocoa.h"
|
#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 {
|
namespace atom {
|
||||||
|
|
||||||
TrayIconCocoa::TrayIconCocoa() {
|
TrayIconCocoa::TrayIconCocoa() {
|
||||||
|
item_.reset([[[NSStatusBar systemStatusBar]
|
||||||
|
statusItemWithLength:NSVariableStatusItemLength] retain]);
|
||||||
|
[item_ setEnabled:YES];
|
||||||
|
[item_ setHighlightMode:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
TrayIconCocoa::~TrayIconCocoa() {
|
TrayIconCocoa::~TrayIconCocoa() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) {
|
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) {
|
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) {
|
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
|
} // namespace atom
|
||||||
|
|
|
@ -21,4 +21,7 @@ void TrayIconGtk::SetPressedImage(const gfx::ImageSkia& image) {
|
||||||
void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
|
void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIconGtk::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -16,6 +16,7 @@ class TrayIconGtk : public TrayIcon {
|
||||||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||||
|
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayIconGtk();
|
TrayIconGtk();
|
||||||
|
|
|
@ -21,4 +21,7 @@ void TrayIconWin::SetPressedImage(const gfx::ImageSkia& image) {
|
||||||
void TrayIconWin::SetToolTip(const std::string& tool_tip) {
|
void TrayIconWin::SetToolTip(const std::string& tool_tip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayIconWin::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -16,6 +16,7 @@ class TrayIconWin : public TrayIcon {
|
||||||
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
|
||||||
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
virtual void SetToolTip(const std::string& tool_tip) OVERRIDE;
|
||||||
|
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayIconWin();
|
TrayIconWin();
|
||||||
|
|
Loading…
Reference in a new issue