Add Tray.displayBallon API

This commit is contained in:
Cheng Zhao 2014-11-28 18:39:30 +08:00
parent 2650e34867
commit 8097cb2b9e
2 changed files with 21 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/ui/tray_icon.h" #include "atom/browser/ui/tray_icon.h"
#include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "native_mate/constructor.h" #include "native_mate/constructor.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
@ -74,6 +75,23 @@ void Tray::SetHighlightMode(mate::Arguments* args, bool highlight) {
tray_icon_->SetHighlightMode(highlight); tray_icon_->SetHighlightMode(highlight);
} }
void Tray::DisplayBalloon(mate::Arguments* args,
const mate::Dictionary& options) {
if (!CheckTrayLife(args))
return;
gfx::ImageSkia icon;
options.Get("icon", &icon);
base::string16 title, content;
if (!options.Get("title", &title) ||
!options.Get("content", &content)) {
args->ThrowError("'title' and 'content' must be defined");
return;
}
tray_icon_->DisplayBalloon(icon, title, content);
}
void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) { void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
if (!CheckTrayLife(args)) if (!CheckTrayLife(args))
return; return;
@ -99,6 +117,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setToolTip", &Tray::SetToolTip) .SetMethod("setToolTip", &Tray::SetToolTip)
.SetMethod("setTitle", &Tray::SetTitle) .SetMethod("setTitle", &Tray::SetTitle)
.SetMethod("setHighlightMode", &Tray::SetHighlightMode) .SetMethod("setHighlightMode", &Tray::SetHighlightMode)
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("_setContextMenu", &Tray::SetContextMenu); .SetMethod("_setContextMenu", &Tray::SetContextMenu);
} }

View file

@ -17,6 +17,7 @@ class ImageSkia;
namespace mate { namespace mate {
class Arguments; class Arguments;
class Dictionary;
} }
namespace atom { namespace atom {
@ -49,6 +50,7 @@ class Tray : public mate::EventEmitter,
void SetToolTip(mate::Arguments* args, const std::string& tool_tip); void SetToolTip(mate::Arguments* args, const std::string& tool_tip);
void SetTitle(mate::Arguments* args, const std::string& title); void SetTitle(mate::Arguments* args, const std::string& title);
void SetHighlightMode(mate::Arguments* args, bool highlight); void SetHighlightMode(mate::Arguments* args, bool highlight);
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
void SetContextMenu(mate::Arguments* args, Menu* menu); void SetContextMenu(mate::Arguments* args, Menu* menu);
private: private: