tray_icon_->SetContextMenu(menu->model());
}
+gfx::Rect Tray::GetBounds() {
+ return tray_icon_->GetBounds();
+}
+
v8::Local<v8::Object> Tray::ModifiersToObject(v8::Isolate* isolate,
int modifiers) {
mate::Dictionary obj(isolate, v8::Object::New(isolate));
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("popUpContextMenu", &Tray::PopUpContextMenu)
- .SetMethod("setContextMenu", &Tray::SetContextMenu);
+ .SetMethod("setContextMenu", &Tray::SetContextMenu)
+ .SetMethod("getBounds", &Tray::GetBounds);
}
} // namespace api
// Set the context menu for this icon.
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
+ // Returns the bounds of tray icon.
+ virtual gfx::Rect GetBounds();
+
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
+
void NotifyClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
void NotifyBalloonShow();
#include "base/strings/sys_string_conversions.h"
#include "ui/events/cocoa/cocoa_event_utils.h"
#include "ui/gfx/image/image.h"
+#include "ui/gfx/mac/coordinate_conversion.h"
#include "ui/gfx/screen.h"
namespace {
// Single click event.
if (event.clickCount == 1)
trayIcon_->NotifyClicked(
- [self getBoundsFromEvent:event],
+ gfx::ScreenRectFromNSRect(event.window.frame),
ui::EventFlagsFromModifiers([event modifierFlags]));
// Double click event.
if (event.clickCount == 2)
trayIcon_->NotifyDoubleClicked(
- [self getBoundsFromEvent:event],
+ gfx::ScreenRectFromNSRect(event.window.frame),
ui::EventFlagsFromModifiers([event modifierFlags]));
[self setNeedsDisplay:YES];
- (void)rightMouseUp:(NSEvent*)event {
trayIcon_->NotifyRightClicked(
- [self getBoundsFromEvent:event],
+ gfx::ScreenRectFromNSRect(event.window.frame),
ui::EventFlagsFromModifiers([event modifierFlags]));
}
return isHighlightEnable_ && (inMouseEventSequence_ || isMenuOpen);
}
-- (gfx::Rect)getBoundsFromEvent:(NSEvent*)event {
- 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;
-}
@end
namespace atom {
[status_item_view_ setMenuController:menu_.get()];
}
+gfx::Rect TrayIconCocoa::GetBounds() {
+ auto bounds = gfx::ScreenRectFromNSRect([status_item_view_ window].frame);
+ // Calling [window frame] immediately after the view gets created will have
+ // negative |y| sometimes.
+ if (bounds.y() < 0)
+ bounds.set_y(0);
+ return bounds;
+}
+
void TrayIconCocoa::MenuClosed() {
[status_item_view_ setNeedsDisplay:YES];
}