2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-05-30 02:31:27 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/ui/tray_icon_cocoa.h"
|
|
|
|
|
2014-05-30 06:37:53 +00:00
|
|
|
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2015-07-29 04:01:27 +00:00
|
|
|
#include "ui/events/cocoa/cocoa_event_utils.h"
|
2014-06-23 04:59:10 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
2015-05-01 09:54:22 +00:00
|
|
|
#include "ui/gfx/screen.h"
|
2014-05-30 06:37:53 +00:00
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-07-29 05:27:07 +00:00
|
|
|
// By default, OS X sets 4px to tray image as left and right padding margin.
|
|
|
|
const CGFloat kHorizontalMargin = 4;
|
2015-07-30 03:57:34 +00:00
|
|
|
// OS X tends to make the title 2px lower.
|
|
|
|
const CGFloat kVerticalTitleMargin = 2;
|
2015-07-15 10:26:39 +00:00
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@interface StatusItemView : NSView {
|
2014-06-02 03:28:23 +00:00
|
|
|
atom::TrayIconCocoa* trayIcon_; // weak
|
2015-07-16 02:49:55 +00:00
|
|
|
AtomMenuController* menuController_; // weak
|
2015-07-15 10:26:39 +00:00
|
|
|
BOOL isHighlightEnable_;
|
2015-12-02 11:05:22 +00:00
|
|
|
BOOL forceHighlight_;
|
2015-07-15 10:26:39 +00:00
|
|
|
BOOL inMouseEventSequence_;
|
|
|
|
base::scoped_nsobject<NSImage> image_;
|
|
|
|
base::scoped_nsobject<NSImage> alternateImage_;
|
2015-07-29 05:27:07 +00:00
|
|
|
base::scoped_nsobject<NSImageView> image_view_;
|
2015-07-15 10:26:39 +00:00
|
|
|
base::scoped_nsobject<NSString> title_;
|
|
|
|
base::scoped_nsobject<NSStatusItem> statusItem_;
|
2014-06-02 03:28:23 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@end // @interface StatusItemView
|
2014-06-02 03:28:23 +00:00
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@implementation StatusItemView
|
2014-06-02 03:28:23 +00:00
|
|
|
|
2015-07-30 03:57:34 +00:00
|
|
|
- (id)initWithImage:(NSImage*)image icon:(atom::TrayIconCocoa*)icon {
|
|
|
|
image_.reset([image copy]);
|
2014-06-02 03:28:23 +00:00
|
|
|
trayIcon_ = icon;
|
2015-07-15 10:26:39 +00:00
|
|
|
isHighlightEnable_ = YES;
|
2015-12-02 11:05:22 +00:00
|
|
|
forceHighlight_ = NO;
|
|
|
|
inMouseEventSequence_ = NO;
|
2015-07-30 03:57:34 +00:00
|
|
|
|
2015-11-17 21:43:55 +00:00
|
|
|
if ((self = [super initWithFrame: CGRectZero])) {
|
2015-07-30 03:57:34 +00:00
|
|
|
// Setup the image view.
|
2015-11-17 21:43:55 +00:00
|
|
|
image_view_.reset([[NSImageView alloc] initWithFrame: CGRectZero]);
|
2015-07-30 03:57:34 +00:00
|
|
|
[image_view_ setImageScaling:NSImageScaleNone];
|
|
|
|
[image_view_ setImageAlignment:NSImageAlignCenter];
|
|
|
|
[self addSubview:image_view_];
|
|
|
|
|
2015-07-29 05:27:07 +00:00
|
|
|
// Unregister image_view_ as a dragged destination, allows its parent view
|
|
|
|
// (StatusItemView) handle dragging events.
|
|
|
|
[image_view_ unregisterDraggedTypes];
|
2015-11-17 21:43:55 +00:00
|
|
|
[self registerForDraggedTypes: @[NSFilenamesPboardType]];
|
2015-07-30 03:57:34 +00:00
|
|
|
|
|
|
|
// Create the status item.
|
2015-11-17 21:43:55 +00:00
|
|
|
NSStatusItem * item = [[NSStatusBar systemStatusBar]
|
|
|
|
statusItemWithLength:NSVariableStatusItemLength];
|
|
|
|
statusItem_.reset([item retain]);
|
2015-07-15 10:26:39 +00:00
|
|
|
[statusItem_ setView:self];
|
2015-11-17 21:43:55 +00:00
|
|
|
|
|
|
|
// Finalize setup by sizing our views
|
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
2014-06-02 03:28:23 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-11-17 21:43:55 +00:00
|
|
|
- (void)updateDimensions {
|
|
|
|
NSStatusBar * bar = [NSStatusBar systemStatusBar];
|
|
|
|
[image_view_ setFrame: NSMakeRect(0, 0, [self iconWidth], [bar thickness])];
|
|
|
|
[self setFrame: NSMakeRect(0, 0, [self fullWidth], [bar thickness])];
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
- (void)removeItem {
|
|
|
|
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
|
|
|
|
statusItem_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)dirtyRect {
|
2015-07-29 05:27:07 +00:00
|
|
|
// Draw the tray icon and title that align with NSStatusItem, layout:
|
2015-07-16 02:49:55 +00:00
|
|
|
// ----------------
|
|
|
|
// | icon | title |
|
|
|
|
/// ----------------
|
2015-07-30 03:57:34 +00:00
|
|
|
|
|
|
|
// Draw background.
|
2015-07-15 10:26:39 +00:00
|
|
|
BOOL highlight = [self shouldHighlight];
|
2015-07-30 03:57:34 +00:00
|
|
|
CGFloat thickness = [[statusItem_ statusBar] thickness];
|
2015-11-17 21:43:55 +00:00
|
|
|
[statusItem_ drawStatusBarBackgroundInRect:self.bounds withHighlight:highlight];
|
2015-07-29 05:27:07 +00:00
|
|
|
|
2015-07-30 03:57:34 +00:00
|
|
|
// Make use of NSImageView to draw the image, which can correctly draw
|
|
|
|
// template image under dark menu bar.
|
2016-01-05 17:47:19 +00:00
|
|
|
if (inMouseEventSequence_ && alternateImage_ &&
|
2015-07-30 03:57:34 +00:00
|
|
|
[image_view_ image] != alternateImage_.get()) {
|
2015-07-29 05:27:07 +00:00
|
|
|
[image_view_ setImage:alternateImage_];
|
2015-07-30 03:57:34 +00:00
|
|
|
} else if ([image_view_ image] != image_.get()) {
|
2015-07-29 05:27:07 +00:00
|
|
|
[image_view_ setImage:image_];
|
|
|
|
}
|
|
|
|
|
2015-07-16 02:49:55 +00:00
|
|
|
if (title_) {
|
2015-07-30 03:57:34 +00:00
|
|
|
// Highlight the text when icon is highlighted or in dark mode.
|
|
|
|
highlight |= [self isDarkMode];
|
|
|
|
// Draw title.
|
|
|
|
NSRect titleDrawRect = NSMakeRect(
|
|
|
|
[self iconWidth], -kVerticalTitleMargin, [self titleWidth], thickness);
|
2015-07-16 02:49:55 +00:00
|
|
|
[title_ drawInRect:titleDrawRect
|
2015-07-30 03:57:34 +00:00
|
|
|
withAttributes:[self titleAttributesWithHighlight:highlight]];
|
2015-07-16 02:49:55 +00:00
|
|
|
}
|
2015-07-29 05:27:07 +00:00
|
|
|
}
|
2015-07-16 02:49:55 +00:00
|
|
|
|
2015-07-30 03:57:34 +00:00
|
|
|
- (BOOL)isDarkMode {
|
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSString* mode = [defaults stringForKey:@"AppleInterfaceStyle"];
|
|
|
|
return mode && [mode isEqualToString:@"Dark"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The width of the full status item.
|
|
|
|
- (CGFloat)fullWidth {
|
|
|
|
if (title_)
|
|
|
|
return [self iconWidth] + [self titleWidth] + kHorizontalMargin;
|
|
|
|
else
|
|
|
|
return [self iconWidth];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The width of the icon.
|
|
|
|
- (CGFloat)iconWidth {
|
|
|
|
CGFloat thickness = [[NSStatusBar systemStatusBar] thickness];
|
|
|
|
CGFloat imageHeight = [image_ size].height;
|
|
|
|
CGFloat imageWidth = [image_ size].width;
|
|
|
|
CGFloat iconWidth = imageWidth;
|
|
|
|
if (imageWidth < thickness) {
|
|
|
|
// Image's width must be larger than menu bar's height.
|
|
|
|
iconWidth = thickness;
|
|
|
|
} else {
|
|
|
|
CGFloat verticalMargin = thickness - imageHeight;
|
|
|
|
// Image must have same horizontal vertical margin.
|
|
|
|
if (verticalMargin > 0 && imageWidth != imageHeight)
|
|
|
|
iconWidth = imageWidth + verticalMargin;
|
|
|
|
CGFloat horizontalMargin = thickness - imageWidth;
|
|
|
|
// Image must have at least kHorizontalMargin horizontal margin on each
|
|
|
|
// side.
|
|
|
|
if (horizontalMargin < 2 * kHorizontalMargin)
|
|
|
|
iconWidth = imageWidth + 2 * kHorizontalMargin;
|
|
|
|
}
|
|
|
|
return iconWidth;
|
2015-07-16 02:49:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 03:57:34 +00:00
|
|
|
// The width of the title.
|
2015-07-16 10:36:45 +00:00
|
|
|
- (CGFloat)titleWidth {
|
2015-07-30 03:57:34 +00:00
|
|
|
if (!title_)
|
|
|
|
return 0;
|
|
|
|
base::scoped_nsobject<NSAttributedString> attributes(
|
2015-07-16 02:49:55 +00:00
|
|
|
[[NSAttributedString alloc] initWithString:title_
|
2015-07-30 03:57:34 +00:00
|
|
|
attributes:[self titleAttributes]]);
|
2015-07-16 02:49:55 +00:00
|
|
|
return [attributes size].width;
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 03:57:34 +00:00
|
|
|
- (NSDictionary*)titleAttributesWithHighlight:(BOOL)highlight {
|
2015-07-15 10:26:39 +00:00
|
|
|
NSFont* font = [NSFont menuBarFontOfSize:0];
|
2015-07-30 03:57:34 +00:00
|
|
|
NSColor* foregroundColor = highlight ?
|
|
|
|
[NSColor whiteColor] :
|
|
|
|
[NSColor colorWithRed:0.265625 green:0.25390625 blue:0.234375 alpha:1.0];
|
2015-11-17 21:43:55 +00:00
|
|
|
return @{
|
|
|
|
NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: foregroundColor
|
|
|
|
};
|
2015-07-30 03:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary*)titleAttributes {
|
|
|
|
return [self titleAttributesWithHighlight:[self isDarkMode]];
|
2014-06-02 03:28:23 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
- (void)setImage:(NSImage*)image {
|
|
|
|
image_.reset([image copy]);
|
2015-11-17 21:43:55 +00:00
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlternateImage:(NSImage*)image {
|
|
|
|
alternateImage_.reset([image copy]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHighlight:(BOOL)highlight {
|
|
|
|
isHighlightEnable_ = highlight;
|
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)setTitle:(NSString*)title {
|
2015-11-17 21:43:55 +00:00
|
|
|
if (title.length > 0) {
|
2015-07-30 03:57:34 +00:00
|
|
|
title_.reset([title copy]);
|
2015-11-17 21:43:55 +00:00
|
|
|
} else {
|
2015-07-30 03:57:34 +00:00
|
|
|
title_.reset();
|
2015-11-17 21:43:55 +00:00
|
|
|
}
|
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMenuController:(AtomMenuController*)menu {
|
2015-07-16 02:49:55 +00:00
|
|
|
menuController_ = menu;
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)mouseDown:(NSEvent*)event {
|
2015-07-15 10:26:39 +00:00
|
|
|
inMouseEventSequence_ = YES;
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)mouseUp:(NSEvent*)event {
|
2015-07-15 10:26:39 +00:00
|
|
|
if (!inMouseEventSequence_) {
|
|
|
|
// If the menu is showing, when user clicked the tray icon, the `mouseDown`
|
|
|
|
// event will be dissmissed, we need to close the menu at this time.
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inMouseEventSequence_ = NO;
|
2015-07-27 10:15:51 +00:00
|
|
|
|
2015-08-26 08:28:22 +00:00
|
|
|
// Show menu when there is a context menu.
|
|
|
|
// NB(hokein): Make tray's behavior more like official one's.
|
|
|
|
// When the tray icon gets clicked quickly multiple times, the
|
|
|
|
// event.clickCount doesn't always return 1. Instead, it returns a value that
|
|
|
|
// counts the clicked times.
|
|
|
|
// So we don't check the clickCount here, just pop up the menu for each click
|
|
|
|
// event.
|
|
|
|
if (menuController_)
|
2015-08-10 04:18:00 +00:00
|
|
|
[statusItem_ popUpStatusItemMenu:[menuController_ menu]];
|
|
|
|
|
|
|
|
// Don't emit click events when menu is showing.
|
|
|
|
if (menuController_)
|
|
|
|
return;
|
2015-07-15 10:26:39 +00:00
|
|
|
|
2015-08-10 04:18:00 +00:00
|
|
|
// Single click event.
|
|
|
|
if (event.clickCount == 1)
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyClicked(
|
|
|
|
[self getBoundsFromEvent:event],
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-07-15 10:26:39 +00:00
|
|
|
|
2015-08-10 04:18:00 +00:00
|
|
|
// Double click event.
|
|
|
|
if (event.clickCount == 2)
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyDoubleClicked(
|
|
|
|
[self getBoundsFromEvent:event],
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-08-10 04:18:00 +00:00
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2015-12-02 11:05:22 +00:00
|
|
|
- (void)popUpContextMenu:(ui::SimpleMenuModel*)menu_model {
|
|
|
|
// Show a custom menu.
|
|
|
|
if (menu_model) {
|
|
|
|
base::scoped_nsobject<AtomMenuController> menuController(
|
|
|
|
[[AtomMenuController alloc] initWithModel:menu_model]);
|
|
|
|
forceHighlight_ = YES; // Should highlight when showing menu.
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
[statusItem_ popUpStatusItemMenu:[menuController menu]];
|
|
|
|
forceHighlight_ = NO;
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-16 02:50:53 +00:00
|
|
|
if (menuController_ && ![menuController_ isMenuOpen]) {
|
2015-07-30 03:57:34 +00:00
|
|
|
// Redraw the dray icon to show highlight if it is enabled.
|
2015-07-16 02:50:53 +00:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
[statusItem_ popUpStatusItemMenu:[menuController_ menu]];
|
|
|
|
// The popUpStatusItemMenu returns only after the showing menu is closed.
|
|
|
|
// When it returns, we need to redraw the tray icon to not show highlight.
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:23:12 +00:00
|
|
|
- (void)rightMouseUp:(NSEvent*)event {
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyRightClicked(
|
|
|
|
[self getBoundsFromEvent:event],
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-07-15 11:23:12 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 04:12:28 +00:00
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
|
2015-11-06 00:45:43 +00:00
|
|
|
trayIcon_->NotifyDragEntered();
|
2015-07-19 04:12:28 +00:00
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
|
2015-11-06 00:45:43 +00:00
|
|
|
- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
|
|
|
trayIcon_->NotifyDragExited();
|
|
|
|
}
|
|
|
|
|
2015-11-10 16:02:50 +00:00
|
|
|
- (void)draggingEnded:(id <NSDraggingInfo>)sender {
|
|
|
|
trayIcon_->NotifyDragEnded();
|
|
|
|
|
2015-12-29 09:25:21 +00:00
|
|
|
if (NSPointInRect([sender draggingLocation], self.frame)) {
|
|
|
|
trayIcon_->NotifyDrop();
|
|
|
|
[self handleDrop:sender];
|
|
|
|
}
|
2015-11-10 16:02:50 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 09:25:21 +00:00
|
|
|
- (BOOL)handleDrop:(id <NSDraggingInfo>)sender {
|
2015-07-19 04:12:28 +00:00
|
|
|
NSPasteboard* pboard = [sender draggingPasteboard];
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
|
|
|
|
std::vector<std::string> dropFiles;
|
|
|
|
NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
for (NSString* file in files)
|
|
|
|
dropFiles.push_back(base::SysNSStringToUTF8(file));
|
2015-10-18 05:32:13 +00:00
|
|
|
trayIcon_->NotifyDropFiles(dropFiles);
|
2015-07-19 04:12:28 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:25:21 +00:00
|
|
|
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (BOOL)shouldHighlight {
|
2015-12-02 11:05:22 +00:00
|
|
|
if (isHighlightEnable_ && forceHighlight_)
|
|
|
|
return true;
|
2015-07-30 03:57:34 +00:00
|
|
|
BOOL isMenuOpen = menuController_ && [menuController_ isMenuOpen];
|
|
|
|
return isHighlightEnable_ && (inMouseEventSequence_ || isMenuOpen);
|
2014-09-09 11:45:21 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (gfx::Rect)getBoundsFromEvent:(NSEvent*)event {
|
2015-07-15 11:23:12 +00:00
|
|
|
NSRect frame = event.window.frame;
|
|
|
|
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
|
|
|
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
|
|
|
return bounds;
|
|
|
|
}
|
2014-06-02 03:28:23 +00:00
|
|
|
@end
|
|
|
|
|
2014-05-30 02:31:27 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2015-08-10 04:48:22 +00:00
|
|
|
TrayIconCocoa::TrayIconCocoa() : menu_model_(nullptr) {
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrayIconCocoa::~TrayIconCocoa() {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ removeItem];
|
2015-08-10 04:48:22 +00:00
|
|
|
if (menu_model_)
|
|
|
|
menu_model_->RemoveObserver(this);
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:43:56 +00:00
|
|
|
void TrayIconCocoa::SetImage(const gfx::Image& image) {
|
2015-07-30 03:57:34 +00:00
|
|
|
if (status_item_view_) {
|
|
|
|
[status_item_view_ setImage:image.AsNSImage()];
|
|
|
|
} else {
|
|
|
|
status_item_view_.reset(
|
|
|
|
[[StatusItemView alloc] initWithImage:image.AsNSImage()
|
|
|
|
icon:this]);
|
|
|
|
}
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:43:56 +00:00
|
|
|
void TrayIconCocoa::SetPressedImage(const gfx::Image& image) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setAlternateImage:image.AsNSImage()];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setToolTip:base::SysUTF8ToNSString(tool_tip)];
|
2014-05-30 06:37:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 11:33:58 +00:00
|
|
|
void TrayIconCocoa::SetTitle(const std::string& title) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setTitle:base::SysUTF8ToNSString(title)];
|
2014-09-09 11:33:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 11:39:39 +00:00
|
|
|
void TrayIconCocoa::SetHighlightMode(bool highlight) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setHighlight:highlight];
|
2014-09-09 11:39:39 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 10:43:11 +00:00
|
|
|
void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
|
|
|
|
ui::SimpleMenuModel* menu_model) {
|
2015-12-02 11:05:22 +00:00
|
|
|
[status_item_view_ popUpContextMenu:menu_model];
|
2015-07-16 02:50:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 06:37:53 +00:00
|
|
|
void TrayIconCocoa::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
2015-08-10 04:48:22 +00:00
|
|
|
// Substribe to MenuClosed event.
|
|
|
|
if (menu_model_)
|
|
|
|
menu_model_->RemoveObserver(this);
|
|
|
|
static_cast<AtomMenuModel*>(menu_model)->AddObserver(this);
|
|
|
|
|
|
|
|
// Create native menu.
|
2014-05-30 06:37:53 +00:00
|
|
|
menu_.reset([[AtomMenuController alloc] initWithModel:menu_model]);
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setMenuController:menu_.get()];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 04:48:22 +00:00
|
|
|
void TrayIconCocoa::MenuClosed() {
|
|
|
|
[status_item_view_ setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
2014-05-30 15:57:54 +00:00
|
|
|
// static
|
|
|
|
TrayIcon* TrayIcon::Create() {
|
|
|
|
return new TrayIconCocoa;
|
|
|
|
}
|
|
|
|
|
2014-05-30 02:31:27 +00:00
|
|
|
} // namespace atom
|