feat: add tray.getTitle() (#17385)
* feat: add tray.getTitle * fix spec
This commit is contained in:
parent
38d75010c7
commit
2fb9085e5b
8 changed files with 53 additions and 14 deletions
|
@ -159,7 +159,17 @@ void Tray::SetToolTip(const std::string& tool_tip) {
|
|||
}
|
||||
|
||||
void Tray::SetTitle(const std::string& title) {
|
||||
#if defined(OS_MACOSX)
|
||||
tray_icon_->SetTitle(title);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Tray::GetTitle() {
|
||||
#if defined(OS_MACOSX)
|
||||
return tray_icon_->GetTitle();
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
void Tray::SetHighlightMode(TrayIcon::HighlightMode mode) {
|
||||
|
@ -227,6 +237,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setPressedImage", &Tray::SetPressedImage)
|
||||
.SetMethod("setToolTip", &Tray::SetToolTip)
|
||||
.SetMethod("setTitle", &Tray::SetTitle)
|
||||
.SetMethod("getTitle", &Tray::GetTitle)
|
||||
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
|
||||
.SetMethod("setIgnoreDoubleClickEvents",
|
||||
&Tray::SetIgnoreDoubleClickEvents)
|
||||
|
|
|
@ -69,6 +69,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
|
|||
void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
void SetToolTip(const std::string& tool_tip);
|
||||
void SetTitle(const std::string& title);
|
||||
std::string GetTitle();
|
||||
void SetHighlightMode(TrayIcon::HighlightMode mode);
|
||||
void SetIgnoreDoubleClickEvents(bool ignore);
|
||||
bool GetIgnoreDoubleClickEvents();
|
||||
|
|
|
@ -12,8 +12,6 @@ TrayIcon::~TrayIcon() {}
|
|||
|
||||
void TrayIcon::SetPressedImage(ImageType image) {}
|
||||
|
||||
void TrayIcon::SetTitle(const std::string& title) {}
|
||||
|
||||
void TrayIcon::SetHighlightMode(TrayIcon::HighlightMode mode) {}
|
||||
|
||||
void TrayIcon::DisplayBalloon(ImageType icon,
|
||||
|
|
|
@ -39,10 +39,6 @@ class TrayIcon {
|
|||
// status icon (e.g. Ubuntu Unity).
|
||||
virtual void SetToolTip(const std::string& tool_tip) = 0;
|
||||
|
||||
// Sets the title displayed aside of the status icon in the status bar. This
|
||||
// only works on macOS.
|
||||
virtual void SetTitle(const std::string& title);
|
||||
|
||||
// Sets the status icon highlight mode. This only works on macOS.
|
||||
enum HighlightMode {
|
||||
ALWAYS, // Always highlight the tray icon
|
||||
|
@ -51,11 +47,14 @@ class TrayIcon {
|
|||
};
|
||||
virtual void SetHighlightMode(HighlightMode mode);
|
||||
|
||||
// Setter and getter for the flag which determines whether to ignore double
|
||||
// click events. These only work on macOS.
|
||||
#if defined(OS_MACOSX)
|
||||
// Set/Get flag determining whether to ignore double click events.
|
||||
virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;
|
||||
virtual bool GetIgnoreDoubleClickEvents() = 0;
|
||||
|
||||
// Set/Get title displayed next to status icon in the status bar.
|
||||
virtual void SetTitle(const std::string& title) = 0;
|
||||
virtual std::string GetTitle() = 0;
|
||||
#endif
|
||||
|
||||
// Displays a notification balloon with the specified contents.
|
||||
|
|
|
@ -26,6 +26,7 @@ class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
|
|||
void SetPressedImage(const gfx::Image& image) override;
|
||||
void SetToolTip(const std::string& tool_tip) override;
|
||||
void SetTitle(const std::string& title) override;
|
||||
std::string GetTitle() override;
|
||||
void SetHighlightMode(TrayIcon::HighlightMode mode) override;
|
||||
void SetIgnoreDoubleClickEvents(bool ignore) override;
|
||||
bool GetIgnoreDoubleClickEvents() override;
|
||||
|
|
|
@ -235,6 +235,10 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
[self updateDimensions];
|
||||
}
|
||||
|
||||
- (NSString*)title {
|
||||
return title_;
|
||||
}
|
||||
|
||||
- (void)updateAttributedTitle {
|
||||
NSDictionary* attributes =
|
||||
@{NSFontAttributeName : [NSFont menuBarFontOfSize:0]};
|
||||
|
@ -459,6 +463,10 @@ void TrayIconCocoa::SetTitle(const std::string& title) {
|
|||
[status_item_view_ setTitle:base::SysUTF8ToNSString(title)];
|
||||
}
|
||||
|
||||
std::string TrayIconCocoa::GetTitle() {
|
||||
return base::SysNSStringToUTF8([status_item_view_ title]);
|
||||
}
|
||||
|
||||
void TrayIconCocoa::SetHighlightMode(TrayIcon::HighlightMode mode) {
|
||||
[status_item_view_ setHighlight:mode];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue